# Hyperparameter tuning using Trainer not getting same performance

**URL:** <https://discuss.huggingface.co/t/hyperparameter-tuning-using-trainer-not-getting-same-performance/38351>\
**Category:** 🤗Transformers\
**Created:** [May 1, 2023, 10:46pm UTC](https://discuss.huggingface.co/t/hyperparameter-tuning-using-trainer-not-getting-same-performance/38351 "2023-05-01T22:46:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nitigoel303](https://avatars.discourse-cdn.com/v4/letter/n/48db29/32.png) [@nitigoel303](https://discuss.huggingface.co/u/nitigoel303)\
**Post date:** [May 1, 2023, 10:46pm UTC](https://discuss.huggingface.co/t/hyperparameter-tuning-using-trainer-not-getting-same-performance/38351/1 "2023-05-01T22:46:39Z")

</div>

I am doing hyperparameter tuning as suggested in below link [Hyperparameter Search using Trainer API (huggingface.co)](https://huggingface.co/docs/transformers/hpo_train).

After tuning, when I try to train the model with best parameters I am not getting the same performance.

the best trial - Trial 2 finished with value: 0.8181818181818182 and parameters: {‘weight\_decay’: 0.18182315978815689, ‘learning\_rate’: 2.8534508921816434e-05, ‘warmup\_steps’: 83}. Best is trial 2 with value: 0.8181818181818182.

Training with best parameters -  
model = AutoModelForSequenceClassification.from\_pretrained(“distilbert-base-uncased”, num\_labels=2)  
training\_args = TrainingArguments(output\_dir=“test\_trainer”, evaluation\_strategy=“epoch”,num\_train\_epochs=1,per\_device\_train\_batch\_size=32,per\_device\_eval\_batch\_size=32,weight\_decay=0.18182315978815689, learning\_rate= 2.8534508921816434e-05, warmup\_steps=83)  
trainer = CustomTrainer(  
#model=model,  
args=training\_args,  
train\_dataset=tokenized\_train\_dataset,  
eval\_dataset=tokenized\_test\_dataset,  
compute\_metrics=compute\_metrics,  
model\_init=model\_init  
)  
trainer.train()

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/2X/7/7c6f6c1c57fa7e807bfdf044bcce55cf98205c53.png)
