执行摘要
修复 --save-hf 的 HuggingFace 权重转换逻辑
修复 --save-hf 功能,确保 HuggingFace 权重转换正确性,特别是对 SGLang 兼容性至关重要的 q_a_proj 与 kv_a_proj 配对。
值得合并,修复了明显 bug。建议同步检视相关测试覆盖。
该 PR 无 review 评论。
修复 --save-hf 功能,确保 HuggingFace 权重转换正确性,特别是对 SGLang 兼容性至关重要的 q_a_proj 与 kv_a_proj 配对。
值得合并,修复了明显 bug。建议同步检视相关测试覆盖。
该 PR 无 review 评论。
slime/backends/megatron_utils/hf_checkpoint_saver.py 中 save_hf_model_direct_to_path 函数,调整 should_convert_chunk 参数从 is_writer_rank and idx % num_save_nodes == save_node_rank 改为仅 is_writer_rank,使得每个 writer 节点都处理所有 chunk。| 文件 | 模块 | 状态 | 重要度 |
|---|---|---|---|
slime/backends/megatron_utils/hf_checkpoint_saver.py |
后端 | modified | 5.67 |
slime/backends/megatron_utils/hf_checkpoint_saver.py
core-logic
核心变更文件,修复 HuggingFace 检查点保存时权重转换 chunk 过滤逻辑
# slime/backends/megatron_utils/hf_checkpoint_saver.py
# 在 save_hf_model_direct_to_path 函数中,原先是:
# should_convert_chunk=lambda idx: is_writer_rank and idx % num_save_nodes == save_node_rank
# 现在改为:
should_convert_chunk=lambda _idx: is_writer_rank, # 所有 writer 处理所有 chunk
# 原因说明(代码内注释):
# Megatron-to-HF conversion is stateful for some parameters. For
# example, q_a_proj and kv_a_proj can land in adjacent chunks but
# must be emitted together for SGLang compatibility. Every node
# writer therefore has to observe every chunk so that pairs can
# cross chunk boundaries. Writers still only persist their
# modulo-assigned shards below; non-writer ranks skip conversion.
当前评论区没有形成足够清晰的争议点或结论,后续有更多讨论时会体现在这里。
风险较低,但需注意:所有 writer 节点现在都执行转换,可能小幅增加 CPU 开销;但持久化写操作仍按取模分片,对磁盘写入无影响。
影响范围较小,仅影响 --save-hf 路径,修复 HuggingFace 检查点保存的正确性。对 SGLang 部署兼容性有正面影响。
当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。
参与讨论