# TypeErrors when passing search spaces to trainable function

**URL:** https://discuss.ray.io/t/typeerrors-when-passing-search-spaces-to-trainable-function/4591
**Category:** Ray Tune
**Created:** [January 5, 2022, 8:30pm UTC](https://discuss.ray.io/t/typeerrors-when-passing-search-spaces-to-trainable-function/4591 "2022-01-05T20:30:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![DomByrne](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/dombyrne/32/1902_2.png) [@DomByrne](https://discuss.ray.io/u/DomByrne)
#### Post date: [January 5, 2022, 8:30pm UTC](https://discuss.ray.io/t/typeerrors-when-passing-search-spaces-to-trainable-function/4591/1 "2022-01-05T20:30:17Z")

</div>

I’m trying to use ray tune to train a pytorch model and I get type errors, suggesting that the whole search space distribution is being passed to the function rather than actual values from the distribution?

Code excerpts:  
#search space  
config = {  
‘hidden\_size’: tune.sample\_from(lambda \_: 2 \*\* np.random.randint(7, 10)),  
‘num\_hidden’: tune.sample\_from(lambda \_: np.arange(1,5)),  
‘lr’: tune.loguniform(1e-4, 1e-1),  
‘batch\_size’: tune.sample\_from(lambda \_: 2 \*\* np.random.randint(7, 10))  
}

result = tune.run(  
partial(train\_model, config, checkpoint\_dir),  
resources\_per\_trial={“cpu”: cpus\_per\_trial, “gpu”: gpus\_per\_trial},  
config=config,  
num\_samples=num\_resamples,  
max\_concurrent\_trials=max\_concurrent,  
scheduler=scheduler,  
progress\_reporter=reporter,  
fail\_fast=‘raise’  
)

The most relevant portion of the error message:  
File “/Users/dombyrne/phd/synthetic\_genotypes/src/synthetic\_geno\_nn\_cls.py”, line 87, in train\_model  
model = MLP(config[‘hidden\_size’], config[‘num\_hidden’], config[‘input\_size’])  
File “/Users/dombyrne/phd/synthetic\_genotypes/src/synthetic\_geno\_nn\_cls.py”, line 44, in **init**  
l\_sizes = [input\_size] + [hidden\_size] \* int(num\_hidden) + [output\_size]  
TypeError: int() argument must be a string, a bytes-like object or a number, not ‘Categorical’

I’ve tried reinstalling tune using pip, which makes no difference. I’m using ray version 1.9.0.

Best wishes,  
Dom

---

<div class="post-metadata">

### Author: ![matthewdeng](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/matthewdeng/32/1446_2.png) [@matthewdeng](https://discuss.ray.io/u/matthewdeng)
#### Post date: [January 5, 2022, 8:38pm UTC](https://discuss.ray.io/t/typeerrors-when-passing-search-spaces-to-trainable-function/4591/2 "2022-01-05T20:38:12Z")

</div>

Hey @DomByrne,

What happens if you just specify `train_model` as the trainable function?

```diff
- partial(train_model, config, checkpoint_dir),
+ train_model,

```

Tune should generate the configuration and pass it into `train_model` during execution.

---

<div class="post-metadata">

### Author: ![DomByrne](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/dombyrne/32/1902_2.png) [@DomByrne](https://discuss.ray.io/u/DomByrne)
#### Post date: [January 6, 2022, 3:53pm UTC](https://discuss.ray.io/t/typeerrors-when-passing-search-spaces-to-trainable-function/4591/3 "2022-01-06T15:53:41Z")

</div>

That works, thank you!
