|
30 | 30 | WeightConversionTask, |
31 | 31 | _HFNameSuffixMapping, |
32 | 32 | ) |
33 | | -from megatron.bridge.models.conversion.param_mapping import split_qkv_weights |
| 33 | +from megatron.bridge.models.conversion.param_mapping import QKVMapping, split_qkv_weights |
34 | 34 | from megatron.bridge.models.hf_pretrained.causal_lm import PreTrainedCausalLM |
35 | 35 |
|
36 | 36 |
|
@@ -160,6 +160,31 @@ def megatron_to_hf(self, megatron_weights, megatron_module): |
160 | 160 |
|
161 | 161 |
|
162 | 162 | class TestFp8ParamExport: |
| 163 | + def test_build_export_fp8_tasks_rejects_unaligned_qkv_scale_blocks(self, monkeypatch): |
| 164 | + bridge = DummyBridge() |
| 165 | + global_name = "decoder.layers.0.self_attention.linear_qkv.weight" |
| 166 | + mapping = QKVMapping(global_name, "hf.q.weight", "hf.k.weight", "hf.v.weight") |
| 167 | + _patch_export_task_context( |
| 168 | + monkeypatch, |
| 169 | + bridge, |
| 170 | + global_name, |
| 171 | + registry_factory=lambda: MegatronMappingRegistry(mapping), |
| 172 | + detect_fp8=lambda *_a, **_k: {global_name: 128}, |
| 173 | + ) |
| 174 | + model = SimpleNamespace( |
| 175 | + config=SimpleNamespace( |
| 176 | + num_attention_heads=64, |
| 177 | + num_query_groups=8, |
| 178 | + hidden_size=2880, |
| 179 | + kv_channels=64, |
| 180 | + share_embeddings_and_output_weights=False, |
| 181 | + ), |
| 182 | + named_parameters=lambda: [], |
| 183 | + ) |
| 184 | + |
| 185 | + with pytest.raises(ValueError, match="QKV head size 64.*FP8 block size 128"): |
| 186 | + bridge.build_export_fp8_tasks(SimpleNamespace(state=SimpleNamespace(source=SimpleNamespace())), [model]) |
| 187 | + |
163 | 188 | @pytest.mark.parametrize( |
164 | 189 | "export_weight_dtype, expect_unquantized", |
165 | 190 | [("fp8", True), ("bf16", False)], |
|
0 commit comments