Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ray] Fix datasets_modules ImportError with Ray Tune #12749

Merged
merged 2 commits into from
Jul 19, 2021

Conversation

Yard1
Copy link
Contributor

@Yard1 Yard1 commented Jul 15, 2021

What does this PR do?

This PR fixes an ImportError throws due to datasets_modules not being loaded on Ray Actors when tuning hyperparamters with Ray, fixing the following issues:
huggingface/blog#106
huggingface/transformers#11565
https://discuss.huggingface.co/t/using-hyperparameter-search-in-trainer/785/34
https://discuss.huggingface.co/t/using-hyperparameter-search-in-trainer/785/35

Fixes #11565

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@Yard1
Copy link
Contributor Author

Yard1 commented Jul 15, 2021

@richardliaw @pvcastro

Comment on lines +266 to +271
dynamic_modules_path = os.path.join(datasets.load.init_dynamic_modules(), "__init__.py")
# load dynamic_modules from path
spec = importlib.util.spec_from_file_location("datasets_modules", dynamic_modules_path)
datasets_modules = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = datasets_modules
spec.loader.exec_module(datasets_modules)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to use runtime environments here instead? just curious

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not without editing Ray Tune itself as it would need to be added to an Actor option in trial executor. Also it doesn't appear you can actually import a module from path in a runtime env (only pip and conda), unless I missed that in the docs

@Yard1 Yard1 changed the title [ray] Fix dynamic_modules ImportError with Ray Tune [ray] Fix datasets_modules ImportError with Ray Tune Jul 15, 2021
Comment on lines +266 to +270
dynamic_modules_path = os.path.join(datasets.load.init_dynamic_modules(), "__init__.py")
# load dynamic_modules from path
spec = importlib.util.spec_from_file_location("datasets_modules", dynamic_modules_path)
datasets_modules = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = datasets_modules
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another comment: should this be moved upstream to datasets eventually?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it belongs there. The actual import needs to somewhere in Tune, and here is the most convenient place

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK that's fine then.

Copy link
Collaborator

@richardliaw richardliaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great to me :)

@pvcastro
Copy link

Great! @richardliaw , another approval is still required?

@richardliaw
Copy link
Collaborator

@sgugger @LysandreJik could you help take a look :)

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this!

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@LysandreJik LysandreJik merged commit cab3b86 into huggingface:master Jul 19, 2021
@Yard1 Yard1 deleted the fix_ray_dynamic_modules branch July 19, 2021 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hyperparameter_search raytune: ModuleNotFoundError: No module named 'datasets_modules'
5 participants