[New features] Add Fleet<->HF config export/import bridge (hf_export) - #1769
Conversation
Single source of truth for the Fleet<->open-source(HF) config.json bridge: naming map (FLEET_HF_FIELD_MAPPING / ROPE_SCALING_KEYMAP -> HF_EXPORT_RULES / HF_IMPORT_RULES) plus model-fact helpers (structural YaRN detection, rope_scaling pack/unpack, SWA/CSA window semantics, MTP-layer trimming, mHC injection). Pure Python, no paddle dependency; sibling of TransformerConfig.transform_rules. Consumed by the erniebot HF config export engine, which keeps only the export strategy (whitelist/blacklist) and I/O. Adds tests/single_card_tests/transformer/test_hf_export.py (30 cases). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
| 序号 | 位置 | 优先级 | 状态 |
|---|---|---|---|
| 1 | hf_export.py:36 | ✅ | |
| 2 | hf_export.py:59 | ✅ | |
| 3 | hf_export.py:66 | ✅ | |
| 4 | hf_export.py:271 | ✅ | |
| 5 | hf_export.py:301 | ✅ | |
| 6 | PR 标题 | ✅ | |
| 7 | hf_export.py:180 | ✅ |
|
|
||
| # rope_scaling structural map: HF nested key -> Fleet flat field name. | ||
| ROPE_SCALING_KEYMAP = { | ||
| "type": "rope_type", |
There was a problem hiding this comment.
当前提交已同时兼容 canonical rope_type 和旧版 type,并覆盖两者并存时的优先级,问题已解决。
| "params_dtype", | ||
| "torch_dtype", | ||
| lambda v: str(v).replace("paddle.", ""), | ||
| lambda v: f"paddle.{v}" |
There was a problem hiding this comment.
当前提交已将导入 dtype 规范化为 Paddle 可接受的不带前缀字符串,并补充对应测试,问题已解决。
| ( | ||
| "hidden_act", | ||
| "hidden_act", | ||
| lambda v: v.__name__ if callable(v) else v, |
There was a problem hiding this comment.
当前提交已显式识别 gelu_pytorch_tanh 的 functools.partial 形式,并覆盖导出规则,问题已解决。
| def is_swa_config(hf_config): | ||
| """Whether an HF config declares SWA-specific fields.""" | ||
| return any( | ||
| key in SWA_MARKER_HF_KEYS or key.startswith("swa_") for key in hf_config |
There was a problem hiding this comment.
当前提交已改为仅在 DSv4/压缩比例标记存在时按 CSA 重命名,标准 HF sliding_window 会保持原名,问题已解决。
| MTP_TRIM_KEYS = ( | ||
| "window_attn_skip_freq", | ||
| "csa_compress_ratios", | ||
| "compress_ratios", |
There was a problem hiding this comment.
当前提交已将 hybrid_layer_pattern 加入 MTP 裁剪键,并补充 HF 字段测试,问题已解决。
For dsv4_hybrid the RoPE mode is decided per layer, so a global rope_type="yarn" must not short-circuit -- HCA/CSA follow their per-type overrides (default YaRN unless forced to "rope"), MLA (-2) layers follow the global rope_type, and window layers stay plain RoPE. Add regression tests for the override / MLA / window combos.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1769 +/- ##
==========================================
Coverage ? 93.10%
==========================================
Files ? 1
Lines ? 116
Branches ? 33
==========================================
Hits ? 108
Misses ? 5
Partials ? 3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
✅ Cherry-pick successful! Created PR: #1782 |
PR Category
Execute Infrastructure
PR Types
New features
Description
Single source of truth for the Fleet<->open-source(HF) config.json bridge: naming map (FLEET_HF_FIELD_MAPPING / ROPE_SCALING_KEYMAP -> HF_EXPORT_RULES / HF_IMPORT_RULES) plus model-fact helpers (structural YaRN detection, rope_scaling pack/unpack, SWA/CSA window semantics, MTP-layer trimming, mHC injection).
Adds tests/single_card_tests/transformer/test_hf_export.py.
是否引起精度变化
否