[BUG] MSE histogram calibration: wrong amax for INT, TypeError for FP8 (args passed in the bias slot)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 82/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
調査の方向性
modelopt/torch/quantization/calib/histogram.pyから始め、fake_tensor_quantとscaled_e4m3のシグネチャとあわせて_compute_amax_mseを調べてください。issueにあるINT8とFP8のCPU例を再現し、その後、両方の形式について回帰テストを追加してください。両方が例外を発生させず妥当なamax値を返し、共有MSEキャリブレーション経路を通した場合も同様であれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
HistogramCalibrator.compute_amax("mse") returns an amax that is far too small for INT formats. For FP8 (E4M3) it raises a TypeError. calibrate_weights(method="mse") goes through the same code, so it has the same problem.
The cause is in _compute_amax_mse in modelopt/torch/quantization/calib/histogram.py:
quant_centers = fake_tensor_quant(centers, amax, num_bits, unsigned)
...
quant_centers = scaled_e4m3(centers, amax, num_bits[0], num_bits[1])
Both functions now take bias as their third argument (fake_tensor_quant(inputs, amax, bias=None, num_bits=8, unsigned=False, ...), scaled_e4m3(inputs, amax, bias=None, E=4, M=3, ...)).
- INT path: the call passes
bias=8andnum_bits=False, so every candidate amax gives the same constant output and the same MSE.argminthen returns the first candidate,centers[start_bin]. - FP8 path:
Mis missing, so the call raises.
Steps to reproduce
Main at 86bd9b78425a23a45b329c7c9b86ea772d7a9e77, CPU.
import torch
from modelopt.torch.quantization import calib
torch.manual_seed(0)
x = torch.randn(100_000)
print("max|x|:", x.abs().max().item())
for num_bits in (8, (4, 3)):
cal = calib.HistogramCalibrator(num_bits, None, False, num_bins=2048)
cal.collect(x)
try:
print(num_bits, "mse amax:", cal.compute_amax("mse").item())
except Exception as e:
print(num_bits, type(e).__name__, e)
Actual:
max|x|: 4.562695503234863
8 mse amax: 0.28628242015838623
(4, 3) TypeError ScaledE4M3Function.forward() missing 1 required positional argument: 'M'
Expected: an amax a bit below max|x| for both formats. With the arguments passed correctly the same script prints 4.0603 (INT8) and 4.3811 (FP8).
With CUDA available the histogram moves to the GPU and the quantizers go through the CUDA extension. The same script on B300 prints 4.5616 for INT8 (the amax lands at max|x|, not at the MSE optimum 4.0603) and the same TypeError for FP8.
Same effect through the public API on CPU: calibrate_weights(model, method="mse", perchannel=True) on an INT8 per-channel Linear(256, 4) sets every channel's amax to 0.0039 while max|w| is about 0.0625. The relative weight error after quantization is 0.908. With the fix it is 0.0039.
The existing TestMSECalibrator tests still pass on main. They only check that amax is closer to the bulk value than to the outlier, and the first candidate bin also satisfies that.
Proposed fix
Pass None for bias in both calls, plus a Gaussian regression test for INT8 and FP8.
Could a maintainer confirm this is a bug and not already fixed internally? I have the fix and tests ready and can open a PR after your reply.
- 主要言語
- Python
- スター
- 5.5k
- フォーク
- 800
- 平均マージ
- 3日 6時間
- マージ済み PR(30日)
- 267
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
NVIDIA/Model-Optimizer のほかの issue
-
[Bug] modelopt-mcp: all launcher subprocesses hang when the server runs as a stdio MCP server — missing stdin=DEVNULL対応中かも @ChenhanYu が 38 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
NVIDIA/Model-Optimizer#2551 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Puzzletron Progress 6/8 (calculating one block scores) takes 10 to 20 times more than in tutorial再び着手できるかも @tejasng053 が 45 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
NVIDIA/Model-Optimizer#1667 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
NVIDIA/Model-Optimizer#3262 ·
メンテナーはふだん 1 日以内に返信
-
[ONNX] graph_surgery / llm_export compute head_dim as hidden_size // num_attention_heads, ignoring config.head_dim (breaks Qwen3, Gemma, Mistral-Small)対応中かも @sylvesterkaczmarek が 4 日前に担当しました。 オープンbug
難易度 3/5 1〜2日 初心者へのやさしさ 71/100
NVIDIA/Model-Optimizer#3245 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
Alpamayo quantized model doesn't run and cannot be converted to TensorRT対応中かも @rohansjoshi が 4 日前に担当しました。 オープンbug torch.quantization waiting for feedback
NVIDIA/Model-Optimizer#3227 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
NVIDIA/Model-Optimizer の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Project-N-E-K-O/N.E.K.O#3670 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
type:docs
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
jejjohnson/xtremax#123 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
triage
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
microsoft/agent-framework#10218 ·
メンテナーはふだん 1 日以内に返信
-
fidelity
難易度 2/5 半日 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信