An MLIR-based compiler framework designed for a co-design ecosystem from DSL (domain-specific languages) to DSA (domain-specific architectures). (Project page)
Getting Started
Dependencies
LLVM/MLIR dependencies
Please make sure the dependencies are available
on your machine.
DeepSeek R1, Whisper, and Qwen3-VL support template-based layer-partitioned compilation. It is disabled by default. Enable it explicitly by passing
--cmake-args=-DBUDDY_MODEL_LAYER_PARTITION=ON to build_model.py. DeepSeek R1 also retains the existing PartitionedGraphDriver workflow. See Layer Partitioning for details.
For example, enable template-based layer partitioning for Whisper with:
To import weights from a local HuggingFace style directory (offline or a custom path), pass --local-model to that directory (it must contain config.json and the weight files). If you omit --hf-config, build_model.py uses <local-model>/config.json for codegen when present:
models/qwen3_vl is a self-contained vision-language model (ViT + DeepStack
encoder feeding a dense Qwen3 decoder) that runs end-to-end on buddy-compiled
kernels via buddy-cli. Use the same tools/buddy-codegen/build_model.py entry
point with the Qwen3-VL spec (a local HuggingFace snapshot is required):
python3 tools/buddy-codegen/build_model.py \
--spec models/qwen3_vl/specs/instruct_2b.json \
--build-dir build \
--local-model /path/to/Qwen3-VL-2B-Instruct
./build/bin/buddy-cli \
--model ./build/models/qwen3_vl/qwen3_vl.rax \
--image ./models/qwen3_vl/test_text.png \
--prompt "Read all the text in the image."
We provide examples to demonstrate how to use the passes and interfaces in buddy-mlir, including IR-level transformations, domain-specific applications, and testing demonstrations.
Triton AST/TTIR compilation is provided by the external triton-riscv AOT
frontend. Buddy consumes verified standard buffer Contracts and owns BOSCAME
planning, emission and firmware construction. All Triton Python examples and the
ViT model live in triton-riscv/examples/BOSCAMEFPGA. Buddy’s three standalone
examples live in examples/BOSCAMEFPGA and start at kernel.frontend.mlir.
See Triton Contract handoff.
To maintain code quality, this project provides pre-commit checks:
pre-commit install
How to Cite
If you find our project and research useful or refer to it in your own work, please cite the survey paper in which the Buddy Compiler design was first proposed:
@article{zhang2023compiler,
title={Compiler Technologies in Deep Learning Co-Design: A Survey},
author={Zhang, Hongbin and Xing, Mingjie and Wu, Yanjun and Zhao, Chen},
journal={Intelligent Computing},
year={2023},
publisher={AAAS}
}
BUDDY MLIR
An MLIR-based compiler framework designed for a co-design ecosystem from DSL (domain-specific languages) to DSA (domain-specific architectures). (Project page)
Getting Started
Dependencies
Please make sure the dependencies are available on your machine.
Clone and Initialize
Prepare Python Environment
pip
uv
conda
On a RISC-V host, add the Ruyi package index for the riscv64 wheels, see docs/RVVEnvironment.md.
Build and Test LLVM/MLIR/CLANG
If your target machine includes an NVIDIA GPU, you can add the following configuration:
Build buddy-mlir
Set the
PYTHONPATHenvironment variable to include both the LLVM/MLIR Python bindings andbuddy-mlirPython packages:If you want to test your model end-to-end conversion and inference, you can add the following configuration
Building and running the model
Use the following to build:
For Whisper, use the same build entry point with the Whisper spec:
DeepSeek R1, Whisper, and Qwen3-VL support template-based layer-partitioned compilation. It is disabled by default. Enable it explicitly by passing
--cmake-args=-DBUDDY_MODEL_LAYER_PARTITION=ONtobuild_model.py. DeepSeek R1 also retains the existingPartitionedGraphDriverworkflow. See Layer Partitioning for details.For example, enable template-based layer partitioning for Whisper with:
To import weights from a local HuggingFace style directory (offline or a custom path), pass
--local-modelto that directory (it must containconfig.jsonand the weight files). If you omit--hf-config,build_model.pyuses<local-model>/config.jsonfor codegen when present:If CMake is configured with
-DBUDDY_BUILD_DEEPSEEK_R1_MODEL=ON, you can build the model with:To build the DeepSeek R1 f32 tiered KV cache variant for use with
buddy-cli, use the dedicated spec:Whisper uses the same
.rax/buddy-clideployment path, with an audio input:Qwen3-VL (vision-language OCR)
models/qwen3_vlis a self-contained vision-language model (ViT + DeepStack encoder feeding a dense Qwen3 decoder) that runs end-to-end on buddy-compiled kernels viabuddy-cli. Use the sametools/buddy-codegen/build_model.pyentry point with the Qwen3-VL spec (a local HuggingFace snapshot is required):See
models/qwen3_vl/README.mdfor prerequisites and details.Build Python Package
We use
setuptoolsto bundle CMake outputs (Python packages,bin/, andlib/) into a single wheel.Build x86_64 artifacts:
Build riscv64 artifacts:
This script calls
docker runinternally to enter the offical manylinux container, builds LLVM and buddy_mlir, and writes artifacts to:./build-docker/x86_64/<py_tag>/target./build-docker/riscv64/<py_tag>/targetSee Manylinux release notes for current known build notes.
Install and test the wheel:
Examples
We provide examples to demonstrate how to use the passes and interfaces in
buddy-mlir, including IR-level transformations, domain-specific applications, and testing demonstrations.For more details, please see the examples documentation.
Triton FPGA frontend boundary
Triton AST/TTIR compilation is provided by the external triton-riscv AOT frontend. Buddy consumes verified standard buffer Contracts and owns BOSCAME planning, emission and firmware construction. All Triton Python examples and the ViT model live in
triton-riscv/examples/BOSCAMEFPGA. Buddy’s three standalone examples live inexamples/BOSCAMEFPGAand start atkernel.frontend.mlir. See Triton Contract handoff.BOSCAME reading map:
Contributions
We welcome contributions to our open-source project!
Before contributing, please read the Contributor Guide and Code Style.
To maintain code quality, this project provides pre-commit checks:
How to Cite
If you find our project and research useful or refer to it in your own work, please cite the survey paper in which the Buddy Compiler design was first proposed:
For direct access to the paper, please visit Compiler Technologies in Deep Learning Co-Design: A Survey.