Handle starter checkpoints in RFDETR.from_checkpoint when pretrain_weights is unset-like - #1065
Merged
Merged
Conversation
2 tasks
…issing Agent-Logs-Url: https://github.com/roboflow/rf-detr/sessions/a62f584a-ae39-4140-86de-39397f9951d0 Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
Agent-Logs-Url: https://github.com/roboflow/rf-detr/sessions/a62f584a-ae39-4140-86de-39397f9951d0 Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix RFDETR from_checkpoint to load starter weights
Handle starter checkpoints in May 23, 2026
RFDETR.from_checkpoint when pretrain_weights is unset-like
Borda
marked this pull request as ready for review
May 25, 2026 10:04
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ 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:
|
Contributor
There was a problem hiding this comment.
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_weightswithstrip().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_weightsis 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. |
- 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>
Borda
approved these changes
May 25, 2026
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
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>
2 tasks
Merged
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.
Starter weights published for nano/small/medium can fail
RFDETR.from_checkpointinference when checkpoints do not includemodel_nameand storeargs.pretrain_weightsas"none". This updates fallback inference so those checkpoints can be resolved without manual model-class mapping.Checkpoint class inference hardening
RFDETR.from_checkpoint, normalizeargs.pretrain_weightswithstrip().lower()."","none","null") as unresolved and fall back to parsing the checkpoint filename (path) for variant tokens (nano,small,medium, etc.).model_namefirst, then legacy weight-name inference.Regression coverage for missing-like
pretrain_weightstests/models/test_from_checkpoint.pyto verify class resolution from checkpoint filename whenpretrain_weightsis"none","null", or empty.num_classes).Try-instantiate integration coverage
tests/try_instantiate_all_models.pyto round-trip an additional starter-like checkpoint (pretrain_weights="none") per model and verifyfrom_checkpointreturns the expected class.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.comif 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)
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)