Skip to content

Commit 8ebe8d5

Browse files
committed
fix lint
1 parent 85e5350 commit 8ebe8d5

5 files changed

Lines changed: 29 additions & 51 deletions

File tree

recipes/lm/sft/scripts/run_qwen35_gsm8k.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/unit/models/qwen/test_qwen35_attention.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ class TestQwen35Attention:
2424
def test_forward_produces_correct_shape(self) -> None:
2525
"""Output shape is (B, S, model_dim)."""
2626
sdpa = NaiveSDPA(IdentityBias())
27-
attn = Qwen35Attention(
28-
model_dim=64, num_heads=4, sdpa=sdpa, head_dim=16
29-
)
27+
attn = Qwen35Attention(model_dim=64, num_heads=4, sdpa=sdpa, head_dim=16)
3028
attn = attn.to(device)
3129

3230
seqs = torch.randn(2, 8, 64, device=device)
@@ -41,9 +39,7 @@ def test_forward_produces_correct_shape(self) -> None:
4139
def test_output_gating_effect(self) -> None:
4240
"""When gate output is all zeros, attention output should be near zero."""
4341
sdpa = NaiveSDPA(IdentityBias())
44-
attn = Qwen35Attention(
45-
model_dim=64, num_heads=4, sdpa=sdpa, head_dim=16
46-
)
42+
attn = Qwen35Attention(model_dim=64, num_heads=4, sdpa=sdpa, head_dim=16)
4743
attn = attn.to(device)
4844

4945
seqs = torch.randn(1, 4, 64, device=device)
@@ -147,9 +143,7 @@ def test_qk_norm_applied(self) -> None:
147143
def test_incremental_kv_cache_matches_full_forward(self) -> None:
148144
"""Token-by-token decoding with KV cache produces the same logits as causal full-sequence forward."""
149145
sdpa = NaiveSDPA(CausalAttentionBias())
150-
attn = Qwen35Attention(
151-
model_dim=64, num_heads=4, sdpa=sdpa, head_dim=16
152-
)
146+
attn = Qwen35Attention(model_dim=64, num_heads=4, sdpa=sdpa, head_dim=16)
153147
attn = attn.to(device)
154148
attn.eval()
155149

tests/unit/models/qwen/test_qwen35_decoder_layer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ def test_full_attention_layer_forward(self) -> None:
2929
"""Full attention layer produces correct shape."""
3030
model_dim = 64
3131
sdpa = NaiveSDPA(IdentityBias())
32-
self_attn = Qwen35Attention(
33-
model_dim, num_heads=4, sdpa=sdpa, head_dim=16
34-
)
32+
self_attn = Qwen35Attention(model_dim, num_heads=4, sdpa=sdpa, head_dim=16)
3533
ffn = GLUFeedForwardNetwork(model_dim, 128, bias=False, inner_dim_scale=1.0)
3634
layer = Qwen35DecoderLayer(
3735
"full_attention",

tests/unit/models/qwen/test_qwen35_interop.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ def test_rmsnorm_weight_conversion(self) -> None:
8787
hf_state_dict[f"model.layers.{i}.input_layernorm.weight"] = torch.zeros(
8888
config.model_dim
8989
)
90-
hf_state_dict[
91-
f"model.layers.{i}.post_attention_layernorm.weight"
92-
] = torch.zeros(config.model_dim)
90+
hf_state_dict[f"model.layers.{i}.post_attention_layernorm.weight"] = (
91+
torch.zeros(config.model_dim)
92+
)
9393
hf_state_dict["model.norm.weight"] = torch.zeros(config.model_dim)
9494
hf_state_dict["model.embed_tokens.weight"] = torch.zeros(
9595
config.vocab_size, config.model_dim
@@ -112,9 +112,7 @@ def test_gdn_norm_weight_not_converted(self) -> None:
112112
config = self._make_small_config()
113113

114114
# Simulate HF state dict with GDN norm weight
115-
hf_state_dict: dict[str, object] = {
116-
"model.embed_tokens.weight": torch.zeros(1)
117-
}
115+
hf_state_dict: dict[str, object] = {"model.embed_tokens.weight": torch.zeros(1)}
118116
hf_state_dict["model.layers.0.linear_attn.norm.weight"] = (
119117
torch.ones(config.linear_value_head_dim) * 0.5
120118
)
@@ -264,7 +262,13 @@ def test_rmsnorm_weight_reversed(self) -> None:
264262

265263
# HF weights should be 0.0 (1.0 - 1.0)
266264
for key in hg_state_dict:
267-
if key.endswith(("input_layernorm.weight", "post_attention_layernorm.weight", "model.norm.weight")):
265+
if key.endswith(
266+
(
267+
"input_layernorm.weight",
268+
"post_attention_layernorm.weight",
269+
"model.norm.weight",
270+
)
271+
):
268272
weight = hg_state_dict[key]
269273
assert isinstance(weight, torch.Tensor)
270274
assert_close(weight, torch.zeros_like(weight))
@@ -341,7 +345,10 @@ def test_to_hg_config(self) -> None:
341345
assert data["num_experts"] == config.num_experts
342346
assert data["num_experts_per_tok"] == config.num_experts_per_tok
343347
assert data["moe_intermediate_size"] == config.moe_intermediate_size
344-
assert data["shared_expert_intermediate_size"] == config.shared_expert_intermediate_size
348+
assert (
349+
data["shared_expert_intermediate_size"]
350+
== config.shared_expert_intermediate_size
351+
)
345352
assert data["router_aux_loss_coef"] == config.router_aux_loss_coef
346353

347354
def test_state_dict_round_trip(self) -> None:
@@ -441,9 +448,9 @@ def test_visual_and_mtp_keys_filtered(self) -> None:
441448
}
442449
result = convert_qwen35_state_dict(dict(state_dict), config)
443450
for key in result:
444-
assert not key.startswith(("model.visual.", "mtp.")), (
445-
f"Unexpected key not filtered: {key}"
446-
)
451+
assert not key.startswith(
452+
("model.visual.", "mtp.")
453+
), f"Unexpected key not filtered: {key}"
447454

448455
def test_text_only_format_still_works(self) -> None:
449456
"""model.layers.* (text-only format) is still handled correctly."""
@@ -475,7 +482,7 @@ def test_end_to_end_vl_checkpoint(self) -> None:
475482
vl_state_dict: dict[str, object] = {}
476483
for k, v in hg_state_dict.items():
477484
if k.startswith("model."):
478-
vl_state_dict["model.language_model." + k[len("model."):]] = v
485+
vl_state_dict["model.language_model." + k[len("model.") :]] = v
479486
else:
480487
vl_state_dict[k] = v
481488
# Add visual/mtp keys

tests/unit/models/qwen/test_qwen35_moe.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def test_logits_are_raw_pre_softmax(self) -> None:
6464
class TestQwen35Experts:
6565
def test_forward_output_shape(self) -> None:
6666
"""Experts output shape matches input shape (T, D)."""
67-
experts = Qwen35Experts(
68-
num_experts=4, model_dim=32, expert_inner_dim=16
69-
).to(device)
67+
experts = Qwen35Experts(num_experts=4, model_dim=32, expert_inner_dim=16).to(
68+
device
69+
)
7070
torch.nn.init.normal_(experts.gate_up_proj, std=0.01)
7171
torch.nn.init.normal_(experts.down_proj, std=0.01)
7272

@@ -84,9 +84,9 @@ def test_forward_output_shape(self) -> None:
8484

8585
def test_weighted_output(self) -> None:
8686
"""Output is weighted by routing weights — zero weight means no contribution."""
87-
experts = Qwen35Experts(
88-
num_experts=4, model_dim=16, expert_inner_dim=8
89-
).to(device)
87+
experts = Qwen35Experts(num_experts=4, model_dim=16, expert_inner_dim=8).to(
88+
device
89+
)
9090
torch.nn.init.normal_(experts.gate_up_proj, std=0.01)
9191
torch.nn.init.normal_(experts.down_proj, std=0.01)
9292

0 commit comments

Comments
 (0)