data_juicer.utils.ckpt_utils module

class data_juicer.utils.ckpt_utils.CheckpointManager(ckpt_dir, original_process_list, num_proc=1)[源代码]

基类:object

This class is used to save the latest version of dataset to checkpoint directory or load it from checkpoint directory, a bit like cache management Rerun the same config will reload the checkpoint and skip ops before it.

If any args of operator in process list is changed, all ops will be rerun from the beginning.

__init__(ckpt_dir, original_process_list, num_proc=1)[源代码]

Initialization method.

参数:
  • ckpt_dir -- path to save and load checkpoint

  • original_process_list -- process list in config

  • num_proc -- number of process workers when saving dataset

get_left_process_list()[源代码]

Get left process list of ops for processing dataset, when checkpoint is available, remove some ops from process list, otherwise keep it unchanged.

返回:

process list of left ops

check_ckpt()[源代码]

Check if checkpoint is available.

返回:

True when checkpoint is available, else False

record(op_cfg: dict)[源代码]

Save op name and args to op record, which is used to compare with the process list from config to decide if a checkpoint is available.

check_ops_to_skip()[源代码]

Check which ops need to be skipped in the process list.

If op record list from checkpoint are the same as the prefix part of process list, then skip these ops and start processing from the checkpoint. Otherwise, process the original dataset from scratch.

返回:

whether to skip some ops or not

save_ckpt(ds)[源代码]

Save dataset to checkpoint directory and dump processed ops list.

参数:

ds -- input dataset to save

load_ckpt()[源代码]

Load dataset from a checkpoint file.

返回:

a dataset stored in checkpoint file.