Skip to content

Studio: train a local dataset folder on its train split, not every file - #17938

Merged
danielhanchen merged 4 commits into
unslothai:mainfrom
ellaslan11:fix-dataset-folder-split-files
Nov 16, 2026
Merged

danielhanchen merged 4 commits into
unslothai:mainfrom
ellaslan11:fix-dataset-folder-split-files

Conversation

@ellaslan11

Copy link
Copy Markdown
Contributor

Fixes #17937

Summary

A local training dataset folder now trains on the files datasets.load_dataset(folder) puts in its train split, instead of concatenating every supported file.

Before, dataset_files_in_dir globbed every .json/.jsonl/.csv/.parquet file in the folder. Two failures followed:

Folder Before After
train.jsonl + val.jsonl Both used for training, so validation rows leak into training silently train.jsonl only
train.jsonl + filter_report.json DatasetGenerationCastError (the local form of #7585) train.jsonl only, loads
train-*.parquet + validation-*.parquet + test.parquet All three concatenated train-*.parquet only
part1.jsonl + part2.jsonl (no split names) Both Both (unchanged)
val.jsonl + notes.jsonl (no train-named file) Both Both (unchanged)

Change

studio/backend/utils/paths/storage_roots.py gains a _train_split_files(directory, files) helper, applied to both the parquet branch and the mixed-format branch of dataset_files_in_dir:

  • It calls datasets.data_files.get_data_patterns and DataFilesDict.from_patterns, the same split inference load_dataset uses, so Studio and datasets agree on what train means instead of keeping a second keyword list.
  • It only filters the files Studio already selected, so the existing extension filter, the AppleDouble guard and the top-level-only glob are unchanged.
  • It returns the original list unchanged when no file is named as a train split (patterns == DEFAULT_PATTERNS_ALL or no train key), when the intersection is empty, or if datasets raises. This keeps test_a_dataset_directory_prefers_its_parquet_export (which keeps a non-AppleDouble ._mine.parquet) and other unnamed folders working as before.

dataset_files_in_dir feeds UnslothTrainer._resolve_local_files, the equivalent paths in core/training/worker.py, and core/training/decision_trainer.py, so all of them pick up the fix.

Note for review: _resolve_local_files is also used for local_eval_datasets, so a split-named folder chosen as the eval dataset now resolves to its train files too. I raised this in #17937. If you'd like eval to take the folder's validation files, I can add a split argument in this PR.

Tests

New studio/backend/tests/test_dataset_folder_splits.py with 5 tests:

  • a validation file is not merged into training
  • a sidecar JSON next to the train split doesn't break the load (also runs load_dataset on the result)
  • split-named parquet files keep only train
  • a folder without split names still loads every file
  • a folder with no train split still loads every file

On main, the first three fail and the last two pass. With this change, all five pass.

Regression check on macOS 27.0 (arm64), Python 3.12.6, datasets==4.3.0, running every tests/test_*dataset*, *storage_roots*, *appledouble* and *s3* file in studio/backend (56 files): 1707 passed both with and without this change. The same 14 failures and 4 collection errors appear in both runs. They come from optional dependencies not installed locally (torch, video decoding, sandbox), not from this change.

dataset_files_in_dir concatenated every supported file in a folder, so
train.jsonl beside val.jsonl leaked validation rows into training, and a
sidecar like filter_report.json failed the load with
DatasetGenerationCastError. Reuse datasets' own split detection to keep
only the train-split files when files are named by split, matching
datasets.load_dataset(folder). Folders without split names, or without a
train-named file, load every file as before.

Fixes unslothai#17937
@danielhanchen danielhanchen self-assigned this Nov 16, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T08:50:00.594342Z 80e285c Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 80e285cd51

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Studio trains on every file in a local dataset folder: val.jsonl is merged into training and sidecar JSON breaks the load

2 participants