Skip to content

Commit

Permalink
fine tune dup name assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
kali committed Jun 14, 2023
1 parent 0a661fe commit 87d26da
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
16 changes: 15 additions & 1 deletion core/src/model/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ where

/// Performs a sanity check on network connections.
#[cfg(all(debug_assertions, feature = "paranoid_assertions"))]
#[inline]
pub fn check_edges(&self) -> TractResult<()> {
for node_id in self.eval_order()? {
let node = &self.nodes[node_id];
Expand Down Expand Up @@ -466,6 +465,21 @@ where
Ok(())
}

#[cfg(not(all(debug_assertions, feature = "paranoid_assertions")))]
#[inline]
pub fn check_names(&self) -> TractResult<()> {
Ok(())
}

/// Performs a sanity check on network connections.
#[cfg(all(debug_assertions, feature = "paranoid_assertions"))]
pub fn check_names(&self) -> TractResult<()> {
let dups =
self.eval_order()?.iter().map(|n| &self.nodes[*n].name).duplicates().collect_vec();
ensure!(dups.len() == 0, "Duplicate node name(s) : {:?}\n{}", dups, &self);
Ok(())
}

/// Converts the model into a `RunnableModel` which fixes the inputs and outputs and allows passing data through the model.
pub fn into_runnable(self) -> TractResult<RunnableModel<F, O, Self>> {
crate::plan::SimplePlan::new(self)
Expand Down
1 change: 1 addition & 0 deletions core/src/ops/change_axes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ impl TypedOp for AxisOp {
}
}


// a, b, c is a <- b, b <- c, c <- a
fn perm_to_cycles(perm: &[usize]) -> TVec<TVec<usize>> {
let mut cycles: TVec<TVec<usize>> = tvec!();
Expand Down
4 changes: 0 additions & 4 deletions core/src/optim/change_axes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,6 @@ pub fn change_axes(
interface_change.push((InOut::Out(ix), change.clone()));
}
}
debug_assert!(
patch.model.nodes.iter().map(|n| &n.name).collect::<std::collections::HashSet<_>>().len()
== patch.model.nodes.len()
);
debug!("Patch ready for {:?}", change);
Ok(Some((patch, interface_change)))
}
Expand Down
1 change: 1 addition & 0 deletions core/src/optim/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl<'o> OptimizerSession<'o> {
pub fn optimize(&mut self, model: &mut TypedModel) -> TractResult<()> {
model.check_consistency().context("during optimizer preflight check")?;
model.compact().context("during optimizer preflight compaction")?;
model.check_names().context("after optimizer preflight compaction")?;
for i in 0.. {
let old = self.counter;
self.run_all_passes(i, model)?;
Expand Down

0 comments on commit 87d26da

Please sign in to comment.