file_path
stringlengths
7
180
content
stringlengths
0
811k
repo
stringclasses
11 values
examples/onnx/1l_relu/gen.py
from torch import nn from ezkl import export class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() self.layer = nn.ReLU() def forward(self, x): return self.layer(x) circuit = MyModel() export(circuit, input_shape = [3])
https://github.com/zkonduit/ezkl
examples/onnx/1l_reshape/gen.py
import torch from torch import nn from ezkl import export class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): x = x.reshape([-1, 6]) return x circuit = MyModel() export(circuit, input_shape=[1, 3, 2])
https://github.com/zkonduit/ezkl
examples/onnx/1l_sigmoid/gen.py
from torch import nn from ezkl import export class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() self.layer = nn.Sigmoid() def forward(self, x): return self.layer(x) circuit = MyModel() export(circuit, input_shape = [3])
https://github.com/zkonduit/ezkl
examples/onnx/1l_slice/gen.py
import torch from torch import nn from ezkl import export class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): return x[:,1:2] circuit = MyModel() export(circuit, input_shape=[3, 2])
https://github.com/zkonduit/ezkl
examples/onnx/1l_softmax/gen.py
import torch from torch import nn from ezkl import export class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() self.layer = nn.Softmax(dim=1) def forward(self, x): return self.layer(x) circuit = MyModel() export(circuit, input_shape=[3])
https://github.com/zkonduit/ezkl
examples/onnx/1l_sqrt/gen.py
import torch from torch import nn from ezkl import export class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): return torch.sqrt(x) circuit = MyModel() export(circuit, input_shape = [3])
https://github.com/zkonduit/ezkl
examples/onnx/1l_tiny_div/gen.py
from torch import nn import torch import json class Circuit(nn.Module): def __init__(self, inplace=False): super(Circuit, self).__init__() def forward(self, x): return x/ 10000 circuit = Circuit() x = torch.empty(1, 8).random_(0, 2) out = circuit(x) print(out) torch.onnx.export(circuit,...
https://github.com/zkonduit/ezkl
examples/onnx/1l_topk/gen.py
from torch import nn import torch import json class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): topk_largest = torch.topk(x, 4) topk_smallest = torch.topk(x, 4, largest=False) print(topk_largest) print(topk_smallest) ...
https://github.com/zkonduit/ezkl
examples/onnx/1l_upsample/gen.py
import io import numpy as np from torch import nn import torch.onnx import torch.nn as nn import torch.nn.init as init import json class Circuit(nn.Module): def __init__(self, inplace=False): super(Circuit, self).__init__() self.upsample = nn.Upsample(scale_factor=2, mode='nearest') def forwar...
https://github.com/zkonduit/ezkl
examples/onnx/1l_var/gen.py
from torch import nn from ezkl import export import torch class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): return [torch.var(x, unbiased=False, dim=[1,2])] circuit = MyModel() export(circuit, input_shape = [1,3,3])
https://github.com/zkonduit/ezkl
examples/onnx/1l_where/gen.py
from torch import nn import torch import json class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): return [torch.where(x >= 0.0, 3.0, 5.0)] circuit = MyModel() x = torch.randint(1, (1, 64)) torch.onnx.export(circuit, x, "network.onnx", ...
https://github.com/zkonduit/ezkl
examples/onnx/2l_relu_fc/gen.py
from torch import nn import torch.nn.init as init from ezkl import export class Model(nn.Module): def __init__(self, inplace=False): super(Model, self).__init__() self.aff1 = nn.Linear(3,1) self.relu = nn.ReLU() self._initialize_weights() def forward(self, x): x = sel...
https://github.com/zkonduit/ezkl
examples/onnx/2l_sigmoid_small/gen.py
from torch import nn from ezkl import export class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() self.relu = nn.ReLU() self.sigmoid = nn.Sigmoid() self.fc = nn.Linear(3, 2) def forward(self, x): x = self.sigmoid(x) x = self.sigmoid(x) ...
https://github.com/zkonduit/ezkl
examples/onnx/3l_relu_conv_fc/gen.py
from torch import nn from ezkl import export class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() self.conv1 = nn.Conv2d(1,4, kernel_size=5, stride=2) self.conv2 = nn.Conv2d(4,4, kernel_size=5, stride=2) self.relu = nn.ReLU() self.fc = nn.Linear(4*4*...
https://github.com/zkonduit/ezkl
examples/onnx/4l_relu_conv_fc/gen.py
from torch import nn from ezkl import export class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() self.conv1 = nn.Conv2d(in_channels=1, out_channels=2, kernel_size=5, stride=2) self.conv2 = nn.Conv2d(in_channels=2, out_channels=3, kernel_size=5, stride=2) ...
https://github.com/zkonduit/ezkl
examples/onnx/arange/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self): return torch.arange(0, 10, 2) circuit = MyModel() torch.onnx.export(circuit, (), "network.onnx", export_para...
https://github.com/zkonduit/ezkl
examples/onnx/bitshift/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, w, x, y, z): return x << 2, y >> 3, z << 1, w >> 4 circuit = MyModel() # random integers between 0 and 100 x = torch.empty...
https://github.com/zkonduit/ezkl
examples/onnx/bitwise_ops/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, w, x, y, z): # bitwise and and_xy = torch.bitwise_and(x, y) # bitwise or or_yz = torch.bitwise_or(y, z)...
https://github.com/zkonduit/ezkl
examples/onnx/blackman_window/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): # bitwise and bmw = torch.blackman_window(8) + x return bmw circuit = MyModel() x = torch.empty(1, 8).unifor...
https://github.com/zkonduit/ezkl
examples/onnx/boolean/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, w, x, y, z): return [((x & y)) == (x & (y | (z ^ w)))] circuit = MyModel() a = torch.empty(1, 3).uniform_(0, 1) w = torch.bernou...
https://github.com/zkonduit/ezkl
examples/onnx/boolean_identity/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): return [x] circuit = MyModel() a = torch.empty(1, 3).uniform_(0, 1) x = torch.bernoulli(a).to(torch.bool) torch.onnx.expor...
https://github.com/zkonduit/ezkl
examples/onnx/celu/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): m = nn.CELU()(x) return m circuit = MyModel() x = torch.empty(1, 8).uniform_(0, 1) out = circuit...
https://github.com/zkonduit/ezkl
examples/onnx/clip/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): m = torch.clamp(x, min=0.4, max=0.8) return m circuit = MyModel() x = torch.empty(1, 2, 2, 8).uniform_(0, 1...
https://github.com/zkonduit/ezkl
examples/onnx/decision_tree/gen.py
# Train a model. import json import onnxruntime as rt from skl2onnx import to_onnx import numpy as np from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.tree import DecisionTreeClassifier as De import sk2torch import torch iris = load_iris() X, y = iris.data, iris....
https://github.com/zkonduit/ezkl
examples/onnx/doodles/gen.py
from torch import nn from ezkl import export class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): return x circuit = MyModel() export(circuit, input_shape=[1, 64, 64])
https://github.com/zkonduit/ezkl
examples/onnx/eye/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): m = x @ torch.eye(8) return m circuit = MyModel() x = torch.empty(1, 8).uniform_(0, 1) out = cir...
https://github.com/zkonduit/ezkl
examples/onnx/gather_elements/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, w, x): return torch.gather(w, 1, x) circuit = MyModel() w = torch.rand(1, 15, 18) x = torch.randint(0, 15, (1, 15, 2)) torch.on...
https://github.com/zkonduit/ezkl
examples/onnx/gather_nd/gen.py
from torch import nn import json import numpy as np import tf2onnx import tensorflow as tf from tensorflow.keras.layers import * from tensorflow.keras.models import Model # gather_nd in tf then export to onnx x = in1 = Input((15, 18,)) w = in2 = Input((15, 1), dtype=tf.int32) x = tf.gather_nd(x, w, batch_dims=1...
https://github.com/zkonduit/ezkl
examples/onnx/gradient_boosted_trees/gen.py
# make sure you have the dependencies required here already installed import json import numpy as np from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.ensemble import GradientBoostingClassifier as Gbc import sk2torch import torch import ezkl import os from torch im...
https://github.com/zkonduit/ezkl
examples/onnx/gru/gen.py
import random import math import numpy as np import torch from torch import nn import torch.nn.functional as F import json model = nn.GRU(3, 3) # Input dim is 3, output dim is 3 x = torch.randn(1, 3) # make a sequence of length 5 print(x) # Flips the neural net into inference mode model.eval() model.to('cpu') #...
https://github.com/zkonduit/ezkl
examples/onnx/hard_max/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): m = torch.argmax(x) return m circuit = MyModel() x = torch.empty(1, 8).uniform_(0, 1) out = circ...
https://github.com/zkonduit/ezkl
examples/onnx/hard_sigmoid/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): m = nn.Hardsigmoid()(x) return m circuit = MyModel() x = torch.empty(1, 8).uniform_(0, 1) out = ...
https://github.com/zkonduit/ezkl
examples/onnx/hard_swish/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): m = nn.Hardswish()(x) return m circuit = MyModel() x = torch.empty(1, 8).uniform_(0, 1) out = circuit(x) print(out)...
https://github.com/zkonduit/ezkl
examples/onnx/hummingbird_decision_tree/gen.py
# Train a model. import json import onnxruntime as rt from skl2onnx import to_onnx import numpy as np from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.tree import DecisionTreeClassifier as De from hummingbird.ml import convert import torch iris = load_iris() X, y...
https://github.com/zkonduit/ezkl
examples/onnx/layernorm/gen.py
import torch import torch.nn as nn import json # A single model that only does layernorm class LayerNorm(nn.Module): def __init__(self, hidden_size): super().__init__() self.ln = nn.LayerNorm(hidden_size) def forward(self, x): return self.ln(x) x = torch.randn(1, 10, 10) model =...
https://github.com/zkonduit/ezkl
examples/onnx/less/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, w, x): return torch.less(w, x) circuit = MyModel() w = torch.rand(1, 4) x = torch.rand(1, 4) torch.onnx.export(circuit, (w, x),...
https://github.com/zkonduit/ezkl
examples/onnx/lightgbm/gen.py
# make sure you have the dependencies required here already installed import json import numpy as np from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from lightgbm import LGBMClassifier as Gbc import torch import ezkl import os from torch import nn import xgboost as xgb from h...
https://github.com/zkonduit/ezkl
examples/onnx/linear_regression/gen.py
import os import torch import ezkl import json from hummingbird.ml import convert # here we create and (potentially train a model) # make sure you have the dependencies required here already installed import numpy as np from sklearn.linear_model import LinearRegression X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]]) ...
https://github.com/zkonduit/ezkl
examples/onnx/log_softmax/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): m = nn.LogSoftmax()(x) return m circuit = MyModel() x = torch.empty(1, 8).uniform_(0, 1) out = c...
https://github.com/zkonduit/ezkl
examples/onnx/logsumexp/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): m = torch.logsumexp(x, dim=1) return m circuit = MyModel() x = torch.empty(1, 2, 2, 8).uniform_(0...
https://github.com/zkonduit/ezkl
examples/onnx/lstm/gen.py
import random import math import numpy as np import torch from torch import nn import torch.nn.functional as F import json model = nn.LSTM(3, 3) # Input dim is 3, output dim is 3 x = torch.randn(1, 3) # make a sequence of length 5 print(x) # Flips the neural net into inference mode model.eval() model.to('cpu') ...
https://github.com/zkonduit/ezkl
examples/onnx/ltsf/gen.py
import torch import torch.nn as nn import torch.nn.functional as F import numpy as np import json class moving_avg(nn.Module): """ Moving average block to highlight the trend of time series """ def __init__(self, kernel_size, stride): super(moving_avg, self).__init__() self.kernel_size ...
https://github.com/zkonduit/ezkl
examples/onnx/max/gen.py
from torch import nn from ezkl import export import torch class Model(nn.Module): def __init__(self): super(Model, self).__init__() def forward(self, x): return [torch.max(x)] circuit = Model() export(circuit, input_shape=[3, 2, 2])
https://github.com/zkonduit/ezkl
examples/onnx/min/gen.py
from torch import nn from ezkl import export import torch class Model(nn.Module): def __init__(self): super(Model, self).__init__() def forward(self, x): return [torch.min(x)] circuit = Model() export(circuit, input_shape=[3, 2, 2])
https://github.com/zkonduit/ezkl
examples/onnx/mish/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): m = nn.Mish()(x) return m circuit = MyModel() x = torch.empty(1, 8).uniform_(0, 1) out = circuit...
https://github.com/zkonduit/ezkl
examples/onnx/multihead_attention/gen.py
# 1. We define a simple transformer model with MultiHeadAttention layers import ezkl import json import torch import torch.nn as nn import torch.nn.functional as F class ScaledDotProductAttention(nn.Module): def __init__(self, d_model, dropout=0.1): super().__init__() self.temperature = d_model **...
https://github.com/zkonduit/ezkl
examples/onnx/nanoGPT/gen.py
""" Reference: https://github.com/karpathy/nanoGPT """ import json import math from dataclasses import dataclass import torch import torch.nn as nn from torch.nn import functional as F import sys import os SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.dirname(SCRIPT_DIR)) def new...
https://github.com/zkonduit/ezkl
examples/onnx/oh_decision_tree/gen.py
# Train a model. import json import onnxruntime as rt from skl2onnx import to_onnx import numpy as np from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.tree import DecisionTreeClassifier as De import sk2torch import torch iris = load_iris() X, y = iris.data, iris....
https://github.com/zkonduit/ezkl
examples/onnx/quantize_dequantize/gen.py
import json import torch import torch.nn as nn import torch.optim as optim from torch.ao.quantization import QuantStub, DeQuantStub # define NN architecture class PredictLiquidationsV0(nn.Module): def __init__(self): super().__init__() self.quant = QuantStub() self.layer_1 = nn.Linear(in_...
https://github.com/zkonduit/ezkl
examples/onnx/random_forest/gen.py
# make sure you have the dependencies required here already installed import json import numpy as np from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.ensemble import RandomForestClassifier as Rf import sk2torch import torch import ezkl import os from torch import ...
https://github.com/zkonduit/ezkl
examples/onnx/reducel1/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): m = torch.norm(x, p=1, dim=1) return m circuit = MyModel() x = torch.empty(1, 2, 2, 8).uniform_(0...
https://github.com/zkonduit/ezkl
examples/onnx/reducel2/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): m = torch.norm(x, p=2, dim=1) return m circuit = MyModel() x = torch.empty(1, 2, 2, 8).uniform_(0...
https://github.com/zkonduit/ezkl
examples/onnx/remainder/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): return x % 0.5 circuit = MyModel() x = torch.empty(1, 8).uniform_(0, 1) out = circuit(x) print(out) torc...
https://github.com/zkonduit/ezkl
examples/onnx/rnn/gen.py
import random import math import numpy as np import torch from torch import nn import torch.nn.functional as F import json model = nn.RNN(3, 3) # Input dim is 3, output dim is 3 x = torch.randn(1, 3) # make a sequence of length 5 print(x) # Flips the neural net into inference mode model.eval() model.to('cpu') #...
https://github.com/zkonduit/ezkl
examples/onnx/rounding_ops/gen.py
import io import numpy as np from torch import nn import torch.onnx import torch import torch.nn as nn import torch.nn.init as init import json class Circuit(nn.Module): def __init__(self): super(Circuit, self).__init__() def forward(self, w, x, y): return torch.round(w), torch.floor(x), tor...
https://github.com/zkonduit/ezkl
examples/onnx/scatter_elements/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, w, x, src): # scatter_elements return w.scatter(2, x, src) circuit = MyModel() w = torch.rand(1, 15, 18) src = torch.ran...
https://github.com/zkonduit/ezkl
examples/onnx/scatter_nd/gen.py
import torch import torch.nn as nn import sys import json sys.path.append("..") class Model(nn.Module): """ Just one Linear layer """ def __init__(self, configs): super(Model, self).__init__() self.seq_len = configs.seq_len self.pred_len = configs.pred_len # Use this l...
https://github.com/zkonduit/ezkl
examples/onnx/self_attention/gen.py
""" Reference: https://github.com/karpathy/nanoGPT :) """ import torch import json from torch import nn import math from dataclasses import dataclass from torch.nn import functional as F @dataclass class GPTConfig: block_size: int = 1024 vocab_size: int = 50304 # GPT-2 vocab_size of 50257, padded up to near...
https://github.com/zkonduit/ezkl
examples/onnx/selu/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): m = nn.SELU()(x) return m circuit = MyModel() x = torch.empty(1, 8).uniform_(0, 1) out = circuit...
https://github.com/zkonduit/ezkl
examples/onnx/softplus/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): m = nn.Softplus()(x) return m circuit = MyModel() x = torch.empty(1, 8).uniform_(0, 1) out = cir...
https://github.com/zkonduit/ezkl
examples/onnx/softsign/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): m = nn.Softsign()(x) return m circuit = MyModel() x = torch.empty(1, 8).uniform_(0, 1) out = cir...
https://github.com/zkonduit/ezkl
examples/onnx/trig/gen.py
import io import numpy as np from torch import nn import torch.onnx import torch import torch.nn as nn import torch.nn.init as init import json class Circuit(nn.Module): def __init__(self): super(Circuit, self).__init__() self.softplus = nn.Softplus() def forward(self, x): x = self.so...
https://github.com/zkonduit/ezkl
examples/onnx/tril/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): m = torch.triu(x) return m circuit = MyModel() x = torch.empty(1, 3, 3).uniform_(0, 5) out = cir...
https://github.com/zkonduit/ezkl
examples/onnx/triu/gen.py
from torch import nn import torch import json import numpy as np class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() def forward(self, x): m = torch.tril(x) return m circuit = MyModel() x = torch.empty(1, 3, 3).uniform_(0, 5) out = cir...
https://github.com/zkonduit/ezkl
examples/onnx/tutorial/gen.py
import io import numpy as np from torch import nn import torch.onnx import torch.nn as nn import torch.nn.init as init import json class Circuit(nn.Module): def __init__(self, inplace=False): super(Circuit, self).__init__() self.relu = nn.ReLU() self.sigmoid = nn.Sigmoid() self.co...
https://github.com/zkonduit/ezkl
examples/onnx/xgboost/gen.py
# make sure you have the dependencies required here already installed import json import numpy as np from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from xgboost import XGBClassifier as Gbc import torch import ezkl import os from torch import nn import xgboost as xgb from hum...
https://github.com/zkonduit/ezkl
examples/onnx/xgboost_reg/gen.py
# make sure you have the dependencies required here already installed import json import numpy as np from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from xgboost import XGBRegressor as Gbc import torch import ezkl import os from torch import nn import xgboost as xgb from humm...
https://github.com/zkonduit/ezkl
jest.config.js
module.exports = { preset: 'ts-jest', testEnvironment: 'node', };
https://github.com/zkonduit/ezkl
src/bin/ezkl.rs
// ignore file if compiling for wasm #[cfg(not(target_arch = "wasm32"))] use clap::Parser; #[cfg(not(target_arch = "wasm32"))] use colored_json::ToColoredJson; #[cfg(not(target_arch = "wasm32"))] use ezkl::commands::Cli; #[cfg(not(target_arch = "wasm32"))] use ezkl::execute::run; #[cfg(not(target_arch = "wasm32"))] us...
https://github.com/zkonduit/ezkl
src/circuit/mod.rs
/// pub mod modules; /// pub mod table; /// pub mod utils; /// pub mod ops; pub use ops::chip::*; pub use ops::*; /// Tests #[cfg(test)] mod tests;
https://github.com/zkonduit/ezkl
src/circuit/modules/mod.rs
/// pub mod poseidon; /// pub mod polycommit; /// pub mod planner; use halo2_proofs::{ circuit::Layouter, plonk::{ConstraintSystem, Error}, }; use halo2curves::ff::PrimeField; pub use planner::*; use crate::tensor::{TensorType, ValTensor}; use super::region::ConstantsMap; /// Module trait used to extend ez...
https://github.com/zkonduit/ezkl
src/circuit/modules/planner.rs
use std::cmp; use std::collections::HashMap; use std::fmt; use std::marker::PhantomData; use halo2curves::ff::Field; use halo2_proofs::{ circuit::{ layouter::{RegionColumn, RegionLayouter, RegionShape, SyncDeps, TableLayouter}, Cell, Layouter, Region, RegionIndex, RegionStart, Table, Value, },...
https://github.com/zkonduit/ezkl
src/circuit/modules/polycommit.rs
/* An easy-to-use implementation of the Poseidon Hash in the form of a Halo2 Chip. While the Poseidon Hash function is already implemented in halo2_gadgets, there is no wrapper chip that makes it easy to use in other circuits. Thanks to https://github.com/summa-dev/summa-solvency/blob/master/src/chips/poseidon/hash.rs ...
https://github.com/zkonduit/ezkl
src/circuit/modules/poseidon.rs
/* An easy-to-use implementation of the Poseidon Hash in the form of a Halo2 Chip. While the Poseidon Hash function is already implemented in halo2_gadgets, there is no wrapper chip that makes it easy to use in other circuits. Thanks to https://github.com/summa-dev/summa-solvency/blob/master/src/chips/poseidon/hash.rs ...
https://github.com/zkonduit/ezkl
src/circuit/modules/poseidon/poseidon_params.rs
//! This file was generated by running generate_params.py //! Number of round constants: 340 //! Round constants for GF(p): //! Parameters for using rate 4 Poseidon with the BN256 field. //! The parameters can be reproduced by running the following Sage script from //! [this repository](https://github.com/daira/pasta-h...
https://github.com/zkonduit/ezkl
src/circuit/modules/poseidon/spec.rs
//! This file was generated by running generate_params.py //! Specification for rate 5 Poseidon using the BN256 curve. //! Patterned after [halo2_gadgets::poseidon::primitives::P128Pow5T3] use halo2_gadgets::poseidon::primitives::*; use halo2_proofs::arithmetic::Field; use halo2_proofs::halo2curves::bn256::Fr as Fp; u...
https://github.com/zkonduit/ezkl
src/circuit/ops/base.rs
use crate::tensor::TensorType; use std::{ fmt, ops::{Add, Mul, Neg, Sub}, }; #[allow(missing_docs)] /// An enum representing the operations that can be used to express more complex operations via accumulation #[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub enum BaseOp { Dot, DotInit, ...
https://github.com/zkonduit/ezkl
src/circuit/ops/chip.rs
use std::str::FromStr; use thiserror::Error; use halo2_proofs::{ circuit::Layouter, plonk::{ConstraintSystem, Constraints, Expression, Selector}, poly::Rotation, }; use log::debug; #[cfg(feature = "python-bindings")] use pyo3::{ conversion::{FromPyObject, PyTryFrom}, exceptions::PyValueError, ...
https://github.com/zkonduit/ezkl
src/circuit/ops/hybrid.rs
use super::*; use crate::{ circuit::{layouts, utils, Tolerance}, fieldutils::i128_to_felt, graph::multiplier_to_scale, tensor::{self, Tensor, TensorType, ValTensor}, }; use halo2curves::ff::PrimeField; use serde::{Deserialize, Serialize}; // import run args from model #[allow(missing_docs)] /// An enum...
https://github.com/zkonduit/ezkl
src/circuit/ops/layouts.rs
use std::{ collections::{HashMap, HashSet}, error::Error, ops::Range, }; use halo2_proofs::circuit::Value; use halo2curves::ff::PrimeField; use itertools::Itertools; use log::{error, trace}; use maybe_rayon::{ iter::IntoParallelRefIterator, prelude::{IndexedParallelIterator, IntoParallelIterator, P...
https://github.com/zkonduit/ezkl
src/circuit/ops/lookup.rs
use super::*; use serde::{Deserialize, Serialize}; use std::error::Error; use crate::{ circuit::{layouts, table::Range, utils}, fieldutils::{felt_to_i128, i128_to_felt}, graph::multiplier_to_scale, tensor::{self, Tensor, TensorError, TensorType}, }; use super::Op; use halo2curves::ff::PrimeField; #[a...
https://github.com/zkonduit/ezkl
src/circuit/ops/mod.rs
use std::{any::Any, error::Error}; use serde::{Deserialize, Serialize}; use crate::{ graph::quantize_tensor, tensor::{self, Tensor, TensorType, ValTensor}, }; use halo2curves::ff::PrimeField; use self::{lookup::LookupOp, region::RegionCtx}; /// pub mod base; /// pub mod chip; /// pub mod hybrid; /// Layouts...
https://github.com/zkonduit/ezkl
src/circuit/ops/poly.rs
use crate::{ circuit::layouts, tensor::{self, Tensor, TensorError}, }; use super::{base::BaseOp, *}; #[allow(missing_docs)] /// An enum representing the operations that can be expressed as arithmetic (non lookup) operations. #[derive(Clone, Debug, Serialize, Deserialize)] pub enum PolyOp { GatherElements ...
https://github.com/zkonduit/ezkl
src/circuit/ops/region.rs
use crate::{ circuit::table::Range, tensor::{Tensor, TensorError, TensorType, ValTensor, ValType, VarTensor}, }; #[cfg(not(target_arch = "wasm32"))] use colored::Colorize; use halo2_proofs::{ circuit::Region, plonk::{Error, Selector}, }; use halo2curves::ff::PrimeField; use portable_atomic::AtomicI128 a...
https://github.com/zkonduit/ezkl
src/circuit/table.rs
use std::{error::Error, marker::PhantomData}; use halo2curves::ff::PrimeField; use halo2_proofs::{ circuit::{Layouter, Value}, plonk::{ConstraintSystem, Expression, TableColumn}, }; use log::{debug, warn}; use maybe_rayon::prelude::{IntoParallelIterator, ParallelIterator}; use crate::{ circuit::CircuitEr...
https://github.com/zkonduit/ezkl
src/circuit/tests.rs
use crate::circuit::ops::poly::PolyOp; use crate::circuit::*; use crate::tensor::{Tensor, TensorType, ValTensor, VarTensor}; use halo2_proofs::{ circuit::{Layouter, SimpleFloorPlanner, Value}, dev::MockProver, plonk::{Circuit, ConstraintSystem, Error}, }; use halo2curves::bn256::Fr as F; use halo2curves::ff...
https://github.com/zkonduit/ezkl
src/circuit/utils.rs
use serde::{Deserialize, Serialize}; // -------------------------------------------------------------------------------------------- // // Float Utils to enable the usage of f32s as the keys of HashMaps // This section is taken from the `eq_float` crate verbatim -- but we also implement deserialization methods // // ...
https://github.com/zkonduit/ezkl
src/commands.rs
use clap::{Parser, Subcommand}; #[cfg(not(target_arch = "wasm32"))] use ethers::types::H160; #[cfg(feature = "python-bindings")] use pyo3::{ conversion::{FromPyObject, PyTryFrom}, exceptions::PyValueError, prelude::*, types::PyString, }; use serde::{Deserialize, Serialize}; use std::path::PathBuf; use s...
https://github.com/zkonduit/ezkl
src/eth.rs
use crate::graph::input::{CallsToAccount, FileSourceInner, GraphData}; use crate::graph::modules::POSEIDON_INSTANCES; use crate::graph::DataSource; #[cfg(not(target_arch = "wasm32"))] use crate::graph::GraphSettings; use crate::pfsys::evm::EvmVerificationError; use crate::pfsys::Snark; use ethers::abi::Contract; use et...
https://github.com/zkonduit/ezkl
src/execute.rs
use crate::circuit::CheckMode; #[cfg(not(target_arch = "wasm32"))] use crate::commands::CalibrationTarget; use crate::commands::Commands; #[cfg(not(target_arch = "wasm32"))] use crate::commands::H160Flag; #[cfg(not(target_arch = "wasm32"))] use crate::eth::{deploy_contract_via_solidity, deploy_da_verifier_via_solidity}...
https://github.com/zkonduit/ezkl
src/fieldutils.rs
use halo2_proofs::arithmetic::Field; /// Utilities for converting from Halo2 PrimeField types to integers (and vice-versa). use halo2curves::ff::PrimeField; /// Converts an i32 to a PrimeField element. pub fn i32_to_felt<F: PrimeField>(x: i32) -> F { if x >= 0 { F::from(x as u64) } else { -F::f...
https://github.com/zkonduit/ezkl
src/graph/input.rs
use super::quantize_float; use super::GraphError; use crate::circuit::InputType; use crate::fieldutils::i128_to_felt; #[cfg(not(target_arch = "wasm32"))] use crate::tensor::Tensor; use crate::EZKL_BUF_CAPACITY; use halo2curves::bn256::Fr as Fp; #[cfg(not(target_arch = "wasm32"))] use postgres::{Client, NoTls}; #[cfg(fe...
https://github.com/zkonduit/ezkl
src/graph/mod.rs
/// Representations of a computational graph's inputs. pub mod input; /// Crate for defining a computational graph and building a ZK-circuit from it. pub mod model; /// Representations of a computational graph's modules. pub mod modules; /// Inner elements of a computational graph that represent a single operation / co...
https://github.com/zkonduit/ezkl
src/graph/model.rs
use super::extract_const_quantized_values; use super::node::*; use super::scale_to_multiplier; use super::vars::*; use super::GraphError; use super::GraphSettings; use crate::circuit::hybrid::HybridOp; use crate::circuit::region::ConstantsMap; use crate::circuit::region::RegionCtx; use crate::circuit::table::Range; use...
https://github.com/zkonduit/ezkl
src/graph/modules.rs
use crate::circuit::modules::polycommit::{PolyCommitChip, PolyCommitConfig}; use crate::circuit::modules::poseidon::spec::{PoseidonSpec, POSEIDON_RATE, POSEIDON_WIDTH}; use crate::circuit::modules::poseidon::{PoseidonChip, PoseidonConfig}; use crate::circuit::modules::Module; use crate::circuit::region::ConstantsMap; u...
https://github.com/zkonduit/ezkl
src/graph/node.rs
use super::scale_to_multiplier; #[cfg(not(target_arch = "wasm32"))] use super::utilities::node_output_shapes; #[cfg(not(target_arch = "wasm32"))] use super::VarScales; #[cfg(not(target_arch = "wasm32"))] use super::Visibility; use crate::circuit::hybrid::HybridOp; use crate::circuit::lookup::LookupOp; use crate::circui...
https://github.com/zkonduit/ezkl
src/graph/utilities.rs
#[cfg(not(target_arch = "wasm32"))] use super::GraphError; #[cfg(not(target_arch = "wasm32"))] use super::VarScales; use super::{Rescaled, SupportedOp, Visibility}; #[cfg(not(target_arch = "wasm32"))] use crate::circuit::hybrid::HybridOp; #[cfg(not(target_arch = "wasm32"))] use crate::circuit::lookup::LookupOp; #[cfg(n...
https://github.com/zkonduit/ezkl
src/graph/vars.rs
use std::error::Error; use std::fmt::Display; use crate::tensor::TensorType; use crate::tensor::{ValTensor, VarTensor}; use crate::RunArgs; use halo2_proofs::plonk::{Column, ConstraintSystem, Instance}; use halo2curves::ff::PrimeField; use itertools::Itertools; use log::debug; #[cfg(feature = "python-bindings")] use p...
https://github.com/zkonduit/ezkl
src/lib.rs
#![deny( bad_style, dead_code, improper_ctypes, non_shorthand_field_patterns, no_mangle_generic_items, overflowing_literals, path_statements, patterns_in_fns_without_body, unconditional_recursion, unused, unused_allocation, unused_comparisons, unused_parens, while...
https://github.com/zkonduit/ezkl
src/logger.rs
use colored::*; use env_logger::Builder; use log::{Level, LevelFilter, Record}; use std::env; use std::fmt::Formatter; use std::io::Write; /// sets the log level color #[allow(dead_code)] pub fn level_color(level: &log::Level, msg: &str) -> String { match level { Level::Error => msg.red(), Level::W...
https://github.com/zkonduit/ezkl