Reference
Federated Models
A boilerplate code for creating Federated Model
FederatedModel
This class is used to encapsulate the (PyTorch) federated model that we will train. It accepts only the PyTorch models and provides a utility functions to initialize the model, retrieve the weights or perform an indicated number of traning epochs.
Source code in FedJust\model\federated_model.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
|
__init__(net, optimizer_template, loader_batch_size, force_cpu=False)
Initialize the Federated Model. This model will be attached to a specific client and will wait for further instructionss
Parameters
net: nn.Module The Neural Network architecture that we want to use. optimizer_template: functools.partial The partial function of the optimizer that will be used as a template node_name: int | str The name of the node loader_batch_size: int Batch size of the trainloader and testloader. force_gpu: bool = False Option to force the calculations on cpu even if the gpu is available.
Returns
None
Source code in FedJust\model\federated_model.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
attach_dataset_id(local_dataset, node_name, only_test=False, hugging_face_map=True)
Attaches huggingface dataset to the model by firstly converting it into a pytorch-appropiate standard.
Parameters
local_dataset: list[datasets.arrow_dataset.Dataset] A local dataset that should be loaded into DataLoader node_name: int | str The name of the node attributed to particular dataset only_test: bool [default to False]: If true, only a test set will be returned batch_size: int [default to 32]: Batch size used in test and train loader higging_face_map: bool [default to True]: If set to True, will use hugging face map function, that takes more time to process but results in a more stable and reversable transformation of the results. Returns
None
Source code in FedJust\model\federated_model.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
evaluate_model()
Validate the network on the local test set.
Parameters
Returns
Tuple[float, float]: loss and accuracy on the test set.
Source code in FedJust\model\federated_model.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
|
get_gradients()
Get the gradients of the network (differences between received and trained model)
Parameters
Raises
Exception: if the original model was not preserved.
Returns
Oredered_Dict: Gradients of the network.
Source code in FedJust\model\federated_model.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
get_weights()
Get the weights of the network.
Parameters
Raises
Exception: if the model is not initialized it raises an exception.
Returns
_type_: weights of the network
Source code in FedJust\model\federated_model.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
preserve_initial_model()
Preserve the initial model provided at the end of the turn (necessary for computing gradients, when using aggregating methods such as FedOpt).
Parameters
Returns
Tuple[float, float]: Loss and accuracy on the training set.
Source code in FedJust\model\federated_model.py
277 278 279 280 281 282 283 284 285 286 287 288 289 |
|
store_model_on_disk(iteration, path)
Saves local model in a .pt format. Parameters
Iteration: int Current iteration Path: str Path to the saved repository
Returns:
None
Raises
Exception if the model is not initialized it raises an exception
Source code in FedJust\model\federated_model.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
|
train(iteration, epoch)
Train the network and computes loss and accuracy.
Parameters
iterations: int Current iteration epoch: int Current (local) epoch
Returns
None
Source code in FedJust\model\federated_model.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
|
transform_func(data)
Convers datasets.arrow_dataset.Dataset into a PyTorch Tensor Parameters
local_dataset: datasets.arrow_dataset.Dataset A local dataset that should be loaded into DataLoader only_test: bool [default to False]: If true, only a test set will be returned
Returns
None
Source code in FedJust\model\federated_model.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
|
update_weights(avg_tensors)
Updates the weights of the network stored on client with passed tensors.
Parameters
avg_tensors: Ordered_Dict An Ordered Dictionary containing a averaged tensors
Raises
Exception: description
Returns
None
Source code in FedJust\model\federated_model.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
Federated Nodes
A boilerplate code for creating Federated Node
FederatedNode
Source code in FedJust\node\federated_node.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
__init__()
An abstract object representing a single node in the federated training.
Parameters
None Returns
None
Source code in FedJust\node\federated_node.py
22 23 24 25 26 27 28 29 30 31 32 33 |
|
connect_data_id(node_id, model, data, orchestrator=False)
Attaches dataset and id to a node, creating an individualised version.
Parameters
node_id: int | str ID of the node model: FederatedModel FederatedModel template that should be copied and attached to the node data: Any Data to be attached to a FederatedModel. orchestrator: bool (default to False) Boolean flag if the node is belonging to the orchestrator Returns
None
Source code in FedJust\node\federated_node.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
get_weights()
Extended API call to recover model weights. Causes the same effect as calling node.model.get_weigts() Parameters
None Returns OrderedDict None
Source code in FedJust\node\federated_node.py
67 68 69 70 71 72 73 74 75 76 77 |
|
local_training(iteration, epoch)
Helper method for performing one epoch of local training. Performs one round of Federated Training and pack the results (metrics) into the appropiate data structure.
Parameters
Returns
dict[int, int]: metrics from the training.
Source code in FedJust\node\federated_node.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
train_local_model(iteration, local_epochs, mode='weights', save_model=False, save_path=None)
This function starts the server phase of the federated learning. In particular, it trains the model locally and then sends the weights. Then the updated weights are received and used to update the global model.
Parameters
node: FederatedNode Node that we want to train. iteration: int Current global iteration local_epochs: int Number of local epochs for which the node should be training. mode: str (default to 'weights') Mode = 'weights': Node will return model's weights. Mode = 'gradients': Node will return model's gradients. save_model: bool (default to False) Boolean flag to save a model. save_path: str (defualt to None) Path object used to save a model
Returns
Tuple[int, OrderedDict, List[float], List[float]]:
Source code in FedJust\node\federated_node.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
update_weights(weights)
Extended API call to update model. Causes the same effect as calling node.model.update_weights() Parameters
weights:OrderedDict OrderedDict to be uploaded onto the model. Returns None
Source code in FedJust\node\federated_node.py
80 81 82 83 84 85 86 87 88 89 90 91 |
|
Aggregators
Aggregators serve as a boilerplate for merging the weights derived from local models
Aggregator
Basic class for all Federated Aggregators
Source code in FedJust\aggregators\aggregator.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
aggregate_weights(weights)
Basic aggregate function (equal to FedAvg) that returns the aggregate version of the weights. Perform deepcopy on the passed parameters.
Parameters
weights: dict[int: OrderedDict]
Returns
OrderedDict
Source code in FedJust\aggregators\aggregator.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
Fedopt_Optimizer
Bases: Aggregator
Fedopt Optimizer that performs a generalized version of Federated Averaging. Suitable for performing Federated Optimization based on gradients, with verying learning rates.
Attributes
None
Source code in FedJust\aggregators\fedopt_aggregator.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
optimize_weights(weights, gradients, learning_rate)
FedOpt Aggregation Function (equal to FedAvg when lr=1.0) that returns the updated version of the weights.
Parameters
weights: dict[int: OrderedDict] Weights of the previous (central) model. gradients: dict[int: OrderedDict] Gradients (defined as trainedmodel - dispatched model) learning_rate: float Learning rate used to
Returns
OrderedDict
Source code in FedJust\aggregators\fedopt_aggregator.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
Simulations
Simulation class serve as a boilerplate code for simulating all the actions happening in the decentralised environment
Simulation
Simulation class representing a generic simulation type.
Attributes
model_template : FederatedModel Initialized instance of a Federated Model class that is uploaded to every client. node_template : FederatedNode Initialized instance of a Federated Node class that is used to simulate nodes. data : dict Local data used for the training in a dictionary format, mapping each client to its respective dataset.
Source code in FedJust\simulation\simulation.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
__init__(model_template, node_template, seed=42, **kwargs)
Creating simulation instant requires providing an already created instance of model template and node template. Those instances then will be copied n-times to create n different nodes, each with a different dataset. Additionally, a data for local nodes should be passed in form of a dictionary, maping dataset to each respective client.
Parameters
model_template : FederatedModel Initialized instance of a Federated Model class that will be uploaded to every client. node_template : FederatedNode Initialized instance of a Federated Node class that will be used to simulate nodes. seed : int, Seed for the simulation, default to 42 kwargs : dict, optional Extra arguments to enable selected features of the Orchestrator. passing full_debug to kwargs, allow to enter a full debug mode.
Returns
None
Source code in FedJust\simulation\simulation.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
attach_node_model(nodes_data)
Attaches models of the nodes to the simulation instance.
Parameters
orchestrator_data: Any Orchestrator data that should be attached to nodes models. Returns
None
Source code in FedJust\simulation\simulation.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
attach_orchestrator_model(orchestrator_data)
Attaches model of the orchestrator that is saved as an instance attribute.
Parameters
orchestrator_data: Any Orchestrator data that should be attached to the orchestrator model.
Returns
None
Source code in FedJust\simulation\simulation.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
train_epoch(sampled_nodes, iteration, local_epochs, mode='weights', save_model=False, save_path=None)
Performs one training round of a federated learning. Returns training results upon completion.
Parameters
samples_nodes: dict[int: FederatedNode] Dictionary containing sampled Federated Nodes iteration: int Current global iteration of the training process local_epochs: int Number of local epochs for which the local model should be trained. mode: str (default to 'weights') Mode = 'weights': Node will return model's weights. Mode = 'gradients': Node will return model's gradients. save_model: bool (default to False) Boolean flag to save a model. save_path: str (defualt to None) Path object used to save a model
Returns
tuple[dict[int, int, float, float, list, list], dict[int, OrderedDict]]
Source code in FedJust\simulation\simulation.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
training_protocol(iterations, sample_size, local_epochs, aggrgator, metrics_savepath, nodes_models_savepath, orchestrator_models_savepath)
Performs a full federated training according to the initialized settings. The train_protocol of the generic_orchestrator.Orchestrator follows a classic FedAvg algorithm - it averages the local weights and aggregates them taking a weighted average. SOURCE: Communication-Efficient Learning of Deep Networks from Decentralized Data, H.B. McMahan et al.
Parameters
iterations: int Number of (global) iterations // epochs to train the models for. sample_size: int Size of the sample local_epochs: int Number of local epochs for which the local model should be trained. aggregator: Aggregator Instance of the Aggregator object that will be used to aggregate the result each round metrics_savepath: str Path for saving the metrics nodes_models_savepath: str Path for saving the models in the .pt format. orchestrator_models_savepath: str Path for saving the orchestrator models.
Returns
int Returns 0 on the successful completion of the training.
Source code in FedJust\simulation\simulation.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
Adaptive_Optimizer_Simulation
Bases: Simulation
Simulation class representing a generic simulation type.
Attributes
model_template : FederatedModel Initialized instance of a Federated Model class that is uploaded to every client. node_template : FederatedNode Initialized instance of a Federated Node class that is used to simulate nodes. data : dict Local data used for the training in a dictionary format, mapping each client to its respective dataset.
Source code in FedJust\simulation\adaptive_optimizer_simulation.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
training_protocol(iterations, sample_size, local_epochs, aggrgator, learning_rate, metrics_savepath, nodes_models_savepath, orchestrator_models_savepath)
Performs a full federated training according to the initialized settings. The train_protocol of the generic_orchestrator.Orchestrator follows a classic FedOpt algorithm - it averages the local gradients and aggregates them using a selecred optimizer. SOURCE:
Parameters
iterations: int Number of (global) iterations // epochs to train the models for. sample_size: int Size of the sample local_epochs: int Number of local epochs for which the local model should be trained. aggregator: Aggregator Instance of the Aggregator object that will be used to aggregate the result each round learning_rate: float Learning rate to be used for optimization. metrics_savepath: str Path for saving the metrics nodes_models_savepath: str Path for saving the models in the .pt format. orchestrator_models_savepath: str Path for saving the orchestrator models.
Returns
int Returns 0 on the successful completion of the training.
Source code in FedJust\simulation\adaptive_optimizer_simulation.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
Opearations
A boilerplate code for some additional operations performed in a Federated scenario.
automatic_node_evaluation(iteration, nodes, save_path, logger=None, log_to_screen=False)
Used to automatically evaluate a set of provided node and preserve metrics in the indicated directory.
Parameters
iteration: int Current iteration of the training. nodes: dict[int: FederatedNode] Dictionary containing nodes to be evaluated. saving_path: str (default to None) The saving path of the csv file, must end with the .csv extension. logger: Logger (default to None) Logger object that we want to use to handle the logs. log_to_screen: bool (default to False) Boolean flag whether we want to log the results to the screen.
Returns
None
Source code in FedJust\operations\evaluations.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
evaluate_model(iteration, model, save_path, logger=None, log_to_screen=False)
Used to save the model metrics.
Parameters
iteration: int Current iteration of the training. model: FederatedModel FederatedModel to be evaluated saving_path: str (default to None) The saving path of the csv file, must end with the .csv extension. logger: Logger (default to None) Logger object that we want to use to handle the logs. log_to_screen: bool (default to False) Boolean flag whether we want to log the results to the screen.
Returns
None
Source code in FedJust\operations\evaluations.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
sample_nodes(nodes, sample_size, generator)
Sample the nodes given the provided sample size. If sample_size is bigger or equal to the number of av. nodes, the sampler will return the original list.
Parameters
nodes: dict[int: FederatedNode])
Original dictionary of nodes to be sampled from.
sample_size: int,
Size of the sample
generator: np.random.Generator
A numpy generator initialized on the server side.
Returns
dict[id: FederatedNode]
Source code in FedJust\operations\orchestrations.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
sample_weighted_nodes(nodes, sample_size, generator, sampling_array)
Sample the nodes given the provided sample size. It requires passing a sampling array containing list of weights associated with each node.
Parameters
nodes: dict[int: FederatedNode])
Original dictionary of nodes to be sampled from.
sample_size: int,
Size of the sample
generator: np.random.Generator
A numpy generator initialized on the server side.
sampling_array: np.array
Sampling array containing weights for the sampling
Returns
dict[id: FederatedNode]
Source code in FedJust\operations\orchestrations.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
train_nodes(node, iteration, local_epochs, mode='weights', save_model=False, save_path=None)
Used to command the node to start the local training. Invokes .train_local_model method and returns the results.
Parameters
node: FederatedNode Node that we want to train. iteration: int Current (global) iteration. local_epochs: int Number of local epochs for which to train a node mode: str (default to False) Mode of the training. Mode = 'weights': Node will return model's weights. Mode = 'gradients': Node will return model's gradients. save_model: bool (default to False) Boolean flag to enable model saving. save_path: str (default to None) Save path for preserving a model (applicable only when save_model = True) Returns
tpule[int, OrderedDict, List[float], List[float]]
Source code in FedJust\operations\orchestrations.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
Aggregators
A boilerplate code for functions serving to merge the local weights.
Aggregator
Basic class for all Federated Aggregators
Source code in FedJust\aggregators\aggregator.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
aggregate_weights(weights)
Basic aggregate function (equal to FedAvg) that returns the aggregate version of the weights. Perform deepcopy on the passed parameters.
Parameters
weights: dict[int: OrderedDict]
Returns
OrderedDict
Source code in FedJust\aggregators\aggregator.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
Fedopt_Optimizer
Bases: Aggregator
Fedopt Optimizer that performs a generalized version of Federated Averaging. Suitable for performing Federated Optimization based on gradients, with verying learning rates.
Attributes
None
Source code in FedJust\aggregators\fedopt_aggregator.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
optimize_weights(weights, gradients, learning_rate)
FedOpt Aggregation Function (equal to FedAvg when lr=1.0) that returns the updated version of the weights.
Parameters
weights: dict[int: OrderedDict] Weights of the previous (central) model. gradients: dict[int: OrderedDict] Gradients (defined as trainedmodel - dispatched model) learning_rate: float Learning rate used to
Returns
OrderedDict
Source code in FedJust\aggregators\fedopt_aggregator.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|