mirror of
https://github.com/MPCStats/zk-stats-lib.git
synced 2026-01-10 05:57:55 -05:00
median done
This commit is contained in:
@@ -52,7 +52,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -69,244 +69,36 @@
|
||||
"import math"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Export model\n",
|
||||
"def export_onnx(model, data_tensor_array, model_loc):\n",
|
||||
" circuit = model()\n",
|
||||
"\n",
|
||||
" device = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")\n",
|
||||
"\n",
|
||||
" # print(device)\n",
|
||||
"\n",
|
||||
" circuit.to(device)\n",
|
||||
"\n",
|
||||
" # Flips the neural net into inference mode\n",
|
||||
" circuit.eval()\n",
|
||||
" input_names = []\n",
|
||||
" dynamic_axes = {}\n",
|
||||
"\n",
|
||||
" data_tensor_tuple = ()\n",
|
||||
" for i in range(len(data_tensor_array)):\n",
|
||||
" data_tensor_tuple += (data_tensor_array[i],)\n",
|
||||
" input_index = \"input\"+str(i+1)\n",
|
||||
" input_names.append(input_index)\n",
|
||||
" dynamic_axes[input_index] = {0 : 'batch_size'}\n",
|
||||
" dynamic_axes[\"output\"] = {0 : 'batch_size'}\n",
|
||||
"\n",
|
||||
" # Export the model\n",
|
||||
" torch.onnx.export(circuit, # model being run\n",
|
||||
" data_tensor_tuple, # model input (or a tuple for multiple inputs)\n",
|
||||
" model_loc, # where to save the model (can be a file or file-like object)\n",
|
||||
" export_params=True, # store the trained parameter weights inside the model file\n",
|
||||
" opset_version=11, # the ONNX version to export the model to\n",
|
||||
" do_constant_folding=True, # whether to execute constant folding for optimization\n",
|
||||
" input_names = input_names, # the model's input names\n",
|
||||
" output_names = ['output'], # the model's output names\n",
|
||||
" dynamic_axes=dynamic_axes)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# mode is either \"accuracy\" or \"resources\"\n",
|
||||
"\n",
|
||||
"def gen_settings(comb_data_path, onnx_filename, scale, mode, settings_filename):\n",
|
||||
" print(\"==== Generate & Calibrate Setting ====\")\n",
|
||||
" # Set input to be Poseidon Hash, and param of computation graph to be public\n",
|
||||
" # Poseidon is not homomorphic additive, maybe consider Pedersens or Dory commitment.\n",
|
||||
" gip_run_args = ezkl.PyRunArgs()\n",
|
||||
" gip_run_args.input_visibility = \"hashed\" # matrix and generalized inverse commitments\n",
|
||||
" gip_run_args.output_visibility = \"public\" # no parameters used\n",
|
||||
" gip_run_args.param_visibility = \"private\" # should be Tensor(True)--> to enforce arbitrary data in w\n",
|
||||
"\n",
|
||||
" # generate settings\n",
|
||||
" ezkl.gen_settings(onnx_filename, settings_filename, py_run_args=gip_run_args)\n",
|
||||
" if scale ==\"default\":\n",
|
||||
" ezkl.calibrate_settings(\n",
|
||||
" comb_data_path, onnx_filename, settings_filename, mode)\n",
|
||||
" else:\n",
|
||||
" ezkl.calibrate_settings(\n",
|
||||
" comb_data_path, onnx_filename, settings_filename, mode, scales = scale)\n",
|
||||
"\n",
|
||||
" assert os.path.exists(settings_filename)\n",
|
||||
" assert os.path.exists(comb_data_path)\n",
|
||||
" assert os.path.exists(onnx_filename)\n",
|
||||
" f_setting = open(settings_filename, \"r\")\n",
|
||||
" print(\"scale: \", scale)\n",
|
||||
" print(\"setting: \", f_setting.read())\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def verifier_init(verifier_model, verifier_model_path, verifier_compiled_model_path, dummy_data_path_array, settings_path, srs_path, pk_path, vk_path, scale, mode):\n",
|
||||
"\n",
|
||||
" # load data from dummy_data_path_array into dummy_data_array\n",
|
||||
" dummy_data_tensor_array = []\n",
|
||||
" comb_dummy_data = []\n",
|
||||
" for path in dummy_data_path_array:\n",
|
||||
" dummy_data = np.array(json.loads(open(path, \"r\").read())[\"input_data\"][0])\n",
|
||||
" # print(\"dumm: \", dummy_data)\n",
|
||||
" dummy_data_tensor_array.append(torch.reshape(torch.tensor(dummy_data), (1, len(dummy_data),1 )))\n",
|
||||
" comb_dummy_data.append(dummy_data.tolist())\n",
|
||||
" # export onnx file\n",
|
||||
" export_onnx(verifier_model,dummy_data_tensor_array, verifier_model_path)\n",
|
||||
"\n",
|
||||
" comb_dummy_data_path = os.path.join('generated/comb_dummy_data.json')\n",
|
||||
" # Serialize data into file:\n",
|
||||
" json.dump(dict(input_data = comb_dummy_data), open(comb_dummy_data_path, 'w' ))\n",
|
||||
"\n",
|
||||
" # gen + calibrate setting\n",
|
||||
" gen_settings(comb_dummy_data_path, verifier_model_path, scale, mode, settings_path)\n",
|
||||
"\n",
|
||||
" # compile circuit\n",
|
||||
" res = ezkl.compile_circuit(verifier_model_path, verifier_compiled_model_path, settings_path)\n",
|
||||
" assert res == True\n",
|
||||
"\n",
|
||||
" # srs path\n",
|
||||
" res = ezkl.get_srs(srs_path, settings_path)\n",
|
||||
"\n",
|
||||
" # setupt vk, pk param for use..... prover can use same pk or can init their own!\n",
|
||||
" print(\"==== setting up ezkl ====\")\n",
|
||||
" start_time = time.time()\n",
|
||||
" res = ezkl.setup(\n",
|
||||
" verifier_compiled_model_path,\n",
|
||||
" vk_path,\n",
|
||||
" pk_path,\n",
|
||||
" srs_path)\n",
|
||||
" end_time = time.time()\n",
|
||||
" time_setup = end_time -start_time\n",
|
||||
" print(f\"Time setup: {time_setup} seconds\")\n",
|
||||
"\n",
|
||||
" assert res == True\n",
|
||||
" assert os.path.isfile(vk_path)\n",
|
||||
" assert os.path.isfile(pk_path)\n",
|
||||
" assert os.path.isfile(settings_path)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def prover_gen(prover_model, data_path_array, witness_path, prover_model_path, prover_compiled_model_path, settings_path, proof_path):\n",
|
||||
" # load data from data_path\n",
|
||||
" # data = json.loads(open(data_path, \"r\").read())[\"input_data\"][0]\n",
|
||||
" # data_tensor = torch.reshape(torch.tensor(data), (1, len(data),1 ))\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" data_tensor_array = []\n",
|
||||
" comb_data = []\n",
|
||||
" for path in data_path_array:\n",
|
||||
" data = np.array(json.loads(open(path, \"r\").read())[\"input_data\"][0])\n",
|
||||
" # print(\"dumm: \", dummy_data)\n",
|
||||
" data_tensor_array.append(torch.reshape(torch.tensor(data), (1, len(data),1 )))\n",
|
||||
" comb_data.append(data.tolist())\n",
|
||||
"\n",
|
||||
" # export onnx file\n",
|
||||
" export_onnx(prover_model, data_tensor_array, prover_model_path)\n",
|
||||
"\n",
|
||||
" comb_data_path = os.path.join('generated/comb_data.json')\n",
|
||||
" # Serialize data into file:\n",
|
||||
" json.dump(dict(input_data = comb_data), open(comb_data_path, 'w' ))\n",
|
||||
"\n",
|
||||
" res = ezkl.compile_circuit(prover_model_path, prover_compiled_model_path, settings_path)\n",
|
||||
" assert res == True\n",
|
||||
" # now generate the witness file\n",
|
||||
" print('==== Generating Witness ====')\n",
|
||||
" witness = ezkl.gen_witness(comb_data_path, prover_compiled_model_path, witness_path)\n",
|
||||
" assert os.path.isfile(witness_path)\n",
|
||||
" # print(witness[\"outputs\"])\n",
|
||||
" settings = json.load(open(settings_path))\n",
|
||||
" output_scale = settings['model_output_scales']\n",
|
||||
" print(\"witness boolean: \", ezkl.vecu64_to_float(witness['outputs'][0][0], output_scale[0]))\n",
|
||||
" for i in range(len(witness['outputs'][1])):\n",
|
||||
" print(\"witness result\", i+1,\":\", ezkl.vecu64_to_float(witness['outputs'][1][i], output_scale[1]))\n",
|
||||
"\n",
|
||||
" # GENERATE A PROOF\n",
|
||||
" print(\"==== Generating Proof ====\")\n",
|
||||
" start_time = time.time()\n",
|
||||
" res = ezkl.prove(\n",
|
||||
" witness_path,\n",
|
||||
" prover_compiled_model_path,\n",
|
||||
" pk_path,\n",
|
||||
" proof_path,\n",
|
||||
" srs_path,\n",
|
||||
" \"single\",\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" print(\"proof: \" ,res)\n",
|
||||
" end_time = time.time()\n",
|
||||
" time_gen_prf = end_time -start_time\n",
|
||||
" print(f\"Time gen prf: {time_gen_prf} seconds\")\n",
|
||||
" assert os.path.isfile(proof_path)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def verifier_verify(proof_path, settings_path, vk_path, srs_path):\n",
|
||||
" # enforce boolean statement to be true\n",
|
||||
" settings = json.load(open(settings_path))\n",
|
||||
" output_scale = settings['model_output_scales']\n",
|
||||
"\n",
|
||||
" proof = json.load(open(proof_path))\n",
|
||||
" num_inputs = len(settings['model_input_scales'])\n",
|
||||
" print(\"num_inputs: \", num_inputs)\n",
|
||||
" proof[\"instances\"][0][num_inputs] = ezkl.float_to_vecu64(1.0, output_scale[0])\n",
|
||||
" json.dump(proof, open(proof_path, 'w'))\n",
|
||||
"\n",
|
||||
" print(\"prf instances: \", proof['instances'])\n",
|
||||
"\n",
|
||||
" print(\"proof boolean: \", ezkl.vecu64_to_float(proof['instances'][0][num_inputs], output_scale[0]))\n",
|
||||
" for i in range(num_inputs+1, len(proof['instances'][0])):\n",
|
||||
" print(\"proof result\",i-num_inputs,\":\", ezkl.vecu64_to_float(proof['instances'][0][i], output_scale[1]))\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" res = ezkl.verify(\n",
|
||||
" proof_path,\n",
|
||||
" settings_path,\n",
|
||||
" vk_path,\n",
|
||||
" srs_path,\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" assert res == True\n",
|
||||
" print(\"verified\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%run -i ../../core.py"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# init path\n",
|
||||
"os.makedirs(os.path.dirname('generated/'), exist_ok=True)\n",
|
||||
"verifier_model_path = os.path.join('generated/verifier.onnx')\n",
|
||||
"prover_model_path = os.path.join('generated/prover.onnx')\n",
|
||||
"verifier_compiled_model_path = os.path.join('generated/verifier.compiled')\n",
|
||||
"prover_compiled_model_path = os.path.join('generated/prover.compiled')\n",
|
||||
"pk_path = os.path.join('generated/test.pk')\n",
|
||||
"vk_path = os.path.join('generated/test.vk')\n",
|
||||
"proof_path = os.path.join('generated/test.pf')\n",
|
||||
"settings_path = os.path.join('generated/settings.json')\n",
|
||||
"srs_path = os.path.join('generated/kzg.srs')\n",
|
||||
"witness_path = os.path.join('generated/witness.json')"
|
||||
"os.makedirs(os.path.dirname('shared/'), exist_ok=True)\n",
|
||||
"os.makedirs(os.path.dirname('prover/'), exist_ok=True)\n",
|
||||
"verifier_model_path = os.path.join('shared/verifier.onnx')\n",
|
||||
"prover_model_path = os.path.join('prover/prover.onnx')\n",
|
||||
"verifier_compiled_model_path = os.path.join('shared/verifier.compiled')\n",
|
||||
"prover_compiled_model_path = os.path.join('prover/prover.compiled')\n",
|
||||
"pk_path = os.path.join('shared/test.pk')\n",
|
||||
"vk_path = os.path.join('shared/test.vk')\n",
|
||||
"proof_path = os.path.join('shared/test.pf')\n",
|
||||
"settings_path = os.path.join('shared/settings.json')\n",
|
||||
"srs_path = os.path.join('shared/kzg.srs')\n",
|
||||
"witness_path = os.path.join('prover/witness.json')\n",
|
||||
"# this is private to prover since it contains actual data\n",
|
||||
"comb_data_path = os.path.join('prover/comb_data.json')"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -317,27 +109,35 @@
|
||||
"======================= ZK-STATS FLOW ======================="
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Currently, the circuit is too huge, possibly by requesting covariance and stdev and just calculate it on verifier side instead!"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"corr: 0.8928765321817651\n",
|
||||
"corr: 0.8928769029553791\n",
|
||||
"x mean: 49.5\n",
|
||||
"y mean: 227.70285322096493\n",
|
||||
"dummy corr: 0.09976008761504027\n",
|
||||
"dummy x mean: 47.253905389196696\n",
|
||||
"dummy y mean: 249.24999539636343\n"
|
||||
"y mean: 227.703\n",
|
||||
"dummy corr: 0.09636370915922249\n",
|
||||
"dummy x mean: 49.00761737545071\n",
|
||||
"dummy y mean: 237.99976726082184\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"x_vals_path = os.path.join('x_vals.json')\n",
|
||||
"dummy_x_vals_path = os.path.join('generated/dummy_x_vals.json')\n",
|
||||
"dummy_x_vals_path = os.path.join('shared/dummy_x_vals.json')\n",
|
||||
"x_open = open(x_vals_path, \"r\")\n",
|
||||
"x_vals= json.loads(x_open.read())['input_data'][0]\n",
|
||||
"dummy_x_vals = np.random.uniform(min(x_vals), max(x_vals), len(x_vals))\n",
|
||||
@@ -345,7 +145,7 @@
|
||||
"\n",
|
||||
"\n",
|
||||
"y_vals_path = os.path.join('y_vals.json')\n",
|
||||
"dummy_y_vals_path = os.path.join('generated/dummy_y_vals.json')\n",
|
||||
"dummy_y_vals_path = os.path.join('shared/dummy_y_vals.json')\n",
|
||||
"y_open = open(y_vals_path, \"r\")\n",
|
||||
"y_vals= json.loads(y_open.read())[\"input_data\"][0]\n",
|
||||
"dummy_y_vals = np.random.uniform(min(y_vals), max(y_vals), len(y_vals))\n",
|
||||
@@ -379,20 +179,227 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"execution_count": 34,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"right side: tensor(2.0466e+09, dtype=torch.float64)\n",
|
||||
"left side: tensor(2.0466e+09, dtype=torch.float64)\n",
|
||||
"==== Generate & Calibrate Setting ====\n",
|
||||
"scale: [0]\n",
|
||||
"setting: {\"run_args\":{\"tolerance\":{\"val\":0.0,\"scale\":1.0},\"input_scale\":0,\"param_scale\":0,\"scale_rebase_multiplier\":10,\"lookup_range\":[-10,91880],\"logrows\":17,\"num_inner_cols\":1,\"variables\":[[\"batch_size\",1]],\"input_visibility\":{\"Hashed\":{\"hash_is_public\":true,\"outlets\":[]}},\"output_visibility\":\"Public\",\"param_visibility\":\"Private\"},\"num_rows\":13120,\"total_assignments\":611,\"total_const_size\":1,\"model_instance_shapes\":[[1],[1]],\"model_output_scales\":[0,0],\"model_input_scales\":[0,0],\"module_sizes\":{\"kzg\":[],\"poseidon\":[13120,[2]],\"elgamal\":[0,[0]]},\"required_lookups\":[\"Abs\",{\"Div\":{\"denom\":50.0}},{\"Ln\":{\"scale\":1.0}},{\"GreaterThan\":{\"a\":0.0}}],\"check_mode\":\"UNSAFE\",\"version\":\"5.0.8\",\"num_blinding_factors\":null}\n"
|
||||
"xxx: tensor([[[62.9795],\n",
|
||||
" [22.0217],\n",
|
||||
" [52.3409],\n",
|
||||
" [37.5802],\n",
|
||||
" [58.1255],\n",
|
||||
" [52.4249],\n",
|
||||
" [20.3958],\n",
|
||||
" [47.2491],\n",
|
||||
" [23.8496],\n",
|
||||
" [ 7.8126],\n",
|
||||
" [13.9089],\n",
|
||||
" [79.6785],\n",
|
||||
" [43.2629],\n",
|
||||
" [62.6596],\n",
|
||||
" [92.1490],\n",
|
||||
" [17.4866],\n",
|
||||
" [14.0891],\n",
|
||||
" [ 4.9190],\n",
|
||||
" [78.6948],\n",
|
||||
" [41.2017],\n",
|
||||
" [42.2647],\n",
|
||||
" [43.9585],\n",
|
||||
" [83.9661],\n",
|
||||
" [89.5124],\n",
|
||||
" [95.3961],\n",
|
||||
" [60.9797],\n",
|
||||
" [23.4067],\n",
|
||||
" [17.3428],\n",
|
||||
" [90.6992],\n",
|
||||
" [79.7309],\n",
|
||||
" [87.4945],\n",
|
||||
" [45.8548],\n",
|
||||
" [22.1585],\n",
|
||||
" [92.6558],\n",
|
||||
" [ 7.5434],\n",
|
||||
" [ 6.0029],\n",
|
||||
" [46.7445],\n",
|
||||
" [59.2296],\n",
|
||||
" [26.6279],\n",
|
||||
" [43.9125],\n",
|
||||
" [ 2.2883],\n",
|
||||
" [52.6816],\n",
|
||||
" [35.7346],\n",
|
||||
" [54.6388],\n",
|
||||
" [75.4577],\n",
|
||||
" [ 7.3459],\n",
|
||||
" [82.0465],\n",
|
||||
" [85.7411],\n",
|
||||
" [46.4742],\n",
|
||||
" [64.1138],\n",
|
||||
" [46.7118],\n",
|
||||
" [85.1890],\n",
|
||||
" [44.0479],\n",
|
||||
" [86.8898],\n",
|
||||
" [19.1891],\n",
|
||||
" [38.0513],\n",
|
||||
" [73.5213],\n",
|
||||
" [77.7149],\n",
|
||||
" [68.4295],\n",
|
||||
" [37.9432],\n",
|
||||
" [83.8206],\n",
|
||||
" [65.2856],\n",
|
||||
" [91.2397],\n",
|
||||
" [70.4041],\n",
|
||||
" [67.8913],\n",
|
||||
" [16.5063],\n",
|
||||
" [64.8318],\n",
|
||||
" [28.4944],\n",
|
||||
" [29.0290],\n",
|
||||
" [62.3993],\n",
|
||||
" [19.7002],\n",
|
||||
" [63.5303],\n",
|
||||
" [48.8265],\n",
|
||||
" [36.1527],\n",
|
||||
" [82.4579],\n",
|
||||
" [93.9550],\n",
|
||||
" [71.1069],\n",
|
||||
" [52.8947],\n",
|
||||
" [32.2252],\n",
|
||||
" [38.8979],\n",
|
||||
" [35.0119],\n",
|
||||
" [28.1229],\n",
|
||||
" [45.7980],\n",
|
||||
" [58.1556],\n",
|
||||
" [63.2104],\n",
|
||||
" [10.0951],\n",
|
||||
" [22.9158],\n",
|
||||
" [79.7788],\n",
|
||||
" [ 4.3663],\n",
|
||||
" [48.3876],\n",
|
||||
" [94.3303],\n",
|
||||
" [56.7153],\n",
|
||||
" [83.0030],\n",
|
||||
" [10.8275],\n",
|
||||
" [13.0768],\n",
|
||||
" [19.4223],\n",
|
||||
" [ 1.9992],\n",
|
||||
" [36.1875],\n",
|
||||
" [ 5.3506],\n",
|
||||
" [81.8356]]], dtype=torch.float64)\n",
|
||||
"mean X: tensor(49.0076, dtype=torch.float64)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/onnx/symbolic_opset9.py:2174: FutureWarning: 'torch.onnx.symbolic_opset9._cast_Bool' is deprecated in version 2.0 and will be removed in the future. Please Avoid using this function and create a Cast node instead.\n",
|
||||
" return fn(g, to_cast_func(g, input, False), to_cast_func(g, other, False))\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# precise float number is hard, so we calculate 100*correlation instead.\n",
|
||||
"# Verifier/ data consumer side:\n",
|
||||
"class verifier_model(nn.Module):\n",
|
||||
" def __init__(self):\n",
|
||||
" super(verifier_model, self).__init__()\n",
|
||||
" self.corr = nn.Parameter(data = torch.tensor(dummy_corr*100), requires_grad = False)\n",
|
||||
" self.x_mean = nn.Parameter(data = torch.tensor(dummy_x_mean), requires_grad = False)\n",
|
||||
" self.y_mean = nn.Parameter(data = torch.tensor(dummy_y_mean), requires_grad = False)\n",
|
||||
" self.x_var = nn.Parameter(data = torch.tensor(dummy_x_var), requires_grad = False)\n",
|
||||
" self.y_var = nn.Parameter(data = torch.tensor(dummy_y_var), requires_grad = False)\n",
|
||||
" def forward(self,X,Y):\n",
|
||||
" # some expression of tolerance to error in the inference\n",
|
||||
" # need to enforce same length, not yet\n",
|
||||
" x_mean_cons = torch.abs(torch.sum(X)-X.size()[1]*(self.x_mean))<0.01*X.size()[1]*(self.x_mean)\n",
|
||||
" y_mean_cons = torch.abs(torch.sum(Y)-Y.size()[1]*(self.y_mean))<0.01*Y.size()[1]*(self.y_mean)\n",
|
||||
" x_var_cons = torch.abs(torch.sum((X-self.x_mean)*(X-self.x_mean))-self.x_var*(X.size()[1]-1))<0.01*self.x_var*(X.size()[1]-1)\n",
|
||||
" y_var_cons = torch.abs(torch.sum((Y-self.y_mean)*(Y-self.y_mean))-self.y_var*(Y.size()[1]-1))<0.01*self.y_var*(Y.size()[1]-1)\n",
|
||||
" corr_cons = torch.abs(torch.sum((X-self.x_mean)*(Y-self.y_mean))-(torch.sqrt(self.x_var)*torch.sqrt(self.y_var)*torch.div(self.corr, 100)))<0.01*(torch.sqrt(self.x_var)*torch.sqrt(self.y_var)*torch.div(self.corr, 100))\n",
|
||||
"\n",
|
||||
" # return (torch.logical_and(corr_cons, torch.logical_and(torch.logical_and(x_mean_cons, y_mean_cons), torch.logical_and(x_var_cons, y_var_cons))), self.corr)\n",
|
||||
" # return (torch.logical_and(corr_cons, torch.logical_and(x_mean_cons, y_mean_cons)), self.corr)\n",
|
||||
" # return (torch.logical_and(torch.logical_and(x_var_cons,corr_cons), torch.logical_and(x_mean_cons, y_mean_cons)), self.corr)\n",
|
||||
" # return (torch.logical_and(x_var_cons,torch.logical_and(corr_cons, torch.logical_and(x_mean_cons, y_mean_cons))), self.corr)\n",
|
||||
" return (torch.logical_and(x_var_cons, corr_cons), self.corr)\n",
|
||||
"verifier_define_calculation(verifier_model, verifier_model_path, [dummy_x_vals_path, dummy_y_vals_path])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 37,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"theory output: tensor(0.8929)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ename": "RuntimeError",
|
||||
"evalue": "std and var only support floating point and complex dtypes",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)",
|
||||
"Cell \u001b[0;32mIn[37], line 27\u001b[0m\n\u001b[1;32m 22\u001b[0m \u001b[39m# return (torch.logical_and(corr_cons, torch.logical_and(torch.logical_and(x_mean_cons, y_mean_cons), torch.logical_and(x_var_cons, y_var_cons))), self.corr)\u001b[39;00m\n\u001b[1;32m 23\u001b[0m \u001b[39m# return (torch.logical_and(corr_cons, torch.logical_and(x_mean_cons, y_mean_cons)), self.corr)\u001b[39;00m\n\u001b[1;32m 24\u001b[0m \u001b[39m# return (torch.logical_and(torch.logical_and(corr_cons, x_var_cons), torch.logical_and(x_mean_cons, y_mean_cons)), self.corr)\u001b[39;00m\n\u001b[1;32m 25\u001b[0m \u001b[39m# return (torch.logical_and(x_var_cons,torch.logical_and(corr_cons, torch.logical_and(x_mean_cons, y_mean_cons))), self.corr)\u001b[39;00m\n\u001b[1;32m 26\u001b[0m \u001b[39mreturn\u001b[39;00m (torch\u001b[39m.\u001b[39mlogical_and(x_var_cons, corr_cons), \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mcorr)\n\u001b[0;32m---> 27\u001b[0m prover_gen_settings([x_vals_path, y_vals_path], comb_data_path, prover_model,prover_model_path, [\u001b[39m0\u001b[39;49m], \u001b[39m\"\u001b[39;49m\u001b[39mresources\u001b[39;49m\u001b[39m\"\u001b[39;49m, settings_path)\n",
|
||||
"File \u001b[0;32m~/Desktop/zk-stats-lib/core.py:97\u001b[0m, in \u001b[0;36mprover_gen_settings\u001b[0;34m(data_path_array, comb_data_path, prover_model, prover_model_path, scale, mode, settings_path)\u001b[0m\n\u001b[1;32m 94\u001b[0m json\u001b[39m.\u001b[39mdump(\u001b[39mdict\u001b[39m(input_data \u001b[39m=\u001b[39m comb_data), \u001b[39mopen\u001b[39m(comb_data_path, \u001b[39m'\u001b[39m\u001b[39mw\u001b[39m\u001b[39m'\u001b[39m ))\n\u001b[1;32m 96\u001b[0m \u001b[39m# export onnx file\u001b[39;00m\n\u001b[0;32m---> 97\u001b[0m export_onnx(prover_model, data_tensor_array, prover_model_path)\n\u001b[1;32m 98\u001b[0m \u001b[39m# gen + calibrate setting\u001b[39;00m\n\u001b[1;32m 99\u001b[0m gen_settings(comb_data_path, prover_model_path, scale, mode, settings_path)\n",
|
||||
"File \u001b[0;32m~/Desktop/zk-stats-lib/core.py:31\u001b[0m, in \u001b[0;36mexport_onnx\u001b[0;34m(model, data_tensor_array, model_loc)\u001b[0m\n\u001b[1;32m 28\u001b[0m dynamic_axes[\u001b[39m\"\u001b[39m\u001b[39moutput\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m {\u001b[39m0\u001b[39m : \u001b[39m'\u001b[39m\u001b[39mbatch_size\u001b[39m\u001b[39m'\u001b[39m}\n\u001b[1;32m 30\u001b[0m \u001b[39m# Export the model\u001b[39;00m\n\u001b[0;32m---> 31\u001b[0m torch\u001b[39m.\u001b[39;49monnx\u001b[39m.\u001b[39;49mexport(circuit, \u001b[39m# model being run\u001b[39;49;00m\n\u001b[1;32m 32\u001b[0m data_tensor_tuple, \u001b[39m# model input (or a tuple for multiple inputs)\u001b[39;49;00m\n\u001b[1;32m 33\u001b[0m model_loc, \u001b[39m# where to save the model (can be a file or file-like object)\u001b[39;49;00m\n\u001b[1;32m 34\u001b[0m export_params\u001b[39m=\u001b[39;49m\u001b[39mTrue\u001b[39;49;00m, \u001b[39m# store the trained parameter weights inside the model file\u001b[39;49;00m\n\u001b[1;32m 35\u001b[0m opset_version\u001b[39m=\u001b[39;49m\u001b[39m11\u001b[39;49m, \u001b[39m# the ONNX version to export the model to\u001b[39;49;00m\n\u001b[1;32m 36\u001b[0m do_constant_folding\u001b[39m=\u001b[39;49m\u001b[39mTrue\u001b[39;49;00m, \u001b[39m# whether to execute constant folding for optimization\u001b[39;49;00m\n\u001b[1;32m 37\u001b[0m input_names \u001b[39m=\u001b[39;49m input_names, \u001b[39m# the model's input names\u001b[39;49;00m\n\u001b[1;32m 38\u001b[0m output_names \u001b[39m=\u001b[39;49m [\u001b[39m'\u001b[39;49m\u001b[39moutput\u001b[39;49m\u001b[39m'\u001b[39;49m], \u001b[39m# the model's output names\u001b[39;49;00m\n\u001b[1;32m 39\u001b[0m dynamic_axes\u001b[39m=\u001b[39;49mdynamic_axes)\n",
|
||||
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/onnx/utils.py:516\u001b[0m, in \u001b[0;36mexport\u001b[0;34m(model, args, f, export_params, verbose, training, input_names, output_names, operator_export_type, opset_version, do_constant_folding, dynamic_axes, keep_initializers_as_inputs, custom_opsets, export_modules_as_functions, autograd_inlining)\u001b[0m\n\u001b[1;32m 189\u001b[0m \u001b[39m@_beartype\u001b[39m\u001b[39m.\u001b[39mbeartype\n\u001b[1;32m 190\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mexport\u001b[39m(\n\u001b[1;32m 191\u001b[0m model: Union[torch\u001b[39m.\u001b[39mnn\u001b[39m.\u001b[39mModule, torch\u001b[39m.\u001b[39mjit\u001b[39m.\u001b[39mScriptModule, torch\u001b[39m.\u001b[39mjit\u001b[39m.\u001b[39mScriptFunction],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 208\u001b[0m autograd_inlining: Optional[\u001b[39mbool\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mTrue\u001b[39;00m,\n\u001b[1;32m 209\u001b[0m ) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 210\u001b[0m \u001b[39m \u001b[39m\u001b[39mr\u001b[39m\u001b[39m\"\"\"Exports a model into ONNX format.\u001b[39;00m\n\u001b[1;32m 211\u001b[0m \n\u001b[1;32m 212\u001b[0m \u001b[39m If ``model`` is not a :class:`torch.jit.ScriptModule` nor a\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 513\u001b[0m \u001b[39m All errors are subclasses of :class:`errors.OnnxExporterError`.\u001b[39;00m\n\u001b[1;32m 514\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 516\u001b[0m _export(\n\u001b[1;32m 517\u001b[0m model,\n\u001b[1;32m 518\u001b[0m args,\n\u001b[1;32m 519\u001b[0m f,\n\u001b[1;32m 520\u001b[0m export_params,\n\u001b[1;32m 521\u001b[0m verbose,\n\u001b[1;32m 522\u001b[0m training,\n\u001b[1;32m 523\u001b[0m input_names,\n\u001b[1;32m 524\u001b[0m output_names,\n\u001b[1;32m 525\u001b[0m operator_export_type\u001b[39m=\u001b[39;49moperator_export_type,\n\u001b[1;32m 526\u001b[0m opset_version\u001b[39m=\u001b[39;49mopset_version,\n\u001b[1;32m 527\u001b[0m do_constant_folding\u001b[39m=\u001b[39;49mdo_constant_folding,\n\u001b[1;32m 528\u001b[0m dynamic_axes\u001b[39m=\u001b[39;49mdynamic_axes,\n\u001b[1;32m 529\u001b[0m keep_initializers_as_inputs\u001b[39m=\u001b[39;49mkeep_initializers_as_inputs,\n\u001b[1;32m 530\u001b[0m custom_opsets\u001b[39m=\u001b[39;49mcustom_opsets,\n\u001b[1;32m 531\u001b[0m export_modules_as_functions\u001b[39m=\u001b[39;49mexport_modules_as_functions,\n\u001b[1;32m 532\u001b[0m autograd_inlining\u001b[39m=\u001b[39;49mautograd_inlining,\n\u001b[1;32m 533\u001b[0m )\n",
|
||||
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/onnx/utils.py:1596\u001b[0m, in \u001b[0;36m_export\u001b[0;34m(model, args, f, export_params, verbose, training, input_names, output_names, operator_export_type, export_type, opset_version, do_constant_folding, dynamic_axes, keep_initializers_as_inputs, fixed_batch_size, custom_opsets, add_node_names, onnx_shape_inference, export_modules_as_functions, autograd_inlining)\u001b[0m\n\u001b[1;32m 1593\u001b[0m dynamic_axes \u001b[39m=\u001b[39m {}\n\u001b[1;32m 1594\u001b[0m _validate_dynamic_axes(dynamic_axes, model, input_names, output_names)\n\u001b[0;32m-> 1596\u001b[0m graph, params_dict, torch_out \u001b[39m=\u001b[39m _model_to_graph(\n\u001b[1;32m 1597\u001b[0m model,\n\u001b[1;32m 1598\u001b[0m args,\n\u001b[1;32m 1599\u001b[0m verbose,\n\u001b[1;32m 1600\u001b[0m input_names,\n\u001b[1;32m 1601\u001b[0m output_names,\n\u001b[1;32m 1602\u001b[0m operator_export_type,\n\u001b[1;32m 1603\u001b[0m val_do_constant_folding,\n\u001b[1;32m 1604\u001b[0m fixed_batch_size\u001b[39m=\u001b[39;49mfixed_batch_size,\n\u001b[1;32m 1605\u001b[0m training\u001b[39m=\u001b[39;49mtraining,\n\u001b[1;32m 1606\u001b[0m dynamic_axes\u001b[39m=\u001b[39;49mdynamic_axes,\n\u001b[1;32m 1607\u001b[0m )\n\u001b[1;32m 1609\u001b[0m \u001b[39m# TODO: Don't allocate a in-memory string for the protobuf\u001b[39;00m\n\u001b[1;32m 1610\u001b[0m defer_weight_export \u001b[39m=\u001b[39m (\n\u001b[1;32m 1611\u001b[0m export_type \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m _exporter_states\u001b[39m.\u001b[39mExportTypes\u001b[39m.\u001b[39mPROTOBUF_FILE\n\u001b[1;32m 1612\u001b[0m )\n",
|
||||
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/onnx/utils.py:1135\u001b[0m, in \u001b[0;36m_model_to_graph\u001b[0;34m(model, args, verbose, input_names, output_names, operator_export_type, do_constant_folding, _disable_torch_constant_prop, fixed_batch_size, training, dynamic_axes)\u001b[0m\n\u001b[1;32m 1132\u001b[0m args \u001b[39m=\u001b[39m (args,)\n\u001b[1;32m 1134\u001b[0m model \u001b[39m=\u001b[39m _pre_trace_quant_model(model, args)\n\u001b[0;32m-> 1135\u001b[0m graph, params, torch_out, module \u001b[39m=\u001b[39m _create_jit_graph(model, args)\n\u001b[1;32m 1136\u001b[0m params_dict \u001b[39m=\u001b[39m _get_named_param_dict(graph, params)\n\u001b[1;32m 1138\u001b[0m \u001b[39mtry\u001b[39;00m:\n",
|
||||
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/onnx/utils.py:1011\u001b[0m, in \u001b[0;36m_create_jit_graph\u001b[0;34m(model, args)\u001b[0m\n\u001b[1;32m 1006\u001b[0m graph \u001b[39m=\u001b[39m _C\u001b[39m.\u001b[39m_propagate_and_assign_input_shapes(\n\u001b[1;32m 1007\u001b[0m graph, flattened_args, param_count_list, \u001b[39mFalse\u001b[39;00m, \u001b[39mFalse\u001b[39;00m\n\u001b[1;32m 1008\u001b[0m )\n\u001b[1;32m 1009\u001b[0m \u001b[39mreturn\u001b[39;00m graph, params, torch_out, \u001b[39mNone\u001b[39;00m\n\u001b[0;32m-> 1011\u001b[0m graph, torch_out \u001b[39m=\u001b[39m _trace_and_get_graph_from_model(model, args)\n\u001b[1;32m 1012\u001b[0m _C\u001b[39m.\u001b[39m_jit_pass_onnx_lint(graph)\n\u001b[1;32m 1013\u001b[0m state_dict \u001b[39m=\u001b[39m torch\u001b[39m.\u001b[39mjit\u001b[39m.\u001b[39m_unique_state_dict(model)\n",
|
||||
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/onnx/utils.py:915\u001b[0m, in \u001b[0;36m_trace_and_get_graph_from_model\u001b[0;34m(model, args)\u001b[0m\n\u001b[1;32m 913\u001b[0m prev_autocast_cache_enabled \u001b[39m=\u001b[39m torch\u001b[39m.\u001b[39mis_autocast_cache_enabled()\n\u001b[1;32m 914\u001b[0m torch\u001b[39m.\u001b[39mset_autocast_cache_enabled(\u001b[39mFalse\u001b[39;00m)\n\u001b[0;32m--> 915\u001b[0m trace_graph, torch_out, inputs_states \u001b[39m=\u001b[39m torch\u001b[39m.\u001b[39;49mjit\u001b[39m.\u001b[39;49m_get_trace_graph(\n\u001b[1;32m 916\u001b[0m model,\n\u001b[1;32m 917\u001b[0m args,\n\u001b[1;32m 918\u001b[0m strict\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[1;32m 919\u001b[0m _force_outplace\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[1;32m 920\u001b[0m _return_inputs_states\u001b[39m=\u001b[39;49m\u001b[39mTrue\u001b[39;49;00m,\n\u001b[1;32m 921\u001b[0m )\n\u001b[1;32m 922\u001b[0m torch\u001b[39m.\u001b[39mset_autocast_cache_enabled(prev_autocast_cache_enabled)\n\u001b[1;32m 924\u001b[0m warn_on_static_input_change(inputs_states)\n",
|
||||
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/jit/_trace.py:1285\u001b[0m, in \u001b[0;36m_get_trace_graph\u001b[0;34m(f, args, kwargs, strict, _force_outplace, return_inputs, _return_inputs_states)\u001b[0m\n\u001b[1;32m 1283\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39misinstance\u001b[39m(args, \u001b[39mtuple\u001b[39m):\n\u001b[1;32m 1284\u001b[0m args \u001b[39m=\u001b[39m (args,)\n\u001b[0;32m-> 1285\u001b[0m outs \u001b[39m=\u001b[39m ONNXTracedModule(\n\u001b[1;32m 1286\u001b[0m f, strict, _force_outplace, return_inputs, _return_inputs_states\n\u001b[1;32m 1287\u001b[0m )(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m 1288\u001b[0m \u001b[39mreturn\u001b[39;00m outs\n",
|
||||
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/module.py:1518\u001b[0m, in \u001b[0;36mModule._wrapped_call_impl\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1516\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_compiled_call_impl(\u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs) \u001b[39m# type: ignore[misc]\u001b[39;00m\n\u001b[1;32m 1517\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m-> 1518\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_call_impl(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
|
||||
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/module.py:1527\u001b[0m, in \u001b[0;36mModule._call_impl\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1522\u001b[0m \u001b[39m# If we don't have any hooks, we want to skip the rest of the logic in\u001b[39;00m\n\u001b[1;32m 1523\u001b[0m \u001b[39m# this function, and just call forward.\u001b[39;00m\n\u001b[1;32m 1524\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m (\u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_backward_hooks \u001b[39mor\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_backward_pre_hooks \u001b[39mor\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_forward_hooks \u001b[39mor\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_forward_pre_hooks\n\u001b[1;32m 1525\u001b[0m \u001b[39mor\u001b[39;00m _global_backward_pre_hooks \u001b[39mor\u001b[39;00m _global_backward_hooks\n\u001b[1;32m 1526\u001b[0m \u001b[39mor\u001b[39;00m _global_forward_hooks \u001b[39mor\u001b[39;00m _global_forward_pre_hooks):\n\u001b[0;32m-> 1527\u001b[0m \u001b[39mreturn\u001b[39;00m forward_call(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m 1529\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m 1530\u001b[0m result \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m\n",
|
||||
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/jit/_trace.py:133\u001b[0m, in \u001b[0;36mONNXTracedModule.forward\u001b[0;34m(self, *args)\u001b[0m\n\u001b[1;32m 130\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 131\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mtuple\u001b[39m(out_vars)\n\u001b[0;32m--> 133\u001b[0m graph, out \u001b[39m=\u001b[39m torch\u001b[39m.\u001b[39;49m_C\u001b[39m.\u001b[39;49m_create_graph_by_tracing(\n\u001b[1;32m 134\u001b[0m wrapper,\n\u001b[1;32m 135\u001b[0m in_vars \u001b[39m+\u001b[39;49m module_state,\n\u001b[1;32m 136\u001b[0m _create_interpreter_name_lookup_fn(),\n\u001b[1;32m 137\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mstrict,\n\u001b[1;32m 138\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_force_outplace,\n\u001b[1;32m 139\u001b[0m )\n\u001b[1;32m 141\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_return_inputs:\n\u001b[1;32m 142\u001b[0m \u001b[39mreturn\u001b[39;00m graph, outs[\u001b[39m0\u001b[39m], ret_inputs[\u001b[39m0\u001b[39m]\n",
|
||||
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/jit/_trace.py:124\u001b[0m, in \u001b[0;36mONNXTracedModule.forward.<locals>.wrapper\u001b[0;34m(*args)\u001b[0m\n\u001b[1;32m 122\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_return_inputs_states:\n\u001b[1;32m 123\u001b[0m inputs_states\u001b[39m.\u001b[39mappend(_unflatten(in_args, in_desc))\n\u001b[0;32m--> 124\u001b[0m outs\u001b[39m.\u001b[39mappend(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49minner(\u001b[39m*\u001b[39;49mtrace_inputs))\n\u001b[1;32m 125\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_return_inputs_states:\n\u001b[1;32m 126\u001b[0m inputs_states[\u001b[39m0\u001b[39m] \u001b[39m=\u001b[39m (inputs_states[\u001b[39m0\u001b[39m], trace_inputs)\n",
|
||||
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/module.py:1518\u001b[0m, in \u001b[0;36mModule._wrapped_call_impl\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1516\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_compiled_call_impl(\u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs) \u001b[39m# type: ignore[misc]\u001b[39;00m\n\u001b[1;32m 1517\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m-> 1518\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_call_impl(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
|
||||
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/module.py:1527\u001b[0m, in \u001b[0;36mModule._call_impl\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1522\u001b[0m \u001b[39m# If we don't have any hooks, we want to skip the rest of the logic in\u001b[39;00m\n\u001b[1;32m 1523\u001b[0m \u001b[39m# this function, and just call forward.\u001b[39;00m\n\u001b[1;32m 1524\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m (\u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_backward_hooks \u001b[39mor\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_backward_pre_hooks \u001b[39mor\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_forward_hooks \u001b[39mor\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_forward_pre_hooks\n\u001b[1;32m 1525\u001b[0m \u001b[39mor\u001b[39;00m _global_backward_pre_hooks \u001b[39mor\u001b[39;00m _global_backward_hooks\n\u001b[1;32m 1526\u001b[0m \u001b[39mor\u001b[39;00m _global_forward_hooks \u001b[39mor\u001b[39;00m _global_forward_pre_hooks):\n\u001b[0;32m-> 1527\u001b[0m \u001b[39mreturn\u001b[39;00m forward_call(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m 1529\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m 1530\u001b[0m result \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m\n",
|
||||
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/module.py:1508\u001b[0m, in \u001b[0;36mModule._slow_forward\u001b[0;34m(self, *input, **kwargs)\u001b[0m\n\u001b[1;32m 1506\u001b[0m recording_scopes \u001b[39m=\u001b[39m \u001b[39mFalse\u001b[39;00m\n\u001b[1;32m 1507\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m-> 1508\u001b[0m result \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mforward(\u001b[39m*\u001b[39;49m\u001b[39minput\u001b[39;49m, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m 1509\u001b[0m \u001b[39mfinally\u001b[39;00m:\n\u001b[1;32m 1510\u001b[0m \u001b[39mif\u001b[39;00m recording_scopes:\n",
|
||||
"Cell \u001b[0;32mIn[37], line 18\u001b[0m, in \u001b[0;36mprover_model.forward\u001b[0;34m(self, X, Y)\u001b[0m\n\u001b[1;32m 16\u001b[0m y_mean_cons \u001b[39m=\u001b[39m torch\u001b[39m.\u001b[39mabs(torch\u001b[39m.\u001b[39msum(Y)\u001b[39m-\u001b[39mY\u001b[39m.\u001b[39msize()[\u001b[39m1\u001b[39m]\u001b[39m*\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39my_mean))\u001b[39m<\u001b[39m\u001b[39m0.01\u001b[39m\u001b[39m*\u001b[39mY\u001b[39m.\u001b[39msize()[\u001b[39m1\u001b[39m]\u001b[39m*\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39my_mean)\n\u001b[1;32m 17\u001b[0m x_var_cons \u001b[39m=\u001b[39m torch\u001b[39m.\u001b[39mabs(torch\u001b[39m.\u001b[39msum((X\u001b[39m-\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mx_mean)\u001b[39m*\u001b[39m(X\u001b[39m-\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mx_mean))\u001b[39m-\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mx_var\u001b[39m*\u001b[39m(X\u001b[39m.\u001b[39msize()[\u001b[39m1\u001b[39m]\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m))\u001b[39m<\u001b[39m\u001b[39m0.01\u001b[39m\u001b[39m*\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mx_var\u001b[39m*\u001b[39m(X\u001b[39m.\u001b[39msize()[\u001b[39m1\u001b[39m]\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m)\n\u001b[0;32m---> 18\u001b[0m x_var \u001b[39m=\u001b[39m torch\u001b[39m.\u001b[39;49mvar(X, correction\u001b[39m=\u001b[39;49m\u001b[39m1\u001b[39;49m)\n\u001b[1;32m 19\u001b[0m y_var_cons \u001b[39m=\u001b[39m torch\u001b[39m.\u001b[39mabs(torch\u001b[39m.\u001b[39msum((Y\u001b[39m-\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39my_mean)\u001b[39m*\u001b[39m(Y\u001b[39m-\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39my_mean))\u001b[39m-\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39my_var\u001b[39m*\u001b[39m(Y\u001b[39m.\u001b[39msize()[\u001b[39m1\u001b[39m]\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m))\u001b[39m<\u001b[39m\u001b[39m0.01\u001b[39m\u001b[39m*\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39my_var\u001b[39m*\u001b[39m(Y\u001b[39m.\u001b[39msize()[\u001b[39m1\u001b[39m]\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m)\n\u001b[1;32m 20\u001b[0m corr_cons \u001b[39m=\u001b[39m torch\u001b[39m.\u001b[39mabs(torch\u001b[39m.\u001b[39msum((X\u001b[39m-\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mx_mean)\u001b[39m*\u001b[39m(Y\u001b[39m-\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39my_mean))\u001b[39m-\u001b[39m(torch\u001b[39m.\u001b[39msqrt(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mx_var)\u001b[39m*\u001b[39mtorch\u001b[39m.\u001b[39msqrt(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39my_var)\u001b[39m*\u001b[39mtorch\u001b[39m.\u001b[39mdiv(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mcorr, \u001b[39m100\u001b[39m)))\u001b[39m<\u001b[39m\u001b[39m0.01\u001b[39m\u001b[39m*\u001b[39m(torch\u001b[39m.\u001b[39msqrt(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mx_var)\u001b[39m*\u001b[39mtorch\u001b[39m.\u001b[39msqrt(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39my_var)\u001b[39m*\u001b[39mtorch\u001b[39m.\u001b[39mdiv(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mcorr, \u001b[39m100\u001b[39m))\n",
|
||||
"\u001b[0;31mRuntimeError\u001b[0m: std and var only support floating point and complex dtypes"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Prover/ data owner side\n",
|
||||
"theory_output = torch.tensor(real_corr)\n",
|
||||
"print(\"theory output: \", theory_output)\n",
|
||||
"class prover_model(nn.Module):\n",
|
||||
" def __init__(self):\n",
|
||||
" super(prover_model, self).__init__()\n",
|
||||
" self.corr = nn.Parameter(data = torch.tensor(real_corr*100), requires_grad = False)\n",
|
||||
" self.x_mean = nn.Parameter(data = torch.tensor(x_mean), requires_grad = False)\n",
|
||||
" self.y_mean = nn.Parameter(data = torch.tensor(y_mean), requires_grad = False)\n",
|
||||
" self.x_var = nn.Parameter(data = torch.tensor(x_var), requires_grad = False)\n",
|
||||
" self.y_var = nn.Parameter(data = torch.tensor(y_var), requires_grad = False)\n",
|
||||
" def forward(self,X,Y):\n",
|
||||
" # some expression of tolerance to error in the inference\n",
|
||||
" # need to enforce same length, not yet\n",
|
||||
" x_mean_cons = torch.abs(torch.sum(X)-X.size()[1]*(self.x_mean))<0.01*X.size()[1]*(self.x_mean)\n",
|
||||
" y_mean_cons = torch.abs(torch.sum(Y)-Y.size()[1]*(self.y_mean))<0.01*Y.size()[1]*(self.y_mean)\n",
|
||||
" x_var_cons = torch.abs(torch.sum((X-self.x_mean)*(X-self.x_mean))-self.x_var*(X.size()[1]-1))<0.01*self.x_var*(X.size()[1]-1)\n",
|
||||
" y_var_cons = torch.abs(torch.sum((Y-self.y_mean)*(Y-self.y_mean))-self.y_var*(Y.size()[1]-1))<0.01*self.y_var*(Y.size()[1]-1)\n",
|
||||
" corr_cons = torch.abs(torch.sum((X-self.x_mean)*(Y-self.y_mean))-(torch.sqrt(self.x_var)*torch.sqrt(self.y_var)*torch.div(self.corr, 100)))<0.01*(torch.sqrt(self.x_var)*torch.sqrt(self.y_var)*torch.div(self.corr, 100))\n",
|
||||
"\n",
|
||||
" # return (torch.logical_and(corr_cons, torch.logical_and(torch.logical_and(x_mean_cons, y_mean_cons), torch.logical_and(x_var_cons, y_var_cons))), self.corr)\n",
|
||||
" # return (torch.logical_and(corr_cons, torch.logical_and(x_mean_cons, y_mean_cons)), self.corr)\n",
|
||||
" # return (torch.logical_and(torch.logical_and(corr_cons, x_var_cons), torch.logical_and(x_mean_cons, y_mean_cons)), self.corr)\n",
|
||||
" # return (torch.logical_and(x_var_cons,torch.logical_and(corr_cons, torch.logical_and(x_mean_cons, y_mean_cons))), self.corr)\n",
|
||||
" return (torch.logical_and(x_var_cons, corr_cons), self.corr)\n",
|
||||
"prover_gen_settings([x_vals_path, y_vals_path], comb_data_path, prover_model,prover_model_path, [0], \"resources\", settings_path)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 24,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
@@ -412,92 +419,37 @@
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"spawning module 0\n",
|
||||
"spawning module 2\n"
|
||||
"thread '<unnamed>' panicked at src/circuit/ops/region.rs:237:38:\n",
|
||||
"called `Option::unwrap()` on a `None` value\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Time setup: 11.269559860229492 seconds\n"
|
||||
"ename": "PanicException",
|
||||
"evalue": "called `Option::unwrap()` on a `None` value",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mPanicException\u001b[0m Traceback (most recent call last)",
|
||||
"Cell \u001b[0;32mIn[24], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[39m# Here verifier & prover can concurrently call setup since all params are public to get pk. \u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[39m# Here write as verifier function to emphasize that verifier must calculate its own vk to be sure\u001b[39;00m\n\u001b[0;32m----> 3\u001b[0m verifier_setup(verifier_model_path, verifier_compiled_model_path, settings_path, srs_path,vk_path, pk_path )\n\u001b[1;32m 5\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39m\"\u001b[39m\u001b[39m=======================================\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m 6\u001b[0m \u001b[39m# Prover generates proof\u001b[39;00m\n",
|
||||
"File \u001b[0;32m~/Desktop/zk-stats-lib/core.py:117\u001b[0m, in \u001b[0;36mverifier_setup\u001b[0;34m(verifier_model_path, verifier_compiled_model_path, settings_path, srs_path, vk_path, pk_path)\u001b[0m\n\u001b[1;32m 115\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39m\"\u001b[39m\u001b[39m==== setting up ezkl ====\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m 116\u001b[0m start_time \u001b[39m=\u001b[39m time\u001b[39m.\u001b[39mtime()\n\u001b[0;32m--> 117\u001b[0m res \u001b[39m=\u001b[39m ezkl\u001b[39m.\u001b[39;49msetup(\n\u001b[1;32m 118\u001b[0m verifier_compiled_model_path,\n\u001b[1;32m 119\u001b[0m vk_path,\n\u001b[1;32m 120\u001b[0m pk_path,\n\u001b[1;32m 121\u001b[0m srs_path)\n\u001b[1;32m 122\u001b[0m end_time \u001b[39m=\u001b[39m time\u001b[39m.\u001b[39mtime()\n\u001b[1;32m 123\u001b[0m time_setup \u001b[39m=\u001b[39m end_time \u001b[39m-\u001b[39mstart_time\n",
|
||||
"\u001b[0;31mPanicException\u001b[0m: called `Option::unwrap()` on a `None` value"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Verifier/ data consumer side:\n",
|
||||
"class verifier_model(nn.Module):\n",
|
||||
" def __init__(self):\n",
|
||||
" super(verifier_model, self).__init__()\n",
|
||||
" self.corr = nn.Parameter(data = torch.tensor(dummy_corr), requires_grad = False)\n",
|
||||
" self.x_mean = nn.Parameter(data = torch.tensor(dummy_x_mean), requires_grad = False)\n",
|
||||
" self.y_mean = nn.Parameter(data = torch.tensor(dummy_y_mean), requires_grad = False)\n",
|
||||
" self.x_var = nn.Parameter(data = torch.tensor(dummy_x_var), requires_grad = False)\n",
|
||||
" self.y_var = nn.Parameter(data = torch.tensor(dummy_y_var), requires_grad = False)\n",
|
||||
" def forward(self,X,Y):\n",
|
||||
" # some expression of tolerance to error in the inference\n",
|
||||
" print(\"right side: \", torch.sum((X-self.x_mean)*(Y-self.y_mean))*torch.sum((X-self.x_mean)*(Y-self.y_mean)))\n",
|
||||
" print(\"left side: \",torch.sum((X-self.x_mean)*(X-self.x_mean))*torch.sum((Y-self.y_mean)*(Y-self.y_mean))*self.corr*self.corr )\n",
|
||||
" # need to enforce same length, not yet\n",
|
||||
" # return (torch.logical_and(torch.logical_and(torch.abs(torch.sum(X)-X.size()[1]*(self.x_mean))<0.01*torch.sum(X), torch.abs(torch.sum(Y)-Y.size()[1]*(self.y_mean))<0.01*torch.sum(Y)), torch.abs(torch.sum((X-self.x_mean)*(Y-self.y_mean))*torch.sum((X-self.x_mean)*(Y-self.y_mean))-torch.sum((X-self.x_mean)*(X-self.x_mean))*torch.sum((Y-self.y_mean)*(Y-self.y_mean))*self.corr*self.corr)<0.01*torch.sum((X-self.x_mean)*(Y-self.y_mean))*torch.sum((X-self.x_mean)*(Y-self.y_mean))), self.corr)\n",
|
||||
" # return (torch.abs(torch.sum((X-self.x_mean)*(Y-self.y_mean))*torch.sum((X-self.x_mean)*(Y-self.y_mean))-self.x_var*self.y_var*self.corr*self.corr)<0.01*torch.sum((X-self.x_mean)*(Y-self.y_mean))*torch.sum((X-self.x_mean)*(Y-self.y_mean)), self.corr)\n",
|
||||
" return (torch.abs(2*torch.log(torch.sum((X-self.x_mean)*(Y-self.y_mean)))-(torch.log(self.x_var)+torch.log(self.y_var)+2*torch.log(self.corr*self.corr)))<0.01*2*torch.log(torch.sum((X-self.x_mean)*(Y-self.y_mean))), self.corr)\n",
|
||||
"# 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",
|
||||
"\n",
|
||||
"verifier_init(verifier_model, verifier_model_path, verifier_compiled_model_path, [dummy_x_vals_path, dummy_y_vals_path], settings_path, srs_path, pk_path, vk_path, [0], \"accuracy\")"
|
||||
"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)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"theory output: tensor(0.8929)\n",
|
||||
"right side: tensor(1.0129e+11, dtype=torch.float64)\n",
|
||||
"left side: tensor(1.0129e+11, dtype=torch.float64)\n",
|
||||
"==== Generating Witness ====\n",
|
||||
"witness boolean: 0.0\n",
|
||||
"witness result 1 : 1.0\n",
|
||||
"==== Generating Proof ====\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"spawning module 0\n",
|
||||
"spawning module 2\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Prover/ data owner side\n",
|
||||
"theory_output = torch.tensor(real_corr)\n",
|
||||
"print(\"theory output: \", theory_output)\n",
|
||||
"class prover_model(nn.Module):\n",
|
||||
" def __init__(self):\n",
|
||||
" super(prover_model, self).__init__()\n",
|
||||
" self.corr = nn.Parameter(data = torch.tensor(real_corr), requires_grad = False)\n",
|
||||
" self.x_mean = nn.Parameter(data = torch.tensor(x_mean), requires_grad = False)\n",
|
||||
" self.y_mean = nn.Parameter(data = torch.tensor(y_mean), requires_grad = False)\n",
|
||||
" self.x_var = nn.Parameter(data = torch.tensor(x_var), requires_grad = False)\n",
|
||||
" self.y_var = nn.Parameter(data = torch.tensor(y_var), requires_grad = False)\n",
|
||||
" def forward(self,X,Y):\n",
|
||||
" # some expression of tolerance to error in the inference\n",
|
||||
" # need to enforce same length, not yet\n",
|
||||
" # return (torch.logical_and(torch.logical_and(torch.abs(torch.sum(X)-X.size()[1]*(self.x_mean))<0.01*torch.sum(X), torch.abs(torch.sum(Y)-Y.size()[1]*(self.y_mean))<0.01*torch.sum(Y)), torch.abs(torch.sum((X-self.x_mean)*(Y-self.y_mean))*torch.sum((X-self.x_mean)*(Y-self.y_mean))-torch.sum((X-self.x_mean)*(X-self.x_mean))*torch.sum((Y-self.y_mean)*(Y-self.y_mean))*self.corr*self.corr)<0.01*torch.sum((X-self.x_mean)*(Y-self.y_mean))*torch.sum((X-self.x_mean)*(Y-self.y_mean))), self.corr)\n",
|
||||
" # return (torch.abs(torch.sum((X-self.x_mean)*(Y-self.y_mean))*torch.sum((X-self.x_mean)*(Y-self.y_mean))-self.x_var*self.y_var*self.corr*self.corr)<0.01*torch.sum((X-self.x_mean)*(Y-self.y_mean))*torch.sum((X-self.x_mean)*(Y-self.y_mean)), self.corr)\n",
|
||||
" return (torch.abs(2*torch.log(torch.sum((X-self.x_mean)*(Y-self.y_mean)))-(torch.log(self.x_var)+torch.log(self.y_var)+2*torch.log(self.corr*self.corr)))<0.01*2*torch.log(torch.sum((X-self.x_mean)*(Y-self.y_mean))), self.corr)\n",
|
||||
"\n",
|
||||
"prover_gen(prover_model, [x_vals_path, y_vals_path], witness_path, prover_model_path, prover_compiled_model_path, settings_path, proof_path)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"execution_count": 20,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -505,9 +457,9 @@
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"num_inputs: 2\n",
|
||||
"prf instances: [[[14955570959218682635, 4667139652385906200, 12836539004462631467, 1774684518626433649], [2636517083442646612, 5059672846326347070, 4705835036930416229, 3312472395716484608], [12436184717236109307, 3962172157175319849, 7381016538464732718, 1011752739694698287], [5743885005642251665, 3430503978676436355, 7149667244725939006, 2902673458086333540]]]\n",
|
||||
"prf instances: [[[14955570959218682635, 4667139652385906200, 12836539004462631467, 1774684518626433649], [4224417983558473805, 851357164555783563, 5363851773531956453, 1448631618362554917], [12436184717236109307, 3962172157175319849, 7381016538464732718, 1011752739694698287], [6856486776492523050, 3509301300289033549, 11286023888431465720, 2871037162753880935]]]\n",
|
||||
"proof boolean: 1.0\n",
|
||||
"proof result 1 : 3215.0\n",
|
||||
"proof result 1 : 89.0\n",
|
||||
"verified\n"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1 +1,12 @@
|
||||
{"input_data": [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]]}
|
||||
{
|
||||
"input_data": [
|
||||
[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
|
||||
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
|
||||
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
|
||||
57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
|
||||
75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
|
||||
93, 94, 95, 96, 97, 98, 99
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1 +1,17 @@
|
||||
{"input_data": [[124.09399070683597, -37.122697540682225, 80.21221552102804, 62.13409539637114, 0.20399163314000646, 45.790227611829025, 49.20187473673988, 105.67632769906695, 159.44458038353153, 135.96637051811052, 141.5628072636904, 64.51163930838622, 9.559841949088494, 116.32572841932554, 8.94172979233771, 70.32335026736132, 79.544771598796, 33.520446900379454, 123.45042524563256, 79.17153837839723, 185.37994376611474, 113.50092583906918, 32.73987944307804, 204.2320753142401, 130.2652303660729, 76.63209097408668, 106.42202318455051, 191.19285291212267, 202.93009712588972, 212.25782087550996, 146.63510746550338, 161.90654974414394, 203.83655819003104, 160.0946424049401, 124.30633572286364, 200.52494440617804, 220.16531742773788, 117.14219198294175, 270.7106847163913, 232.61716005294167, 152.37425252152565, 137.62536824894235, 145.49709430931318, 290.3828790554155, 210.03456605036945, 305.24837279035467, 161.26275938184514, 213.91779815160288, 126.23234910050124, 166.7884726557922, 174.65790678687696, 252.52501466880204, 229.94372028329548, 307.2055187533065, 190.17162149105098, 250.21519881336474, 215.20457862472557, 195.99749926633234, 195.60593663586766, 250.2265164779991, 318.48033068248515, 235.65189074495507, 178.28299334219457, 200.53845306589974, 293.7841832622702, 243.94519787326388, 319.71826475040456, 255.915347924076, 313.5161577076917, 376.3558273624361, 304.54065640356254, 327.65318486942505, 317.20641225928705, 413.6205341065968, 400.08746392469124, 347.7061064020289, 333.17527997349356, 302.6425121523407, 308.0844867063057, 430.21905751892314, 268.84619012450156, 367.58250168144355, 402.198370488393, 274.009234859437, 460.2746495714749, 442.8359115200344, 280.6537635212046, 448.92999840532474, 345.6406602817736, 384.94125085483284, 438.06020481702996, 457.2572992756619, 337.6030356913139, 303.74113539114404, 345.5681408263937, 494.3801926252247, 450.31132730424827, 383.4852738474566, 353.10605195804726, 392.6126762481633]]}
|
||||
{
|
||||
"input_data": [
|
||||
[
|
||||
124.09, -37.12, 80.21, 62.13, 0.2, 45.79, 49.2, 105.68, 159.44, 135.97,
|
||||
141.56, 64.51, 9.56, 116.33, 8.94, 70.32, 79.54, 33.52, 123.45, 79.17,
|
||||
185.38, 113.5, 32.74, 204.23, 130.27, 76.63, 106.42, 191.19, 202.93,
|
||||
212.26, 146.64, 161.91, 203.84, 160.09, 124.31, 200.52, 220.17, 117.14,
|
||||
270.71, 232.62, 152.37, 137.63, 145.5, 290.38, 210.03, 305.25, 161.26,
|
||||
213.92, 126.23, 166.79, 174.66, 252.53, 229.94, 307.21, 190.17, 250.22,
|
||||
215.2, 196.0, 195.61, 250.23, 318.48, 235.65, 178.28, 200.54, 293.78,
|
||||
243.95, 319.72, 255.92, 313.52, 376.36, 304.54, 327.65, 317.21, 413.62,
|
||||
400.09, 347.71, 333.18, 302.64, 308.08, 430.22, 268.85, 367.58, 402.2,
|
||||
274.01, 460.27, 442.84, 280.65, 448.93, 345.64, 384.94, 438.06, 457.26,
|
||||
337.6, 303.74, 345.57, 494.38, 450.31, 383.49, 353.11, 392.61
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1 +1,17 @@
|
||||
{"input_data": [[124.09399070683597, -37.122697540682225, 80.21221552102804, 62.13409539637114, 0.20399163314000646, 45.790227611829025, 49.20187473673988, 105.67632769906695, 159.44458038353153, 135.96637051811052, 141.5628072636904, 64.51163930838622, 9.559841949088494, 116.32572841932554, 8.94172979233771, 70.32335026736132, 79.544771598796, 33.520446900379454, 123.45042524563256, 79.17153837839723, 185.37994376611474, 113.50092583906918, 32.73987944307804, 204.2320753142401, 130.2652303660729, 76.63209097408668, 106.42202318455051, 191.19285291212267, 202.93009712588972, 212.25782087550996, 146.63510746550338, 161.90654974414394, 203.83655819003104, 160.0946424049401, 124.30633572286364, 200.52494440617804, 220.16531742773788, 117.14219198294175, 270.7106847163913, 232.61716005294167, 152.37425252152565, 137.62536824894235, 145.49709430931318, 290.3828790554155, 210.03456605036945, 305.24837279035467, 161.26275938184514, 213.91779815160288, 126.23234910050124, 166.7884726557922, 174.65790678687696, 252.52501466880204, 229.94372028329548, 307.2055187533065, 190.17162149105098, 250.21519881336474, 215.20457862472557, 195.99749926633234, 195.60593663586766, 250.2265164779991, 318.48033068248515, 235.65189074495507, 178.28299334219457, 200.53845306589974, 293.7841832622702, 243.94519787326388, 319.71826475040456, 255.915347924076, 313.5161577076917, 376.3558273624361, 304.54065640356254, 327.65318486942505, 317.20641225928705, 413.6205341065968, 400.08746392469124, 347.7061064020289, 333.17527997349356, 302.6425121523407, 308.0844867063057, 430.21905751892314, 268.84619012450156, 367.58250168144355, 402.198370488393, 274.009234859437, 460.2746495714749, 442.8359115200344, 280.6537635212046, 448.92999840532474, 345.6406602817736, 384.94125085483284, 438.06020481702996, 457.2572992756619, 337.6030356913139, 303.74113539114404, 345.5681408263937, 494.3801926252247, 450.31132730424827, 383.4852738474566, 353.10605195804726, 392.6126762481633]]}
|
||||
{
|
||||
"input_data": [
|
||||
[
|
||||
124.09, -37.12, 80.21, 62.13, 0.2, 45.79, 49.2, 105.68, 159.44, 135.97,
|
||||
141.56, 64.51, 9.56, 116.33, 8.94, 70.32, 79.54, 33.52, 123.45, 79.17,
|
||||
185.38, 113.5, 32.74, 204.23, 130.27, 76.63, 106.42, 191.19, 202.93,
|
||||
212.26, 146.64, 161.91, 203.84, 160.09, 124.31, 200.52, 220.17, 117.14,
|
||||
270.71, 232.62, 152.37, 137.63, 145.5, 290.38, 210.03, 305.25, 161.26,
|
||||
213.92, 126.23, 166.79, 174.66, 252.53, 229.94, 307.21, 190.17, 250.22,
|
||||
215.2, 196.0, 195.61, 250.23, 318.48, 235.65, 178.28, 200.54, 293.78,
|
||||
243.95, 319.72, 255.92, 313.52, 376.36, 304.54, 327.65, 317.21, 413.62,
|
||||
400.09, 347.71, 333.18, 302.64, 308.08, 430.22, 268.85, 367.58, 402.2,
|
||||
274.01, 460.27, 442.84, 280.65, 448.93, 345.64, 384.94, 438.06, 457.26,
|
||||
337.6, 303.74, 345.57, 494.38, 450.31, 383.49, 353.11, 392.61
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
31
examples/median/data.json
Normal file
31
examples/median/data.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"input_data": [
|
||||
[
|
||||
33.0, 75.0, 38.0, 38.0, 70.0, 44.0, 34.0, 67.0, 54.0, 78.0, 80.0, 21.0,
|
||||
41.0, 47.0, 57.0, 50.0, 65.0, 43.0, 51.0, 54.0, 62.0, 68.0, 45.0, 39.0,
|
||||
51.0, 48.0, 48.0, 42.0, 37.0, 75.0, 40.0, 48.0, 65.0, 26.0, 42.0, 53.0,
|
||||
51.0, 56.0, 74.0, 54.0, 55.0, 15.0, 58.0, 46.0, 64.0, 59.0, 39.0, 36.0,
|
||||
62.0, 39.0, 72.0, 32.0, 82.0, 76.0, 88.0, 51.0, 44.0, 35.0, 18.0, 53.0,
|
||||
52.0, 45.0, 64.0, 31.0, 32.0, 61.0, 66.0, 59.0, 50.0, 69.0, 44.0, 22.0,
|
||||
45.0, 45.0, 46.0, 42.0, 83.0, 53.0, 53.0, 69.0, 53.0, 33.0, 48.0, 49.0,
|
||||
34.0, 66.0, 29.0, 66.0, 52.0, 45.0, 83.0, 54.0, 53.0, 31.0, 71.0, 60.0,
|
||||
30.0, 33.0, 43.0, 26.0, 55.0, 56.0, 56.0, 54.0, 57.0, 68.0, 58.0, 61.0,
|
||||
62.0, 38.0, 52.0, 74.0, 76.0, 37.0, 42.0, 54.0, 38.0, 38.0, 30.0, 31.0,
|
||||
52.0, 41.0, 69.0, 40.0, 46.0, 69.0, 29.0, 28.0, 66.0, 41.0, 40.0, 36.0,
|
||||
52.0, 58.0, 46.0, 42.0, 85.0, 45.0, 70.0, 49.0, 48.0, 34.0, 18.0, 39.0,
|
||||
64.0, 46.0, 54.0, 42.0, 45.0, 64.0, 46.0, 68.0, 46.0, 54.0, 47.0, 41.0,
|
||||
69.0, 27.0, 61.0, 37.0, 25.0, 66.0, 30.0, 59.0, 67.0, 34.0, 36.0, 40.0,
|
||||
55.0, 58.0, 74.0, 55.0, 66.0, 55.0, 72.0, 40.0, 27.0, 38.0, 74.0, 52.0,
|
||||
45.0, 40.0, 35.0, 46.0, 64.0, 41.0, 50.0, 45.0, 42.0, 22.0, 25.0, 55.0,
|
||||
39.0, 58.0, 56.0, 62.0, 55.0, 65.0, 57.0, 34.0, 44.0, 47.0, 70.0, 60.0,
|
||||
34.0, 50.0, 43.0, 60.0, 66.0, 46.0, 58.0, 76.0, 40.0, 49.0, 64.0, 45.0,
|
||||
22.0, 50.0, 34.0, 44.0, 76.0, 63.0, 59.0, 36.0, 59.0, 47.0, 70.0, 64.0,
|
||||
44.0, 55.0, 50.0, 48.0, 66.0, 40.0, 76.0, 48.0, 75.0, 73.0, 55.0, 41.0,
|
||||
43.0, 50.0, 34.0, 57.0, 50.0, 53.0, 28.0, 35.0, 52.0, 52.0, 49.0, 67.0,
|
||||
41.0, 41.0, 61.0, 24.0, 43.0, 51.0, 40.0, 52.0, 44.0, 25.0, 81.0, 54.0,
|
||||
64.0, 76.0, 37.0, 45.0, 48.0, 46.0, 43.0, 67.0, 28.0, 35.0, 25.0, 71.0,
|
||||
50.0, 31.0, 43.0, 54.0, 40.0, 51.0, 40.0, 49.0, 34.0, 26.0, 46.0, 62.0,
|
||||
40.0, 25.0, 61.0, 58.0, 56.0, 39.0, 46.0, 53.0, 21.0, 57.0, 42.0, 80.0
|
||||
]
|
||||
]
|
||||
}
|
||||
435
examples/median/median.ipynb
Normal file
435
examples/median/median.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
@@ -157,7 +157,7 @@
|
||||
" def forward(self,X):\n",
|
||||
" # some expression of tolerance to error in the inference\n",
|
||||
" x_mean_cons = torch.abs(torch.sum(X)-X.size()[1]*(self.data_mean))<0.01*X.size()[1]*(self.data_mean)\n",
|
||||
" return (torch.logical_and(torch.abs(torch.sum((X-self.data_mean)*(X-self.data_mean))-self.w*self.w*(X.size()[1]-1))<0.01*self.w*self.w*(X.size()[1]-1),x_mean_cons),self.w)\n",
|
||||
" return (torch.logical_and(torch.abs(torch.sum((X-self.data_mean)*(X-self.data_mean))-self.w*self.w*(X.size()[1]-1))<0.02*self.w*self.w*(X.size()[1]-1),x_mean_cons),self.w)\n",
|
||||
"\n",
|
||||
"verifier_define_calculation(verifier_model, verifier_model_path, [dummy_data_path])"
|
||||
]
|
||||
@@ -192,7 +192,7 @@
|
||||
" def forward(self,X):\n",
|
||||
" # some expression of tolerance to error in the inference\n",
|
||||
" x_mean_cons = torch.abs(torch.sum(X)-X.size()[1]*(self.data_mean))<0.01*X.size()[1]*(self.data_mean)\n",
|
||||
" return (torch.logical_and(torch.abs(torch.sum((X-self.data_mean)*(X-self.data_mean))-self.w*self.w*(X.size()[1]-1))<0.01*self.w*self.w*(X.size()[1]-1),x_mean_cons),self.w)\n",
|
||||
" return (torch.logical_and(torch.abs(torch.sum((X-self.data_mean)*(X-self.data_mean))-self.w*self.w*(X.size()[1]-1))<0.02*self.w*self.w*(X.size()[1]-1),x_mean_cons),self.w)\n",
|
||||
"\n",
|
||||
"prover_gen_settings([data_path], comb_data_path, prover_model,prover_model_path, [0], \"resources\", settings_path)"
|
||||
]
|
||||
|
||||
9
playground.py
Normal file
9
playground.py
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
# just for testing simple code stuffs
|
||||
input = [124.09399070683597, -37.122697540682225, 80.21221552102804, 62.13409539637114, 0.20399163314000646, 45.790227611829025, 49.20187473673988, 105.67632769906695, 159.44458038353153, 135.96637051811052, 141.5628072636904, 64.51163930838622, 9.559841949088494, 116.32572841932554, 8.94172979233771, 70.32335026736132, 79.544771598796, 33.520446900379454, 123.45042524563256, 79.17153837839723, 185.37994376611474, 113.50092583906918, 32.73987944307804, 204.2320753142401, 130.2652303660729, 76.63209097408668, 106.42202318455051, 191.19285291212267, 202.93009712588972, 212.25782087550996, 146.63510746550338, 161.90654974414394, 203.83655819003104, 160.0946424049401, 124.30633572286364, 200.52494440617804, 220.16531742773788, 117.14219198294175, 270.7106847163913, 232.61716005294167, 152.37425252152565, 137.62536824894235, 145.49709430931318, 290.3828790554155, 210.03456605036945, 305.24837279035467, 161.26275938184514, 213.91779815160288, 126.23234910050124, 166.7884726557922, 174.65790678687696, 252.52501466880204, 229.94372028329548, 307.2055187533065, 190.17162149105098, 250.21519881336474, 215.20457862472557, 195.99749926633234, 195.60593663586766, 250.2265164779991, 318.48033068248515, 235.65189074495507, 178.28299334219457, 200.53845306589974, 293.7841832622702, 243.94519787326388, 319.71826475040456, 255.915347924076, 313.5161577076917, 376.3558273624361, 304.54065640356254, 327.65318486942505, 317.20641225928705, 413.6205341065968, 400.08746392469124, 347.7061064020289, 333.17527997349356, 302.6425121523407, 308.0844867063057, 430.21905751892314, 268.84619012450156, 367.58250168144355, 402.198370488393, 274.009234859437, 460.2746495714749, 442.8359115200344, 280.6537635212046, 448.92999840532474, 345.6406602817736, 384.94125085483284, 438.06020481702996, 457.2572992756619, 337.6030356913139, 303.74113539114404, 345.5681408263937, 494.3801926252247, 450.31132730424827, 383.4852738474566, 353.10605195804726, 392.6126762481633]
|
||||
|
||||
new_input = []
|
||||
for ele in input:
|
||||
new_input.append(round(ele,2))
|
||||
|
||||
print(new_input)
|
||||
Reference in New Issue
Block a user