# Ray Tune Error Help

**URL:** <https://discuss.ray.io/t/ray-tune-error-help/3923>\
**Category:** Ray Tune\
**Created:** [October 25, 2021, 7:40pm UTC](https://discuss.ray.io/t/ray-tune-error-help/3923 "2021-10-25T19:40:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GMCobraz\_T](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/gmcobraz_t/32/1647_2.png) [@GMCobraz\_T](https://discuss.ray.io/u/GMCobraz_T)\
**Post date:** [October 25, 2021, 7:40pm UTC](https://discuss.ray.io/t/ray-tune-error-help/3923/1 "2021-10-25T19:40:09Z")

</div>

Dear all,  
I encountered an error as per image.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/ray/original/2X/b/b61c34a185d7a6f237f420d8ee1f6df7bf21ca8a.png)

Here are part of my code:  
config = {

```
"n_hidden_size": 64,

"kernel_size": 3,

"lr": 1e-4,

"batch_size": 32

```

}

def train\_class\_tune\_checkpoint(config, checkpoint\_dir=None, num\_epochs=10):

kwargs = {

```
  "max_epochs": num_epochs,

  "gpus": 1,

  "logger": TensorBoardLogger(

      save_dir=tune.get_trial_dir(), name="", version="."),

  "progress_bar_refresh_rate": 0,

  "callbacks": [

      TuneReportCheckpointCallback(

          metrics={"loss": "val_loss", "mean_accuracy": "val_accuracy"},

          filename="checkpoint",

          on="validation_end")

  ]

```

}

if checkpoint\_dir:

```
    kwargs["resume_from_checkpoint"] = os.path.join(

        checkpoint_dir, "checkpoint")

```

model = Classification(config, num\_inputs = 3, n\_classes = 4, n\_layer=4)

data\_module = VehicleDataModule(final\_train, final\_test, config)

data\_module.setup()

trainer = pl.Trainer(\*\*kwargs)

trainer.fit(model, data\_module)

def tune\_class\_pbt(num\_samples, num\_epochs):

config = {

```
"n_hidden_size": tune.choice([32, 64, 128]),

"kernel_size": 3,

"lr": 1e-3,

"batch_size": 64,

```

}

scheduler = PopulationBasedTraining(

```
    perturbation_interval=4,

    hyperparam_mutations={

        "lr": tune.loguniform(1e-4, 1e-1),

        "batch_size": [32, 64, 128]

    })

```

reporter = CLIReporter(

```
    parameter_columns=["n_hidden_size", "lr", "batch_size"],

    metric_columns=["loss", "mean_accuracy", "training_iteration"])

```

analysis = tune.run(

```
    tune.with_parameters(

        train_class_tune_checkpoint,

        num_epochs=num_epochs,

        num_gpus=1),

    resources_per_trial={

        "cpu": 1,

        "gpu": 1

    },

    metric="loss",

    mode="min",

    config=config,

    num_samples=num_samples,

    scheduler=scheduler,

    progress_reporter=reporter,

    name="tune_class_pbt")

```

print("Best hyperparameters found were: ", analysis.best\_config)

tune\_class\_pbt(10, 10)

I used tune.with\_parameters, but why I still encounter that error?  
May I know how to use ray.put?

Thanks

---

<div class="post-metadata">

**Author:** ![xwjiang2010](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/xwjiang2010/32/1476_2.png) [@xwjiang2010](https://discuss.ray.io/u/xwjiang2010)\
**Post date:** [October 26, 2021, 6:32pm UTC](https://discuss.ray.io/t/ray-tune-error-help/3923/2 "2021-10-26T18:32:52Z")

</div>

Some piece of the code is missing so I can’t really run it. I wonder if you could refactor `train_class_tune_checkpoint` a little bit. For example take out data\_module and pass it as an argument?  
I think `tune.with_parameters` is probably the right approach here. One note about it is it only `ray.put` the rest of the kwargs other than `train_class_tune_checkpoint` itself. It will only be meaningful after you refactor some stuff from function signature into arguments.
