# Need help with Optimizer Error!

**URL:** <https://discuss.pytorch.org/t/need-help-with-optimizer-error/183323>\
**Category:** Opacus\
**Created:** [July 3, 2023, 2:31am UTC](https://discuss.pytorch.org/t/need-help-with-optimizer-error/183323 "2023-07-03T02:31:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![xie\_huanyi](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/xie_huanyi/32/61815_2.png) [@xie\_huanyi](https://discuss.pytorch.org/u/xie_huanyi)\
**Post date:** [July 3, 2023, 2:31am UTC](https://discuss.pytorch.org/t/need-help-with-optimizer-error/183323/1 "2023-07-03T02:31:59Z")

</div>

I am finetuning a gpt-like model with Opacus. But got an error with the optimizer

```auto
Traceback (most recent call last):
  File "main.py", line 50, in <module>
    main()
  File "main.py", line 47, in main
    args=args
  File "/code/src/finetune.py", line 19, in finetune
    optimizer.step()
  File "/opt/conda/lib/python3.7/site-packages/opacus/optimizers/optimizer.py", line 513, in step
    if self.pre_step():
  File "/opt/conda/lib/python3.7/site-packages/opacus/optimizers/optimizer.py", line 494, in pre_step
    self.clip_and_accumulate()
  File "/opt/conda/lib/python3.7/site-packages/opacus/optimizers/optimizer.py", line 404, in clip_and_accumulate
    per_sample_norms = torch.stack(per_param_norms, dim=1).norm(2, dim=1)
RuntimeError: stack expects each tensor to be equal size, but got [32] at entry 0 and [1] at entry 234

```

But it works fine when I don’t use Opacus. Could anyone help me?
