|
19 | 19 | import pytest |
20 | 20 | import torch |
21 | 21 | import torch.nn.functional as F |
| 22 | +from megatron.core.transformer.enums import AttnBackend |
22 | 23 |
|
23 | 24 | from megatron.bridge.models.gpt_provider import GPTModelProvider |
24 | 25 | from megatron.bridge.models.hybrid.hybrid_provider import HybridModelProvider |
@@ -111,6 +112,19 @@ class DenseHybridSmokeModelProvider(HybridModelProvider): |
111 | 112 | gradient_accumulation_fusion: bool = False |
112 | 113 |
|
113 | 114 |
|
| 115 | +@dataclass |
| 116 | +class MLAMoEHybridSmokeModelProvider(HybridModelProvider): |
| 117 | + """Small MLA/MoE HybridModel configuration for the MFSDP V2 EP smoke test.""" |
| 118 | + |
| 119 | + attention_backend: AttnBackend = AttnBackend.auto |
| 120 | + seq_length: int = 128 |
| 121 | + hidden_size: int = 128 |
| 122 | + multi_latent_attention: bool = True |
| 123 | + hybrid_layer_pattern: str = "+E" |
| 124 | + num_moe_experts: int = 4 |
| 125 | + expert_model_parallel_size: int = 2 |
| 126 | + |
| 127 | + |
114 | 128 | def create_fsdp_model_config(seq_length: int, bf16: bool = True, **kwargs) -> Llama3FSDPTestModelProvider: |
115 | 129 | """Create a standardized FSDP model configuration.""" |
116 | 130 | base_config = { |
@@ -427,6 +441,23 @@ def test_fsdp_v2_dense_hybrid_pretrain_smoke(self): |
427 | 441 |
|
428 | 442 | torch.distributed.barrier() |
429 | 443 |
|
| 444 | + @pytest.mark.run_only_on("GPU") |
| 445 | + def test_fsdp_v2_mla_moe_ep2_pretrain_smoke(self): |
| 446 | + """Train a small MLA/MoE HybridModel with MFSDP V2 and EP=2.""" |
| 447 | + initialize_distributed() |
| 448 | + torch.distributed.barrier() |
| 449 | + |
| 450 | + cfg = create_fsdp_config_container( |
| 451 | + seq_length=128, |
| 452 | + train_iters=10, |
| 453 | + optimizer={"clip_grad": 0.0}, |
| 454 | + ) |
| 455 | + cfg.model = MLAMoEHybridSmokeModelProvider() |
| 456 | + cfg.ddp.megatron_fsdp_version = 2 |
| 457 | + |
| 458 | + pretrain(cfg, forward_step) |
| 459 | + torch.distributed.barrier() |
| 460 | + |
430 | 461 | @pytest.mark.run_only_on("GPU") |
431 | 462 | def test_fsdp_pretrain_save_resume(self, tmp_path): |
432 | 463 | """ |
|
0 commit comments