Repository navigation
Closed
Description
Hi.
I'm trying to use deepspeed in my code with multiple models, but got an error like below. Do you have any idea to solve this issue? Thanks in advance.
File "train_ds.py", line 98, in <module>
solver = Solver(opt)
File "/data2/1konny/svg/solver_ds.py", line 40, in __init__
self.init_models_and_optimizers()
File "/data2/1konny/svg/solver_ds.py", line 117, in init_models_and_optimizers
self.decoder, self.decoder_optimizer, _, _ = ds.initialize(opt, model=decoder, model_parameters=decoder_params)
File "/usr/local/lib/python3.6/dist-packages/deepspeed/__init__.py", line 87, in initialize
collate_fn=collate_fn)
File "/usr/local/lib/python3.6/dist-packages/deepspeed/pt/deepspeed_light.py", line 123, in __init__
dist.init_process_group(backend="nccl")
File "/usr/local/lib/python3.6/dist-packages/torch/distributed/distributed_c10d.py", line 372, in init_process_group
raise RuntimeError("trying to initialize the default process group "
RuntimeError: trying to initialize the default process group twice!
ds_config.json
{
"train_batch_size": 4,
"gradient_accumulation_steps": 1,
"steps_per_print": 1,
"optimizer": {
"type": "Adam",
"params": {
"lr": 0.0001,
"max_grad_norm": 1.0,
"betas": [
0.9,
0.999
]
}
}
}
command-line
deepspeed train_ds.py --deepspeed --deepspeed_config deepspeed_util/ds_config.json ...
code
training_data = load_dataset()
encoder_params = filter(lambda p: p.requires_grad, encoder.parameters())
decoder_params = filter(lambda p: p.requires_grad, decoder.parameters())
self.encoder, self.encoder_optim, train_loader, _ = deepspeed.initialize(opt, model=encoder, model_parameters=encoder_params, training_data=training_data)
self.decoder, self.decoder_optim, _, _ = deepspeed.initialize(opt, model=decoder, model_parameters=decoder_params)
Metadata
Metadata
Assignees
Labels
No labels
Activity
1Konny commentedon Feb 12, 2020
I modified my code as below and the issue does not appear now, but I wonder this is fine.
Also, following this tutorial, I changed my training code as below, which also throws an error:
RuntimeError: Trying to backward through the graph a second time, but the buffers have already been freed. Specify retain_graph=True when calling backward the first time.I couldn't find a way to set an option like
retrain_graph=True, so now I changed my code as below and do not see any errors, but still wonder if this is the right way to use deepspeed.So I would greatly appreciate if you could provide us a tutorial when there are multiple models to be trained. Thanks!
tjruwase commentedon Feb 12, 2020
This error message suggests to me that nccl initialization had occurred earlier in your code before the first call to deepspeed.initialize(). Can you confirm that? If this is the case, can you try setting dist_init_required=False in all the deepspeed.initialize() calls?
jeffra commentedon Feb 15, 2020
Hi @1Konny, have you tried anything further with this issue?
1Konny commentedon Feb 15, 2020
Hi all, sorry for the late response.
this initialization issue has been fixed in my case as I commented. I set
dist_init_required=Truewhen initializing the first model engine, and setdist_init_required=Falsefor the rest. Now it works like a charm.when I set
dist_init_requires=Falsein all deepspeed.initialize() calls,raise RuntimeError("trying to initialize the default process group "occurs since I conjecture there is no any other deepspeed.initialize() calls in my codes.[downstream] merge from upstream 96d0765 (20220831) (deepspeedai#65)
Merge azure branch manually (deepspeedai#65)