Repository navigation
Let Gemma 4 31B train when it is split across GPUs - #12233
danielhanchen merged 3 commits into
Conversation
|
Review record for #12233, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#212. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found. Round 1: reviewed mirror
|
# Conflicts: # unsloth/models/vision.py
Training Gemma 4 31B stopped before the first step with "indices should be either on cpu or on the same device as the indexed tensor (cuda:0)" whenever the model was split over two or more GPUs. Studio does that split by itself when one card is too small for the run, for example on 16 GB cards. On a single GPU the same run trained fine.
The 31B builds an image attention mask from a token type tensor that lands on the first GPU, while the text embeddings it is compared against sit on the last one. This moves that tensor next to the embeddings, only for Gemma 4 models spread over several GPUs. Single GPU runs and other models are unchanged.
PR #12095 turns off padding-free batching instead, but the same error still happens with it.
Fixes #11952
Testing
unsloth/gemma-4-31B-itQLoRA (Studio split it over both cards by itself): main fails at step 0 withindices should be either on cpu or on the same device as the indexed tensor (cuda:0); this PR trains 5/5 steps. The library API withdevice_map="unsloth_balanced"gives the same result, and the losses (3.811, 3.340, 2.380, 2.305, 2.635) track a single-GPU run (3.794, 3.426, 2.382, 2.383, 2.599).tests/test_gemma4_split_vision_mask.pyneeds two GPUs, so hosted CI skips it. On 2 GPUs with transformers 5.5.0 it fails on main and passes here. transformers 5.9 and newer move the token types themselves, so there the hook is a harmless no-op.