MLX.zig is a Zig language binding for Apple's MLX framework.
What it does
MLX.zig enables building and running LLMs directly in Zig without external build tools. The repository includes:
- A pure Zig build system that handles all C/C++ dependencies
- Direct bindings to MLX's C API for optimal performance
- A working transformer-based language model implementation
- A TikToken implementation using PCRE2 for text tokenization
Example usage
// Initialize components
var tokenizer = try Tokenizer.init(allocator, null);
var transformer = try Transformer.init(allocator, null);
// Encode and generate text
const input_ids = try tokenizer.encodeChat(allocator, "You are a helpful assistant.", "Hello world");
const output_ids = try transformer.generate(input_ids, 20);
// Decode the result
const output_text = try tokenizer.decode(output_ids);
Acknowledgement
The build system is based on Erik Kaunismäki's zig-build-mlx approach.
Top comments (0)