Skip to content

Error with Multi-GPU peft Reward Training #480

@mnoukhov

Description

@mnoukhov

There is an issue when you combine all four:

  • peft quantization
  • gradient checkpointing
  • multi-gpu ddp
  • two gradients on the same parameters (as you have in the loss function for Reward Trainer)

This is reproducible if you correctly enable gradient checkpointing in examples/multi-adapter-rl as shown in PR #479 and then run in a multi-gpu setup

accelerate launch --multi_gpu reward_modeling.py --gradient_checkpointing True

you will receive the error

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. Parameter at index 127 has been marked as ready twice. This means that multiple autograd engine hooks have fired for this particular parameter during this iteration. You can set the environment variable
TORCH_DISTRIBUTED_DEBUG to either INFO or DETAIL to print parameter names for further debugging.

With TORCH_DISTRIBUTED_DEBUG=DETAIL, we find the affected parameter is a LoRA parameter. It is not related to pytorch/pytorch#60844 because find_unused_parameters is set to False.

This is likely a problem between peft and accelerate/ddp but I'm putting the issue here because it affects RewardTrainer and quantization + multi gpu + gradient checkpointing are a common combination

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions