Scheme Dialects #54
Replies: 4 comments 19 replies
-
I am happy to prototype a CGGI dialect, since that's the scheme I'm most familiar with. I would also like to review the CKKS and BGV-like dialect drafts so I can better learn them myself. |
Beta Was this translation helpful? Give feedback.
-
In yesterday's Working Group meeting (see notes), the desire to have a target/hardware-agnostic interface (e.g., as a specification for accelerators to implement) came up. While scheme-specific dialects (like Zama's tfhe-rs-derived CGGI one, or HECO's seal-derived BFV one) seems like an ideal candidate for this at first glance, programs at this abstraction level are usually already (over)specified with a specific implementation in mind. These dialects might already encode parameter and algorithm choices (even if only partially, i.e., specifying number of RNS limbs, coeff vs eval form, etc) that should be chosen to fit the specific target implementation. The following is a brief list of examples of choices that might need to be made in a target-dependent way.
Therefore, I propose to have an "intermediate" abstraction step between high-level and (traditional) scheme-specific, something we might call semantic/declarative scheme-level IR. This would omit details such as parameters/etc, and instead express requirements (e.g., precision of arithmetic operations, precision of bootstrap, etc, all in bits) similar to the high-level dialect. In order to be a meaningfully "lower" level abstraction, the intent is still to restrict the set of operations to those that have "direct" equivalents in the underlying scheme. This could then serve as a natural separation point between more "high-level" oriented compilers (e.g. open-source HECO) and more "low-level" oriented compilers (e.g., toolchains for DPRIVE accelerators). In addition, it would be a very useful interchange format for "apples to apples" benchmarking between different libraries/accelerators. Some current open questions are:
|
Beta Was this translation helpful? Give feedback.
-
Here is an attempt at (sketch of an) example for integer division. (I'll mostly write pseudo-code as I'm not quite confident enough in my MLIR knowledge.) High-level code: # a and b are secret 16-bits unsigned integers; with want a correct result up to 0.5%
c = a / b; Translation into high-level dialect: %c = fhe.uint_div(%a, %b) {prec = 8} : (!fhe.secret<u16>,!fhe.secret<u16>) -> !fhe.secret<u16> (Open question 1: Do we want to return a special value indicating an error in case There are multiple ways this could be lowered, e.g.:
(Open question 2: At which point is the selection of the best algorithm and scheme made?) For definiteness, let's assume we choose to use Goldschmidt's algorithm implemented with CKKS. We then need to
The multiplications, division by I realise this is a bit sketchy; but hopefully it helps showing a possible sequence of operations on another example. |
Beta Was this translation helpful? Give feedback.
-
I'm seeing the prototypes that @asraa put together for BGV and the one I'm working on for CGGI (#119), and I was thinking we might want to have a common type-only dialect for LWE and RLWE (or combine them into one "generalized LWE" type a la Zama) so that ciphertext types can be shared across scheme-specific dialects. The BGV type has a ring array attr, and the RLWE type for CGGI would just need a single ring attribute, so maybe that could just be an array of size 1 and the CGGI op verifiers can check that. I think only CGGI uses vanilla LWE, but it might still be nice to have it as a separate concept. Thoughts? |
Beta Was this translation helpful? Give feedback.
-
As discussed in the MLIR Dialects Session, I'm setting up three discussions topics, corresponding to the three streams identified.
This is the Scheme Dialects discussion, you can find the High-Level FHE Dialect and Poly/Math Dialects discussions at the links.
The goal of this abstraction/dialect is to provide a dialect (or set of dialects) that can act as an intermediate representation and exchange format for FHE computations at the "circuit"-ish level.
Technical/MLIR Challenges
As this is supposed to be something of an "XONN/StableHLO for FHE", we should strive to follow modern MLIR best practices in dialect design. However, as the MLIR project has been continuously evolving, it is not immediately clear what exactly these best practices currently are and which, if any, of the upstream dialects showcase them.
In addition to providing the "raw" dialect(s), the aim of this project is to "include batteries", i.e. features and tooling around the dialect(s). This includes pretty printers for concise textual representations, efficient binarization to allow this to be used as an actual interchange format, and a yet-to-be-determined set of canonicalizations, folds, and potentially passes.
Conceptual Challenges
FHE schemes tend to define a natural "API" of sorts, which is reflected in the existing FHE libraries. Therefore, it should be relatively straightforward to define per-scheme dialects, with the majority of the challenge lying in ensuring that the dialects are expressive enough to support a variety of different implementations (potentially as drastically different as RNS vs non-RNS implementations, but certainly differing in approaches to noise management during ciphertext maintenance operations). From this starting point, we should then try to identify common components that can be factored out, enabling a slow transition to a universal dialect.
Next steps
The presence of high-quality dialects to represent FHE computations at this level appears to be a blocking issue for (parts of) the further development of the MLIR version of the FHE Transpiler and new versions of HECO. As a result, the goal is to start rapidly prototyping working dialects for the schemes/variants that are most relevant for these uses cases. The timeline for this is 1 month, at which point we should report our progress back to the working group and switch to exploring towards a universal abstraction.
Tasks
Beta Was this translation helpful? Give feedback.
All reactions