worker.learner.comm¶
learner_comm¶
BaseCommLearner¶
- class ding.worker.learner.comm.base_comm_learner.BaseCommLearner(cfg: EasyDict)[source]¶
- Overview:
Abstract baseclass for CommLearner.
- Interfaces:
__init__, send_policy, get_data, send_learn_info, start, close
- Property:
hooks4call
- __init__(cfg: EasyDict) None[source]¶
- Overview:
Initialization method.
- Arguments:
cfg (
EasyDict): Config dict
- abstract get_data(batch_size: int) list[source]¶
- Overview:
Get batched meta data from coordinator. Will be registered in base learner.
- Arguments:
batch_size (
int): Batch size.
- Returns:
stepdata (
list): A list of training data, each element is one trajectory.
- abstract send_learn_info(learn_info: dict) None[source]¶
- Overview:
Send learn info to coordinator. Will be registered in base learner.
- Arguments:
learn_info (
dict): Learn info in dict type.
FlaskFileSystemLearner¶
- class ding.worker.learner.comm.flask_fs_learner.FlaskFileSystemLearner(cfg: EasyDict)[source]¶
- Overview:
An implementation of CommLearner, using flask and the file system.
- Interfaces:
__init__, send_policy, get_data, send_learn_info, start, close
- Property:
hooks4call
- close() None[source]¶
- Overview:
Join learner thread and close learner if still running. Then close learner slave and comm learner itself.
- get_data(batch_size: int) List[Callable][source]¶
- Overview:
Get a list of data loading function, which can be implemented by dataloader to read data from files.
- Arguments:
batch_size (
int): Batch size.
- Returns:
data (
List[Callable]): A list of callable data loading function.
- send_learn_info(learn_info: dict) None[source]¶
- Overview:
Store learn info dict in queue, which will be retrieved by callback function “deal_with_learner_learn” in learner slave, then will be sent to coordinator.
- Arguments:
learn_info (
dict): Learn info in dict type. Keys are like ‘learner_step’, ‘priority_info’ ‘finished_task’, etc. You can refer tolearn_info``(``worker/learner/base_learner.py) for details.
create_comm_learner¶
- Overview:
Given the key(comm_learner_name), create a new comm learner instance if in comm_map’s values, or raise an KeyError. In other words, a derived comm learner must first register, then can call
create_comm_learnerto get the instance.- Arguments:
cfg (
dict): Learner config. Necessary keys: [import_names, comm_learner_type].
- Returns:
learner (
BaseCommLearner): The created new comm learner, should be an instance of one of comm_map’s values.