# I am facing some error, when I SFTTrainer

**URL:** <https://discuss.huggingface.co/t/i-am-facing-some-error-when-i-sfttrainer/44865>\
**Category:** 🤗Transformers\
**Created:** [June 28, 2023, 4:35pm UTC](https://discuss.huggingface.co/t/i-am-facing-some-error-when-i-sfttrainer/44865 "2023-06-28T16:35:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Imran1](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/imran1/32/18779_2.png) [@Imran1](https://discuss.huggingface.co/u/Imran1)\
**Post date:** [June 28, 2023, 4:35pm UTC](https://discuss.huggingface.co/t/i-am-facing-some-error-when-i-sfttrainer/44865/1 "2023-06-28T16:35:29Z")

</div>

hy, when i start training they showing the following error.

`trainer.train()`

here is the error  
**RuntimeError: unscale\_() has already been called on this optimizer since the last update().**

> 

| Step | Training Loss |
| --- | --- |

```
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮│in\<cell line: 1\>:1││││/usr/local/lib/python3.10/dist-packages/transformers/trainer.py:1645intrain││││1642 │ │ inner_training_loop = find_executable_batch_size(││1643 │ │ │ self._inner_training_loop,self._train_batch_size, args.auto_find_batch_size││1644 │ │ )││❱ 1645│ │ returninner_training_loop(││1646 │ │ │ args=args,││1647 │ │ │ resume_from_checkpoint=resume_from_checkpoint,││1648 │ │ │ trial=trial,││││/usr/local/lib/python3.10/dist-packages/transformers/trainer.py:1987in\_inner\_training\_loop││││1984 │ │ │ │ │ │ │ │ args.max_grad_norm,││1985 │ │ │ │ │ │ │ )││1986 │ │ │ │ │ │ else:││❱ 1987│ │ │ │ │ │ │ self.accelerator.clip_grad_norm_(││1988 │ │ │ │ │ │ │ │ model.parameters(),││1989 │ │ │ │ │ │ │ │ args.max_grad_norm,││1990 │ │ │ │ │ │ │ )││││/usr/local/lib/python3.10/dist-packages/accelerate/accelerator.py:1893inclip\_grad\_norm\_││││1890 │ │ │ # `accelerator.backward(loss)` is doing that automatically. Therefore, its i││1891 │ │ │ # We cannot return the gradient norm because DeepSpeed does it.││1892 │ │ │ returnNone││❱ 1893│ │ self.unscale_gradients()││1894 │ │ returntorch.nn.utils.clip_grad_norm_(parameters, max_norm, norm_type=norm_type)││1895 │ ││1896 │ defclip\_grad\_value\_(self, parameters, clip_value):││││/usr/local/lib/python3.10/dist-packages/accelerate/accelerator.py:1856inunscale\_gradients││││1853 │ │ │ foroptinoptimizer:││1854 │ │ │ │ whileisinstance(opt, AcceleratedOptimizer):││1855 │ │ │ │ │ opt = opt.optimizer││❱ 1856│ │ │ │ self.scaler.unscale_(opt)││1857 │ ││1858 │ defclip\_grad\_norm\_(self, parameters, max_norm, norm_type=2):││1859 │ │ """││││/usr/local/lib/python3.10/dist-packages/torch/cuda/amp/grad\_scaler.py:275inunscale\_││││272 │ │ optimizer_state =self._per_optimizer_states[id(optimizer)]││273 │ │ ││274 │ │ ifoptimizer_state["stage"]isOptState.UNSCALED:││❱ 275│ │ │ raiseRuntimeError("unscale\_() has already been called on this optimizer sin││276 │ │ elifoptimizer_state["stage"]isOptState.STEPPED:││277 │ │ │ raiseRuntimeError("unscale\_() is being called after step().")││278 │╰──────────────────────────────────────────────────────────────────────────────────────────────────╯RuntimeError: unscale\_()has already been called on this optimizer since the lastupdate().
```

---

<div class="post-metadata">

**Author:** ![muellerzr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/muellerzr/32/21583_2.png) [@muellerzr](https://discuss.huggingface.co/u/muellerzr)\
**Post date:** [June 28, 2023, 5:58pm UTC](https://discuss.huggingface.co/t/i-am-facing-some-error-when-i-sfttrainer/44865/2 "2023-06-28T17:58:40Z")

</div>

Try installing from main, should be fixed there:

`!pip install git+https://github.com/huggingface/transformers git+https://github.com/huggingface/accelerate`
