Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions torchtitan/experiments/compiler_toolkit/deepseek_v3/parallelize.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
from torch._guards import tracing

from torch.distributed.tensor import DTensor, Replicate

from torch.fx.traceback import annotate_fn
from torchtitan.config import JobConfig
from torchtitan.distributed import ParallelDims
from torchtitan.distributed.expert_parallel import ExpertParallel

from torchtitan.experiments.compiler_toolkit.graph_utils import export_joint
from torchtitan.experiments.simple_fsdp.deepseek_v3.parallelize import (
parallelize_deepseekv3 as simple_fsdp_parallelize_deepseekv3,
)
from torchtitan.models.moe.moe import MoE
from torchtitan.tools.logging import logger


Expand Down Expand Up @@ -128,12 +132,25 @@ def wrapper_fn(args):
return wrapper_fn


def annotate_model() -> None:
# annotate the MoE with dispatch, compute and combine
ExpertParallel._token_dispatch = annotate_fn({"EP": "dispatch"})(
ExpertParallel._token_dispatch
)
ExpertParallel._token_combine = annotate_fn({"EP": "combine"})(
ExpertParallel._token_combine
)
MoE.forward = annotate_fn({"EP": "compute"})(MoE.forward)


def parallelize_deepseekv3(
model: nn.Module,
parallel_dims: ParallelDims,
job_config: JobConfig,
) -> CompiledModule:

annotate_model()

# Diable torch.compile over the model in the compiler toolkit style workflow
with disable_compile(job_config):
model = simple_fsdp_parallelize_deepseekv3(model, parallel_dims, job_config)
Expand Down