pub struct GraphOptimizer { /* private fields */ }Expand description
Graph optimization manager
Implementations§
Source§impl GraphOptimizer
impl GraphOptimizer
Sourcepub fn add_default_passes(&mut self)
pub fn add_default_passes(&mut self)
Add default optimization passes
Sourcepub fn for_eager_execution() -> Self
pub fn for_eager_execution() -> Self
Build an optimizer using only the passes that are safe to run ahead
of the eager Session executor.
This deliberately excludes:
OperationFusionPass: it rewrites nodes into fused operation names ("Dense","AddReLU","ConvBatchNormReLU", …) that the eager executor’s operation dispatcher does not implement. Running it here would silently turn a working graph (e.g. anyMatMulimmediately followed byAdd) into a hard “operation not supported” error at execution time.MemoryOptimizationPassandDevicePlacementOptimizationPass: both only annotate node attributes (lifetime hints, in-place markers, device placement metadata) that the eager executor never reads, so running them would add cost without any effect.
The remaining passes (constant folding, algebraic simplification, common subexpression elimination, strength reduction, scheduling, and dead code elimination) only ever produce operation names the executor already understands, or mutate a node’s inputs/op in place while preserving its id, so they are safe to run unconditionally.
Sourcepub fn add_pass(&mut self, pass: Box<dyn OptimizationPass>)
pub fn add_pass(&mut self, pass: Box<dyn OptimizationPass>)
Add an optimization pass
Sourcepub fn set_max_iterations(&mut self, max_iterations: usize)
pub fn set_max_iterations(&mut self, max_iterations: usize)
Set maximum number of optimization iterations
Sourcepub fn pass_count(&self) -> usize
pub fn pass_count(&self) -> usize
Get the number of optimization passes
Sourcepub fn optimize(&self, graph: &mut Graph) -> Result<OptimizationStats>
pub fn optimize(&self, graph: &mut Graph) -> Result<OptimizationStats>
Optimize a computation graph
Sourcepub fn optimize_with_outputs(
&self,
graph: &mut Graph,
outputs: &HashSet<NodeId>,
) -> Result<OptimizationStats>
pub fn optimize_with_outputs( &self, graph: &mut Graph, outputs: &HashSet<NodeId>, ) -> Result<OptimizationStats>
Optimize a computation graph while protecting outputs from being
eliminated or merged away.
outputs should contain every node id that must keep its identity
after optimization — typically the fetch targets a caller (such as
the eager Session executor) intends to read back by node id or
name. Every pass is informed of this set via
OptimizationPass::set_outputs before running; passes that never
destroy a node’s identity ignore it, while dead code elimination,
common subexpression elimination, and identity-removing algebraic /
strength-reduction rewrites treat these ids as protected (skipping
the rewrite for that node this iteration rather than applying it).
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for GraphOptimizer
impl !Send for GraphOptimizer
impl !Sync for GraphOptimizer
impl !UnwindSafe for GraphOptimizer
impl Freeze for GraphOptimizer
impl Unpin for GraphOptimizer
impl UnsafeUnpin for GraphOptimizer
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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