Skip to main content
Muna supports compiling a tiny-but-growing subset of Python language constructs. Below are requirements and guidelines for compiling a Python function with Muna:

Specifying the Function Signature

The prediction function must be a module-level function, and must have parameter and return type annotations:
The prediction function must not have any variable-length positional or keyword arguments.

Supported Parameter Types

Muna supports a fixed set of predictor input and output value types. Below are supported type annotations:
Floating-point input and return values should be annotated with the float built-in type.
Unlike Python which defaults to 64-bit floats, Muna will always lower a Python float to 32 bits.
For control over the binary width of the number, use the numpy.float[16,32,64] types:
Integer input and return values should be annotated with the int built-in type.
Unlike Python which supports arbitrary-precision integers, Muna will always lower a Python int to 32 bits.
For control over the binary width of the integer, use the numpy.int[8,16,32,64] types:
Boolean input and return values must be annotated with the bool built-in type.
Tensor input and return values must be annotated with the NumPy numpy.typing.NDArray[T] type, where T is the tensor element type.
You can also annotate with the np.ndarray type, but doing so will always assume a float32 element type (following PyTorch semantics).
Below are the supported element types:
Muna does not yet support complex numbers or tensors.
Muna only supports, and will always assume, little-endian ordering for multi-byte element types.
String input and return values must be annotated with the str built-in type.
List input and return values must be annotated with the list[T] built-in type, where T is the element type.
When the list element type T is a Pydantic BaseModel, a full JSON schema will be generated.
Providing an element type T is optional but strongly recommended because it is used to generate a schema for the parameter or return value.
Dictionary input and return values can be annotated in one of two ways:
  1. Using a Pydantic BaseModel subclass.
  2. Using the dict[str, T] built-in type.
We strongly recommend the Pydantic BaseModel annotation, as it allows us to generate a full JSON schema.
When using the dict annotation, they key type must be str. The value type T can be any arbitrary type.
Image input and return values must be annotated with the Pillow PIL.Image.Image type.
Binary input and return values can be annotated in one of three ways:
  1. Using the bytes built-in type.
  2. Using the bytearray built-in type.
  3. Using the io.BytesIO type.

Using Parameter Annotations

Muna supports attaching additional annotations to the function’s parameter and return types:
These annotations serve multiple important purposes:
  • They help users know what input data to provide to the predictor and how to use output data from the predictor, via the parameter description.
  • They help users search for predictors using highly detailed queries (e.g. MCP clients).
  • They help the Muna client automatically provide familiar interfaces around your prediction function, e.g. with the OpenAI interface.
  • They help the Muna website automatically create interactive visualizers for your prediction function.
While not required, we highly recommend using parameter annotations on your compiled functions.
Below are currently supported annotations:
Use the Parameter.Generic annotation to provide information about a general input or output parameters:
predictor.py
Below is the full Parameter.Generic annotation definition:
Use the Parameter.Numeric annotation to specify numeric input or output parameters:
calculate_area.py
Below is the full Parameter.Numeric annotation definition:
Use the Parameter.Audio annotation to specify audio parameters:
transcribe_audio.py
The Parameter.Audio annotation allows the compiled predictor to be used by our OpenAI speech client.
Below is the full Parameter.Audio annotation definition:
Use the Parameter.AudioSpeed annotation to specify audio speed parameters in audio generation predictors:
generate_speech.py
Below is the full Parameter.AudioSpeed annotation definition:
Use the Parameter.AudioVoice annotation to specify audio voice parameters in audio generation predictors:
generate_speech.py
Below is the full Parameter.AudioVoice annotation definition:
Use the Parameter.BoundingBox or Parameter.BoundingBoxes annotations to specify bounding box parameters in object detection predictors:
Below is the full Parameter.BoundingBox annotation definition:
Use the Parameter.DepthMap annotation to specify depth map parameters in depth estimation predictors:
estimate_depth.py
Below is the full Parameter.DepthMap annotation definition:
Use the Parameter.Embedding annotation to specify vector embedding parameters in embedding predictors:
embed_text.py
The Parameter.Embedding annotation allows the compiled predictor to be used by our
OpenAI embedding client.
Below is the full Parameter.Embedding annotation definition:
Use the Parameter.EmbeddingDims annotation to specify an embedding Matryoshka dimension parameter in embedding predictors:
embed_text.py
Below is the full Parameter.EmbeddingDims annotation definition:

Writing the Function Body

The function body can contain arbitrary Python code. Given that the Muna compiler is currently a proof of concept, it has limited coverage for Python language features. Below is a list of Python language features that we either partially support, or do not support at all:
Tracing through classes is not yet supported.
Over time the list of unsupported language features will shrink and eventually, will be empty.

Using Compiler Sandboxes

Muna supports defining custom sandboxes that can be used to reconstruct your Python environment before compiling your function.
Sandboxes are very much experimental, and will likely see major changes, additions, and revisions in the near future.
Use the Sandbox.pip_install method to install Python packages from the PyPi registry:
predictor.py
We highly recommend pinning the specific versions of Python packages in use, so as to prevent incompatibilities when creating the sandbox.
Use the Sandbox.apt_install method to install Debian system packages:
predictor.py
Use the Sandbox.env method to define plaintext environment variables:
predictor.py
Muna does not yet support defining secrets. Do not provide secrets using sandbox environment variables as they are not designed for storing secrets.
Use the Sandbox.upload_file method to upload a file to a path in the sandbox:
predictor.py
Use the Sandbox.upload_directory method to upload a directory and all its contents to a path in the sandbox:
predictor.py

Using Compiler Metadata

Muna’s compiler supports specifying metadata, allowing you to configure the compiler or provide additional information.
Use the TensorRTInferenceMetadata metadata type to compile a PyTorch nn.Module to TensorRT:
ai.py
The TensorRT inference backend is only available on Linux and Windows devices with compatible Nvidia GPUs.
We are working on adding support for consumer RTX GPUs with TensorRT for RTX.

Target CUDA Architectures

TensorRT engines must be compiled for specific target CUDA architectures. Below are CUDA architectures that our compiler supports:

TensorRT Inference Precision

TensorRT allows for specifying the inference engine’s precision. Below are supported precision modes:
Use the OnnxRuntimeInferenceMetadata metadata type to compile a PyTorch nn.Module for inference with ONNXRuntime:
ai.py
Use the OnnxRuntimeInferenceSessionMetadata metadata type to compile an OnnxRuntime InferenceSession:
ai.py
The ONNX model file must exist at the provided model_path within the compiler sandbox.
Use the CoreMLInferenceMetadata metadata type to compile a PyTorch nn.Module to CoreML:
ai.py
The CoreML inference backend is only available on iOS, macOS, and visionOS devices.
Use the LlamaCppInferenceMetadata metadata type to compile a Llama instance:
llm.py

Llama.cpp Hardware Backends

Llama.cpp supports several hardware backends to accelerate model inference. Below are targets that are currently supported by Muna:
Use the ExecuTorchInferenceMetadata metadata type to compile a PyTorch nn.Module for inference with ExecuTorch:
ai.py
The ExecuTorch inference backend is only available on Android.

ExecuTorch Hardware Backends

ExecuTorch supports several hardware backends to accelerate model inference. Below are targets that are currently supported by Muna:
Use the LiteRTInferenceMetadata metadata type to compile a PyTorch nn.Module for inference with LiteRT:
ai.py
Use the TFLiteInterpreterMetadata metadata type to compile a TensorFlow Lite Interpreter:
ai.py
The TensorFlow Lite model file must exist at the provided model_path within the compiler sandbox.
Use the QnnInferenceMetadata metadata type to compile a PyTorch nn.Module to a Qualcomm QNN context binary:
ai.py
The QNN inference backend is only available on Android and Windows devices with Qualcomm processors.

QNN Hardware Backends

QNN requires that a hardware device backend is specified ahead of time. Below are supported backends:
Learn more about QNN hardware backends.

QNN Model Quantization

When using the htp backend, you must specify a model quantization mode as the Hexagon NPU only supports running integer-quantized models. Below are supported quantization modes:
Use the OpenVINOInferenceMetadata metadata type to compile a PyTorch nn.Module to OpenVINO IR:
ai.py
At runtime, the OpenVINO IR will be used for inference with the OpenVINO toolkit.
The OpenVINO inference backend is only available on Linux and Windows x86_64 devices with Intel processors.
Use the muna.beta.IREEInferenceMetadata metadata type to compile a PyTorch nn.Module for inference with IREE:
ai.py
The IREE inference backend is only available on Android devices.

IREE HAL Target Backends

IREE supports several HAL target backends that the model can be compiled against. Below are targets that are currently supported by Muna:
Coming soon 🤫.

Library Coverage

We are adding support for popular libraries, across tensor frameworks, scientific computing, and more:
Below are libraries currently supported by our compiler:
If you need a specific library to be supported by the Muna compiler, reach out to us.