执行摘要
清理 NPU 量化注释中的外部归属引用
文档性后续清理,使注释直接描述 SGLang 实现,保持术语自包含,避免外部项目引用,便于维护和理解。
值得快速回顾,作为文档清理的示例,但无需深入阅读。可参考其清理外部归属的方法,保持代码注释自包含。
reviewer ping1jing2 在评论中指出"只是注释更新,无需重新运行 CI",且已批准该 PR,无其他讨论。
文档性后续清理,使注释直接描述 SGLang 实现,保持术语自包含,避免外部项目引用,便于维护和理解。
值得快速回顾,作为文档清理的示例,但无需深入阅读。可参考其清理外部归属的方法,保持代码注释自包含。
reviewer ping1jing2 在评论中指出"只是注释更新,无需重新运行 CI",且已批准该 PR,无其他讨论。
python/sglang/srt/hardware_backend/npu/quantization/linear_method_npu.py:删除注释与 docstring 中对 vllm-ascend 的引用,改写为直接描述 SGLang 的布局与行为。python/sglang/srt/layers/quantization/modelslim/schemes/modelslim_mxfp4_w4a8.py:移除 docstring 中对 vllm-ascend 方法的引用。| 文件 | 模块 | 状态 | 重要度 |
|---|---|---|---|
python/sglang/srt/hardware_backend/npu/quantization/linear_method_npu.py |
量化实现 | modified | 4.84 |
python/sglang/srt/layers/quantization/modelslim/schemes/modelslim_mxfp4_w4a8.py |
量化方案 | modified | 3.8 |
python/sglang/srt/hardware_backend/npu/quantization/linear_method_npu.py
core-logic
核心 NPU 量化实现,注释和 docstring 中移除了 vllm-ascend 引用,保留关键实现细节。
# 在线路径:在加载时将 FP16/BF16 权重量化到 MXFP8。
if weight.dtype not in (torch.float16, torch.bfloat16):
logger.warning(...)
weight = weight.to(torch.bfloat16)
# 将权重移至 NPU(如果 CPU offload 将其移回 CPU)。
if not weight.is_npu:
weight = weight.to(f"npu:{torch.npu.current_device()}")
# 在线 MXFP8 权重量化(block_size=32)。
# qw: [out, in] float8_e4m3fn, w_scale: [out, in//64, 2] uint8。
qw, w_scale = torch.ops.npu.npu_dynamic_mx_quant(
weight, dst_type=torch.float8_e4m3fn
)
layer.weight = Parameter(qw.transpose(0, 1), requires_grad=False)
layer.weight_scale_inv = Parameter(
w_scale.transpose(0, 1), requires_grad=False
)
# 两条路径都产生 weight [in, out] 和 weight_scale_inv [in//64, out, 2] 作为
# strided transpose 视图 —— 不要调用 .contiguous()。matmul 归约循环按输出列扫描
# in 维;[out, in] 行主序源通过转置视图为该扫描提供 stride-1 访问,
# 匹配 msmodelslim 的离线布局。调用 .contiguous() 会将物理顺序重排为
# [in, out] 行主序,使内循环 stride 等于 out,降低 HBM 带宽。
ping1jing2 评论 "just comments update, no need to rerun CI",认为不需要重新运行 CI。
结论:决定不重新运行 CI · 已解决
风险极低,仅修改注释和 docstring,不影响任何代码逻辑、配置或 API。但需注意,docstring 可能被自动文档工具提取,修改后需确认文档措辞准确。
对用户和系统无任何功能影响,仅改善代码可读性和可维护性。对团队而言,减少了对外部项目(vllm-ascend)的引用,增强了 SGLang 实现的自包含性。
当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。
参与讨论