Skip to content

Handle starter checkpoints in RFDETR.from_checkpoint when pretrain_weights is unset-like - #1065

Merged
Borda merged 13 commits into
developfrom
copilot/fix-weight-loading-checkpoint
May 25, 2026
Merged

Borda merged 13 commits into
developfrom
copilot/fix-weight-loading-checkpoint

Conversation

Copilot AI commented May 23, 2026

Copy link
Copy Markdown
Contributor

Starter weights published for nano/small/medium can fail RFDETR.from_checkpoint inference when checkpoints do not include model_name and store args.pretrain_weights as "none". This updates fallback inference so those checkpoints can be resolved without manual model-class mapping.

  • Checkpoint class inference hardening

    • In RFDETR.from_checkpoint, normalize args.pretrain_weights with strip().lower().
    • Treat missing-like values ("", "none", "null") as unresolved and fall back to parsing the checkpoint filename (path) for variant tokens (nano, small, medium, etc.).
    • Keeps existing priority order: model_name first, then legacy weight-name inference.
  • Regression coverage for missing-like pretrain_weights

    • Added tests in tests/models/test_from_checkpoint.py to verify class resolution from checkpoint filename when pretrain_weights is "none", "null", or empty.
    • Asserts constructor receives expected checkpoint-derived arguments (num_classes).
  • Try-instantiate integration coverage

    • Extended tests/try_instantiate_all_models.py to round-trip an additional starter-like checkpoint (pretrain_weights="none") per model and verify from_checkpoint returns the expected class.
# new fallback behavior (conceptual)
weights_name = str(args.get("pretrain_weights", "")).strip().lower()
if weights_name in {"", "none", "null"}:
    weights_name = os.path.basename(os.fspath(path)).lower()
# continue existing variant token matching against weights_name

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • pypi.nvidia.com
    • Triggering command: `/home/REDACTED/.cache/uv/builds-v0/.tmpncZhiZ/bin/python /home/REDACTED/.cache/uv/builds-v0/.tmpncZhiZ/bin/python -c import sys

if sys.path[0] == "":
sys.path.pop(0)

sys.path = [] + sys.path

import wheel_stub.buildapi as backend

wheel_filename = backend.build_wheel("/home/REDACTED/.cache/uv/builds-v0/.tmpsdGozi", {}, None)
with open("/home/REDACTED/.cache/uv/builds` (dns block)

  • Triggering command: `/home/REDACTED/.cache/uv/builds-v0/.tmpD7gA2x/bin/python /home/REDACTED/.cache/uv/builds-v0/.tmpD7gA2x/bin/python -c import sys

if sys.path[0] == "":
sys.path.pop(0)

sys.path = [] + sys.path

import wheel_stub.buildapi as backend

wheel_filename = backend.build_wheel("/home/REDACTED/.cache/uv/builds-v0/.tmplt0ION", {}, None)
with open("/home/REDACTED/.cache/uv/builds` (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix RFDETR from_checkpoint to load starter weights Handle starter checkpoints in RFDETR.from_checkpoint when pretrain_weights is unset-like May 23, 2026
Copilot finished work on behalf of Borda May 23, 2026 21:48
Copilot AI requested a review from Borda May 23, 2026 21:48
@Borda
Borda marked this pull request as ready for review May 25, 2026 10:04
@Borda
Borda requested a review from SkalskiP as a code owner May 25, 2026 10:04
Copilot AI review requested due to automatic review settings May 25, 2026 10:04
@codecov

codecov Bot commented May 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77%. Comparing base (83c82aa) to head (9411e78).
⚠️ Report is 1 commits behind head on develop.

❌ Your project check has failed because the head coverage (77%) 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   #1065   +/-   ##
=======================================
  Coverage       77%     77%           
=======================================
  Files          102     102           
  Lines         9032    9047   +15     
=======================================
+ Hits          6966    6979   +13     
- Misses        2066    2068    +2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 hardens RFDETR.from_checkpoint model-class inference for “starter” checkpoints that omit model_name and store an unset-like args.pretrain_weights (e.g. "none"), enabling inference without manual model-class mapping.

Changes:

  • Normalize pretrain_weights with strip().lower() and treat {"", "none", "null"} as unresolved, falling back to parsing the checkpoint filename.
  • Add unit regression coverage ensuring fallback to checkpoint filename when pretrain_weights is missing-like.
  • Extend the integration “try instantiate all models” script to round-trip a starter-like checkpoint per model.

Reviewed changes

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

File Description
src/rfdetr/detr.py Makes checkpoint class inference more robust by normalizing pretrain_weights and falling back to checkpoint basename parsing when it’s unset-like.
tests/models/test_from_checkpoint.py Adds regression coverage for missing-like pretrain_weights values and validates inferred class + forwarded num_classes.
tests/try_instantiate_all_models.py Adds an additional from-checkpoint round-trip using a starter-like checkpoint name/args to validate end-to-end inference.

Comment thread src/rfdetr/detr.py Outdated
Comment thread tests/models/test_from_checkpoint.py Outdated
Comment thread tests/try_instantiate_all_models.py Outdated
Borda and others added 8 commits May 25, 2026 18:11
- Expand from_checkpoint docstring: describe model_name → pretrain_weights →
  checkpoint filename fallback chain with starter-weights rationale
- Update Raises: mention checkpoint filename as third inference source
- Clarify inline comment at fallback branch

---
Co-authored-by: Claude Code <noreply@anthropic.com>
…variants

Extend parametrize for pretrain_weights fallback test:
- Add whitespace-padded cases ("  None  ", "  ", " null ") — guard against
  future .strip() removal silently breaking normalisation
- Add Python None case — str(None).lower() == "none" hits sentinel set
- Use pytest.param(..., id=...) for readable test IDs

---
Co-authored-by: Claude Code <noreply@anthropic.com>
Starter checkpoint round-trip is resolution-independent; running it for
every resolution variant doubles CI time without adding coverage.
Add test_starter kwarg to _test_from_checkpoint; pass test_starter=(res is None)
at the call site so it runs only at default resolution.

---
Co-authored-by: Claude Code <noreply@anthropic.com>
Silent fallback is a misclassification footgun — short tokens like "base"
match any filename containing that string.  Emit logger.info with the
inferred class name, checkpoint path, and matched filename so users can
spot wrong-class loads immediately without digging into shape errors.

---
Co-authored-by: Claude Code <noreply@anthropic.com>
Namespace (argparse) checkpoints went untested through the new fallback
code path.  Add 7-case parametrized test in TestFromCheckpointNamespaceArgs
mirroring the existing dict-args variant.

---
Co-authored-by: Claude Code <noreply@anthropic.com>
…back

os.fspath(bytes_path) returns bytes; os.path.basename(bytes) is bytes and
the subsequent substring check fails with TypeError.  str(path) always
yields a str, consistent with the constructor_kwargs assignment at line 412.

---
Co-authored-by: Claude Code <noreply@anthropic.com>
"none" in checkpoint args is a PTL serialisation of Python None, not an
intentional "no pretraining" flag.  Document this distinction and the
role of each sentinel value inline.

---
Co-authored-by: Claude Code <noreply@anthropic.com>
…fallback

Two missing cases through the new fallback code path:
- ValueError when filename contains no known model token (finetuned.pth)
- ImportError when filename implies xlarge but rfdetr_plus not installed

---
Co-authored-by: Claude Code <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread src/rfdetr/detr.py Outdated
Comment thread src/rfdetr/detr.py Outdated
Comment thread tests/models/test_from_checkpoint.py
Borda and others added 2 commits May 25, 2026 19:46
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Borda
Borda merged commit 27b9d23 into develop May 25, 2026
26 checks passed
@Borda
Borda deleted the copilot/fix-weight-loading-checkpoint branch May 25, 2026 20:01
Borda added a commit that referenced this pull request May 28, 2026
…_weights` is unset-like (#1065)

* fix: infer model variant from checkpoint filename when pretrain tag missing
* test: cover starter-like checkpoint fallback paths
* docs(detr): document 3-tier inference order in from_checkpoint
* test(from_checkpoint): guard .strip() via whitespace-padded sentinel variants
* test(try_instantiate): run starter-like checkpoint test once per class
* refine(detr): log inferred model class when filename-fallback fires
* test(from_checkpoint): cover Namespace-args path of filename fallback
* fix(detr): use str(path) instead of os.fspath(path) for filename fallback
* docs(detr): clarify sentinel set semantics for pretrain_weights fallback
* test(from_checkpoint): cover ValueError and ImportError via filename-fallback

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
Co-authored-by: Claude Code <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Borda Borda mentioned this pull request Jun 16, 2026
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.

[1.7.0] RFDETR.from_checkpoint cannot load starter weights (nano,small,medium)

3 participants