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 Values
Floating Point Values
Floating-point input and return values should be annotated with the For control over the binary width of the number, use the
float
built-in type.Unlike Python which defaults to 64-bit floats, Muna will always lower a Python
float
to 32 bits.numpy.float[16,32,64]
types:Integer Values
Integer Values
Integer input and return values should be annotated with the For control over the binary width of the integer, use the
int
built-in type.Unlike Python which supports arbitrary-precision integers, Muna will always lower a Python
int
to 32 bits.numpy.int[8,16,32,64]
types:Boolean Values
Boolean Values
Boolean input and return values must be annotated with the
bool
built-in type.Tensor Values
Tensor Values
Tensor input and return values must be annotated with the NumPy Below are the supported element types:
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).Numpy data type | Muna data type |
---|---|
np.float16 | float16 |
np.float32 | float32 |
np.float64 | float64 |
np.int8 | int8 |
np.int16 | int16 |
np.int32 | int32 |
np.int64 | int64 |
np.uint8 | uint8 |
np.uint16 | uint16 |
np.uint32 | uint32 |
np.uint64 | uint64 |
bool | bool |
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 Values
String Values
String input and return values must be annotated with the
str
built-in type.List Values
List Values
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 Values
Dictionary Values
Dictionary input and return values can be annotated in one of two ways:
- Using a Pydantic
BaseModel
subclass. - 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 Values
Image Values
Image input and return values must be annotated with the Pillow
PIL.Image.Image
type.Binary Values
Binary Values
Binary input and return values can be annotated in one of three ways:
- Using the
bytes
built-in type. - Using the
bytearray
built-in type. - Using the
io.BytesIO
type.
Using Parameter Annotations
Muna supports attaching additional annotations to the function’s parameter and return types:- 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 very strongly recommend using parameter annotations on your compiled functions.
Generic Annotation
Generic Annotation
Use the Below is the full
Parameter.Generic
annotation to provide information about a general input or output type:predictor.py
Parameter.Generic
annotation definition:Numeric Annotation
Numeric Annotation
Use the Below is the full
Parameter.Numeric
annotation to provide information about a numeric input or output type:predictor.py
Parameter.Numeric
annotation definition:Audio Annotation
Audio Annotation
Use the Below is the full
Parameter.Audio
annotation to provide information about an audio input or output type:predictor.py
Parameter.Audio
annotation definition:Embedding Annotation
Embedding Annotation
Use the Below is the full
Parameter.Embedding
annotation to provide information about a vector embedding input or output type:predictor.py
The
Parameter.Embedding
annotation allows the compiled predictor to be used by the
OpenAI embedding interface.Parameter.Embedding
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:Functions
Functions
Statement | Status | Notes |
---|---|---|
Recursive functions | 🔨 | Recursive functions must have a return type annotation. |
Lambda expressions | 🚧 | Lambda expressions can be invoked, but cannot be used as objects. |
Literals
Literals
Collection | Status | Notes |
---|---|---|
List literals | 🚧 | List must contain primitive members (e.g. int , str ). |
Dictionary literals | 🚧 | Dictionary must contain primitive members (e.g. int , str ). |
Set literals | 🚧 | Set must contain primitive members (e.g. int , str ). |
Tuple literals | 🚧 | Tuple must contain primitive members (e.g. int , str ). |
Classes
Classes
Tracing through classes is not yet supported.
Exceptions
Exceptions
Statement | Status | Notes |
---|---|---|
raise statements | 🔨 | |
try..except statement | 🔨 |
Over time the list of unsupported language features will shrink and eventually, will be empty.
Library Coverage
We are adding support for popular libraries, across tensor frameworks, scientific computing, and more:Supported Libraries
Supported Libraries
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.