hiyouga/LlamaFactory · error · ValueError

The dataset is not applicable in the current training stage.

Error message

The dataset is not applicable in the current training stage.

What it means

ValueError from _get_merged_dataset enforcing ranking-format compatibility: RM training requires preference datasets (ranking=True, i.e. chosen/rejected pairs), while pt/sft/ppo/kto stages require non-ranking datasets (ranking=False). A mismatch between the stage in your training YAML and the dataset's format raises this before loading.

Source

Thrown at src/llamafactory/data/loader.py:179

    return align_dataset(dataset, dataset_attr, data_args, training_args)


def _get_merged_dataset(
    dataset_names: list[str] | None,
    model_args: "ModelArguments",
    data_args: "DataArguments",
    training_args: "Seq2SeqTrainingArguments",
    stage: Literal["pt", "sft", "rm", "ppo", "kto"],
    return_dict: bool = False,
) -> Union["Dataset", "IterableDataset", dict[str, "Dataset"]] | None:
    r"""Return the merged datasets in the standard format."""
    if dataset_names is None:
        return None

    datasets = {}
    for dataset_name, dataset_attr in zip(dataset_names, get_dataset_list(dataset_names, data_args.dataset_dir)):
        if (stage == "rm" and dataset_attr.ranking is False) or (stage != "rm" and dataset_attr.ranking is True):
            raise ValueError("The dataset is not applicable in the current training stage.")

        datasets[dataset_name] = _load_single_dataset(dataset_attr, model_args, data_args, training_args)

    if return_dict:
        return datasets
    else:
        return merge_dataset(list(datasets.values()), data_args, seed=training_args.seed)


def _get_dataset_processor(
    data_args: "DataArguments",
    stage: Literal["pt", "sft", "rm", "ppo", "kto"],
    template: "Template",
    tokenizer: "PreTrainedTokenizer",
    processor: Optional["ProcessorMixin"],
    do_generate: bool = False,
) -> "DatasetProcessor":
    r"""Return the corresponding dataset processor."""

View on GitHub (pinned to f28afaf635)

Solutions

  1. For stage rm (and pairwise DPO), use a dataset with chosen/rejected responses, e.g. {"file_name": "pairs.json", "ranking": true, "columns": {"chosen": "chosen", "rejected": "rejected", ...}}.
  2. For stage sft/ppo/kto/pt, remove "ranking": true from the dataset entry or pick a non-ranking dataset.
  3. If you meant preference optimization without pairs, use stage kto with a label/kto_tag column instead of rm.
  4. Double-check the stage: value in the training YAML matches the data you prepared.

Example fix

# before: stage: rm with alpaca-format data

# after: prepare preference data and register
dataset_info.json:
"my_pref": {
  "file_name": "prefs.json",
  "ranking": true,
  "columns": {"prompt": "question", "chosen": "chosen", "rejected": "rejected"}
}
# train.yaml: stage: rm, dataset: my_pref
Defensive patterns

Strategy: validation

Validate before calling

def stage_matches_ranking(stage: str, ranking: bool) -> bool:
    return ranking if stage == "rm" else not ranking

Prevention

When it happens

Trigger: Setting stage: rm with a plain sharegpt/alpaca conversation dataset (no chosen/rejected columns); or stage: sft/kto/ppo with a dataset registered with "ranking": true; occurs per dataset while merging the dataset list.

Common situations: Reusing a YAML from an SFT run and only changing stage to rm; feeding a preference dataset (e.g. a DPO-style pairs file) to the sft stage; misunderstanding that KTO uses non-ranking data with a label field while DPO/RM use ranking data.

Related errors


AI-assisted analysis of hiyouga/LlamaFactory@f28afaf635 (2026-08-14). Data as JSON: /api/errors/d69d848fefc1a6d5. Report an issue: GitHub.