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

How to pickle an Ptxt? #234

Open
Shakemilktea opened this issue Mar 20, 2024 · 2 comments
Open

How to pickle an Ptxt? #234

Shakemilktea opened this issue Mar 20, 2024 · 2 comments
Labels
Functionality Wether this library supports a certain operation or not

Comments

@Shakemilktea
Copy link

Shakemilktea commented Mar 20, 2024

Hello, I got some error when pickling ptxt. This is the error:

Traceback (most recent call last):
  File "E:\NCKU\ICLab\code\Pyfhel-master\examples\Demo_4_SaveNRestore.py", line 172, in <module>
    pkls_ptxt = pickle.dumps(p)
  File "<stringsource>", line 2, in Pyfhel.PyPtxt.PyPtxt.__reduce_cython__
TypeError: no default __reduce__ due to non-trivial __cinit__

I'd like to encode the deep learning model's weights, then I can perform operations between the encrypted image and the encoded weights. However, when I attempt to encode the weights, a MemoryError might occur (I guess, because the code will stop without raising an error.) Therefore, I intend to pickle the encoded weights (Ptxt) to avoid overloading the RAM. Pickling ctxt doing well in #81, but pickling ptxt gets error.

Do you have any advice?

@Shakemilktea Shakemilktea added the Functionality Wether this library supports a certain operation or not label Mar 20, 2024
@ibarrond
Copy link
Owner

ibarrond commented Mar 25, 2024

@Shakemilktea The encoding operation is light-weight compared to the homomorphic operations. That being said, you could:

  • Pickle the weights as numpy objects.

  • Forl Pyfhel, implement the necessary pickling mechanism for PyPtxt and merge it on the main repo. This seems doable:

    1. Create a __reduce__ method in PyPtxt.pyx that does exactly what PyCtxt.__reduce__ does
    2. Test it and add some example of its use in an examples file.

I'd be happy to provide further assistance if you decide to implement it.

@Shakemilktea
Copy link
Author

Thanks for your advice! It looks good when multiplying Numpy and Ctxt!
Regarding the pickling of Ptxt, I haven't had experience with Cython before, so I need to study it first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Functionality Wether this library supports a certain operation or not
Projects
None yet
Development

No branches or pull requests

2 participants