Skip to content

Python API reference

pip install munet-nn, then import munet as mu (import munet_nn also works). Each section links to the guide that explains it.

Top level: munet

Name What it does
compile(fn=None, *, device="vulkan", precision="mixed", fuse=True, profile=False, autotune=None, recover=None, activations="fp32") trace fn (a function or a module) into a GPU program; usable as @mu.compile or @mu.compile(device=...) (Training). recover="rebuild" recompiles and retries once after a GPU reset (Troubleshooting). activations="fp16" stores forward activations as half floats (Training)
devices() names of the Vulkan GPUs; "vulkan:N" is the N-th (GPU vendors)
device_info(index=None) memory, vendor, matrix-core support of a GPU; default index MUNET_VULKAN_DEVICE or 0 (GPU vendors)
probe_device(index=None) / device_profile(index=None) verify and time the per-GPU kernel choices and store a device profile / read it (Inference and performance)
save(program, path) / load(path, *, device="vulkan", precision="mixed", fuse=True, activations="fp32") .mnet files for Python, C, C++, Rust (ONNX)
DataParallel(loss_fn, parameters, optimizer, devices, *, precision="fp32", fuse=True, split="even", max_rows=None) multi-GPU training: .step(*batch), .counts, .stats(). Note the "fp32" default (Multiple GPUs)
quantize(model, calib_data=None, *, scheme="w8a8_dynamic", observer="minmax", group_size=128, device="cpu") quantize Linear layers in place (Quantization)
Tensor, Parameter, Buffer traced values, trainable weights, non-trained state
Result output of a compiled program (see below)
cat, stack, where, as_tensor, grad tensor functions
license() license status dict: status ("licensed", "evaluation", "invalid", "expired"), customer, expires, error, ... (Install)
VulkanError, DeviceLostError GPU errors (DeviceLostError after a GPU reset)
metrics counters / histograms; metrics.prometheus() for scraping

Compiled programs

Returned by mu.compile, from_onnx, from_torch and mu.load.

Member
program(*arrays) run; returns a Result or a tuple of them (integer outputs of ONNX models: NumPy arrays)
Result.numpy(), .item(), .shape read back; valid until the next call
stats() gpu_ms (last call), kernels, arena_bytes, upload/download bytes, compile times, int8 kernel counts, device
describe() per kernel: path, fused ops, ONNX node names, gpu_ms with profile=True
optimizations (ONNX imports) layer merges applied

Data: munet.data (Data loading)

Name
DataLoader(dataset, batch_size=1, *, shuffle=False, drop_last=True, seed=0, workers=0, prefetch=2, collate=None, shard=None) batches of NumPy arrays; set_epoch(n), len()
ArrayDataset(*arrays, transform=None) samples are rows of arrays
Dataset optional base class (__len__, __getitem__)
default_collate(samples) stacks samples field by field; the default collate

Layers and functions: munet.nn (Training)

  • Modules: Module (parameters(), named_parameters(), state_dict(), load_state_dict(), train(), eval(), requires_grad_()), plus layers in the PyTorch style: Linear, Conv1d/2d, ConvTranspose1d/2d, BatchNorm1d/2d, LayerNorm, GroupNorm, RMSNorm, MultiheadAttention, Transformer*, LSTM, GRU, Embedding, pooling, activations, and the *Loss classes.
  • Functional: munet.nn.functional holds activations, losses, scaled_dot_product_attention, interpolate, grid_sample, pad, conv*, normalization, roi_align, nms, batched_nms, einsum, and more.

Optimizers: munet.optim (Training)

Name
SGD(params, lr=0.01, momentum=0, weight_decay=0, nesterov=False, dampening=0) parameter groups; live param_groups[i]["lr"]
AdamW(params, lr=1e-3, betas=(0.9, 0.999), eps=1e-8, weight_decay=0.01) parameter groups; live settings
MultiStepLR(optimizer, milestones, gamma=0.1) step per epoch
ModelEMA(model, decay=0.9999, warmups=2000) update() inside the step, copy_to(model)
clip_grad_norm_(params, max_norm, norm_type=2.0) between backward() and step()

All have state_dict() / load_state_dict().

Checkpoints: munet.checkpoint

save_state(tree, path) / load_state(path): atomic, data-only archives of nested dicts / lists of float32 arrays and plain values (Training).

ONNX and PyTorch: munet.interop (ONNX)

Name
from_onnx(path, *, device="vulkan", precision="mixed", input_shapes=None, int8=None, autotune=None, optimize=True, profile=False, native=False, max_specializations=8, fuse=True) import
from_torch(model, example_inputs, *, device="vulkan", fuse=True, **from_onnx_options) import a PyTorch module through ONNX (inference only)
to_onnx(program, path) export
SUPPORTED_ONNX supported operator names

Quantization: munet.quantization (Quantization)

Name
calibrate_onnx(path, batches, *, observer="minmax", min_snr_db=20, device="vulkan", bins=2048, native=False) int8 activation scales for from_onnx(int8=...)
autoquantize(model, calibration, validation=None, *, metric=None, tolerance=0.01, device="vulkan", autotune=True, observer="minmax", ...) choose int8 layers of an ONNX model by measured speed and accuracy
quantize(model, calib_data=None, *, scheme="w8a8_dynamic", ...) w8a8_dynamic, w8a8, w8, w4 for Linear layers
compare(reference, candidate, inputs) cosine / max / relative error

Training across machines: munet.pool

Pool, Node, Nodes and tls_context: see Training pool.