> ## Documentation Index
> Fetch the complete documentation index at: https://docs.muna.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Compiling Models

> Compile your models before you deploy them.

Muna compiles stateless Python functions into self-contained executable binaries.

> [!TIP]
>
> Your Python code is lowered directly to native code, and does not rely on
> the Python runtime (or any other managed runtime).

## Why Compile?

Deployment is not the first step in shipping a model--compilation is. Compiled models are smaller,
faster, and can yield up to **45x reductions in cold-start times**:

![Cumulative time to first token](https://mintcdn.com/natml/DosmBe7QcFA8KLH1/images/cttft.png?fit=max\&auto=format\&n=DosmBe7QcFA8KLH1\&q=85\&s=2b548042fc1f92e7b77783f4c9d47ce7)

Cumulative time to first token, compiled vs. uncompiled.

This matters most in serverless and autoscaling deployments, where every scale-up event pays the
cold-start tax. Faster cold starts mean fewer warm replicas--and a smaller GPU bill.

A compiled model is also a portable artifact: the exact same binary can serve requests on
[our hosted endpoint](https://docs.muna.ai/inference/quickstart.md), on [your own GPUs](https://docs.muna.ai/cli/deploy.md), or on
[end-user devices](https://docs.muna.ai/sdk/install.md)--with [hardware-optimized performance](https://docs.muna.ai/compile/how-it-works.md)
on each.

## Defining a Function

Write your function, add a docstring, then wrap it with our `@compile` decorator:

```py greeting.py icon="python" theme={null}
from muna import compile

@compile()
def greeting(name: str) -> str:
    """
    Say a friendly greeting.
    """
    return f"Hey there {name}! We're glad you're using Muna and we hope you like it."
```

> [!NOTE]
>
> The docstring is used as a description, is required, and must be 100 characters or less.

> [!NOTE]
>
> The function **must** specify parameter and return type annotations. [Learn more](https://docs.muna.ai/compile/requirements).

## Compiling the Function

Use the Muna CLI to compile the function. First, make sure you are logged into the Muna CLI:

```bash icon="terminal" theme={null}
# Login to the CLI
$ muna auth login <access key>
```

Then run the following command:

```bash icon="terminal" theme={null}
# Compile the function
$ muna compile --overwrite greeting.py
```

Muna will upload your code, perform code generation on your function and its dependencies,
then compile for our supported platforms:

![](https://www.muna.ai/compile.gif)

Compiling a function with the Muna CLI. This is realtime--not sped up.

## Using the Function

Depending on the complexity of your function, it can take anywhere from a few seconds to a
few minutes for the function to be compiled for all platforms. Once the function is compiled, you can
run it everywhere:

```ts JavaScript icon="js" theme={null}
import { Muna } from "muna"

// 💥 Create your Muna client
const muna = new Muna({ accessKey: "..." });

// 🔥 Run inference
const prediction = await muna.predictions.create({
    tag: "@your-username/greeting",
    inputs: { name: "Lina" }
});

// 🚀 Print the result
console.log(prediction.results[0]);
```

```py Python icon="python" theme={null}
from muna import Muna

# 💥 Create your Muna client
muna = Muna(access_key="...")

# 🔥 Run inference
prediction = muna.predictions.create(
    tag="@your-username/greeting",
    inputs={ "name": "Lina" }
)

# 🚀 Use the results
print(prediction.results[0])
```

```swift iOS icon="swift" theme={null}
import Muna

// 💥 Create a Muna client
let muna = Muna(accessKey: "...")

// 🔥 Run inference
let prediction = try await muna.predictions.create(
    tag: "@your-username/greeting",
    inputs: ["name": "Lina"]
)

// 🚀 Use the results
print(prediction.results![0])
```

```kt Android icon="android" theme={null}
import ai.muna.muna.Muna

// 💥 Create a Muna client
val muna = Muna("...")

// 🔥 Run inference
val prediction = muna.predictions.create(
    "@your-username/greeting",
    mapOf("name" to "Lina")
)

// 🚀 Use the results
println(prediction.results!![0])
```

```csharp Unity icon="unity" theme={null}
using Muna;

// 💥 Create your Muna client
var muna = new Muna(accessKey: "...");

// 🔥 Run inference
var prediction = await muna.Predictions.Create(
    tag: "@your-username/greeting",
    inputs: new() { ["name"] = "Lina" }
);

// 🚀 Use the results
Debug.Log(prediction.results[0]);
```

```bash CLI icon="terminal" theme={null}
# 🔥 Run inference
$ muna predict @your-username/greeting --name Lina
```

> [!NOTE]
>
> You can check the compilation status of the function at [muna.ai/predictors](https://muna.ai/predictors).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.