ray-project / tune-sklearn

A drop-in replacement for Scikit-Learn’s GridSearchCV / RandomizedSearchCV -- but with cutting edge hyperparameter tuning techniques.
https://docs.ray.io/en/master/tune/api_docs/sklearn.html
Apache License 2.0
465 stars 52 forks source link

TuneSearchCV doesn't seem to search for modules in alternative locations included in the PATH environment variable #267

Closed RNarayan73 closed 1 year ago

RNarayan73 commented 1 year ago

Hello,

I have saved a number of modules within a subdirectory structure (based on releases) of the location containing the main jupyter notebook.

main script/notebook ! !-- build !---- train !------ module1.py !------ module2.py !---- predict !------ module3.py ! !-- stable !---- train !------ module1.py !------ module2.py !---- predict !------ module3.py

Depending upon the release, I append one of these paths i.e. either build > train or stable > train to the PATH variable within my code to select the appropriate modules within the train package. These folders have an init.py to designate them as packages.

The import calls to the modules themselves use "train." as a prefix so for example: from train.module1 import <something>

However, TuneSearchCV doesn't seem to search these paths at all. It only looks at the modules and packages that are stored relative to the main notebook's location like so:

main script/notebook ! !-- train !---- module1.py !---- module2.py !-- predict !---- module3.py

Can you please fix this and have it search for modules within the folders of the PATH variable?

Regards Narayan

Yard1 commented 1 year ago

This is most likely due to how Ray operates (it spawns new python processes, which do not automatically inherit the environment). Try first running ray.init(runtime_env={"env_vars":{"PATH":value}}) before you call any tune-sklearn methods. You can also specify a working_dir in ray.init, which will change the working directory of Ray processes.

RNarayan73 commented 1 year ago

@Yard1 Thanks for the tip. I used the runtime_env argument with the 'PYTHONPATH' variable which I realised stores the paths for python libraries and it worked.