Commit eb2617a
Extract dynamic vision/audio tensors into standalone pure functions (huggingface#45396)
* Extract pure vision/audio functions into standalone utilities
- Create top-level `modeling_vision_utils.py` with shared pure functions:
`get_vision_cu_seqlens`, `get_rotary_pos_ids`, `get_rotary_pos_ids_interleaved`,
`get_window_index`, `get_pos_embed_indices`
- Move audio precompute functions (`chunk_and_pad_features`, `get_audio_cu_seqlens`,
`get_valid_indices`, `get_pool_indices`) into modular files directly
- Simplify `VisionRotaryEmbedding.forward` to accept `pos_ids` tensor directly
via broadcast multiply, eliminating data-dependent table creation
- Make vision/audio encoder forwards accept optional precomputed tensors
(`cu_seqlens`, `rotary_pos_ids`, `window_index`, `embed_indices`, etc.)
- Use explicit naming: `get_vision_cu_seqlens` / `get_audio_cu_seqlens`
Models: qwen2_vl, qwen2_5_vl, qwen3_vl, qwen3_5, qwen3_vl_moe, qwen3_5_moe,
qwen2_5_omni, qwen3_omni_moe, glm4v, glm4v_moe, glm_image, glm_ocr,
ernie4_5_vl_moe, video_llama_3, mlcd, paddleocr_vl
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
* Fix stale compute_ docstring references to match actual function names
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
* Revert mlcd changes — not part of this PR
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
* fix
* kwargs
* opt-in
* fix dtype
* style
* guard torch import
* standarize
* propagate inputs
* fix docs
* fix docs
* auto docs
* more docs fixing
* fix omni
* fix paddle
* revert paddle ocr until another time
* finally fixed paddle ocr
* fix review
* revert chunking
* Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
* Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
* fix torch compilable check
* fix docs
* correct func name
* fix omni
* fix video llama 3
* fix video llama 3
* requires torch
* add missing grid device
* keep rot emb in fp32
* fix test device
* fix flm4v flex attention test
* rename to vision utils
* only one get_rotary_pos_ids is needed
* style
* style
* deprecate only
* fix
* simplify and revert processor changes
* renames
* move some stuff to their original place
* style
* style
* use chunked attention
* use decorator
* pass kwargs and return_dict
* fix missing
* keep in and get from kwargs
* revert some trailing commas
* fix
* fixes
* video llama fixes
* fix qwen3 vl
* forgot glm ocr
* address comments
* drop unnecessary
* use correct flash attn check
* missed deprecation
* empty commit 1
* empty commit 2
* revert video llama 3 config changes
* style
* style fix
* address comments
* remove unnecessary
* revert TransformersKwargs and add a todo
---------
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>1 parent 04850b3 commit eb2617a
41 files changed
Lines changed: 1856 additions & 2219 deletions
File tree
- src/transformers
- models
- ernie4_5_vl_moe
- exaone4_5
- glm46v
- glm4v_moe
- glm4v
- glm_image
- glm_ocr
- paddleocr_vl
- qwen2_5_omni
- qwen2_5_vl
- qwen2_vl
- qwen3_5_moe
- qwen3_5
- qwen3_omni_moe
- qwen3_vl_moe
- qwen3_vl
- video_llama_3
- utils
- tests/models
- glm4v_moe
- qwen2_5_omni
- qwen2_5_vl
- qwen3_5_moe
- qwen3_5
- qwen3_omni_moe
- qwen3_vl_moe
- qwen3_vl
- video_llama_3
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 33 additions & 50 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
42 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
43 | 49 | | |
| 50 | + | |
44 | 51 | | |
45 | 52 | | |
46 | 53 | | |
| |||
855 | 862 | | |
856 | 863 | | |
857 | 864 | | |
858 | | - | |
859 | | - | |
860 | | - | |
861 | | - | |
| 865 | + | |
| 866 | + | |
862 | 867 | | |
863 | 868 | | |
864 | 869 | | |
| |||
894 | 899 | | |
895 | 900 | | |
896 | 901 | | |
897 | | - | |
898 | | - | |
899 | | - | |
900 | | - | |
901 | | - | |
902 | | - | |
903 | | - | |
904 | | - | |
905 | | - | |
906 | | - | |
907 | | - | |
908 | | - | |
909 | | - | |
910 | | - | |
911 | | - | |
912 | | - | |
913 | | - | |
914 | | - | |
915 | | - | |
916 | | - | |
917 | | - | |
918 | | - | |
919 | | - | |
920 | | - | |
921 | | - | |
922 | | - | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
923 | 909 | | |
924 | 910 | | |
925 | 911 | | |
| |||
931 | 917 | | |
932 | 918 | | |
933 | 919 | | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
934 | 923 | | |
935 | | - | |
| 924 | + | |
936 | 925 | | |
937 | 926 | | |
938 | 927 | | |
939 | | - | |
940 | | - | |
941 | | - | |
942 | | - | |
943 | | - | |
944 | | - | |
945 | | - | |
946 | | - | |
947 | | - | |
948 | | - | |
949 | 928 | | |
950 | 929 | | |
951 | 930 | | |
| |||
1263 | 1242 | | |
1264 | 1243 | | |
1265 | 1244 | | |
| 1245 | + | |
1266 | 1246 | | |
1267 | 1247 | | |
1268 | 1248 | | |
| |||
1277 | 1257 | | |
1278 | 1258 | | |
1279 | 1259 | | |
1280 | | - | |
| 1260 | + | |
1281 | 1261 | | |
1282 | 1262 | | |
1283 | 1263 | | |
| |||
1288 | 1268 | | |
1289 | 1269 | | |
1290 | 1270 | | |
| 1271 | + | |
1291 | 1272 | | |
1292 | 1273 | | |
1293 | 1274 | | |
| |||
1302 | 1283 | | |
1303 | 1284 | | |
1304 | 1285 | | |
1305 | | - | |
| 1286 | + | |
1306 | 1287 | | |
1307 | 1288 | | |
1308 | 1289 | | |
| |||
1434 | 1415 | | |
1435 | 1416 | | |
1436 | 1417 | | |
1437 | | - | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
1438 | 1421 | | |
1439 | 1422 | | |
1440 | 1423 | | |
1441 | 1424 | | |
1442 | 1425 | | |
1443 | 1426 | | |
1444 | 1427 | | |
1445 | | - | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
1446 | 1431 | | |
1447 | 1432 | | |
1448 | 1433 | | |
| |||
1598 | 1583 | | |
1599 | 1584 | | |
1600 | 1585 | | |
1601 | | - | |
1602 | | - | |
1603 | | - | |
| 1586 | + | |
1604 | 1587 | | |
1605 | 1588 | | |
1606 | 1589 | | |
| |||
1615 | 1598 | | |
1616 | 1599 | | |
1617 | 1600 | | |
1618 | | - | |
| 1601 | + | |
1619 | 1602 | | |
1620 | 1603 | | |
1621 | 1604 | | |
| |||
Lines changed: 16 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
| |||
51 | 50 | | |
52 | 51 | | |
53 | 52 | | |
54 | | - | |
| 53 | + | |
55 | 54 | | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
701 | 701 | | |
702 | 702 | | |
703 | 703 | | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
704 | 707 | | |
705 | | - | |
| 708 | + | |
706 | 709 | | |
707 | 710 | | |
708 | 711 | | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | | - | |
718 | | - | |
719 | 712 | | |
720 | 713 | | |
721 | 714 | | |
| |||
962 | 955 | | |
963 | 956 | | |
964 | 957 | | |
| 958 | + | |
965 | 959 | | |
966 | 960 | | |
967 | 961 | | |
| |||
970 | 964 | | |
971 | 965 | | |
972 | 966 | | |
973 | | - | |
| 967 | + | |
974 | 968 | | |
975 | 969 | | |
976 | 970 | | |
| |||
981 | 975 | | |
982 | 976 | | |
983 | 977 | | |
| 978 | + | |
984 | 979 | | |
985 | 980 | | |
986 | 981 | | |
| |||
989 | 984 | | |
990 | 985 | | |
991 | 986 | | |
992 | | - | |
| 987 | + | |
993 | 988 | | |
994 | 989 | | |
995 | 990 | | |
| |||
1031 | 1026 | | |
1032 | 1027 | | |
1033 | 1028 | | |
1034 | | - | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
1035 | 1032 | | |
1036 | 1033 | | |
1037 | 1034 | | |
1038 | 1035 | | |
1039 | 1036 | | |
1040 | 1037 | | |
1041 | 1038 | | |
1042 | | - | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
1043 | 1042 | | |
1044 | 1043 | | |
1045 | 1044 | | |
| |||
0 commit comments