def _validate_config(
    max_seq_len: int,
    decoder_only_format: Optional[bool] = None,
    hf_name: Optional[str] = None,
    local: Optional[str] = None,
    remote: Optional[str] = None,
    hf_kwargs: Optional[dict[str, Any]] = None,
    preprocessing_fn: Optional[str] = None,
    safe_load: Optional[bool] = None,
    streams: Optional[dict[str, Any]] = None,
    target_prompts: Optional[str] = None,
    target_responses: Optional[str] = None,
    allowed_dataset_keys: set[str] = _ALLOWED_DATASET_KEYS,
    **kwargs: dict[str, Any],
) -> set[str]:
    """Validates the dataset configuration.

    Makes sure that the dataset is properly configured for either
    a HuggingFace dataset or a streaming dataset. Must be valid for one or
    the other.

    Args:
        max_seq_len (int): The maximum length of sequences
            in the batch. See :class:`Seq2SeqFinetuningCollator` docstring
            for details.
        decoder_only_format (bool, optional): Whether to format the
            examples for a decoder-only model. See :class:`Seq2SeqFinetuningCollator`
            docstring for details.
        hf_name (str, optional): The name of the HuggingFace dataset
            to use. Can also be a remote http(s) directory or object store bucket
            containing the file {split}.jsonl in the format (prompt, response),
            in which case the builder will create a HuggingFace dataset.
        local (str, optional): Local path where remote data
            will be streamed to. Only valid if `cfg.dataset.remote` has
            also been set.
        remote (str, optional): Location of a MDS-formatted
            streaming dataset to use. Setting this will tell the builder
            to create a streaming dataset rather than a HuggingFace dataset.
        hf_kwargs (DictConfig, optional): Additional kwargs to
            pass to `datasets.load_dataset`, which can be used to load
            a dataset from local files.
        preprocessing_fn (str, optional): The name/import path of
            the preprocessing function to use for formatting the data examples.
            If ``None`` (default), the builder will use the preprocessing function
                registered under `hf_name` (see `tasks.py`), if one exists,
                otherwise it will skip preprocessing.
            If `preprocessing_fn` corresponds to a registered preprocessing
                function in `tasks.py`, the builder will use that.
            Otherwise, it will interpret `preprocessing_fn` as a
                "import.path:function_name" import path; e.g., it will call
                `from import.path import function_name` and use the imported
                function as the preprocessing function.
        safe_load (bool, optional): Whether to enforce safe loading of the dataset.
            If `None`, will default to not applying any safe loading.
        streams (Dict[str, Any], optional): A dictionary with multiple data streams.
            If `None`, will assume no streams.
        target_prompts (str): Which prompts are used as training targets.
            Defaults to "none", meaning prompts are never used as training targets.
            See :class:`Seq2SeqFinetuningCollator` docstring for details.
        target_responses (str): Which responses are used as training targets.
            Defaults to "last", meaning only the final response in multi-turn examples
            will serve as training targets. See :class:`Seq2SeqFinetuningCollator` docstring for
            details.
        allowed_dataset_keys (set[str], optional): The set of allowed keys for the dataset config.
        kwargs (DictConfig, optional): Additional kwargs to
                pass to `datasets.load_dataset`, which can be used to load
                a dataset from local files.

    Raises:
        ValueError: If the dataset configuration does not meet the requirements.

    Returns:
        set[str]: Return the extraneous keys.
    """
    if decoder_only_format is None:
        raise ValueError(
            f'decoder_only_format must be set to either True or False, but it was {decoder_only_format}.',
        )

    extraneous_keys = set()
    if not set(kwargs.keys()).issubset(allowed_dataset_keys):
        extraneous_keys = set(kwargs.keys()) - allowed_dataset_keys
        log.warning(
            'The dataset config contains the following extraneous keys: ' +\
            ', '.join(extraneous_keys),
        )

    if hf_name is not None:
        # Using the HuggingFace dataset codepath
        illegal_keys = ['local', 'remote']
        discovered_illegal_keys = []
        if local is not None:
            discovered_illegal_keys.append('`local`')
        if remote is not None:
            discovered_illegal_keys.append('`remote`')
        if discovered_illegal_keys:
            discovered_illegal_keys_str = ', '.join(discovered_illegal_keys)
            raise ValueError(
                'The dataset config sets a value for `hf_name` as well as the ' +\
                f'following keys: {discovered_illegal_keys_str}.\n' +\
                'Those keys are used when building from a streaming dataset, but ' +\
                'setting `hf_name` instructs the dataset to build from a HuggingFace dataset.',
            )
    elif remote is not None or local is not None:
        # Using the streaming dataset codepath
        illegal_keys = {
            'hf_name': hf_name,
            'hf_kwargs': hf_kwargs,
            'preprocessing_fn': preprocessing_fn,
            'safe_load': safe_load,
        }
        discovered_illegal_keys = []
        for key, value in illegal_keys.items():
            if value is not None:
                discovered_illegal_keys.append('`' + key + '`')
        if discovered_illegal_keys:
            discovered_illegal_keys_str = ', '.join(discovered_illegal_keys)
            raise ValueError(
                'The dataset config sets a value for `remote` as well as the ' +\
                f'following keys: {discovered_illegal_keys_str}.\n' +\
                'Those keys are used when building from a HuggingFace dataset, but ' +\
                'setting `remote` instructs the dataset to build from a streaming dataset.',
            )
        if local is None:
            raise ValueError(
                'Using a streaming dataset requires setting both `remote` and `local`, ' +\
                'but dataset.local is None.',
            )
    elif streams is not None:
        # Using the streaming dataset codepath
        illegal_keys = {
            'hf_name': hf_name,
            'hf_kwargs': hf_kwargs,
            'preprocessing_fn': preprocessing_fn,
            'safe_load': safe_load,
        }
        discovered_illegal_keys = []
        for key, value in illegal_keys.items():
            if value is not None:
                discovered_illegal_keys.append('`' + key + '`')
        if discovered_illegal_keys:
            discovered_illegal_keys_str = ', '.join(discovered_illegal_keys)
            raise ValueError(
                'The dataset config sets a value for `streams` as well as the ' +\
                f'following keys: {discovered_illegal_keys_str}.\n' +\
                'Those keys are used when building from a HuggingFace dataset, but ' +\
                'setting `streams` instructs the dataset to build from a streaming dataset.',
            )
        illegal_keys = {'remote': remote, 'local': local}
        discovered_illegal_keys = []
        for key, value in illegal_keys.items():
            if value is not None:
                discovered_illegal_keys.append('`' + key + '`')
        if discovered_illegal_keys:
            discovered_illegal_keys_str = ', '.join(discovered_illegal_keys)
            raise ValueError(
                'The dataset config sets a value for `streams` as well as the ' +\
                f'following keys: {discovered_illegal_keys_str}.\n' +\
                'Please either use single stream (set remote/local only) ' +\
                'or put remote/local under streams',
            )

    else:
        raise ValueError(
            'In the dataset config, you must set `hf_name` to use a HuggingFace ' +\
            'dataset, or set `remote` to use a streaming dataset, or set ' +\
            '`streams` to use multiple streaming datasets,  but all were None.',
        )

    # Raise an error if the target_prompts + target_responses + decoder_only_format settings
    # are invalid
    if target_prompts is None:
        target_prompts = DEFAULT_TARGET_PROMPTS
    if target_responses is None:
        target_responses = DEFAULT_TARGET_RESPONSES
    target_prompts, target_responses = target_prompts.lower(
    ), target_responses.lower()
    validate_target_settings(
        target_prompts,
        target_responses,
        decoder_only_format,
    )

    return extraneous_keys
Validates the dataset configuration.

    Makes sure that the dataset is properly configured for either
    a HuggingFace dataset or a streaming dataset. Must be valid for one or
    the other.

    Args:
        max_seq_len (int): The maximum length of sequences
            in the batch. See :class:`Seq2SeqFinetuningCollator` docstring
            for details.
        decoder_only_format (bool, optional): Whether to format the
            examples for a decoder-only model. See :class:`Seq2SeqFinetuningCollator`
            docstring for details.
        hf_name (str, optional): The name of the HuggingFace dataset
            to use. Can also be a remote http(s) directory or object store bucket
            containing the file {split}.jsonl in the format (prompt, response),
            in which case the builder will create a HuggingFace dataset.
        local (str, optional): Local path where remote data
            will be streamed to. Only valid if `cfg.dataset.remote` has
            also been set.
        remote (str, optional): Location of a MDS-formatted
            streaming dataset to use. Setting this will tell the builder
            to create a streaming dataset rather than a HuggingFace dataset.
        hf_kwargs (DictConfig, optional): Additional kwargs to
            pass to `datasets.load_dataset`, which can be used to load
            a dataset from local files.
        preprocessing_fn (str, optional): The name/import path of
            the preprocessing function to use for formatting the data examples.
            If ``None`` (default), the builder will use the preprocessing function
                registered under `hf_name` (see `tasks.py`), if one exists,
                otherwise it will skip preprocessing.
            If `preprocessing_fn` corresponds to a registered preprocessing
                function in `tasks.py`, the builder will use that.
            Otherwise, it will interpret `preprocessing_fn` as a
                "import.path:function_name" import path; e.g., it will call
                `from import.path import function_name` and use the imported
                function as the preprocessing function.
        safe_load (bool, optional): Whether to enforce safe loading of the dataset.
            If `None`, will default to not applying any safe loading.
        streams (Dict[str, Any], optional): A dictionary with multiple data streams.
            If `None`, will assume no streams.
        target_prompts (str): Which prompts are used as training targets.
            Defaults to "none", meaning prompts are never used as training targets.
            See :class:`Seq2SeqFinetuningCollator` docstring for details.
        target_responses (str): Which responses are used as training targets.
            Defaults to "last", meaning only the final response in multi-turn examples
            will serve as training targets. See :class:`Seq2SeqFinetuningCollator` docstring for
            details.
        allowed_dataset_keys (set[str], optional): The set of allowed keys for the dataset config.
        kwargs (DictConfig, optional): Additional kwargs to
                pass to `datasets.load_dataset`, which can be used to load
                a dataset from local files.

    Raises:
        ValueError: If the dataset configuration does not meet the requirements.

    Returns:
        set[str]: Return the extraneous keys.
    
llmfoundry/data/finetuning/dataloader.py