Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.
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
19 changes: 16 additions & 3 deletions torchchat/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,9 +928,22 @@ def chat(
self.model_forward, fullgraph=True, **kwargs
)

self.decode_one_token = torch.compile(
self.decode_one_token, fullgraph=True, **kwargs
)
if self.model.config.model_type == ModelType.Flamingo:
# Based on https://github.com/pytorch/torchtune/blob/57ab583c84c4a9dcacac23aeabc81f2a679670fe/torchtune/training/_compile.py#L42-L52
from torchtune.modules import (
TransformerCrossAttentionLayer,
TransformerSelfAttentionLayer,
)
decoder = self.model.model.decoder
for m in reversed(list(decoder.modules())):
if isinstance(m, TransformerSelfAttentionLayer) or isinstance(
m, TransformerCrossAttentionLayer
):
m.compile()
else:
self.decode_one_token = torch.compile(
self.decode_one_token, fullgraph=True, **kwargs
)
Comment on lines +943 to +946

Choose a reason for hiding this comment

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

Out of curiosity, how long does it take to compile in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

About 2 Minutes for Llama 3.1


if generator_args.compile_prefill:
self.prefill = torch.compile(
Expand Down
Loading