pub struct Graph {
pub name: String,
pub config: Option<ModelConfig>,
pub nodes: Vec<Node>,
pub weights: HashMap<String, TensorInfo>,
/* private fields */
}Expand description
The computation graph — the central IR artifact.
Fields§
§name: String§config: Option<ModelConfig>§nodes: Vec<Node>§weights: HashMap<String, TensorInfo>Maps weight names to their tensor info.
Implementations§
Source§impl Graph
impl Graph
pub fn new(name: impl Into<String>) -> Self
pub fn with_config(self, config: ModelConfig) -> Self
Sourcepub fn add_node(
&mut self,
op: Op,
inputs: Vec<NodeId>,
output: TensorInfo,
) -> NodeId
pub fn add_node( &mut self, op: Op, inputs: Vec<NodeId>, output: TensorInfo, ) -> NodeId
Add a node to the graph and return its ID.
Sourcepub fn alloc_tensor_id(&mut self) -> TensorId
pub fn alloc_tensor_id(&mut self) -> TensorId
Allocate a new tensor ID.
Sourcepub fn register_weight(
&mut self,
name: String,
shape: Shape,
dtype: DType,
) -> TensorId
pub fn register_weight( &mut self, name: String, shape: Shape, dtype: DType, ) -> TensorId
Register a weight tensor in the graph.
Sourcepub fn load_weight(
&mut self,
name: impl Into<String>,
shape: Shape,
dtype: DType,
) -> NodeId
pub fn load_weight( &mut self, name: impl Into<String>, shape: Shape, dtype: DType, ) -> NodeId
Add a weight-loading node.
Sourcepub fn input(
&mut self,
name: impl Into<String>,
shape: Shape,
dtype: DType,
) -> NodeId
pub fn input( &mut self, name: impl Into<String>, shape: Shape, dtype: DType, ) -> NodeId
Add an input node.
Sourcepub fn output_info(&self, id: NodeId) -> &TensorInfo
pub fn output_info(&self, id: NodeId) -> &TensorInfo
Get the output tensor info for a node.
Sourcepub fn topological_order(&self) -> Vec<NodeId> ⓘ
pub fn topological_order(&self) -> Vec<NodeId> ⓘ
Return node IDs in topological order. Since nodes are added in dependency order, this is just 0..n.
Sourcepub fn validate(&self) -> Result<(), GraphError>
pub fn validate(&self) -> Result<(), GraphError>
Validate the graph: check that all input references are valid and precede the node that uses them.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Graph
impl<'de> Deserialize<'de> for Graph
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Graph
impl RefUnwindSafe for Graph
impl Send for Graph
impl Sync for Graph
impl Unpin for Graph
impl UnsafeUnpin for Graph
impl UnwindSafe for Graph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more