fhelium.distributed._limb_collectives
Structural scatter and gather collectives for ciphertext RNS limbs.
scatter_ciphertext_limbs
function View source
def scatter_ciphertext_limbs(value_or_none: Ciphertext | None, *, limb_ranges: Sequence[tuple[int, int]] | None=None, src: int=0, group: torch.distributed.ProcessGroup | None=None) -> Ciphertext: ...Slice and scatter caller-selected RNS intervals of one ciphertext.
The source provides one nonempty half-open interval per group rank. The intervals refer to positions on the source's limb axis, form a consecutive range in group-rank order, and may have unequal lengths. slice_limbs selects both Tensor rows and their declared prime_ids. The caller chooses the partition; the collective performs no arithmetic or balancing. It is synchronous and accepts no async_op argument.
Parameters
value_or_none: Source ciphertext onsrc;Noneon every other rank. The source may itself represent an interval of the full basis.limb_ranges: Onsrc, one(start, stop)pair per process-group rank, indexing the source's stored rows rather than global prime IDs. Other ranks supplyNone. The intervals may select a consecutive portion of the source without covering every row.src: Global rank of the source process, which must belong togroup.group: Participating process group.Noneselects the default group.
Returns
The local ciphertext shard with its selected prime IDs and unchanged arithmetic state. On src, it shares the source Tensor storage; other ranks receive newly allocated storage. World size one returns the requested source view without communication or copying.
Raises
ValueError: If the source rank or source/non-source arguments are invalid; the range count differs from group size; or intervals are empty, out of bounds, or not consecutive in group-rank order.RuntimeError: If distributed communication is uninitialized or the caller is not a member ofgroup.
gather_ciphertext_limbs
function View source
def gather_ciphertext_limbs(local_shard: Ciphertext, *, dst: int=0, group: torch.distributed.ProcessGroup | None=None) -> Ciphertext | None: ...Gather and reconstruct one ciphertext from disjoint RNS limb shards.
Group-rank order defines prime-interval order. On dst, compatible, nonempty, contiguous parameter intervals are concatenated along the RNS limb dimension. This is structural reconstruction, not ciphertext addition; use reduce_ciphertext for additive partials. The operation is synchronous, accepts no async_op argument, and returns no torch.distributed.Work.
Parameters
local_shard: Caller-owned rank-local ciphertext shard. It is read but not mutated.dst: Global rank that reconstructs the ciphertext, which must belong togroup. This is not a process-group-relative rank.group: Participating process group.Noneselects the default process group.
Returns
The reconstructed ciphertext on dst and None on every other rank. The destination allocates receive buffers and the concatenated result. For world size one, the validated local_shard object is returned unchanged without concatenation.
Raises
ValueError: Ifdstis outsidegroupor shards differ in logical ciphertext metadata, dtype, device, or contiguous prime layout.RuntimeError: If distributed communication is uninitialized or the caller is not a member ofgroup.