Running Lora+ T5 Gemma 2 on multi gpu results in error

#6
by RomanatoS - opened

Hello! 👋

I’m running into a DDP error when training google/t5gemma-2-4b-4b with LoRA+ on 4 GPUs. Training on a single GPU works fine, but distributed training fails consistently.

Model: https://huggingface.co/google/t5gemma-2-4b-4b

Environment

transformers: 5.0.0.dev0
accelerate: 1.12.0
peft: 0.18.1
torch: 2.9.1
CUDA: 12.4
GPUs: 4× NVIDIA RTX 6000
OS: Ubuntu 20.04.6 LTS
Here you can find the error I encounter, and a screenshot of the full one.
image

[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 forwardfunction. 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 multiplecheckpoint 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 1275 with name base_model.model.model.decoder.layers.33.mlp.down_proj.lora_B.default.weight has been marked as ready twice. This means that multiple autograd engine hooks have fired for this particular parameter during this iteration.

Q: Is this a known incompatibility between LoRA and DDP / Transformers for T5Gemma, or is there a recommended configuration/workaround?

Thank you!

Hi @RomanatoS ,

This seems to be a conflict between DDP and the default 'reentrant' gradient checkpointing. The error Expected to amrk a variable ready only once occurs because reentrant checkpointing re-runs the forward pass during backprop, causing DDP to think the parameters are being synchronised twice in one step. This has nothing to do with T5Gemma.
You can try to force non-reentrant checkpointing: trying adding this to your Training Arguments: gradient_checkpointing_kwargs={"use_reentrant": False} which prevents the backward pass from traversing the graph a second time and it's also recommended across peft community to set ddp_find_unused_parameters=False to prevent DDP from crashing when scanning frozen LORA parameters.

Thank you!

Sign up or log in to comment