Skip to content

Commit 3cde52e

Browse files
committed
clean
1 parent 2ef0e26 commit 3cde52e

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

torchtitan/experiments/llama4/infra/parallelize.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,17 @@ def apply_compile(model: nn.Module):
4040
torch._dynamo.config.fail_on_recompile_limit_hit = True
4141
for layer_id, transformer_block in model.layers.named_children():
4242
if transformer_block.moe_enabled:
43-
# compile the experts directly which can be wrapped by fsdp
4443
moe = transformer_block.moe
45-
46-
# transformer_block.moe.experts = torch.compile(transformer_block.moe.experts, fullgraph=True))
44+
# Individually compile modules to keep fullgraph=True on FSDP wrapped experts
4745
moe.experts = torch.compile(moe.experts, fullgraph=True)
48-
moe.router = torch.compile(moe.router, fullgraph=True)
4946
moe.shared_expert = torch.compile(moe.shared_expert, fullgraph=True)
47+
48+
# Separately compile the code around the FSDP wrapped experts
49+
moe.router = torch.compile(moe.router, fullgraph=True)
5050
else:
5151
transformer_block = torch.compile(transformer_block, fullgraph=True)
5252
model.layers.register_module(layer_id, transformer_block)
5353

54-
# def _compile_child(parent:nn.Module, child_name: str, child: nn.Module):
55-
# parent.register_module(child_name, torch.compile(child, fullgraph=True))
56-
57-
# torch._dynamo.config.fail_on_recompile_limit_hit = True
58-
# for layer_id, transformer_block in model.layers.named_children():
59-
# if transformer_block.moe_enabled:
60-
# # compile the experts directly which can be wrapped by fsdp
61-
# moe = transformer_block.moe
62-
# # for submod_id, submod in moe.named_children():
63-
# # _compile_child(moe, submod_id, submod)
64-
# else:
65-
# _compile_child(transformer_block, layer_id, transformer_block)
66-
6754
logger.info("Compiling each TransformerBlock with torch.compile")
6855

6956

0 commit comments

Comments
 (0)