-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from zkonduit/runs
feat: run through the benchmarks 10 times.
- Loading branch information
Showing
24 changed files
with
1,049 additions
and
739 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "te_regression" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
# If you want to try (experimental) std support, add `features = [ "std" ]` to risc0-zkvm | ||
risc0-zkvm = { version = "0.19.1", default-features = false, features = [ | ||
"std", | ||
] } | ||
# Using git dependency as a workaround for https://github.com/smartcorelib/smartcore/issues/267 | ||
smartcore = { git = "https://github.com/risc0/smartcore.git", rev = "4bd3cadd50ed988c45c239f5264c3e2c2af0a690", features = ["serde"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2023 RISC Zero, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#![no_main] | ||
|
||
use risc0_zkvm::guest::env; | ||
use smartcore::{ensemble::random_forest_regressor::*, linalg::basic::matrix::DenseMatrix}; | ||
|
||
risc0_zkvm::guest::entry!(main); | ||
|
||
pub fn main() { | ||
// Read the model from the host into a SmartCore Decesion Tree model object. | ||
// We MUST explicitly declare the correct type in order for deserialization to be | ||
// successful. | ||
type Model = RandomForestRegressor<f64, u32, DenseMatrix<f64>, Vec<u32>>; | ||
let trained_model: Model = env::read(); | ||
|
||
// Read the input data into a DenseMatrix. | ||
let x_data: DenseMatrix<f64> = env::read(); | ||
|
||
// We call the predict() function on our trained model to perform inference. | ||
let y_hat = trained_model.predict(&x_data).unwrap(); | ||
|
||
// This line is optional and can be commented out, but it's useful to see | ||
// the output of the computation before the proving step begins. | ||
println!("answer: {:?}", &y_hat); | ||
|
||
// We commit the output to the journal. | ||
env::commit(&y_hat); | ||
|
||
// Logging the total cycle count is optional, though it's quite useful for benchmarking | ||
// the various operations in the guest code. env::get_cycle_count() can be | ||
// called anywhere in the guest, multiple times. So if we are interested in | ||
// knowing how many cycles the inference computation takes, we can calculate | ||
// total cycles before and after model.predict() and the difference between | ||
// the two values equals the total cycle count for that section of the guest | ||
// code. | ||
println!( | ||
"Total cycles for guest code execution: {}", | ||
env::get_cycle_count() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.