trellis_sparse_mrp_mlx/tests
John 8981919ee3 Fix RoPE: complex phases, and RMS-norm BEFORE rotation
Two silent bugs, both found by diffing against upstream running on CPU torch. The flow
models have no sparse conv, so upstream is runnable here with flash-attn swapped for
SDPA - a real numerical oracle, unlike the sparse path.

1. rope_phases ships as COMPLEX64 (torch.polar), so the rotation is a complex multiply
   and cos/sin are the phase's real/imag parts. Taking cos() of a complex phase was
   completely wrong. Verified against torch's view_as_complex formulation to 1.2e-7.

2. Upstream applies qk RMS norm BEFORE RoPE; I had it reversed. They do not commute -
   RMS applies a per-component gain, RoPE rotates within pairs. Reversed, one block
   still correlated 0.9998, which compounded to 0.84 across 30 blocks.

After both: SparseStructureFlowModel matches upstream at correlation 1.00000000,
max abs diff 1.2e-5, on the real 1.3B checkpoint.
2026-08-02 12:02:44 +10:00
..
test_dit.py Fix RoPE: complex phases, and RMS-norm BEFORE rotation 2026-08-02 12:02:44 +10:00
test_ops.py Shared TRELLIS-lineage sparse core in MLX 2026-08-02 10:31:07 +10:00
test_sparse.py Add masked upsample and parameterise downsample reduction (16/16 tests) 2026-08-02 10:42:20 +10:00