Skip to content

Commit 66b0105

Browse files
committed
Add Linen SPMD logical partition annotations for Qwen3 model sharding
1 parent 18c085c commit 66b0105

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/maxdiffusion/models/qwen3_flax.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,21 @@ def __call__(self, x):
8484
gate_proj = nn.Dense(
8585
self.config.intermediate_size,
8686
use_bias=False,
87+
kernel_init=nn.with_logical_partitioning(nn.initializers.lecun_normal(), ("embed", "mlp")),
8788
dtype=self.config.dtype,
8889
name="gate_proj",
8990
)
9091
up_proj = nn.Dense(
9192
self.config.intermediate_size,
9293
use_bias=False,
94+
kernel_init=nn.with_logical_partitioning(nn.initializers.lecun_normal(), ("embed", "mlp")),
9395
dtype=self.config.dtype,
9496
name="up_proj",
9597
)
9698
down_proj = nn.Dense(
9799
self.config.hidden_size,
98100
use_bias=False,
101+
kernel_init=nn.with_logical_partitioning(nn.initializers.lecun_normal(), ("mlp", "embed")),
99102
dtype=self.config.dtype,
100103
name="down_proj",
101104
)
@@ -172,24 +175,28 @@ def __call__(
172175
q_proj = nn.Dense(
173176
self.config.num_attention_heads * self.config.head_dim,
174177
use_bias=False,
178+
kernel_init=nn.with_logical_partitioning(nn.initializers.lecun_normal(), ("embed", "heads")),
175179
dtype=self.config.dtype,
176180
name="q_proj",
177181
)
178182
k_proj = nn.Dense(
179183
self.config.num_key_value_heads * self.config.head_dim,
180184
use_bias=False,
185+
kernel_init=nn.with_logical_partitioning(nn.initializers.lecun_normal(), ("embed", "heads")),
181186
dtype=self.config.dtype,
182187
name="k_proj",
183188
)
184189
v_proj = nn.Dense(
185190
self.config.num_key_value_heads * self.config.head_dim,
186191
use_bias=False,
192+
kernel_init=nn.with_logical_partitioning(nn.initializers.lecun_normal(), ("embed", "heads")),
187193
dtype=self.config.dtype,
188194
name="v_proj",
189195
)
190196
o_proj = nn.Dense(
191197
self.config.hidden_size,
192198
use_bias=False,
199+
kernel_init=nn.with_logical_partitioning(nn.initializers.lecun_normal(), ("heads", "embed")),
193200
dtype=self.config.dtype,
194201
name="o_proj",
195202
)
@@ -347,7 +354,9 @@ def __call__(
347354
embed_tokens = nn.Embed(
348355
num_embeddings=self.config.vocab_size,
349356
features=self.config.hidden_size,
350-
embedding_init=nn.initializers.normal(stddev=self.config.hidden_size**-0.5),
357+
embedding_init=nn.with_logical_partitioning(
358+
nn.initializers.normal(stddev=self.config.hidden_size**-0.5), ("vocab", "embed")
359+
),
351360
dtype=self.config.dtype,
352361
name="embed_tokens",
353362
)

0 commit comments

Comments
 (0)