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

bench: instrument hash counts for verifier #19

Merged
merged 40 commits into from
May 27, 2024

Conversation

jonathanpwang
Copy link
Contributor

@jonathanpwang jonathanpwang commented May 15, 2024

I was able to find a way to do this without forking Plonky3. The two traits that need to be implemented for PCS hashes are PseudoCompressionFunction and CryptographicHasher. I make a wrapper struct Instrumented that does the normal operation and also updates the counter. For logging / debugging purposes, I store the lengths of inputs by the input type using type_name. To translate into actual counts, some specific logic about the absorb rate, etc of the specific hash (currently poseidon2) are used.

Notes:

  • CryptographicHasher is for flat hashing long arrays of inputs. I think this is mostly used on the merkle leaf.
  • PseudoCompressionFunction is what is used on the other layers of merkle tree, since it's designed so 2-to-1 hashes have same input and output shape.

What is currently benchmarked: given a matrix with height rows and field_width + 1 columns, we make two AIRs:

  1. Just one big trace matrix, and with a receive interaction (this adds 2 virtual columns and gates for logup partial sum) where the receive is on the vector of field_width with count the column 0 value.
  2. Treat the height-by-field_width matrix as a cached trace, so it is committed to separately. The count matrix that is height-by-1 is a separate matrix that is committed.

We run both of these and log the hashes used, where we count based on the number of Poseidon2 permutations done.

  • Add output to a csv so we can just on a bunch and post-process in spreadsheet
  • Modify bench to time stages of proving. This should not be instrumented because the counter is pretty slow.
  • Instrument challenger -- this is where grinding is done

jonathanpwang and others added 22 commits May 9, 2024 20:15
Merge branch 'main' into feat/main_trace_parts
* feat: add backend readme

* fix: link

* fix: link

* fix: latex

* chore: fix typo

* chore: add code references

---------

Co-authored-by: Yi Sun <yi-sun@users.noreply.github.com>
No need for tracing on non-benchmark tests
* fix: `eval_permutation_constraints` must handle partitioned_main

* feat: integration test with cached trace

* fix: forgot to add test files

* chore: rename folder to `partitioned_sum_air`

* chore: add test utils module

* feat: add indexless cached lookup test for partitioned Air with interactions

* chore: fix typo

* feat: `add_main_matrix(width)` placeholder with mat width

* chore: switch from RefCell to Arc Mutex
@jonathanpwang
Copy link
Contributor Author

jonathanpwang commented May 15, 2024

Some preliminary stats:

log_blowup_factor: 3, num_queries: 33, proof_of_work_bits: 16
Field width: 1, height: 65536 = 1 << 16
Without cached trace:
Hash: (p3_baby_bear::baby_bear::BabyBear, [p3_baby_bear::baby_bear::BabyBear; 8]), Count: 627
Compress: [p3_baby_bear::baby_bear::BabyBear; 8], Count: 7425
Total Count: 8052
With cached trace:
Hash: (p3_baby_bear::baby_bear::BabyBear, [p3_baby_bear::baby_bear::BabyBear; 8]), Count: 660
Compress: [p3_baby_bear::baby_bear::BabyBear; 8], Count: 8052
Total Count: 8712
(Difference in total count: 660)


Field width: 1, height: 1048576 = 1 << 20
Without cached trace:
Hash: (p3_baby_bear::baby_bear::BabyBear, [p3_baby_bear::baby_bear::BabyBear; 8]), Count: 759
Compress: [p3_baby_bear::baby_bear::BabyBear; 8], Count: 10527
Total Count: 11286
With cached trace:
test cached_lookup::instrumented::bench_cached_trace has been running for over 60 seconds
Hash: (p3_baby_bear::baby_bear::BabyBear, [p3_baby_bear::baby_bear::BabyBear; 8]), Count: 792
Compress: [p3_baby_bear::baby_bear::BabyBear; 8], Count: 11286
Total Count: 12078
(Difference in total count: 792)

@jonathanpwang jonathanpwang requested a review from yi-sun May 15, 2024 15:46
@yi-sun
Copy link
Collaborator

yi-sun commented May 15, 2024

To confirm, in case 2, is the logUp still done?

@jonathanpwang jonathanpwang force-pushed the feat/instrument_benches branch from 4467ed8 to 8163e1c Compare May 15, 2024 17:34
@jonathanpwang
Copy link
Contributor Author

jonathanpwang commented May 15, 2024

To confirm, in case 2, is the logUp still done?

In both cases, the logUp is exactly the same: same 2 virtual columns, same constraints. The logUp treats the main trace as one big matrix, and doesn't care about the partition.

@yi-sun
Copy link
Collaborator

yi-sun commented May 15, 2024

Great, I think that's the correct relevant comparison

Base automatically changed from feat/main_trace_parts to main May 16, 2024 00:13
@jonathanpwang
Copy link
Contributor Author

@jonathanpwang jonathanpwang marked this pull request as ready for review May 16, 2024 04:49
@yi-sun yi-sun requested a review from nyunyunyunyu May 16, 2024 19:21
* fix: p3-maybe-rayon `parallel` feature was not on

feature is `parallel` not `rayon`

* chore: simplify code
Moved `run_simple_test` into `config::baby_bear_poseidon2` because it
depends on the engine
@jonathanpwang
Copy link
Contributor Author

@OsamaAlkhodairy FYI I'm going to merge this one.

I added some stuff to test-utils/src/config to start some tooling. I added a StarkEngine trait with the idea we can make a different engine for each field x hash combo. I moved your run_simple_test function to config::baby_bear_poseidon2 because the test depends on the choice of field (babybear) and hash (poseidon2), so I added it both as a function in StarkEngine trait but also it's still nice to have the do-it-all command you had before, so I simply moved its location.

@jonathanpwang jonathanpwang merged commit cc56990 into main May 27, 2024
4 checks passed
@jonathanpwang jonathanpwang deleted the feat/instrument_benches branch May 27, 2024 19:57
luffykai pushed a commit that referenced this pull request Dec 13, 2024
* wip: refactor to use commit pointers

* wip: permutation trace from partitioned main

* wip: fix previous rebase

* wip: show new interface

* chore: rename ChipsetProver to MultiTraceStarkProver

* feat: quotient refactor done

* feat: prover done

* chore: split out prove function into general post-trace part

* feat: finished verifier

* feat: keygen builder

* chore: move fib triple test into same file

* feat: preliminary docs on STARK backend scope/support (#16)

* feat: add backend readme

* fix: link

* fix: link

* fix: latex

* chore: fix typo

* chore: add code references

---------

Co-authored-by: Yi Sun <yi-sun@users.noreply.github.com>

* chore: make DebugBuilder `after_challenge` consistent with other builders

* chore: clean up if statement

* chore: fix fmt

* chore: fix previous merge and remove tracing

No need for tracing on non-benchmark tests

* chore: fix lint

* feat: Partitioned Air Builder (#17)

* fix: `eval_permutation_constraints` must handle partitioned_main

* feat: integration test with cached trace

* fix: forgot to add test files

* chore: rename folder to `partitioned_sum_air`

* chore: add test utils module

* feat: add indexless cached lookup test for partitioned Air with interactions

* chore: fix typo

* feat: `add_main_matrix(width)` placeholder with mat width

* chore: switch from RefCell to Arc Mutex

* chore: address review comment

* chore: rename `MatrixCommitmentPointers`

* feat: add instrumented hash/compress

* chore: return instrument counters since fields are private

* feat: prelim verifier instrumentation

* feat: full benchmark writing to csv

* chore: turn off instrumenting during proving

* fix: instrument not properly on

* fix: flush writer

* chore: clean up config module

* chore(chips): remove old test config module

* feat: add `StarkEngine` for convenience

* feat: add cached_lookup prover benchmark

* fix: p3-maybe-rayon `parallel` feature was not on (#28)

* fix: p3-maybe-rayon `parallel` feature was not on

feature is `parallel` not `rayon`

* chore: simplify code

---------

Co-authored-by: Yi Sun <yi-sun@users.noreply.github.com>
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