Runtime, FFI, Hub, and I/O¶
Reference for jacobi::runtime, jacobi::ffi, jacobi::hub, jacobi::io, and jacobi::error.
Runtime and Devices (jacobi::runtime)¶
| API | Signature / Variants | Description |
|---|---|---|
Backend |
Auto, Cpu, Cuda, Metal, Tpu, Rocm, OneApi, PluginPath(PathBuf) |
Target PJRT accelerator selection |
use_backend / backend_name |
use_backend(Backend) -> Result<Engine>, backend_name() -> Result<String>, installed_accelerator() -> Option<String> |
Switch or query the active default backend |
EngineConfig |
EngineConfig::default().backend(...).cache_dir(...).max_cached_executables(256).max_disk_cache_bytes(512 * 1024 * 1024).auto_download(bool) |
Configure cache limits, offline mode, and plugin paths |
Engine / set_engine |
Engine::with_config(cfg) -> Result<Engine>, set_engine(engine), default_engine() -> Result<Engine> |
Explicit engine lifecycle and binding |
| Device & memory stats | devices() -> Result<Vec<DeviceInfo>>, num_devices() -> Result<usize>, memory_stats() -> Result<MemoryStats>, memory_stats_on(idx), all_memory_stats() |
Query DeviceInfo (id, process_index, kind, debug_string) and PJRT_Device_MemoryStats |
| Multi-node distributed | init_distributed(coordinator_addr, num_processes, process_id) -> Result<()>, num_global_devices(), num_processes(), process_index() |
Initialize multi-process PJRT distributed runtime |
| Debugging | set_debug_nans(bool), debug_nans_enabled(), with_debug_nans(bool, f), debug_print(label, &t) / t.debug_print(label), with_debug_print_capture(f) |
Runtime NaN/Inf trapping and compiled-safe tensor logging |
Host Tensors and Data Loading (jacobi::runtime)¶
HostTensor(data: HostData,shape: Vec<usize>,dtype: Dtype) ownedSend + Synchost tensor supportingF32,F64,BF16(from_bf16,as_bf16),F16(from_f16,as_f16),I8/16/32/64,U8/32, andBoolwith zero-copy upload to device (Tensor::from_host/from_host_on) andruntime::{f32_to_bf16, bf16_to_f32}helpers.Datasettrait (fn len(&self) -> usize,fn get(&self, index: usize) -> Self::Item).DataLoader::new(Arc::new(dataset), batch_size, collate).shuffle(true).drop_last(false).num_workers(4).shard(rank, world_size).start_batch(0).prefetch(2).seed(42)with.num_batches(),.iter_epoch(epoch),.iter_epoch_from(epoch, start_batch), and.iter(). Automatically runs acrossPrefetcher::parallelwhennum_workers > 1with zero epoch-wide batch index allocation.Prefetcher::new(iter, depth)single-thread bounded background prefetch iterator for overlapping host preprocessing withJitFn::call_async.Prefetcher::parallel(start_step, end_step, num_workers, depth, make_batch)multi-worker pool prefetching indexed steps in parallel while yielding items in strictstart_step..end_steporder.Prefetcher::staged(stages, begin, end, num_workers, depth)multi-stage stateful worker prefetcher usingStageFactory<T>andStageStream<T>for curriculum schedules with strict step ordering and clean early-drop shutdown.Prefetcher::pooled(buffers, fill)+.recycle(buf)double/ring-buffered host prefetcher that fills caller-provided buffers in place on a background thread with zero steady-state allocations or page faults.
XLA FFI and Custom Calls (jacobi::ffi)¶
| API | Description |
|---|---|
register_ffi_handler(name, handler: XlaFfiHandler) -> Result<()> |
Register a Rust, C++, CUDA, or PTX handler with PJRT_FFI_Extension |
ffi_call(target, inputs, outputs, backend_config) / ffi_call_one(...) |
Emit a typed XLA FFI custom call inside jit |
ffi_call_with_vjp(input, fwd, bwd) |
Wrap an FFI call with a custom backward pass |
custom_call(target, inputs, outputs, backend_config, api_version, has_side_effect) |
Emit a general stablehlo.custom_call |
custom_call_with_layouts(..., operand_layouts, result_layouts) |
Emit a stablehlo.custom_call with explicit XLA minor-to-major operand/result layouts |
XlaFfiCallFrame / XlaFfiBuffer |
Low-level FFI buffer descriptor (.numel(), .handle_metadata(traits)) |
Hugging Face Integration (jacobi::hub, hf Feature)¶
| API | Description |
|---|---|
hub::weights(repo) / hub::weights_revision(repo, rev) |
Open a lazy memory-mapped WeightLoader for single or sharded Hugging Face .safetensors checkpoints |
WeightLoader |
Scoped loader with .pp(segment), .dtype(Dtype), .device(device_idx), .tensor(name), .linear(in_f, out_f), .rms_norm(dim), .layer_norm(dim), .embedding(v, d), .contains(key), .keys() |
HfExporter |
Export weights or merged LoRA checkpoints to .safetensors and Hugging Face/Candle/vLLM directories (.dtype, .add_tensor, .add_linear, .add_lora_merged, .add_rms_norm, .add_layer_norm, .add_embedding, .save_safetensors, .save_dir(dir, base_repo)) |
Tokenizer |
Tokenizer::from_pretrained(repo), from_file(path), from_bytes(bytes), .encode(text), .encode_tensor(text), .decode(&ids), .decode_tensor(&t) |
| Hub & Datasets | hub::download(repo, file), hub::dataset_file(repo, file), hub::load_config(repo), hub::load_safetensors(repo), hub::load_into(&model, repo), hub::load_dataset(repo, config, split) |
I/O, Interop, Export, and Serving (jacobi::io)¶
| Submodule | Key Functions & Types | Description |
|---|---|---|
io::dlpack |
to_dlpack(&t), from_dlpack(cap), from_dlpack_ptr(ptr), DlPackCapsule, DLManagedTensor, DLTensor, DLDevice, DLDataType |
Zero-copy DLPack exchange with PyTorch, JAX, NumPy, and CuPy (Tensor::to_dlpack, Tensor::from_dlpack) |
io::safetensors |
save, save_with_metadata, read_metadata, read_metadata_bytes, load_map, load_bytes, load_sharded, load_into, load_from_map, WeightLoader, HfExporter |
Memory-mapped .safetensors preserving native BF16, F16, FP8, I16, I8 |
io::onnx |
export_onnx, trace_export_onnx |
Standalone ONNX export (IR v9, Opset 18) |
io::export |
export_mlir, trace_export_mlir, export_mlir_with_weights, trace_export_mlir_external |
Standalone StableHLO .mlir export |
io::serve |
serve_mlir(path, port), serve_mlir_on(path, host, port), serve_mlir_with_weights, serve_mlir_with_weights_on, MlirRunner |
Lightweight HTTP inference server (defaults to 127.0.0.1) |
io::text |
SentencePiece::from_file/from_bytes (.encode_with_offsets, .decode), Tokenizer, load_bytes, decode_bytes |
Native SentencePiece (no C++ dependency) and Hugging Face tokenizers |
io::npy |
load_npy, save_npy, load_npy_host, save_npy_host, load_idx_gz |
NumPy .npy and MNIST IDX binary I/O |
io::image |
load_png, save_png |
PNG image decoding and encoding |
io::audio |
load_wav, load_wav_i16, save_wav |
WAV PCM audio I/O |
io::table |
load_csv, save_csv |
Numeric CSV table I/O |
io::plot |
Figure::new() (.title, .xlabel, .ylabel, .plot, .scatter, .bar, .imshow, .render_svg, .save_svg, .evcxr_display) |
Pure-Rust SVG charts with inline notebook rendering |
Errors (jacobi::error)¶
Errorwraps PJRT, XLA compilation, shape/dtype, I/O, and distributed errors with caller locations.Result<T>isstd::result::Result<T, Error>.