xain_fl.config package¶
This package provides the logic for reading and validating the various configuration options exposed by the CLI and the toml config file.
-
xain_fl.config.
get_cmd_parameters
()¶ Parse the command arguments
- Returns
the parsed command arguments
- Return type
-
class
xain_fl.config.
Config
(ai, storage, server, logging, metrics)¶ Bases:
object
The coordinator configuration.
Configuration is split in three sections: Config.ai for items directly related to the FL protocol, Config.server for the server infrastructure, and Config.storage for storage related items.
The configuration is usually loaded from a dictionary the Config attributes map to the dictionary keys.
- Parameters
ai (
NamedTuple
) – the configuration corresponding to the [ai] section of the toml config filestorage (
NamedTuple
) – the configuration corresponding to the [storage] section of the toml config filserver (
NamedTuple
) – the configuration corresponding to the [server] section of the toml config filelogging (
NamedTuple
) – the configuration corresponding to the [logging] section of the toml config filemetrics (
NamedTuple
) – the configuration corresponding to the [metrics] section of the toml config file
- Example
Here is a valid configuration:
# This section correspond to the `Config.server` attribute [server] # Address to listen on for incoming gRPC connections host = "[::]" # Port to listen on for incoming gRPC connections port = 50051 # This section corresponds to the `Config.ai` attribute [ai] # Number of global rounds the model is going to be trained for. This # must be a positive integer. rounds = 1 # Number of local epochs per round epochs = 1 # Minimum number of participants to be selected for a round. min_participants = 1 # Fraction of total clients that participate in a training round. This # must be a float between 0 and 1. fraction_participants = 1.0 # This section corresponds to the `Config.storage` attribute [storage] # URL to the storage service to use endpoint = "http://localhost:9000" # Name of the bucket for storing the models bucket = "weights" # AWS secret access to use to authenticate to the storage service secret_access_key = "my-secret" # AWS access key ID to use to authenticate to the storage service access_key_id = "my-key-id"
This config file can be loaded and used as follows:
from xain_fl.config import Config config = Config.load("example_config.toml") assert config.server.host == "[::]" assert config.server.port == 50051 assert config.ai.rounds == 1 assert config.ai.epochs == 1 assert config.ai.min_participants == 1 assert config.ai.fraction_participants == 1.0 assert config.storage.endpoint == "http://localhost:9000" assert config.storage.global_weights_bucket == "global_weights" assert config.storage.local_weights_bucket == "local_weights" assert config.storage.secret_access_key == "my-access-key" assert config.storage.access_key_id == "my-key"
-
classmethod
from_unchecked_dict
(dictionary)¶ Check if the given dictionary contains a valid configuration, and if so, create a Config instance from it.
-
classmethod
from_valid_dict
(dictionary)¶ Create a Config instance for the given dictionary, assuming it contains a valid configuration
-
class
xain_fl.config.
AiConfig
¶ Bases:
tuple
FL configuration: number of participant to each training round, etc.
-
property
epochs
¶ Alias for field number 1
-
property
fraction_participants
¶ Alias for field number 3
-
property
min_participants
¶ Alias for field number 2
-
property
rounds
¶ Alias for field number 0
-
property
-
class
xain_fl.config.
LoggingConfig
¶ Bases:
tuple
Logging related configuration: log level, colors, etc.
-
property
console
¶ Alias for field number 1
-
property
level
¶ Alias for field number 0
-
property
third_party
¶ Alias for field number 2
-
property
-
class
xain_fl.config.
StorageConfig
¶ Bases:
tuple
Storage related configuration: storage endpoints and credentials, etc.
-
property
access_key_id
¶ Alias for field number 3
-
property
bucket
¶ Alias for field number 1
-
property
endpoint
¶ Alias for field number 0
-
property
secret_access_key
¶ Alias for field number 2
-
property
-
class
xain_fl.config.
ServerConfig
¶ Bases:
tuple
The server configuration: TLS, addresses for incoming connections, etc.
-
property
grpc_options
¶ Alias for field number 2
-
property
heartbeat_time
¶ Alias for field number 4
-
property
heartbeat_timeout
¶ Alias for field number 5
-
property
host
¶ Alias for field number 0
-
property
port
¶ Alias for field number 1
-
property
thread_pool_workers
¶ Alias for field number 3
-
property
-
class
xain_fl.config.
MetricsConfig
¶ Bases:
tuple
Metrics related configuration: InfluxDB host, InfluxDB port, etc.
-
property
db_name
¶ Alias for field number 5
-
property
enable
¶ Alias for field number 0
-
property
host
¶ Alias for field number 1
-
property
password
¶ Alias for field number 4
-
property
port
¶ Alias for field number 2
-
property
user
¶ Alias for field number 3
-
property
-
exception
xain_fl.config.
InvalidConfig
¶ Bases:
ValueError
Exception raised upon trying to load an invalid configuration
Submodules¶
xain_fl.config.cli module¶
This module provides helpers for parsing the CLI arguments.
xain_fl.config.schema module¶
This module provides helpers for reading and validating the TOML configuration.
-
class
xain_fl.config.schema.
AiConfig
¶ Bases:
tuple
FL configuration: number of participant to each training round, etc.
-
property
epochs
¶ Alias for field number 1
-
property
fraction_participants
¶ Alias for field number 3
-
property
min_participants
¶ Alias for field number 2
-
property
rounds
¶ Alias for field number 0
-
property
-
class
xain_fl.config.schema.
Config
(ai, storage, server, logging, metrics)¶ Bases:
object
The coordinator configuration.
Configuration is split in three sections: Config.ai for items directly related to the FL protocol, Config.server for the server infrastructure, and Config.storage for storage related items.
The configuration is usually loaded from a dictionary the Config attributes map to the dictionary keys.
- Parameters
ai (
NamedTuple
) – the configuration corresponding to the [ai] section of the toml config filestorage (
NamedTuple
) – the configuration corresponding to the [storage] section of the toml config filserver (
NamedTuple
) – the configuration corresponding to the [server] section of the toml config filelogging (
NamedTuple
) – the configuration corresponding to the [logging] section of the toml config filemetrics (
NamedTuple
) – the configuration corresponding to the [metrics] section of the toml config file
- Example
Here is a valid configuration:
# This section correspond to the `Config.server` attribute [server] # Address to listen on for incoming gRPC connections host = "[::]" # Port to listen on for incoming gRPC connections port = 50051 # This section corresponds to the `Config.ai` attribute [ai] # Number of global rounds the model is going to be trained for. This # must be a positive integer. rounds = 1 # Number of local epochs per round epochs = 1 # Minimum number of participants to be selected for a round. min_participants = 1 # Fraction of total clients that participate in a training round. This # must be a float between 0 and 1. fraction_participants = 1.0 # This section corresponds to the `Config.storage` attribute [storage] # URL to the storage service to use endpoint = "http://localhost:9000" # Name of the bucket for storing the models bucket = "weights" # AWS secret access to use to authenticate to the storage service secret_access_key = "my-secret" # AWS access key ID to use to authenticate to the storage service access_key_id = "my-key-id"
This config file can be loaded and used as follows:
from xain_fl.config import Config config = Config.load("example_config.toml") assert config.server.host == "[::]" assert config.server.port == 50051 assert config.ai.rounds == 1 assert config.ai.epochs == 1 assert config.ai.min_participants == 1 assert config.ai.fraction_participants == 1.0 assert config.storage.endpoint == "http://localhost:9000" assert config.storage.global_weights_bucket == "global_weights" assert config.storage.local_weights_bucket == "local_weights" assert config.storage.secret_access_key == "my-access-key" assert config.storage.access_key_id == "my-key"
-
classmethod
from_unchecked_dict
(dictionary)¶ Check if the given dictionary contains a valid configuration, and if so, create a Config instance from it.
-
classmethod
from_valid_dict
(dictionary)¶ Create a Config instance for the given dictionary, assuming it contains a valid configuration
-
exception
xain_fl.config.schema.
InvalidConfig
¶ Bases:
ValueError
Exception raised upon trying to load an invalid configuration
-
class
xain_fl.config.schema.
LoggingConfig
¶ Bases:
tuple
Logging related configuration: log level, colors, etc.
-
property
console
¶ Alias for field number 1
-
property
level
¶ Alias for field number 0
-
property
third_party
¶ Alias for field number 2
-
property
-
class
xain_fl.config.schema.
MetricsConfig
¶ Bases:
tuple
Metrics related configuration: InfluxDB host, InfluxDB port, etc.
-
property
db_name
¶ Alias for field number 5
-
property
enable
¶ Alias for field number 0
-
property
host
¶ Alias for field number 1
-
property
password
¶ Alias for field number 4
-
property
port
¶ Alias for field number 2
-
property
user
¶ Alias for field number 3
-
property
-
class
xain_fl.config.schema.
ServerConfig
¶ Bases:
tuple
The server configuration: TLS, addresses for incoming connections, etc.
-
property
grpc_options
¶ Alias for field number 2
-
property
heartbeat_time
¶ Alias for field number 4
-
property
heartbeat_timeout
¶ Alias for field number 5
-
property
host
¶ Alias for field number 0
-
property
port
¶ Alias for field number 1
-
property
thread_pool_workers
¶ Alias for field number 3
-
property
-
class
xain_fl.config.schema.
StorageConfig
¶ Bases:
tuple
Storage related configuration: storage endpoints and credentials, etc.
-
property
access_key_id
¶ Alias for field number 3
-
property
bucket
¶ Alias for field number 1
-
property
endpoint
¶ Alias for field number 0
-
property
secret_access_key
¶ Alias for field number 2
-
property
-
xain_fl.config.schema.
create_class_from_schema
(class_name, schema)¶ Create a class named class_name from the given schema, where the attributes of the new class are the schema’s keys.
-
xain_fl.config.schema.
error
(key, description)¶ Return an error message for the given configuration item and description of the expected value type.
-
xain_fl.config.schema.
hostname_or_ip_address
(key, expected_value='a valid domain name or IP address')¶ Return a hostname or IP address validator for the given configuration item.
-
xain_fl.config.schema.
is_valid_hostname
(value)¶ Return whether the given string is a valid hostname
-
xain_fl.config.schema.
is_valid_ip_address
(value)¶ Return whether the given string is a valid IP address
-
xain_fl.config.schema.
log_level
(key)¶ Return a validator for logging levels
- Parameters
key (
str
) – key of the configuration item- Return type
Schema
-
xain_fl.config.schema.
non_negative_integer
(key, expected_value='a positive integer')¶ Return a non-negative integer validator for the given configuration item.
-
xain_fl.config.schema.
positive_integer
(key, expected_value='a strictly positive integer')¶ Return a validator for strictly positive integers for the given configuration item.