hiyouga/LlamaFactory · error · ValueError
Can not load dataset from {filepath}.
Error message
Can not load dataset from {filepath}. What it means
The local data loader only handles two cases: an existing directory or an existing file. If the path is neither (nonexistent, a glob pattern, or a URL), it raises this ValueError. Note _get_builder_name may raise first for directories whose first file has a bad extension.
Source
Thrown at src/llamafactory/v1/plugins/data_plugins/loader.py:61
Literal["arrow", "csv", "json", "parquet", "text"]: Dataset builder name.
"""
filetype = os.path.splitext(path)[-1][1:]
if filetype in ["arrow", "csv", "json", "jsonl", "parquet", "txt"]:
return filetype.replace("jsonl", "json").replace("txt", "text")
else:
raise ValueError(f"Unknown dataset filetype: {filetype}.")
@DataLoaderPlugin("local").register()
def load_data_from_file(filepath: str, split: str, streaming: bool) -> HFDataset:
if os.path.isdir(filepath):
filetype = _get_builder_name(os.listdir(filepath)[0])
dataset = load_dataset(filetype, data_dir=filepath, split=split)
elif os.path.isfile(filepath):
filetype = _get_builder_name(filepath)
dataset = load_dataset(filetype, data_files=filepath, split=split)
else:
raise ValueError(f"Can not load dataset from {filepath}.")
if streaming: # faster when data is streamed from local files
dataset = dataset.to_iterable_dataset()
return dataset
def adjust_data_index(
data_index: list[tuple[str, int]], size: int | None, weight: float | None
) -> list[tuple[str, int]]:
"""Adjust dataset index by size and weight.
Args:
data_index (list[tuple[str, int]]): List of (dataset_name, sample_index).
size (Optional[int]): Desired dataset size.
weight (Optional[float]): Desired dataset weight.
Returns:View on GitHub (pinned to f28afaf635)
Solutions
- Check the path exists: correct typos, use absolute paths, or fix the working directory.
- Expand globs yourself and list concrete files in the config.
- For HuggingFace hub datasets, register them properly (dataset_info.json or the hub loader) instead of the local file loader.
- Verify with `ls <path>` from the same shell that launches training.
Example fix
# before dataset_dir: ./datset/train.json # typo # after dataset_dir: ./dataset/train.json # verified with ls
Defensive patterns
Strategy: validation
Validate before calling
import os
assert os.path.isdir(dataset_dir) or os.path.isfile(dataset_dir), f'path not found: {dataset_dir}' Type guard
def is_loadable_path(p: str) -> bool:
"""True when p is an existing file or directory."""
return os.path.exists(p) Try / catch
try:
ds = load_data_from_file(p, split, streaming)
except ValueError as e:
if 'Can not load dataset' in str(e):
raise SystemExit(f'check path: {p!r} (cwd={os.getcwd()})') from None
raise Prevention
- Use absolute paths in training configs.
- Add a `ls` sanity step in launch scripts.
- Expand globs explicitly in data prep, never pass them through.
When it happens
Trigger: Passing a nonexistent path in dataset_dir; passing a glob like 'data/*.json'; passing an HF hub repo id (e.g. 'alpaca') where the local loader plugin is selected instead of the hub loader.
Common situations: Typo in the dataset path; using a relative path while the process cwd differs; expecting local-loader semantics for hub datasets because the dataset_info entry was misconfigured.
Related errors
- File {local_path} not found.
- The length of packed example should be identical to the cuto
- Streaming mode should have an integer val size.
- `max_samples` is incompatible with `streaming`.
- `mask_history` is incompatible with `train_on_prompt`.
AI-assisted analysis of hiyouga/LlamaFactory@f28afaf635 (2026-08-14).
Data as JSON: /api/errors/d3e7c0a3ffe38c06.
Report an issue: GitHub.