facebookresearch / CrypTen

A framework for Privacy Preserving Machine Learning
MIT License
1.52k stars 278 forks source link

Model decryption, save and later load FAILS #470

Closed llop00 closed 1 year ago

llop00 commented 1 year ago

I'm trying to decrypt a model that I have trained with shared encrypted data. And save it so I can then load it into another script and do evaluations on the model in plain text.

The code I'm using for decrypting and saving is:

model = encrypted_model.decrypt() crypten.save_from_party(model, f'modelrank{rank}.pth', src=rank)

And for loading on a separate script:

model = crypten.load_from_party('model_rank_0.pth', src=0)

But I get this error:

Traceback (most recent call last): File "/usr/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap self.run() File "/usr/lib/python3.8/multiprocessing/process.py", line 108, in run self._target(*self._args, *self._kwargs) File "/mnt/c/Users/a2588/.local/lib/python3.8/site-packages/crypten/mpc/context.py", line 30, in _launch return_value = func(func_args, **func_kwargs) File "load_and_inference.py", line 53, in encrypt_model_and_data model = crypten.load_from_party('model_rank_0.pth', src=0) File "/mnt/c/Users/a2588/.local/lib/python3.8/site-packages/crypten/init.py", line 345, in load_from_party raise TypeError("Unrecognized load type %s" % type(result)) TypeError: Unrecognized load type <class 'int'>

I have not seen example with using model.decrypt but only with decrypting tensors via get_plain_text().

Any example provided or help with the error I can't crearly identify would be a great help!