CUDA INT8 fake quantization converts channels-last inputs to default contiguous layout
Maintainer thường phản hồi trong vòng 2 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 50/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- machine-learning
Hướng nghiên cứu
Start with the CUDA fake-quant entry points that call inputs.contiguous() without a memory format, for both per-tensor and per-channel paths, and with the in-place check that rejects channels-last inputs. Run the reproducer in the issue to confirm the output stride changes from (105, 1, 21, 3). Done means the layout is preserved for contiguous_format, channels_last and channels_last_3d, while quantized values stay identical and the CUDA extension tests pass.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
CUDA INT8 fake quantization converts channels-last inputs to the default contiguous memory format. The output has the correct quantized values, but loses the input memory layout.
The main motivation is downstream numerical alignment. In practical use, we observed a substantial downstream numerical mismatch despite identical fake-quant values; preserving the output memory format restored alignment with the layout-preserving reference in that case. The conversion also adds an unnecessary full-tensor copy. The per-tensor and per-channel CUDA entry points both call inputs.contiguous() without a memory format.
Steps/Code to reproduce bug
Run on an unmodified checkout of NVIDIA/Model-Optimizer at 472ecb39ad498a6b0d818583d5b1dc483a708abf with CUDA and the ModelOpt CUDA extension available:
import torch
from modelopt.torch.quantization.extensions import get_cuda_ext
ext = get_cuda_ext(raise_if_failed=True)
x = torch.linspace(-1, 1, 210, device="cuda").reshape(2, 3, 5, 7)
x = x.contiguous(memory_format=torch.channels_last)
amax = torch.tensor(1.0, device="cuda")
y = ext.fake_tensor_quant(x, amax)
reference = ext.fake_tensor_quant(x.contiguous(), amax)
print("input stride:", x.stride())
print("output stride:", y.stride())
print("same quantized values:", torch.equal(y, reference))
print("channels-last output:", y.is_contiguous(memory_format=torch.channels_last))
Observed on the original CUDA implementation:
input stride: (105, 1, 21, 3)
output stride: (105, 35, 7, 1)
same quantized values: True
channels-last output: False
This synthetic reproducer demonstrates the layout side effect. The downstream numerical mismatch described above is an application observation, rather than a result measured by this minimal reproducer.
The public tensor_quant.fake_tensor_quant API reaches the same CUDA implementation. Per-channel quantization through fake_tensor_quant_with_axis and 5D channels_last_3d inputs also lose their memory format. The in-place per-tensor entry point rejects channels-last inputs despite their dense contiguous storage.
Expected behavior
Preserve supported contiguous input memory formats (contiguous_format, channels_last, channels_last_3d) without changing the quantization formula, ranges, or output values. Continue to handle non-contiguous inputs safely.
A possible localized fix is to prepare out-of-place inputs with inputs.contiguous(inputs.suggest_memory_format()) and accept the same contiguous formats in the in-place check. The per-channel kernel already uses the actual axis stride to select its amax. A candidate fix and synthetic regression tests have been prepared.
Verification
The reproducer above was executed against both original and fixed CUDA extensions with PyTorch 2.12.1 / CUDA 13.0. The candidate preserves (105, 1, 21, 3) while retaining identical quantized values.
Synthetic regression tests cover per-tensor, every per-channel axis, in-place behavior, non-contiguous inputs, and FP32/FP16/BF16. The original extension fails 12 channels-last cases; all 76 CUDA extension tests and 47 CPU tensor-quantization tests pass with the candidate.
Who can help?
Quantization maintainers.
System information
- OS: Ubuntu 22.04.5 LTS (container).
- CPU architecture: x86_64.
- GPU: one NVIDIA GeForce RTX 5090, approximately 32 GB.
- Python: 3.12.3.
- ModelOpt: upstream commit
472ecb39ad498a6b0d818583d5b1dc483a708abf. - CUDA toolkit: 13.0 (V13.0.88); driver: 595.71.05.
- PyTorch:
2.12.1+cu130(within the declared PyTorch >=2.10 range). - Also reproduced with PyTorch
2.7.0+cu128/ CUDA 12.8 as supplemental older-version evidence. - Transformers, TensorRT-LLM, ONNXRuntime, TensorRT: not required by the reproducer.
- Ngôn ngữ chính
- Python
- Star
- 5.5k
- Fork
- 800
- Merge trung bình
- 3 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 278
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của NVIDIA/Model-Optimizer
-
[Bug] modelopt-mcp: all launcher subprocesses hang when the server runs as a stdio MCP server — missing stdin=DEVNULLCó thể đã có người làm @ChenhanYu đã nhận 33 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NVIDIA/Model-Optimizer#2551 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Puzzletron Progress 6/8 (calculating one block scores) takes 10 to 20 times more than in tutorialCó thể làm lại được @tejasng053 đã nhận 40 ngày trước và không có pull request nào đang mở. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
NVIDIA/Model-Optimizer#1667 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 18/100
NVIDIA/Model-Optimizer#3178 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
INT4 packing extension never loads from a read-only installCó thể đã có người làm @ajrasane đã nhận 6 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
NVIDIA/Model-Optimizer#3025 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Puzzletron] Runtime stats benchmark model computes head size as hidden_size // num_attention_heads instead of reading head_dimCó thể đã có người làm @grzegorz-k-karch đã nhận 10 ngày trước. Đang mởbug
NVIDIA/Model-Optimizer#3016 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của NVIDIA/Model-Optimizer
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
huggingface/deep-rl-class#723 ·
-
[tool] bug: Qwen3 XML tool parser raises on `...` argument values (Ellipsis is not JSON serializable)Có thể đã có người làm @super-yuki đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 87/100
verl-project/verl#8559 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
TencentCloud/octop-harness#228 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
google/osv-scalibr#2585 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
NousResearch/hermes-agent#149323 ·
Maintainer thường phản hồi trong vòng 1 ngày