Skip to content

Commit d28698b

Browse files
committed
revert: remove FA4-only vision metadata changes
Signed-off-by: Ajay Balasa <abalasa@nvidia.com>
1 parent 36d03ce commit d28698b

6 files changed

Lines changed: 3 additions & 101 deletions

File tree

‎src/megatron/bridge/models/ernie_vl/modeling_ernie45_vl/vision_model.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def build_packed_seq_params(
267267
cu_seqlens = seqlens.cumsum(dim=0)
268268
cu_seqlens = F.pad(cu_seqlens, (1, 0), value=0).int()
269269

270-
max_seqlen_q = int(seqlens.max().item())
270+
max_seqlen_q = seqlens.max()
271271
return PackedSeqParams(
272272
cu_seqlens_q=cu_seqlens,
273273
cu_seqlens_kv=cu_seqlens,

‎src/megatron/bridge/models/qwen_vl/modelling_qwen3_vl/vision_model.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def build_packed_seq_params(
383383
cu_seqlens = seqlens.cumsum(dim=0)
384384
cu_seqlens = F.pad(cu_seqlens, (1, 0), value=0).int()
385385

386-
max_seqlen_q = int(seqlens.max().item())
386+
max_seqlen_q = seqlens.max()
387387
return PackedSeqParams(
388388
cu_seqlens_q=cu_seqlens,
389389
cu_seqlens_kv=cu_seqlens,

‎src/megatron/bridge/training/nemotron_omni_step.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def _build_vision_packed_seq_params(
158158
cu.append(cu[-1] + sl)
159159
device = imgs_sizes.device if torch.is_tensor(imgs_sizes) else torch.device("cpu")
160160
cu_tensor = torch.tensor(cu, dtype=torch.int32, device=device)
161-
max_len = max(seq_lens, default=0)
161+
max_len = torch.tensor(max(seq_lens) if seq_lens else 0, dtype=torch.int32, device=device)
162162
return PackedSeqParams(
163163
qkv_format="thd",
164164
cu_seqlens_q=cu_tensor,

‎tests/unit_tests/models/ernie_vl/test_ernie45_vl_bridge.py‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,6 @@
3434
MultiTypeMoeSubmodules,
3535
)
3636
from megatron.bridge.models.ernie_vl.modeling_ernie45_vl.model import ErnieMultimodalRotaryEmbedding
37-
from megatron.bridge.models.ernie_vl.modeling_ernie45_vl.vision_model import ErnieVLVisionModel
38-
39-
40-
@pytest.mark.unit
41-
@pytest.mark.parametrize(
42-
"grid,expected_boundaries,expected_max",
43-
[
44-
([[1, 2, 3]], [0, 6], 6),
45-
([[2, 2, 3], [1, 2, 4]], [0, 6, 12, 20], 8),
46-
],
47-
)
48-
def test_vision_packed_metadata_uses_integer_maxima(grid, expected_boundaries, expected_max):
49-
grid = torch.tensor(grid, dtype=torch.int64)
50-
51-
packed = ErnieVLVisionModel.build_packed_seq_params(None, grid)
52-
53-
assert packed.qkv_format == "thd"
54-
assert type(packed.max_seqlen_q) is int
55-
assert type(packed.max_seqlen_kv) is int
56-
assert packed.max_seqlen_q == packed.max_seqlen_kv == expected_max
57-
for boundaries in (packed.cu_seqlens_q, packed.cu_seqlens_kv):
58-
assert boundaries.tolist() == expected_boundaries
59-
assert boundaries.dtype == torch.int32
60-
assert boundaries.device == grid.device
6137

6238

6339
def _make_vision_config():

‎tests/unit_tests/models/qwen_vl/modelling_qwen3_vl/test_vision_model.py‎

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -95,36 +95,6 @@ def test_raises_when_seq_exceeds_max(self):
9595
class TestVisionForwardPackedAttentionSetup:
9696
"""Tests for ``_vision_forward_packed_attention_setup``."""
9797

98-
@pytest.mark.unit
99-
@pytest.mark.parametrize(
100-
"grid,expected_boundaries,expected_max",
101-
[
102-
([[1, 2, 3]], [0, 6], 6),
103-
([[2, 2, 3], [1, 2, 4]], [0, 6, 12, 20], 8),
104-
],
105-
)
106-
def test_non_cuda_graph_path_uses_integer_maxima(self, grid, expected_boundaries, expected_max):
107-
grid = torch.tensor(grid, dtype=torch.int64)
108-
seq_len = expected_boundaries[-1]
109-
packed, mask = _vision_forward_packed_attention_setup(
110-
use_cuda_graph_padding=False,
111-
hidden_states=torch.zeros(seq_len, 1, 8),
112-
original_seq_len=seq_len,
113-
seq_len=seq_len,
114-
grid_thw=grid,
115-
build_packed_seq_params=lambda value: Qwen3VLVisionModel.build_packed_seq_params(None, value),
116-
)
117-
118-
assert mask is None
119-
assert packed.qkv_format == "thd"
120-
assert type(packed.max_seqlen_q) is int
121-
assert type(packed.max_seqlen_kv) is int
122-
assert packed.max_seqlen_q == packed.max_seqlen_kv == expected_max
123-
for boundaries in (packed.cu_seqlens_q, packed.cu_seqlens_kv):
124-
assert boundaries.tolist() == expected_boundaries
125-
assert boundaries.dtype == torch.int32
126-
assert boundaries.device == grid.device
127-
12898
def test_non_cuda_graph_path_calls_builder_and_no_mask(self):
12999
grid = torch.tensor([[1, 4, 4]], dtype=torch.long)
130100
hidden = torch.zeros(5, 1, 8, dtype=torch.float32)

‎tests/unit_tests/training/test_nemotron_omni_step.py‎

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,6 @@
2222
from megatron.bridge.training.utils.packed_seq_utils import get_packed_seq_params
2323

2424

25-
@pytest.mark.unit
26-
@pytest.mark.parametrize(
27-
"image_sizes,expected_boundaries,expected_max",
28-
[
29-
([[512, 512]], [0, 1024], 1024),
30-
([[32, 48], [64, 32]], [0, 6, 14], 8),
31-
],
32-
)
33-
def test_vision_packed_metadata_uses_integer_maxima(image_sizes, expected_boundaries, expected_max):
34-
image_sizes = torch.tensor(image_sizes, dtype=torch.int64)
35-
36-
metadata = nemotron_omni_step._build_vision_packed_seq_params(image_sizes)
37-
38-
assert metadata.qkv_format == "thd"
39-
assert type(metadata.max_seqlen_q) is int
40-
assert type(metadata.max_seqlen_kv) is int
41-
assert metadata.max_seqlen_q == metadata.max_seqlen_kv == expected_max
42-
for boundaries in (metadata.cu_seqlens_q, metadata.cu_seqlens_kv):
43-
assert boundaries.tolist() == expected_boundaries
44-
assert boundaries.dtype == torch.int32
45-
assert boundaries.device == image_sizes.device
46-
47-
4825
def test_batch_moves_only_one_compatible_token_alias_to_cuda(monkeypatch):
4926
cuda_inputs = []
5027

@@ -145,27 +122,6 @@ def _pipeline_cfg(*, packed=True, defer_packing=False, temporal_patch_dim=1):
145122
)
146123

147124

148-
@pytest.mark.unit
149-
@pytest.mark.parametrize("packed", [False, True])
150-
def test_first_pipeline_batch_keeps_vision_maxima_as_integers(monkeypatch, packed):
151-
monkeypatch.setattr(torch.Tensor, "cuda", lambda self, **kwargs: self)
152-
monkeypatch.setattr(nemotron_omni_step, "is_pp_first_stage", lambda group: True)
153-
monkeypatch.setattr(nemotron_omni_step, "is_pp_last_stage", lambda group: False)
154-
batch = _packed_pipeline_batch()
155-
if not packed:
156-
for key in (*nemotron_omni_step._PACKED_SEQ_PARAM_KEYS, "padding_mask"):
157-
batch.pop(key, None)
158-
159-
result = get_batch(iter([batch]), _pipeline_cfg(packed=packed), pg_collection=SimpleNamespace(pp=object()))
160-
161-
vision_metadata = result[12]
162-
assert type(vision_metadata.max_seqlen_q) is int
163-
assert type(vision_metadata.max_seqlen_kv) is int
164-
assert vision_metadata.max_seqlen_q == vision_metadata.max_seqlen_kv == 4
165-
assert vision_metadata.cu_seqlens_q.tolist() == [0, 4, 8]
166-
assert vision_metadata.cu_seqlens_kv.tolist() == [0, 4, 8]
167-
168-
169125
def test_forward_rejects_deferred_multimodal_packing():
170126
state = SimpleNamespace(
171127
timers=None,

0 commit comments

Comments
 (0)