hiyouga/LlamaFactory · error · ValueError
File types should be identical.
Error message
File types should be identical.
What it means
Raised when a dataset loaded from a directory contains files with differing extensions: the type inferred from the first file is compared against every other file, and any mismatch aborts loading. LlamaFactory can only merge local files of a single format per dataset entry.
Source
Thrown at src/llamafactory/data/loader.py:89
data_path = dataset_attr.dataset_name
elif dataset_attr.load_from == "file":
data_files = []
local_path = os.path.join(data_args.dataset_dir, dataset_attr.dataset_name)
if os.path.isdir(local_path): # is directory
for file_name in os.listdir(local_path):
data_files.append(os.path.join(local_path, file_name))
elif os.path.isfile(local_path): # is file
data_files.append(local_path)
else:
raise ValueError(f"File {local_path} not found.")
data_path = FILEEXT2TYPE.get(os.path.splitext(data_files[0])[-1][1:], None)
if data_path is None:
raise ValueError("Allowed file types: {}.".format(",".join(FILEEXT2TYPE.keys())))
if any(data_path != FILEEXT2TYPE.get(os.path.splitext(data_file)[-1][1:], None) for data_file in data_files):
raise ValueError("File types should be identical.")
else:
raise NotImplementedError(f"Unknown load type: {dataset_attr.load_from}.")
if dataset_attr.load_from == "ms_hub":
check_version("modelscope>=1.14.0", mandatory=True)
from modelscope import MsDataset # type: ignore
from modelscope.utils.config_ds import MS_DATASETS_CACHE # type: ignore
cache_dir = model_args.cache_dir or MS_DATASETS_CACHE
dataset = MsDataset.load(
dataset_name=data_path,
subset_name=data_name,
data_dir=data_dir,
data_files=data_files,
split=dataset_attr.split,
cache_dir=cache_dir,
token=model_args.ms_hub_token,
use_streaming=data_args.streaming,View on GitHub (pinned to f28afaf635)
Solutions
- Make every file in the directory the same format/extension; convert the odd ones out (e.g. rewrite .json shards as .jsonl).
- Remove non-data files from the directory (.DS_Store, README, backups).
- Alternatively split the formats into separate directories and register each as its own dataset entry, then list both in the dataset field.
- Point dataset_name at a single file instead of the directory if only one file is needed.
Example fix
# before: data/mydir/ contains part1.json, part2.jsonl # after: data/mydir/ contains part1.jsonl, part2.jsonl # (convert part1.json: one JSON object per line, then rename)
Defensive patterns
Strategy: validation
Validate before calling
import os
def dir_uniform(d: str) -> bool:
exts = {os.path.splitext(f)[-1] for f in os.listdir(d)}
return len(exts) == 1 Prevention
- Keep one format per dataset directory; convert shards before adding them.
- Exclude non-data files (.DS_Store, README, backups) from data directories.
- Register each format as a separate dataset entry if mixing is required.
When it happens
Trigger: Pointing dataset_name at a directory that mixes .json and .jsonl, or .csv and .parquet, or contains stray files (e.g. .DS_Store, README.md, a lock file, or a backup copy with a different suffix).
Common situations: Incrementally exported data where a later export used a different format; macOS .DS_Store or editor backup files inside the data folder; combining sharded datasets saved with different serializers.
Related errors
- Allowed file types: {}.
- Unsupported model type: {getattr(config, 'model_type')}.
- Dataset converter {name} not found.
- Unknown mixing strategy: {data_args.mix_strategy}.
- Cannot specify `val_size` if `eval_dataset` is not None.
AI-assisted analysis of hiyouga/LlamaFactory@f28afaf635 (2026-08-14).
Data as JSON: /api/errors/77f757d5725668a0.
Report an issue: GitHub.