Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta Adatta ai principianti
#90 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

Il bug si trova in int8_quantize_kernel in wan/triton_kernels.py, intorno alle righe 29-31, dove l'offset di arrotondamento ±0.5 viene convertito in int8 prima di essere sommato, quindi diventa 0. Leggi il kernel circostante per capire come vengono usati x_scale e la maschera di store, poi verifica se l'output è limitato a [-127, 127]. È completato quando l'offset viene sommato in float prima della conversione in int8 e un piccolo test che confronta l'output del kernel con l'arrotondamento a metà allontanandosi da zero dà risultati corretti su input di esempio.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
2.4k
Fork
257
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di SkyworkAI/Matrix-Game

Tutte le issue di SkyworkAI/Matrix-Game

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.