Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nnef example #1284

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/nnef-dump-mobilenet-v2/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -ex

wget https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_1.4_224.tgz
[ -e mobilenet_v2_1.4_224.tgz ] || wget https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_1.4_224.tgz
tar zxf mobilenet_v2_1.4_224.tgz

cargo run -p tract -- mobilenet_v2_1.4_224_frozen.pb -i 1,224,224,3,f32 dump --nnef mobilenet.nnef.tgz
Expand Down
19 changes: 0 additions & 19 deletions nnef/src/ops/core/einsum.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::internal::*;
use crate::ser::*;
use tract_core::ops::einsum::BasicMatMul;
use tract_core::ops::einsum::EinSum;
use tract_core::tract_data::itertools::Itertools;

pub fn register(registry: &mut Registry) {
registry.register_dumper(ser_basic_matmul);
registry.register_dumper(ser);
registry.register_primitive(
"tract_core_einsum",
Expand Down Expand Up @@ -54,23 +52,6 @@ pub fn ser(ast: &mut IntoAst, node: &TypedNode, op: &EinSum) -> TractResult<Opti
}
}

pub fn ser_basic_matmul(ast: &mut IntoAst, node: &TypedNode, op: &BasicMatMul) -> TractResult<Option<Arc<RValue>>> {
let inputs = node.inputs.iter().map(|i| (*ast.mapping[i]).clone()).collect_vec();
if op.transpose_c {
Ok(Some(invocation(
"matmul",
&[Arc::new(inputs[1].clone()), Arc::new(inputs[0].clone())],
&[("transposeA", logical(!op.transpose_b)), ("transposeB", logical(!op.transpose_a))],
)))
} else {
Ok(Some(invocation(
"matmul",
&[Arc::new(inputs[0].clone()), Arc::new(inputs[1].clone())],
&[("transposeA", logical(op.transpose_a)), ("transposeB", logical(op.transpose_b))],
)))
}
}

pub fn ser_einsum(ast: &mut IntoAst, node: &TypedNode) -> TractResult<Option<Arc<RValue>>> {
let einsum = node.op_as::<EinSum>().unwrap();
let inputs: Vec<_> = node.inputs.iter().map(|i| (*ast.mapping[i]).clone()).collect();
Expand Down
2 changes: 2 additions & 0 deletions nnef/src/ops/nnef/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ pub fn tract_nnef() -> Registry {
primitive(&mut registry, "box", deser::sum_pool);
registry.register_dumper(ser::sum_pool);

registry.register_dumper(ser::basic_matmul);

for frag in stdlib {
if frag.body.is_some() {
registry.register_fragment(frag);
Expand Down
19 changes: 19 additions & 0 deletions nnef/src/ops/nnef/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use tract_core::ops::cnn::Conv;
use tract_core::ops::cnn::DeconvUnary;
use tract_core::ops::cnn::KernelFormat;
use tract_core::ops::cnn::PoolSpec;
use tract_core::ops::einsum::BasicMatMul;
use tract_core::ops::nn::DataFormat;
use tract_core::tract_data::itertools::Itertools;

pub fn source(
ast: &mut IntoAst,
Expand All @@ -29,6 +31,23 @@ pub fn source(
Ok(None)
}

pub fn basic_matmul(ast: &mut IntoAst, node: &TypedNode, op: &BasicMatMul) -> TractResult<Option<Arc<RValue>>> {
let inputs = node.inputs.iter().map(|i| (*ast.mapping[i]).clone()).collect_vec();
if op.transpose_c {
Ok(Some(invocation(
"matmul",
&[Arc::new(inputs[1].clone()), Arc::new(inputs[0].clone())],
&[("transposeA", logical(!op.transpose_b)), ("transposeB", logical(!op.transpose_a))],
)))
} else {
Ok(Some(invocation(
"matmul",
&[Arc::new(inputs[0].clone()), Arc::new(inputs[1].clone())],
&[("transposeA", logical(op.transpose_a)), ("transposeB", logical(op.transpose_b))],
)))
}
}

pub fn konst(
ast: &mut IntoAst,
node: &TypedNode,
Expand Down