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

Splitting proof error #773

Open
mammadmaheri7 opened this issue Apr 8, 2024 · 0 comments
Open

Splitting proof error #773

mammadmaheri7 opened this issue Apr 8, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@mammadmaheri7
Copy link

I attempted to split a proof following the example notebooks provided, using the code snippet below:

input_path = "network_complete.onnx"
output_path = "network_split_0.onnx"
input_names = ["input"]
output_names = ["/Add_output_0"]
# first model
onnx.utils.extract_model(input_path, output_path, input_names, output_names, check_model=False)

input_path = "network_complete.onnx"
output_path = "network_split_1.onnx"
input_names = ["/Add_output_0"]
output_names = ["output"]
# second model
onnx.utils.extract_model(input_path, output_path, input_names, output_names,check_model=False)

# iterate over each submodel gen-settings, compile circuit and setup zkSNARK
import sys

def setup(i):
    # file names
    model_path = os.path.join('network_split_'+str(i)+'.onnx')
    settings_path = os.path.join('settings_split_'+str(i)+'.json')
    data_path =  os.path.join('input_'+str(i)+'.json')
    compiled_model_path = os.path.join('network_split_'+str(i)+'.compiled')
    pk_path = os.path.join('test_split_'+str(i)+'.pk')
    vk_path = os.path.join('test_split_'+str(i)+'.vk')
    witness_path = os.path.join('witness_split_'+str(i)+'.json')

    if i > 0:
         prev_witness_path = os.path.join('witness_split_'+str(i-1)+'.json')
         witness = json.load(open(prev_witness_path, 'r'))
         data = dict(input_data = witness['outputs'])
         # Serialize data into file:
         json.dump(data, open(data_path, 'w' ))
    else:
         data_path = os.path.join('input_0.json')

    # generate settings for the current model
    res = ezkl.gen_settings(model_path, settings_path, py_run_args=run_args)
    res = ezkl.calibrate_settings(data_path, model_path, settings_path, "resources", scales=[run_args.input_scale], max_logrows=run_args.logrows)
    assert res == True

    # load settings and print them to the console
    settings = json.load(open(settings_path, 'r'))
    settings['run_args']['logrows'] = run_args.logrows
    json.dump(settings, open(settings_path, 'w' ))

    print("=== compile circuit === i:",i)
    res = ezkl.compile_circuit(model_path, compiled_model_path, settings_path)

    print("=== setup === i:",i)
    res = ezkl.setup(
         compiled_model_path,
         vk_path,
         pk_path,
      )

    assert res == True
    assert os.path.isfile(vk_path)
    assert os.path.isfile(pk_path)

    res = ezkl.gen_witness(data_path, compiled_model_path, witness_path, vk_path)
    run_args.input_scale = settings["model_output_scales"][0]

for i in range(2):
    setup(i)

However, I encountered the following error in witness generation (In the second iteration of the loop):

Traceback (most recent call last):
  File "splitproof.py", line 1830, in <module>
    setup(i)
  File "splitproof.py", line 1800, in setup
    res = ezkl.gen_settings(model_path, settings_path, py_run_args=run_args)
RuntimeError: Failed to generate settings: Translating node #0 "/Add_output_0" Source ToTypedTranslator

I have attached input_0.json and the ONNX files for reference. My EZKL version is 10.2.9.

Any assistance in resolving this issue would be greatly appreciated. Thank you!

debug.zip

@mammadmaheri7 mammadmaheri7 added the bug Something isn't working label Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant