Skip to content

Add Initial Compile for Llama 3.2 11B: Decoder TransformerSelfAttentionLayer, TransformerCrossAttentionLayer #1287

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

Merged
merged 1 commit into from
Oct 10, 2024
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