Commit c7e344b
committed
[None][fix] Restore Qwen3-VL vision-block RoPE shape after EXAONE-4.5 rebase
The qwen3vl_opt branch's ``1c4e86892d "Further optimize Qwen3-VL"``
removed ``rope_position_ids`` from the per-block call and added a
``rotary_pos_emb.flatten(1).repeat(1, 2).cos()/.sin()`` chain in the
vision tower forward. At authoring time that matched the HF
``apply_rotary_pos_emb_vision`` ABI (cos/sin shape
``(seq, head_dim)``), which ``Qwen2_5_VLVisionAttention.forward`` used.
After upstream ``7279d6322d "EXAONE-4.5 Support"`` refactored that
attention class to route through the new ``apply_rope`` helper
(``RotaryEmbedding.apply_rotary_pos_emb`` / FlashInfer), the expected
``cos.shape[-1]`` became ``head_dim // 2``: ``apply_rotary_pos_emb``
computes ``rot_dim = cos.shape[-1] * 2`` and chunks q/k into halves
of size ``cos.shape[-1]``. With Qwen3-VL's ``head_dim = 72``
(``72 % 64 != 0``, so the FlashInfer gate misses and the PyTorch
fallback runs), the prior ``.repeat(1, 2)`` made cos/sin
``(total, 72)`` and the elementwise multiply against
``q.chunk(2)[i]`` (shape ``(..., 36)``) raised
``RuntimeError: The size of tensor a (36) must match the size of
tensor b (72) at non-singleton dimension 2`` -- silently broken at
rebase time, missed by every unit test on this branch because they
verified isolated cos/sin construction (pos_ids, lru_cache identity,
gather equivalence) but never piped them through the actual attention
block. CI's model-level test would have caught it.
Fix:
* ``Qwen3VisionModel.forward``: drop ``cos.repeat(1, 2)`` /
``sin.repeat(1, 2)``. The cos/sin tuple returned by ``rot_pos_emb``
is already at the post-EXAONE shape ``(total_tokens, 2 * freq_dim)
= (total_tokens, head_dim // 2)``.
* ``Qwen3VisionModel.forward``: restore the pre-1c4e86892d
``rope_position_ids = torch.arange(seq_len, dtype=int32,
pin_memory=prefer_pinned()).to(device, non_blocking=True)`` and
pass ``position_ids=rope_position_ids`` into each block. This
keeps the FlashInfer ``position_ids is not None`` gate satisfied
for any future config where ``head_dim % 64 == 0``; for Qwen3-VL
itself it still falls through to the PyTorch path, which now has
the correct broadcast.
All prior optimizations on this branch are preserved: cos/sin
pre-computed init buffers (``rope_cos_cache`` / ``rope_sin_cache``),
L2 per-(t, h, w) cache, batched Triton pos-embed kernel,
rot_pos_ids lru_cache, async_tensor_h2d helper, argsort inverse
permutation, deepstack dict lookup. The fix is a layout correction
on the output side of ``rot_pos_emb``, not a revert of the
optimizations.
Test: ``test_qwen3vl_vision_block_forward_end_to_end`` builds one
``Qwen3VLVisionBlock`` with random weights and runs forward with the
post-EXAONE cos/sin shape and ``position_ids``. Without this fix it
raises the same broadcasting error; with it the block returns the
expected ``(seq_len, hidden)`` tensor. Any future regression that
re-introduces a stray ``.repeat(1, 2)`` on cos/sin (or drops
``position_ids``) will surface here, not only at CI time.
Signed-off-by: yechank <161688079+yechank-nvidia@users.noreply.github.com>1 parent af0731d commit c7e344b
2 files changed
Lines changed: 117 additions & 4 deletions
File tree
- tensorrt_llm/_torch/models
- tests/unittest/_torch/modeling
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1132 | 1132 | | |
1133 | 1133 | | |
1134 | 1134 | | |
1135 | | - | |
1136 | | - | |
1137 | | - | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
1138 | 1140 | | |
1139 | 1141 | | |
1140 | 1142 | | |
1141 | 1143 | | |
1142 | 1144 | | |
1143 | 1145 | | |
1144 | 1146 | | |
1145 | | - | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
1146 | 1157 | | |
1147 | 1158 | | |
1148 | 1159 | | |
1149 | 1160 | | |
1150 | 1161 | | |
| 1162 | + | |
1151 | 1163 | | |
1152 | 1164 | | |
1153 | 1165 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
951 | 951 | | |
952 | 952 | | |
953 | 953 | | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
0 commit comments