# \[Ray\] How to get the best model per trial

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fray-how-to-get-the-best-model-per-trial%2F11155%3E%5C
**Category:** 🤗Transformers\
**Created:** [October 28, 2021, 9:01am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fray-how-to-get-the-best-model-per-trial%2F11155 "2021-10-28T09:01:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rai](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@Rai](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FRai)%5C
**Post date:** [October 28, 2021, 9:01am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fray-how-to-get-the-best-model-per-trial%2F11155%2F1 "2021-10-28T09:01:36Z")

</div>

Hi everyone,

I’m trying to use the feature “hyperparameter\_search” but cannot get the best model per the trial. Each trial always get the last value.

I see the code line here calling the Ray tune function to get the best model without the “scope” parameter passed. Default value of that function is “last”.

> <https://github.com/huggingface/transformers/blob/123cce6ffcafe6ecece7eb9914395d2ebcc98a48/src/transformers/integrations.py#L294>

Is there any way to workaround this?

Thanks!

---

<div class="post-metadata">

**Author:** ![DaniTypeform](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/danitypeform/32/3228_2.png) [@DaniTypeform](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FDaniTypeform)%5C
**Post date:** [November 18, 2021, 11:10am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fray-how-to-get-the-best-model-per-trial%2F11155%2F2 "2021-11-18T11:10:21Z")

</div>

Thanks for raising this.

I am having the same problem with the Optuna backend.
