Closed echzhai closed 6 months ago
Hi @echzhai , does it happens during checkpointing? Can you remove the RayTrainReportCallback
and see if it works?
the problem sovled after I add below two line of codes: gradient_checkpointing=True, gradient_checkpointing_kwargs={'use_reentrant':False},
What happened + What you expected to happen
if i run fine tuning without ray, it works. but if i use ray, i will get 2024-02-20 21:43:02,050 ERROR tune_controller.py:1374 -- Trial task failed for trial TorchTrainer_8c08f_00000 Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/ray/air/execution/_internal/event_manager.py", line 110, in resolve_future result = ray.get(future) File "/usr/local/lib/python3.8/site-packages/ray/_private/auto_init_hook.py", line 22, in auto_init_wrapper return fn(*args, kwargs) File "/usr/local/lib/python3.8/site-packages/ray/_private/client_mode_hook.py", line 103, in wrapper return func(*args, *kwargs) File "/usr/local/lib/python3.8/site-packages/ray/_private/worker.py", line 2624, in get raise value.as_instanceof_cause() ray.exceptions.RayTaskError(RuntimeError): ray::_Inner.train() (pid=18374, ip=192.168.236.20, actor_id=6d35f3067f42e27c7332f0add2000000, repr=TorchTrainer) File "/usr/local/lib/python3.8/site-packages/ray/tune/trainable/trainable.py", line 342, in train raise skipped from exception_cause(skipped) File "/usr/local/lib/python3.8/site-packages/ray/train/_internal/utils.py", line 43, in check_for_failure ray.get(object_ref) ray.exceptions.RayTaskError(RuntimeError): ray::_RayTrainWorkerexecute.get_next() (pid=18430, ip=192.168.236.20, actor_id=d38d2fa719c30e8683c347cdd2000000, repr=<ray.train._internal.worker_group.RayTrainWorker object at 0x7f53f43c5dc0>) File "/usr/local/lib/python3.8/site-packages/ray/train/_internal/worker_group.py", line 33, in execute raise skipped from exception_cause(skipped) File "/usr/local/lib/python3.8/site-packages/ray/train/_internal/utils.py", line 118, in discard_return_wrapper train_func(args, kwargs) File "train-colab.py", line 98, in train_func trainer.train() File "/tmp/ray/session_2024-02-15_19-25-10_223548_21/runtime_resources/pip/76b53ca467e56ecaa61f8563fec3d519a6155603/virtualenv/lib/python3.8/site-packages/trl/trainer/sft_trainer.py", line 331, in train output = super().train(args, kwargs) File "/tmp/ray/session_2024-02-15_19-25-10_223548_21/runtime_resources/pip/76b53ca467e56ecaa61f8563fec3d519a6155603/virtualenv/lib/python3.8/site-packages/transformers/trainer.py", line 1539, in train return inner_training_loop( File "/tmp/ray/session_2024-02-15_19-25-10_223548_21/runtime_resources/pip/76b53ca467e56ecaa61f8563fec3d519a6155603/virtualenv/lib/python3.8/site-packages/transformers/trainer.py", line 1869, in _inner_training_loop tr_loss_step = self.training_step(model, inputs) File "/tmp/ray/session_2024-02-15_19-25-10_223548_21/runtime_resources/pip/76b53ca467e56ecaa61f8563fec3d519a6155603/virtualenv/lib/python3.8/site-packages/transformers/trainer.py", line 2781, in training_step self.accelerator.backward(loss) File "/tmp/ray/session_2024-02-15_19-25-10_223548_21/runtime_resources/pip/76b53ca467e56ecaa61f8563fec3d519a6155603/virtualenv/lib/python3.8/site-packages/accelerate/accelerator.py", line 1966, in backward loss.backward(kwargs) File "/tmp/ray/session_2024-02-15_19-25-10_223548_21/runtime_resources/pip/76b53ca467e56ecaa61f8563fec3d519a6155603/virtualenv/lib/python3.8/site-packages/torch/_tensor.py", line 522, in backward torch.autograd.backward( File "/tmp/ray/session_2024-02-15_19-25-10_223548_21/runtime_resources/pip/76b53ca467e56ecaa61f8563fec3d519a6155603/virtualenv/lib/python3.8/site-packages/torch/autograd/init.py", line 266, in backward Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass File "/tmp/ray/session_2024-02-15_19-25-10_223548_21/runtime_resources/pip/76b53ca467e56ecaa61f8563fec3d519a6155603/virtualenv/lib/python3.8/site-packages/torch/autograd/function.py", line 289, in apply return user_fn(self, args) File "/tmp/ray/session_2024-02-15_19-25-10_223548_21/runtime_resources/pip/76b53ca467e56ecaa61f8563fec3d519a6155603/virtualenv/lib/python3.8/site-packages/torch/utils/checkpoint.py", line 319, in backward torch.autograd.backward(outputs_with_grad, args_with_grad) File "/tmp/ray/session_2024-02-15_19-25-10_223548_21/runtime_resources/pip/76b53ca467e56ecaa61f8563fec3d519a6155603/virtualenv/lib/python3.8/site-packages/torch/autograd/init.py", line 266, in backward 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 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. Parameter at index 319 with name base_model.model.model.layers.31.mlp.gate_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.Versions / Dependencies
ray 2.9.2
Reproduction script
Issue Severity
None