Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

int8_quantize_kernel truncates toward zero instead of rounding (the ±0.5 offset is cast to int8 before being added)

オープン 初心者向け
#90 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python

調査の方向性

バグは wan/triton_kernels.py の int8_quantize_kernel、30行目付近(29〜31行目)にあります。±0.5 の丸めオフセットが加算される前に int8 にキャストされているため、0 になっています。周囲のカーネルを読んで x_scale とストアマスクの使われ方を確認し、出力が [-127, 127] にクランプされているかを確認してください。完了の条件は、int8 へのキャストの前に float でオフセットを加算すること、そして、カーネルの出力を「0から遠ざかる方向への半分切り上げ(round-half-away-from-zero)」と比較する小さなテストがサンプル入力で一致することです。

索引モデルが issue の本文から書いたものです。

説明

Where: https://github.com/SkyworkAI/Matrix-Game/blob/ad397b34dd78880bad068232227a49f7106af817/Matrix-Game-3/wan/triton_kernels.py#L29-L31

x_scaled = x * x_scale
x_scaled += (0.5 * tl.where(x_scaled >= 0, 1, -1)).to(tl.int8)
tl.store(out_ptr + h_offset, x_scaled, mask=h_offset < HDIM)

What happens: (0.5 * sign).to(tl.int8) evaluates to 0, so nothing is added. The float x_scaled is then stored into the int8 output, which truncates toward zero. The intended rounding (half away from zero) is lost and every activation is biased toward zero.

Suggested fix: add the offset in float before the cast:

x_scaled = x_scaled + 0.5 * tl.where(x_scaled >= 0, 1.0, -1.0)
tl.store(out_ptr + h_offset, x_scaled.to(tl.int8), mask=h_offset < HDIM)

(or use a round-to-nearest intrinsic). Since x_scale = 127 / max|x|, the rounded value stays within [-127, 127].

Measured impact (our replication, Matrix-Game-3.0 distilled, --use_int8 path on the 240 attention q/k/v/o layers, real activations from one rollout):

  • Mean relative output MSE vs BF16: 3.68e-3 with the current kernel vs 6.44e-4 with round-to-nearest (about 5.7x lower).
  • The current kernel's error is a systematic magnitude shrinkage (cosine between error and output between -0.62 and -0.85; about 0 with rounding).
  • Other factors (int32 accumulation, bf16 weight scales, per-token / per-channel granularity) change the error by less than 2%.
  • In our closed-loop rollouts (352x640 and 704x1280) we did not detect visible degradation from the current kernel with our metrics, so this is a precision issue rather than an obvious quality break; fixing it should still reduce error at no cost.

Happy to share the per-layer measurements if useful.

主要言語
Python
スター
2.4k
フォーク
257
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

SkyworkAI/Matrix-Game のほかの issue

SkyworkAI/Matrix-Game の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。