int8_quantize_kernel truncates toward zero instead of rounding (the ±0.5 offset is cast to int8 before being added)
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
该问题位于 wan/triton_kernels.py 中的 int8_quantize_kernel,大约在第 29-31 行,±0.5 的舍入偏移在相加之前就被转换为 int8,因此变成了 0。请阅读周围的内核代码,看看 x_scale 和存储掩码是如何使用的,然后检查输出是否被限制在 [-127, 127] 范围内。完成标准是:在转换为 int8 之前以 float 形式加上偏移量,并且一个小测试在示例输入上将内核输出与“向远离零方向四舍五入(round-half-away-from-zero)”的结果进行比较且一致。
由索引模型根据 Issue 内容生成。
描述
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.7k
- 派生
- 285
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
SkyworkAI/Matrix-Game 的其他 Issue
-
Replace deprecated v2.ToTensor() in Matrix-Game-2/inference.py with v2.ToImage() + v2.ToDtype(scale=True)可能已有人在做 @xyf5432 于 58 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 90/100
SkyworkAI/Matrix-Game#82 ·
-
难度 1/5 1 小时以内 新手友好度 88/100
SkyworkAI/Matrix-Game#80 ·
-
run logic error when finish可能已有人在做 @Arison591 于 95 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 88/100
SkyworkAI/Matrix-Game#77 ·
-
难度 1/5 1 小时以内 新手友好度 20/100
SkyworkAI/Matrix-Game#93 ·
-
难度 4/5 3-5 天 新手友好度 25/100
SkyworkAI/Matrix-Game#92 ·
查看 SkyworkAI/Matrix-Game 的全部 Issue
相似的 Issue
-
wr.dynamodb.read_items returns [{}] for a single partition value that does not exist可能已有人在做 @auraseb 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
aws/aws-sdk-pandas#3520 ·
维护者通常 2 天内回复
-
requires triage typing
难度 2/5 1-3 小时 新手友好度 78/100
sqlalchemy/sqlalchemy#13704 ·
维护者通常 1 天内回复
-
Edit tool converts CRLF files to LF可能已有人在做 @RaphaelFakhri 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
huggingface/tau#774 ·
维护者通常 1 天内回复
-
show ignores the row limit when a column or table name contains "limit"可能已有人在做 @RaphaelFakhri 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 67/100
linebender/resvg#1179 · 1 条评论 ·
维护者通常 2 天内回复