Book contents +

XVI · Apple MLX acceleration (welvet.mlx) / CHAPTER 23

Apple MLX: caps and dtype rejects

Samuel Watson · Welvet feature bookOriginal source ↗

github.com/openfluke/welvet/nativemlxdarwin arm64


Why it exists

Unsupported mounts must hard-fail before any GPU work: not soft-fallback to Go labeled as MLX.

What it is

Print SupportedLayers, accept dense/float32, and show RequireLayer rejecting dense/float64.

Caps table

nativemlx.LayerSupported(layer, dtype) and SupportedLayers() mirror the welvet.mlx C ABI caps. SyncToMLX / RequireLayer refuse anything outside that table. Dense GPU compute rejects float64; host I/O stays Float32 activations with FormatNone parameter storage.

welvet.mlx 1.0.0 caps list the signed leaf ops (Dense, Softmax, RMSNorm, LayerNorm, CNN2/3, ConvT2/3, LSTM, Embedding, Residual, SwiGLU, MHA). Sequential is a container that mounts supported children: see §112. Full dtype matrix: FORWARD_CHECKLIST.md.

Requirements: chapter 110.

Go example

examples/111-apple-mlx-caps/main.go

Run:cd welvet/examples/111-apple-mlx-caps && source ../env.sh && go run .
// Print MLX caps and demonstrate RequireLayer rejects.
package main

import (
	"fmt"
	"log"
	"runtime"
	"strings"

	"github.com/openfluke/welvet/nativemlx"
)

func main() {
	if err := run(); err != nil {
		log.Fatal(err)
	}
}

func run() error {
	if runtime.GOOS != "darwin" || runtime.GOARCH != "arm64" {
		fmt.Println("SKIP: Apple MLX needs Apple silicon macOS and cgo")
		return nil
	}
	if !nativemlx.Available() {
		fmt.Println("SKIP: need libwelvet_mlx.dylib + Metal GPU")
		return nil
	}

	layers := nativemlx.SupportedLayers()
	fmt.Println("version", nativemlx.Version())
	fmt.Println("supported_layers", strings.Join(layers, ","))
	fmt.Println("dense/float32", nativemlx.LayerSupported("dense", "float32"))
	fmt.Println("dense/float64", nativemlx.LayerSupported("dense", "float64"))

	if err := nativemlx.RequireLayer("dense", "float32"); err != nil {
		return fmt.Errorf("expected dense/float32 ok: %w", err)
	}
	fmt.Println("RequireLayer dense/float32: ok")

	err := nativemlx.RequireLayer("dense", "float64")
	if err == nil {
		return fmt.Errorf("expected dense/float64 reject")
	}
	fmt.Println("RequireLayer dense/float64:", err)
	return nil
}

Output

exit 0 · last run via go run .

version 1.0.0
supported_layers dense,softmax,rmsnorm,layernorm,cnn2,cnn3,convt2,convt3,lstm,embedding,residual,swiglu,mha
dense/float32 true
dense/float64 false
RequireLayer dense/float32: ok
RequireLayer dense/float64: nativemlx: reject dense/float64: not supported on MLX GPU (see SupportedLayers)

Validate (harness)

cd welvet/examples/111-apple-mlx-caps && source ../env.sh && go run .