{"record":{"id":"3a128d8000ffc7ea","repo":"hiyouga/LlamaFactory","slug":"cannot-find-valid-samples-check-data-readme-md","errorCode":null,"errorMessage":"Cannot find valid samples, check `data/README.md` for the data format.","messagePattern":"Cannot find valid samples, check `data/README\\.md` for the data format\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/data/loader.py","lineNumber":271,"sourceCode":"        )\n\n    dataset = dataset.map(\n        dataset_processor.preprocess_dataset,\n        batched=True,\n        batch_size=data_args.preprocessing_batch_size,\n        remove_columns=column_names,\n        **kwargs,\n    )\n\n    if training_args.should_log:\n        try:\n            print(\"eval example:\" if is_eval else \"training example:\")\n            dataset_processor.print_data_example(next(iter(dataset)))\n        except StopIteration:\n            if stage == \"pt\":\n                raise RuntimeError(\"Cannot find sufficient samples, consider increasing dataset size.\")\n            else:\n                raise RuntimeError(\"Cannot find valid samples, check `data/README.md` for the data format.\")\n\n    return dataset\n\n\ndef get_dataset(\n    template: \"Template\",\n    model_args: \"ModelArguments\",\n    data_args: \"DataArguments\",\n    training_args: \"Seq2SeqTrainingArguments\",\n    stage: Literal[\"pt\", \"sft\", \"rm\", \"ppo\", \"kto\"],\n    tokenizer: \"PreTrainedTokenizer\",\n    processor: Optional[\"ProcessorMixin\"] = None,\n) -> \"DatasetModule\":\n    r\"\"\"Get the train dataset and optionally gets the evaluation dataset.\"\"\"\n    # Load tokenized dataset if path exists\n    if data_args.tokenized_path is not None:\n        if has_tokenized_data(data_args.tokenized_path):\n            logger.warning_rank0(\"Loading dataset from disk will ignore other data arguments.\")","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/data/loader.py#L253-L289","documentation":"Same StopIteration path as the pt variant, but for sft/rm/ppo/kto stages: after .filter() over the tokenized dataset, not a single valid sample remains, so printing the data example fails. 'Valid' means the sample passed all stage-specific filters (non-empty labels, matching pair lengths, acceptable token counts), and the message directs you to the documented data format.","triggerScenarios":"Alpaca-format rows where output is empty and the formatter yields no trainable tokens; conversations whose messages do not match the columns mapping; rm pairs where chosen/rejected tokenize to equal length 0; max_samples/cutoff_len filtering everything; wrong template producing empty encoded results.","commonSituations":"Columns mapping in dataset_info.json not matching the actual JSONL field names; datasets where all answers live in a field mapped to None; template/tags misconfiguration stripping all content; every sample exceeding cutoff_len.","solutions":["Read data/README.md and align your dataset fields with the expected format for the stage, including the columns mapping in dataset_info.json.","Verify each sample yields trainable tokens: for sft the output/response field must be non-empty; for rm both chosen and rejected must be present.","Raise cutoff_len / remove max_samples so samples survive filtering.","Test with a tiny known-good dataset (e.g. the built-in alpaca demo) to isolate whether the template or the data is at fault."],"exampleFix":"# before (dataset_info.json, field names mismatch)\n\"columns\": {\"prompt\": \"instruction\", \"query\": \"input\", \"response\": \"answer\"}\n\n# after (match actual JSONL keys)\n\"columns\": {\"prompt\": \"instruction\", \"query\": \"input\", \"response\": \"output\"}","handlingStrategy":"validation","validationCode":"def sft_rows_trainable(rows: list[dict], resp_key: str) -> list[int]:\n    return [i for i, r in enumerate(rows) if not (r.get(resp_key) or \"\").strip()]  # indices that will be dropped","typeGuard":"def row_has_response(row: dict, response_key: str) -> bool:\n    return bool((row.get(response_key) or \"\").strip())","tryCatchPattern":null,"preventionTips":["Verify columns mapping keys equal the actual JSONL field names.","Ensure every training row has a non-empty response/output.","Test one dataset with the built-in alpaca demo template first to separate template vs data issues."],"tags":["dataset","data-format","empty-dataset","preprocessing"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}