# How to configure prepare\_model

**URL:** https://discuss.ray.io/t/how-to-configure-prepare-model/10024
**Category:** Ray Train
**Created:** [April 3, 2023, 5:29am UTC](https://discuss.ray.io/t/how-to-configure-prepare-model/10024 "2023-04-03T05:29:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![AnnnxXXx](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@AnnnxXXx](https://discuss.ray.io/u/AnnnxXXx)
#### Post date: [April 3, 2023, 5:29am UTC](https://discuss.ray.io/t/how-to-configure-prepare-model/10024/1 "2023-04-03T05:29:16Z")

</div>

**How severe does this issue affect your experience of using Ray?**

- High: It blocks me to complete my task.

Code runs to  
When “model=train. task. prepare\_model (model)” is selected, pychar reports an error and outputs the prompt “ray. train. error. SessionMisseError: prepare/accelerate utility functions should be called inside a training function executed by ‘Trainer. run’”. Do I need to write any other code?

---

<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: [April 3, 2023, 5:44am UTC](https://discuss.ray.io/t/how-to-configure-prepare-model/10024/2 "2023-04-03T05:44:50Z")

</div>

Hey, you’ll need to create a `TorchTrainer` to run your code in a distributed fashion.

Can you take a look at the following resources and see if they help?

- [Getting Started with Distributed Model Training in Ray Train — Ray 2.3.0](https://docs.ray.io/en/latest/train/getting-started.html)
- [Distributed Deep Learning with Ray Train User Guide — Ray 2.3.0](https://docs.ray.io/en/latest/train/dl_guide.html)

---

<div class="post-metadata">

### Author: ![AnnnxXXx](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@AnnnxXXx](https://discuss.ray.io/u/AnnnxXXx)
#### Post date: [April 3, 2023, 7:35am UTC](https://discuss.ray.io/t/how-to-configure-prepare-model/10024/3 "2023-04-03T07:35:41Z")

</div>

I have created a TorchTrainer . But I passed a lot of parameters directly in train\_func, should this be avoided?  
For example, trainer = TorchTrainer(  
train\_func(a,b,c,d,e,f,g),  
scaling\_config=ScalingConfig(use\_gpu=use\_gpu, num\_workers=2)  
)

---

<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: [April 3, 2023, 1:51pm UTC](https://discuss.ray.io/t/how-to-configure-prepare-model/10024/4 "2023-04-03T13:51:41Z")

</div>

Yeah, if you do that then it will be executing `train_func(a,b,c,d,e,f,g)` and passing the result to `TorchTrainer`, rather than the function itself!

You _could_ try something like:

```python
def updated_train_func():
    return train_func(a,b,c,d,e,f,g)

trainer = TorchTrainer(
    updated_train_func, # note that there is no ()
    scaling_config=ScalingConfig(use_gpu=use_gpu, num_workers=2)
)

```

However, keep in mind that the whole function is serialized, so if any of the parameters `a,b,c,d,e,f,g` are large (e.g. a dataset or a model), it would be a good idea to initialize them within the training function directly!

---

<div class="post-metadata">

### Author: ![AnnnxXXx](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@AnnnxXXx](https://discuss.ray.io/u/AnnnxXXx)
#### Post date: [April 3, 2023, 2:06pm UTC](https://discuss.ray.io/t/how-to-configure-prepare-model/10024/5 "2023-04-03T14:06:42Z")

</div>

Ok, thank you very much for your answer, I will try to modify it!
