p2pfl.learning.frameworks.tensorflow.callbacks.scaffold_callback moduleΒΆ
Callback for SCAFFOLD operations (Keras).
- class p2pfl.learning.frameworks.tensorflow.callbacks.scaffold_callback.SCAFFOLDCallback[source]ΒΆ
Bases:
Callback,P2PFLCallbackCallback for SCAFFOLD operations to use with TensorFlow Keras.
At the beginning of the training, the callback initializes control variates and substitutes the optimizer with a custom one to apply control variate adjustments. After training, it updates the local control variate (c_i) and computes the deltas.
- on_train_batch_end(batch, logs=None)[source]ΒΆ
Increment the local step counter after each batch.
- Parameters:
batch (
Any) β The batch.logs (
dict[str,Any] |None) β The logs.
- Return type:
None
- on_train_begin(logs=None)[source]ΒΆ
Initialize control variates and replace the optimizer with custom one.
- Parameters:
logs (
dict[str,Any] |None)- Return type:
None
- class p2pfl.learning.frameworks.tensorflow.callbacks.scaffold_callback.ScaffoldOptimizerWrapper(*args, **kwargs)[source]ΒΆ
Bases:
OptimizerWraps an optimizer to only redefine apply_gradients, delegating other calls.
- apply_gradients(grads_and_vars, name=None, **kwargs)ΒΆ
Apply gradients with SCAFFOLD adjustments.