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

[tfhers compatibility] frontend support #820

Merged
merged 4 commits into from
May 28, 2024
Merged

[tfhers compatibility] frontend support #820

merged 4 commits into from
May 28, 2024

Conversation

youben11
Copy link
Member

@youben11 youben11 commented May 8, 2024

No description provided.

@cla-bot cla-bot bot added the cla-signed label May 8, 2024
@youben11 youben11 force-pushed the tfhe-rs-compat-v0 branch 2 times, most recently from 16a7aa0 to 4db9e8f Compare May 10, 2024 16:28
Copy link
Contributor

@umut-sahin umut-sahin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strong start 💪

frontends/concrete-python/concrete/fhe/tfhers/values.py Outdated Show resolved Hide resolved
frontends/concrete-python/concrete/fhe/tfhers/tracing.py Outdated Show resolved Hide resolved
frontends/concrete-python/concrete/fhe/tfhers/tracing.py Outdated Show resolved Hide resolved
frontends/concrete-python/concrete/fhe/tfhers/tracing.py Outdated Show resolved Hide resolved
frontends/concrete-python/concrete/fhe/tfhers/tracing.py Outdated Show resolved Hide resolved
Comment on lines 399 to 405
tfhers_to_native = {
inputs_and_output_share_precision,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about from native?
Also is this the condition we really want?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We basically want to have the input precision (the one of the tfhers integer) to rule it, as tfhers inputs should come from an external computation. We can't just decrease tfhers int bitwidth, so the native one have to follow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we assign it the precision obtained from the inputset? (e.g., maybe all values that will be given to the circuit is smaller than 10 so it's enough to process 5 chunks from TFHE-rs)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It really depends on the usecase, but as I'm currently seeing it, we don't control the tfhers computation part, and we aren't asked to look at it, and what are its outputs, all we know is it's output bitwidth. So we shouldn't have a meaningful inputset to use here to try to know how many chunks should we use.
Cc @BourgerieQuentin wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that'll still be how the circuit is compiled. If they want to have the full range, they should give it in the inputset.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it was what we said, so the output precision can differ

frontends/concrete-python/concrete/fhe/mlir/converter.py Outdated Show resolved Hide resolved
frontends/concrete-python/concrete/fhe/mlir/context.py Outdated Show resolved Hide resolved
@@ -116,6 +117,20 @@ def typeof(self, value: Union[ValueDescription, Node]) -> ConversionType:
assert isinstance(value.dtype, Integer)
bit_width = value.dtype.bit_width

# TODO: what about the element type? only unsigned? or not eint at all?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it depends on how it's done in TFHE-rs. We should think about which operations would be performed on this type and use eint or esint accordingly. We should also test correct transfer of sign (if input was -3 in TFHE-rs, it should correctly be converted to -3 in Concrete).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will have at least to see how they do sign encoding and consider that as part of the MLIR conversion

Comment on lines 399 to 405
tfhers_to_native = {
inputs_and_output_share_precision,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we assign it the precision obtained from the inputset? (e.g., maybe all values that will be given to the circuit is smaller than 10 so it's enough to process 5 chunks from TFHE-rs)

Comment on lines +35 to +98
int8 = partial(TFHERSIntegerType, True, 8)
uint8 = partial(TFHERSIntegerType, False, 8)
int16 = partial(TFHERSIntegerType, True, 16)
uint16 = partial(TFHERSIntegerType, False, 16)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an _ in the beginning would be enough IMO 🙂

@youben11 youben11 marked this pull request as ready for review May 21, 2024 10:15
frontends/concrete-python/concrete/fhe/mlir/converter.py Outdated Show resolved Hide resolved
frontends/concrete-python/concrete/fhe/mlir/converter.py Outdated Show resolved Hide resolved
Comment on lines 399 to 405
tfhers_to_native = {
inputs_and_output_share_precision,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it was what we said, so the output precision can differ

@youben11
Copy link
Member Author

@slab-ci concrete-python-tests-linux

this comes from the need of supporting tfhers integers, which would get
erased by this recreation of the dtype, so instead we would update the
dtype inplace
- add new tfhers types
- add conversion functions between concrete and tfhers types
- support conversion function in the compilation pipeline
Copy link
Contributor

@umut-sahin umut-sahin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small remark, looks good!

Comment on lines +7 to +8
from concrete import fhe
from concrete.fhe import tfhers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be better if we can do:

from concrete import fhe, tfhers

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means a different module, and I'm not sure it makes sense as they would depend on each other

@youben11 youben11 removed the request for review from BourgerieQuentin May 28, 2024 13:43
@youben11 youben11 merged commit 6f35a8b into main May 28, 2024
26 checks passed
@youben11 youben11 deleted the tfhe-rs-compat-v0 branch May 28, 2024 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants