refactor: BuilderArgs Protocol + ModelConfig/TrainConfig field deduplication#841
Open
refactor: BuilderArgs Protocol + ModelConfig/TrainConfig field deduplication#841
Conversation
…ication (PR 4) Item #7 — BuilderArgs Protocol: - Add `src/rfdetr/models/_types.py` with `@runtime_checkable BuilderArgs Protocol` documenting the minimum attribute set for `build_model()` and `build_criterion_and_postprocessors()`. - Annotate both builder functions with `args: "BuilderArgs"`. - Export `BuilderArgs` from `rfdetr.models.__all__`. Item #3 Phase A — field ownership deprecation warnings: - `TrainConfig.group_detr`, `.ia_bce_loss`, `.segmentation_head`, `.num_select` emit `DeprecationWarning` when explicitly set (ownership moves to `ModelConfig` in v1.9). - `ModelConfig.cls_loss_coef` emits `DeprecationWarning` when explicitly set (ownership moves to `TrainConfig` in v1.9). - Fix `_namespace.py`: `num_select` always reads from `ModelConfig` (fixes the silent regression where `TrainConfig.num_select=300` overrode model-specific values of 100–200). - Fix `_namespace.py`: `cls_loss_coef` reads from `TrainConfig` by default, with backward-compat fallback to `ModelConfig` when explicitly set there and not on `TrainConfig` (Phase A transitional logic; Codex-supplied fix). Tests: 20 new tests — Protocol structural checks, all 4 cls_loss_coef precedence combinations, num_select regression guard, per-field deprecation warnings. Co-Authored-By: Codex <noreply@openai.com> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…cope comment - CHANGELOG: add [Unreleased] section with BuilderArgs addition, 5 deprecated TrainConfig/ModelConfig fields (v1.9 removal), and num_select regression fix. - _types.py: add comment explaining why decoder_norm / dropout / num_feature_levels are intentionally absent from BuilderArgs (they are computed constants, not caller-supplied values). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a typed BuilderArgs protocol for model builder functions and implements/validates a Phase A transition of config field ownership between ModelConfig and TrainConfig (with deprecation warnings), including fixing num_select precedence in the builder namespace.
Changes:
- Added
BuilderArgs(typing.Protocol) and annotatedbuild_model()/build_criterion_and_postprocessors()to accept it; exported viarfdetr.models. - Added
DeprecationWarningemission when deprecated fields are explicitly set on the “wrong” config object. - Updated
_namespace.build_namespace()to sourcenum_selectfromModelConfigunconditionally and to apply transitional precedence forcls_loss_coef; expanded tests and changelog accordingly.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/rfdetr/models/_types.py |
Adds BuilderArgs Protocol describing builder inputs. |
src/rfdetr/models/lwdetr.py |
Annotates builder functions to accept BuilderArgs. |
src/rfdetr/models/__init__.py |
Re-exports BuilderArgs from rfdetr.models. |
src/rfdetr/config.py |
Adds model/train config validators that emit deprecation warnings for field ownership transitions. |
src/rfdetr/_namespace.py |
Fixes namespace forwarding for num_select and implements transitional cls_loss_coef precedence logic. |
tests/test_namespace.py |
Adds tests for BuilderArgs satisfaction and for field ownership/precedence rules. |
tests/training/test_args.py |
Updates tests to expect deprecation warnings for explicit deprecated field usage. |
tests/models/test_config.py |
Adds coverage for deprecation warnings and non-warning defaults behavior. |
CHANGELOG.md |
Documents the new Protocol, deprecations, and the num_select regression fix under Unreleased. |
Comments suppressed due to low confidence (1)
src/rfdetr/models/lwdetr.py:356
build_model()is now typed as takingBuilderArgs, but later in this function it mutatesargs(e.g. settingargs.num_feature_levels). If the stated goal is to eventually passModelConfig/TrainConfigdirectly, Pydantic configs forbid setting undeclared attributes, so this will break at runtime. Prefer computing derived values locally (or building a separate mutable namespace) instead of mutating the incomingargs.
def build_model(args: "BuilderArgs"):
# the `num_classes` naming here is somewhat misleading.
# it indeed corresponds to `max_obj_id + 1`, where max_obj_id
# is the maximum id for a class in your dataset. For example,
# COCO has a max_obj_id of 90, so we pass `num_classes` to be 91.
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project check has failed because the head coverage (76%) is below the target coverage (95%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #841 +/- ##
======================================
Coverage 75% 76%
======================================
Files 92 93 +1
Lines 7148 7222 +74
======================================
+ Hits 5383 5457 +74
Misses 1765 1765 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Item #7 — BuilderArgs Protocol:
src/rfdetr/models/_types.pywith@runtime_checkable BuilderArgs Protocoldocumenting the minimum attribute set for
build_model()andbuild_criterion_and_postprocessors().args: "BuilderArgs".BuilderArgsfromrfdetr.models.__all__.Item #3 Phase A — field ownership deprecation warnings:
TrainConfig.group_detr,.ia_bce_loss,.segmentation_head,.num_selectemit
DeprecationWarningwhen explicitly set (ownership moves toModelConfigin v1.9).
ModelConfig.cls_loss_coefemitsDeprecationWarningwhen explicitly set(ownership moves to
TrainConfigin v1.9)._namespace.py:num_selectalways reads fromModelConfig(fixes thesilent regression where
TrainConfig.num_select=300overrode model-specificvalues of 100–200).
_namespace.py:cls_loss_coefreads fromTrainConfigby default, withbackward-compat fallback to
ModelConfigwhen explicitly set there and not onTrainConfig(Phase A transitional logic; Codex-supplied fix).Type of Change
Testing
Additional Context