Skip to content

[dev] C2 - Add typed configs as pydantic dataclasses & omegaconf dictconfigs#3191

Merged
deruyter92 merged 9 commits intofeat/structured_configsfrom
jaap/add_typed_configs
Feb 4, 2026
Merged

[dev] C2 - Add typed configs as pydantic dataclasses & omegaconf dictconfigs#3191
deruyter92 merged 9 commits intofeat/structured_configsfrom
jaap/add_typed_configs

Conversation

@deruyter92
Copy link
Collaborator

@deruyter92 deruyter92 commented Jan 29, 2026

This PR is part of the WIP for migrating from dictionary configs to typed & validated configurations (see #3193 for an overview). (Credits to @arashsm79 for originally introducing these changes).

Motivation
Introduces typed, validated config classes (Pydantic + OmegaConf) and a shared ConfigMixin for project and pose configs. Replaces ad-hoc dicts with a consistent load/save/validation API and better type support.

Changes:

  • Core: ConfigMixin, ProjectConfig, and utils (moved from core/config.py). New core/types.py with PydanticNDArray.
  • Weight init: WeightInitialization is a Pydantic dataclass using ConfigMixin; snapshot_path optional; conversion_array typed as PydanticNDArray.
  • Pose PyTorch: New typed configs in pose_estimation_pytorch/config/ (data, inference, logger, model, pose, project, runner, training). GenSamplingConfig moved from data/generative_sampling.py to config/data.py. Inference config classes moved from runners/inference.py to config/inference.py; inference runner uses InferenceConfig.from_any().
  • Deps: omegaconf>=2.3.0, pydantic>=2.12.3.
  • Tests: tests/core/config/test_config_mixin.py for ConfigMixin.

Notes:

  • The typed configurations are not yet used in the pipeline, but implemented in parallel as part of the work-in-progress.
  • The typed configurations in this PR mimic the structure of the older dictionary configs (same fields) to facilitate easy migration. These will be updated later.

@deruyter92 deruyter92 force-pushed the jaap/add_typed_configs branch 3 times, most recently from 59b4623 to 5c950a5 Compare January 30, 2026 13:05
@deruyter92 deruyter92 force-pushed the jaap/add_typed_configs branch from 5c950a5 to d58be73 Compare January 30, 2026 14:02
@deruyter92 deruyter92 added WORK IN PROGRESS! developers are currently working on this feature... stay tuned. enhancement New feature or request labels Feb 2, 2026
@deruyter92 deruyter92 marked this pull request as ready for review February 2, 2026 10:33
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 introduces typed, validated configuration classes using Pydantic and OmegaConf to replace dictionary-based configurations. The changes establish a foundation for better type safety and validation while maintaining backward compatibility with existing dictionary structures.

Changes:

  • Adds ConfigMixin base class providing common config operations (load, save, validate, convert)
  • Implements typed config classes for project, data, model, training, runner, inference, and logger configurations
  • Migrates WeightInitialization and GenSamplingConfig to use Pydantic dataclasses
  • Adds omegaconf>=2.3.0 and pydantic>=2.12.3 as dependencies

Reviewed changes

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

Show a summary per file
File Description
tests/core/config/test_config_mixin.py Comprehensive test coverage for ConfigMixin functionality
setup.py Adds omegaconf and pydantic dependencies
deeplabcut/pose_estimation_pytorch/runners/inference.py Removes InferenceConfig classes (moved to config module)
deeplabcut/pose_estimation_pytorch/data/generative_sampling.py Removes GenSamplingConfig (moved to config/data.py)
deeplabcut/pose_estimation_pytorch/data/dataset.py Updates import for GenSamplingConfig
deeplabcut/pose_estimation_pytorch/data/base.py Updates import for GenSamplingConfig
deeplabcut/pose_estimation_pytorch/data/init.py Updates import for GenSamplingConfig
deeplabcut/pose_estimation_pytorch/config/training.py Adds TrainSettingsConfig dataclass
deeplabcut/pose_estimation_pytorch/config/runner.py Adds OptimizerConfig, SchedulerConfig, SnapshotCheckpointConfig, and RunnerConfig
deeplabcut/pose_estimation_pytorch/config/project.py Adds typed ProjectConfig matching old dictionary structure
deeplabcut/pose_estimation_pytorch/config/pose.py Adds main PoseConfig with enums for method and network types
deeplabcut/pose_estimation_pytorch/config/model.py Adds ModelConfig and DetectorModelConfig
deeplabcut/pose_estimation_pytorch/config/logger.py Adds LoggerConfig classes for WandB and CSV loggers
deeplabcut/pose_estimation_pytorch/config/inference.py Adds typed inference config classes
deeplabcut/pose_estimation_pytorch/config/data.py Adds data config classes including GenSamplingConfig
deeplabcut/pose_estimation_pytorch/init.py Updates import for GenSamplingConfig
deeplabcut/core/weight_init.py Converts WeightInitialization to Pydantic dataclass with ConfigMixin
deeplabcut/core/types.py Adds PydanticNDArray type alias for numpy array support
deeplabcut/core/config/project_config.py Adds core ProjectConfig (duplicate of pose_estimation_pytorch version)
deeplabcut/core/config/config_mixin.py Implements ConfigMixin base class
deeplabcut/core/config/init.py Exports config utilities and classes

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

@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 changed the title Add typed configs as pydantic dataclasses & omegaconf dictconfigs [dev] C2 - Add typed configs as pydantic dataclasses & omegaconf dictconfigs Feb 3, 2026
@deruyter92 deruyter92 added this to the Structured configs milestone Feb 3, 2026
Base automatically changed from jaap/centralize_project_configs to feat/structured_configs February 4, 2026 08:40
deruyter92 and others added 9 commits February 4, 2026 09:45
This mixin provides methods for:
    - Loading configurations from dictionaries or YAML files
    - Validating configuration data against pydantic models
    - Converting configurations to dictionaries
    - Pretty printing configuration data

add imports from utils
- Introduced new configuration classes for inference, logging, model, pose, project, runner, and training settings.
- Refactored data loading mechanisms to utilize new configuration structures.
- Moved the multithreading and compilation options in inference configuration to the config module.
- Typed configuration for logging.
- Updated dataset loaders to accept model configurations directly or via file paths.
(The fields are kept identical to old multianimal project configs for now)

move ProjectConfig to deeplabcut/core/config
The return value should be the dictionary, not the instantiated transforms
@deruyter92 deruyter92 force-pushed the jaap/add_typed_configs branch 2 times, most recently from e00941b to 120aedc Compare February 4, 2026 08:57
@deruyter92 deruyter92 merged commit defdd32 into feat/structured_configs Feb 4, 2026
1 check failed
@deruyter92 deruyter92 deleted the jaap/add_typed_configs branch February 4, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request WORK IN PROGRESS! developers are currently working on this feature... stay tuned.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants