Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reward_modeling.py errors on multi-GPU training #891

Closed
vwxyzjn opened this issue Oct 18, 2023 · 1 comment · Fixed by #912
Closed

reward_modeling.py errors on multi-GPU training #891

vwxyzjn opened this issue Oct 18, 2023 · 1 comment · Fixed by #912

Comments

@vwxyzjn
Copy link
Contributor

vwxyzjn commented Oct 18, 2023

To repro accelerate launch --num_processes 8 examples/scripts/reward_modeling.py

https://wandb.ai/costa-huang/huggingface/runs/ordvc1sq/logs?workspace=user-costa-huang

  File "examples/scripts/reward_trainer_summarize.py", line 165, in <module>
    trainer.train()
  File "/admin/home/costa/.pyenv/versions/3.8.11/envs/trl/lib/python3.8/site-packages/transformers/trainer.py", line 1506, in train
    return inner_training_loop(
  File "/admin/home/costa/.pyenv/versions/3.8.11/envs/trl/lib/python3.8/site-packages/transformers/trainer.py", line 1801, in _inner_training_loop
    tr_loss_step = self.training_step(model, inputs)
  File "/admin/home/costa/.pyenv/versions/3.8.11/envs/trl/lib/python3.8/site-packages/transformers/trainer.py", line 2659, in training_step
    self.accelerator.backward(loss)
  File "/admin/home/costa/.pyenv/versions/3.8.11/envs/trl/lib/python3.8/site-packages/accelerate/accelerator.py", line 1923, in backward
    loss.backward(**kwargs)
  File "/admin/home/costa/.pyenv/versions/3.8.11/envs/trl/lib/python3.8/site-packages/torch/_tensor.py", line 487, in backward
    torch.autograd.backward(
  File "/admin/home/costa/.pyenv/versions/3.8.11/envs/trl/lib/python3.8/site-packages/torch/autograd/__init__.py", line 200, in backward
    Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
  File "/admin/home/costa/.pyenv/versions/3.8.11/envs/trl/lib/python3.8/site-packages/torch/autograd/function.py", line 274, in apply
Traceback (most recent call last):
  File "examples/scripts/reward_trainer_summarize.py", line 165, in <module>
    return user_fn(self, *args)
  File "/admin/home/costa/.pyenv/versions/3.8.11/envs/trl/lib/python3.8/site-packages/torch/utils/checkpoint.py", line 157, in backward
    torch.autograd.backward(outputs_with_grad, args_with_grad)
  File "/admin/home/costa/.pyenv/versions/3.8.11/envs/trl/lib/python3.8/site-packages/torch/autograd/__init__.py", line 200, in backward
    trainer.train()
  File "/admin/home/costa/.pyenv/versions/3.8.11/envs/trl/lib/python3.8/site-packages/transformers/trainer.py", line 1506, in train
    Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
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 433 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.
@younesbelkada
Copy link
Contributor

Hi @vwxyzjn
If you install trl, peft and transformers from source, passing gradient_checkpointing_kwargs={"use_reentrant": False} to RewardConfig should fix the issue. We will have releases in each of these libraries soon !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants