Skip to content

[dev] C3 - Replace configuration dictionaries with DictConfigs.#3194

Merged
deruyter92 merged 14 commits intofeat/structured_configsfrom
jaap/replace_config_loaders_with_typed
Feb 5, 2026
Merged

[dev] C3 - Replace configuration dictionaries with DictConfigs.#3194
deruyter92 merged 14 commits intofeat/structured_configsfrom
jaap/replace_config_loaders_with_typed

Conversation

@deruyter92
Copy link
Collaborator

@deruyter92 deruyter92 commented Jan 30, 2026

This PR is part of the WIP for migrating from dictionary configs to typed & validated configurations, and follows PR #3191. (see issue #3193 for an overview).

Summary:
Refactors the PyTorch pose pipeline to use typed config classes (PoseConfig, ProjectConfig, ModelConfig) and OmegaConf DictConfig instead of raw dicts.

Main changes:

  • Isolated the logic for loading default model configuration for a given model
  • make_pose_config now creates an OmegaConf DictConfig validated against PoseConfig dataclass
  • internally, the PyTorch Loaders now use PoseConfig DictConfig configurations instead of dictionaries

@deruyter92 deruyter92 force-pushed the jaap/replace_config_loaders_with_typed branch 2 times, most recently from ffdb60a to 9dbd2b3 Compare February 2, 2026 10:54
@deruyter92 deruyter92 changed the title Replace configuration dictionaries with DictConfigs. And add migration system for new versions. Replace configuration dictionaries with DictConfigs. Feb 2, 2026
@deruyter92 deruyter92 force-pushed the jaap/add_typed_configs branch 2 times, most recently from e290a0c to 8b5d13f Compare February 2, 2026 12:32
@deruyter92 deruyter92 force-pushed the jaap/replace_config_loaders_with_typed branch 2 times, most recently from 6c77aad to f3014f1 Compare February 2, 2026 12:52
@deruyter92 deruyter92 marked this pull request as ready for review February 2, 2026 12:54
@deruyter92 deruyter92 marked this pull request as draft February 2, 2026 12:56
@deruyter92 deruyter92 force-pushed the jaap/replace_config_loaders_with_typed branch from f3014f1 to c36ce50 Compare February 2, 2026 13:44
@deruyter92 deruyter92 marked this pull request as ready for review February 2, 2026 13:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the PyTorch pose pipeline from raw dictionaries to typed configuration classes (PoseConfig, ProjectConfig, ModelConfig) with OmegaConf DictConfig support, introducing a config versioning and migration system for backward compatibility.

Changes:

  • Introduced config versioning system with migration support between versions
  • Replaced raw dict configs with typed config classes that validate against Pydantic models
  • Updated loaders and model initialization to use from_any() factory methods for flexible config input

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
deeplabcut/pose_estimation_pytorch/models/model.py Updated PoseModel to accept ModelConfig/DictConfig/dict/Path/str and convert to validated DictConfig
deeplabcut/pose_estimation_pytorch/data/dlcloader.py Refactored DLCLoader to use ProjectConfig with typed validation and OmegaConf for nested access
deeplabcut/pose_estimation_pytorch/data/cocoloader.py Added model_config parameter to replace deprecated model_config_path
deeplabcut/pose_estimation_pytorch/data/base.py Introduced legacy argument handling for model_config_path with deprecation warning
deeplabcut/pose_estimation_pytorch/config/make_pose_config.py Refactored config creation to use typed configs and split defaults loading into separate function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@deruyter92 deruyter92 force-pushed the jaap/replace_config_loaders_with_typed branch from c36ce50 to 9ce60b5 Compare February 3, 2026 08:33
@deruyter92 deruyter92 changed the title Replace configuration dictionaries with DictConfigs. [dev] C3 - Replace configuration dictionaries with DictConfigs. Feb 3, 2026
@deruyter92 deruyter92 added this to the Structured configs milestone Feb 3, 2026
Copy link
Collaborator

@C-Achard C-Achard left a comment

Choose a reason for hiding this comment

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

Overall very good, but I would change/check a few things in this one.

Also to have this written down somewhere, I'd strongly favor checking whether we truly need OmegaConf and its features; I feel we do, even if we do not take full advantage of them yet, but keeping dependencies lean is also a very important consideration imo.

You probably have a better outlook than I do, but another path I see is just making pydantic dataclasses have dict-like access and use that in downstream code.

@deruyter92 deruyter92 force-pushed the jaap/add_typed_configs branch from 7c7f018 to 120aedc Compare February 4, 2026 08:53
Base automatically changed from jaap/add_typed_configs to feat/structured_configs February 4, 2026 09:09
@deruyter92 deruyter92 force-pushed the feat/structured_configs branch 2 times, most recently from f5a825c to 2d3ef49 Compare February 4, 2026 10:14
@deruyter92 deruyter92 force-pushed the jaap/replace_config_loaders_with_typed branch from aa82654 to 1dff963 Compare February 4, 2026 10:44
@deruyter92 deruyter92 force-pushed the feat/structured_configs branch from 2d3ef49 to b5f2fdc Compare February 4, 2026 10:52
@deruyter92 deruyter92 force-pushed the jaap/replace_config_loaders_with_typed branch from 1dff963 to 5272d90 Compare February 4, 2026 10:53
@deruyter92 deruyter92 force-pushed the feat/structured_configs branch from b5f2fdc to fdfec16 Compare February 4, 2026 11:04
@deruyter92 deruyter92 force-pushed the jaap/replace_config_loaders_with_typed branch from 530347a to 4350295 Compare February 5, 2026 15:05
@deruyter92 deruyter92 force-pushed the jaap/replace_config_loaders_with_typed branch from 1d24b90 to 00fd419 Compare February 5, 2026 15:28
The head_cfg (a part of PoseConfig) was used for dumping modules. This is not supported for typed configs.

The container is now replaced with a plain dict type instead of config.
@deruyter92 deruyter92 force-pushed the jaap/replace_config_loaders_with_typed branch from 00fd419 to 94cdc66 Compare February 5, 2026 16:05
@deruyter92
Copy link
Collaborator Author

@C-Achard, some relevant additional changes:

Pathlib and Enum serialization (see 538ca3a and 347ff18):
For the project_path and pose_config_path field, the default type is now changed to Path. For Enums and Paths, the values are stored as plain str when written to yaml file and converted back.

Empty yaml field handling (see b890d6c):
When yaml fields are empty, the field is ignored when reading. Without this, the code would break in several places, but we might want to consider stricter validation in the future, where empty fields are interpreted as None and a ValidationError is raised when None-type values are not allowed.

e.g. ProjectConfig.from_yaml('myconfig.yaml') with the following yaml

# myconfig.yaml
Task: openfield
scorer: Pranav
multianimalproject:
identity:

results in

ProjectConfig(Task='openfield', scorer='Pranav', multianimalproject=False, identity=None, ...)

@deruyter92 deruyter92 merged commit 6c3f4b3 into feat/structured_configs Feb 5, 2026
1 check failed
@deruyter92 deruyter92 deleted the jaap/replace_config_loaders_with_typed branch February 5, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants