Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion torchtitan/models/deepseek_v3/infra/parallelize.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def parallelize_deepseekv3(
)

if model_compile_enabled:
apply_compile(model, job_config.compile)
apply_compile(model, job_config.compile, job_config.activation_checkpoint)

dp_mesh: DeviceMesh | None = None
if parallel_dims.fsdp_enabled or parallel_dims.ep_enabled:
Expand Down
17 changes: 14 additions & 3 deletions torchtitan/models/llama4/infra/parallelize.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
SequenceParallel,
)
from torchtitan.config import JobConfig, TORCH_DTYPE_MAP
from torchtitan.config.job_config import Compile as CompileConfig
from torchtitan.config.job_config import (
ActivationCheckpoint as ACConfig,
Compile as CompileConfig,
)
from torchtitan.distributed import NoParallel, ParallelDims
from torchtitan.distributed.activation_checkpoint import apply_ac

Expand Down Expand Up @@ -129,7 +132,7 @@ def parallelize_llama(

# turn on per-TransformerBlock compile after AC wrapping and before FSDP
if model_compile_enabled:
apply_compile(model, job_config.compile)
apply_compile(model, job_config.compile, job_config.activation_checkpoint)

dp_mesh: DeviceMesh | None = None
if parallel_dims.fsdp_enabled or parallel_dims.ep_enabled:
Expand Down Expand Up @@ -506,11 +509,19 @@ def apply_moe_ep_tp(
)


def apply_compile(model: nn.Module, compile_config: CompileConfig):
def apply_compile(model: nn.Module, compile_config: CompileConfig, ac_config: ACConfig):
"""
Apply torch.compile to each TransformerBlock, which makes compilation efficient due to
repeated structure. Alternatively one can compile the whole model (after applying DP).
"""

if ac_config.mode == "selective":
logger.warning(
"Compile + Selective Activation Checkpointing is not yet supported for MoE models, "
"please use Full Activation Checkpointing instead. Turning off Compile."
)
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just error out?


# NOTE: This flag is needed for torch.compile to avoid graph breaking on dynamic shapes in token-choice MoE
# but it is experimental.
torch._dynamo.config.capture_scalar_outputs = True
Expand Down
2 changes: 1 addition & 1 deletion torchtitan/models/qwen3/infra/parallelize.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def parallelize_qwen3(

# turn on per-TransformerBlock compile after AC wrapping and before FSDP
if model_compile_enabled:
apply_compile(model, job_config.compile)
apply_compile(model, job_config.compile, job_config.activation_checkpoint)

if parallel_dims.fsdp_enabled:
# apply FSDP or HSDP, potentially with Context Parallel
Expand Down
Loading