Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
15 changes: 10 additions & 5 deletions deepspeed/runtime/sequence_parallel/ulysses_sp.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,14 +491,19 @@ def register_with_transformers(
local_seq_length = seq_length // mpu.get_sequence_parallel_world_size()
global_seq_length = seq_length

arch_cfg = hf_model_config.get_text_config()

uattn = UlyssesSPAttentionHF(
attn=core_attn_function,
batch_size=micro_batch_size,
attn_head_count=hf_model_config.num_attention_heads,
attn_head_size=getattr(hf_model_config, "head_dim",
hf_model_config.hidden_size // hf_model_config.num_attention_heads),
kv_head_count=hf_model_config.num_key_value_heads,
num_hidden_layers=hf_model_config.num_hidden_layers,
attn_head_count=arch_cfg.num_attention_heads,
attn_head_size=getattr(
arch_cfg,
"head_dim",
arch_cfg.hidden_size // arch_cfg.num_attention_heads,
),
kv_head_count=arch_cfg.num_key_value_heads,
num_hidden_layers=arch_cfg.num_hidden_layers,
process_group=mpu.get_sequence_parallel_group(),
seq_length_is_variable=seq_length_is_variable,
local_seq_length=local_seq_length,
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/multimodal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# SPDX-License-Identifier: Apache-2.0
# DeepSpeed Team
27 changes: 27 additions & 0 deletions tests/unit/multimodal/test_gemma4_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SPDX-License-Identifier: Apache-2.0
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@delock please move: tests/unit/multimodal -> tests/unit/v1/multimodal

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

CI only targets tests/unit/v1

# DeepSpeed Team

from transformers import Gemma4Config
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Guard Gemma4Config import by transformers version

This module-level import makes test collection fail on environments that satisfy DeepSpeed’s declared minimum (transformers>=4.51.3) but do not yet include Gemma4Config (introduced much later), because pytest errors before any skip logic can run. In those setups, unrelated unit test runs that discover tests/unit/multimodal will fail at import time instead of executing normally, so this should be wrapped in a version gate or pytest.importorskip inside the test.

Useful? React with 👍 / 👎.



def test_gemma4_text_config_fallback():
config = Gemma4Config()
assert not hasattr(config, 'num_attention_heads'), \
"Gemma4Config top-level should not have num_attention_heads"
arch_cfg = config.get_text_config()
assert hasattr(arch_cfg, 'num_attention_heads')
assert arch_cfg.num_attention_heads > 0
assert hasattr(arch_cfg, 'num_key_value_heads')
assert arch_cfg.num_key_value_heads > 0
assert hasattr(arch_cfg, 'num_hidden_layers')
assert arch_cfg.num_hidden_layers > 0
assert hasattr(arch_cfg, 'hidden_size')
assert arch_cfg.hidden_size > 0


def test_gemma4_text_config_matches_text_config():
config = Gemma4Config()
arch_cfg = config.get_text_config()
assert arch_cfg is config.text_config
assert arch_cfg.num_attention_heads == config.text_config.num_attention_heads
assert arch_cfg.num_key_value_heads == config.text_config.num_key_value_heads
Loading