int8_quantize_kernel truncates toward zero instead of rounding (the ±0.5 offset is cast to int8 before being added)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- machine-learning
Research direction
The bug is in int8_quantize_kernel in wan/triton_kernels.py, around lines 29-31, where the ±0.5 rounding offset is cast to int8 before it is added, so it becomes 0. Read the surrounding kernel to see how x_scale and the store mask are used, then check whether the output is clamped to [-127, 127]. Done means the offset is added in float before the int8 cast, and a small test comparing the kernel output with round-half-away-from-zero matches on sample inputs.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 2.7k
- Forks
- 285
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from SkyworkAI/Matrix-Game
-
Replace deprecated v2.ToTensor() in Matrix-Game-2/inference.py with v2.ToImage() + v2.ToDtype(scale=True)Possibly taken @xyf5432 claimed this 60 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
SkyworkAI/Matrix-Game#82 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
SkyworkAI/Matrix-Game#80 ·
-
run logic error when finishPossibly taken @Arison591 claimed this 97 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
SkyworkAI/Matrix-Game#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 20/100
SkyworkAI/Matrix-Game#93 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
SkyworkAI/Matrix-Game#92 ·
All issues in SkyworkAI/Matrix-Game
Similar issues
-
Validate non-divisible effective batch sizes in the Unsloth LoRA backendPossibly taken @debesh-biswas claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
reflex-dev/reflex#7634 · 1 comment ·
Maintainers usually reply within 2 days
-
documentation
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
topoteretes/cognee#6239 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ranaroussi/yfinance#3009 ·
Maintainers usually reply within 1 day
-
Test discovery aborts on GPU builds without cuStateVec: check_cuStateVec expects a failed result but set_config() now raises RuntimeErrorPossibly taken @dmeliksetian claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Qiskit/qiskit-aer#2495 ·
Maintainers usually reply within 1 day