Commit 437ee45
[train] Add VLM SFT support on the Megatron backend (Qwen3-VL)
Adds vision-language-model support to the Megatron SFT path, mirroring the
existing FSDP VLM data plumbing. The vision tower runs on the first pipeline
stage; image tensors (pixel_values / image_grid_thw) flow through the same
TrainingInputBatch -> Experience path the FSDP backend already uses.
Changes:
- skyrl/utils/tok.py: add check_is_vlm and get_processor helpers.
- skyrl/train/sft_trainer.py: detect VLMs in setup(), build an HF processor,
thread it through tokenize_chat_example / _tokenize_chat_last_assistant,
emit image tensors as a TensorList in collate_sft_batch, force sequential
tokenization for VLMs, and disable sequence packing / microbatch padding
removal (unsupported for VLMs).
- megatron_model_wrapper.py: is_vlm flag, VLM constraint asserts (no packing,
CP, or SP), and pixel_values/image_grid_thw passthrough in both forward and
forward_backward_mini_batch.
- megatron_worker.py: VLM detection off the HF config, plumb is_vlm into the
wrapper, and forward image tensors through the micro-batch builders.
- tests: GPU init/forward + 5-step train test (test_megatron_vlm_init.py),
CPU tokenization/collation cases (test_sft_tokenization.py).
Constraints carried over from the FSDP VLM path: no sample/microbatch packing,
no context parallelism, no sequence parallelism, and homogeneous (all-image)
batches. MoE+VLM is out of scope.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 7f65395 commit 437ee45
6 files changed
Lines changed: 543 additions & 27 deletions
File tree
- skyrl
- backends/skyrl_train/workers/megatron
- train
- utils
- tests
- backends/skyrl_train/gpu/gpu_ci/megatron
- train
Lines changed: 41 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
69 | 83 | | |
70 | 84 | | |
71 | 85 | | |
| |||
86 | 100 | | |
87 | 101 | | |
88 | 102 | | |
| 103 | + | |
| 104 | + | |
89 | 105 | | |
90 | 106 | | |
91 | 107 | | |
| |||
124 | 140 | | |
125 | 141 | | |
126 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
127 | 152 | | |
128 | 153 | | |
129 | 154 | | |
130 | 155 | | |
131 | | - | |
| 156 | + | |
132 | 157 | | |
133 | 158 | | |
134 | 159 | | |
| |||
137 | 162 | | |
138 | 163 | | |
139 | 164 | | |
140 | | - | |
| 165 | + | |
141 | 166 | | |
142 | 167 | | |
143 | 168 | | |
| |||
146 | 171 | | |
147 | 172 | | |
148 | 173 | | |
| 174 | + | |
149 | 175 | | |
150 | 176 | | |
151 | 177 | | |
| |||
224 | 250 | | |
225 | 251 | | |
226 | 252 | | |
| 253 | + | |
| 254 | + | |
227 | 255 | | |
228 | 256 | | |
229 | 257 | | |
| |||
434 | 462 | | |
435 | 463 | | |
436 | 464 | | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
437 | 473 | | |
438 | 474 | | |
439 | 475 | | |
440 | 476 | | |
441 | | - | |
| 477 | + | |
442 | 478 | | |
443 | 479 | | |
444 | 480 | | |
| |||
448 | 484 | | |
449 | 485 | | |
450 | 486 | | |
451 | | - | |
| 487 | + | |
452 | 488 | | |
453 | 489 | | |
454 | 490 | | |
| |||
457 | 493 | | |
458 | 494 | | |
459 | 495 | | |
| 496 | + | |
460 | 497 | | |
461 | 498 | | |
462 | 499 | | |
| |||
Lines changed: 33 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
333 | 333 | | |
334 | 334 | | |
335 | 335 | | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
336 | 341 | | |
337 | 342 | | |
338 | 343 | | |
| |||
632 | 637 | | |
633 | 638 | | |
634 | 639 | | |
| 640 | + | |
635 | 641 | | |
636 | 642 | | |
637 | 643 | | |
| |||
673 | 679 | | |
674 | 680 | | |
675 | 681 | | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
676 | 688 | | |
677 | 689 | | |
678 | 690 | | |
679 | 691 | | |
680 | 692 | | |
681 | 693 | | |
682 | 694 | | |
| 695 | + | |
683 | 696 | | |
684 | 697 | | |
685 | 698 | | |
| |||
719 | 732 | | |
720 | 733 | | |
721 | 734 | | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
722 | 740 | | |
723 | 741 | | |
724 | 742 | | |
| |||
732 | 750 | | |
733 | 751 | | |
734 | 752 | | |
| 753 | + | |
735 | 754 | | |
736 | 755 | | |
737 | 756 | | |
| |||
823 | 842 | | |
824 | 843 | | |
825 | 844 | | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
826 | 850 | | |
827 | 851 | | |
828 | 852 | | |
| |||
838 | 862 | | |
839 | 863 | | |
840 | 864 | | |
| 865 | + | |
841 | 866 | | |
842 | 867 | | |
843 | 868 | | |
| |||
1196 | 1221 | | |
1197 | 1222 | | |
1198 | 1223 | | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
1199 | 1230 | | |
1200 | 1231 | | |
1201 | 1232 | | |
1202 | 1233 | | |
1203 | 1234 | | |
1204 | 1235 | | |
1205 | 1236 | | |
| 1237 | + | |
1206 | 1238 | | |
1207 | 1239 | | |
1208 | 1240 | | |
| |||
1287 | 1319 | | |
1288 | 1320 | | |
1289 | 1321 | | |
1290 | | - | |
| 1322 | + | |
1291 | 1323 | | |
1292 | 1324 | | |
1293 | 1325 | | |
| |||
0 commit comments