feat(cli): adapt raw rf-detr PyTorch-Lightning checkpoints on upload#488
Draft
leeclemnet wants to merge 1 commit into
Draft
feat(cli): adapt raw rf-detr PyTorch-Lightning checkpoints on upload#488leeclemnet wants to merge 1 commit into
leeclemnet wants to merge 1 commit into
Conversation
7 tasks
leeclemnet
added a commit
to roboflow/rf-detr
that referenced
this pull request
Jun 1, 2026
Add RFDETR.save_upload_bundle(output_dir) — the network-free core of
deploy_to_roboflow that writes weights.pt ({"model": state_dict, "args": args},
args carrying resolution + embedded class_names) and class_names.txt. Refactor
deploy_to_roboflow to call it; net behavior unchanged.
This gives the Roboflow SDK a single, drift-free way to turn raw PyTorch-Lightning
rf-detr checkpoints into a deploy-ready bundle (companion: roboflow/roboflow-python#488).
Also updates TestDeployToRoboflow, whose MagicMock(spec=RFDETR) fixture was
no-op'ing the now-delegated save_upload_bundle; the real method is bound so those
end-to-end regression tests still exercise it.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
318dfbc to
db28572
Compare
leeclemnet
added a commit
to roboflow/rf-detr
that referenced
this pull request
Jun 1, 2026
Add RFDETR.save_upload_bundle(output_dir) — the network-free core of
deploy_to_roboflow that writes weights.pt ({"model": state_dict, "args": args},
args carrying resolution + embedded class_names) and class_names.txt. Refactor
deploy_to_roboflow to call it; net behavior unchanged.
This gives the Roboflow SDK a single, drift-free way to turn raw PyTorch-Lightning
rf-detr checkpoints into a deploy-ready bundle (companion: roboflow/roboflow-python#488).
Also updates TestDeployToRoboflow, whose MagicMock(spec=RFDETR) fixture was
no-op'ing the now-delegated save_upload_bundle; the real method is bound so those
end-to-end regression tests still exercise it.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
leeclemnet
added a commit
to roboflow/rf-detr
that referenced
this pull request
Jun 1, 2026
Add RFDETR.export_for_roboflow(output_dir) — the network-free core of
deploy_to_roboflow that writes weights.pt ({"model": state_dict, "args": args},
args carrying resolution + embedded class_names) and class_names.txt. Creates
output_dir if missing. Refactor deploy_to_roboflow to call it; net behavior
unchanged.
Gives the Roboflow SDK a single, drift-free way to turn raw PyTorch-Lightning
rf-detr checkpoints into a deploy-ready bundle (companion: roboflow/roboflow-python#488).
Also updates TestDeployToRoboflow, whose MagicMock(spec=RFDETR) fixture was
no-op'ing the now-delegated method; the real method is bound so those end-to-end
regression tests still exercise it.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
db28572 to
7150b7c
Compare
Detect a raw PTL rf-detr checkpoint (`pytorch-lightning_version` key) in _process_rfdetr and rebuild it into an upload-ready bundle: lazy-import rfdetr (capability-guarded on RFDETR.export_for_roboflow), load via RFDETR.from_checkpoint, falling back to an SDK-local model_type→class map (_RFDETR_MODEL_TYPE_TO_CLASS — also the single source for the supported-type check) when the checkpoint lacks the metadata rf-detr needs to infer its class, then call export_for_roboflow to write weights.pt (args with resolution) + class_names.txt. The legacy path is unchanged and imports no rfdetr. Depends on rf-detr's export_for_roboflow (roboflow/rf-detr#1086); capability- guarded so it works once that release ships. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
7150b7c to
8f5fc73
Compare
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?
Lets
roboflow upload_modelaccept raw rf-detr PyTorch-Lightning checkpoints (e.g.checkpoint_best_ema.pth) and adapt them into the upload-ready bundle the backend conversion expects.In
_process_rfdetr, after loading the checkpoint:pytorch-lightning_versionkey (_is_ptl_checkpoint).rfdetr(capability-guarded onRFDETR.export_for_roboflow; actionableRuntimeErrorif missing/too old — mirrors the ultralytics/yolo pattern).RFDETR.from_checkpoint(pth), falling back to the SDK-localmodel_type→class map (_RFDETR_MODEL_TYPE_TO_CLASS) when the checkpoint lacks the metadata rf-detr needs to infer its class (nomodel_name/pretrain_weights).model.export_for_roboflow(model_path)writesweights.pt(args withresolution) +class_names.txt.rfdetr.Related Issue(s): Depends on rf-detr's
export_for_roboflow— roboflow/rf-detr#1086. Capability-guarded, so it merges independently and works end-to-end once that rf-detr release ships.Type of Change
Testing
Test details:
python -m unittest tests.util.test_model_processor→ 26 tests pass (with torch); torch-masked (CI condition) the 4 integration tests skip and the module imports cleanly — verified both. Tests inject a fakerfdetrviasys.modulesand cover: PTL detection,from_checkpointsuccess,ValueError→SDK-map fallback, both guard errors, the_RFDETR_MODEL_TYPE_TO_CLASScontract, and the unchanged legacy path.make check_code_quality(ruff + mypy) clean.Checklist
Additional Context
RFDETR_MIN_VERSION = "1.8.0"is a# TODOplaceholder — pin once the rf-detr release containingexport_for_roboflowis cut. Scoped down from an earlier version that depended on a publicrfdetr.model_class_for_size; per review the SDK keeps its own smallmodel_type→class map instead (single source of truth for the supported-type check and the fallback).