Skip to main content

clika_runtime.io

Model files and media in and out.

Checkpoints load as a dict of tensors (:func:load_safetensors, :func:load_torch_checkpoint, :func:load_gguf) or open as a :class:TensorsContainer whose entries read from disk on first use (:func:open_safetensors, :func:open_torch_checkpoint, :func:open_gguf, or :meth:TensorsContainer.open by file suffix). :func:peek_gguf reads a GGUF file's header alone (its metadata and tensor table, from as little as the file's first bytes). A safetensors file's own order and its metadata read back through :func:load_safetensors_entries (a :class:SafetensorsEntries: the (name, tensor) pairs in header order and the metadata as string pairs), and :func:save_safetensors writes its entries in the given order with optional metadata. ONNX models open as an editable :class:OnnxModel and compile into a :class:ModelGraph, which runs once finalized; a :class:CompileOptions pins the input shapes and names the device the weights live on::

options = crt.io.CompileOptions(specs={"X": [8, 131]})
graph = crt.io.OnnxModel.open("model.onnx").compile(options)

:mod:clika_runtime.onnx is the one-call loader over them. The audio pair decodes and writes waveforms; the npy pair moves one tensor.

Video: :func:peek_video reads a clip's header (a :class:VideoInfo), :func:load_video decodes a whole clip into a :class:VideoData (every frame as one [T, H, W, 3] uint8 tensor with its indices and timestamps, a :class:FrameBatch, beside the stream's info), and :class:VideoReader decodes on demand, per index, per timestamp or in batches, for a clip too long to hold at once. :class:VideoWriter encodes [H, W, 3] uint8 frames into a file, with an :class:AudioTrack when the clip carries sound; it is a context manager, so the file is finalized when the with block ends. :func:video_capability reports whether this host has a video backend. A source is a path or the encoded bytes. Images: :func:peek_image reads a header (an :class:ImageInfo), :func:load_image decodes to a [H, W, C] uint8 tensor, :func:encode_image writes PNG bytes and :func:save_image the format a path's suffix asks for::

with crt.io.VideoWriter.open("clip.mp4", fps=24, width=64, height=48) as writer:
for frame in frames:
writer.write_frame(frame)
reader = crt.io.VideoReader.open("clip.mp4")
batch = reader.sample_uniform(8)
NameKind
AudioTrackclass
BenchOptionsclass
BenchReportclass
CompileOptionsclass
ContainerEntryclass
DefaultsOptionsclass
DimDomainclass
FeedFillclass
FrameBatchclass
ImageInfoclass
InputShapeclass
KVCacheLayerInfoclass
ModelGraphclass
OnnxModelclass
OnnxNodeInfoclass
OptimizeReportclass
SafetensorsEntriesclass
ShapeDomainclass
TensorsContainerclass
TransformReportclass
VideoDataclass
VideoInfoclass
VideoReaderclass
VideoWriterclass
functionsmodule functions