pytorch - ✅(Solved) Fix Internal Assert Failure in `torch.ao.nn.quantized.GroupNorm` with incorrectly sized bias tensor [2 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#177825Fetched 2026-04-08 01:01:38
View on GitHub
Comments
0
Participants
1
Timeline
22
Reactions
0
Participants
Timeline (top)
mentioned ×9subscribed ×9cross-referenced ×2labeled ×2

Error Message

RuntimeError: !beta.defined() || (!affine_per_channel && beta.numel() == N) || (affine_per_channel && beta.numel() == num_channels) INTERNAL ASSERT FAILED at "/pytorch/aten/src/ATen/native/quantized/cpu/kernels/QuantizedOpKernels.cpp":2938, please report a bug to PyTorch. Unexpected size of beta

Fix Action

Fix / Workaround

CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian Address sizes: 46 bits physical, 57 bits virtual CPU(s): 64 On-line CPU(s) list: 0-63 Thread(s) per core: 2 Core(s) per socket: 16 Socket(s): 2 NUMA node(s): 2 Vendor ID: GenuineIntel CPU family: 6 Model: 106 Model name: Intel(R) Xeon(R) Gold 6326 CPU @ 2.90GHz Stepping: 6 CPU MHz: 895.670 CPU max MHz: 3500.0000 CPU min MHz: 800.0000 BogoMIPS: 5800.00 Virtualization: VT-x L1d cache: 1.5 MiB L1i cache: 1 MiB L2 cache: 40 MiB L3 cache: 48 MiB NUMA node0 CPU(s): 0-15,32-47 NUMA node1 CPU(s): 16-31,48-63 Vulnerability Gather data sampling: Mitigation; Microcode Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Not affected Vulnerability Spec rstack overflow: Not affected Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 invpcid_single intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect wbnoinvd dtherm ida arat pln pts avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid fsrm md_clear pconfig flush_l1d arch_capabilities

PR fix notes

PR #177893: negative mem alloc size error raised for torch.cuda.memory.caching_allocator_alloc

Description (problem / solution / changelog)

in PyTorch when using the API torch.cuda.memory.caching_allocator_alloc. The crash is triggered by an internal C++ assertion failure when a negative integer (e.g., -1024) is passed as the memory allocation size.

Raises clear value error

Fixes 177827

Changed files

  • test/test_cuda.py (modified, +4/-0)
  • torch/csrc/cuda/Module.cpp (modified, +5/-0)

PR #178459: TORCH_CHECK guards in quantized_group_norm_impl for weight or bias

Description (problem / solution / changelog)

user encountered bug in PyTorch when using the API torch.ao.nn.quantized.GroupNorm. The crash is triggered by an internal C++ assertion failure when the bias parameter (referred to internally as beta) is initialized with a size that does not match the num_channels dimension.

Fixed at cpp level such that both python and cpp is taken care. Not adding in python wrapper.

Fixes 177825

cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @jerryzh168 @aditew01

Changed files

  • aten/src/ATen/native/quantized/cpu/qnormalization.cpp (modified, +14/-0)
  • test/quantization/core/test_quantized_op.py (modified, +25/-0)

Code Example

import torch
import torch.ao.nn.quantized as nnq

input_tensor = torch.randn(20, 6, 10, 10)
num_groups = 2
num_channels = 6
weight = torch.nn.Parameter(torch.randn(num_channels))
bias = torch.nn.Parameter(torch.tensor([float('inf')]))  # Invalid memory address
scale = 1.0
zero_point = 0
dtype = torch.qint8

q_input = torch.quantize_per_tensor(input_tensor, scale=scale, zero_point=zero_point, dtype=dtype)
group_norm = nnq.GroupNorm(num_groups, num_channels, weight=weight, bias=bias, scale=scale, zero_point=zero_point)
output = group_norm(q_input)

---

RuntimeError: !beta.defined() || (!affine_per_channel && beta.numel() == N) || (affine_per_channel && beta.numel() == num_channels) INTERNAL ASSERT FAILED at "/pytorch/aten/src/ATen/native/quantized/cpu/kernels/QuantizedOpKernels.cpp":2938, please report a bug to PyTorch. Unexpected size of beta
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

I encountered a bug in PyTorch when using the API torch.ao.nn.quantized.GroupNorm. The crash is triggered by an internal C++ assertion failure when the bias parameter (referred to internally as beta) is initialized with a size that does not match the num_channels dimension. The code to reproduce this is as follows:

import torch
import torch.ao.nn.quantized as nnq

input_tensor = torch.randn(20, 6, 10, 10)
num_groups = 2
num_channels = 6
weight = torch.nn.Parameter(torch.randn(num_channels))
bias = torch.nn.Parameter(torch.tensor([float('inf')]))  # Invalid memory address
scale = 1.0
zero_point = 0
dtype = torch.qint8

q_input = torch.quantize_per_tensor(input_tensor, scale=scale, zero_point=zero_point, dtype=dtype)
group_norm = nnq.GroupNorm(num_groups, num_channels, weight=weight, bias=bias, scale=scale, zero_point=zero_point)
output = group_norm(q_input)

Output

RuntimeError: !beta.defined() || (!affine_per_channel && beta.numel() == N) || (affine_per_channel && beta.numel() == num_channels) INTERNAL ASSERT FAILED at "/pytorch/aten/src/ATen/native/quantized/cpu/kernels/QuantizedOpKernels.cpp":2938, please report a bug to PyTorch. Unexpected size of beta

Here is the gist.

Versions

Collecting environment information... PyTorch version: 2.10.0+cu128 Is debug build: False CUDA used to build PyTorch: 12.8 ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.3 LTS (x86_64) GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0 Clang version: Could not collect CMake version: Could not collect Libc version: glibc-2.31

Python version: 3.13.12 | packaged by Anaconda, Inc. | (main, Feb 24 2026, 16:13:31) [GCC 14.3.0] (64-bit runtime) Python platform: Linux-5.15.0-139-generic-x86_64-with-glibc2.31 Is CUDA available: True CUDA runtime version: Could not collect CUDA_MODULE_LOADING set to: GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3090 GPU 1: NVIDIA GeForce RTX 3090 GPU 2: NVIDIA GeForce RTX 3090 GPU 3: NVIDIA GeForce RTX 3090 GPU 4: NVIDIA GeForce RTX 3090 GPU 5: NVIDIA GeForce RTX 3090 GPU 6: NVIDIA GeForce RTX 3090 GPU 7: NVIDIA GeForce RTX 3090

Nvidia driver version: 535.183.01 cuDNN version: Could not collect Is XPU available: False HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True Caching allocator config: N/A

CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian Address sizes: 46 bits physical, 57 bits virtual CPU(s): 64 On-line CPU(s) list: 0-63 Thread(s) per core: 2 Core(s) per socket: 16 Socket(s): 2 NUMA node(s): 2 Vendor ID: GenuineIntel CPU family: 6 Model: 106 Model name: Intel(R) Xeon(R) Gold 6326 CPU @ 2.90GHz Stepping: 6 CPU MHz: 895.670 CPU max MHz: 3500.0000 CPU min MHz: 800.0000 BogoMIPS: 5800.00 Virtualization: VT-x L1d cache: 1.5 MiB L1i cache: 1 MiB L2 cache: 40 MiB L3 cache: 48 MiB NUMA node0 CPU(s): 0-15,32-47 NUMA node1 CPU(s): 16-31,48-63 Vulnerability Gather data sampling: Mitigation; Microcode Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Not affected Vulnerability Spec rstack overflow: Not affected Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 invpcid_single intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect wbnoinvd dtherm ida arat pln pts avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid fsrm md_clear pconfig flush_l1d arch_capabilities

Versions of relevant libraries: [pip3] numpy==2.4.3 [pip3] nvidia-cublas-cu12==12.8.4.1 [pip3] nvidia-cuda-cupti-cu12==12.8.90 [pip3] nvidia-cuda-nvrtc-cu12==12.8.93 [pip3] nvidia-cuda-runtime-cu12==12.8.90 [pip3] nvidia-cudnn-cu12==9.10.2.21 [pip3] nvidia-cufft-cu12==11.3.3.83 [pip3] nvidia-curand-cu12==10.3.9.90 [pip3] nvidia-cusolver-cu12==11.7.3.90 [pip3] nvidia-cusparse-cu12==12.5.8.93 [pip3] nvidia-cusparselt-cu12==0.7.1 [pip3] nvidia-nccl-cu12==2.27.5 [pip3] nvidia-nvjitlink-cu12==12.8.93 [pip3] nvidia-nvtx-cu12==12.8.90 [pip3] optree==0.19.0 [pip3] torch==2.10.0 [pip3] triton==3.6.0 [conda] numpy 2.4.3 pypi_0 pypi [conda] nvidia-cublas-cu12 12.8.4.1 pypi_0 pypi [conda] nvidia-cuda-cupti-cu12 12.8.90 pypi_0 pypi [conda] nvidia-cuda-nvrtc-cu12 12.8.93 pypi_0 pypi [conda] nvidia-cuda-runtime-cu12 12.8.90 pypi_0 pypi [conda] nvidia-cudnn-cu12 9.10.2.21 pypi_0 pypi [conda] nvidia-cufft-cu12 11.3.3.83 pypi_0 pypi [conda] nvidia-curand-cu12 10.3.9.90 pypi_0 pypi [conda] nvidia-cusolver-cu12 11.7.3.90 pypi_0 pypi [conda] nvidia-cusparse-cu12 12.5.8.93 pypi_0 pypi [conda] nvidia-cusparselt-cu12 0.7.1 pypi_0 pypi [conda] nvidia-nccl-cu12 2.27.5 pypi_0 pypi [conda] nvidia-nvjitlink-cu12 12.8.93 pypi_0 pypi [conda] nvidia-nvtx-cu12 12.8.90 pypi_0 pypi [conda] optree 0.19.0 pypi_0 pypi [conda] torch 2.10.0 pypi_0 pypi [conda] triton 3.6.0 pypi_0 pypi

cc @jerryzh168 @jianyuh @raghuramank100 @jamesr66a @vkuzo @jgong5 @Xia-Weiwen @leslie-fang-intel

extent analysis

Fix Plan

The issue arises from the bias parameter not matching the num_channels dimension. To fix this, we need to ensure the bias is initialized with the correct size.

  • Initialize the bias with the correct size:

bias = torch.nn.Parameter(torch.randn(num_channels))

*   Replace the invalid `bias` initialization in the provided code:
    ```python
input_tensor = torch.randn(20, 6, 10, 10)
num_groups = 2
num_channels = 6
weight = torch.nn.Parameter(torch.randn(num_channels))
bias = torch.nn.Parameter(torch.randn(num_channels))  # Corrected bias initialization
scale = 1.0
zero_point = 0
dtype = torch.qint8

q_input = torch.quantize_per_tensor(input_tensor, scale=scale, zero_point=zero_point, dtype=dtype)
group_norm = nnq.GroupNorm(num_groups, num_channels, weight=weight, bias=bias, scale=scale, zero_point=zero_point)
output = group_norm(q_input)

Verification

To verify the fix, run the corrected code and check that it no longer raises the RuntimeError related to the bias size.

Extra Tips

  • Always ensure that the sizes of parameters like weight and bias match the expected dimensions of the layer.
  • Be cautious when using float('inf') as it can lead to unexpected behavior, especially in numerical computations.
  • When working with quantized modules, pay attention to the scale and zero-point values, as they can significantly affect the results.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

pytorch - ✅(Solved) Fix Internal Assert Failure in `torch.ao.nn.quantized.GroupNorm` with incorrectly sized bias tensor [2 pull requests, 1 participants]