In languages that donβt support fixed-size floating point scalars, the data type for floating point values
defaults to float32. Use a tensor constructor to explicitly specify the data type.
Support for half-precision floating point scalars float16 is planned for the future depending on language support.
Muna supports floating point vectors (i.e. one-dimensional floating point tensors):
Copy
import type { Tensor } from "muna"const prediction = await muna.predictions.create({ tag: "@fxn/identity", inputs: { vector: new Float32Array([ 1.2, 2.2, 3.2, 4.5 ]) }});const vector = prediction.results[0] as Tensor;
Although Muna supports input vectors, predictors will always output either scalars or Tensor instancesβnever plain vectors.
Muna supports floating point tensors:
Copy
import type { Tensor } from "muna"const prediction = await muna.predictions.create({ tag: "@fxn/identity", inputs: { matrix: { data: new Float64Array([ 1.2, 2.2, 3.2, 4.5 ]), shape: [2, 2] } satisfies Tensor }});const matrix = prediction.results[0] as Tensor;
Integer Values
Muna supports several signed and unsigned integer scalars:
Input dictionary values must be JSON-serializable.
Image Values
Muna supports images, represented as raw pixel buffers with 8 bytes per pixel and interleaved by channel.
Muna supports three pixel buffer formats:
Pixel format
Channels
Description
A8
1
Single channel luminance or alpha image.
RGB888
3
Color image without alpha channel.
RGBA8888
4
Color image with alpha channel.
Some client SDKs provide Image utility types for working with images:
Copy
import type { Image } from "muna"const prediction = await muna.predictions.create({ tag: "@vision-co/remove-background", inputs: { image: { data: new Uint8ClampedArray(1280 * 720 * 3), width: 1280, height: 720, channels: 3 } satisfies Image }});const image = prediction.results[0] as Image;
Binary Values
Muna supports binary blobs:
Copy
const prediction = await muna.predictions.create({ tag: "@vision-co/decode-jpeg", inputs: { buffer: new ArrayBuffer(1024) }});const buffer = prediction.results[0] as ArrayBuffer;
Because Munaβs security model prohibits file system access, binary input values
are always fully read into memory before being passed to the predictor.To make predictions on large files, consider mapping the file into memory
using mmap or your environmentβs equivalent.
Streaming in Muna is designed to fully separate how a prediction function
is implemented from how the function might be consumed. Consider these two predictors:
Copy
def predict() -> str: return "hello from Muna"
Here are the reuslts of creating vs. streaming each function at runtime:
Creating Predictions with eager.py
In this case, the single prediction is returned:
Copy
// Create a prediction with the eager predictorconst prediction = await muna.predictions.create({ tag: "@muna/eager", inputs: { }});// Display the resultsconsole.log(prediction.results[0]);// Outputs:// "hello from Muna"
Creating Predictions with generator.py
In this case, the Muna client will consume all partial predictions yielded
by the predictor then return the very last one:
Copy
// Create a prediction with the streaming predictorconst prediction = await muna.predictions.create({ tag: "@muna/generator", inputs: { }});// Display the resultsconsole.log(prediction.results[0]);// Outputs:// "hello from Muna"
Streaming Predictions with eager.py
In this case, the Muna client will return a prediction stream with the single prediction returned by the predictor:
Copy
// Create a prediction stream with the eager predictorconst stream = await muna.predictions.stream({ tag: "@muna/eager", inputs: { }});// Display the resultsfor await (const prediction of stream) console.log(prediction.results[0]);// Outputs:// "hello from Muna"
Streaming Predictions with generator.py
In this case, the Muna client will provide a prediction stream containing all
partial predictions yielded by the predictor:
Copy
// Create a prediction stream with the generator predictorconst stream = await muna.predictions.stream({ tag: "@muna/generator", inputs: { }});// Display the resultsfor await (const prediction of stream) console.log(prediction.results[0]);// Outputs:// "hello"// "hello from"// "hello from Muna"
You can choose how to consume a prediction function depending on what works best for your user experience.
You donβt have to care about the underlying function!