Skip to content

feat(models): add IDOL (idol) image to 3D Gaussian splats in mlxcel predict - #3731

Open
Jaeyeong-CHOI wants to merge 1 commit into
lablup:mainfrom
Jaeyeong-CHOI:feat/3232-idol
Open

Jaeyeong-CHOI wants to merge 1 commit into
lablup:mainfrom
Jaeyeong-CHOI:feat/3232-idol

Conversation

@Jaeyeong-CHOI

Copy link
Copy Markdown
Contributor

Summary

Closes #3232.

Adds Sperid Labs' IDOL (speridlabs/idol) to mlxcel predict as the dense family idol: one object photo becomes a standard 3D Gaussian Splatting gaussian.ply, with the prepared input.png, the predicted camera.json, the sampled latent and camera in result.safetensors, and meta.json. Ported from mlx-vlm's mlx_vlm/models/idol (Neywa-Labs/mlx-vlm#2644, 92e07596), which adapts speridlabs/idol-sdk.

Before this change mlxcel predict -m <speridlabs/idol> failed with model_type not found in .../config.json, and mlxcel arch did not list idol.

What changed

  • src/vision/dense/idol/ (new):
    • config.rs, options.rs: the published config.json and the --opts surface (mode, num_gaussians, steps, guidance, rescale_t, seed, crop_margin, batch_cfg, dinov3, flux2_vae, dinov3_dtype, background_removal), validated with upstream's messages.
    • preprocess.rs: preprocess_image on 8-bit pixels as Pillow computes it: Lanczos resize of the short side to 1024 (premultiplied RGBA), BiRefNet when the alpha is not real, a 3x3 minimum filter with replicated edges, the square crop around the alpha bounding box (crop_margin 1.2 for synthetic, 1.7 for real, Python int truncation, transparent padding), a second Lanczos resize and DIV255 compositing on black.
    • birefnet.rs, birefnet_swin.rs, deform_conv.rs: BiRefNet in f32: the Swin-L backbone (shifted windows, relative position bias, patch merging) on the full and half-resolution image, the ASPP blocks with modulated deformable convolutions (bilinear gathers, one kernel row at a time), and the multi-scale decoder.
    • conditioning.rs: DINOv3-H+ runs on the SAM 3D Body DINOv3 tower, loaded from the Hugging Face DINOv3ViTModel layout through a key map (layer.* or model.layer.*, gated MLP to w1/w2/w3, LayerScale lambda1, register tokens, RoPE periods from rope_theta); the parameter-free LayerNorm then gives feature1 [1, 4101, 1280]. FLUX.2-dev runs on the shared Flux2Vae encoder in bf16: the posterior is sampled, 2x2-patchified with channel order (C, py, px), batch-norm normalized and prefixed with five zero tokens (feature2 [1, 4101, 128]).
    • layers.rs, denoiser.rs, sampler.rs: LatentSeqMMFlowModel with upstream's dtypes (transformer linears f16, everything else f32, explicit casts at each boundary): RePo learned rotary positions, modulated and unmodulated unified blocks, the joint [latent, condition, camera] blocks and the output modulation; Euler rectified-flow sampling with the rescale_t time warp and guidance against a zero condition, sequential or batched (batch_cfg).
    • octree.rs, gaussian.rs, camera.rs: the octree decoder with systematic_sample (CDF rounding, one offset per cell) and host-side packing once per level, the Gaussian decoder and its activations, the y-up PLY transform with IDOL's clamps, and decode_camera. Random draws come from MLX's global generator, seeded after the encoders load as upstream does; tests can inject recorded draws.
  • Detection: checkpoint_model_type returns idol for a config without model_type whose denoiser is LatentSeqMMFlowModel and that has decoder_gs and image_encoders; idol is in KNOWN_MODEL_TYPES and FAMILIES. The generation-side detector reports dense prediction checkpoint (idol): use mlxcel predict for the same layout instead of model_type not found.
  • Registry: an idol StandaloneArchitectureFamily (category dense_prediction, image input) with a new output kind gaussian_splats.
  • Shared code:
    • sam3d_body/backbone.rs: forward_tokens returns every normalized token (CLS, storage, patches) for any float input dtype; forward keeps its F32 check and slices the patches as before. After RoPE, q and k return to the value dtype (a no-op for the F32 Body tower).
    • imagegen/vae/model.rs: Flux2Vae::moments() returns the posterior mean and the log-variance clipped to [-30, 20]; encode now calls it, unchanged in result.
    • dense/preprocess.rs: PillowResizeFilter::Lanczos and resize_pillow_rgba8 (Pillow's RGBa round trip; a resize to the current size returns a copy, as Image.resize does, so translucent pixels keep their exact values). The two passes are now generic over the band count as a const parameter (3 for RGB, 4 for RGBA); resize_pillow_rgb8 output is unchanged. Its Used by: note now lists every caller (git grep -ln 'resize_pillow_rgb8(' -- src).
    • dense/predictor.rs, dense/output.rs: DenseOutput gains images and documents, which the shared writer saves as <name>.png and <name>.json (names restricted to input and camera). Each attachment replaces only a file or symlink of its own name when it is written. Neither name is on the shared stale-artifact list, so a run of any other family leaves a user's input.png or camera.json in the output directory alone; IDOL writes both on every run.
  • Docs (supported-models.md, dense-prediction.md with the gated-encoder instructions, vision-model-scope.md, environment-variables.md for the test variables), NOTICE (mlx-vlm, Idol SDK, diffusers Wan; the encoder weights keep their own licenses) and CHANGELOG.md under ## [Unreleased].

Deviations from the issue

  • Parity bounds for guided sampling. The issue asks for latent and camera relative error under 3e-3 after 4 steps. The unguided latent meets it (measured 0); with the default guidance 3.0 the bound is 5e-3 for the latent and 2e-2 for the camera token (five values), and the test records why:
    • mlx-vlm does not meet 3e-3 against itself. Its sequential guidance and its batch_cfg guidance compute the same thing at batch 1 and batch 2, and on the same seeded inputs their 4-step results differ by 1.08e-2 in the latent and 5.4e-3 in the camera (computed from the committed fixture, sample.* against sample_batch_cfg.*). mlxcel's sequential path is 3.8e-3 / 3.6e-3 from mlx-vlm's sequential result, inside that gap, and its batch_cfg path is bit-identical to mlx-vlm's.
    • mlx-vlm is sensitive to last-bit changes here. Replacing only its compiled tanh GELU with the op-by-op formula (x * x * x order; one f16 ulp on 30 of 8,193 values) moves its guided 4-step latent by 8.9e-3 and the camera by 1.3e-2, and the unguided latent by 9.7e-4; running its denoiser in f32 moves the guided latent by 2.5e-2. Guidance 3 multiplies the difference of two passes by four.
    • Why mlxcel's sequential guided path is not bit-identical while the unguided and batch_cfg paths are was not isolated.
  • Octree checked level by level. The issue asks for decode with the recorded offsets and uniforms. The Gaussian decoder on upstream's points is compared over the recorded Gaussians, and the octree is compared one level at a time on upstream's cells with its offsets, allowing one percent of the cells to split differently (6 of 2,804 measured, at levels 3 to 5). The chained decode is not compared cell for cell because the split of a cell on a systematic-sampling boundary is not reproducible even within mlx-vlm: an mlx-vlm script that replays the same per-level loop with the same latent and recorded offsets reached 65 cells at level 4, where the run that produced the reference reached 64, and every later level then differs. On that replay's cells mlxcel's per-level split probabilities are bit-identical to mlx-vlm's at all eight levels (its logits at levels 3 to 5 differ by about 1e-3 relative, the others are bit-identical). The cause of the boundary differences was not isolated. The full chained decode still runs in the test with MLX's generator and is checked for anchor count and finite output.
  • Tanh GELU. mlx-vlm's nn.GELU(approx="tanh") is MLX's compiled gelu_approx; IDOL uses the shared compiled port (compiled_objects_gelu_tanh, which keeps the Power(x, 3) primitive) because the op-by-op formula differs in the last bit on 30 of 8,193 f16 values, and the 24-block f16 denoiser carries that into the latent (the replacement experiment above). A unit test pins it bit for bit against the recorded mlx.nn table.
  • Encoder repository lookup. Without dinov3 / flux2_vae in --opts, the repository ids in image_encoders are looked up in ./models, the Hugging Face cache and the mlxcel store without downloading, rather than resolved with an automatic download: the encoders are gated, and an automatic fetch of black-forest-labs/FLUX.2-dev would pull far more than its vae/. A miss names the gated repository and the option.
  • Size limits. Upstream has none. An extreme aspect ratio scaled to a 1024-pixel short side, or a large crop_margin, now stops with an error before an intermediate image passes 8192 x 8192 pixels, and a crop box that saturates the pixel range is an error instead of an overflow. steps is capped at 10,000.
  • Output kind. mlxcel arch reports the new gaussian_splats output kind for idol; the existing kinds had no Gaussian-only entry (SAM 3D Objects, which also writes meshes, stays mesh).

Verification

GB10 (sm_121, 121 GB unified memory), CUDA 13, MLX_ENABLE_TF32=0. The reference is mlx-vlm at e8035ae3 (contains Neywa-Labs/mlx-vlm#2644, 92e07596) with mlx 0.32.4. Checkpoints: speridlabs/idol 2731c2291fc65a797c5cb627a5e5526fc1490902, facebook/dinov3-vith16plus-pretrain-lvd1689m and the vae/ folder of black-forest-labs/FLUX.2-dev.

Before (main ac5716b8f). mlxcel predict -m <speridlabs/idol> --image castle.webp --task gaussian -o out fails with load model: classify checkpoint: model_type not found in .../config.json; mlxcel arch has no idol. The new tests reference vision::dense::idol, which does not exist on main.

Unit tests (cargo test --profile test-fast --features cuda --lib vision::dense::idol): 46 passed, 3 ignored (the real-checkpoint tests below). They cover the published-config detection and its negatives (no model_type and missing decoder_gs, image_encoders or the denoiser name still fail with model_type not found; an explicit model_type wins); systematic_sample against values printed by mlx-vlm for nine cases (zero, one and 1,000,000 points, all-zero and negative probabilities, a 1e-30 ratio, fixed offsets 0, 0.5 and 0.999); octree point conservation at every level and recorded-draw shape checks; RePo3DRotaryEmbedding and PcdAbsolutePositionEmbedder/v2 against hand-computed values; the Gaussian activations and the y-up PLY transform on two points, including the written bytes and a NaN scale that must not pass max(s, 1e-6); decode_camera perspective, orthographic and zero-direction cases; Pillow Lanczos RGBA resizes (premultiplied, upscale, a resize to the same size, which Pillow returns as a copy, and a tall image whose vertical pass runs first) and mlx-vlm's preprocess_image for both modes on two sources, one of them a translucent 24x16 image whose short side is already 16 and whose synthetic crop is exactly 16 square, byte for byte against Pillow 13.0.0 output (tests/fixtures/idol/pillow_cases.txt); crop geometry, erosion, compositing, half-to-even rounding and the size limits; the deformable convolution against a direct DCNv2 on a 6x6 input for 1x1, 3x3 and 7x7 kernels with offsets past the border; the Body DINOv3 tower against a direct Hugging Face DINOv3 forward with shared random weights (layer.* and model.layer.*, max difference under 1e-4, bf16 cosine above 0.999); the sampler time grid, guidance and batched guidance; the tanh GELU bit for bit against mlx.nn on 8,193 f16 values; options with upstream's messages; encoder path lookup that never downloads.

Real-checkpoint parity (MLXCEL_TEST_IDOL_DIR=... cargo test ... vision::dense::idol::real_tests -- --ignored, reference tests/fixtures/idol/reference.safetensors):

Check Result Bound
Seeded condition and noise regenerated with MLX's generator bit-identical to mlx-vlm's exact
4 steps, unguided: latent / camera 0 / 0 (bit-identical) 3e-3
4 steps, guidance 3.0, batch_cfg: latent / camera 0 / 0 (bit-identical) 5e-3 / 2e-2
4 steps, guidance 3.0, sequential: latent / camera 3.8e-3 / 3.6e-3 5e-3 / 2e-2
Gaussian decoder on upstream's 1,024 points: first 4,096 Gaussians, every attribute 0 (bit-identical); column sums of all 32,768 within 7e-5 1e-3
Octree, each level on upstream's cells with its offsets 6 of 2,804 cells split differently (levels 3-5) 1%
Chained decode at 32,768 Gaussians with MLX's generator 1,024 anchors, finite runs

With the gated encoders (MLXCEL_TEST_IDOL_ENCODER_REFERENCE, generated locally by generate_reference.py --encoders, not committed): BiRefNet alpha on mlx-vlm's resized RGB image differs by at most 1 level (140 and 141 of 2,097,152 pixels in two runs); DINOv3 feature1 cosine 0.99992 over all 4,101 tokens (lowest single token 0.979); FLUX.2 VAE posterior mean relative error 1.04e-2 (bound 3e-2) and feature2 with the recorded posterior noise 9.5e-3 (bound 3e-2). The full preprocessing of an RGB photo (BiRefNet included) gives an input.png within 2 levels of mlx-vlm's prepared image (93 of 1,048,576 pixels differ). For the reference only, mlx-vlm's BiRefNet convolutions that the mlx 0.32.4 wheel finds no cuDNN plan for (MLX_ENABLE_TF32=0) run on its CPU stream; mlxcel's MLX falls back to the gemm convolution for those (#2739).

End to end (mlxcel predict, release-style test-fast build):

mlxcel predict -m speridlabs-idol --image castle-rgb.png --task gaussian -o out/rgb \
  --opts '{"dinov3": "<dinov3 dir>", "flux2_vae": "<FLUX.2-dev dir>", "mode": "synthetic"}'
mlxcel predict -m speridlabs-idol --image castle.webp --task gaussian -o out/rgba \
  --opts '{"dinov3": "...", "flux2_vae": "...", "mode": "real", "num_gaussians": 32768, "steps": 25, "batch_cfg": true}'
  • RGB photo (the castle from speridlabs/idol's gallery composited on white, 640x320), background removed by BiRefNet, defaults (50 steps, guidance 3.0, 262,144 Gaussians): 2 min wall clock including model loading (meta.json timing_ms 118,357 for the prediction), 2.6 GB peak RSS. Its input.png is within 2 levels of mlx-vlm's prepared image (93 of 1,048,576 pixels differ; the BiRefNet alpha differs by at most 1 level, see above). gaussian.ply is 17,826,208 bytes: 262,144 vertices, the 17 standard fields in order (x y z nx ny nz f_dc_0..2 opacity scale_0..2 rot_0..3), binary little-endian, all finite, zero normals, quaternion norms 1 +- 3e-7, opacity logits within logit(1e-6) on both sides, log scales -7.01 to -1.73. input.png is 1024x1024, camera.json holds yaw, pitch, radius and fov, result.safetensors holds latent [1, 8192, 16] and camera [1, 1, 5], and meta.json the seed, steps, guidance, rescale_t, num_gaussians, mode, crop margin and background_removed: true.
  • The same castle as RGBA with its own alpha, mode: real, 32,768 Gaussians, 25 steps, batch_cfg: 50 s, 32,768 finite vertices. Its input.png is byte-identical to mlx-vlm's preprocess_image on the same file with Pillow 13.0.0.
  • That RGBA castle upscaled to 2048x1024, so the first resize keeps the size (4 steps): input.png byte-identical to mlx-vlm's preprocess_image on the same file. Taking the premultiplied round trip there, which Pillow skips at the same size, changes 25,486 of 1,048,576 pixels by up to 3 levels.
  • background_removal: false with the RGB photo: An RGB input needs background removal; pass an RGBA image or enable BiRefNet. num_gaussians: 32769: num_gaussians must be a multiple of 32 between 32768 and 1048576. No encoder options and no local copy: the error names facebook/dinov3-vith16plus-pretrain-lvd1689m and the dinov3 option.
  • mlxcel arch lists idol; mlxcel arch --json reports it as dense_prediction, runtime predict, output gaussian_splats.

Gates (the committed tree):

  • cargo fmt --all -- --check: pass.
  • cargo clippy --locked --workspace --all-targets --features cuda -- -D warnings: pass.
  • python3 scripts/ci/check_used_by.py, bash scripts/ci/check_used_by_test.sh, python3 scripts/ci/check_env_var_docs.py, python3 scripts/ci/check_binary_assets.py, python3 scripts/ci/check_kernel_dtype_keys.py: pass. check_cross_repo_refs.py ran without a GitHub token; the bare references it lists (#3232, and the existing #3604, #3612 on an edited comment line) are lablup/mlxcel numbers.
  • Related lib tests: vision::dense::registry 11, vision::dense::preprocess 8, vision::dense::geometry_io 5, vision::dense::output 12 (three new: a run of another family leaves an existing input.png and camera.json untouched; attachments replace a symlink of their own name without writing through it; unsupported, duplicate and empty attachments are refused before any earlier output is removed), vision::dense::sam3d_body 20, imagegen::vae 32 (1 ignored), models::registry 22, and the detection redirect test: all pass.
  • make verify-test-cuda (--test-threads=1): 18,943 passed, 2 failed, 581 ignored. The two failures fail the same way on unmodified main (9402cf893) in the same build directory: mlx_test_guard_coverage::mlx_evaluating_lib_tests_take_mlx_test_guard lists only src/vision/encoders/nemotron_h_nano_omni_tests.rs:276 pos_embed_resample_runs_in_f32, and step3p7_parity::text_decode_delegates_sequence_local_native_batching fails at tests/step3p7_parity.rs:519; both are [nightly-verify] main is red #3652.
  • The branch is one commit on current main (9402cf893) and merges cleanly (git merge-tree).

Limits

  • The parity bounds were measured on GB10 only; the sequential guided latent (3.8e-3 against 5e-3) has the thinnest margin.
  • Not run on Metal or ROCm; the module uses only MLX operations available on both, and the registry marks ROCm as partial like the other dense families.
  • The PLY was checked field by field (17 standard 3DGS fields, binary little-endian, finite, unit quaternions, opacity logits within logit(1e-6)) but not opened in a 3DGS viewer here.
  • Upstream's /v1/meshes job API, mesh extraction and text conditioning are out of scope, as the issue says. Video input is refused.
  • The encoder reference contains DINOv3 and FLUX.2 outputs, so it is generated locally and not committed; that test is ignored without it.
  • At systematic-sampling boundaries the octree's cell splits were not reproducible even between two mlx-vlm runs (see Deviations), so seed-for-seed output can differ from mlx-vlm's at a few anchors although each network pass matches within the bounds above.

…redict

Port Sperid Labs' IDOL (speridlabs/idol) from mlx-vlm as the dense
family `idol`: BiRefNet background removal, DINOv3-H+ (on the SAM 3D
Body tower, loaded from the Hugging Face layout) and FLUX.2 VAE
conditioning, the rectified-flow denoiser over the object latent and
camera token, the octree point sampler and the Gaussian decoder.
`mlxcel predict` writes gaussian.ply (y-up 3DGS), input.png,
camera.json, result.safetensors and meta.json.

The checkpoint has no model_type; its config layout is detected as
`idol`. Flux2Vae gains moments(), the shared Pillow resampler gains
Lanczos and RGBA resizing, DenseOutput gains image and JSON
attachments, and the architecture registry gains the gaussian_splats
output kind.

Closes lablup#3232.

This branch has not been deployed

No deployments
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.

feat(models): add IDOL (idol) image to 3D Gaussian splats in mlxcel predict

1 participant