While having a look at the CKKS key switch lowering, I noticed that the last step (Step 4: Remove the key-switch primes) incorrectly performs an LWE level basis conversion op from QP to Q instead of a modulus switch from QP to Q. These operations would correspond to Conv (basis conversion) and ModDown (modulus switching) in Appendix A of Faster Bootstrapping for CKKS with Less Modulus Consumption.
While investigating how ModDown could be implemented I also found the following:
I propose the following fixes:
- Remove the LWE level basis conversion op. The direct translation from LWE basis conversion to RNS basis conversion is an indication that basis conversion should live in the RNS dialect and not the LWE one.
- Define a
ModUp (basis extension from Q to QP) and a ModDown (modulus switching from QP to Q) operation on the LWE dialect following the standard naming convention from Section 2.2 of HK19. These ops will use the RNS level base conversion when lowered.
- Replace the usages (basis extension and modulus switching) of the current LWE level basis conversion with the newly added
ModUp and ModDown ops.
- Reimplement the RNS level basis conversion lowering to use the fast base conversion algorithm (Section 2.2), which is the standard algorithm used in CKKS (hybrid) key switching implementations. The Garner's algorithm implementation could optionally be kept as an exact basis conversion algorithm.
If you think this is a good direction I can start putting together PRs for these. I am not confident about the compiler/MLIR side of things, so any suggestions are welcome.
tagging @AlexanderViand, @crockeea, @j2kun
While having a look at the CKKS key switch lowering, I noticed that the last step (Step 4: Remove the key-switch primes) incorrectly performs an LWE level basis conversion op from
QPtoQinstead of a modulus switch fromQPtoQ. These operations would correspond toConv(basis conversion) andModDown(modulus switching) in Appendix A of Faster Bootstrapping for CKKS with Less Modulus Consumption.While investigating how
ModDowncould be implemented I also found the following:I propose the following fixes:
ModUp(basis extension fromQtoQP) and aModDown(modulus switching fromQPtoQ) operation on the LWE dialect following the standard naming convention from Section 2.2 of HK19. These ops will use the RNS level base conversion when lowered.ModUpandModDownops.If you think this is a good direction I can start putting together PRs for these. I am not confident about the compiler/MLIR side of things, so any suggestions are welcome.
tagging @AlexanderViand, @crockeea, @j2kun