Skip to content

Fix static_llama to read some previously hardcoded options from ModelArgs #8846

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
Mar 3, 2025
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
8 changes: 5 additions & 3 deletions examples/qualcomm/oss_scripts/llama/model/static_llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, config: ModelArgs, output_new_cache_only=False):
super().__init__()
self.dim = config.dim
self.n_heads = config.n_heads
self.head_dim = config.dim // config.n_heads
self.head_dim = config.head_dim
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I miss something, isn't head_dim the same as dim / n_heads?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not necessarily, it can be anything, it's internal to the attention, the wo layer make sure the output of the attention has size dim.

self.n_kv_heads = config.n_kv_heads
self.num_key_value_groups = config.n_heads // self.n_kv_heads
self.max_seq_len = config.max_seq_len
Expand Down Expand Up @@ -304,7 +304,7 @@ def __init__(
):
super().__init__()
self.dim = config.dim
self.head_dim = config.dim // config.n_heads
self.head_dim = config.head_dim
self.max_batch_size = config.max_batch_size
self.max_seq_len = config.max_seq_len
self.n_heads = config.n_heads
Expand All @@ -328,9 +328,11 @@ def __init__(
self.output = nn.Linear(config.dim, config.vocab_size, bias=False)
self.tok_embeddings = nn.Embedding(config.vocab_size, config.dim)
freqs_cos, freqs_sin = precompute_freqs_cis(
config.dim // config.n_heads,
config.head_dim,
config.max_seq_len,
config.rope_freq_base,
config.use_scaled_rope,
config.rope_scale_factor,
)
self.register_buffer("freqs_cos", freqs_cos, persistent=False)
self.register_buffer("freqs_sin", freqs_sin, persistent=False)
Expand Down
Loading