Struct tract_core::model::ModelPatch

source ·
pub struct ModelPatch<F, O>
where F: Fact + Clone + 'static, O: Display + Debug + AsRef<dyn Op> + AsMut<dyn Op> + Clone + 'static,
{ pub context: Vec<String>, pub dont_apply_twice: Option<String>, pub model: Graph<F, O>, pub inputs: HashMap<usize, usize>, pub taps: HashMap<OutletId, OutletId>, pub shunts: HashMap<OutletId, OutletId>, pub obliterate: Vec<usize>, }
Expand description

A change to apply to a model.

Actually structured around a model that represent the new nodes to be inserted, plus information about how to connect these new nodes to the pre-existing graph.

Fields§

§context: Vec<String>

patch label for auditing and debugging

§dont_apply_twice: Option<String>

optimizer will ignore this patch in node to node loop if it was already encountered

§model: Graph<F, O>

the model-like ‘patch’ of nodes to add to the model

§inputs: HashMap<usize, usize>

map of replaced inputs (patch node id to model node id)

§taps: HashMap<OutletId, OutletId>

map of patch inputs to model wires

§shunts: HashMap<OutletId, OutletId>

map of old model wires to be replaced by wires from the patch

§obliterate: Vec<usize>

operations to discard from the model

Implementations§

source§

impl<F, O> ModelPatch<F, O>
where F: Fact + Clone + 'static, O: Display + Debug + AsRef<dyn Op> + AsMut<dyn Op> + Clone + 'static, Graph<F, O>: SpecialOps<F, O>,

source

pub fn new(s: impl Into<String>) -> Self

source

pub fn push_context(&mut self, s: impl Into<String>)

source

pub fn with_context(self, s: impl Into<String>) -> Self

source

pub fn is_empty(&self) -> bool

source

pub fn tap_model( &mut self, model: &Graph<F, O>, outlet: OutletId ) -> TractResult<OutletId>

Draw a tap from a preexisting node.

returns an OutletId usable in the little “patch” model

source

pub fn taps<'a>( &mut self, model: &Graph<F, O>, outlets: impl IntoIterator<Item = &'a OutletId> ) -> TractResult<TVec<OutletId>>

Draw taps from a preexisting node.

returns an OutletId usable in the little “patch” model

source

pub unsafe fn shunt_outside_unchecked( &mut self, outlet: OutletId, by: OutletId ) -> TractResult<()>

source

pub fn shunt_outside( &mut self, model: &Graph<F, O>, outlet: OutletId, by: OutletId ) -> TractResult<()>

Replace an Outlet in the target model by one from the patch.

source

pub fn obliterate(&mut self, node: usize) -> TractResult<()>

source

pub fn replace_single_op<IO: Into<O>>( patched_model: &Graph<F, O>, node: &Node<F, O>, inputs: &[OutletId], new_op: IO ) -> TractResult<ModelPatch<F, O>>

Convenience method creating a patch that replaces a single operation.

source

pub fn fuse_with_next<IO: Into<O>>( patched_model: &Graph<F, O>, node: &Node<F, O>, new_op: IO ) -> TractResult<ModelPatch<F, O>>

Convenience method creating a patch that fuses an op with the next one.

source

pub fn shunt_one_op( patched_model: &Graph<F, O>, node: &Node<F, O> ) -> TractResult<Option<ModelPatch<F, O>>>

Convenience method creating a patch that shunts the given node.

source

pub fn rewire( patched_model: &Graph<F, O>, from: &[OutletId], to: &[OutletId], wiring: &dyn Fn(&mut Self, &[OutletId]) -> TractResult<TVec<OutletId>> ) -> TractResult<ModelPatch<F, O>>

source

pub fn single_unary_op<IO: Into<O>>( patched_model: &Graph<F, O>, node: &Node<F, O>, new_op: IO ) -> TractResult<ModelPatch<F, O>>

Convenience method creating a patch that replace a single unary operation.

source

pub fn intercept<IO: Into<O>>( patched_model: &Graph<F, O>, outlet: OutletId, name: impl Into<String>, new_op: IO, fact: F ) -> TractResult<ModelPatch<F, O>>

Convenience method creating a patch that insert an unary op on an outlet.

source

pub fn apply(self, target: &mut Graph<F, O>) -> TractResult<()>

Apply all changes in the patch to the target model.

Methods from Deref<Target = Graph<F, O>>§

source

pub fn add_source( &mut self, name: impl Into<String>, fact: F ) -> TractResult<OutletId>

source

pub fn add_node( &mut self, name: impl Into<String>, op: impl Into<O>, output_facts: TVec<F> ) -> TractResult<usize>

source

pub fn add_edge(&mut self, outlet: OutletId, inlet: InletId) -> TractResult<()>

Connect a node outlet to a node inlet.

source

pub fn input_outlets(&self) -> TractResult<&[OutletId]>

Get model inputs.

source

pub fn set_input_outlets(&mut self, inputs: &[OutletId]) -> TractResult<()>

Change model inputs.

source

pub fn set_input_names( &mut self, inputs: impl IntoIterator<Item = impl AsRef<str>> ) -> TractResult<()>

Set model inputs by the node name.

source

pub fn input_fact(&self, ix: usize) -> TractResult<&F>

Get the ix-th input tensor type information.

source

pub fn input_fact_mut(&mut self, ix: usize) -> TractResult<&mut F>

Get the ix-th input tensor type information, mutably.

source

pub fn set_input_fact(&mut self, input: usize, fact: F) -> TractResult<()>

Set the ix-th input tensor type information.

source

pub fn output_outlets(&self) -> TractResult<&[OutletId]>

Get model outputs.

source

pub fn auto_outputs(&mut self) -> TractResult<()>

Guess outputs from the topology: node or nodes with no successors.

source

pub fn set_output_outlets(&mut self, outputs: &[OutletId]) -> TractResult<()>

Change model outputs.

source

pub fn set_output_names( &mut self, outputs: impl IntoIterator<Item = impl AsRef<str>> ) -> TractResult<()>

Set model outputs by node names.

source

pub fn output_fact(&self, ix: usize) -> TractResult<&F>

Get the ix-th input tensor type information.

source

pub fn output_fact_mut(&mut self, ix: usize) -> TractResult<&mut F>

Get the ix-th input tensor type information, mutably.

source

pub fn set_output_fact(&mut self, output: usize, fact: F) -> TractResult<()>

Set the ix-th output tensor type information.

source

pub fn node_names(&self) -> impl Iterator<Item = &str>

Iterate over all node names.

source

pub fn node_id_by_name(&self, name: &str) -> TractResult<usize>

source

pub fn node_by_name(&self, name: impl AsRef<str>) -> TractResult<&Node<F, O>>

Find a node by its name.

source

pub fn node_by_name_mut( &mut self, name: impl AsRef<str> ) -> TractResult<&mut Node<F, O>>

Borrow mutably a node by its name.

source

pub fn rename_node(&mut self, id: usize, name: &str) -> TractResult<()>

source

pub fn node(&self, id: usize) -> &Node<F, O>

Find a node by its id.

source

pub fn node_mut(&mut self, id: usize) -> &mut Node<F, O>

Find a node by its id.

source

pub fn nodes(&self) -> &[Node<F, O>]

Access the nodes table.

source

pub fn nodes_mut(&mut self) -> &mut [Node<F, O>]

Access the nodes table.

source

pub fn node_facts(&self, id: usize) -> TractResult<(TVec<&F>, TVec<&F>)>

Get input and output tensor information for a node.

source

pub fn node_input_facts(&self, node_id: usize) -> TractResult<TVec<&F>>

Get input tensor information for a node.

source

pub fn node_output_facts(&self, node_id: usize) -> TractResult<TVec<&F>>

Get output tensor information for a node.

source

pub fn outlet_fact(&self, outlet: OutletId) -> TractResult<&F>

Get tensor information for a single outlet.

source

pub fn outlet_fact_mut(&mut self, outlet: OutletId) -> TractResult<&mut F>

Get tensor information for a single outlet.

source

pub fn outlets_fact_mut( &mut self, outlets: &[OutletId] ) -> TractResult<TVec<&mut F>>

Get multiple mutable tensor information for outlets.

source

pub fn set_outlet_fact(&mut self, outlet: OutletId, fact: F) -> TractResult<()>

Set tensor information for a single outlet.

source

pub fn outlet_label(&self, outlet: OutletId) -> Option<&str>

Get label for an outlet.

source

pub fn set_outlet_label( &mut self, outlet: OutletId, label: String ) -> TractResult<()>

Set label for an outlet.

source

pub fn find_outlet_label(&self, label: &str) -> Option<OutletId>

Find outlet by label.

source

pub fn eval_order(&self) -> TractResult<Vec<usize>>

Computes an evalutation order for the graph inputs and outputs

source

pub fn eval_order_opt_ram(&self) -> TractResult<Vec<usize>>

Computes an evalutation order for the graph inputs and outputs. This order will minimize temporary buffers.

source

pub fn check_edges(&self) -> TractResult<()>

source

pub fn check_names(&self) -> TractResult<()>

source

pub fn single_prec(&self, id: usize) -> TractResult<Option<&Node<F, O>>>

source

pub fn single_prec_at( &self, id: usize, count: usize ) -> TractResult<Option<&Node<F, O>>>

source

pub fn single_succ_at( &self, id: usize, count: usize ) -> TractResult<Option<&Node<F, O>>>

source

pub fn single_succ(&self, id: usize) -> TractResult<Option<&Node<F, O>>>

source

pub fn outlet_successors(&self, outlet: OutletId) -> &[InletId]

source

pub fn check_compact(&self) -> TractResult<()>

source

pub fn compact(&mut self) -> TractResult<()>

source

pub fn check_consistency(&self) -> TractResult<()>

source

pub fn transform(&mut self, transform: &dyn ModelTransform) -> TractResult<()>

Perform declutter passes on the network.

source

pub fn declutter(&mut self) -> TractResult<()>

Perform declutter passes on the network.

source

pub fn optimize_with_session( &mut self, session: &mut OptimizerSession<'_> ) -> TractResult<()>

Perform optimization passes on the model, using a given optimizer session.

source

pub fn concretize_dims(&self, values: &SymbolValues) -> TractResult<TypedModel>

source

pub fn optimize(&mut self) -> TractResult<()>

Translate the graph to locally optimized operators (LIR or MIR ops).

source

pub fn node_axes_mapping(&self, id: usize) -> TractResult<AxesMapping>

source

pub fn axes_mapping(&self) -> TractResult<AxesMapping>

Trait Implementations§

source§

impl<F, O> Clone for ModelPatch<F, O>
where F: Fact + Clone + 'static + Clone, O: Display + Debug + AsRef<dyn Op> + AsMut<dyn Op> + Clone + 'static + Clone,

source§

fn clone(&self) -> ModelPatch<F, O>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<F, O> Debug for ModelPatch<F, O>
where F: Fact + Clone + 'static + Debug, O: Display + Debug + AsRef<dyn Op> + AsMut<dyn Op> + Clone + 'static + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<F, O> Default for ModelPatch<F, O>
where F: Fact + Clone + 'static, O: Display + Debug + AsRef<dyn Op> + AsMut<dyn Op> + Clone + 'static,

source§

fn default() -> ModelPatch<F, O>

Returns the “default value” for a type. Read more
source§

impl<F, O> Deref for ModelPatch<F, O>
where F: Fact + Clone + 'static, O: Display + Debug + AsRef<dyn Op> + AsMut<dyn Op> + Clone + 'static,

§

type Target = Graph<F, O>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Graph<F, O>

Dereferences the value.
source§

impl<F, O> DerefMut for ModelPatch<F, O>
where F: Fact + Clone + 'static, O: Display + Debug + AsRef<dyn Op> + AsMut<dyn Op> + Clone + 'static,

source§

fn deref_mut(&mut self) -> &mut Graph<F, O>

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<F, O> Freeze for ModelPatch<F, O>

§

impl<F, O> RefUnwindSafe for ModelPatch<F, O>

§

impl<F, O> Send for ModelPatch<F, O>
where O: Send,

§

impl<F, O> Sync for ModelPatch<F, O>
where O: Sync,

§

impl<F, O> Unpin for ModelPatch<F, O>
where O: Unpin, F: Unpin,

§

impl<F, O> UnwindSafe for ModelPatch<F, O>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.