Skip to content

[Fix] Gate HF export key remapping behind explicit --vllm flag#63

Merged
yubofredwang merged 2 commits intomainfrom
fix/convert-to-hf-native-export
Apr 6, 2026
Merged

[Fix] Gate HF export key remapping behind explicit --vllm flag#63
yubofredwang merged 2 commits intomainfrom
fix/convert-to-hf-native-export

Conversation

@yubofredwang
Copy link
Copy Markdown
Collaborator

Summary

  • preserve native TorchSpec checkpoint keys by default during HF export so sglang outputs keep midlayer.*
  • add an explicit --vllm flag to opt into the midlayer.* -> layers.0.* remap needed for vLLM-compatible exports
  • thread the export mode through both standard and vocab-pruned save paths

Test plan

  • python3 tools/convert_to_hf.py --help
  • python3 -m py_compile tools/convert_to_hf.py
  • manually regenerated iter_0014701_hf without --vllm and verified exported safetensors contained midlayer.* keys and no layers.0.* keys

Preserve native TorchSpec checkpoint keys by default so sglang exports keep midlayer-prefixed weights. Add an explicit --vllm option for the layers.0 remap path needed by vLLM-compatible exports.
Copilot AI review requested due to automatic review settings April 6, 2026 18:00
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 19d966a39a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +245 to +246
logger.info("Exporting native checkpoint keys")
return dict(tensors)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Gate Kimi layer-id config rewrite behind --vllm

When export_for_vllm is false, this new branch emits native midlayer.* weights, but the saved config is still rewritten by _fixup_export_config in both save paths, and that helper unconditionally increments eagle_aux_hidden_state_layer_ids for model_type == "kimi_k2" (a vLLM-specific adjustment per its comment). This leaves default/native exports with off-by-one aux-layer IDs in config.json, which can select wrong hidden-state layers for non-vLLM consumers despite using native keys.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the HuggingFace export tool to preserve TorchSpec-native checkpoint key names by default, and only apply the midlayer.* -> layers.0.* key remapping when explicitly exporting for vLLM.

Changes:

  • Added an explicit --vllm CLI flag to opt into vLLM-compatible key remapping during export.
  • Centralized tensor preparation behind _prepare_export_tensors() and threaded the export mode through both vocab-pruned and non-pruned save paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Only apply the Kimi K2 layer-id rewrite when exporting vLLM-compatible checkpoints so native sglang exports preserve the original config semantics alongside the original weight keys.
@yubofredwang yubofredwang merged commit 96452a4 into main Apr 6, 2026
1 check passed
@yubofredwang yubofredwang deleted the fix/convert-to-hf-native-export branch April 6, 2026 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants