compressed-weight-stream

command
v0.6.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

compressed-weight-stream

Zero-cgo benchmark and verification example comparing Metal native compressed weight loading (MTLIOCreateCompressionContext + x/metalio.OpenCompressedFile) against uncompressed x/metalio and CPU x/compression.Decode + copy.

What it does

  1. Generates a deterministic synthetic quantized/FP16-like weight tensor in $TMPDIR (default 64 MiB; automatically removed on exit) with clustered small FP16 exponents, quantized mantissas, and ~25% zero sparsity.
  2. Packs .mtlio compressed files using Metal's native MTLIOCreateCompressionContext, MTLIOCompressionContextAppendData, and MTLIOFlushAndDestroyCompressionContext for both LZ4 and LZFSE.
  3. Encodes matching raw LZ4 and LZFSE files using x/compression.Encode.
  4. Loads all five representations into a shared MTLBuffer and compares on-disk size, compression ratio, latency, effective uncompressed GiB/s, and exact byte-for-byte + CRC32 parity:
    • metalio (uncompressed): x/metalio.OpenFile + Queue.LoadBuffer.
    • metalio (LZ4 .mtlio): x/metalio.OpenCompressedFile(..., MTLIOCompressionMethodLZ4) + Queue.LoadBuffer.
    • metalio (LZFSE .mtlio): x/metalio.OpenCompressedFile(..., MTLIOCompressionMethodLZFSE) + Queue.LoadBuffer.
    • cpu x/compression (LZ4)+copy: os.ReadFile + x/compression.Decode(LZ4, ...) + copy into MTLBuffer.
    • cpu x/compression (LZFSE)+copy: os.ReadFile + x/compression.Decode(LZFSE, ...) + copy into MTLBuffer.

Usage

CGO_ENABLED=0 go run ./examples/metal/compressed-weight-stream
CGO_ENABLED=0 go run ./examples/metal/compressed-weight-stream -size-mib 128 -iters 5
CGO_ENABLED=0 go test -v ./examples/metal/compressed-weight-stream

Live Results (Apple M4 Max, macOS 26.6.2)

Recorded on Apple M4 Max (UnifiedMemory=true), macOS 26.6.2 (Build 25G83), Go 1.27.0 (darwin/arm64), CGO_ENABLED=0, default 64 MiB (67,108,864 bytes, MTLIO chunk size 65,536 bytes, iters=5, warmup=1):

Parity
  • Byte & CRC32 parity: all_exact=true, crc32=0x74c44f1d across all 5 paths.
Compression Ratio & Throughput (Warm Page Cache)
Path Disk MiB Ratio Median Mean Min Eff. GiB/s CRC32 Exact
metalio (uncompressed) 64.00 1.00x 5.797ms 6.905ms 5.265ms 10.78 0x74c44f1d true
metalio (LZ4 .mtlio) 55.85 1.15x 53.851ms 60.747ms 38.547ms 1.16 0x74c44f1d true
metalio (LZFSE .mtlio) 36.19 1.77x 113.204ms 118.189ms 111.517ms 0.55 0x74c44f1d true
cpu x/compression (LZ4)+copy 55.55 1.15x 48.732ms 47.079ms 41.424ms 1.28 0x74c44f1d true
cpu x/compression (LZFSE)+copy 36.18 1.77x 109.435ms 114.335ms 106.14ms 0.57 0x74c44f1d true
Notes
  • LZFSE shrinks the synthetic quantized/FP16-like tensor by 1.77x (64.00 MiB -> 36.19 MiB on disk), compared to 1.15x (55.85 MiB) for LZ4.
  • Under warm page cache, single-buffer metalio (LZ4 .mtlio) (1.16 GiB/s) and metalio (LZFSE .mtlio) (0.55 GiB/s) match CPU x/compression.Decode + copy (1.28 GiB/s / 0.57 GiB/s) while decoding directly into the target MTLBuffer without allocating an intermediate Go heap buffer.
  • Uncompressed metalio (10.78 GiB/s) is memory-copy bound under warm page cache; compressed .mtlio trades CPU/decompression throughput for smaller storage footprint and reduced cold-storage I/O.

Documentation

Rendered for darwin/amd64

Overview

Command compressed-weight-stream benchmarks Metal compressed weight loading (.mtlio LZ4 and LZFSE via x/metalio.OpenCompressedFile) against uncompressed x/metalio and CPU x/compression.Decode + copy, verifying CRC32 and exact byte-for-byte parity.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL