{"record":{"id":"b0d1d8ceace71748","repo":"hiyouga/LlamaFactory","slug":"rm-training-dataset-is-empty-dataset-path","errorCode":null,"errorMessage":"RM training dataset is empty: {dataset_path}","messagePattern":"RM training dataset is empty: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/v1/trainers/rm_trainer.py","lineNumber":35,"sourceCode":"import torch.nn.functional as F\n\nfrom ..accelerator.interface import Dim, DistributedInterface\nfrom ..config import InputArgument, TrainingArguments, get_args\nfrom ..config.arg_utils import ModelClass\nfrom ..core.base_trainer import BaseTrainer\nfrom ..core.data_engine import DataEngine\nfrom ..core.model_engine import ModelEngine\nfrom ..utils import logging\nfrom ..utils.types import BatchInput, HFModel, Tensor\n\n\nlogger = logging.get_logger(__name__)\n\n\ndef _validate_rm_dataset_format(train_dataset: DataEngine, dataset_path: str) -> None:\n    \"\"\"Validate RM dataset format early for clearer error messages.\"\"\"\n    if len(train_dataset) == 0:\n        raise ValueError(f\"RM training dataset is empty: {dataset_path}\")\n\n    sample = train_dataset[0]\n    if \"chosen_messages\" in sample and \"rejected_messages\" in sample:\n        return\n\n    dataset_name = sample.get(\"_dataset_name\", \"unknown\")\n    sample_keys = sorted(sample.keys())\n    raise ValueError(\n        \"RM training requires pair-format samples containing chosen/rejected responses. \"\n        f\"First sample from dataset '{dataset_name}' has keys: {sample_keys}. \"\n        \"Please use pair data (e.g. a dataset with chosen_messages/rejected_messages, \"\n        \"or set converter='pair' for raw chosen/rejected fields).\"\n    )\n\n\ndef _init_score_head(model: HFModel) -> None:\n    \"\"\"Initialize the score head for RM training with small Gaussian weights.\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/v1/trainers/rm_trainer.py#L17-L53","documentation":"ValueError from _validate_rm_dataset_format (rm_trainer.py:35) when the reward-model train DataEngine has zero samples. Like the DPO counterpart, it is an early check at trainer construction that replaces a cryptic empty-dataloader failure. Unlike DPO, there is no streaming exemption in this function.","triggerScenarios":"Constructing RMTrainer with an empty processed dataset: empty source file, all rows filtered out, or a dataset_info entry pointing at a nonexistent/empty data file.","commonSituations":"max_samples or filtering discards every row; wrong dataset name; converter column-name mismatch causing zero surviving samples during preprocessing.","solutions":["Load the dataset with the same configuration and assert len(train_dataset) > 0 before creating the trainer.","Check dataset_info.json and any filter/max_samples settings for over-aggressive filtering.","Confirm the data file path in dataset_info.json exists and contains rows."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"assert len(train_dataset) > 0, f\"RM dataset {dataset_path} is empty\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Log dataset size after all filtering steps.","Alert on zero-row datasets in the data pipeline."],"tags":["data","dataset","reward-model","validation"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}