Repository navigation
Conversation
|
@JulienVig I think we need to refactor a bit the architecture of disco. The goal would be to decouple some components a bit more and make it easier to implement different algorithms in the future. PR #1289 already does some refactoring in this direction, but still there are some smells, like algorithm-specific parameters being thrown in the trainer. I will use this PR to come up with a design doc for a new architecture which we can review together before moving forward with it (if you agree) |
|
Yes, refactoring the architecture makes a lot of sense. Let me know when the document is ready for review. |
7c58547 to
222de30
Compare
222de30 to
5dedee3
Compare
JulienVig
left a comment
There was a problem hiding this comment.
Thanks Alessandro. The idea themselves look interesting but the proposal document looks really messy and too wordy. It mixes up design ideas, current technical bugs, and implementation details which makes understanding the proposal quite hard without getting lost in the details.
What's useful to include in a design proposal:
- the current limitations at a conceptual level
- the description of the conceptual refactoring idea
- the expected limitations of the refactoring
- You include conceptual diagrams if you have a clear point to make and your written text should reference the specific part of the diagram you're talking about.
What's not useful to include:
- Code
- Current bugs (you can create separate issues for these)
- References to precise lines or specific files
- Technical implementation details
- Math formulas
If you're unsure you can use collapsable sections to hide potentially interesting details.
Note that the design document shouldn't be specific to Tensorflow.js.
…tails in Section 2" This reverts commit c7585b2.
…o other frameworks
269c827 to
3203fbc
Compare
|
@JulienVig Hi sorry, I had miscklicked and tagged you as reviewer, tried to undo that but I guess you got the notification anyways. I am still making some changes, will tag you once I am done |
JulienVig
left a comment
There was a problem hiding this comment.
Great work, I like the 3 axis design and make Trainer less bloated. I mainly wonder how to handle algorithms that don't fall cleanly into one axis.
For TFJS let's go with Option 2, it aligns well with the rust transition
| 2. **training:** Intra-round local client optimization strategies plus composable options like `lr`, `learningRateSchedule`, `goldfishLoss`, composable with any `aggregation.strategy`. | ||
| 3. **communication transforms** Post-round client update transformations executed in a canonical mathematical order before communication such as _differential privacy_, or model compression. | ||
|
|
||
| **Pro**: This removes the problems mentioned in 2.1, it dedicates a place in the config for training-only options, without cluttering aggregation configs. So for example, `FedProx`, being only a training strategy, would be composable with byzantine aggregators. It also adds space for other pre-communication strategy different than privacy, such as compression, or client-side clipping and so on, without having to put them under a specific aggregator. |
There was a problem hiding this comment.
The byzantine algorithm works in two parts:
- aggregation: the server aggregates weights with momentum and clipping
- communication transform: clients clip their weight before sending. This interacts with DP to clip to the minimum between the DP and the byzantine radius.
How would this design handle:
- an algorithm that is spread over multiple axes? (byzantine = aggregation + communication transform)
- an algorithm that interacts with another? (byzantine and DP clipping)
There was a problem hiding this comment.
So for the specific case you're mentioning, clipping would happen both client-side (for DP) and server side (as in the reference paper) and this would be the correct execution. Client side clipping with byzantine aggregation is an artifact of the previous coupled implementation, it should not be like that, due to byzantine nodes not necessarily following client side rules.
But in general, if I understand correctly you're saying:
Suppose we have an algorithm "Foo" that mandates a certain aggregation function + a pre-communication transform. The user would have to explicitly configure both of them.
I see the option of having a top-level field such as algorithm: "Foo" that would then compile to a set of known communication + aggregation hooks (i.e you parse Foo so you know you have to instantiate those hooks). Or you assume the user knows how the algorithm works, and let them write the config accordingly.
The idea is that we give the modular pieces.
an algorithm that interacts with another? (byzantine and DP clipping)
That's a fair point and I also mentioned in the config. This should be not too common, and the few conflicts could be resovled ad-hoc. In any case there's a trade-off about config complexity and capability/consistency, there's only so much you can do with a JSON config without going through a DSL route.
There was a problem hiding this comment.
Algorithm presets
I see the option of having a top-level field such as algorithm: "Foo" that would then compile to a set of known communication + aggregation hooks (i.e you parse Foo so you know you have to instantiate those hooks)
Yes I think we should do that. Allow either setting a high-level algorithm which is a preset defined over the three axes or alternatively pick each of the three axes manually.
As you mentioned yourself in section 4 FedNova spans the 3 axes and imply data communication: axis 1: count the number of local steps performed (τ_i), axis 2: normalize the local update per step and send the local step count to the server, axis 3: weighted average of the contributions and rescaled by the effective step count parameter (τ_eff)
So implementing FedNova would imply implementing a FedNovaTrainingHook + a FedNovaAggregator. Instead of manually picking two settings in different places let's allow setting "fednova" in a single place so a user creating a task doesn't need an understanding of the internals of DISCO to correctly setup an algorithm.
| | { name: "fedprox", params: { mu: ... } }, | ||
| lr?: ..., | ||
| learningRateSchedule?: ..., | ||
| goldfishLoss?: ..., |
There was a problem hiding this comment.
I'm guess goldfishLoss would fall in training strategies
| 1. **Intra-Round Local Training Strategy (Client Optimization):** How each client optimizes its local model over its local dataset during a round: | ||
| - Standard Empirical Risk Minimization (FedAvg) | ||
| - Proximal regularization towards the round's initial weights: $\min_w F_k(w) + \frac{\mu}{2}\|w - w^{(t)}\|^2$ (FedProx) | ||
| - Round- or epoch-level learning rate schedules and warmups | ||
| 2. **Post-Round Client Update Transformation & Privacy (Pre-Communication):** How a client transforms its local weight progress $\Delta w_i^{(t)} = w_i^{(t, K)} - w^{(t)}$ after completing local epochs/iterations and before transmitting weights to the server or peers: | ||
| - Explicit global or per-layer update norm clipping | ||
| - Adaptive layer-wise Frobenius norm clipping + Gaussian noise injection (ALDP-FL Differential Privacy) | ||
| 3. **Inter-Client Weight Aggregation & Protocol (Server / Peer Combination):** How updates from multiple participants are combined across the network (e.g mean, byzantine, ...) |
There was a problem hiding this comment.
Can you use the same axis order and names as in the next sections?
|
|
||
| ### 3.2. Unified `TrainingHook` Lifecycle | ||
|
|
||
| Even after having a dedicated place for training settings in the config, we still need to make `Trainer` scalable and independent of the specific strategies, so we don't have to change it every time we add a new strategy. Instead of adding algorithm-specific fields to `Trainer` or algorithm-specific methods (`attachRegularizer`, `adaptLearningRate`, etc.) to `Model`, **every client-side training algorithm is expressed as a TrainingHook**. This is similar to other frameworks suchas **Flower's `Strategy`** and \*\*PyTorch Lightning / Keras `Callback`. |
There was a problem hiding this comment.
related to my comment above:
"every client-side training algorithm is expressed as a TraningHook" -> what about algorithms that aren't client-side only?
There was a problem hiding this comment.
I'm not sure about this one. What is a specific scenario that you're thinking of? If training depends on some global state that could be shared by the server, we need to make the communication protocol richer, to send more data than just the model, as it is highlighted in the Future extensions.
So once we do that, any training hook can use onAfterCommunication to catch relevant parameters that need to be bound to the training.
Aggregators are the server-side part and they're handled by the aggregation configs.
There was a problem hiding this comment.
Client-server data exchange
I was thinking of algorithms like FedNova that spans the 3 axes
If training depends on some global state that could be shared by the server, we need to make the communication protocol richer, to send more data than just the model, as it is highlighted in the Future extensions.
I also think we should directly implement the possibility to exchange data between client and server (both directions, not just server -> client) described in section 4. For algorithms like FedNova and I was also thinking of adding support to weighted-averaging soon
| interface TrainingHook<D extends DataType = DataType> | ||
| extends Partial<Disposable> { | ||
| onRoundBegin?(ctx: HookContext<D>): Promise<void> | void; | ||
| onBeforeCommunication?( | ||
| weights: WeightsContainer, | ||
| ctx: HookContext<D>, | ||
| ): Promise<WeightsContainer> | WeightsContainer; | ||
| onAfterAggregation?( | ||
| aggregatedWeights: WeightsContainer, | ||
| ctx: HookContext<D>, | ||
| ): Promise<void> | void; | ||
| onRoundEnd?(ctx: HookContext<D>): Promise<void> | void; | ||
|
|
||
| onEpochBegin?(ctx: HookContext<D>): Promise<void> | void; | ||
| onEpochEnd?(logs: EpochLogs, ctx: HookContext<D>): Promise<void> | void; | ||
| onBatchBegin?(ctx: HookContext<D>): Promise<void> | void; | ||
| onBatchEnd?(logs: BatchLogs, ctx: HookContext<D>): Promise<void> | void; | ||
| computeLoss?(baseLoss: tf.Scalar, ctx: HookContext<D>): tf.Scalar; | ||
| } |
There was a problem hiding this comment.
Splitting TrainingHook in two
(I'm adding titles to make it easier for me to navigate the different discussions)
Shouldn't the TrainingHook interface be split in two? It seems to cover both axes 1 and 2 which could make it awkward to independently change only one of the 2.
We could split TrainingHook into two interfaces:
TrainingHook: round begin/end, epoch and batch callbacks andcomputeLoss- something like
CommunicationTransform:onBeforeCommunication,onAfterAggregationand could handle client-server data exchanges
Then an algorithm can be specified as a preset combination { trainingHooks, communicationTransforms, aggregator }
What & why
Disco currently models collaborative learning variations primarily through a single
aggregationStrategyaxis while embedding algorithm-specific state and update clipping directly insideTrainer. This coupling prevents composing client-side optimization strategies (such as FedProx or learning rate schedules) with robust or private aggregators (ByzantineRobustAggregator,SecureAggregator) and forcesTrainerandModelsubclasses (TFJS,GPT) to accumulate ad-hoc branches or custom training loops for every new algorithm.This PR introduces a design document detailing these architectural limitations and proposing a modular, hook-driven target architecture.
Todo
TrainingHookpipeline,installOptimizerLossHooksvia autograd, and unifiedTrainer.#executeRound).trainingStrategyfromaggregationStrategyinTrainingInformation,cli, andwebapp).ByzantineRobustAggregatorand restrict DP noise to trainable parameters).