Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT LAND] compile more modules #1938

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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 recipes/full_finetune_single_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ def train(self) -> None:
self._profiler.step()

self.epochs_run += 1
self.save_checkpoint(epoch=curr_epoch)
# self.save_checkpoint(epoch=curr_epoch)

self._profiler.stop()

Expand Down
1 change: 0 additions & 1 deletion torchtune/modules/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ def reset_caches(self):
for layer in self.layers:
layer.reset_cache()

@torch.compiler.disable
def chunked_output(self, last_hidden_state: torch.Tensor) -> List[torch.Tensor]:
"""
Apply output projection in chunks. This should be applied in conjunction with
Expand Down
11 changes: 11 additions & 0 deletions torchtune/training/_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def compile_model(
"""
backend = os.environ.get("TORCH_COMPILE_BACKEND", "inductor")
if isinstance(model, DeepFusionModel):
# TODO: compile encoder too. Make sure to compile decoder.norm, etc..
model = model.decoder
if torch_version_ge("2.5.0"):
if verbose:
Expand All @@ -50,6 +51,16 @@ def compile_model(
m, TransformerCrossAttentionLayer
):
m.compile(backend=backend)

if hasattr(model, "norm"):
model.norm.compile(backend=backend)

if hasattr(model, "chunked_output"):
model.chunked_output = torch.compile(model.chunked_output, backend=backend)

if hasattr(model, "token_embeddings"):
model.token_embeddings.compile(backend=backend)

else:
if verbose:
log.info(
Expand Down
Loading