tract_core/model/mod.rs
1//! ## Models and their lifecycle
2//!
3//! In order to reason on the model and performs optimisations, a model needs
4//! to be `typed`. This means all tensor exchanged between the nodes have a
5//! well defined element type (f32, i32, etc) and a shape ([1, 12, 53, 13]).
6//!
7//! A model typically starts as an `InferenceModel`, with minimum or partial
8//! tensor type information. At this stage, the application developper can add
9//! types and shapes hints (like the model inputs and output element types
10//! and shapes), then `tract` will perform type inference propagating this
11//! information. Hopefully `tract` will be able to infer a type and shape for
12//! all tensors in the model graph.
13//!
14//! At this stage, the model can be converted into a `TypedModel`.
15//!
16//! InferanceModel and TypeModel are two variants of `Graph`, Parameterized
17//! by a Fact implementation: TypedModel uses TypedFact, enforcing
18//! complete determination of element type and shape, and allowing a constant
19//! value for the tensor. InferenceModel uses InferenceFact, which can handle
20//! partial information.
21//!
22//! We call `declutter` the process getting the network closer to a normal
23//! form:. This normal form is akin to an IR in compiler technologies. This is
24//! the favourite form on which tract optimisation is implemented.
25//!
26//! For instance an Add node adding a constant input to a variable
27//! tensor input would be replaced by an unary Add operator taking only the
28//! variable input and for which the constant to add is a fixed construction
29//! attribute. In the same decluttering process, we try and replace proprietary
30//! operators (eg, from TensorFlow) by tract core operators: it is not always
31//! possible to simply map TensorFlow operators to tract-core while loading the
32//! network: their interfaces can be different (what is an input, what is an
33//! attribute) and constant propagation may be necessary before the right
34//! core operator could be chosen.
35//!
36use std::collections::HashMap;
37use std::str;
38
39mod fact;
40mod graph;
41pub mod memory;
42mod node;
43pub mod order;
44mod patch;
45mod rewriter;
46pub mod translator;
47pub mod typed;
48
49pub use self::fact::*;
50pub use self::graph::*;
51pub use self::node::*;
52pub use self::patch::ModelPatch;
53pub use self::rewriter::Rewriter;
54pub use crate::ops::{Op, TypedOp};
55
56pub use typed::*;