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

Đang mở
#3,232 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
8/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
machine-learning

Hướng nghiên cứu

Start in src/vision/dense/registry.rs at checkpoint_model_type, which fails on configs without a model_type key, and read geometry_io.rs for write_gaussian_ply and the Gaussians struct. The full port spans a new src/vision/dense/idol/ module tree plus a DINOv3 and FLUX.2 VAE reuse decision, so a newcomer should first agree the scope with maintainers. Done means the structural detection resolves to idol and the parity tests in each submodule pass against precomputed features.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

area:models modelsize:small modeltype:vlm priority:low status:ready type:enhancement

Summary

Port Sperid Labs' IDOL single-image-to-3D model (speridlabs/idol) as a mlxcel predict dense family idol: an object photo becomes a standard 3D Gaussian Splatting .ply, the prepared input PNG and predicted camera parameters. The pipeline is BiRefNet background removal, DINOv3-H+ and FLUX.2 VAE image conditioning, a rectified-flow transformer over an 8192-token object latent and a camera token, an octree point sampler, and a Gaussian decoder. Today mlxcel predict -m speridlabs/idol fails because its config.json has no model_type and no dense family matches. The output surface (mlxcel predict, write_gaussian_ply) already exists from #2349 and #2381, so this is a single-family port with one structural-detection addition.

Upstream reference

Architecture (from upstream code and speridlabs/idol/config.json)

config.json has no model_type; it holds denoiser (name: LatentSeqMMFlowModel, q_token_length 8192, in_channels 16, cam_channels 5, model_channels 1024, cond_channels 1280, cond2_channels 128, num_blocks 24, num_refiner_blocks 2, num_heads 16, mlp_ratio 4), decoder (OctreeProbabilityFixedlenDecoder, 1024 channels, cond_channels 16, 4 blocks), decoder_gs (GaussianFixedlenDecoder, 16 blocks, representation_config: num_gaussians 32 per anchor, lr per attribute (_rotation 0.1, others 1.0), perturbe_size 1.5, 3d_filter_kernel_size 0.0009, scaling_bias 0.004, opacity_bias 0.1), image_size 1024, max_voxel_level 8, and image_encoders (dinov3: facebook/dinov3-vith16plus-pretrain-lvd1689m, flux2_vae: black-forest-labs/FLUX.2-dev). Weights: denoiser.safetensors (1.48 GB), decoder.safetensors (0.20 GB), decoder_gs.safetensors (0.95 GB), birefnet.safetensors (0.44 GB).

  • Preprocess (preprocess_image): load as RGBA; resize so the short side is 1024 (LANCZOS); if the alpha channel is not real (min 255), predict one with BiRefNet in f32 at 1024 px; erode the alpha by a 3x3 min filter; crop a square of side max(1, bbox_w, bbox_h) * crop_margin around the alpha bounding-box centre (crop_margin 1.2 for mode: synthetic, the default, and 1.7 for mode: real); resize to 1024 (LANCZOS); composite on black. An empty alpha is an error.
  • Conditioning (ImageEncoder): pixels / 255; DINOv3-H+ (HF layout, CLS + 4 register tokens, axial RoPE with per-axis coordinates (i + 0.5) / n * 2 - 1 and rope_theta, gated SiLU MLP, LayerScale lambda1) on ImageNet-normalized input in bf16 by default, then a parameter-free LayerNorm (eps 1e-5) in f32: feature1 [1, 4101, 1280]. The FLUX.2-dev VAE encoder in bf16 on pixels * 2 - 1: posterior mean + exp(0.5 * clip(logvar, -30, 20)) * noise, 2x2 patchify with channel order (C, py, px), batch-norm normalization (eps 1e-4), and 5 leading zero tokens: feature2 [1, 4101, 128]. The two token counts must match. The RNG is seeded after the encoders load, and the VAE posterior noise is drawn from that stream before sampling.
  • Denoiser (LatentSeqMMFlowModel, f16 linears, f32 embeddings, norms and learned rotary parameters): h_x = input_layer(latent) + pos_embedder(pos_pe) (a stored scrambled Sobol position table [1, 8192, 3]); h_cond = cond_embedder(feature1) + cond_embedder2(feature2); t_mod = adaLN_modulation(SinusoidalEmbedder(t)) (6 x 1024); 2 modulated noise_refiner blocks on the latent, 2 unmodulated context_refiner blocks on the condition, an MLP cam_refiner on the camera token, then 24 joint blocks over [latent, condition, camera]; each block has its own RePo3DRotaryEmbedding (positions predicted from content: LayerNorm in f32, final_map(silu(gate_map(h)) * content_map(h)) to 3 values per head, frequencies linspace(1, 16, ...) per axis, angles times pi, interleaved-pair rotation in f32); output LayerNorm, shift_table + t_emb modulation, out_layer (latent velocity [B, 8192, 16]) and cam_out_layer ([B, 1, 5]).
  • Sampler (sample_flow): noise latent [B, 8192, 16], camera [B, 1, 5]; ts = linspace(1, 0, steps + 1), ts = rescale_t * ts / (1 + (rescale_t - 1) * ts); model time 1000 * ts[i]; guidance against a zero condition: v = (1 + cfg) * v_cond - cfg * v_zero when cfg > 0; Euler x -= v * (ts[i] - ts[i + 1]); batch_cfg runs both passes as one batch. Defaults: 50 steps, cfg_strength 3.0, rescale_t 3.0, seed 42.
  • Octree decoder: starting from one root cell holding num_gaussians / 32 points, for depth 1..8 predict an 8-way child distribution per cell from the cell centres and the latent (cross-attention-only modulated blocks, level embedding), split counts with systematic sampling (one uniform offset per row, CDF rounding), keep cells with points (host-side variable-length packing); final points are (cell + uniform) / 2^8.
  • Gaussian decoder: 16 cross blocks over the points and the latent, out_proj to 32 anchors' attributes (_xyz 3, _features_dc 1x3, _scaling 3, _rotation 4, _opacity 1, _offset_scale 1); positions tanh(offset) * 0.75 * softplus(offset_scale + base_offset_scale) + point with a stored per-anchor perturbation; activations: xyz - 0.5, softplus scaling with the bias offset and sqrt(s^2 + 0.0009^2), normalized quaternion raw + [1, 0, 0, 0], sigmoid opacity with the opacity_bias logit offset.
  • PLY export (Gaussian.save_ply): binary little-endian with the 17 standard 3DGS float fields; positions rotated from z-up to y-up (x, -z, y), quaternions (w - x, w + x, y - z, y + z) * sqrt(0.5), opacity clipped to [1e-6, 1 - 1e-6] and stored as a logit, scale stored as log(max(s, 1e-6)); non-finite attributes are an error.
  • Camera (decode_camera): yaw atan2(dx, dy), pitch asin(dz), radius 1 / inverse_distance (orthographic, radius 1000, below 1e-3), vertical FOV in degrees.
  • Sanitize (sanitize_weights per module): conv kernels to MLX layout, transformer linears cast to f16, the rest kept f32; DINOv3 keys layer.* / model.layer.* to encoder.layer.*; the FLUX.2 VAE keeps encoder.*, quant_conv.*, bn.* with .to_out.0. to .to_out..

Checkpoints and host

Component Id Size Access
IDOL weights speridlabs/idol 3.13 GB Public, Apache-2.0
DINOv3-H+ encoder facebook/dinov3-vith16plus-pretrain-lvd1689m 3.36 GB (840.6M f32 parameters) Gated (DINOv3 license; accept terms)
FLUX.2 VAE (only vae/) black-forest-labs/FLUX.2-dev 0.34 GB Gated (FLUX.2-dev license; accept terms)

Upstream measured 9.49 GB peak MLX memory for the default 262,144-Gaussian run, so any 16 GB machine is enough. Each piece is under 5 GB (home = both); the gated encoders must be downloaded by someone who accepted their terms. Encoder access is not needed to sample and decode from precomputed features, which is how the unit-level parity tests run.

Current behavior

  • src/vision/dense/registry.rs:149 (checkpoint_model_type) requires a model_type key, so IDOL's config fails with model_type not found; KNOWN_MODEL_TYPES (:106) and FAMILIES have no idol.
  • Reusable in-tree pieces: src/vision/dense/geometry_io.rs (Gaussians :18, write_gaussian_ply :151, which writes the 17 fields but applies no axis rotation, clamps opacity to [1e-7, 1 - 1e-7] and takes ln(scale) without a floor); src/vision/dense/sam3d_objects/ (flow-matching object generation and the gaussian.ply output precedent); src/vision/dense/sam3d_body/backbone.rs:121 (a DINOv3-H+ backbone with storage tokens and axial RoPE, loaded from the SAM 3D Body schema) and sam3d_body/rope.rs:77 (apply_rope); src/imagegen/vae/model.rs:286 (Flux2Vae, Diffusers names from <model>/vae/, encode at :466); src/vision/dense/interpolate.rs (resizes, grid_sample).

Proposed solution

New src/vision/dense/idol/ (mod.rs with pub fn load(path) -> Result<Box<dyn DensePredictor>>, config.rs, preprocess.rs, birefnet.rs, deform_conv.rs, conditioning.rs, layers.rs, denoiser.rs, sampler.rs, octree.rs, gaussian.rs, camera.rs, tests beside each); in src/vision/dense/registry.rs a structural fallback in checkpoint_model_type that returns "idol" when model_type is absent and denoiser.name == "LatentSeqMMFlowModel" with decoder_gs and image_encoders present, idol in KNOWN_MODEL_TYPES, and a DenseFamily { model_type: "idol", supports_prompts: false, supports_sidecars: false, load } row; a StandaloneArchitectureFamily in src/models/registry.rs (category dense_prediction, input image, output Gaussian splats).

  • Task gaussian (the only task). Options through --opts: mode (synthetic default or real), num_gaussians (multiple of 32 in [32768, 1048576], default 262144), rescale_t, crop_margin, batch_cfg, dinov3, flux2_vae (local paths; default: the ids in image_encoders resolved the way -m resolves a model, failing with a message naming the gated repo when absent), dinov3_dtype (bf16 default, fp32, fp16), background_removal (default true; false requires a real alpha). --steps-style shared knobs go through --opts as steps, guidance, seed.
  • Outputs through the shared writer: gaussian.ply, input.png (the prepared image), camera.json, result.safetensors (latent, camera) and meta.json (seed, steps, guidance, num_gaussians, mode).
  • PLY: convert to y-up and apply IDOL's clamps (max(s, 1e-6), opacity in [1e-6, 1 - 1e-6]) when building Gaussians, then call write_gaussian_ply unchanged; its own clamp is a no-op on those values, so the bytes match upstream's. Do not change the writer (SAM 3D Objects depends on it).
  • DINOv3-H+: reuse sam3d_body/backbone.rs if it can be loaded from the HF facebook/dinov3-vith16plus-pretrain-lvd1689m key layout through a key map and its RoPE matches (per-axis normalization, rope_theta periods); a unit test with shared random weights decides. Otherwise move the DINOv3 ViT into src/vision/dense/dinov3.rs, used by both, rather than writing a second copy inside idol/.
  • FLUX.2 VAE: reuse Flux2Vae's encoder; add a moments() accessor that returns mean and clipped log-variance so IDOL can sample the posterior; update its // Used by: comment.
  • BiRefNet: new (Swin-L backbone, ASPP with deformable convolutions, the multi-scale decoder) in birefnet.rs and deform_conv.rs; f32.
  • Host-side packing: the octree's variable-length packing runs on the CPU once per level, as upstream does; all network passes and random draws stay in MLX.

Rejected alternative: a /v1/meshes job API like upstream's. mlxcel dense prediction has no server route; adding one is separate infrastructure (see docs/vision-model-scope.md "Re-scoping a family", condition 2).

Scope

In scope: the module, the structural detection, CLI prediction with background removal, docs/supported-models.md and docs/dense-prediction.md entries (with the gated-encoder instructions), a row in the dense prediction table of docs/vision-model-scope.md, NOTICE (Idol SDK Apache-2.0, diffusers Wan Apache-2.0, mlx-vlm MIT; the DINOv3 and FLUX.2-dev weights keep their own licenses and are not redistributed).

Out of scope: a server route, mesh extraction, text conditioning, quantized weights, matching PyTorch outputs seed for seed (different RNGs).

Implementation notes

  • Dtype: transformer linears f16, embeddings and norms f32, rotary computations f32, BiRefNet f32, VAE bf16, DINOv3 bf16 by default.
  • Edge cases: an RGBA input with real alpha (skips BiRefNet), an RGB input with background_removal: false (error), an alpha mask that is empty after erosion (error), a non-square or tiny image, num_gaussians not a multiple of 32 or outside the range (error), steps < 1, negative or non-finite guidance or rescale_t (error), a missing encoder (error naming the repo).
  • Error handling: every validation error has upstream's message; non-finite Gaussian attributes fail the export.

Acceptance criteria

  • Detection test: the published config.json resolves to idol; a config without model_type and without the IDOL keys still fails with model_type not found.
  • Unit tests: systematic_sample with fixed offsets against upstream values; octree point counts sum to num_gaussians / 32 per level; RePo3DRotaryEmbedding and PcdAbsolutePositionEmbedderv2 against hand-computed values; Gaussian activations and the y-up PLY transform on a 2-point example; decode_camera perspective and orthographic cases; the preprocess crop geometry for both modes; deformable convolution against a direct reference on a 6x6 input.
  • Parity with fixed inputs against mlx-vlm on speridlabs/idol (no encoders needed). Upstream's sample and decode draw their noise, systematic-sampling offsets and final uniforms from the MLX RNG internally, so build the fixtures with a script that runs upstream and records those drawn arrays together with the outputs (upstream's systematic_sample already takes offsets); give mlxcel's sampler and octree decoder optional injected random inputs for tests. Fixtures: a stored random condition, recorded noise and 4 steps (latent and camera relative error under 3e-3, upstream's mixed-precision bound), and decode from a fixed latent at 32,768 Gaussians with the recorded offsets and uniforms (attribute relative error under 1e-3). They fail on current code.
  • With the encoders present: BiRefNet alpha on a fixture image within one 8-bit level of upstream's, DINOv3 features cosine similarity above 0.999 and VAE posterior mean relative error under 3e-2 against upstream.
  • mlxcel predict -m speridlabs/idol --image toy-castle.webp --task gaussian -o out/ --opts '{"mode": "synthetic"}' writes a finite gaussian.ply with 262,144 vertices, input.png and camera.json; the PLY opens in a standard 3DGS viewer.
  • mlxcel arch lists idol.

Verification

cargo test --profile test-fast vision::dense::idol
cargo test --profile test-fast vision::dense::geometry_io
make verify-test
cargo clippy --workspace --all-targets -- -D warnings
cargo fmt --check
./target/release/mlxcel predict -m models/idol --image tests/fixtures/<object>.png --task gaussian -o /tmp/idol --opts '{"num_gaussians": 32768}'

Related

  • Dense prediction surface #2349, epic #2382, SAM 3D Objects #2381 (Gaussian PLY output precedent), FLUX.2 VAE from #2424.
Ngôn ngữ chính
Rust
Star
505
Fork
81
Merge trung bình
14 giờ 2 phút
Pull request đã merge (30 ngày)
448

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của lablup/mlxcel

Tất cả issue của lablup/mlxcel

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.