You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m following the code in the DDP guide
to train Qwen2.5-VL on 2 GPUs, but the process hangs and eventually crashes. It appears that the example works for LLMs but not for VLMs.
Could you please investigate this issue and add support for multi-GPU training for VLM models?
Hey @John1231983 can you share the script or the command you tried? Or at least the stack trace of the error/crash maybe
I can run it on my end to verify.
But from the looks of it, it can potentially be related to #3687 which should be hopefully fixed by unslothai/unsloth-zoo#379
The bug log with use_gradient_checkpointing="unsloth" and two GPU @Datta0
[rank1]: File "/home/jonh/unsloth/unsloth_compiled_cache/UnslothSFTTrainer.py", line 55, in wrapper
[rank1]: output = f(self, *args, **kwargs)
[rank1]: ^^^^^^^^^^^^^^^^^^^^^^^^
[rank1]: File "/home/jonh/unsloth/lib/python3.12/site-packages/transformers/trainer.py", line 2325, in train
[rank1]: return inner_training_loop(
[rank1]: ^^^^^^^^^^^^^^^^^^^^
[rank1]: File "<string>", line 328, in _fast_inner_training_loop
[rank1]: File "/home/jonh/unsloth/unsloth_compiled_cache/UnslothSFTTrainer.py", line 1068, in training_step
[rank1]: return super().training_step(*args, **kwargs)
[rank1]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank1]: File "<string>", line 91, in _unsloth_training_step
[rank1]: File "/home/jonh/unsloth/lib/python3.12/site-packages/accelerate/accelerator.py", line 2852, in backward
[rank1]: loss.backward(**kwargs)
[rank1]: File "/home/jonh/unsloth/lib/python3.12/site-packages/torch/_tensor.py", line 625, in backward
[rank1]: torch.autograd.backward(
[rank1]: File "/home/jonh/unsloth/lib/python3.12/site-packages/torch/autograd/__init__.py", line 354, in backward
[rank1]: _engine_run_backward(
[rank1]: File "/home/jonh/unsloth/lib/python3.12/site-packages/torch/autograd/graph.py", line 841, in _engine_run_backward
[rank1]: return Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass
[rank1]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank1]: File "/home/jonh/unsloth/lib/python3.12/site-packages/torch/autograd/function.py", line 315, in apply
[rank1]: return user_fn(self, *args)
[rank1]: ^^^^^^^^^^^^^^^^^^^^
[rank1]: File "/home/jonh/unsloth/lib/python3.12/site-packages/unsloth_zoo/gradient_checkpointing.py", line 606, in backward
[rank1]: torch.autograd.backward(outputs_with_grad, args_with_grad)
[rank1]: File "/home/jonh/unsloth/lib/python3.12/site-packages/torch/autograd/__init__.py", line 354, in backward
[rank1]: _engine_run_backward(
[rank1]: File "/home/jonh/unsloth/lib/python3.12/site-packages/torch/autograd/graph.py", line 841, in _engine_run_backward
[rank1]: return Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass
[rank1]: RuntimeError: Expected to mark a variable ready only once. This error is caused by one of the following reasons: 1) Use of a module parameter outside the `forward` function. Please make sure model parameters are not shared across multiple concurrent forward-backward passes. or try to use _set_static_graph() as a workaround if this module graph does not change during training loop.2) Reused parameters in multiple reentrant backward passes. For example, if you use multiple `checkpoint` functions to wrap the same part of your model, it would result in the same set of parameters been used by different reentrant backward passes multiple times, and hence marking a variable ready multiple times. DDP does not support such use cases in default. You can try to use _set_static_graph() as a workaround if your module graph does not change over iterations.
[rank1]: Parameter at index 694 with name base_model.model.model.language_model.layers.35.mlp.down_proj.lora_A.default.weight has been marked as ready twice. This means that multiple autograd engine hooks have fired for this particular parameter during this iteration.
W1213 08:32:55.366000 3094064 /home/jonh/unsloth/lib/python3.12/site-packages/torch/distributed/elastic/multiprocessing/api.py:908] Sending process 3094183 closing signal SIGTERM
E1213 08:32:57.842000 3094064 /home/jonh/unsloth/lib/python3.12/site-packages/torch/distributed/elastic/multiprocessing/api.py:882] failed (exitcode: 1) local_rank: 1 (pid: 3094184) of binary: /home/jonh/unsloth/bin/python3.12
Traceback (most recent call last):
File "/home/jonh/unsloth/bin/torchrun", line 7, in <module>
sys.exit(main())
^^^^^^
File "/home/jonh/unsloth/lib/python3.12/site-packages/torch/distributed/elastic/multiprocessing/errors/__init__.py", line 357, in wrapper
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File "/home/jonh/unsloth/lib/python3.12/site-packages/torch/distributed/run.py", line 936, in main
run(args)
File "/home/jonh/unsloth/lib/python3.12/site-packages/torch/distributed/run.py", line 927, in run
elastic_launch(
File "/home/jonh/unsloth/lib/python3.12/site-packages/torch/distributed/launcher/api.py", line 156, in __call__
return launch_agent(self._config, self._entrypoint, list(args))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jonh/unsloth/lib/python3.12/site-packages/torch/distributed/launcher/api.py", line 293, in launch_agent
raise ChildFailedError(
torch.distributed.elastic.multiprocessing.errors.ChildFailedError:
============================================================
ft_ddp.py FAILED
------------------------------------------------------------
Failures:
<NO_OTHER_FAILURES>
------------------------------------------------------------
Root Cause (first observed failure):
[0]:
time : 2025-12-13_08:32:55
host : localhost.localdomain
rank : 1 (local_rank: 1)
exitcode : 1 (pid: 3094184)
error_file: <N/A>
traceback : To enable traceback see: https://pytorch.org/docs/stable/elastic/errors.html
@John1231983 thanks for the repro info! I was able to reproduce.
Seems like this is an edge case with DDP + re-entrant gradient checkpointing + VLM models specifically. I'll work on a fix, seems nontrivial from a first look.
No update yet, been busy with other pieces of work. Hopefully will take another stab at this today.
Easiest fix would be to use non-reentrant gradient checkpointing for VLM models, but that will result in higher VRAM use during training. I'll likely push up this fix today just to get things working, but long term I'd like to have a better solution.
Activity
mishra077 commentedon Dec 11, 2025
can you check at what point the system crashes does it happen during model loading or during training.
John1231983 commentedon Dec 11, 2025
It does not work — it crashes and never reaches the training phase.
Could you please provide the code you mentioned that is confirmed to work?
Datta0 commentedon Dec 12, 2025
Hey @John1231983 can you share the script or the command you tried? Or at least the stack trace of the error/crash maybe
I can run it on my end to verify.
But from the looks of it, it can potentially be related to #3687 which should be hopefully fixed by unslothai/unsloth-zoo#379
John1231983 commentedon Dec 12, 2025
The bug log with
use_gradient_checkpointing="unsloth"and two GPU @Datta0djsaunde commentedon Dec 15, 2025
@John1231983 Please provide the command / script you're running so we can reproduce this on our end.
djsaunde commentedon Dec 15, 2025
In the meantime, if you haven't already, please make sure you have the latest unsloth / unsloth-zoo with:
John1231983 commentedon Dec 16, 2025
@djsaunde I used the code from the ipynp and convert to python
https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen2.5_VL_(7B)-Vision.ipynb
And run
djsaunde commentedon Dec 16, 2025
@John1231983 thanks for the repro info! I was able to reproduce.
Seems like this is an edge case with DDP + re-entrant gradient checkpointing + VLM models specifically. I'll work on a fix, seems nontrivial from a first look.
John1231983 commentedon Dec 18, 2025
@djsaunde any update for the bug. Thanks
djsaunde commentedon Dec 18, 2025
No update yet, been busy with other pieces of work. Hopefully will take another stab at this today.
Easiest fix would be to use non-reentrant gradient checkpointing for VLM models, but that will result in higher VRAM use during training. I'll likely push up this fix today just to get things working, but long term I'd like to have a better solution.
Fix DDP "marked ready twice" for VLMs with CPU offload + TiledMLP
DDP: find unused params for a fully finetuned VLM on text-only batche…