AttributeError: 'AdamW' object has no attribute 'train'
Author: AbdulmohsenA
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.45.0.dev0
- Platform: Windows-10-10.0.19045-SP0
- Python version: 3.11.9
- Huggingface_hub version: 0.25.0    
- Safetensors version: 0.4.4
- Accelerate version: 0.33.0
- Accelerate config:    not found
- PyTorch version (GPU?): 2.4.0+cu118 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using distributed or parallel set-up in script?: False
- Using GPU in script?: True
- GPU type: NVIDIA GeForce GTX 1060 6GB

The issue does not seem to be from the hardware, as I also tried the same code on Kaggle's notebook and yielded the same error.

### Who can help?

@SunMarc

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [X] My own task or dataset (give details below)

### Reproduction

the code:
```python
# Instantiating The Model
model_name = "Abdulmohsena/Faseeh"

tokenizer = AutoTokenizer.from_pretrained(model_name, src_lang="eng_Latn", tgt_lang="arb_Arab")
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
generation_config = GenerationConfig.from_pretrained(model_name)

from transformers import Seq2SeqTrainingArguments, Seq2SeqTrainer
train_batch_size = 4
torch.cuda.empty_cache()

# https://huggingface.co/docs/transformers/v4.44.2/performance
training_args = Seq2SeqTrainingArguments(
    output_dir=f"{model_name}",
    save_total_limit=3,
    load_best_model_at_end=True,

    per_device_train_batch_size=train_batch_size,
    per_device_eval_batch_size=train_batch_size,
    gradient_accumulation_steps=16 // train_batch_size,
    gradient_checkpointing=True,
    # torch_compile=True,
    
    logging_strategy="steps",
    logging_steps=500,
    
    save_strategy='steps',
    
    eval_strategy='steps',
    metric_for_best_model="bertscore-f1",
    greater_is_better=True,
    
    weight_decay=0.01,
    warmup_steps=1_000,
    learning_rate=3e-5,
    lr_scheduler_type="cosine",
    
#     remove_unused_columns=True,  # required as the PeftModel forward doesn't have the signature of the wrapped model's forward
#     label_names=["labels"],  # same reason as above
    
    num_train_epochs=2,
    
    predict_with_generate=True,
    fp16=True,
    
    push_to_hub=True,
    report_to='wandb'
)

trainer = Seq2SeqTrainer(
    model=model,
    args=training_args,
    train_dataset=tokenized_dataset["train"],
    eval_dataset=tokenized_dataset["test"],
    tokenizer=tokenizer,
    data_collator=data_collator,
    compute_metrics=compute_metrics,
)

model.config.use_cache = False

trainer.train()
```

```
AttributeError                            Traceback (most recent call last)
Cell In[30], [line 3](vscode-notebook-cell:?execution_count=30&line=3)
      [1](vscode-notebook-cell:?execution_count=30&line=1) from datetime import datetime
      [2](vscode-notebook-cell:?execution_count=30&line=2) # wandb.init(project="Faseeh", name=f"Run @ {datetime.now()}")
----> [3](vscode-notebook-cell:?execution_count=30&line=3) trainer.train()
      [4](vscode-notebook-cell:?execution_count=30&line=4) # wandb.finish()

File d:\anaconda\envs\Faseeh\Lib\site-packages\transformers\trainer.py:2012, in Trainer.train(self, resume_from_checkpoint, trial, ignore_keys_for_eval, **kwargs)
   [2009](file:///D:/anaconda/envs/Faseeh/Lib/site-packages/transformers/trainer.py:2009) try:
   [2010](file:///D:/anaconda/envs/Faseeh/Lib/site-packages/transformers/trainer.py:2010)     # Disable progress bars when uploading models during checkpoints to avoid polluting stdout
   [2011](file:///D:/anaconda/envs/Faseeh/Lib/site-packages/transformers/trainer.py:2011)     hf_hub_utils.disable_progress_bars()
-> [2012](file:///D:/anaconda/envs/Faseeh/Lib/site-packages/transformers/trainer.py:2012)     return inner_training_loop(
   [2013](file:///D:/anaconda/envs/Faseeh/Lib/site-packages/transformers/trainer.py:2013)         args=args,
   [2014](file:///D:/anaconda/envs/Faseeh/Lib/site-packages/transformers/trainer.py:2014)         resume_from_checkpoint=resume_from_checkpoint,
   [2015](file:///D:/anaconda/envs/Faseeh/Lib/site-packages/transformers/trainer.py:2015)         trial=trial,
   [2016](file:///D:/anaconda/envs/Faseeh/Lib/site-packages/transformers/trainer.py:2016)         ignore_keys_for_eval=ignore_keys_for_eval,
   [2017](file:///D:/anaconda/envs/Faseeh/Lib/site-packages/transformers/trainer.py:2017)     )
   [2018](file:///D:/anaconda/envs/Faseeh/Lib/site-packages/transformers/trainer.py:2018) finally:
   [2019](file:///D:/anaconda/envs/Faseeh/Lib/site-packages/transformers/trainer.py:2019)     hf_hub_utils.enable_progress_bars()

File d:\anaconda\envs\Faseeh\Lib\site-packages\transformers\trainer.py:2357, in Trainer._inner_training_loop(self, batch_size, args, resume_from_checkpoint, trial, ignore_keys_for_eval)
   [2354](file:///D:/anaconda/envs/Faseeh/Lib/site-packages/transformers/trainer.py:2354)     self.control = self.callback_handler.on_step_begin(args, self.state, self.control)
   [2356](file:///D:/anaconda/envs/Faseeh/Lib/site-packages/transformers/trainer.py:2356) with self.accelerator.accumulate(model):
-> [2357](file:///D:/anaconda/envs/Faseeh/Lib/site-packages/transformers/trainer.py:2357)     tr_loss_step = self.training_step(model, inputs)
...
    [126](file:///D:/anaconda/envs/Faseeh/Lib/site-packages/accelerate/optimizer.py:126)     Sets the optimizer to "train" mode. Useful for optimizers like `schedule_free`
    [127](file:///D:/anaconda/envs/Faseeh/Lib/site-packages/accelerate/optimizer.py:127)     """
--> [128](file:///D:/anaconda/envs/Faseeh/Lib/site-packages/accelerate/optimizer.py:128)     return self.optimizer.train()

AttributeError: 'AdamW' object has no attribute 'train'
```

The reason I am using 4.45 is that the training gives me an error when I want to Quantize and use LoRA in my model, I get the error: 
```
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn
```

### Expected behavior

The training to commence successfuly

Comments:
@AbdulmohsenA were you able to figure out what caused the error? Looks like its new in v4.45 of transformers and v4.44.2 doesn't have it

Updating `accelerate` to `0.34.2` solves this problem.

accelerate 0.34.2 and more recent version of transformers also gave me the same issue. But, using 
accelerate version 0.34.2
transformers version 4.45.0 
solved this problem.