Repository navigation
Conversation
…ister The kernel-contract suites published each probe with two fallible appends, its list then the kernel list. When the second failed, the probe was already in its list: a suite whose errdefer frees the probe freed it twice (the errdefer, then Suite.deinit), and one without an errdefer leaked it on any earlier failure. contract.register (zig/src/core/contract/register.zig) reserves room in both lists, then publishes with appendAssumeCapacity on both, so a failure leaves neither holding the probe and the caller's errdefer still owning it; once it returns, the lists own the probe. It is generic over the probe and takes the kernel value, so a suite whose kernel is p.kernel(name) or a literal uses it too; either list may be passed as a pointer or as a pointer field. All 85 two-append sites on main (59 files under zig/tests/contract) now call it, and every probe has an errdefer that mirrors its suite's teardown (deinit once initialized, destroy where the teardown destroys) and runs only until it is published: 107 errdefers were added where a suite had none or only half. register_test.zig, run by test-kernel-contract, counts a probe's frees under std.testing.FailingAllocator: the old pattern frees it twice when the kernel list's growth fails and never when the probe list's does; register frees it exactly once either way, and once at teardown on success. Test code and the contract harness only: no kernel, engine or token change.
…together, in every suite
…attention alone loop_backend declared max_streams = 1, so four streams ran four forwards and each read all the weights. loop_round.zig runs every stream's rows in one pass: the row-wise kernels (mix, AR, gates, QKV, row dots, router, experts) once over all rows, each slot's convs and attention as its solo launches over its own rows. Each slot keeps its own window backup and history, so every stream rewinds alone. The backend verifies and keeps several windows at once and declares plain_share, max_streams and batch_rows (round_rows, 128). Every kernel gives a row the bits it gives it alone, so each stream's tokens are its solo tokens.
ashhart#4786 moves each stream's window backup and history from the shared scratch into its slot. Main's stream budget (ashhart#4640) reports per stream exactly what newSlot and the lane buffers allocate, so slotAllocs now sizes all four slot allocations, newSlot and histBytes take their sizes from it, and streamBytes sums them. Without this, admission would count each extra stream short by its backup and history. The stream_bytes test still pins the report to what the allocation hook sees, and its explicit formula now includes the backup and history.
…ged in whole 128-byte reads tf_ink2_loop_project_qkv tiles 16 rows by 16 outputs, so a one-row decode left 15 of 16 threads idle and re-read its weights in 32-column slices. For up to 16 rows, tf_ink2_loop_qkv_rows1/4/16 run a warp per 32 output columns: the warp stages its 32 weight rows 64 columns at a time with whole-row 128-byte reads and the rows' inputs, and each thread runs its output's rows over the same ascending FP32 chain, so the BF16 results are tf_ink2_loop_project_qkv's. Prompt chunks keep tf_ink2_loop_project_qkv.
…places, its usage on every SM projectQkvTiles keeps tf_ink2_loop_project_qkv's 16x16-tile launch callable at any row count (prompts take it as before); the contract's ProjectQkv now names it in replaces, so gate 3 compares the decode kernels' q, k and v bytes with the tiles' on the same inputs at every served shape. The control told one row fewer stays red against the tiles. tf_ink2_loop_qkv_rows1/4/16 compiled with nvcc 13.0 -cubin -O3 per SM: 128/128/90 registers on sm_80, 128/128/88 on sm_86 and sm_89, 86/90/103 on sm_120 as on sm_121; static shared bytes and the 32-thread bound as on sm_121, no stack or spills.
Refs ashhart#4961 Use ceiling-power-of-two sp_matvec_{1,2,4,8,16,32} dispatch in inkling2/metal/forward.zig so non-power-of-two widths up to 32 rows read weights once instead of 2x-4x, and 64-row prefills dispatch 32+32. Guard X row loads in core/bf16_matvec.metal (early return for a.rows == 0 and branchless min(r, active - 1u) clamping on partial tiles), and tile ROWS > 16 into <=16-row sub-chunks inside the single 32-row kernel to avoid acc[32] register spilling while preserving exact FP32 serial summation order. Add host dispatch and Metal tight-buffer exactness tests for inkling2 dense(), and exercise partial-tile row counts (5, 9, 17) in llama matvec contract probes.
…ision glue (ashhart#2251) Qwen-Image's qi_sum, MOSS-Image's mi_sum, Unlimited-OCR-2's uv_sum, ud_sum and ud_max, Idol's id_sum and DINOv3's dn_sum were copies of vision_glue.metal's tf_vis_sum and tf_vis_max. Those libraries now start with the vision glue and call its helpers; vision_glue.metal includes metal_stdlib itself, so the OCR libraries, which have no template ahead of it, compile it too. GLM's glmv_bias and Qwen-VL's qwv_bias had the same body, bf16(y + b) after the rounded product: both come from TF_VIS_BIAS, qwv_bias keeping its 256-thread reservation. Kernel names and signatures are unchanged.
…art#2251) fn_rows_hc.metal's stream_rinv and fn_prompt.metal's pf_rinv had the same body. core/stream_rinv.metal now holds it, ahead of both libraries in sources.zig; the Qwen4 HC source reads it from there.
…three prompt libraries that copied it (ashhart#2251) fn_select, fn_pool_pos and fn_mrope each carried fn_rotary_scalar.metal's text verbatim. They now include it, and sources.zig puts the file in at that line, so the assembled libraries are byte-identical to before.
- Dropped a trailing blank line.
…ps in 64 bits and k leaves room for a block's stride
…a stress row over every head, its head sum simulated in the accumulator
…est that a failing second set leaks nothing
…d sparse_index images and exports
…nvcc 13.0.88 builds it
…y, same accepted values
…ate.modelAdmission, before the model is created
…ded to bf16 in registers on the bf16 experts' chain The two downs (fp32 and bf16 sums) in the decode and prompt forms read a checkpoint's MXFP4 experts as stored, [E][N][K/2] codes low nibble first and [E][N][K/32] scales, decode each weight to bf16 exactly and run experts_bf16's mma chain, so they give the bf16 experts' bytes on the host-decoded weights. Up is refused; checkScales takes E8M0 codes 2 to 252, where every E2M1 multiple is a finite, normal bf16. Registered with the kernel contract against float64 (two controls), with nvcc 13.0's launch records; no served checkpoint selects it.
|
Thanks for moving the H3 video and audio VAE support forward. The static review confirms that the current stereo plane indexing is correct, and that the new media paths are opt-in. The added read-ahead and serialization coverage is useful, but the aggregate test step needs to keep the existing read-ahead runs. Several correctness issues still need fixes before this is ready. The RoPE sine slices are empty before they are written, temporal padding and final cropping differ from the checked-in reference, and RGB tiles are quantized before blending. The re-voice path also advances video despite the documented hold-fixed contract. The encoder's odd-dimension tracking and unit-test call need correction, and the standalone audio decoder must derive stereo length from the input instead of assuming 207 frames. The stereo regression should exercise the actual writer. Finally, please split the oversized video module, make the parity fixtures self-contained and exact, and rewrite the parts ported from
|
…tiling module One-line docstrings in the H3 python references, single-line doc comments in the H3 Zig files, one-line file headers, vae_video.zig split past 600 lines into vae_video_tiling.zig with decodePiece, and stale debug dump blocks removed from the decode path.
|
Thank you @mikolaj92 for splitting the video module and adding the stereo-writer regression. STOP. The supplied tree still contains code expressly identified as adapted from another Please replace the adapted implementations with your own code written from documented behavior.
|
What this changes
Before: H3 video and audio decode ran through the Python MLX reference implementations; main cannot generate H3 video natively in Zig. After: the video VAE, image VAE and audio VAE decoders run as native Zig on Metal, and one tf-h3-dit run denoises the picture and re-voices the audio without a second checkpoint load.
Checks on this head
Receipt
Kernel contract, only when a GPU kernel is new or changed
Checklist
For a change that reaches inference: