DeepSpeed: AttributeError: 'FP16_DeepSpeedZeroOptimizer' object has no attribute 'ipg_index'
Hi, I want use DeepSpeed to speed my transformer , and I came across such problem:
File "main.py", line 460, in <module>
main(args)
File "main.py", line 392, in main
train_stats = train_one_epoch(
File "/opt/ml/code/deepspeed/engine.py", line 57, in train_one_epoch
loss_scaler(loss, optimizer, clip_grad=clip_grad, clip_mode=clip_mode,
File "/usr/local/lib/python3.8/dist-packages/timm/utils/cuda.py", line 43, in __call__
self._scaler.scale(loss).backward(create_graph=create_graph)
File "/usr/local/lib/python3.8/dist-packages/torch/tensor.py", line 245, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs)
File "/usr/local/lib/python3.8/dist-packages/torch/autograd/__init__.py", line 145, in backward
Variable._execution_engine.run_backward(
File "/usr/local/lib/python3.8/dist-packages/deepspeed/runtime/zero/stage2.py", line 661, in reduce_partition_and_remove_grads
self.reduce_ready_partitions_and_remove_grads(param, i)
File "/usr/local/lib/python3.8/dist-packages/deepspeed/runtime/zero/stage2.py", line 1104, in reduce_ready_partitions_and_remove_grads
self.reduce_independent_p_g_buckets_and_remove_grads(param, i)
File "/usr/local/lib/python3.8/dist-packages/deepspeed/runtime/zero/stage2.py", line 724, in reduce_independent_p_g_buckets_and_remove_grads
new_grad_tensor = self.ipg_buffer[self.ipg_index].narrow(
AttributeError: 'FP16_DeepSpeedZeroOptimizer' object has no attribute 'ipg_index'
My config.json is as follows:
{
"gradient_accumulation_steps": 1,
"train_micro_batch_size_per_gpu":1,
"steps_per_print": 100,
"optimizer": {
"type": "Adam",
"params": {
"lr": 0.00001,
"weight_decay": 1e-2
}
},
"flops_profiler": {
"enabled": false,
"profile_step": 100,
"module_depth": -1,
"top_modules": 3,
"detailed": true
},
"fp16": {
"enabled": true,
"loss_scale": 0,
"loss_scale_window": 1000,
"initial_scale_power": 18,
"hysteresis": 2,
"min_loss_scale": 1
},
"zero_optimization": {
"stage": 1,
"cpu_offload": false,
"contiguous_gradients": true,
"overlap_comm": true,
"reduce_scatter": true,
"reduce_bucket_size":1e8,
"allgather_bucket_size": 5e8
},
"activation_checkpointing": {
"partition_activations": false,
"contiguous_memory_optimization": false,
"cpu_checkpointing": false
},
"gradient_clipping": 1.0,
"wall_clock_breakdown": false,
"zero_allow_untested_optimizer": true
}
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 1
- Comments: 23 (7 by maintainers)
I solved it by using
DeepSpeedEngine.backward(loss)
andDeepSpeedEngine.step()
not torch nativeloss.backward()
andoptimizer.step()
.Hi @jeffra, yes I’m experiencing the same issue. Here is the error I get:
And here is my config file:
I got the same issue. But fixed by remove a redundant backward.
And this code is from chatGPT, so it is excusable.
Well, let me join this thread too… Have the same issue as described above
The code I run can be found here: https://github.com/BlinkDL/RWKV-LM/blob/main/RWKV-v4/train.py
Configuration I use
Traceback:
“stage”: 2 > “stage”:1 Solved