fhelium.distributed._ciphertext_reduction
Arithmetic ciphertext reduction collectives.
reduce_ciphertext
function View source
def reduce_ciphertext(value: Ciphertext, *, dst: int=0, engine: Engine, group: torch.distributed.ProcessGroup | None=None) -> None: ...Synchronously sum ciphertext partials onto dst using add.
A binomial tree combines complete ciphertexts and works for every positive process-group size, not only powers of two. The tree uses P - 1 full ciphertext messages, O(log P) critical-path rounds, and one temporary receive buffer per active rank. Non-destination values are partial or unchanged after return and must not be interpreted as the global sum. This is component-wise CKKS ciphertext addition modulo the active Q primes, not gathering independent values or concatenating RNS limbs. The operation accepts no async_op argument and returns no torch.distributed.Work.
Parameters
value: Rank-local additive ciphertext partial. The object ondstis updated in place; intermediate receivers may also be mutated as the tree accumulates subtrees. Non-overlapping strided views are supported without replacing their Tensor storage.dst: Global rank that receives the complete sum, which must belong togroup. This is not a process-group-relative rank.engine: Rank-local CKKS engine used for in-place modular ciphertext addition. Every participating rank must provide an engine compatible with itsvalue.group: Participating process group.Noneselects the default process group.
Returns
None. Only value on dst is guaranteed to contain the global sum. For world size one, the sole value is already the sum and remains unchanged.
Raises
ValueError: Ifdstis outsidegroup; rank-local values are not ciphertexts with identical shape and arithmetic metadata; or the engine rejects an incompatible value.RuntimeError: If distributed communication is uninitialized or the caller is not a member ofgroup.
all_reduce_ciphertext
function View source
def all_reduce_ciphertext(value: Ciphertext, *, engine: Engine, group: torch.distributed.ProcessGroup | None=None) -> None: ...Synchronously sum ciphertext partials and update every rank in place.
The reduction phase uses the arbitrary-world-size binomial tree documented by reduce_ciphertext. The root then uses a representation-preserving tensor broadcast because broadcasting ciphertext payload bits requires no arithmetic specialization. Asynchronous composite Work semantics are intentionally deferred until a measured workload demonstrates useful communication/add overlap. The implicit root is the first global rank in process-group-rank order.
Parameters
value: Rank-local additive ciphertext partial. Every rank's object is overwritten in place with the component-wise CKKS sum modulo the active Q primes. Non-overlapping strided views retain their Tensor storage and are updated through any existing aliases.engine: Rank-local CKKS engine used during tree reduction. Every participating rank must provide an engine compatible with itsvalue.group: Participating process group.Noneselects the default process group. No caller-selected root is used.
Returns
None. Every rank's existing value object contains the global sum after return. For world size one, the value remains unchanged. The function accepts no async_op argument and returns no torch.distributed.Work.
Raises
ValueError: If rank-local values are not ciphertexts with identical shape and arithmetic metadata, or an engine rejects an incompatible value.RuntimeError: If distributed communication is uninitialized or the caller is not a member ofgroup.