Skip to main content

Petit

Petit provides optimized AMD GPU kernels for dense matrix multiplication, Mixture-of-Experts (MoE), and experimental single-node MegaMoE workloads. Its FP16/BF16 × FP4 kernels support NVFP4- and MXFP4-quantized models on GPUs with or without native FP4 arithmetic.

Features

  • Dense matrix multiplication with NVFP4 and MXFP4 weights
  • Fused MoE kernels for BF16 and MXFP4 workloads
  • Experimental single-node MegaMoE kernels with BF16 and MXFP4 activations

Requirements

  • AMD CDNA2, CDNA3, or CDNA4 GPUs (MI200, MI300, or MI350 series)
  • ROCm 6.2 or later
  • PyTorch 2.5 or later

MegaMoE support currently requires CDNA4 (gfx950).

Installation and usage

Install Petit from the repository with pip:

CMAKE_ARGS="-DCMAKE_PREFIX_PATH=/opt/rocm;$(python -c 'import torch; print(torch.utils.cmake_prefix_path)')" \
  pip install .

Set CMAKE_PREFIX_PATH through CMAKE_ARGS so that CMake can locate ROCm and PyTorch.

Petit exposes Python APIs for matrix multiplication and MoE kernels for integration with inference frameworks such as SGLang and vLLM. It also provides C++ bindings for integrations with frameworks such as llama.cpp.

Techniques and performance

Like Marlin, Petit shuffles weights offline to make GPU dequantization more efficient. It also uses ranged buffer loads and vector instructions designed for AMD CDNA architectures. See Optimizing FP4 Mixed-Precision Inference on AMD GPUs for details.

FP4 quantization provides approximately 3.3× memory savings. For example, a server with eight AMD MI300X GPUs running SGLang v0.4.9.post2 can serve both Llama-3.3-70B-Instruct and Llama-3.3-70B-Instruct-FP4, which achieve MMLU scores of 82.15 and 80.79, respectively.

Petit targets small-batch LLM inference. For BF16 matrix multiplication with batch sizes below 16, Petit is 1.2–2.2× faster than hipBLASLt. At larger batch sizes, where performance becomes compute-bound, Petit reaches 70% of the performance of the hand-optimized hipBLASLt library.

Known limitations

  • Petit's offline data transformation assumes that scales are positive and quantized weights contain no negative zeros. This is compatible with output from the TensorRT Model Optimizer.

  • MFMA instructions on AMD MI200-series GPUs flush input and output denormal values to zero, which can affect numerical accuracy. Petit's corrective measures add approximately 10% overhead on these GPUs.

  • AMD CDNA architectures are sensitive to kernel hyperparameters such as shared-memory tile shapes. Run the included benchmarking tools to tune these parameters for optimal performance.

Contact and contributions

We thank AMD and InnoMatrix for generously providing access to the GPUs that made this project possible. Neither organization is involved in the development of Petit.

Petit is a young project, and many optimizations are still in progress. Questions, feedback, and contributions are welcome. Contact haohui@causalflow.ai for more information.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

petit_kernel-0.0.5-cp312-cp312-manylinux_2_34_x86_64.whl (8.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

petit_kernel-0.0.5-cp310-cp310-manylinux_2_34_x86_64.whl (8.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

File details

Details for the file petit_kernel-0.0.5-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for petit_kernel-0.0.5-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 7f5b274e8b8e5d1918606219a369991a5008ddff7bb77134e623222e2bfde79c
MD5 9ecfd1aa4ae3975ebf9a444a3f6719ff
BLAKE2b-256 3197a07c12bcc00f55eda020cbb8b2a2c5e2b3795a80c82c2efbfff21067c9a3

See more details on using hashes here.

File details

Details for the file petit_kernel-0.0.5-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for petit_kernel-0.0.5-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 63e074a34ee37e180a4d697d2f427f14efdb8e7bcde1cc3c4b223773d0ba23ee
MD5 d528ad199ce5441441082d979e3597c4
BLAKE2b-256 f50cfc13d8d6b87beec08625b3e8c1de8b1611b118470ae485d6b6ab88b2d4ad

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page