mirror of
https://github.com/MPCStats/zk-stats-lib.git
synced 2026-01-09 05:27:57 -05:00
ezkl 7.0.0, refine median + mode
This commit is contained in:
29
bench.py
29
bench.py
@@ -71,13 +71,13 @@ def gen_settings(comb_data_path, onnx_filename, scale, mode, settings_filename):
|
||||
|
||||
# Here prover can concurrently call this since all params are public to get pk.
|
||||
# Here write as verifier function to emphasize that verifier must calculate its own vk to be sure
|
||||
def verifier_setup(verifier_model_path, verifier_compiled_model_path, settings_path, srs_path,vk_path, pk_path ):
|
||||
def verifier_setup(verifier_model_path, verifier_compiled_model_path, settings_path,vk_path, pk_path ):
|
||||
# compile circuit
|
||||
res = ezkl.compile_circuit(verifier_model_path, verifier_compiled_model_path, settings_path)
|
||||
assert res == True
|
||||
|
||||
# srs path
|
||||
res = ezkl.get_srs(srs_path, settings_path)
|
||||
res = ezkl.get_srs(settings_path)
|
||||
|
||||
# setupt vk, pk param for use..... prover can use same pk or can init their own!
|
||||
# print("==== setting up ezkl ====")
|
||||
@@ -85,8 +85,7 @@ def verifier_setup(verifier_model_path, verifier_compiled_model_path, settings_p
|
||||
res = ezkl.setup(
|
||||
verifier_compiled_model_path,
|
||||
vk_path,
|
||||
pk_path,
|
||||
srs_path)
|
||||
pk_path)
|
||||
end_time = time.time()
|
||||
time_setup = end_time -start_time
|
||||
# print(f"Time setup: {time_setup} seconds")
|
||||
@@ -100,7 +99,7 @@ def verifier_setup(verifier_model_path, verifier_compiled_model_path, settings_p
|
||||
# ===================================================================================================
|
||||
|
||||
# return time gen proof
|
||||
def prover_gen_proof(prover_model_path, comb_data_path, witness_path, prover_compiled_model_path, settings_path, proof_path, pk_path, srs_path):
|
||||
def prover_gen_proof(prover_model_path, comb_data_path, witness_path, prover_compiled_model_path, settings_path, proof_path, pk_path):
|
||||
res = ezkl.compile_circuit(prover_model_path, prover_compiled_model_path, settings_path)
|
||||
assert res == True
|
||||
# now generate the witness file
|
||||
@@ -122,7 +121,6 @@ def prover_gen_proof(prover_model_path, comb_data_path, witness_path, prover_com
|
||||
prover_compiled_model_path,
|
||||
pk_path,
|
||||
proof_path,
|
||||
srs_path,
|
||||
"single",
|
||||
)
|
||||
|
||||
@@ -137,7 +135,7 @@ def prover_gen_proof(prover_model_path, comb_data_path, witness_path, prover_com
|
||||
# ===================================================================================================
|
||||
|
||||
# return result array
|
||||
def verifier_verify(proof_path, settings_path, vk_path, srs_path):
|
||||
def verifier_verify(proof_path, settings_path, vk_path):
|
||||
# enforce boolean statement to be true
|
||||
settings = json.load(open(settings_path))
|
||||
output_scale = settings['model_output_scales']
|
||||
@@ -161,8 +159,7 @@ def verifier_verify(proof_path, settings_path, vk_path, srs_path):
|
||||
res = ezkl.verify(
|
||||
proof_path,
|
||||
settings_path,
|
||||
vk_path,
|
||||
srs_path,
|
||||
vk_path
|
||||
)
|
||||
|
||||
assert res == True
|
||||
@@ -184,7 +181,6 @@ def bench_one(data_path_array, model_func, gen_param_func, data_name, scale,mode
|
||||
vk_path = os.path.join('shared/test.vk')
|
||||
proof_path = os.path.join('shared/test.pf')
|
||||
settings_path = os.path.join('shared/settings.json')
|
||||
srs_path = os.path.join('shared/kzg.srs')
|
||||
witness_path = os.path.join('prover/witness.json')
|
||||
|
||||
# this is private to prover since it contains actual data
|
||||
@@ -216,11 +212,11 @@ def bench_one(data_path_array, model_func, gen_param_func, data_name, scale,mode
|
||||
gen_settings(comb_data_path, prover_model_path, scale, mode, settings_path)
|
||||
f_setting = open(settings_path, "r")
|
||||
print("setting: ", f_setting.read())
|
||||
verifier_setup(verifier_model_path, verifier_compiled_model_path, settings_path, srs_path,vk_path, pk_path )
|
||||
verifier_setup(verifier_model_path, verifier_compiled_model_path, settings_path,vk_path, pk_path )
|
||||
|
||||
gen_prf_time = prover_gen_proof(prover_model_path, comb_data_path, witness_path, prover_compiled_model_path, settings_path, proof_path, pk_path, srs_path)
|
||||
gen_prf_time = prover_gen_proof(prover_model_path, comb_data_path, witness_path, prover_compiled_model_path, settings_path, proof_path, pk_path)
|
||||
|
||||
result= verifier_verify(proof_path, settings_path, vk_path, srs_path)
|
||||
result= verifier_verify(proof_path, settings_path, vk_path)
|
||||
|
||||
# f_setting = open(settings_path, "r")
|
||||
# print("setting: ", f_setting.read())
|
||||
@@ -244,7 +240,6 @@ def bench_all(data_path_nested_array, model_func, gen_param_func, scale):
|
||||
vk_path = os.path.join('shared/test.vk')
|
||||
proof_path = os.path.join('shared/test.pf')
|
||||
settings_path = os.path.join('shared/settings.json')
|
||||
srs_path = os.path.join('shared/kzg.srs')
|
||||
witness_path = os.path.join('prover/witness.json')
|
||||
|
||||
# this is private to prover since it contains actual data
|
||||
@@ -297,11 +292,11 @@ def bench_all(data_path_nested_array, model_func, gen_param_func, scale):
|
||||
f_setting = open(settings_path, "r")
|
||||
print("setting: ", f_setting.read())
|
||||
|
||||
verifier_setup(verifier_model_path, verifier_compiled_model_path, settings_path, srs_path,vk_path, pk_path )
|
||||
verifier_setup(verifier_model_path, verifier_compiled_model_path, settings_path,vk_path, pk_path )
|
||||
|
||||
gen_prf_time = prover_gen_proof(prover_model_path, comb_data_path, witness_path, prover_compiled_model_path, settings_path, proof_path, pk_path, srs_path)
|
||||
gen_prf_time = prover_gen_proof(prover_model_path, comb_data_path, witness_path, prover_compiled_model_path, settings_path, proof_path, pk_path)
|
||||
|
||||
result= verifier_verify(proof_path, settings_path, vk_path, srs_path)
|
||||
result= verifier_verify(proof_path, settings_path, vk_path)
|
||||
|
||||
# f_setting = open(settings_path, "r")
|
||||
# print("setting: ", f_setting.read())
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -273,12 +273,12 @@
|
||||
"source": [
|
||||
"# Here verifier & prover can concurrently call setup since all params are public to get pk. \n",
|
||||
"# Here write as verifier function to emphasize that verifier must calculate its own vk to be sure\n",
|
||||
"verifier_setup(verifier_model_path, verifier_compiled_model_path, settings_path, srs_path,vk_path, pk_path )\n",
|
||||
"verifier_setup(verifier_model_path, verifier_compiled_model_path, settings_path,vk_path, pk_path )\n",
|
||||
"\n",
|
||||
"print(\"=======================================\")\n",
|
||||
"# Prover generates proof\n",
|
||||
"print(\"Theory output: \", theory_output)\n",
|
||||
"prover_gen_proof(prover_model_path, comb_data_path, witness_path, prover_compiled_model_path, settings_path, proof_path, pk_path, srs_path)"
|
||||
"prover_gen_proof(prover_model_path, comb_data_path, witness_path, prover_compiled_model_path, settings_path, proof_path, pk_path)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -300,7 +300,7 @@
|
||||
],
|
||||
"source": [
|
||||
"# Verifier verifies\n",
|
||||
"verifier_verify(proof_path, settings_path, vk_path, srs_path)"
|
||||
"verifier_verify(proof_path, settings_path, vk_path)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
10
examples/mean/data.json
Normal file
10
examples/mean/data.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"input_data": [
|
||||
[
|
||||
46.2, 40.4, 44.8, 48.1, 51.2, 91.9, 38.2, 36.3, 22.2, 11.5, 17.9, 20.2,
|
||||
99.9, 75.2, 29.8, 19.4, 46.1, 94.8, 6.6, 94.5, 99.7, 1.6, 4.0, 86.7, 28.7,
|
||||
63.0, 66.7, 2.5, 41.4, 35.6, 45.0, 13.7, 9.6, 16.6, 9.8, 20.3, 25.9, 71.9,
|
||||
27.5, 30.9, 62.9, 18.6, 45.7, 2.4, 91.4, 16.2, 61.5, 41.4, 77.1, 53.2
|
||||
]
|
||||
]
|
||||
}
|
||||
3
examples/mean/data1.json
Normal file
3
examples/mean/data1.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"input_data": [[4, 5, 6.0]]
|
||||
}
|
||||
3
examples/mean/data2.json
Normal file
3
examples/mean/data2.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"input_data": [[8, 9.0, 13]]
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -75,7 +75,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%run -i ../../core.py"
|
||||
"%run -i ../../zkstats/core.py"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
411
examples/mean/mean_across.ipynb
Normal file
411
examples/mean/mean_across.ipynb
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,4 +1,4 @@
|
||||
ezkl==5.4.2
|
||||
ezkl==7.0.0
|
||||
torch
|
||||
requests
|
||||
scipy
|
||||
|
||||
@@ -144,13 +144,13 @@ def prover_gen_settings(data_path_array, comb_data_path, prover_model,prover_mod
|
||||
|
||||
# Here prover can concurrently call this since all params are public to get pk.
|
||||
# Here write as verifier function to emphasize that verifier must calculate its own vk to be sure
|
||||
def verifier_setup(verifier_model_path, verifier_compiled_model_path, settings_path, srs_path,vk_path, pk_path ):
|
||||
def verifier_setup(verifier_model_path, verifier_compiled_model_path, settings_path,vk_path, pk_path ):
|
||||
# compile circuit
|
||||
res = ezkl.compile_circuit(verifier_model_path, verifier_compiled_model_path, settings_path)
|
||||
assert res == True
|
||||
|
||||
# srs path
|
||||
res = ezkl.get_srs(srs_path, settings_path)
|
||||
res = ezkl.get_srs(settings_path)
|
||||
|
||||
# setup vk, pk param for use..... prover can use same pk or can init their own!
|
||||
print("==== setting up ezkl ====")
|
||||
@@ -158,8 +158,7 @@ def verifier_setup(verifier_model_path, verifier_compiled_model_path, settings_p
|
||||
res = ezkl.setup(
|
||||
verifier_compiled_model_path,
|
||||
vk_path,
|
||||
pk_path,
|
||||
srs_path)
|
||||
pk_path)
|
||||
end_time = time.time()
|
||||
time_setup = end_time -start_time
|
||||
print(f"Time setup: {time_setup} seconds")
|
||||
@@ -181,7 +180,6 @@ def prover_setup(
|
||||
scale,
|
||||
mode,
|
||||
settings_path,
|
||||
srs_path,
|
||||
vk_path,
|
||||
pk_path,
|
||||
):
|
||||
@@ -191,7 +189,7 @@ def prover_setup(
|
||||
export_onnx(prover_model, data_tensor_array, prover_model_path)
|
||||
# gen + calibrate setting
|
||||
gen_settings(comb_data_path, prover_model_path, scale, mode, settings_path)
|
||||
verifier_setup(prover_model_path, prover_compiled_model_path, settings_path, srs_path, vk_path, pk_path)
|
||||
verifier_setup(prover_model_path, prover_compiled_model_path, settings_path, vk_path, pk_path)
|
||||
|
||||
|
||||
def prover_gen_proof(
|
||||
@@ -201,8 +199,7 @@ def prover_gen_proof(
|
||||
prover_compiled_model_path,
|
||||
settings_path,
|
||||
proof_path,
|
||||
pk_path,
|
||||
srs_path,
|
||||
pk_path
|
||||
):
|
||||
print("!@# compiled_model exists?", os.path.isfile(prover_compiled_model_path))
|
||||
res = ezkl.compile_circuit(prover_model_path, prover_compiled_model_path, settings_path)
|
||||
@@ -227,7 +224,6 @@ def prover_gen_proof(
|
||||
prover_compiled_model_path,
|
||||
pk_path,
|
||||
proof_path,
|
||||
srs_path,
|
||||
"single",
|
||||
)
|
||||
|
||||
@@ -240,7 +236,7 @@ def prover_gen_proof(
|
||||
# ===================================================================================================
|
||||
# ===================================================================================================
|
||||
|
||||
def verifier_verify(proof_path, settings_path, vk_path, srs_path):
|
||||
def verifier_verify(proof_path, settings_path, vk_path):
|
||||
# enforce boolean statement to be true
|
||||
settings = json.load(open(settings_path))
|
||||
output_scale = settings['model_output_scales']
|
||||
@@ -262,7 +258,6 @@ def verifier_verify(proof_path, settings_path, vk_path, srs_path):
|
||||
proof_path,
|
||||
settings_path,
|
||||
vk_path,
|
||||
srs_path,
|
||||
)
|
||||
|
||||
assert res == True
|
||||
|
||||
Reference in New Issue
Block a user