diff --git a/eth/demo.ipynb b/eth/demo.ipynb index 1f61cb7..547e997 100644 --- a/eth/demo.ipynb +++ b/eth/demo.ipynb @@ -3,7 +3,7 @@ { "cell_type": "code", "execution_count": 1, - "id": "a5691c85", + "id": "d67e4546", "metadata": {}, "outputs": [], "source": [ @@ -18,7 +18,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "f7a41f4f", + "id": "c50ceb61", "metadata": {}, "outputs": [], "source": [ @@ -44,7 +44,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "2138ebc4", + "id": "b19d3ed1", "metadata": {}, "outputs": [ { @@ -85,7 +85,7 @@ { "cell_type": "code", "execution_count": 4, - "id": "827a379e", + "id": "c753219e", "metadata": {}, "outputs": [ { @@ -105,7 +105,7 @@ { "cell_type": "code", "execution_count": 5, - "id": "3b9d3002", + "id": "93515c3a", "metadata": {}, "outputs": [], "source": [ @@ -118,7 +118,7 @@ { "cell_type": "code", "execution_count": 6, - "id": "97c69fba", + "id": "94b24907", "metadata": {}, "outputs": [ { @@ -139,7 +139,7 @@ { "cell_type": "code", "execution_count": 7, - "id": "4bbca5b0", + "id": "ffac2ddb", "metadata": {}, "outputs": [], "source": [ @@ -151,7 +151,7 @@ { "cell_type": "code", "execution_count": 8, - "id": "add9e6ca", + "id": "cc826e58", "metadata": {}, "outputs": [ { @@ -183,7 +183,7 @@ { "cell_type": "code", "execution_count": 9, - "id": "10e128e2", + "id": "863ac375", "metadata": {}, "outputs": [], "source": [ @@ -191,18 +191,25 @@ "\n", "alpha_X = 0\n", "beta_X = 8\n", + "\n", "alpha_W = -1\n", - "beta_W = 1\n", - "alpha_Y = 2\n", + "beta_W = 8\n", + "\n", + "alpha_Y = 0\n", "beta_Y = 8\n", - "alpha_Yt = 2\n", + "\n", + "alpha_Yt = 0\n", "beta_Yt = 8\n", + "\n", "alpha_b = 0\n", "beta_b = 8\n", + "\n", "alpha_R = -1\n", "beta_R = 1\n", + "\n", "alpha_S = 0\n", "beta_S = 0.4\n", + "\n", "m = 20\n", "p = 4\n", "n = 1" @@ -211,7 +218,7 @@ { "cell_type": "code", "execution_count": 10, - "id": "8e0375e9", + "id": "dc953a1b", "metadata": {}, "outputs": [ { @@ -224,16 +231,8 @@ "mse assertion passed\n", "Mean Squared Error actual: 0.1123029571353145\n", "quantized 18403\n", - "Mean Squared Error simulated: 0.11229933467618874454\n", - "quantized 18402\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/liaopeiyuan/Documents/GitHub/zkml-core/eth/scripts/quantize_model.py:19: UserWarning: Results are negative, circom may not be happy\n", - " warnings.warn(\"Results are negative, circom may not be happy\")\n" + "Mean Squared Error simulated: 0.11232375022889581895\n", + "quantized 18406\n" ] } ], @@ -252,7 +251,7 @@ { "cell_type": "code", "execution_count": 11, - "id": "f5f109a0", + "id": "c82fd740", "metadata": {}, "outputs": [], "source": [ @@ -270,7 +269,7 @@ { "cell_type": "code", "execution_count": null, - "id": "0c402cfd", + "id": "ca9063d9", "metadata": {}, "outputs": [], "source": [] diff --git a/eth/quantized_dataset.json b/eth/quantized_dataset.json index 6cea1bc..c158f40 100644 --- a/eth/quantized_dataset.json +++ b/eth/quantized_dataset.json @@ -1,74 +1,74 @@ { - "out": 18402, + "out": 18844, "sR2sSq_numerator": 5, "sR2sSq_denominator": 32766, "z_R": 32770, "z_Sq": 4, "Yt_q": [ [ - 38231 + 45057 ], [ - 37139 + 44238 ], [ - 32770 + 40962 ], [ - 56798 + 58983 ], [ - 54614 + 57344 ], [ - 46969 + 51610 ], [ - 45876 + 50791 ], [ - 38231 + 45057 ], [ - 46969 + 51610 ], [ - 31678 + 40142 ], [ - 49153 + 53249 ], [ - 34954 + 42600 ], [ - 37139 + 44238 ], [ - 62259 + 63079 ], [ - 44784 + 49972 ], [ - 48061 + 52430 ], [ - 39323 + 45876 ], [ - 40415 + 46696 ], [ - 26217 + 36047 ], [ - 44784 + 49972 ] ], - "sYsR_numerator": 3, + "sYsR_numerator": 4, "sYsR_denominator": 1, - "sYtsR_numerator": 3, + "sYtsR_numerator": 4, "sYtsR_denominator": 1, "constant": 32770, "X_q": [ @@ -193,31 +193,12 @@ 16387 ] ], - "W_q": [ - [ - 54097 - ], - [ - 57560 - ], - [ - 16638 - ], - [ - 27056 - ] - ], - "b_q": [ - [ - 14438 - ] - ], "z_X": 4, - "z_W": 32770, + "z_W": 7285, "z_b": 4, - "z_Y": 21888242871839275222246405745257275088548364400416034343698204186575808517457, - "sbsY_numerator": 4, - "sbsY_denominator": 3, - "sXsWsY_numerator": 2, - "sXsWsY_denominator": 49149 + "z_Y": 4, + "sbsY_numerator": 1, + "sbsY_denominator": 1, + "sXsWsY_numerator": 3, + "sXsWsY_denominator": 21844 } \ No newline at end of file diff --git a/eth/quantized_model.json b/eth/quantized_model.json index 960fca6..2314755 100644 --- a/eth/quantized_model.json +++ b/eth/quantized_model.json @@ -1,74 +1,74 @@ { - "out": 18403, + "out": 18406, "sR2sSq_numerator": 5, "sR2sSq_denominator": 32766, "z_R": 32770, "z_Sq": 4, "Yt_q": [ [ - 38231 + 45057 ], [ - 37139 + 44238 ], [ - 32770 + 40962 ], [ - 56798 + 58983 ], [ - 54614 + 57344 ], [ - 46969 + 51610 ], [ - 45876 + 50791 ], [ - 38231 + 45057 ], [ - 46969 + 51610 ], [ - 31678 + 40142 ], [ - 49153 + 53249 ], [ - 34954 + 42600 ], [ - 37139 + 44238 ], [ - 62259 + 63079 ], [ - 44784 + 49972 ], [ - 48061 + 52430 ], [ - 39323 + 45876 ], [ - 40415 + 46696 ], [ - 26217 + 36047 ], [ - 44784 + 49972 ] ], - "sYsR_numerator": 3, + "sYsR_numerator": 4, "sYsR_denominator": 1, - "sYtsR_numerator": 3, + "sYtsR_numerator": 4, "sYtsR_denominator": 1, "constant": 32770, "X_q": [ @@ -193,12 +193,31 @@ 16387 ] ], + "W_q": [ + [ + 12024 + ], + [ + 12794 + ], + [ + 3700 + ], + [ + 6015 + ] + ], + "b_q": [ + [ + 14438 + ] + ], "z_X": 4, - "z_W": 32770, + "z_W": 7285, "z_b": 4, - "z_Y": 21888242871839275222246405745257275088548364400416034343698204186575808517457, - "sbsY_numerator": 4, - "sbsY_denominator": 3, - "sXsWsY_numerator": 2, - "sXsWsY_denominator": 49149 + "z_Y": 4, + "sbsY_numerator": 1, + "sbsY_denominator": 1, + "sXsWsY_numerator": 3, + "sXsWsY_denominator": 21844 } \ No newline at end of file diff --git a/eth/scripts/__pycache__/quantize_model.cpython-38.pyc b/eth/scripts/__pycache__/quantize_model.cpython-38.pyc index d9c4200..889572e 100644 Binary files a/eth/scripts/__pycache__/quantize_model.cpython-38.pyc and b/eth/scripts/__pycache__/quantize_model.cpython-38.pyc differ diff --git a/eth/scripts/quantize_model.py b/eth/scripts/quantize_model.py index 8969027..68f26fa 100644 --- a/eth/scripts/quantize_model.py +++ b/eth/scripts/quantize_model.py @@ -657,7 +657,7 @@ def q_dataset( sXsWsY_denominator=proc(sXsWsY_denominator), ) - with open("./quantized_model.json", "w") as f: + with open("./quantized_dataset.json", "w") as f: json.dump(data_all, f, indent=2)