strategy_server
StrategyServer(num_clients, total_epoch)
¶
Bases: ABC
Implement the strategy of server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_clients |
int
|
client number |
required |
total_epoch |
int
|
the epoch number of client trainning |
required |
Attributes:
Name | Type | Description |
---|---|---|
_num_clients |
int)
|
client number |
_total_epoch |
int
|
the epoch number of client trainning |
_custom_handlers |
Dict[str, Any]
|
|
_complete_num |
int
|
the number of client that has completed federated learning |
_clients |
Dict[str, ClientStatus])
|
a dict storage the client status |
_training_clients |
dict)
|
a dict storage the training clients |
_server_param |
dict
|
the server model |
_ready_num |
int
|
the number of ready client |
_uploaded_num |
int
|
the number of client that has uploaded its model parameters |
_aggregated_num |
int
|
the number of client that has aggregated its model parameters |
_on_aggregating |
bool
|
whether the server is in aggregating stage |
_params |
dict
|
the server model parameters |
Source code in iflearner/business/homo/strategy/strategy_server.py
clients_to_json()
¶
save clients to json file.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
json string |
Source code in iflearner/business/homo/strategy/strategy_server.py
get_client_notification(party_name)
¶
Get the notification information of the specified client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
party_name |
str
|
client name |
required |
Returns:
Type | Description |
---|---|
Tuple[str, Any]
|
Tuple[str, Any]: the notification message type and notification data |
Source code in iflearner/business/homo/strategy/strategy_server.py
handler_client_ready(party_name)
¶
Handle the message of MSG_CLIENT_READY from the client.
Source code in iflearner/business/homo/strategy/strategy_server.py
handler_complete(party_name)
¶
Handle the message of MSG_COMPLETE from the client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
party_name |
str
|
client name |
required |
Raises:
Type | Description |
---|---|
HomoException
|
if party_name not in the register list, raise the Unauthorized error |
Source code in iflearner/business/homo/strategy/strategy_server.py
handler_register(party_name, sample_num=0, step_num=0)
¶
Handle the message of MSG_REGISTER from the client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
party_name |
str
|
client name |
required |
sample_num |
Optional[int]
|
the total sample number of client |
0
|
step_num |
int
|
The number a client epoch needs to be optimized, always equals to the batch number of client. Defaults to 0. |
0
|
Raises:
Type | Description |
---|---|
HomoException
|
description |
Returns:
Type | Description |
---|---|
homo_pb2.RegistrationResponse
|
homo_pb2.RegistrationResponse: if party_name not in the register list, raise the Unauthorized error |
Source code in iflearner/business/homo/strategy/strategy_server.py
handler_upload_param(party_name, data)
¶
Handle the message of MSG_UPLOAD_PARAM from the client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
party_name |
str
|
client name |
required |
data |
homo_pb2.UploadParam
|
the data uploaded from |
required |
Raises:
Type | Description |
---|---|
HomoException
|
if party_name not in the training_clients list, raise the Forbidden error |