How to set configuration
All runs use OmegaConf, a hierarchical configuration system.
Load default configuration
Every run requires to set the configuration defined in DictConfig format. We can easily load the default configuration setting by
[3]:
from appfl.config import *
cfg: DictConfig = OmegaConf.structured(Config)
The configuration cfg is initialized with the default values. Let’s check the configuration values.
[4]:
print(OmegaConf.to_yaml(cfg))
fed:
type: fedavg
servername: FedAvgServer
clientname: FedAvgClient
args:
num_local_epochs: 1
loss_type: torch.nn.CrossEntropyLoss()
optim: SGD
optim_args:
lr: 0.01
momentum: 0.9
weight_decay: 1.0e-05
epsilon: false
clip_value: false
clip_norm: 1
num_epochs: 2
batch_training: true
train_data_batch_size: 64
train_data_shuffle: false
test_data_batch_size: 64
test_data_shuffle: false
load_model: false
load_model_dirname: ''
load_model_filename: ''
save_model: false
save_model_dirname: ''
save_model_filename: ''
output_dirname: ./outputs
output_filename: result
device: cpu
validation: true
max_message_size: 10485760
operator:
id: 1
server:
id: 1
host: localhost
port: 50051
use_tls: false
api_key: null
client:
id: 1
Most variables are self-explanatory.
Variable
fedsets the choice of algorithms, each of which is also defined as a dataclass. The classes should be accessible byappfl.config.fed.*.gRPC configurations:
max_message_size: the maximum size of data to be sent or received in a single RPC call, default 10 MB. If the size of weights for a single neuron is larger than 10 MB, you need to increase this value.host: the URL of a serverport: the port number of a server
Initialize configuration with arguments
We can also initialize the configuration with other values. For example, the following code is loading the configuration with the algorithm choice of IIADMM.
[5]:
cfg: DictConfig = OmegaConf.structured(Config(
fed = fed.iiadmm.IIADMM()
))
print(OmegaConf.to_yaml(cfg.fed))
type: iiadmm
servername: IIADMMServer
clientname: IIADMMClient
args:
num_local_epochs: 1
loss_type: torch.nn.CrossEntropyLoss()
accum_grad: true
coeff_grad: false
optim: SGD
optim_args:
lr: 0.01
init_penalty: 100.0
residual_balancing:
res_on: false
res_on_every_update: false
tau: 1.1
mu: 10
epsilon: false
clip_value: false
clip_norm: 1
Change configuration values
We can also change the configuration value after initialization. For example, we can change fed variable as follows:
[6]:
cfg: DictConfig = OmegaConf.structured(Config)
my_fed: DictConfig = OmegaConf.structured(fed.fedavg.FedAvg)
cfg.fed = my_fed
print(OmegaConf.to_yaml(cfg.fed))
type: fedavg
servername: FedAvgServer
clientname: FedAvgClient
args:
num_local_epochs: 1
loss_type: torch.nn.CrossEntropyLoss()
optim: SGD
optim_args:
lr: 0.01
momentum: 0.9
weight_decay: 1.0e-05
epsilon: false
clip_value: false
clip_norm: 1