Skip to content

"bad optional access" (naive matmul) #25

Description

@Wheest

I am looking at GEMM computations in EVA.

EVA uses vectorised computations, though following the paper Secure Outsourced Matrix Computation and Application to Neural Networks, we can run a naive encrypted matmul by having the vector size be 1.

This issue asks if the EVA Extension Library (EXL) will be released, which may already implement this, however it is not current available as far as I know.

I have tried to implement this, however I am getting an error: RuntimeError: bad optional access.

You can see my example before, is there something I am missing?

#!/usr/bin/env pythonfromevaimportEvaProgram, Input, Output, evaluatefromeva.ckksimportCKKSCompilerfromeva.sealimportgenerate_keysfromeva.metricimportvaluation_mseimportnumpyasnpdefget_gemm(N, K, M):
gemm=EvaProgram("gemm", vec_size=1)
withgemm:
outputs= [[0] *N] *Mforninrange(N):
forminrange(M):
forkinrange(K):
x=Input(f"x_{n}_{k}")
w=Input(f"w_{k}_{m}")
outputs[n][m] +=x*mforninrange(N):
forminrange(M):
Output(f"out_{n}_{m}", outputs[n][m])
gemm.set_input_scales(25)
gemm.set_output_ranges(10)
returngemmdefgenerate_inputs(N, K):
inputs=dict()
i=0forninrange(N):
forkinrange(K):
inputs[f"x_{n}_{k}"] = [i]
i+=1returninputsdefgenerate_weights(K, M):
inputs=dict()
i=0forkinrange(K):
forminrange(M):
inputs[f"w_{k}_{m}"] = [i]
i+=1returninputsdefmain():
N, K, M=8, 8, 8inputs=generate_inputs(N, K)
weights=generate_weights(K, M)
gemm=get_gemm(N, K, M)
data= {**weights, **inputs}
print(data)
forprogin [gemm]:
print(f"Compiling {prog.name}")
compiler=CKKSCompiler()
compiled, params, signature=compiler.compile(prog)
public_ctx, secret_ctx=generate_keys(params)
enc_inputs=public_ctx.encrypt(data, signature)
print("excuting GEMM")
enc_outputs=public_ctx.execute(compiled, enc_inputs)
outputs=secret_ctx.decrypt(enc_outputs, signature)
reference=evaluate(compiled, inputs)
print("MSE", valuation_mse(outputs, reference))
print()
if__name__=="__main__":
main()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions