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

feat: configure ModelCircuit with params #208

Merged
merged 6 commits into from
Apr 27, 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ render = ["halo2_proofs/dev-graph", "plotters"]
tensorflow = ["dep:tensorflow"]
onnx = ["dep:tract-onnx"]
python-bindings = ["pyo3", "pyo3-log"]
ezkl = ["onnx", "serde", "serde_json", "log", "colored", "env_logger", "tabled", "colored_json"]
ezkl = ["onnx", "serde", "serde_json", "log", "colored", "env_logger", "tabled", "colored_json", "halo2_proofs/circuit-params"]
1 change: 1 addition & 0 deletions benches/accum_conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct MyCircuit {
impl Circuit<Fr> for MyCircuit {
type Config = BaseConfig<Fr>;
type FloorPlanner = SimpleFloorPlanner;
type Params = ();

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down
1 change: 1 addition & 0 deletions benches/accum_dot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct MyCircuit {
impl Circuit<Fr> for MyCircuit {
type Config = BaseConfig<Fr>;
type FloorPlanner = SimpleFloorPlanner;
type Params = ();

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down
1 change: 1 addition & 0 deletions benches/accum_matmul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct MyCircuit {
impl Circuit<Fr> for MyCircuit {
type Config = BaseConfig<Fr>;
type FloorPlanner = SimpleFloorPlanner;
type Params = ();

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down
1 change: 1 addition & 0 deletions benches/accum_matmul_relu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct MyConfig {
impl Circuit<Fr> for MyCircuit {
type Config = MyConfig;
type FloorPlanner = SimpleFloorPlanner;
type Params = ();

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down
1 change: 1 addition & 0 deletions benches/accum_pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct MyCircuit {
impl Circuit<Fr> for MyCircuit {
type Config = BaseConfig<Fr>;
type FloorPlanner = SimpleFloorPlanner;
type Params = ();

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down
1 change: 1 addition & 0 deletions benches/accum_sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct MyCircuit {
impl Circuit<Fr> for MyCircuit {
type Config = BaseConfig<Fr>;
type FloorPlanner = SimpleFloorPlanner;
type Params = ();

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down
1 change: 1 addition & 0 deletions benches/accum_sumpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct MyCircuit {
impl Circuit<Fr> for MyCircuit {
type Config = BaseConfig<Fr>;
type FloorPlanner = SimpleFloorPlanner;
type Params = ();

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down
1 change: 1 addition & 0 deletions benches/pairwise_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct MyCircuit {
impl Circuit<Fr> for MyCircuit {
type Config = BaseConfig<Fr>;
type FloorPlanner = SimpleFloorPlanner;
type Params = ();

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down
1 change: 1 addition & 0 deletions benches/pairwise_pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct MyCircuit {
impl Circuit<Fr> for MyCircuit {
type Config = BaseConfig<Fr>;
type FloorPlanner = SimpleFloorPlanner;
type Params = ();

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down
1 change: 1 addition & 0 deletions benches/relu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct NLCircuit {
impl Circuit<Fr> for NLCircuit {
type Config = Config<Fr>;
type FloorPlanner = SimpleFloorPlanner;
type Params = ();

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down
2 changes: 2 additions & 0 deletions examples/conv2d_mnist/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use halo2curves::pasta::vesta;
use halo2curves::pasta::Fp as F;
use mnist::*;
use rand::rngs::OsRng;
use std::marker::PhantomData;
use std::time::Instant;

mod params;
Expand Down Expand Up @@ -131,6 +132,7 @@ where
PADDING,
>;
type FloorPlanner = SimpleFloorPlanner;
type Params = PhantomData<F>;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down
1 change: 1 addition & 0 deletions examples/mlp_4d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl<F: PrimeField + TensorType + PartialOrd, const LEN: usize, const BITS: usiz
{
type Config = MyConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = PhantomData<F>;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down
12 changes: 6 additions & 6 deletions src/circuit/ops/layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ pub fn sum_axes<F: PrimeField + TensorType + PartialOrd>(
}

/// Max accumulated layout
pub fn max_axes<F: PrimeField + TensorType + PartialOrd + PartialOrd>(
pub fn max_axes<F: PrimeField + TensorType + PartialOrd>(
config: &mut BaseConfig<F>,
region: &mut Option<&mut Region<F>>,
values: &[ValTensor<F>; 1],
Expand Down Expand Up @@ -369,7 +369,7 @@ pub fn max_axes<F: PrimeField + TensorType + PartialOrd + PartialOrd>(
}

/// Min accumulated layout
pub fn min_axes<F: PrimeField + TensorType + PartialOrd + PartialOrd>(
pub fn min_axes<F: PrimeField + TensorType + PartialOrd>(
config: &mut BaseConfig<F>,
region: &mut Option<&mut Region<F>>,
values: &[ValTensor<F>; 1],
Expand Down Expand Up @@ -622,7 +622,7 @@ pub fn matmul<F: PrimeField + TensorType + PartialOrd>(
}

/// Iff
pub fn iff<F: PrimeField + TensorType + PartialOrd + PartialOrd>(
pub fn iff<F: PrimeField + TensorType + PartialOrd>(
config: &mut BaseConfig<F>,
region: &mut Option<&mut Region<F>>,
values: &[ValTensor<F>; 3],
Expand Down Expand Up @@ -792,7 +792,7 @@ pub fn sumpool<F: PrimeField + TensorType + PartialOrd>(
}

/// Convolution accumulated layout
pub fn max_pool2d<F: PrimeField + TensorType + PartialOrd + PartialOrd>(
pub fn max_pool2d<F: PrimeField + TensorType + PartialOrd>(
config: &mut BaseConfig<F>,
region: &mut Option<&mut Region<F>>,
values: &[ValTensor<F>; 1],
Expand Down Expand Up @@ -1294,7 +1294,7 @@ pub fn mean<F: PrimeField + TensorType + PartialOrd>(
}

/// max layout
pub fn max<F: PrimeField + TensorType + PartialOrd + PartialOrd>(
pub fn max<F: PrimeField + TensorType + PartialOrd>(
config: &mut BaseConfig<F>,
region: &mut Option<&mut Region<F>>,
values: &[ValTensor<F>; 1],
Expand Down Expand Up @@ -1408,7 +1408,7 @@ pub fn max<F: PrimeField + TensorType + PartialOrd + PartialOrd>(
}

/// min layout
pub fn min<F: PrimeField + TensorType + PartialOrd + PartialOrd>(
pub fn min<F: PrimeField + TensorType + PartialOrd>(
config: &mut BaseConfig<F>,
region: &mut Option<&mut Region<F>>,
values: &[ValTensor<F>; 1],
Expand Down
23 changes: 23 additions & 0 deletions src/circuit/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ use halo2curves::pasta::Fp as F;
use rand::rngs::OsRng;
use std::marker::PhantomData;

#[derive(Default)]
struct TestParams;

#[cfg(test)]
mod matmul {

Expand All @@ -28,6 +31,7 @@ mod matmul {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for MatmulCircuit<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down Expand Up @@ -101,6 +105,7 @@ mod matmul_col_overflow {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for MatmulCircuit<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down Expand Up @@ -174,6 +179,7 @@ mod dot {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for MyCircuit<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down Expand Up @@ -244,6 +250,7 @@ mod dot_col_overflow {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for MyCircuit<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down Expand Up @@ -314,6 +321,7 @@ mod sum {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for MyCircuit<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down Expand Up @@ -382,6 +390,7 @@ mod sum_col_overflow {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for MyCircuit<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down Expand Up @@ -450,6 +459,7 @@ mod composition {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for MyCircuit<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down Expand Up @@ -539,6 +549,7 @@ mod conv {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for ConvCircuit<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down Expand Up @@ -665,6 +676,7 @@ mod sumpool {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for ConvCircuit<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down Expand Up @@ -743,6 +755,7 @@ mod add_w_shape_casting {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for MyCircuit<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down Expand Up @@ -813,6 +826,7 @@ mod add {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for MyCircuit<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down Expand Up @@ -883,6 +897,7 @@ mod add_with_overflow {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for MyCircuit<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down Expand Up @@ -953,6 +968,7 @@ mod sub {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for MyCircuit<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down Expand Up @@ -1023,6 +1039,7 @@ mod mult {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for MyCircuit<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down Expand Up @@ -1093,6 +1110,7 @@ mod pow {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for MyCircuit<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down Expand Up @@ -1161,6 +1179,7 @@ mod pack {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for MyCircuit<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down Expand Up @@ -1229,6 +1248,7 @@ mod rescaled {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for MyCircuit<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down Expand Up @@ -1308,6 +1328,7 @@ mod matmul_relu {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for MyCircuit<F> {
type Config = MyConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down Expand Up @@ -1411,6 +1432,7 @@ mod rangecheck {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for MyCircuit<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down Expand Up @@ -1503,6 +1525,7 @@ mod relu {
impl<F: PrimeField + TensorType + PartialOrd> Circuit<F> for ReLUCircuit<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = TestParams;

fn without_witnesses(&self) -> Self {
self.clone()
Expand Down
2 changes: 1 addition & 1 deletion src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl std::fmt::Display for StrategyType {
}

/// Parameters specific to a proving run
#[derive(Debug, Args, Deserialize, Serialize, Clone)]
#[derive(Debug, Args, Deserialize, Serialize, Clone, Default)]
pub struct RunArgs {
/// The tolerance for error on model outputs
#[arg(short = 'T', long, default_value = "0")]
Expand Down
Loading