Skip to content
Open
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
62 changes: 35 additions & 27 deletions examples/models/llama/static_attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,38 +812,46 @@ def __init__(
[StaticVCache(layer_id, i) for i in range(self.n_kv_heads)]
)
else:
self.wqs = nn.ModuleList(
[
nn.Linear(
self.dim,
self.head_dim * self.n_heads,
bias=self.attention_qkv_bias,
)
]
)
self.wks = nn.ModuleList(
[
nn.Linear(
self.dim,
self.head_dim * self.n_kv_heads,
bias=self.attention_qkv_bias,
)
]
)
self.wvs = nn.ModuleList(
[
nn.Linear(
self.dim,
self.head_dim * self.n_kv_heads,
bias=self.attention_qkv_bias,
has_lora = config.target_modules is not None
_PROJ_TARGET = {
"wqs": ("q_proj", self.dim, self.head_dim * self.n_heads),
"wks": ("k_proj", self.dim, self.head_dim * self.n_kv_heads),
"wvs": ("v_proj", self.dim, self.head_dim * self.n_kv_heads),
}
for attr, (target, in_dim, out_dim) in _PROJ_TARGET.items():
if has_lora and target in config.target_modules:
proj = LoRALinear(
in_dim=in_dim,
out_dim=out_dim,
rank=config.r,
alpha=config.lora_alpha,
use_bias=self.attention_qkv_bias,
)
Comment on lines +815 to 829
Copy link

Copilot AI Mar 19, 2026

Choose a reason for hiding this comment

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

When config.target_modules is set but config.r and/or config.lora_alpha are left as None (both are Optional in ModelArgs), this path will attempt to construct LoRALinear(rank=None, alpha=None) and fail with a low-signal TypeError. Consider adding an explicit validation (ValueError with a clear message) before creating any LoRALinear modules, similar to LoRAFeedForward.

Copilot uses AI. Check for mistakes.
]
)
else:
proj = nn.Linear(in_dim, out_dim, bias=self.attention_qkv_bias)
setattr(self, attr, nn.ModuleList([proj]))

Comment on lines +815 to 833
Copy link

Copilot AI Mar 19, 2026

Choose a reason for hiding this comment

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

New behavior is introduced here (direct StaticAttention(..., split_mha=False) now conditionally builds LoRALinear based on config.target_modules), but existing tests in test_static_attention.py only exercise LoRA via from_attention_mha. Please add a unit test that directly constructs StaticAttention with split_mha=False and target_modules set, and asserts the expected projection types and a forward equivalence check.

Copilot uses AI. Check for mistakes.
self.k_caches = nn.ModuleList([StaticKCache(layer_id, 0)])
self.v_caches = nn.ModuleList([StaticVCache(layer_id, 0)])

self.wo = nn.Linear(self.n_heads * self.head_dim, self.dim, bias=False)
wo_use_lora = (
not self.split_mha
and config.target_modules is not None
and (
"output_proj" in config.target_modules
or "o_proj" in config.target_modules
)
)
if wo_use_lora:
self.wo = LoRALinear(
in_dim=self.n_heads * self.head_dim,
out_dim=self.dim,
rank=config.r,
alpha=config.lora_alpha,
use_bias=False,
)
else:
self.wo = nn.Linear(self.n_heads * self.head_dim, self.dim, bias=False)
self.rope = _Rope(rope.params)
self.layer_id = layer_id

Expand Down
Loading