Skip to content

[Bug] DDP with Qwen2.5VL 7B #3713

Closed

Description

@John1231983

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?

Activity

  1. mishra077 commented on Dec 11, 2025

    @mishra077

    can you check at what point the system crashes does it happen during model loading or during training.

  2. John1231983 commented on Dec 11, 2025

    @John1231983
    Author

    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?

  3. Datta0 commented on Dec 12, 2025

    @Datta0
    Contributor

    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

  4. John1231983 commented on Dec 12, 2025

    @John1231983
    Author

    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
    
  5. djsaunde commented on Dec 15, 2025

    @djsaunde
    Contributor

    @John1231983 Please provide the command / script you're running so we can reproduce this on our end.

  6. djsaunde commented on Dec 15, 2025

    @djsaunde
    Contributor

    In the meantime, if you haven't already, please make sure you have the latest unsloth / unsloth-zoo with:

    pip install --force-reinstall --no-deps --no-cache-dir unsloth unsloth_zoo
  7. John1231983 commented on Dec 16, 2025

    @John1231983
    Author

    @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

    CUDA_VISIBLE_DEVICES=0,1 torchrun --nproc_per_node=2 train.py
    
  8. djsaunde commented on Dec 16, 2025

    @djsaunde
    Contributor

    @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.

  9. John1231983 commented on Dec 18, 2025

    @John1231983
    Author

    @djsaunde any update for the bug. Thanks

  10. djsaunde commented on Dec 18, 2025

    @djsaunde
    Contributor

    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.

  11. added a commit that references this issue on Feb 17, 2026
    4e18856
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions