Skip to main content

SecureAggregation

Struct SecureAggregation 

Source
pub struct SecureAggregation { /* private fields */ }
Expand description

Secure aggregation for federated learning.

Implements privacy-preserving aggregation where the server cannot see individual client updates, only the aggregated result.

Implementations§

Source§

impl SecureAggregation

Source

pub fn new(threshold: usize, total_clients: usize) -> Result<Self>

Create a new secure aggregation instance.

Source

pub fn generate_masks( &self, client_id: &str, all_client_ids: &[String], round: usize, parameter_shapes: &[Vec<usize>], ) -> Result<Vec<Tensor>>

Generate client_id’s pairwise-cancelling masks for parameter_shapes (the caller’s real model parameter shapes, in the fixed order every client and the server agree on for this round).

Uses the standard pairwise-masking construction for secure aggregation (Bonawitz et al.): for every OTHER id in all_client_ids, client_id and that client derive the same seed (via Self::pairwise_seed) and therefore the same pseudorandom values – client_id adds them to its mask if it sorts before the other id, subtracts them otherwise. Summing every participant’s mask together then cancels exactly (up to floating-point rounding): each pairwise contribution appears once with each sign. See Self::secure_aggregate for the aggregation side and what this construction does and does not protect against.

all_client_ids must be the exact same participant set (including client_id itself) on every client’s call for a given round, and parameter_shapes must be given in the same order everywhere, or the masks will not cancel. This does not implement dropout recovery (a full Bonawitz-style scheme additionally secret-shares each pairwise seed so surviving clients can reconstruct a dropped client’s contribution): if any client whose id appears in all_client_ids does not actually submit a masked update to Self::secure_aggregate, the missing client’s pairwise terms are never cancelled and the aggregate is biased by exactly that client’s unpaired contribution.

Source

pub fn secure_aggregate( &self, masked_updates: HashMap<String, Vec<Tensor>>, ) -> Result<Vec<Tensor>>

Sum (and average) masked client updates without the server ever seeing an individual client’s true update.

This assumes every masked update in masked_updates was produced by Self::generate_masks with the same all_client_ids/round (i.e. masked_updates.keys() matches all_client_ids exactly): the pairwise masks then cancel exactly when summed (up to floating-point rounding), leaving the true sum. If any participant named in that all_client_ids set is missing from masked_updates (a dropout), its pairwise terms are NOT cancelled and the result is biased by that client’s unpaired mask contribution – this implementation has no secret-sharing-based dropout recovery (see Self::generate_masks’s doc comment). threshold only checks a minimum client count; it does not verify the update set actually matches a generate_masks call.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more