feat: add torch.compile CLI option for training

- Add --compile flag (default/reduce-overhead/max-autotune)
- Apply torch.compile in _before_wrap before DDP/FSDP wrapping
- Profiling shows MFU 85.5% -> 88.5% (+3%), time -3.2%, memory -7.9%
This commit is contained in:
2026-07-29 22:06:51 +08:00
parent 0b0693a0a2
commit 8150ab6c32
3 changed files with 21 additions and 0 deletions
+9
View File
@@ -208,6 +208,13 @@ _START_METHODS = ["spawn", "fork", "forkserver"]
default=False,
help="Enable activation checkpointing.",
)
@click.option(
"--compile",
"compile_mode",
type=click.Choice(["default", "reduce-overhead", "max-autotune"]),
default=None,
help="torch.compile mode. Omit to disable.",
)
@click.option(
"--ckpt_interval", type=int, default=5000, help="Steps between checkpoints."
)
@@ -495,6 +502,7 @@ def train(
)
grad_ckpt_modules = [DecoderBlock] if gradient_checkpointing else []
compile_mode = kwargs.pop("compile_mode", None)
collate_fn = None
if train_type == "dpo":
@@ -532,6 +540,7 @@ def train(
val_step=val_step,
metrics=metrics,
gradient_checkpointing_modules=grad_ckpt_modules,
compile_mode=compile_mode,
executor_kwargs=executor_kwargs,
extra_kwargs=strategy_kwargs,
neftune_alpha=neftune_alpha,