Visitar URL original
Add missing RunnerConfig field by C-Achard · Pull Request #3557 · DeepLabCut/DeepLabCut · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions deeplabcut/pose_estimation_pytorch/config/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class RunnerConfig(DLCBaseConfig):
optimizer: Optimizer configuration
scheduler: Scheduler configuration
snapshots: Snapshot configuration
load_scheduler_state_dict: Whether to load the scheduler state when
resuming training from a snapshot
load_weights_only: Value for torch.load() weights_only parameter
"""

Expand All @@ -81,4 +83,5 @@ class RunnerConfig(DLCBaseConfig):
scheduler: SchedulerConfig | None = None
snapshots: SnapshotCheckpointConfig | None = None
snapshot_prefix: str | None = None
load_scheduler_state_dict: bool = True
load_weights_only: bool | None = None
31 changes: 31 additions & 0 deletions tests/pose_estimation_pytorch/config/test_runner_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# DeepLabCut Toolbox (deeplabcut.org)
# © A. & M.W. Mathis Labs
# https://github.com/DeepLabCut/DeepLabCut
#
# Please see AUTHORS for contributors.
# https://github.com/DeepLabCut/DeepLabCut/blob/main/AUTHORS
#
# Licensed under GNU Lesser General Public License v3.0
#
"""Tests for RunnerConfig validation."""

from __future__ import annotations

import pytest

from deeplabcut.pose_estimation_pytorch.config.runner import RunnerConfig


@pytest.mark.parametrize("value", [True, False])
def test_accepts_load_scheduler_state_dict(value: bool) -> None:
"""Regression test for #3556: the documented key was rejected as extra."""
cfg = RunnerConfig.from_dict({"type": "PoseTrainingRunner", "load_scheduler_state_dict": value})
assert cfg.load_scheduler_state_dict is value
assert cfg.to_dict()["load_scheduler_state_dict"] is value


def test_load_scheduler_state_dict_defaults_to_true() -> None:
"""The default matches the fallback used when building the training runner."""
cfg = RunnerConfig.from_dict({"type": "PoseTrainingRunner"})
assert cfg.load_scheduler_state_dict is True
Loading