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

nested instantiation #2519

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

Conversation

felipemello1
Copy link
Contributor

@felipemello1 felipemello1 commented Mar 19, 2025

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)

Enable nested instantiation, e.g.

from omegaconf import OmegaConf
from torchtune.config import instantiate


class Spice:
    def __init__(self, heat_level):
        self.heat_level = heat_level


class Food:
    def __init__(self, seed, ingredient):
        self.seed = seed
        self.ingredient = ingredient


config = OmegaConf.create(
    {
        "_component_": "Food",
        "seed": 0,
        "ingredient": {"_component_": "Spice", "heat_level": 5},
    }
)
food = instantiate(config, seed=42)
print(food.seed)  # 42
print(food.ingredient.heat_level)  # 5
new_spice = {"_component_": "Spice", "heat_level": 10}
food = instantiate(config, ingredient=new_spice)
print(food.ingredient.heat_level)  # 10

Test plan

Unit test is blocked by #2518

Sorry, something went wrong.

Felipe Mello added 2 commits March 19, 2025 11:57
Copy link

pytorch-bot bot commented Mar 19, 2025

🔗 Helpful Links

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

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

❌ 2 New Failures, 4 Cancelled Jobs

As of commit ddad6f3 with merge base c370348 (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
@ebsmothers
Copy link
Contributor

I understand the motivation here, but at this point why not just use Hydra?

@felipemello1
Copy link
Contributor Author

felipemello1 commented Mar 19, 2025

I understand the motivation here, but at this point why not just use Hydra?

bigger PR, but i think we should

@felipemello1 felipemello1 marked this pull request as draft March 19, 2025 19:29
@RdoubleA
Copy link
Contributor

bigger PR, but i think we should

I'm bout to flip

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.

None yet

4 participants