# Passing in model to optuna

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fpassing-in-model-to-optuna%2F24052%3E%5C
**Category:** Beginners\
**Created:** [October 6, 2022, 2:44am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fpassing-in-model-to-optuna%2F24052 "2022-10-06T02:44:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Satyen](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@Satyen](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FSatyen)%5C
**Post date:** [October 6, 2022, 2:44am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fpassing-in-model-to-optuna%2F24052%2F1 "2022-10-06T02:44:36Z")

</div>

Hello all! One of the things I would like to see is which pretrained model from huggingface works best for my dataset. I would like to pass in the different model names as one of the parameters to optimize on to Optuna. How can I integrate that with the HuggingFace Trainer?

For example if you want to test out different models such as “base-base-uncased” or “roberta-base” or “mpnet-base-v2” etc.

I currently have it set up like this:

```auto
epochs = trial.suggest_categorical("epochs", EPOCHS)
    batch_size = trial.suggest_categorical("batch_size", BATCH_SIZE)
    learning_rate = trial.suggest_categorical("learning_rate", LEARNING_RATES)
    scheduler = trial.suggest_categorical("scheduler", SCHEDULERS)
    model_name = trial.suggest_categorical("model_name", MODEL_NAMES)
    
    hp_space = {
        "model_name": model_name,
        "batch_size": batch_size,
        "learning_rate": learning_rate,
        "scheduler": scheduler,
        "epochs": epochs,
    }

```

I am not sure how to pass this in correctly to Trainer

---

<div class="post-metadata">

**Author:** ![ravitejac](https://avatars.discourse-cdn.com/v4/letter/r/71e660/32.png) [@ravitejac](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fravitejac)%5C
**Post date:** [October 7, 2022, 8:52pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fpassing-in-model-to-optuna%2F24052%2F2 "2022-10-07T20:52:09Z")

</div>

Modifying the model\_init function as below should help

```auto
MODEL_NAMES=[“base-base-uncased” , “roberta-base” , “mpnet-base-v2”]
def model_init(params):
    model_name=MODEL_NAMES[0]
    if params is not None:
        model_name=params['model_name']
    return your_model(model_name)

```
