Use of Encrypted Tensor


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:

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))
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)

public_args = circuit.encrypt(input)

encrypted_result =
decrypted_result = circuit.decrypt(encrypted_result)

Hello Tristan,

The runtime error is reflecting the fact that the input #0 wasn’t expected to be a tensor, because the compilation takes into account the type of the input, so when you did compile using an inputset of it did consider the input to the compiled function to be a scalar, so now you can only use that. However, if you use an inputset of similar tensors during the compilation, then it should work fine. So in general, your compiled function would have typed inputs (the dimensions of tensors is also part of the type), and you can only use inputs of the same type during execution.

1 Like

Ok thank you for your answer !