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

[Feature Request] Looking for overriding the group parameter in config #2956

Closed
foreverYoungGitHub opened this issue Sep 17, 2024 · 3 comments
Labels
enhancement Enhanvement request

Comments

@foreverYoungGitHub
Copy link

🚀 Feature Request

Looking for overriding the group parameter in config.

Motivation

Is your feature request related to a problem? Please describe.

Yes, this feature request is related to a problem I am encountering with configuration management. When I have a main config file and an experiment config file, I want to override the group parameter defined in the main file. For example:

In the main file:

model:
  loss:
    _target_: a
    param_1: 0

In the experiment file:

model:
  loss:
    _target_: b
    param_2: 0

Currently, it seems that the parameters from the main file are not fully overridden by the experiment file, resulting in a merged configuration that includes both param_1 and param_2. This is problematic because param_1 is not supported by _target_: b.

Pitch

Describe the solution you'd like

I would like a feature that allows the full override of a group parameter in the configuration. Specifically, when running with the experiment config file, the loss parameter should only contain param_2 and not param_1, as param_1 is not supported by _target_: b.

Describe alternatives you've considered

An alternative solution could be to add a special parameter like _override_ that explicitly indicates that the group parameter should be fully overridden. For example:

model:
  loss:
    _override_: true
    _target_: b
    param_2: 0

Are you willing to open a pull request? (See CONTRIBUTING)
Yes, I am willing to open a pull request to implement this feature.

Additional context

Add any other context or screenshots about the feature request here.

This feature would greatly simplify configuration management in scenarios where different experiment configurations need to fully override parameters defined in a main config file. It would help avoid conflicts and ensure that only the relevant parameters for the specified target are included.

Thank you for considering this feature request!

@foreverYoungGitHub foreverYoungGitHub added the enhancement Enhanvement request label Sep 17, 2024
@qsh-zh
Copy link

qsh-zh commented Nov 22, 2024

This feature would be very useful! @jesszzzz @omry

Does anyone have another solution to bypass the default behavior?

@omry
Copy link
Collaborator

omry commented Nov 22, 2024

Use config composition.
Do not include use-case specific defaults in your base config, but compose them in.
e.g.:
config.yaml:

defaults:
  - model: a

model/a.yaml:

loss:
  _target_: a
  param_1: 0

model/b.yaml:

loss:
  _target_: b
  param_2: 0

experiment/b_with_99.yaml:

# @package _global_
defaults:
  - override /model: b

loss:
  param_2: 99

@omry omry closed this as completed Nov 22, 2024
@qsh-zh
Copy link

qsh-zh commented Nov 22, 2024

Hi @omry thank you for your response.

Indeed, what your propose a good practice for above case. However, there are many cases that enable to delete inherated config group is help. For example, the config experiment/a_param1_9_with_other_config_override and config experiment/b_param2_10_with_other_config_override only diffs on model group. Let experiment/b_param2_10_with_other_config_override inherite from experiment/a_param1_9_with_other_config_override and only change model group will help reduce lots of duplicated code for other_config_override.

I have being using hydra / omegaconf for more than 3 years. #2993 has a good example. My colleagues and I want this feature~(inheritate for most of config but totally override one group) for a long time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhanvement request
Projects
None yet
Development

No branches or pull requests

3 participants