Skip to content

feat: port Sapiens2 dense prediction - #2550

Merged
inureyes merged 4 commits into
mainfrom
feature/issue-2371-sapiens2-port
Oct 22, 2026
Merged

inureyes merged 4 commits into
mainfrom
feature/issue-2371-sapiens2-port

Conversation

@inureyes

@inureyes inureyes commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Public Sapiens2 checkpoints now run through mlxcel's dense-prediction runtime with their actual ViT backbone and task heads. The port covers pose, semantic segmentation, surface normals, pointmaps, image matting, and backbone features; pose follows the upstream crop, flip-test, DARK, and UDP coordinate path, while dense tasks restore source-resolution outputs.

Changes

  • Load both current flat configs and the published legacy nested segmentation schema with bounded, config-driven 0.4B, 0.8B, 1B, and 5B backbone dimensions.
  • Implement checkpoint-backed compiled 2D RoPE, mixed GQA/MHSA layers, QK RMSNorm, LayerScale, compiled SwiGLU, exact BF16 linear/convolution/deconvolution graphs, all five task heads, and pointmap scaling.
  • Add bounded pose boxes, affine crops, half-pixel grid sampling, flip-pair remapping, DARK/UDP decoding, and source-image coordinate conversion.
  • Register sapiens2 with mlxcel predict and mlxcel arch, document the task contracts, and add compact, reproducible exact-pin upstream fixtures.
  • Preserve published Sapiens2 BF16 weights because an authentic BF16/F16 upstream comparison exceeds the 1.5-pixel pose bound after F16 conversion.

Validation

All numerical acceptance checks used the canonical lossless input and an exact-native MLX 0.32.5 reference pinned to bff10220c742907f0c68e55ff174aaea56f74e3d on the same gfx1151 device.

  • Focused Sapiens2 units: 26 passed, 0 failed, 1 ignored; shared grid sampling: 4 passed.
  • All captured stages: every internal tensor across all 24 backbone blocks and every pose-head stage was bit-exact; final heatmaps were bit-exact.
  • Real checkpoints, 6/6 passed under the ROCm guard:
    • pose flip off: maximum error 0.001930 px across all 308 points; exact scores;
    • pose flip on: maximum error 0.010028 px across all 308 points; exact scores;
    • segmentation: 99.9723307% label agreement;
    • normals: full-output relative RMS 0.000000046;
    • pointmaps: full-output relative RMS 0.000000037;
    • matting: finite source-resolution alpha and foreground outputs.
  • Rebased real-model integration target: build exit 0; all six tests passed.
  • Rebased CLI: build exit 0; real pose prediction on gfx1151 wrote result.safetensors, keypoints.json, and meta.json; the JSON contains 308 named points and the tensor result independently matches upstream within 0.001930 px.
  • Targeted clippy for the library, CLI, and real-model target passed with -D warnings; CI-equivalent --lib --tests clippy also passed.
  • Binary asset policy passed: 22 declared files, 3978.9 KiB of the 4188 KiB budget. Python fixture scripts parse and git diff --check passes.

Public 0.4B task checkpoints and the 1B matting checkpoint were runtime-validated. The standard 0.8B and 5B architectures use the same bounded config-driven implementation, but their public config URLs were inaccessible during validation, so runtime parity is not claimed for those sizes. Sapiens2 4K tokenizer checkpoints are outside this issue and are rejected explicitly. CPU and ROCm upstream results differ in low-confidence pose points, so acceptance uses the exact-pin same-backend reference without relaxing the original thresholds.

The branch is rebased on current main. After the shared-core update, the targeted integration build passed, all six real-checkpoint checks repeated with the same metrics, and --lib --tests clippy passed with warnings denied. Fresh PR CI is the remaining external gate.

Closes #2371

@inureyes inureyes added status:in-progress Currently being worked on type:enhancement New features, capabilities, or significant additions priority:low Low priority area:models Model architectures, weights, loading, metadata modelsize:medium 4-bit checkpoint 10-50GB; comfortable on a 128GB dev box modeltype:vlm Vision-language model labels Oct 22, 2026
@inureyes
inureyes force-pushed the feature/issue-2371-sapiens2-port branch from f809d13 to 2ae94d4 Compare October 22, 2026 19:51
Declare exact limits for all five committed Sapiens2 binary fixtures before generic rules, retaining the cumulative DINOv2 and Sapiens2 budget. Normalize two import lists without changing model numerics.

Formatting, diff checks, and all eight fast contract targets pass after rebasing onto the merged DINOv2 base.
@inureyes
inureyes force-pushed the feature/issue-2371-sapiens2-port branch from 2ae94d4 to 6dfaa4a Compare October 22, 2026 20:31
@inureyes
inureyes marked this pull request as ready for review October 22, 2026 20:42
@inureyes inureyes added status:done Completed and removed status:in-progress Currently being worked on labels Oct 22, 2026
@inureyes
inureyes merged commit 84d3629 into main Oct 22, 2026
29 checks passed
@inureyes
inureyes deleted the feature/issue-2371-sapiens2-port branch October 22, 2026 21:02
@inureyes inureyes added this to the 0.8 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:models Model architectures, weights, loading, metadata modelsize:medium 4-bit checkpoint 10-50GB; comfortable on a 128GB dev box modeltype:vlm Vision-language model priority:low Low priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Port Sapiens2 (sapiens2) human pose and dense human prediction

1 participant