Files

438 lines
23 KiB
Markdown
Raw Permalink Normal View History

2026-06-28 20:05:10 -07:00
<p align="center"><img src=".github/hero.svg" alt="ml" width="880"></p>
2026-02-22 01:15:52 -08:00
# Hanzo ML
[![crates.io](https://img.shields.io/crates/v/hanzo-ml.svg?style=flat-square&color=black)](https://crates.io/crates/hanzo-ml)
[![docs.rs](https://img.shields.io/docsrs/hanzo-ml?style=flat-square&color=black)](https://docs.rs/hanzo-ml)
[![license](https://img.shields.io/badge/license-MIT%2FApache--2.0-black?style=flat-square)](https://github.com/hanzoai/ml)
**Fast, multi-backend tensor & ML for Rust — CPU · CUDA · Metal · ROCm · Vulkan, with quantization built in.**
Hanzo ML is a lightweight, memory-safe machine-learning framework for Rust, tuned for performance and
built for real deployment — the compute core beneath [Hanzo](https://hanzo.ai) inference. Rebuilt for the
Hanzo stack with optimizations for Edge AI, quantization, multimodal workloads, and NVIDIA GB10 / DGX
Spark unified memory. It's the canonical Rust implementation of the Hanzo compute substrate: one core,
every backend, from a browser tab to a datacenter GPU.
2026-02-22 01:15:52 -08:00
## Key Features
- **High Performance**: GPU acceleration via CUDA (incl. unified/managed memory for NVIDIA GB10 / DGX Spark), Metal (Apple Silicon), ROCm (AMD RDNA3.5 APUs), Vulkan, and CPU optimizations
- **Edge AI Optimized**: Quantization support (GGUF, GGML, AFQ, GPTQ, AWQ). On AMD `gfx1151` the full GGUF quant zoo (22 types: Q/K, legacy, IQ1-4, TQ) decodes resident + bit-exact through one unified compute core -- prefill beats llama.cpp (1.1-1.26x), decode at HIP parity.
2026-02-22 01:15:52 -08:00
- **Multimodal**: Text, vision, audio, and 3D model support
- **WebAssembly**: Run models in the browser with WASM support
- **Rust Native**: Memory-safe, zero-cost abstractions
- **Hanzo Integration**: Works seamlessly with Hanzo Engine for inference
2023-07-10 12:51:37 +02:00
2023-08-23 08:32:59 +00:00
## Get started
2023-07-10 12:51:37 +02:00
Make sure that you have [`hanzo-ml`](https://github.com/hanzoai/ml/tree/main/hanzo-ml) correctly installed as described in the [installation guide](https://github.com/hanzoai/ml/blob/main/hanzo-ml-book/src/guide/installation.md).
2023-08-23 08:32:59 +00:00
2023-08-23 08:52:53 +00:00
Let's see how to run a simple matrix multiplication.
2023-08-23 13:26:21 +02:00
Write the following to your `myapp/src/main.rs` file:
2023-08-23 08:32:59 +00:00
```rust
2026-02-22 01:15:52 -08:00
use hanzo_ml_core::{Device, Tensor};
2023-08-23 08:32:59 +00:00
2023-08-23 13:26:21 +02:00
fn main() -> Result<(), Box<dyn std::error::Error>> {
2023-08-23 08:42:47 +00:00
let device = Device::Cpu;
let a = Tensor::randn(0f32, 1., (2, 3), &device)?;
let b = Tensor::randn(0f32, 1., (3, 4), &device)?;
2023-08-23 08:32:59 +00:00
let c = a.matmul(&b)?;
println!("{c}");
Ok(())
}
2023-07-10 12:51:37 +02:00
```
2023-08-23 13:33:45 +02:00
`cargo run` should display a tensor of shape `Tensor[[2, 4], f32]`.
2023-08-23 08:32:59 +00:00
2026-02-22 01:15:52 -08:00
Having installed `hanzo` with Cuda support, simply define the `device` to be on GPU:
2023-08-23 08:32:59 +00:00
```diff
2023-08-23 08:42:47 +00:00
- let device = Device::Cpu;
2023-08-23 08:40:23 +00:00
+ let device = Device::new_cuda(0)?;
2023-08-23 08:32:59 +00:00
```
2023-08-23 08:52:53 +00:00
For more advanced examples, please have a look at the following section.
2023-07-10 12:51:37 +02:00
## Check out our examples
Browser (WASM) examples — build and run locally from [`hanzo-ml-wasm-examples`](https://github.com/hanzoai/ml/tree/main/hanzo-ml-wasm-examples):
- **yolo**: pose estimation and object recognition.
- **whisper**: speech recognition.
- **llama2.c**: text generation.
- **T5**: text generation.
- **Phi-1.5 / Phi-2**: text generation.
- **Segment Anything Model**: image segmentation.
- **BLIP**: image captioning.
2023-09-13 10:05:47 +02:00
2025-06-25 00:15:18 +02:00
We also provide some command line based examples using state of the art models:
2026-02-22 01:15:52 -08:00
- [LLaMA v1, v2, and v3](./hanzo-ml-examples/examples/llama/): general LLM, includes
the SOLAR-10.7B variant.
2026-02-22 01:15:52 -08:00
- [Falcon](./hanzo-ml-examples/examples/falcon/): general LLM.
- [Codegeex4](./hanzo-ml-examples/examples/codegeex4-9b/): Code completion, code interpreter, web search, function calling, repository-level
- [GLM4](./hanzo-ml-examples/examples/glm4/): Open Multilingual Multimodal Chat LMs by THUDM
- [Gemma v1 and v2](./hanzo-ml-examples/examples/gemma/): 2b and 7b+/9b general LLMs from Google Deepmind.
- [RecurrentGemma](./hanzo-ml-examples/examples/recurrent-gemma/): 2b and 7b
Griffin based models from Google that mix attention with a RNN like state.
2026-02-22 01:15:52 -08:00
- [Phi-1, Phi-1.5, Phi-2, and Phi-3](./hanzo-ml-examples/examples/phi/): 1.3b,
2024-04-24 20:54:24 +02:00
2.7b, and 3.8b general LLMs with performance on par with 7b models.
2026-02-22 01:15:52 -08:00
- [StableLM-3B-4E1T](./hanzo-ml-examples/examples/stable-lm/): a 3b general LLM
pre-trained on 1T tokens of English and code datasets. Also supports
StableLM-2, a 1.6b LLM trained on 2T tokens, as well as the code variants.
2026-02-22 01:15:52 -08:00
- [Mamba](./hanzo-ml-examples/examples/mamba/): an inference only
2023-12-23 10:46:02 +01:00
implementation of the Mamba state space model.
2026-02-22 01:15:52 -08:00
- [Mistral7b-v0.1](./hanzo-ml-examples/examples/mistral/): a 7b general LLM with
2023-12-16 06:23:12 -06:00
better performance than all publicly available 13b models as of 2023-09-28.
2026-02-22 01:15:52 -08:00
- [Mixtral8x7b-v0.1](./hanzo-ml-examples/examples/mixtral/): a sparse mixture of
2023-12-16 06:23:12 -06:00
experts 8x7b general LLM with better performance than a Llama 2 70B model with
much faster inference.
2026-02-22 01:15:52 -08:00
- [StarCoder](./hanzo-ml-examples/examples/bigcode/) and
[StarCoder2](./hanzo-ml-examples/examples/starcoder2/): LLM specialized to code generation.
- [Qwen1.5](./hanzo-ml-examples/examples/qwen/): Bilingual (English/Chinese) LLMs.
- [RWKV v5 and v6](./hanzo-ml-examples/examples/rwkv/): An RNN with transformer level LLM
2024-02-14 10:58:32 +01:00
performance.
2026-02-22 01:15:52 -08:00
- [Replit-code-v1.5](./hanzo-ml-examples/examples/replit-code/): a 3.3b LLM specialized for code completion.
- [Yi-6B / Yi-34B](./hanzo-ml-examples/examples/yi/): two bilingual
(English/Chinese) general LLMs with 6b and 34b parameters.
2026-02-22 01:15:52 -08:00
- [Quantized LLaMA](./hanzo-ml-examples/examples/quantized/): quantized version of
2023-08-20 14:33:21 +01:00
the LLaMA model using the same quantization techniques as
[llama.cpp](https://github.com/ggerganov/llama.cpp).
2023-09-13 10:05:47 +02:00
<img src="https://github.com/hanzoai/ml/raw/main/hanzo-ml-examples/examples/quantized/assets/aoc.gif" width="600">
2023-09-13 10:05:47 +02:00
2026-02-22 01:15:52 -08:00
- [Stable Diffusion](./hanzo-ml-examples/examples/stable-diffusion/): text to
2023-12-03 15:37:10 +08:00
image generative model, support for the 1.5, 2.1, SDXL 1.0 and Turbo versions.
2023-09-13 10:05:47 +02:00
<img src="https://github.com/hanzoai/ml/raw/main/hanzo-ml-examples/examples/stable-diffusion/assets/stable-diffusion-xl.jpg" width="200">
2023-09-13 10:05:47 +02:00
2026-02-22 01:15:52 -08:00
- [Wuerstchen](./hanzo-ml-examples/examples/wuerstchen/): another text to
2023-09-20 13:09:35 +01:00
image generative model.
<img src="https://github.com/hanzoai/ml/raw/main/hanzo-ml-examples/examples/wuerstchen/assets/cat.jpg" width="200">
2023-09-20 13:09:35 +01:00
2026-02-22 01:15:52 -08:00
- [yolo-v3](./hanzo-ml-examples/examples/yolo-v3/) and
[yolo-v8](./hanzo-ml-examples/examples/yolo-v8/): object detection and pose
estimation models.
2023-09-13 10:05:47 +02:00
<img src="https://github.com/hanzoai/ml/raw/main/hanzo-ml-examples/examples/yolo-v8/assets/bike.od.jpg" width="200"><img src="https://github.com/hanzoai/ml/raw/main/hanzo-ml-examples/examples/yolo-v8/assets/bike.pose.jpg" width="200">
2026-02-22 01:15:52 -08:00
- [segment-anything](./hanzo-ml-examples/examples/segment-anything/): image
2023-09-08 14:04:34 +01:00
segmentation model with prompt.
2023-09-13 10:05:47 +02:00
<img src="https://github.com/hanzoai/ml/raw/main/hanzo-ml-examples/examples/segment-anything/assets/sam_merged.jpg" width="200">
2023-09-13 10:05:47 +02:00
2026-02-22 01:15:52 -08:00
- [SegFormer](./hanzo-ml-examples/examples/segformer/): transformer based semantic segmentation model.
- [Whisper](./hanzo-ml-examples/examples/whisper/): speech recognition model.
- [EnCodec](./hanzo-ml-examples/examples/encodec/): high-quality audio compression
model using residual vector quantization.
2026-02-22 01:15:52 -08:00
- [MetaVoice](./hanzo-ml-examples/examples/metavoice/): foundational model for
text-to-speech.
2026-02-22 01:15:52 -08:00
- [Parler-TTS](./hanzo-ml-examples/examples/parler-tts/): large text-to-speech
model.
2026-02-22 01:15:52 -08:00
- [T5](./hanzo-ml-examples/examples/t5), [Bert](./hanzo-ml-examples/examples/bert/),
[JinaBert](./hanzo-ml-examples/examples/jina-bert/) : useful for sentence embeddings.
- [DINOv2](./hanzo-ml-examples/examples/dinov2/): computer vision model trained
2023-09-13 10:05:47 +02:00
using self-supervision (can be used for imagenet classification, depth
evaluation, segmentation).
2026-02-22 01:15:52 -08:00
- [VGG](./hanzo-ml-examples/examples/vgg/),
[RepVGG](./hanzo-ml-examples/examples/repvgg): computer vision models.
- [BLIP](./hanzo-ml-examples/examples/blip/): image to text model, can be used to
2023-10-22 09:44:48 +01:00
generate captions for an image.
2026-02-22 01:15:52 -08:00
- [CLIP](./hanzo-ml-examples/examples/clip/): multi-model vision and language
2024-03-28 23:10:57 +01:00
model.
2026-02-22 01:15:52 -08:00
- [TrOCR](./hanzo-ml-examples/examples/trocr/): a transformer OCR model, with
2024-02-10 15:49:38 +01:00
dedicated submodels for hand-writing and printed recognition.
2026-02-22 01:15:52 -08:00
- [Marian-MT](./hanzo-ml-examples/examples/marian-mt/): neural machine translation
model, generates the translated text from the input text.
2026-02-22 01:15:52 -08:00
- [Moondream](./hanzo-ml-examples/examples/moondream/): tiny computer-vision model
that can answer real-world questions about images.
2023-09-13 10:05:47 +02:00
Run them using commands like:
```
2023-08-20 14:33:21 +01:00
cargo run --example quantized --release
```
In order to use **CUDA** add `--features cuda` to the example command line. If
you have cuDNN installed, use `--features cudnn` for even more speedups.
2023-07-14 17:08:05 +02:00
2023-07-24 15:28:27 +01:00
There are also some wasm examples for whisper and
[llama2.c](https://github.com/karpathy/llama2.c). Build and run them locally with
`trunk` from [`hanzo-ml-wasm-examples`](https://github.com/hanzoai/ml/tree/main/hanzo-ml-wasm-examples)
(whisper, llama2.c, T5, Phi-1.5 / Phi-2, Segment Anything Model).
2023-07-24 15:28:27 +01:00
2023-08-20 14:33:21 +01:00
For LLaMA2, run the following command to retrieve the weight files and start a
2023-07-24 15:28:27 +01:00
test server:
```bash
2026-02-22 01:15:52 -08:00
cd hanzo-ml-wasm-examples/llama2-c
# Tiny Llama-2 weights from Andrej Karpathy's tinyllamas (see the example README for tokenizer.json):
wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin -O model.bin
2023-08-28 11:34:54 +01:00
trunk serve --release --port 8081
2023-07-24 15:28:27 +01:00
```
2023-08-09 19:36:03 +01:00
And then head over to
2023-08-28 11:34:54 +01:00
[http://localhost:8081/](http://localhost:8081/).
2023-09-12 06:06:21 -04:00
<!--- ANCHOR: useful_libraries --->
2023-10-20 09:08:39 +01:00
## Useful External Resources
2026-02-22 01:15:52 -08:00
- [`hanzo-ml-tutorial`](https://github.com/ToluClassics/hanzo-ml-tutorial): A
very detailed tutorial showing how to convert a PyTorch model to ML.
- [`hanzo-ml-lora`](https://github.com/hanzoai/hanzo-ml-lora): Efficient and
2026-02-22 01:15:52 -08:00
ergonomic LoRA implementation for ML. `hanzo-ml-lora` has
out-of-the-box LoRA support for many models from ML, which can be found
[here](https://github.com/hanzoai/hanzo-ml-lora/tree/master/hanzo-ml-lora-transformers/examples).
- [`optimisers`](https://github.com/KGrewal1/optimisers): A collection of optimisers
2023-10-25 21:51:45 +01:00
including SGD with momentum, AdaGrad, AdaDelta, AdaMax, NAdam, RAdam, and RMSprop.
- [`hanzo-ml-vllm`](https://github.com/hanzoai/hanzo-ml-vllm): Efficient platform for inference and
serving local LLMs, with a built-in `/v1` HTTP inference server.
2026-02-22 01:15:52 -08:00
- [`hanzo-ml-ext`](https://github.com/mokeyish/hanzo-ml-ext): An extension library to ML that provides PyTorch functions not currently available in ML.
- [`hanzo-ml-coursera-ml`](https://github.com/vishpat/hanzo-ml-coursera-ml): Implementation of ML algorithms from Coursera's [Machine Learning Specialization](https://www.coursera.org/specializations/machine-learning-introduction) course.
2023-11-21 05:18:14 +00:00
- [`kalosm`](https://github.com/floneum/floneum/tree/master/interfaces/kalosm): A multi-modal meta-framework in Rust for interfacing with local pre-trained models with support for controlled generation, custom samplers, in-memory vector databases, audio transcription, and more.
- [`hanzo-ml-sampling`](https://github.com/hanzoai/hanzo-ml-sampling): Sampling techniques for ML.
2026-02-22 01:15:52 -08:00
- [`gpt-from-scratch-rs`](https://github.com/jeroenvlek/gpt-from-scratch-rs): A port of Andrej Karpathy's _Let's build GPT_ tutorial on YouTube showcasing the ML API on a toy problem.
- [`hanzo-ml-einops`](https://github.com/tomsanbear/hanzo-ml-einops): A pure rust implementation of the python [einops](https://github.com/arogozhnikov/einops) library.
- [`atoma-infer`](https://github.com/atoma-network/atoma-infer): A Rust library for fast inference at scale, leveraging FlashAttention2 for efficient attention computation, PagedAttention for efficient KV-cache memory management, and multi-GPU support. It exposes a `/v1` HTTP inference API.
2025-01-04 17:07:30 -05:00
- [`llms-from-scratch-rs`](https://github.com/nerdai/llms-from-scratch-rs): A comprehensive Rust translation of the code from Sebastian Raschka's Build an LLM from Scratch book.
2023-09-12 06:06:21 -04:00
If you have an addition to this list, please submit a pull request.
<!--- ANCHOR_END: useful_libraries --->
2023-07-27 12:41:15 +02:00
<!--- ANCHOR: features --->
2023-07-10 12:51:37 +02:00
## Features
2023-08-09 21:09:21 +02:00
- Simple syntax, looks and feels like PyTorch.
2023-08-14 08:09:27 +01:00
- Model training.
- Embed user-defined ops/kernels, such as [flash-attention v2](https://github.com/hanzoai/ml/blob/89ba005962495f2bfbda286e185e9c3c7f5300a3/hanzo-flash-attn/src/lib.rs#L152).
2023-08-14 08:09:27 +01:00
- Backends.
- Optimized CPU backend with optional MKL support for x86 and Accelerate for macs.
- CUDA backend for efficiently running on GPUs, multiple GPU distribution via NCCL.
- WASM support, run your models in a browser.
2023-08-18 08:52:14 +01:00
- Included models.
2023-09-16 08:22:24 +02:00
- Language Models.
- LLaMA v1, v2, and v3 with variants such as SOLAR-10.7B.
2023-09-16 08:22:24 +02:00
- Falcon.
2024-02-28 21:02:41 +01:00
- StarCoder, StarCoder2.
2024-04-24 20:54:24 +02:00
- Phi 1, 1.5, 2, and 3.
- Mamba, Minimal Mamba
2024-08-17 19:31:23 +01:00
- Gemma v1 2b and 7b+, v2 2b and 9b.
2023-09-29 12:50:50 +02:00
- Mistral 7b v0.1.
- Mixtral 8x7b v0.1.
- StableLM-3B-4E1T, StableLM-2-1.6B, Stable-Code-3B.
- Replit-code-v1.5-3B.
2023-09-16 08:22:24 +02:00
- Bert.
- Yi-6B and Yi-34B.
2026-02-22 01:15:52 -08:00
- Qwen1.5, Qwen1.5 MoE.
2024-03-01 08:58:30 +01:00
- RWKV v5 and v6.
2023-11-21 09:38:27 +00:00
- Quantized LLMs.
- Llama 7b, 13b, 70b, as well as the chat and code variants.
- Mistral 7b, and 7b instruct.
- Mixtral 8x7b.
2023-12-16 06:23:12 -06:00
- Zephyr 7b a and b (Mistral-7b based).
- OpenChat 3.5 (Mistral-7b based).
- Text to text.
2023-11-09 12:55:09 -05:00
- T5 and its variants: FlanT5, UL2, MADLAD400 (translation), CoEdit (Grammar correction).
- Marian MT (Machine Translation).
2023-10-22 09:44:48 +01:00
- Text to image.
- Stable Diffusion v1.5, v2.1, XL v1.0.
- Wurstchen v2.
- Image to text.
- BLIP.
2024-02-10 15:49:38 +01:00
- TrOCR.
- Audio.
- Whisper, multi-lingual speech-to-text.
- EnCodec, audio compression model.
- MetaVoice-1B, text-to-speech model.
- Parler-TTS, text-to-speech model.
2023-09-16 08:22:24 +02:00
- Computer Vision Models.
2024-02-14 10:58:32 +01:00
- DINOv2, ConvMixer, EfficientNet, ResNet, ViT, VGG, RepVGG, ConvNeXT,
2024-08-28 12:20:09 +03:00
ConvNeXTv2, MobileOne, EfficientVit (MSRA), MobileNetv4, Hiera, FastViT.
2023-10-20 09:08:39 +01:00
- yolo-v3, yolo-v8.
2023-09-16 08:22:24 +02:00
- Segment-Anything Model (SAM).
- SegFormer.
- File formats: load models from safetensors, npz, ggml, or PyTorch files.
2023-08-14 08:09:27 +01:00
- Serverless (on CPU), small and fast deployments.
2023-08-18 08:52:14 +01:00
- Quantization support using the llama.cpp quantized types.
2023-07-10 12:51:37 +02:00
2023-07-27 12:41:15 +02:00
<!--- ANCHOR_END: features --->
2023-08-09 19:36:03 +01:00
## How to use
2023-07-10 12:51:37 +02:00
2023-07-27 12:41:15 +02:00
<!--- ANCHOR: cheatsheet --->
Cheatsheet:
2026-02-22 01:15:52 -08:00
| | Using PyTorch | Using ML |
2023-07-12 18:43:52 +01:00
|------------|------------------------------------------|------------------------------------------------------------------|
2023-08-09 19:24:28 +02:00
| Creation | `torch.Tensor([[1, 2], [3, 4]])` | `Tensor::new(&[[1f32, 2.], [3., 4.]], &Device::Cpu)?` |
| Creation | `torch.zeros((2, 2))` | `Tensor::zeros((2, 2), DType::F32, &Device::Cpu)?` |
2023-07-12 18:43:52 +01:00
| Indexing | `tensor[:, :4]` | `tensor.i((.., ..4))?` |
| Operations | `tensor.view((2, 2))` | `tensor.reshape((2, 2))?` |
| Operations | `a.matmul(b)` | `a.matmul(&b)?` |
| Arithmetic | `a + b` | `&a + &b` |
| Device | `tensor.to(device="cuda")` | `tensor.to_device(&Device::new_cuda(0)?)?` |
2023-07-12 18:43:52 +01:00
| Dtype | `tensor.to(dtype=torch.float16)` | `tensor.to_dtype(&DType::F16)?` |
2026-02-22 01:15:52 -08:00
| Saving | `torch.save({"A": A}, "model.bin")` | `hanzo::safetensors::save(&HashMap::from([("A", A)]), "model.safetensors")?` |
| Loading | `weights = torch.load("model.bin")` | `hanzo::safetensors::load("model.safetensors", &device)` |
2023-07-27 12:41:15 +02:00
<!--- ANCHOR_END: cheatsheet --->
## Structure
2023-07-10 12:51:37 +02:00
2026-02-22 01:15:52 -08:00
- [hanzo-ml](./hanzo-ml): Core ops, devices, and `Tensor` struct definition
- [hanzo-nn](./hanzo-nn/): Tools to build real models
- [hanzo-ml-examples](./hanzo-ml-examples/): Examples of using the library in realistic settings
- [hanzo-kernels](./hanzo-kernels/): CUDA custom kernels
- [hanzo-datasets](./hanzo-datasets/): Datasets and data loaders.
- [hanzo-transformers](./hanzo-transformers): transformers-related utilities.
- [hanzo-flash-attn](./hanzo-flash-attn): Flash attention v2 layer.
- [hanzo-onnx](./hanzo-onnx/): ONNX model evaluation.
2023-07-06 13:25:05 +01:00
## FAQ
2026-02-22 01:15:52 -08:00
### Why should I use ML?
2023-07-10 12:51:37 +02:00
<!--- ANCHOR: goals --->
2026-02-22 01:15:52 -08:00
ML's core goal is to *make serverless inference possible*. Full machine learning frameworks like PyTorch
are very large, which makes creating instances on a cluster slow. ML allows deployment of lightweight
2023-08-09 19:36:03 +01:00
binaries.
2023-07-10 12:51:37 +02:00
2026-02-22 01:15:52 -08:00
Secondly, ML lets you *remove Python* from production workloads. Python overhead can seriously hurt performance,
2023-08-09 19:36:03 +01:00
and the [GIL](https://www.backblaze.com/blog/the-python-gil-past-present-and-future/) is a notorious source of headaches.
2023-07-10 12:51:37 +02:00
2023-08-09 19:36:03 +01:00
Finally, Rust is cool! A lot of the HF ecosystem already has Rust crates, like [safetensors](https://github.com/huggingface/safetensors) and [tokenizers](https://github.com/huggingface/tokenizers).
2023-07-10 12:51:37 +02:00
<!--- ANCHOR_END: goals --->
### Other ML frameworks
- [dfdx](https://github.com/coreylowman/dfdx) is a formidable crate, with shapes being included
2023-08-09 19:36:03 +01:00
in types. This prevents a lot of headaches by getting the compiler to complain about shape mismatches right off the bat.
However, we found that some features still require nightly, and writing code can be a bit daunting for non rust experts.
We're leveraging and contributing to other core crates for the runtime so hopefully both crates can benefit from each
2023-08-09 19:36:03 +01:00
other.
- [burn](https://github.com/burn-rs/burn) is a general crate that can leverage multiple backends so you can choose the best
2023-08-09 19:36:03 +01:00
engine for your workload.
- [tch-rs](https://github.com/LaurentMazare/tch-rs.git) Bindings to the torch library in Rust. Extremely versatile, but they
2023-08-09 19:36:03 +01:00
bring in the entire torch library into the runtime. The main contributor of `tch-rs` is also involved in the development
2026-02-22 01:15:52 -08:00
of `hanzo`.
### Common Errors
#### Missing symbols when compiling with the mkl feature.
2023-07-06 13:25:05 +01:00
If you get some missing symbols when compiling binaries/tests using the mkl
or accelerate features, e.g. for mkl you get:
2023-07-06 13:25:05 +01:00
```
= note: /usr/bin/ld: (....o): in function `blas::sgemm':
.../blas-0.22.0/src/lib.rs:1944: undefined reference to `sgemm_' collect2: error: ld returned 1 exit status
= note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
= note: use the `-l` flag to specify native libraries to link
= note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo
```
or for accelerate:
```
Undefined symbols for architecture arm64:
"_dgemm_", referenced from:
2026-02-22 01:15:52 -08:00
hanzo_core::accelerate::dgemm::h1b71a038552bcabe in libhanzo_core...
"_sgemm_", referenced from:
2026-02-22 01:15:52 -08:00
hanzo_core::accelerate::sgemm::h2cf21c592cba3c47 in libhanzo_core...
ld: symbol(s) not found for architecture arm64
2023-07-06 13:25:05 +01:00
```
2023-08-09 19:36:03 +01:00
This is likely due to a missing linker flag that was needed to enable the mkl library. You
can try adding the following for mkl at the top of your binary:
```rust
2023-07-06 13:25:05 +01:00
extern crate intel_mkl_src;
```
or for accelerate:
```rust
extern crate accelerate_src;
```
2023-08-20 14:33:21 +01:00
#### Cannot run the LLaMA examples: access to source requires login credentials
```
Error: request error: https://huggingface.co/meta-llama/Llama-2-7b-hf/resolve/main/tokenizer.json: status code 401
```
2023-08-20 14:33:21 +01:00
This is likely because you're not permissioned for the LLaMA-v2 model. To fix
this, you have to register on the huggingface-hub, accept the [LLaMA-v2 model
conditions](https://huggingface.co/meta-llama/Llama-2-7b-hf), and set up your
authentication token. See issue
[#350](https://github.com/hanzoai/ml/issues/350) for more details.
2026-02-22 01:15:52 -08:00
#### Missing cute/cutlass headers when compiling flash-attn
2023-09-02 08:56:12 +02:00
```
2026-02-22 01:15:52 -08:00
In file included from kernels/flash_fwd_launch_template.h:11:0,
from kernels/flash_fwd_hdim224_fp16_sm80.cu:5:
kernels/flash_fwd_kernel.h:8:10: fatal error: cute/algorithm/copy.hpp: No such file or directory
#include <cute/algorithm/copy.hpp>
^~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Error: nvcc error while compiling:
```
[cutlass](https://github.com/NVIDIA/cutlass) is provided as a git submodule so you may want to run the following command to check it in properly.
```bash
git submodule update --init
2023-09-02 08:56:12 +02:00
```
2023-09-08 09:15:14 +02:00
#### Compiling with flash-attention fails
```
/usr/include/c++/11/bits/std_function.h:530:146: error: parameter packs not expanded with ...:
```
2024-04-17 22:43:00 +02:00
This is a bug in gcc-11 triggered by the Cuda compiler. To fix this, install a different, supported gcc version - for example gcc-10, and specify the path to the compiler in the NVCC_CCBIN environment variable.
2023-09-08 09:15:14 +02:00
```
2024-04-17 22:43:00 +02:00
env NVCC_CCBIN=/usr/lib/gcc/x86_64-linux-gnu/10 cargo ...
2023-09-08 09:15:14 +02:00
```
2023-09-15 13:25:10 +07:00
#### Linking error on windows when running rustdoc or mdbook tests
```
Couldn't compile the test.
2026-02-22 01:15:52 -08:00
---- .\hanzo-ml-book\src\inference\hub.md - Using_the_hub::Using_in_a_real_model_ (line 50) stdout ----
2023-09-15 13:25:10 +07:00
error: linking with `link.exe` failed: exit code: 1181
//very long chain of linking
= note: LINK : fatal error LNK1181: cannot open input file 'windows.0.48.5.lib'
```
Make sure you link all native libraries that might be located outside a project target, e.g., to run mdbook tests, you should run:
```
2026-02-22 01:15:52 -08:00
mdbook test hanzo-ml-book -L .\target\debug\deps\ `
2023-09-15 13:25:10 +07:00
-L native=$env:USERPROFILE\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows_x86_64_msvc-0.42.2\lib `
-L native=$env:USERPROFILE\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows_x86_64_msvc-0.48.5\lib
```
#### Extremely slow model load time with WSL
This may be caused by the models being loaded from `/mnt/c`, more details on
[stackoverflow](https://stackoverflow.com/questions/68972448/why-is-wsl-extremely-slow-when-compared-with-native-windows-npm-yarn-processing).
#### Tracking down errors
2026-02-22 01:15:52 -08:00
You can set `RUST_BACKTRACE=1` to be provided with backtraces when a hanzo
error is generated.
#### CudaRC error
If you encounter an error like this one `called `Result::unwrap()` on an `Err` value: LoadLibraryExW { source: Os { code: 126, kind: Uncategorized, message: "The specified module could not be found." } }` on windows. To fix copy and rename these 3 files (make sure they are in path). The paths depend on your cuda version.
`c:\Windows\System32\nvcuda.dll` -> `cuda.dll`
`c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4\bin\cublas64_12.dll` -> `cublas.dll`
`c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4\bin\curand64_10.dll` -> `curand.dll`
## Hanzo — the Open AI Cloud
Open source · every language · on-chain settlement. [hanzo.ai](https://hanzo.ai) · [docs.hanzo.ai](https://docs.hanzo.ai)
**SDKs in every language** — [Python](https://github.com/hanzoai/python-sdk) (flagship) · [TypeScript](https://github.com/hanzo-js/sdk) · [Go](https://github.com/hanzo-go/sdk) · [Rust](https://github.com/hanzo-rs/sdk) · [C++](https://github.com/hanzo-cpp/sdk) · [Swift](https://github.com/hanzo-swift/sdk) · [Kotlin](https://github.com/hanzo-kt/sdk) · [umbrella](https://github.com/hanzoai/sdk)