Repository navigation
Closed
Labels
area:cliCommand-line interface / CLI flagsarea:modelsModel architectures, weights, loading, metadatapriority:mediumMedium prioritystatus:doneCompletedtype:enhancementNew features, capabilities, or significant additions
Milestone
Description
mlxcel supports language and vision-language models that emit token streams, but it has no object detection model. RT-DETRv2 is a real-time detection transformer that emits bounding boxes rather than tokens, so it needs a task path outside the generate flow.
Goal
Add RT-DETRv2 to mlxcel and expose it through a new top-level mlxcel detect subcommand that takes an image and emits detections as (left, top, right, bottom, label, confidence), in text or JSON format.
Architecture
- ResNet-50-vd / ResNet-101-vd backbone (3-conv stem, stride-2 maxpool, AvgPool-based downsampling shortcuts), with depth read from the backbone config so both variants share one module.
- Hybrid encoder: an AIFI transformer on the deepest level (2D sine position embedding), a top-down FPN, and a bottom-up PAN with RepVGG/CSPRep blocks.
- Encoder query selection (top-K over the flattened position-by-label score space) feeding a six-layer deformable-attention decoder with iterative bounding-box refinement.
- Multi-scale deformable attention implemented via a pure-MLX bilinear grid_sample (padding zeros, align_corners false).
Scope
- New
src/vision/detection/rt_detr_v2/module: config, sanitize, shared layers, backbone, hybrid encoder, transformer, model, processor, predictor. - A weight-rename pipeline that runs only when raw HF layout is detected, so pre-converted checkpoints load as-is.
- The forward path runs in float32 for box-coordinate precision; weights stay in their stored dtype so float32-input by stored-weight promotion matches the reference.
- New
mlxcel detectsubcommand (--model,--image,--threshold,--format text|json). Detection is a separate subcommand rather than an overload ofgenerateorservebecause the output is boxes, not tokens. - Leave the existing model-type classification module untouched; this model registers no new generate-flow model type.
Acceptance criteria
mlxcel detectloads a ResNet-50-vd RT-DETRv2 checkpoint and prints detections for an image, in both text and JSON.- Detections match a reference predictor on the same checkpoint and image within bf16 rounding and bilinear-resize differences.
- Unit tests cover grid_sample, max and average pool, nearest upsample, anchor generation, inverse-sigmoid round-trip, the rename pipeline, and config parsing.
Metadata
Metadata
Assignees
Labels
area:cliCommand-line interface / CLI flagsarea:modelsModel architectures, weights, loading, metadatapriority:mediumMedium prioritystatus:doneCompletedtype:enhancementNew features, capabilities, or significant additions
Activity
feat(M3): asymmetric MSA mask for chunked/cached prefill (lablup#78)
feat(M3): sparse_sdpa accepts asymmetric q/k blocks (lablup#79)