Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-camuto committed Oct 28, 2024
1 parent ca2adfe commit 81ebdf9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
17 changes: 16 additions & 1 deletion examples/conv2d_mnist/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ where
let params = VarTensor::new_advice(cs, K, NUM_INNER_COLS, LEN);
let output = VarTensor::new_advice(cs, K, NUM_INNER_COLS, LEN);

let _constant = VarTensor::constant_cols(cs, K, LEN, false);

println!("INPUT COL {:#?}", input);

let mut layer_config = PolyConfig::configure(
Expand All @@ -155,6 +157,14 @@ where
CheckMode::SAFE,
);

layer_config
.configure_range_check(cs, &input, &params, (-1, 1), K)
.unwrap();

layer_config
.configure_range_check(cs, &input, &params, (0, 1023), K)
.unwrap();

layer_config
.configure_lookup(
cs,
Expand Down Expand Up @@ -183,6 +193,11 @@ where
) -> Result<(), Error> {
config.layer_config.layout_tables(&mut layouter).unwrap();

config
.layer_config
.layout_range_checks(&mut layouter)
.unwrap();

let x = layouter
.assign_region(
|| "mlp_4d",
Expand Down Expand Up @@ -213,8 +228,8 @@ where
&mut region,
&[x.unwrap()],
Box::new(PolyOp::LeakyReLU {
scale: 1,
slope: 0.0.into(),
scale: 1,
}),
)
.unwrap();
Expand Down
17 changes: 17 additions & 0 deletions examples/mlp_4d_einsum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,25 @@ impl<const LEN: usize, const LOOKUP_MIN: IntegerRep, const LOOKUP_MAX: IntegerRe
let output = VarTensor::new_advice(cs, K, 1, LEN);
// tells the config layer to add an affine op to the circuit gate

let _constant = VarTensor::constant_cols(cs, K, LEN, false);

println!("INPUT COL {:#?}", input);

let mut layer_config = PolyConfig::<F>::configure(
cs,
&[input.clone(), params.clone()],
&output,
CheckMode::SAFE,
);

layer_config
.configure_range_check(cs, &input, &params, (-1, 1), K)
.unwrap();

layer_config
.configure_range_check(cs, &input, &params, (0, 1023), K)
.unwrap();

// sets up a new ReLU table and resuses it for l1 and l3 non linearities
layer_config
.configure_lookup(
Expand Down Expand Up @@ -91,6 +103,11 @@ impl<const LEN: usize, const LOOKUP_MIN: IntegerRep, const LOOKUP_MAX: IntegerRe
) -> Result<(), Error> {
config.layer_config.layout_tables(&mut layouter).unwrap();

config
.layer_config
.layout_range_checks(&mut layouter)
.unwrap();

let x = layouter
.assign_region(
|| "mlp_4d",
Expand Down
Binary file modified tests/assets/model.compiled
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/assets/witness.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"inputs":[["0200000000000000000000000000000000000000000000000000000000000000","0100000000000000000000000000000000000000000000000000000000000000","0100000000000000000000000000000000000000000000000000000000000000"]],"pretty_elements":{"rescaled_inputs":[["2","1","1"]],"inputs":[["0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000001"]],"processed_inputs":[],"processed_params":[],"processed_outputs":[],"rescaled_outputs":[["0","0","0","0"]],"outputs":[["0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"]]},"outputs":[["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000"]],"processed_inputs":null,"processed_params":null,"processed_outputs":null,"max_lookup_inputs":0,"min_lookup_inputs":0,"max_range_size":127}
{"inputs":[["0200000000000000000000000000000000000000000000000000000000000000","0100000000000000000000000000000000000000000000000000000000000000","0100000000000000000000000000000000000000000000000000000000000000"]],"pretty_elements":{"rescaled_inputs":[["2","1","1"]],"inputs":[["0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000001"]],"processed_inputs":[],"processed_params":[],"processed_outputs":[],"rescaled_outputs":[["1","0","1","0"]],"outputs":[["0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000000"]]},"outputs":[["0100000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0100000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000"]],"processed_inputs":null,"processed_params":null,"processed_outputs":null,"max_lookup_inputs":0,"min_lookup_inputs":0,"max_range_size":127}

0 comments on commit 81ebdf9

Please sign in to comment.