Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#90 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
machine-learning

Hướng nghiên cứu

Lỗi nằm trong int8_quantize_kernel tại wan/triton_kernels.py, quanh các dòng 29-31, nơi độ lệch làm tròn ±0.5 bị ép kiểu sang int8 trước khi được cộng, nên nó trở thành 0. Hãy đọc phần kernel xung quanh để xem x_scale và mặt nạ ghi (store mask) được dùng như thế nào, rồi kiểm tra xem đầu ra có được kẹp trong khoảng [-127, 127] hay không. Hoàn thành khi độ lệch được cộng ở kiểu float trước khi ép sang int8, và một bài kiểm thử nhỏ so sánh đầu ra của kernel với làm tròn nửa về phía xa số 0 khớp trên các đầu vào mẫu.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
2.7k
Fork
285
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của SkyworkAI/Matrix-Game

Tất cả issue của SkyworkAI/Matrix-Game

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.