Forma Micro-Models (int4 Quantized UV Kernel Policies)

Two ultra-tiny, pure-integer int4-quantized neural micro-MLPs (1,466 bytes total footprint, 1,644 4-bit weights = 822 bytes packed) compiled directly into Forma (forma-3d) β€” a pure-Rust / WebAssembly headless 3D polyhedral modeling engine for AI agents.

Instead of relying on a single brittle set of hard-coded UV unwrapping thresholds or exhaustively running dozens of expensive LSCM solves per mesh, Forma uses these two sub-kilobyte models to adaptively pick the best UV unwrapping strategy and pre-rank concave chart split cuts in ~1–15 Β΅s on CPU/WASM, with zero external dependencies, zero GPU, and bit-exact determinism across x86_64, aarch64, and wasm32.


What These Models Can Do

1. uv_strategy_int4 β€” Per-Mesh UV Strategy Controller (832 B)

  • Problem it solves: Fixed UV unwrapping parameters fail across diverse 3D geometry. A sharp prismatic flange wants broad planar charts and tight MaxRects sorting, whereas a twisted rail, perforated plate, or curved dome needs aggressive concave bisection, strip slicing, and small-island absorption to avoid wasted atlas space or overlapping/stretched UVs.
  • What it does: Reads 16 fast $O(F)$ geometric invariants from any polyhedral mesh and outputs raw int32 Q-values for 12 diverse UV unwrapping & MaxRects packing strategies (UV_POLICY_ARMS[0..12]), picking argmax in ~1 Β΅s:
    • Arm 0: Classic balanced baseline (seed_dot_min=0.2588, BSSF)
    • Arm 1: Tight-curved balanced (seed_dot_min=0.5733, BLSF)
    • Arm 2: Aggressive concave / L-bracket & shell splitter (split_fill_thresh=0.88, depth 5)
    • Arm 3: Tight strip slicer + small-island absorption (twisted bars, pipes, cylinders)
    • Arms 4–11: Specialized regimes covering perforated plates, curved domes/organic meshes, swept rails, and high-poly assemblies (varying seed_dot_min, split_fill_thresh, split_gain_ratio, target_max_side_mult, MaxRects sort/heuristic, and absorb_small).
  • Training: Quantization-Aware Training (QAT) as a contextual bandit on 706 synthetic procedural Forma meshes across 18 geometric families, validated on 178 strictly disjoint unseen meshes.

Input Feature Vector (16 floats, extract_uv_features)

Index Feature Meaning
0 log_faces $\ln(N_f + 1) / 8$ clamped to $[0, 1]$
1 log_verts $\ln(N_v + 1) / 8$ clamped to $[0, 1]$
2 mean_k_norm Mean face polygon valence normalized from triangles to octagons
3 aspect_mid Middle-to-longest bounding-box extent ratio
4 aspect_min Shortest-to-longest bounding-box extent ratio
5 compactness_excess Surface area vs. RMS spherical area proxy
6 flat_frac Fraction of interior edges that are coplanar ($\text{dot} \ge 0.999$)
7 smooth_frac Fraction of interior edges below the user crease angle
8 sharp_frac Fraction of interior edges above the user crease angle
9 concave_frac Fraction of reflex / concave interior edges
10 mean_turn Mean dihedral turn $(1 - \mathbf{n}_a \cdot \mathbf{n}_b) / 2$
11 smooth_turn Scaled mean dihedral turn among smooth edges
12 max_face_frac Largest single face area fraction
13 top3_frac Combined area fraction of the 3 largest faces
14 genus_norm Estimated topological genus $/ 10$ (from Euler characteristic $\chi = V - E + F$)
15 dom_aligned_frac Area fraction aligned with dominant principal face normals

2. uv_split_ranker_int4 β€” Non-Myopic 2D Chart Split-Cut Pre-Ranker (634 B)

  • Problem it solves: Concave, L-shaped, U-shaped, or perforated UV charts leave huge empty rectangles inside their 2D bounding boxes when packed. Evaluating all 28 candidate split cuts (U, V, +45Β°, -45Β° axes Γ— 7 cut fractions [0.12, 0.22, 0.35, 0.50, 0.65, 0.78, 0.88]) with full sparse LSCM re-parameterization is expensive.
  • What it does: Scores each candidate 2D chart cut in microseconds using 16 cheap $O(F)$ 2D projection features (cut position, axis orientation, child area balance, bounding-box gain, neck width, seam length, concavity) so the UV engine only runs expensive sparse LSCM solves on the Top-K ranked cuts.
  • Validation: 93.5% Val Top-3 Recall on 828 unseen chart split groups (mean regret 0.0045 vs. geometric heuristic 0.0332 β€” a 7.4Γ— regret reduction).

Summary Table

Model Subdirectory Architecture int4 Weights Packed Bytes Total Footprint Latency (CPU/WASM)
UV Strategy Controller uv_strategy_int4/ 16 β†’ 24 β†’ 16 β†’ 12 960 480 B 832 B ~1 Β΅s
UV Split-Cut Pre-Ranker uv_split_ranker_int4/ 16 β†’ 24 β†’ 12 β†’ 1 684 342 B 634 B ~15 Β΅s (all 28 cuts)
Total β€” β€” 1,644 822 B 1,466 B β€”

How to Use These Models

Option 1: Use Out of the Box in Forma (CLI / MCP / WASM)

Both models are already compiled into forma-3d and run automatically whenever Forma generates UVs (e.g., .glb export):

npx -y forma-3d eval --strict --out part.glb -e 'box(4, 2, 0.4) | cut(cyl(0.5, 1))'

Option 2: Run Bit-Exact Reference Inference in Python

Download the repo with the Hugging Face CLI and run the included NumPy + Safetensors reference script (matches Rust i32 arithmetic bit-for-bit):

hf download wrongnebula/forma-micro-models --local-dir ./forma-micro-models
python3 ./forma-micro-models/inference.py
import numpy as np
from inference import score_uv_strategy, score_split_cut

# 1. Pick the best UV strategy arm (0..11) for a mesh
mesh_feats = np.array([
    0.58, 0.55, 0.12, 0.75, 0.42, 0.39, 0.31, 0.26,
    0.43, 0.12, 0.22, 0.10, 0.09, 0.21, 0.07, 0.68,
], dtype=np.float32)
arm_scores = score_uv_strategy(mesh_feats, "./forma-micro-models")
best_arm = int(np.argmax(arm_scores))

# 2. Rank 28 candidate 2D chart split cuts and keep Top-K for LSCM
cut_scores = [score_split_cut(cut_feat, "./forma-micro-models") for cut_feat in candidate_cuts]
top3_indices = np.argsort(cut_scores)[-3:][::-1]

Option 3: Embed Directly in Your Own Rust / C++ / WASM / Shader Engine

Because the entire inference loop is 3 integer matrix-vector products with ReLU and fixed-point bit-shifts (no floats inside the matmuls, no BLAS, no runtime allocations), you can drop the weights straight into any 3D engine:

  • Rust: Copy rust/uv_policy.rs directly β€” zero external crates (std-only).
  • C / C++ / Zig / JS / WGSL: Load weights.json or *.safetensors (layer{1,2,3}.weight_packed_u8 or unpacked weight_int4), quantize normalized inputs via round((x - mean) * inv_std * 32).clamp(-127, 127), accumulate int4 Γ— int8 β†’ int32 + bias, and apply ((max(acc, 0) * M) >> S).clamp(0, 127) between layers.

Quantization Specification

  • Weights: Signed 4-bit ([-8, 7]), stored both unpacked (int8 tensor *.weight_int4) and nibble-packed (uint8 tensor *.weight_packed_u8, offset-binary w + 8, low nibble = even index, high nibble = odd index).
  • Inputs: Z-score normalized with feat_mean / feat_inv_std and quantized to int8 (Q2.5, scale 32.0, clamped [-127, 127]).
  • Hidden layers: int4 Γ— int8 β†’ int32 dot product + int32 bias + ReLU + fixed-point requantization ((acc * M) >> S).clamp(0, 127).

Scope & Limitations

  • These are learned geometric decision policies, not standalone generative 3D models. They are meant to be paired with the lightweight feature extractors in rust/uv_policy.rs inside a UV unwrapping/packing pipeline.
  • Trained primarily on CAD, mechanical, architectural, and procedural polyhedral meshes; for heavily scanned organic/sculpted meshes, you may want to pair them with wrongnebula/hullyeah-micro-models or recalibrate on your own mesh distribution.

Repository Contents

  • forma_micro_models.safetensors β€” Combined safetensors bundle for both models
  • uv_strategy_int4/ & uv_split_ranker_int4/ β€” Per-model model.safetensors, config.json, and weights.json
  • inference.py β€” Bit-exact NumPy + Safetensors reference implementation
  • rust/uv_policy.rs β€” Original pure-Rust zero-dependency implementation from forma-core

License

Released under GPL-3.0-or-later (matching Forma).

Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support