Closed
[refactor] 简化 DeepSeek-V4 并行化包装 #1291
hanboyouAdd on 20 days agoClosed at 17 days ago
[refactor] 简化 DeepSeek-V4 并行化包装 #1291
Closed
Total: 1 files changed+3-25
| @@ -81,26 +81,6 @@ def _dsv4_param_dtypes( | |||
| 81 | return overrides | 81 | return overrides |
| 82 | 82 | ||
| 83 | 83 | ||
| 84 | -def parallelize_deepseek_v4(model, **kwargs): | ||
| 85 | - """Apply upstream eager parallelization with DSV4 FP32 parameter policies.""" | ||
| 86 | - from torchtitan.models.base.model import BaseModel | ||
| 87 | - | ||
| 88 | - return BaseModel.parallelize(model, **kwargs) | ||
| 89 | - | ||
| 90 | - | ||
| 91 | -def annotate_deepseek_v4(model: GraphTrainerDeepSeekV4Model) -> None: | ||
| 92 | - """Attach annotations to FX graph nodes for DeepSeek V4. | ||
| 93 | - | ||
| 94 | - - Expert Parallel (EP) annotations: Tags "dispatch", "combine", and "compute" | ||
| 95 | - regions in MoE for debugging purposes. | ||
| 96 | - - Module FQN annotation: Tags each submodule's forward with its | ||
| 97 | - fully-qualified name for downstream passes (bucketing, SAC region | ||
| 98 | - boundaries, etc.). | ||
| 99 | - """ | ||
| 100 | - annotate_moe_ep_regions() | ||
| 101 | - annotate_module_fqns(model) | ||
| 102 | - | ||
| 103 | - | ||
| 104 | def parallelize_graph_trainer_deepseek_v4( | 84 | def parallelize_graph_trainer_deepseek_v4( |
| 105 | model: GraphTrainerDeepSeekV4Model, | 85 | model: GraphTrainerDeepSeekV4Model, |
| 106 | *, | 86 | *, |
| @@ -125,7 +105,8 @@ def parallelize_graph_trainer_deepseek_v4( | |||
| 125 | "Context Parallel is not yet supported for DeepSeek V4 sparse attention in the GraphTrainer path." | 105 | "Context Parallel is not yet supported for DeepSeek V4 sparse attention in the GraphTrainer path." |
| 126 | ) | 106 | ) |
| 127 | 107 | ||
| 128 | - annotate_deepseek_v4(model) | 108 | + annotate_moe_ep_regions() |
| 109 | + annotate_module_fqns(model) | ||
| 129 | 110 | ||
| 130 | # SPMD declarations must be resolved even when every model-parallel axis is | 111 | # SPMD declarations must be resolved even when every model-parallel axis is |
| 131 | # singleton; the non-graph path applies the same unconditional lifecycle. | 112 | # singleton; the non-graph path applies the same unconditional lifecycle. |
| @@ -138,12 +119,9 @@ def parallelize_graph_trainer_deepseek_v4( | |||
| 138 | # pyrefly: ignore [bad-assignment] | 119 | # pyrefly: ignore [bad-assignment] |
| 139 | model = apply_simple_fsdp(model, parallelism_context=parallelism_context, training=training) | 120 | model = apply_simple_fsdp(model, parallelism_context=parallelism_context, training=training) |
| 140 | 121 | ||
| 141 | - # Apply compilation based on mode | 122 | + apply_graph_trainer_compile( |
| 142 | - # pyrefly: ignore [bad-assignment] | ||
| 143 | - model = apply_graph_trainer_compile( | ||
| 144 | model, | 123 | model, |
| 145 | compile_config=compile_config, | 124 | compile_config=compile_config, |
| 146 | parallelism_context=parallelism_context, | 125 | parallelism_context=parallelism_context, |
| 147 | ) | 126 | ) |
| 148 | - | ||
| 149 | return model | 127 | return model |