fast-weight-loader

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

fast-weight-loader

Zero-cgo benchmark and verification example for github.com/tmc/apple/x/metalio (MTLIOCommandQueue, MTLIOFileHandle, MTLIOCommandBuffer).

What it does

  1. Generates a deterministic multi-tensor float32 weight file in $TMPDIR (default 64 MiB, 16 tensors; automatically removed on exit).
  2. Streams the file into a shared MTLBuffer across four paths:
    • metalio (single): one Queue.LoadBuffer call for the whole file.
    • metalio (batch N): one Queue.LoadBatch call encoding N concurrent tensor loads into a single MTLIOCommandBuffer.
    • posix os.ReadFile+copy: POSIX read into Go heap + copy into MTLBuffer.
    • posix mmap+copy: syscall.Mmap + copy into MTLBuffer.
  3. Verifies exact byte-for-byte and CRC32 parity across all four paths.
  4. Runs a Metal compute reduction kernel (sum_squares_f32) directly over the x/metalio-loaded MTLBuffer and compares against a float64 CPU reference.

Usage

CGO_ENABLED=0 go run ./examples/metal/fast-weight-loader
CGO_ENABLED=0 go run ./examples/metal/fast-weight-loader -size-mib 128 -tensors 32 -iters 5
CGO_ENABLED=0 go test -v ./examples/metal/fast-weight-loader

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, 16 tensors, iters=5, warmup=1):

Parity & Compute Sanity
  • Byte & CRC32 parity: exact=true, crc32=0xaacc2788 across all 4 paths (single, batch 16, os.ReadFile+copy, mmap+copy).
  • Metal compute sum_squares_f32 sanity: gpu=1398106.893066, cpu=1398108.833250, rel_err=1.388e-06.
Throughput & Latency (Warm Page Cache)
Path Median Mean Min Median GiB/s
metalio (single) 9.941 ms 11.068 ms 8.637 ms 6.29
metalio (batch 16) 2.640 ms 3.608 ms 2.048 ms 23.67
posix os.ReadFile+copy 15.036 ms 19.731 ms 12.508 ms 4.16
posix mmap+copy 8.211 ms 8.294 ms 7.863 ms 7.61

Batching per-tensor reads into a concurrent MTLIOCommandQueue (metalio (batch 16)) achieves 23.67 GiB/s median (5.69x over os.ReadFile+copy, 3.11x over mmap+copy) by letting Metal fan out parallel I/O transfers directly into unified MTLBuffer memory without an intermediate Go heap allocation.

Documentation

Rendered for darwin/amd64

Overview

Command fast-weight-loader benchmarks direct NVMe-to-MTLBuffer weight loading using x/metalio against POSIX os.ReadFile+copy and mmap+copy controls, verifies byte/CRC32 parity, and runs a Metal compute dot-product sanity check over the loaded weights.

Jump to

Keyboard shortcuts

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