trainer
Trainer
¶
Bases: ABC
The base class of trainer.
ParameterType
¶
Bases: IntEnum
Define the type of parameter.
config()
¶
get training configuration.
Returns:
Type | Description |
---|---|
Dict[str, float]
|
return a dict, at least including the following keys: |
Dict[str, float]
|
learning_rate |
Dict[str, float]
|
batch_num |
Dict[str, float]
|
sample_num |
evaluate(epoch)
abstractmethod
¶
evaluate model and return metrics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
epoch |
int
|
the current index of epoch |
required |
Returns:
Type | Description |
---|---|
Dict[str, float]
|
dict, k: str (metric name), v: float (metric value) |
fit(epoch)
abstractmethod
¶
fit model on one epoch.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
epoch |
int
|
the current index of epoch |
required |
Returns:
Type | Description |
---|---|
None
|
None |
get(param_type=ParameterType.ParameterModel)
abstractmethod
¶
get parameters form the client, maybe the model parameter or gradient.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
param_type |
ParameterType
|
Param_type is ParameterModel or ParameterGradient, default is ParameterModel. |
ParameterType.ParameterModel
|
Returns:
Type | Description |
---|---|
Dict[str, npt.NDArray[np.float32]]
|
dict, k: str (the parameter name), v: np.ndarray (the parameter value) |
Source code in iflearner/business/homo/trainer.py
set(parameters, param_type=ParameterType.ParameterModel)
abstractmethod
¶
set parameters to the client, maybe the model parameter or gradient.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters |
Dict[str, npt.NDArray[np.float32]]
|
Parameters is the same as the return of 'get' function. |
required |
param_type |
ParameterType
|
Param_type is ParameterModel or ParameterGradient, default is ParameterModel. |
ParameterType.ParameterModel
|