fhelium.backend.ckks.key_switch
Compose hybrid RNS key switching for CKKS ciphertext components.
lift_key_switch_digit
function View source
def lift_key_switch_digit(source, tensors, attributes, digit_index, span, *, out=None, scratch=None): ...Lift one supplied digit a modulo D=product(q_i) into QP Montgomery form.
Exact lifting uses the representative in [0,D). For D_i=D/q_i and u_i=D_i^{-1} mod q_i, raw CRT uses sum_i(a_i D_i u_i); normalized CRT uses sum_i((a_i u_i mod q_i) D_i). CRT tables are live Tensor operands. Only exact lifting consumes the optional Garner scratch buffer.
accumulate_key_switch_products
function View source
def accumulate_key_switch_products(source: torch.Tensor, *, tensors: Mapping[str, torch.Tensor], attributes: Mapping[str, object], key: torch.Tensor, accumulator: torch.Tensor | None=None) -> torch.Tensor: ...Accumulate hybrid digit key products into CT2 NTT/Montgomery QP.
source is one coefficient/standard Q polynomial. The optional accumulator is owned by the caller and is updated in place. Keys and digit tables have the same active QP order for every contribution.
key_switch_corrections
function View source
def key_switch_corrections(source: torch.Tensor, *, tensors: Mapping[str, torch.Tensor], attributes: Mapping[str, object], key: torch.Tensor, output_ntt: bool=False, coefficient_c0: torch.Tensor | None=None) -> torch.Tensor: ...Stream hybrid digit products into QP accumulators and remove P.
NativeKeySwitchImplementation
class View source
NativeKeySwitchImplementation(supports_in_place: bool = False, name: str = 'native-key-switch-streaming', operation_types: tuple[type[Operation], ...] = (ckks.SwitchKeyOp, ckks.ConjugateOp))Switch CT2 secret relations with a shared streaming QP accumulator.
For input phase
Attributes
| Name | Type | Default/value |
|---|---|---|
supports_in_place | bool | False |
name | str | 'native-key-switch-streaming' |
operation_types | tuple[type[Operation], ...] | (ckks.SwitchKeyOp, ckks.ConjugateOp) |
tensor_requirements | staticmethod(native_key_switch_requirements) | |
prepare_operation | prepare_native_key_switch |
resource_requirements
method
def resource_requirements(invocation: OperationInvocation) -> tuple[ResourceRequirement, ...]: ...execute
method
def execute(invocation: OperationInvocation, inputs: tuple[torch.Tensor, ...], resources: tuple[BoundResource, ...], *, in_place: bool) -> tuple[torch.Tensor, ...]: ...NativeRelinearizeImplementation
class View source
NativeRelinearizeImplementation(supports_in_place: bool = False, name: str = 'native-relinearize-streaming', operation_types: tuple[type[Operation], ...] = (ckks.RelinearizeOp,))Relinearize CT3 through one streaming hybrid key-switch schedule.
Attributes
| Name | Type | Default/value |
|---|---|---|
supports_in_place | bool | False |
name | str | 'native-relinearize-streaming' |
operation_types | tuple[type[Operation], ...] | (ckks.RelinearizeOp,) |
tensor_requirements | staticmethod(native_key_switch_requirements) | |
prepare_operation | prepare_native_key_switch |
resource_requirements
method
def resource_requirements(invocation: OperationInvocation) -> tuple[ResourceRequirement, ...]: ...execute
method
def execute(invocation: OperationInvocation, inputs: tuple[torch.Tensor, ...], resources: tuple[BoundResource, ...], *, in_place: bool) -> tuple[torch.Tensor, ...]: ...