Skip to content

feat(cli): adapt raw rf-detr PyTorch-Lightning checkpoints on upload#488

Draft
leeclemnet wants to merge 1 commit into
mainfrom
feat/sdk-rfdetr-lightning-upload
Draft

feat(cli): adapt raw rf-detr PyTorch-Lightning checkpoints on upload#488
leeclemnet wants to merge 1 commit into
mainfrom
feat/sdk-rfdetr-lightning-upload

Conversation

@leeclemnet
Copy link
Copy Markdown
Contributor

@leeclemnet leeclemnet commented Jun 1, 2026

What does this PR do?

Lets roboflow upload_model accept 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:

  • Detect a PTL checkpoint via the pytorch-lightning_version key (_is_ptl_checkpoint).
  • Lazy-import rfdetr (capability-guarded on RFDETR.export_for_roboflow; actionable RuntimeError if missing/too old — mirrors the ultralytics/yolo pattern).
  • Load the model: RFDETR.from_checkpoint(pth), falling back to the SDK-local model_type→class map (_RFDETR_MODEL_TYPE_TO_CLASS) when the checkpoint lacks the metadata rf-detr needs to infer its class (no model_name/pretrain_weights).
  • model.export_for_roboflow(model_path) writes weights.pt (args with resolution) + class_names.txt.
  • Legacy path is unchanged and imports no rfdetr.

Related Issue(s): Depends on rf-detr's export_for_roboflowroboflow/rf-detr#1086. Capability-guarded, so it merges independently and works end-to-end once that rf-detr release ships.

Type of Change

  • New feature (non-breaking change that adds functionality)

Testing

  • I have tested this change locally
  • I have added/updated tests for this change

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 fake rfdetr via sys.modules and cover: PTL detection, from_checkpoint success, ValueError→SDK-map fallback, both guard errors, the _RFDETR_MODEL_TYPE_TO_CLASS contract, and the unchanged legacy path. make check_code_quality (ruff + mypy) clean.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code where necessary
  • My changes generate no new warnings or errors
  • I have updated the documentation accordingly (if applicable)

Additional Context

RFDETR_MIN_VERSION = "1.8.0" is a # TODO placeholder — pin once the rf-detr release containing export_for_roboflow is cut. Scoped down from an earlier version that depended on a public rfdetr.model_class_for_size; per review the SDK keeps its own small model_type→class map instead (single source of truth for the supported-type check and the fallback).

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 leeclemnet force-pushed the feat/sdk-rfdetr-lightning-upload branch from 318dfbc to db28572 Compare June 1, 2026 17:07
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>
@leeclemnet leeclemnet force-pushed the feat/sdk-rfdetr-lightning-upload branch from db28572 to 7150b7c Compare June 1, 2026 17:53
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>
@leeclemnet leeclemnet force-pushed the feat/sdk-rfdetr-lightning-upload branch from 7150b7c to 8f5fc73 Compare June 1, 2026 18:05
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 participant