modelzoo.transformers.pytorch.gpt2.input.GptHDF5MapDataProcessor.GptHDF5MapDataProcessor#

class modelzoo.transformers.pytorch.gpt2.input.GptHDF5MapDataProcessor.GptHDF5MapDataProcessor[source]#

Bases: object

A map style dataset for GPT style models.

Supports data saved on disk in either of the following formats:
  • (num_tokens,), i.e. a set of documents tokenized and concatenated.

    We refer to this as the ‘corpus’ format in what follows.

  • (num_sequences, 3, sequence_length), i.e. data that has already

    been preprocessed into sequences. We refer to this as the ‘sample’ format in what follows.

Parameters

params (dict) –

a dictionary containing the following fields: - “data_dir” (str or list[str]): the path to the HDF5 files.

Exactly one of “data_dir” or “mixture” must be specified.

  • ”batch_size” (int): batch size

  • ”shuffle” (bool): whether or not to shuffle the dataset. Defaults

    to False

  • ”shuffle_seed” (int): seed used for deterministic shuffling.

    Defaults to 0.

  • ”use_worker_cache” (bool): whether or not to copy data to storage

    that is directly attached to each individual worker node. Useful when your network storage is unusually slow, but otherwise discouraged.

  • ”max_sequence_length” (int): the sequence length of samples

    produced by the dataloader. When using the ‘corpus’ data format, the same preprocessed data will work with any max sequence length, so this may be set at runtime. When using the ‘sample’ format this must be set to None.

  • ”data_subset” (str): an optional specification to only consider a

    subset of the full dataset, useful for sequence length scheduling and multi-epoch testing. Expected to be a comma separated list of ranges, e.g. ‘0.0-0.5’ or ‘0.1-0.3,0.7-1.0’. Specifying ‘0.0-0.5’ creates a dataset from the first half of the data on disk and disregards the second half.

  • ”mixture” list[dict]: an optional specification of multiple

    datasets to mix over to create one single weighted combination. Each element must be a dictionary containing keys data_dir and weight. data_dir serves the same purpose as mentioned above. weight defines the probability with which this dataset should be sampled from. Weights are normalized to sum to 1. Optionally, the dictionary may also contain a data_subset field which functions the same as the data_subset argument above.

  • ”drop_last” (bool): similar to the PyTorch drop_last setting

    except that samples that when set to True, samples that would have been dropped at the end of one epoch are yielded at the start of the next epoch so that there is no data loss. This is necessary for a data ordering that is independent of the distributed setup being used.

  • ”num_samples” (int): the number of samples to shuffle over (if

    shuffling is enabled). In multi-epoch training, it is common to set this to the total number of samples that you plan to train on so that epochs are not sequential but instead shuffled together for potentially improved convergence.

  • ”num_workers” (int): the number of PyTorch processes used in the

    dataloader. Defaults to 0.

  • ”prefetch_factor” (int): the number of batches to prefetch in the

    dataloader. Defaults to 10.

  • ”persistent_workers” (bool): whether or not to keep workers

    persistent between epochs. Defaults to True.

  • ”sort_files” (bool): whether or not the reader should sort the input

    files. This is included for backwards compatibility and should almost always be set to True.

  • ”use_vsl” (bool): Flag to enable variable sequence length training.

    It requires the dataset to have two extra features: the attention_span of keys and the position_ids of tokens. Defaults to False.

Methods

create_dataloader

__init__(params)[source]#