Skip to content

[Chatllama] RLHF Training - RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method #262

Description

@shrinath-suresh

While training RL model with the following command

python artifacts/main.py artifacts/config/config.yaml --type RL

we get the torch dataset error. To fix the error, we changed the following lines in trainer.py:427

        # from
        #dataloader = DataLoader(
            #ExperienceDataset(memories, device), batch_size=batch_size
        #)
       # to 
       dataset = ExperienceDataset(memories, device)

and in trainer.py:455

#from
#training_data=dataloader
#to
training_data=dataset

Issue Reference - #229

Post this fix, we are facing the following error

Using /home/ubuntu/.cache/torch_extensions/py39_cu117 as PyTorch extensions root...
No modifications detected for re-loaded extension module utils, skipping build step...
Loading extension module utils...
Time to load utils op: 0.00028014183044433594 seconds
Traceback (most recent call last):
  File "/home/ubuntu/artifacts/main.py", line 48, in <module>
    rlhf_trainer.train()
  File "/opt/conda/envs/pytorch/lib/python3.9/site-packages/chatllama/rlhf/trainer.py", line 788, in train
    self.learn(memories)
  File "<@beartype(chatllama.rlhf.trainer.RLTrainer.learn) at 0x7f279c996820>", line 33, in learn
  File "/opt/conda/envs/pytorch/lib/python3.9/site-packages/chatllama/rlhf/trainer.py", line 492, in learn
    for i, (
  File "/opt/conda/envs/pytorch/lib/python3.9/site-packages/deepspeed/runtime/dataloader.py", line 125, in __next__
    return next(self.data)
  File "/opt/conda/envs/pytorch/lib/python3.9/site-packages/deepspeed/runtime/dataloader.py", line 158, in <genexpr>
    self.data = (x for x in self.dataloader)
  File "/opt/conda/envs/pytorch/lib/python3.9/site-packages/torch/utils/data/dataloader.py", line 628, in __next__
    data = self._next_data()
  File "/opt/conda/envs/pytorch/lib/python3.9/site-packages/torch/utils/data/dataloader.py", line 1333, in _next_data
    return self._process_data(data)
  File "/opt/conda/envs/pytorch/lib/python3.9/site-packages/torch/utils/data/dataloader.py", line 1359, in _process_data
    data.reraise()
  File "/opt/conda/envs/pytorch/lib/python3.9/site-packages/torch/_utils.py", line 543, in reraise
    raise exception
RuntimeError: Caught RuntimeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/opt/conda/envs/pytorch/lib/python3.9/site-packages/torch/utils/data/_utils/worker.py", line 302, in _worker_loop
    data = fetcher.fetch(index)
  File "/opt/conda/envs/pytorch/lib/python3.9/site-packages/torch/utils/data/_utils/fetch.py", line 58, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/opt/conda/envs/pytorch/lib/python3.9/site-packages/torch/utils/data/_utils/fetch.py", line 58, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/opt/conda/envs/pytorch/lib/python3.9/site-packages/chatllama/rlhf/trainer.py", line 207, in __getitem__
    self.data[idx].states.to(self.device),
  File "/opt/conda/envs/pytorch/lib/python3.9/site-packages/torch/cuda/__init__.py", line 217, in _lazy_init
    raise RuntimeError(
RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method

Attaching the log, dataset, config for reference

Training log -
rl_train.log
Configurations -
test.zip
Dataset -
rlhf_training_data.zip

Training Environment:
Nvidia - A10 - 24 GB - g5.4xlarge - AWS instance
Packages are installed from the README instructions

Metadata

Metadata

Assignees

No one assigned

    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