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][example] Extending SC Schema for Experiments #71

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

Conversation

romesco
Copy link
Contributor

@romesco romesco commented Apr 16, 2021

This is very preliminary for the time being. I have a couple more ideas to simplify, but I want to make sure we think through this carefully (including naming conventions, folder structure, etc.).

@addisonklinke I would love to see your approach to doing this purely with dataclasses as well

First draft example can be run by:

# ensure you have hydra-core>=1.1.0.dev4 
cd examples/extend_via_sc_as_schema
python extend_via_schema.py optim=adam_exp_1

Feel free to provide any and all feedback.

@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 Apr 16, 2021
@romesco
Copy link
Contributor Author

romesco commented Apr 16, 2021

I think there are at least 3 meaningful examples to work on:
1.) Barebones, configuring just one thing (like the optimizer)
2.) Full MNIST configuration.
3.) Training framework like Lightning or similar.

@romesco romesco changed the title [example] Extending SC Schema for Experiments [WIP][example] Extending SC Schema for Experiments Apr 17, 2021
@@ -0,0 +1,26 @@
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
Copy link
Contributor

Choose a reason for hiding this comment

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

something.py?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you caught me vimmin'


cs = ConfigStore.instance()
cs.store(name="base_config", node=Config)
cs.store(group="optim", name="base_adam", node=AdamConf)
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have a way for the user to get the config registered? (something like hydra_configs.torch.register_configs()?`
Why are you registering it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you implying we consolidate lines 10-18 into a single call:
hydra_configs.torch.register_configs()?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not exactly.
Registering a schema for your own config is one thing (line 17), but registering AdamConf (and the rest of the configs hydra-torch is providing) is something we can provide a function (or functions as we have discussed) to do.

This app:

  • defines its own Config class.
  • registers it
  • registers a config class defined by the library.
    I am suggesting that registering config classes defined by the library will be done by the library and will be triggered with a function call.

This will enforce a consistent naming convention for the registered classes and will reduce the boilerplate required to use the configs package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, I agree. I'll make a quick PR for the registration. Then we can use that in this example.

@addisonklinke
Copy link

@romesco Here's my approach for pure dataclasses. I'm not sure whether this would be considered best practice in Hydra - it sounds like typically MyDatamoduleConf would be a YAML file validated by the structured config schema instead of its own SC. My thinking was the concrete config would be better as a SC since they provide type safety

from dataclasses import dataclass
from omegaconf import MISSING


@dataclass
class DatamoduleConf:
    """Schema definition to be extended by all concrete datamodules"""
    _target_: str = MISSING
    batch_size: int = MISSING
    num_workers: int = -1

@dataclass
class MyDatamoduleConf(DatamoduleConf):
    """Projects should extend the datamodule schema above"""
    _target_: str = 'project.data.MyDatamodule'  # Required override
    batch_size: int = 100                        # Required override
    crop_dir: str = MISSING                      # New requirement added by the extension
    regions: bool = False                        # New default added by the extension

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.

4 participants