Skip to content

add: functional onnx converter#38

Open
sid-alluri wants to merge 7 commits intoddkang:mainfrom
sid-alluri:main
Open

add: functional onnx converter#38
sid-alluri wants to merge 7 commits intoddkang:mainfrom
sid-alluri:main

Conversation

@sid-alluri
Copy link
Copy Markdown

Converts an onnx model into the .msgpack. Current functionality: converts a simple mnist onnx model.

To run:

  • cargo build --release
  • ./target/release/time_circuit python/onnx_converter/first_transformed_onnx.msgpack examples/mnist/inp.msgpack kzg

Comment thread src/layers/relu.rs
@@ -0,0 +1,45 @@
use std::{collections::HashMap, rc::Rc, vec};
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this as a separate layer? Is it not fused?

Copy link
Copy Markdown
Author

@sid-alluri sid-alluri Aug 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
It is not fused.

Comment thread src/utils/loader.rs Outdated
for tensor in inp {
model.tensors.push(tensor);
model.tensors.push(tensor.clone());
// println!("tensor: {:?}", tensor);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's tons of extraneous changes. Clean them up.

@@ -0,0 +1,302 @@
# Oggn
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turn this into the way that the other converter is written with a class and a main function

struct.pack_into('q', shape, 0, -1)
init.raw_data = bytes(shape)

onnx.save(model, "/Users/siddharthaalluri/Desktop/sid-alluri/zkml/python/onnx_converter/new_mnist.onnx")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix this

Comment thread python/onnx_converter/onnxconverter.py Outdated
params = [kernel[0], kernel[1], stride[0], stride[1]]

elif node.op_type == "Relu":
layer_type = "ReLUONNX"
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there a separate ReluONNX layer?

output_dim = get_output_dim(node_id, model_graph)
params = []

elif node.op_type == "Gemm":
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work for all forms of Gemm?

Comment thread python/onnx_converter/onnxconverter.py Outdated
"layer_type": layer_type,
"params": params, ## Change params HELP HELP HELP HELP
"inp_shapes": inputs_dim,
"inp_idxes": inp_idxes, ### RANDOM COME BACK HERE HELP HELP HELP HELP
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's going on here?

Comment thread src/layers.rs Outdated
pub mod squared_diff;
pub mod tanh;
pub mod update;
pub mod relu;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the rust extension to sort imports.

Comment thread src/layers/dag.rs Outdated
tanh::TanhChip,
update::UpdateChip,
update::UpdateChip,
relu::ReluLayerChip,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move ReLU to the non-linear diretory

Comment thread src/layers/fully_connected.rs Outdated
) -> Array<Value<F>, IxDyn> {
assert_eq!(input.ndim(), 2);
assert_eq!(weight.ndim(), 2);
println!("input shape: {:?}", input.shape());
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extraneous

Comment thread src/layers/layer.rs Outdated
Tanh,
Transpose,
Update,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there an extra space?

Comment thread src/layers/max_pool_2d.rs Outdated
let (sx, sy) = (sx as usize, sy as usize);

// Only support batch size 1 for now

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extraneous

Comment thread src/utils/loader.rs Outdated

model
}
} No newline at end of file
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extraneous

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants