Hello,
I am trying to follow the tutorial here Table Lookup — Concrete Numpy Manual in order to use a tensor input in my lookup table.
I succeed to do the tutorial with a scalar input but when I try to change the input to a numpy array as proposed in the tutorial, I have the following error during encryption:
RuntimeError: argument #0is not a tensor
If I change my input set to match the shape it works fine, but from what I understood it should also work without changing it and apply the lookup table to each entry of my array.
So my question is, how to use an array in a lookup table ?
Thank you
Here is my code:
concrete-numpy==0.5.0
python==3.8
import concrete.numpy as hnp
import os, sys, time
import numpy as np
import torch
from collections import Counter
from concrete.common.values.tensors import EncryptedTensor
from concrete.common.data_types.integers import Integer
input_shape = (2,3)
table = hnp.LookupTable([2, 1, 3, 0])
def f(x):
return table[x]
inputset = np.random.randint(0,4,size=(20))
print(inputset)
compiler = hnp.NPFHECompiler(f,
{"x": "encrypted"},#EncryptedTensor(Integer(64, False), input_shape)},
)
circuit = compiler.compile_on_inputset(inputset)
input = np.array([[0, 1, 3], [2, 3, 1]], dtype=np.uint8)
circuit.keygen()
public_args = circuit.encrypt(input)
encrypted_result = circuit.run(public_args)
decrypted_result = circuit.decrypt(encrypted_result)
print(decrypted_result)