# Making Custom Python Modules Available in RayTune Workers

**URL:** <https://discuss.ray.io/t/making-custom-python-modules-available-in-raytune-workers/15018>\
**Category:** Uncategorized\
**Created:** [June 20, 2024, 9:33pm UTC](https://discuss.ray.io/t/making-custom-python-modules-available-in-raytune-workers/15018 "2024-06-20T21:33:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxpiasevoli](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@maxpiasevoli](https://discuss.ray.io/u/maxpiasevoli)\
**Post date:** [June 20, 2024, 9:33pm UTC](https://discuss.ray.io/t/making-custom-python-modules-available-in-raytune-workers/15018/1 "2024-06-20T21:33:13Z")

</div>

Hello, I’m trying to run hyperparameter tuning via Tuner.fit() and I’m encountering an error because all of my model logic is written in a custom python module on my local machine that can’t be found in the workers. I’ve tried specifying the local\_dir parameter of the Tuner run\_config parameter, but that did not fix the issue. I also tried importing all necessary classes and functions within my train function, but that’s not working.

Any references or suggestions?

---

<div class="post-metadata">

**Author:** ![Sam\_Chan](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sam_chan/32/5011_2.png) [@Sam\_Chan](https://discuss.ray.io/u/Sam_Chan)\
**Post date:** [June 21, 2024, 12:05am UTC](https://discuss.ray.io/t/making-custom-python-modules-available-in-raytune-workers/15018/2 "2024-06-21T00:05:45Z")

</div>

Can you share the error?

---

<div class="post-metadata">

**Author:** ![maxpiasevoli](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@maxpiasevoli](https://discuss.ray.io/u/maxpiasevoli)\
**Post date:** [June 21, 2024, 1:06pm UTC](https://discuss.ray.io/t/making-custom-python-modules-available-in-raytune-workers/15018/3 "2024-06-21T13:06:18Z")

</div>

Yep, here’s the error:

```auto
Traceback (most recent call last):
  File "python/ray/_raylet.pyx", line 1883, in ray._raylet.execute_task
  File "python/ray/_raylet.pyx", line 1984, in ray._raylet.execute_task
  File "python/ray/_raylet.pyx", line 1889, in ray._raylet.execute_task
  File "python/ray/_raylet.pyx", line 1830, in ray._raylet.execute_task.function_executor
  File "/anaconda/envs/azureml_py38/lib/python3.8/site-packages/ray/_private/function_manager.py", line 724, in actor_method_executor
    return method(__ray_actor, *args, **kwargs)
  File "/anaconda/envs/azureml_py38/lib/python3.8/site-packages/ray/_private/function_manager.py", line 636, in temporary_actor_method
    raise RuntimeError(
RuntimeError: The actor with name ImplicitFunc failed to import on the worker. This may be because needed library dependencies are not installed in the worker environment:

Traceback (most recent call last):
  File "/anaconda/envs/azureml_py38/lib/python3.8/site-packages/ray/_private/function_manager.py", line 675, in _load_actor_class_from_gcs
    actor_class = pickle.loads(pickled_class)
ModuleNotFoundError: No module named 'randomwalk_analysis'

```

And if it helps, here’s a snippet of my raytune training setup. I’m effectively running this code in a main.py and importing my train function from a submodule within randomwalk\_analysis. The train function utilizes a variety of datasets, dataloaders, and torch models also defined in in randomwalk\_analysis.model.

```auto
from randomwalk_analysis.model import train_model_raytune

trainable = tune.with_parameters(train_model_raytune, *other parameters*)
    trainable_with_cpu_gpu = tune.with_resources(
        trainable, 
        {"cpu": args.num_workers, "gpu": args.num_gpus}
    )
    tuner = tune.Tuner(
        trainable_with_cpu_gpu,
        param_space=param_space,
        tune_config=tune.TuneConfig(
            num_samples=args.num_samples,
            scheduler=ASHAScheduler(
                metric="val_loss", 
                mode="min",
                max_t=args.max_epochs,
                grace_period=args.grace_period,
                reduction_factor=args.reduction_factor
            )
        ),
        run_config=RunConfig(local_dir=*absolute path to local directory containing randomwalk_analysis*)
    )
    result = tuner.fit()

```
