Uh oh!
There was an error while loading. Please reload this page.
Add linear_combination to BasicAPI for wide linear layers - #205
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces two new binaries: expander-mlp-gen for generating GKR circuits and witnesses for quantized linear MLPs, and transformer_bench for benchmarking GPU transformer proofs. It also adds a new linear_combination API to BasicAPI and Builder to optimize wide linear layers by emitting a single LinComb instruction, significantly reducing memory usage and instruction count. The review feedback highlights a potential signed overflow panic in i64_to_cf when handling i64::MIN, suggests avoiding unnecessary vector clones in set_all_layers by destructuring, and recommends optimizing the fallback linear_combination implementation by skipping zero-coefficient terms.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…linear layers Adds linear_combination(terms, constant) to BasicAPI<C> with a default fallback using repeated mul+add and an optimized Builder<C> override that emits a single LinComb instruction per output neuron. Repeated mul+add causes the optimizer to expand expressions quadratically with layer width, leading to very high peak memory for circuits with dense linear layers (n_in > 64). The LinComb instruction keeps instruction count O(1) per output neuron and avoids the blowup. Also adds transformer_bench and expander-mlp-gen binaries demonstrating use of linear_combination for multi-layer MLP and transformer circuits. Includes equivalence tests verifying linear_combination matches mul+add semantics and that invalid Variable(0) panics correctly. Also fixes pre-existing clippy lints in api.rs: unused import, unused variable, needless &ref patterns, useless as_ref, redundant format args.
19dd0fe to
1f0370bCompare
Building
Σ w_i * x_iwith chainedapi.mul+api.addgrows thePool<Expression<C>>accumulator by one term per weight. PastCOMPRESS_THRESHOLDthe optimizer starts cascading intermediate variables at ~48 bytes each, so a 3072→1024 dense layer can hit tens of GB of RSS duringcompile_to_layered.linear_combination(&[(Variable, F)], constant)emits a singleLinCombinstruction in O(1) per output neuron and avoids the expression accumulator entirely. Keeps the existing invalid-Variable(0)check viaensure_variable_validon each input.On a 784→512→128→10 MLP (1.47M constraints) the peak goes from ~70 GB to ~1.1 GB.