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

(WIP) Enable instantiation from globals #2518

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

felipemello1
Copy link
Contributor

Context

What is the purpose of this PR? Is it to

  • add a new feature
  • fix a bug
  • update tests and/or documentation
  • other (please add here)

Before this PR, you couldn't instantiate 'my_local_function', .e.g. in a script or a jupyter notebook. We only supported functions that were importable. Now you can do this

def my_local_function():
    return 0
config = {"foo": "_component_": "my_local_function"}
foo = instantiate(config)

TODO: need to test it in notebooks.

Test plan

  • Unit test
  • Ran a recipe

Copy link

pytorch-bot bot commented Mar 19, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchtune/2518

Note: Links to docs will display an error until the docs builds have been completed.

❌ 3 New Failures, 3 Cancelled Jobs

As of commit 2e7e122 with merge base 1241231 (image):

NEW FAILURES - The following jobs have failed:

CANCELLED JOBS - The following jobs were cancelled. Please retry:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 19, 2025
@felipemello1 felipemello1 changed the title Enable instantiation from globals (WIP) Enable instantiation from globals Mar 19, 2025
@felipemello1 felipemello1 marked this pull request as draft March 19, 2025 18:56
@felipemello1 felipemello1 mentioned this pull request Mar 19, 2025
4 tasks
Comment on lines +65 to +67
>>> # Assuming FooBar is defined in caller's globals
>>> _get_component_from_path("FooBar", globals())
<class 'SetupDataset'>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

todo: fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants