flgo.algorithm.vflbase
ActiveParty
Bases: PassiveParty
This is the implementation of the active party in vertival FL. The active party owns the data label information and may also own parts of data features. If a active party owns data features, it is also a passive party simultaneously.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
option |
dict
|
running-time option |
required |
Source code in flgo\algorithm\vflbase.py
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 |
|
communicate(selected_clients, mtype=0, asynchronous=False)
The whole simulating communication procedure with the selected clients. This part supports for simulating the client dropping out.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selected_clients |
the clients to communicate with |
required |
Returns:
Type | Description |
---|---|
the unpacked response from clients that is created ny self.unpack() |
Source code in flgo\algorithm\vflbase.py
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 |
|
defuse(fusion)
Defuse the fusion into derivations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fusion |
Any
|
the fused result |
required |
Returns:
Name | Type | Description |
---|---|---|
derivations |
list
|
a list of derivations |
Source code in flgo\algorithm\vflbase.py
302 303 304 305 306 307 308 309 310 311 312 |
|
fuse(activations)
Fuse the activations into one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
activations |
list
|
a list of activations from all the passive parties |
required |
Returns:
Name | Type | Description |
---|---|---|
fusion |
Any
|
the fused result |
Source code in flgo\algorithm\vflbase.py
290 291 292 293 294 295 296 297 298 299 300 |
|
get_batch_data()
Get the batch of data
Returns:
Name | Type | Description |
---|---|---|
batch_data |
Any
|
a batch of data |
Source code in flgo\algorithm\vflbase.py
260 261 262 263 264 265 266 267 268 269 270 271 |
|
iterate()
The standard VFL process.
-
The active party first generates the batch information.
-
Then, it collects activations from all the passive parties.
-
Thirdly, it continues the forward passing and backward passing to update the decoder part of the model, and distributes the derivations to parties.
-
Finally, each passive party will update its local_movielens_recommendation modules accoring to the derivations and activations.
Returns:
Name | Type | Description |
---|---|---|
updated |
bool
|
whether the model is updated in this iteration |
Source code in flgo\algorithm\vflbase.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
pack(party_id, mtype=0)
Pack the necessary information to parties into packages.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
party_id |
int
|
the id of the party |
required |
mtype |
Any
|
the message type |
0
|
Returns:
Name | Type | Description |
---|---|---|
package |
dict
|
the package |
Source code in flgo\algorithm\vflbase.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
|
run()
Start the federated learning symtem where the global model is trained iteratively.
Source code in flgo\algorithm\vflbase.py
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 |
|
set_model_mode(mode='train')
Set all the modes of the modules owned by all the parties.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mode |
str
|
the mode of models |
'train'
|
Source code in flgo\algorithm\vflbase.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
|
test(flag='test')
Test the performance of the model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
flag |
str
|
the type of dataset |
'test'
|
Returns:
Name | Type | Description |
---|---|---|
result |
dict
|
a dict that contains the testing result |
Source code in flgo\algorithm\vflbase.py
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 |
|
unpack(packages_received_from_clients)
Unpack the information from the received packages. Return models and losses as default.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
packages_received_from_clients |
list of dict
|
required |
Returns:
Name | Type | Description |
---|---|---|
res |
dict
|
collections.defaultdict that contains several lists of the clients' reply |
Source code in flgo\algorithm\vflbase.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
update_global_module(activations, model)
Update the global module by computing the forward passing and the backward passing. The attribute self.defusion and self.fusion.grad will be changed after calling this method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
activations |
list
|
a list of activations from all the passive parties |
required |
model |
torch.nn.Module | flgo.utils.fmodule.FModule
|
the model |
required |
Source code in flgo\algorithm\vflbase.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
|
PassiveParty
Bases: BasicParty
This is the implementation of the passive party in vertival FL. The passive party owns only a part of data features without label information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
option |
dict
|
running-time option |
required |
Source code in flgo\algorithm\vflbase.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 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 |
|
backward(package)
Local backward to computing the gradients on local_movielens_recommendation modules
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package |
dict
|
the package from the active party that contains the derivations |
required |
Source code in flgo\algorithm\vflbase.py
59 60 61 62 63 64 65 66 67 68 |
|
forward(package={})
Local forward to computing the activations on local_movielens_recommendation features
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package |
dict
|
the package from the active party that contains batch information and the type of data |
{}
|
Returns:
Name | Type | Description |
---|---|---|
passive_package |
dict
|
the package that contains the activation to be sent to the active party |
Source code in flgo\algorithm\vflbase.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
forward_test(package)
Local forward to computing the activations on local_movielens_recommendation features for testing
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package |
dict
|
the package from the active party that contains batch information and the type of data |
required |
Returns:
Name | Type | Description |
---|---|---|
passive_package |
dict
|
the package that contains the activation to be sent to the active party |
Source code in flgo\algorithm\vflbase.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
update_local_module(derivation, activation)
Update local_movielens_recommendation modules according to the derivation and the activation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
derivation |
Any
|
the derivation from the active party |
required |
activation |
Any
|
the local_movielens_recommendation computed activation |
required |
Source code in flgo\algorithm\vflbase.py
70 71 72 73 74 75 76 77 78 79 80 81 82 |
|