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

ignoring zero diagonals in diagonal_ct_vector_matmul #405

Merged
merged 6 commits into from
Aug 7, 2022

Conversation

mrader1248
Copy link
Contributor

Description

As explained in #398, matrices with diagonals that contain nothing but zeros cannot be multiplied with a vector, as this results in ValueError: result ciphertext is transparent. This can be fixed by simply ignoring zero diagonals, which in addition potentially saves some unnecessary computations.

Affected Dependencies

None

How has this been tested?

I used the following code to test, which previously resulted in the error explained above.

import numpy as np
import tenseal as ts

n = 1000
x = np.random.rand(n)
i = np.eye(n)
poly_mod_degree = 4096
coeff_mod_bit_sizes = [40, 20, 40]
ctx = ts.context(ts.SCHEME_TYPE.CKKS, poly_mod_degree, -1, coeff_mod_bit_sizes)
ctx.generate_galois_keys()
ctx.global_scale = 2 ** 20
x_enc = ts.ckks_vector(ctx, x)
x_enc @ i

Checklist

@MartinNoc MartinNoc mentioned this pull request Jun 22, 2022
@mrader1248 mrader1248 force-pushed the feature-mm-ignore-zero-diagonals branch from 1e223ae to 9e71af8 Compare July 8, 2022 06:42
@mrader1248
Copy link
Contributor Author

Is it possible that the test runner had a problem or _almost_equal had a bad day? I cannot reproduce the reported failure of

tests/python/tenseal/tensors/test_ckks_tensor.py::test_subscript[data0-slices0-new_shape0]

locally.

@mrader1248
Copy link
Contributor Author

@bcebere, could you help me here?

@mrader1248
Copy link
Contributor Author

If make is called with -j the number of processes for the the build process is not limited and it crashes unless there is enough RAM. For this reason, I modified setup.py such that -j is only added if the environment variable MAKEFLAGS is not set. With this, setup.py respects a user's default make flags, e.g. defined in .zshrc or .bashrc, or MAKEFLAGS="-j4" pip install ... can be called to limit the number of processes directly. The default behaviour is unchanged (unlimited number of processes if MAKEFLAGS is not set).

@MartinNoc
Copy link

@youben11
Does anybody have time to review this PR? Thanks 🙏

@bcebere
Copy link
Member

bcebere commented Aug 7, 2022

LGTM!
Thank you for your contribution, @mrader1248 !

@bcebere bcebere merged commit 539e0b9 into OpenMined:main Aug 7, 2022
@mrader1248 mrader1248 deleted the feature-mm-ignore-zero-diagonals branch August 8, 2022 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants