Skip to content

Commit d69c7c4

Browse files
fix(model): reject CP>1 in Gemma4DenseProvider with a clear error (#5895)
Signed-off-by: dafu-wu <wuchengyi2006@163.com> Co-authored-by: gautham-kollu <gkollu@nvidia.com>
1 parent 44c871b commit d69c7c4

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

‎src/megatron/bridge/models/gemma/gemma4_provider.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,20 @@ def provide(
200200
if vp_stage is not None or getattr(self, "pipeline_model_parallel_size", 1) != 1:
201201
raise NotImplementedError("Gemma4DenseProvider currently supports PP=1 only.")
202202

203+
if getattr(self, "context_parallel_size", 1) != 1:
204+
# get_gemma4_layer_spec() builds the dense layer from LocalSpecProvider,
205+
# whose core_attention() is the non-TE DotProductAttention. That module
206+
# asserts context_parallel_size == 1, so CP fails deep inside layer
207+
# construction with "Context parallelism is only supported by
208+
# TEDotProductAttention! when instantiating Gemma4DenseSelfAttention".
209+
# Surface it here instead, next to the PP guard, so the message names the
210+
# provider and the knob to change.
211+
raise NotImplementedError(
212+
"Gemma4DenseProvider currently supports CP=1 only: its layer spec uses "
213+
"the local DotProductAttention, which does not implement context "
214+
"parallelism."
215+
)
216+
203217
return self.build(
204218
pre_process=True if pre_process is None else pre_process,
205219
post_process=True if post_process is None else post_process,

‎tests/unit_tests/models/gemma/test_gemma4_provider.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ def test_provide_rejects_pipeline_parallel(self, provider):
142142
with pytest.raises(NotImplementedError, match="PP=1"):
143143
provider.provide()
144144

145+
def test_provide_rejects_context_parallel(self, provider):
146+
provider.context_parallel_size = 2
147+
with pytest.raises(NotImplementedError, match="CP=1"):
148+
provider.provide()
149+
145150
def test_provide_rejects_virtual_pipeline_stage(self, provider):
146151
with pytest.raises(NotImplementedError, match="PP=1"):
147152
provider.provide(vp_stage=0)

0 commit comments

Comments
 (0)