Shortcuts

framework.middleware.functional.data_processor

data_processor

data_pusher

ding.framework.middleware.functional.data_processor.data_pusher(cfg: EasyDict, buffer_: Buffer, group_by_env: bool | None = None)[source]
Overview:

Push episodes or trajectories into the buffer.

Arguments:
  • cfg (EasyDict): Config.

  • buffer (Buffer): Buffer to push the data in.

offpolicy_data_fetcher

ding.framework.middleware.functional.data_processor.offpolicy_data_fetcher(cfg: EasyDict, buffer_: Buffer | List[Tuple[Buffer, float]] | Dict[str, Buffer], data_shortage_warning: bool = False) Callable[source]
Overview:

The return function is a generator which meanly fetch a batch of data from a buffer, a list of buffers, or a dict of buffers.

Arguments:
  • cfg (EasyDict): Config which should contain the following keys: cfg.policy.learn.batch_size.

  • buffer (Union[Buffer, List[Tuple[Buffer, float]], Dict[str, Buffer]]): The buffer where the data is fetched from. Buffer type means a buffer. List[Tuple[Buffer, float]] type means a list of tuple. In each tuple there is a buffer and a float. The float defines, how many batch_size is the size of the data which is sampled from the corresponding buffer. Dict[str, Buffer] type means a dict in which the value of each element is a buffer. For each key-value pair of dict, batch_size of data will be sampled from the corresponding buffer and assigned to the same key of ctx.train_data.

  • data_shortage_warning (bool): Whether to output warning when data shortage occurs in fetching.

offline_data_fetcher

ding.framework.middleware.functional.data_processor.offline_data_fetcher(cfg: ~easydict.EasyDict, dataset: ~torch.utils.data.dataset.Dataset, collate_fn=<function <lambda>>) Callable[source]
Overview:

The outer function transforms a Pytorch Dataset to DataLoader. The return function is a generator which each time fetches a batch of data from the previous DataLoader. Please refer to the link https://pytorch.org/tutorials/beginner/basics/data_tutorial.html and https://pytorch.org/docs/stable/data.html for more details.

Arguments:
  • cfg (EasyDict): Config which should contain the following keys: cfg.policy.learn.batch_size.

  • dataset (Dataset): The dataset of type torch.utils.data.Dataset which stores the data.

offline_data_saver

ding.framework.middleware.functional.data_processor.offline_data_saver(data_path: str, data_type: str = 'hdf5') Callable[source]
Overview:

Save the expert data of offline RL in a directory.

Arguments:
  • data_path (str): File path where the expert data will be written into, which is usually ./expert.pkl’.

  • data_type (str): Define the type of the saved data. The type of saved data is pkl if data_type == ‘naive’. The type of saved data is hdf5 if data_type == ‘hdf5’.

sqil_data_pusher

ding.framework.middleware.functional.data_processor.sqil_data_pusher(cfg: EasyDict, buffer_: Buffer, expert: bool) Callable[source]
Overview:

Push trajectories into the buffer in sqil learning pipeline.

Arguments:
  • cfg (EasyDict): Config.

  • buffer (Buffer): Buffer to push the data in.

  • expert (bool): Whether the pushed data is expert data or not. In each element of the pushed data, the reward will be set to 1 if this attribute is True, otherwise 0.