Expand description
Safe wrappers around core ggml graph computation APIs.
This module provides the building blocks for creating and executing tensor computation graphs using ggml backends. It’s used for operations like LoRA merging, importance matrix computation, and control vector generation.
§Example
ⓘ
use llama_cpp_4::ggml::*;
// Create a backend and context
let backend = GgmlBackend::cpu()?;
let mut ctx = GgmlContext::new(1024 * 1024, true)?;
// Create tensors
let a = ctx.new_tensor_2d(GgmlType::F32, 4, 4);
let b = ctx.new_tensor_2d(GgmlType::F32, 4, 4);
// Build computation graph
let sum = ctx.add(&a, &b);
let mut graph = ctx.new_graph();
graph.build_forward(&sum);
// Allocate and compute
let mut alloc = GgmlAllocr::new(&backend);
alloc.alloc_graph(&mut graph);
// ... set tensor data ...
backend.graph_compute(&mut graph);
// ... get results ...Structs§
- Ggml
Allocr - A safe wrapper around
ggml_gallocr. - Ggml
Backend - A safe wrapper around
ggml_backend. - Ggml
Context - A safe wrapper around
ggml_context. - Ggml
Graph - A wrapper around
ggml_cgraph. - Ggml
Tensor - A wrapper around a
ggml_tensorpointer.
Functions§
- buffer_
free ⚠ - Free a backend buffer.
- graph_
overhead - Get the overhead in bytes for a computation graph.
- is_
quantized - Check if a type is quantized.
- tensor_
get ⚠ - Get tensor data into a byte slice.
- tensor_
overhead - Get the overhead in bytes for tensor metadata.
- tensor_
set ⚠ - Set tensor data from a byte slice.
- type_
name - Get the name of a ggml type.
Type Aliases§
- ggml_
type - Re-export the raw ggml types for advanced usage.