|
39 | 39 | from megatron.bridge.utils.cuda_graph import clear_cuda_graph_modules, set_cuda_graph_modules |
40 | 40 |
|
41 | 41 |
|
| 42 | +def _enable_gdn_conv_fusion(model) -> None: |
| 43 | + """Enable the GatedDeltaNet pre-gated-delta-rule fusion on a Qwen3.5-VL model. |
| 44 | +
|
| 45 | + Fuses the pre-gated-delta-rule path (causal conv1d + QK L2-norm) into Triton |
| 46 | + kernels. Qwen3.5-VL runs 3 of every 4 layers as GDN -- 30 of 40 at 35B-A3B, |
| 47 | + 45 of 60 at 397B-A17B -- so the fused path covers most of the step. Measured |
| 48 | + +5.8% on 8x GB300 with real DataComp Energon (BF16, MBS4/GBS512, EP8, steps |
| 49 | + 101-150, n=50): 20332.0 -> 19214.8 ms/step, 297.0 -> 314.2 TFLOP/s/GPU. |
| 50 | +
|
| 51 | + Requires a Megatron-Core carrying ``gdn_pre_gated_delta_rule_fusion``. |
| 52 | + Assigning an unknown field on the model config does NOT raise -- it would |
| 53 | + silently create an unused attribute, leaving the recipe looking enabled |
| 54 | + while running unfused -- so the guard is deliberate. |
| 55 | + """ |
| 56 | + if hasattr(type(model), "gdn_pre_gated_delta_rule_fusion") or hasattr(model, "gdn_pre_gated_delta_rule_fusion"): |
| 57 | + model.gdn_pre_gated_delta_rule_fusion = True |
| 58 | + |
| 59 | + |
| 60 | +def _qwen35_vl_provider(hf_path: str): |
| 61 | + """Build the Qwen3.5/Qwen3.6-VL Megatron provider. |
| 62 | +
|
| 63 | + Construction only -- shared so the AutoBridge boilerplate is written once. |
| 64 | + Performance defaults are applied by the recipes, not here. |
| 65 | + """ |
| 66 | + return AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 67 | + |
| 68 | + |
42 | 69 | def _apply_qwen35_vl_35b_a3b_16gpu_h100_execution_config(cfg: ConfigContainer) -> None: |
43 | 70 | """Apply the measured 16-H100 execution policy for Qwen3.5/Qwen3.6-VL 35B-A3B.""" |
44 | 71 | cfg.model.tensor_model_parallel_size = 1 |
@@ -114,7 +141,8 @@ def qwen35_vl_9b_pretrain_4gpu_h100_bf16_mock_config() -> ConfigContainer: |
114 | 141 | cfg = _pretrain_common() |
115 | 142 |
|
116 | 143 | hf_path = "Qwen/Qwen3.5-9B" |
117 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 144 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 145 | + _enable_gdn_conv_fusion(cfg.model) |
118 | 146 | cfg.model.tensor_model_parallel_size = 4 |
119 | 147 | cfg.model.pipeline_model_parallel_size = 1 |
120 | 148 | cfg.model.pipeline_dtype = None |
@@ -162,7 +190,8 @@ def qwen35_vl_27b_pretrain_16gpu_h100_bf16_mock_config() -> ConfigContainer: |
162 | 190 | cfg = _pretrain_common() |
163 | 191 |
|
164 | 192 | hf_path = "Qwen/Qwen3.5-27B" |
165 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 193 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 194 | + _enable_gdn_conv_fusion(cfg.model) |
166 | 195 | cfg.model.tensor_model_parallel_size = 4 |
167 | 196 | cfg.model.pipeline_model_parallel_size = 4 |
168 | 197 | cfg.model.pipeline_dtype = torch.bfloat16 |
@@ -216,7 +245,8 @@ def qwen35_vl_35b_a3b_pretrain_8gpu_h100_bf16_mock_config() -> ConfigContainer: |
216 | 245 | cfg = _pretrain_common() |
217 | 246 |
|
218 | 247 | hf_path = "Qwen/Qwen3.5-35B-A3B" |
219 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 248 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 249 | + _enable_gdn_conv_fusion(cfg.model) |
220 | 250 | cfg.model.tensor_model_parallel_size = 4 |
221 | 251 | cfg.model.pipeline_model_parallel_size = 2 |
222 | 252 | cfg.model.pipeline_dtype = torch.bfloat16 |
@@ -334,7 +364,8 @@ def qwen35_vl_122b_a10b_pretrain_128gpu_h100_bf16_mock_config() -> ConfigContain |
334 | 364 | cfg = _pretrain_common() |
335 | 365 |
|
336 | 366 | hf_path = "Qwen/Qwen3.5-122B-A10B" |
337 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 367 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 368 | + _enable_gdn_conv_fusion(cfg.model) |
338 | 369 | cfg.model.tensor_model_parallel_size = 4 |
339 | 370 | cfg.model.pipeline_model_parallel_size = 8 |
340 | 371 | cfg.model.pipeline_dtype = torch.bfloat16 |
@@ -385,7 +416,8 @@ def qwen35_vl_397b_a17b_pretrain_512gpu_h100_bf16_mock_config() -> ConfigContain |
385 | 416 | cfg = _pretrain_common() |
386 | 417 |
|
387 | 418 | hf_path = "Qwen/Qwen3.5-397B-A17B" |
388 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 419 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 420 | + _enable_gdn_conv_fusion(cfg.model) |
389 | 421 | cfg.model.tensor_model_parallel_size = 4 |
390 | 422 | cfg.model.pipeline_model_parallel_size = 16 |
391 | 423 | cfg.model.pipeline_dtype = torch.bfloat16 |
@@ -450,7 +482,8 @@ def qwen35_vl_800m_sft_1gpu_h100_bf16_config() -> ConfigContainer: |
450 | 482 |
|
451 | 483 | # Model config |
452 | 484 | hf_path = "Qwen/Qwen3.5-0.8B" |
453 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 485 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 486 | + _enable_gdn_conv_fusion(cfg.model) |
454 | 487 | cfg.model.seq_length = 4096 |
455 | 488 |
|
456 | 489 | # Parallelism settings |
@@ -550,7 +583,8 @@ def qwen35_vl_2b_sft_1gpu_h100_bf16_config() -> ConfigContainer: |
550 | 583 |
|
551 | 584 | # Model config |
552 | 585 | hf_path = "Qwen/Qwen3.5-2B" |
553 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 586 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 587 | + _enable_gdn_conv_fusion(cfg.model) |
554 | 588 | cfg.model.seq_length = 4096 |
555 | 589 |
|
556 | 590 | # Parallelism settings |
@@ -650,7 +684,8 @@ def qwen35_vl_4b_sft_2gpu_h100_bf16_config() -> ConfigContainer: |
650 | 684 |
|
651 | 685 | # Model config |
652 | 686 | hf_path = "Qwen/Qwen3.5-4B" |
653 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 687 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 688 | + _enable_gdn_conv_fusion(cfg.model) |
654 | 689 | cfg.model.seq_length = 4096 |
655 | 690 |
|
656 | 691 | # Parallelism settings |
@@ -750,7 +785,8 @@ def qwen35_vl_9b_sft_4gpu_h100_bf16_config() -> ConfigContainer: |
750 | 785 |
|
751 | 786 | # Model config |
752 | 787 | hf_path = "Qwen/Qwen3.5-9B" |
753 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 788 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 789 | + _enable_gdn_conv_fusion(cfg.model) |
754 | 790 | cfg.model.seq_length = 4096 |
755 | 791 |
|
756 | 792 | # Parallelism settings |
@@ -848,7 +884,8 @@ def qwen35_vl_27b_sft_16gpu_h100_bf16_config() -> ConfigContainer: |
848 | 884 |
|
849 | 885 | # Model config |
850 | 886 | hf_path = "Qwen/Qwen3.5-27B" |
851 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 887 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 888 | + _enable_gdn_conv_fusion(cfg.model) |
852 | 889 | cfg.model.seq_length = 4096 |
853 | 890 |
|
854 | 891 | # Parallelism settings |
@@ -952,7 +989,8 @@ def _qwen35_vl_35b_a3b_sft_base_config() -> ConfigContainer: |
952 | 989 |
|
953 | 990 | # Model config |
954 | 991 | hf_path = "Qwen/Qwen3.5-35B-A3B" |
955 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 992 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 993 | + _enable_gdn_conv_fusion(cfg.model) |
956 | 994 | cfg.model.seq_length = 4096 |
957 | 995 |
|
958 | 996 | # Parallelism settings |
@@ -1161,7 +1199,8 @@ def qwen35_vl_35b_a3b_sft_2gpu_h100_bf16_fsdp_config() -> ConfigContainer: |
1161 | 1199 |
|
1162 | 1200 | # Model config |
1163 | 1201 | hf_path = "Qwen/Qwen3.5-35B-A3B" |
1164 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 1202 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 1203 | + _enable_gdn_conv_fusion(cfg.model) |
1165 | 1204 | cfg.model.seq_length = 4096 |
1166 | 1205 |
|
1167 | 1206 | # Parallelism settings |
@@ -1283,7 +1322,8 @@ def qwen35_vl_122b_a10b_sft_48gpu_h100_bf16_config() -> ConfigContainer: |
1283 | 1322 |
|
1284 | 1323 | # Model config |
1285 | 1324 | hf_path = "Qwen/Qwen3.5-122B-A10B" |
1286 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 1325 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 1326 | + _enable_gdn_conv_fusion(cfg.model) |
1287 | 1327 | cfg.model.seq_length = 4096 |
1288 | 1328 |
|
1289 | 1329 | # Parallelism settings |
@@ -1395,7 +1435,8 @@ def qwen35_vl_397b_a17b_sft_128gpu_h100_bf16_config() -> ConfigContainer: |
1395 | 1435 |
|
1396 | 1436 | # Model config |
1397 | 1437 | hf_path = "Qwen/Qwen3.5-397B-A17B" |
1398 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 1438 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 1439 | + _enable_gdn_conv_fusion(cfg.model) |
1399 | 1440 | cfg.model.seq_length = 4096 |
1400 | 1441 |
|
1401 | 1442 | # Parallelism settings |
@@ -1515,7 +1556,8 @@ def qwen35_vl_800m_peft_1gpu_h100_bf16_config( |
1515 | 1556 |
|
1516 | 1557 | # Model config |
1517 | 1558 | hf_path = "Qwen/Qwen3.5-0.8B" |
1518 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 1559 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 1560 | + _enable_gdn_conv_fusion(cfg.model) |
1519 | 1561 | cfg.model.seq_length = 4096 |
1520 | 1562 |
|
1521 | 1563 | # Parallelism settings |
@@ -1616,7 +1658,8 @@ def qwen35_vl_2b_peft_1gpu_h100_bf16_config( |
1616 | 1658 |
|
1617 | 1659 | # Model config |
1618 | 1660 | hf_path = "Qwen/Qwen3.5-2B" |
1619 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 1661 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 1662 | + _enable_gdn_conv_fusion(cfg.model) |
1620 | 1663 | cfg.model.seq_length = 4096 |
1621 | 1664 |
|
1622 | 1665 | # Parallelism settings |
@@ -1717,7 +1760,8 @@ def qwen35_vl_4b_peft_1gpu_h100_bf16_config( |
1717 | 1760 |
|
1718 | 1761 | # Model config |
1719 | 1762 | hf_path = "Qwen/Qwen3.5-4B" |
1720 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 1763 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 1764 | + _enable_gdn_conv_fusion(cfg.model) |
1721 | 1765 | cfg.model.seq_length = 4096 |
1722 | 1766 |
|
1723 | 1767 | # Parallelism settings |
@@ -1818,7 +1862,8 @@ def qwen35_vl_9b_peft_1gpu_h100_bf16_config( |
1818 | 1862 |
|
1819 | 1863 | # Model config |
1820 | 1864 | hf_path = "Qwen/Qwen3.5-9B" |
1821 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 1865 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 1866 | + _enable_gdn_conv_fusion(cfg.model) |
1822 | 1867 | cfg.model.seq_length = 4096 |
1823 | 1868 |
|
1824 | 1869 | # Parallelism settings |
@@ -1919,7 +1964,8 @@ def qwen35_vl_27b_peft_2gpu_h100_bf16_config( |
1919 | 1964 |
|
1920 | 1965 | # Model config |
1921 | 1966 | hf_path = "Qwen/Qwen3.5-27B" |
1922 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 1967 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 1968 | + _enable_gdn_conv_fusion(cfg.model) |
1923 | 1969 | cfg.model.seq_length = 4096 |
1924 | 1970 |
|
1925 | 1971 | # Parallelism settings |
@@ -2025,7 +2071,8 @@ def qwen35_vl_35b_a3b_peft_4gpu_h100_bf16_config( |
2025 | 2071 |
|
2026 | 2072 | # Model config |
2027 | 2073 | hf_path = "Qwen/Qwen3.5-35B-A3B" |
2028 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 2074 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 2075 | + _enable_gdn_conv_fusion(cfg.model) |
2029 | 2076 | cfg.model.seq_length = 4096 |
2030 | 2077 |
|
2031 | 2078 | # Parallelism settings |
@@ -2167,7 +2214,8 @@ def qwen35_vl_122b_a10b_peft_8gpu_h100_bf16_config( |
2167 | 2214 |
|
2168 | 2215 | # Model config |
2169 | 2216 | hf_path = "Qwen/Qwen3.5-122B-A10B" |
2170 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 2217 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 2218 | + _enable_gdn_conv_fusion(cfg.model) |
2171 | 2219 | cfg.model.seq_length = 4096 |
2172 | 2220 |
|
2173 | 2221 | # Parallelism settings |
@@ -2282,7 +2330,8 @@ def qwen35_vl_397b_a17b_peft_32gpu_h100_bf16_config( |
2282 | 2330 |
|
2283 | 2331 | # Model config |
2284 | 2332 | hf_path = "Qwen/Qwen3.5-397B-A17B" |
2285 | | - cfg.model = AutoBridge.from_hf_pretrained(hf_path).to_megatron_provider(load_weights=False) |
| 2333 | + cfg.model = _qwen35_vl_provider(hf_path) |
| 2334 | + _enable_gdn_conv_fusion(cfg.model) |
2286 | 2335 | cfg.model.seq_length = 4096 |
2287 | 2336 |
|
2288 | 2337 | # Parallelism settings |
|
0 commit comments