In Hydra 1.0, when a config file is loaded, if a config with a matching name and group is present in the ConfigStore
,
it is used as the schema for the newly loaded config.
There are several problems with this approach:
- Inflexible: This approach can only be used when a schema should validate a single config file. It does not work if you want to use the same schema to validate multiple config files.
- Unexpected: This behavior can be unexpected. There is no way to tell this is going to happen when looking at a given config file.
Hydra 1.1 deprecates this behavior in favor of an explicit config extension via the Defaults List.
This upgrade page aims to provide a summary of the required changes. It is highly recommended that you read the following pages:
Migrationβ
Before the upgrade, you have two different configs with the same name (a config file, and a Structured Config in the ConfigStore
).
You need to rename one of them. Depending on the circumstances and your preference you may rename one or the other.
- If you control both configs, you can rename either of them.
- If you only control the config file, rename it.
Option 1: rename the Structured Configβ
This option is less disruptive. Use it if you control the Structured Config.
- Use a different name when storing the schema into the Config Store. Common choices:
base_
prefix, e.g.base_mysql
._schema
suffix, e.g.mysql_schema
.
- Add the schema to the Defaults List of the extending config file.
Click to show an example
Hydra 1.0β
# @package _group_
host: localhost
port: 3306
@dataclass
class MySQLConfig:
host: str
port: int
cs = ConfigStore.instance()
cs.store(group="db",
name="mysql",
node=MySQLConfig)
Hydra 1.1β
defaults:
- base_mysql
host: localhost
port: 3306
@dataclass
class MySQLConfig:
host: str
port: int
cs = ConfigStore.instance()
cs.store(group="db",
name="base_mysql",
node=MySQLConfig)
Option 2: rename the config fileβ
This option is a bit more disruptive. Use it if you only control the config file.
- Rename the config file. Common choices are
custom_
ormy_
prefix, e.g.custom_mysql.yaml
. You can also use a domain specific name likeprod_mysql.yaml
. - Add the schema to the Defaults List of the extending config file.
- Update references to the config name accordingly, e.g. on the command-line
db=mysql
would becomedb=custom_mysql
, and in a defaults listdb: mysql
would becomedb: custom_mysql
.
Click to show an example
Hydra 1.0β
# @package _group_
host: localhost
port: 3306
defaults:
- db: mysql
@dataclass
class MySQLConfig:
host: str
port: int
cs = ConfigStore.instance()
cs.store(group="db",
name="mysql",
node=MySQLConfig)
Hydra 1.1β
Rename db/mysql.yaml
to db/custom_mysql.yaml
and explicitly add the schema to the Defaults List.
defaults:
- mysql
host: localhost
port: 3306
defaults:
- db: custom_mysql
NO CHANGES
Don't forget to also update your command line overrides from db=mysql
to db=custom_mysql
.