Use when porting external PyTorch models through the DeepDetect worker backend or making worker adapters exportable for inference.
84%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Low
Low-risk findings worth noting
Use this guide when an LLM agent needs to port, import, adapt, or test an
external PyTorch object detection model in DeepDetect through the external
PyTorch worker backend, the external-pytorch-detector CLI profile,
mllib.entrypoint or service_mllib.entrypoint, connector tensor pull,
generated extern/pytorch_workers/<model_slug>/ adapters, or generic detection
worker hooks.
Read the local implementation before editing. Start with the PyTorch worker
backend docs, the external worker README, the CLI profile code, and the current
detection worker base. Use rg for:
DetectionTrainingWorkerBaseexternal-pytorch-detectorservice_mllibmllib.entrypointconnector_tensor_pulltest_predictionsInspect the target upstream repository before designing the adapter. Identify its package requirements, model factory, YAML or config system, training loss path, postprocessor, checkpoint format, device handling, distributed assumptions, download or pretrained defaults, and label and box conventions.
Verify whether a needed extension point already exists. If a core change is required, make it generic for external detection workers rather than naming the target model.
Keep committed DeepDetect changes reusable:
external-pytorch-detector profile.<target>-detector model profile.mllib.entrypoint or service_mllib.entrypoint.DeepDetectWorker.configure, train,
and predict.extern/pytorch_workers/<model_slug>/
unless the user explicitly asks to commit model-specific code.AGENTS.md as operational CLI and monitoring guidance, not the place
for a long model-porting workflow.Target-specific adapter directories are local workspaces by default. The core repository should not import them unless the user selects them in YAML or API parameters.
Create this layout for a generated external worker:
extern/pytorch_workers/<model_slug>/
worker.py
config.yaml
manifest.json
README.md
notes.md # optionalThe manifest should record upstream repository URL, local checkout path, commit or tag when known, license, dependencies, entrypoint, class name, expected config path, checkpoint compatibility, and generation notes.
The README is required. It should include a quickstart with the concrete train and inference CLI commands for the adapter, required upstream checkout/config settings, checkpoint expectations, key environment variables, and any model-specific label or bbox conversion notes.
Prefer subclassing the existing detection training base for object detectors. Implement only the target-specific pieces:
Make conversions explicit. DeepDetect detection data normally uses pixel xyxy
boxes and one-based foreground labels, with class 0 reserved for background.
Many DETR-style models expect normalized cxcywh boxes and zero-based labels.
Convert labels and boxes in both directions and keep the mapping visible in code.
When useful, preserve or synthesize generic target metadata: orig_size, size,
area, and iscrowd. Keep existing boxes, labels, and image_id behavior
compatible with torchvision-style detection workers.
Raise typed worker errors:
Commit DeepDetect core edits only when they help more than one external detector. Examples of acceptable generic work:
deepdetect module.service_mllib.entrypoint, service_mllib.class, and
target-specific YAML values through normal training flows.Do not commit a target adapter, target config, or target dependency workaround as a DeepDetect core change unless the user explicitly requests it.
For committed generic backend work, add focused tests for the reusable behavior:
external-pytorch-detector config pass-through.For generated target adapters, add local tests with fake upstream modules when
possible. Gate real-upstream tests behind an environment variable such as
<MODEL>_REPO.
Run Python tests from the repository with the local package on PYTHONPATH, for
example:
PYTHONPATH=bindings/python python3 -m pytest bindings/python/tests/test_pytorch_worker_runtime.py bindings/python/tests/test_cli.pyFor manual CLI smoke tests, use the source CLI or project wrapper and select the external detector profile:
PYTHONPATH=bindings/python python3 -m deepdetect.cli.main train external-pytorch-detector \
--config extern/pytorch_workers/<model_slug>/config.yaml \
--train-data train.txt \
--test-data test.txt \
--repository runs/<model_slug>-smoke \
--nclasses 2 \
--iterations 10 \
--test-interval 5 \
--batch-size 1 \
--terminal verbose \
--output-format jsonlAdd --gpu --gpuid <id> when CUDA is required. Add --visdom --visdom-results
when visual monitoring is needed, and inspect sink_warning, run.json,
metrics.jsonl, and saved files under REPOSITORY/visdom-results/.
If upstream import fails, install or document the missing dependency and improve the adapter's dependency error message. If upstream code assumes distributed training, prefer adapter-local single-process setup or disable the upstream path that calls distributed APIs before the process group exists.
If evaluation fails after training begins, inspect device placement, cached CPU tensors, postprocessor size arguments, label offsets, and box units. Prediction conversion bugs often appear first during test intervals or visual result generation.
If metrics look plausible but rendered visual results are wrong, inspect the saved image and JSON pairs before changing training settings. Check test-set ordering, sample indices, coordinate sizes, confidence thresholds, class ids, and whether the backend shuffled evaluation data.
The CLI generates a relocatable inference.yaml with deepdetect export RUN --output DESTINATION; do not add a separate recipe file. See
CLI export documentation for the
metadata schema and legacy-run overrides.
For new adapters, declare export metadata in the existing training YAML:
installed module, package requirements, inference-only settings under
inference, and any auxiliary assets with their configuration field keys.
Training preserves this metadata in the run's effective config.yaml. An
inference.service_mllib mapping replaces opaque training worker settings;
include the architecture/preprocessing parameters needed to reconstruct the
model unless the checkpoint authoritatively stores them.
Use an importable installed module for deployment. Keep a file-entrypoint shim
for development if useful, but declare its installed module explicitly. Load
an explicit mllib.weights checkpoint for inference without requiring solver
state, training data, the original checkout, or pretrained downloads. Keep the
existing configure/train/predict worker contract; no hook is required for checkpoint-bundle export. Optional
ONNX conversion uses the provider contract below.
Declare auxiliary files/directories rather than retaining absolute paths in inference settings. References embedded inside those assets must be relative or resolved by the adapter; the CLI does not rewrite arbitrary file formats. Do not copy the upstream source tree into model exports.
Validate an exported checkpoint with a tar/extract relocation test: use a
second directory and different working directory, make original training paths
unavailable, and compare predictions on the same inputs. Verify that only the
selected checkpoint and declared assets are needed with the worker package
installed. Record any precision/device requirements in the adapter README.
Use export --test-inference for a basic load/run check on a random image at
the exported dimensions; inspect inference_test in export.json. This smoke
test does not replace comparison on real inputs or model-quality assessment.
Keep mllib.onnx_export.enabled false unless requested. For straightforward
models, supply mllib.onnx_export.provider: installed_module:function. The
callable receives (checkpoint_paths, inference_configuration) and returns
(cpu_eval_model, example_positional_inputs, names) where names contains
input_names and optionally output_names. Reconstruct the exact saved
checkpoint without pretrained downloads or access to the live training model.
Use fixed-shape CPU inputs and only simple inference wrappers. Do not add
operator patches, architecture surgery, or fallback exporters to force support.
The detection checkpoint manager triggers background export for aggregate best
checkpoints. Custom loops must instantiate deepdetect.onnx_export.BestOnnxExporter with
backend="pytorch" and use notify(iteration, paths)
after saving their aggregate best, and call close(cancellation=lambda: cancellation.requested) on success or
close(cancel=True) on cancellation/errors. Always arrange cleanup in finally.
Only the checkpoint-writing rank should notify. Export is optional; unsupported
models or missing dependencies disable further attempts, including after resume.
Install the onnx package extra to enable conversion. Successful checker
validation does not establish numerical parity or TensorRT compatibility.
See CLI ONNX documentation for configuration, provider inputs, lifecycle, and artifact provenance. Validate providers with a tiny real export; do not enable them based only on checkpoint loading. Record export limitations in the adapter README.
jolibrain/deepdetect
e6b7dc2
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.