Skip to content

Read @BIN16@ weight blocks: half floats in .bin models - #43

Closed
ChinChangYang wants to merge 1 commit into
masterfrom
fp16-weights
Closed

ChinChangYang wants to merge 1 commit into
masterfrom
fp16-weights

Conversation

@ChinChangYang

Copy link
Copy Markdown
Owner

A .bin model's float block can only be @BIN@ and 32-bit floats, though gzip barely compresses them and every GPU backend that runs in fp16 casts the weights down as it builds the model. AuroraGo ships two b18c384 networks in its app and wants them half the size (ChinChangYang/AuroraGo#92).

A float block may now also be @BIN16@ followed by its count of IEEE 754 half floats, little-endian. desc.cpp's readFloats and katagocoreml's parser read either marker and widen a half block to 32 bits exactly, so nothing after the loader changes; an @BIN@ block reads as before, byte for byte.

AuroraGo rewrites only the convolution and matrix multiply blocks (99.6 % of the floats), keeping the batch norms and biases at 32 bits: 97.9 + 99.1 MB → 49.0 + 49.7 MB. Over 318 positions from real games (kata-raw-nn 0, MLX backend in fp16), the main network's win rate moved by 0.021 percentage points on average (0.27 at most) and its score lead by 0.013 points (0.10 at most), about what two builds of the MLX backend differ by on the same 32-bit file; through katagocoreml on the Neural Engine (FLOAT16) the two files give bit-identical outputs.

Two files, +106 −15. Checked with the MLX build of AuroraGo's corpus engine, where the same hunks are applied (GPU and the ANE mux); AuroraGo vendors the desc.cpp hunks into its Engine/ as for #32 and #42.

🤖 Generated with Claude Code

A binary model's float block may now be "@bin16@" followed by its
count of IEEE 754 half floats, little-endian, which desc.cpp's
readFloats and katagocoreml's parser widen to 32 bits as they read
(exactly: every half is a float). An "@bin@" block reads as before.

AuroraGo ships its two networks with their convolution and matrix
weights rewritten so (ChinChangYang/AuroraGo#92): half the bytes, and
the MLX backend runs those weights in fp16 anyway. The batch norms and
biases stay in "@bin@" blocks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ChinChangYang

Copy link
Copy Markdown
Owner Author

Closed unmerged, as #42: this fork's master is an upstream mirror (ruleset 「master: upstream sync only」). The branch fp16-weights (ff309a6) is the source AuroraGo's Engine/VENDORED.md names.

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.

1 participant