Skip to content

feat(studio): implement S3 dataset loading (completes #5951) - #6222

Merged
wasimysaid merged 16 commits into
unslothai:mainfrom
ashzak:feat/s3-dataset-loader
Jun 12, 2026
Merged

wasimysaid merged 16 commits into
unslothai:mainfrom
ashzak:feat/s3-dataset-loader

Conversation

@ashzak

@ashzak ashzak commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Completes the S3 dataset loader scaffold from #5951 and wires S3 in as a first-class Studio dataset source alongside Hugging Face and local uploads.

Backend

  • Adds core/training/s3_dataset.py to list and download supported dataset files from S3 using IAM role or access-key credentials.
  • Keeps boto3 lazy and optional, with a clear availability guard before S3 training starts.
  • Routes S3 datasets through the existing local-file dataset loading path for standard, MLX, and embedding training.
  • Filters common JSON metadata files, rejects mixed dataset format families before download, and preserves basename-collision handling.
  • Ties owned S3 temp directories to the training lifecycle and cleans them after dataset loading or cancellation.
  • Polls cancellation before listing, between objects, and through the Boto3 transfer callback.
  • Keeps S3 credentials out of persisted Studio config, training run config JSON, and W&B config.

Frontend

  • Adds s3 to the Studio dataset source model and training request payload.
  • Adds the S3 configuration form for bucket, region, prefix, access keys, and IAM role mode.
  • Hides local-only upload and preview controls while S3 is selected.
  • Allows S3 for embedding training now that the backend embedding loader supports it.
  • Blocks S3 for vision and audio model runs until S3 dataset detection is available.
  • Allows standard S3 dataset formats to flow to backend auto-detection.
  • Clears and omits S3 access keys when IAM role mode is selected.

Testing

  • ~/.unsloth/studio/unsloth_studio/bin/python -m pytest studio/backend/tests/test_s3_dataset.py -q
  • ~/.unsloth/studio/unsloth_studio/bin/python -m pytest tests/studio/test_mlx_training_worker_behaviors.py -q
  • ~/.unsloth/studio/unsloth_studio/bin/python -m py_compile studio/backend/core/training/s3_dataset.py studio/backend/core/training/trainer.py studio/backend/core/training/worker.py studio/backend/tests/test_s3_dataset.py
  • ~/.unsloth/studio/unsloth_studio/bin/python -m ruff check studio/backend/core/training/s3_dataset.py studio/backend/core/training/trainer.py studio/backend/core/training/worker.py studio/backend/tests/test_s3_dataset.py
  • npm run typecheck in studio/frontend
  • npm run i18n:check in studio/frontend
  • git diff --check
  • Live S3 bucket to training round trip not run locally

Closes the loader gap from #5951.

ashzak and others added 9 commits June 2, 2026 12:03
Add foundational types and configuration for S3 bucket dataset loading:

- Add S3Config type to frontend training types
- Add S3Config Pydantic model to backend training models
- Add "s3" as a DatasetSource option
- Add s3Config state and setS3Config action to training config store
- Add i18n translations for S3 configuration (English and Chinese)

This provides the type definitions and UI text for S3 integration.
Full implementation requires boto3 dependency and data loading logic.

Refs: unslothai#4539
- Pass s3_config from request into training_kwargs so it flows to training subprocess
- Add s3Config to NON_PERSISTED_STATE_KEYS to prevent AWS secrets from being
  saved to localStorage

Addresses code review feedback on PR unslothai#5951.
Filter out s3_config (which contains secret_access_key) from the
config_json stored in training_runs table, preventing AWS credentials
from being persisted to disk.

Addresses P1 security feedback on PR unslothai#5951.
Builds the actual S3 loader on top of the hardened unslothai#5951 foundation,
turning the 501-gated scaffold into a working dataset source.

Backend:
- Add core/training/s3_dataset.py: lists and downloads supported dataset
  files (parquet/json/jsonl/csv) from an S3 bucket to a temp dir, using
  IAM-role or access-key credentials. boto3 is imported lazily (optional dep).
- Wire s3_config into UnslothTrainer.load_and_format_dataset (downloads then
  reuses the existing local-file path) and thread it through worker.py.
- Replace the 501 "not implemented" gate with a boto3-availability guard so
  S3 works when boto3 is present and fails clearly when it is not.
- Add boto3 to studio.txt requirements.
- Add tests/test_s3_dataset.py (8 tests) covering download/filtering,
  collisions, missing-boto3, and S3Config camelCase/IAM validation.

Frontend:
- Widen DatasetSource to include "s3"; add s3_config to the training payload
  type and mapper; add an S3 validation branch and selectS3Source store action.
- Add s3-config-form.tsx (bucket/region/prefix/keys/IAM toggle) reusing the
  existing studio.dataset.s3.* i18n strings.
- Add a Hugging Face / Local / Amazon S3 source toggle in dataset-section;
  the S3 config card replaces the dataset combobox when S3 is selected.
- Fix DatasetPreviewDialog to accept the widened DatasetSource type.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@ashzak
ashzak marked this pull request as ready for review June 12, 2026 01:44
@ashzak
ashzak requested a review from danielhanchen as a code owner June 12, 2026 01:44
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c60a801eea

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +578 to +580
datasetSource: "s3",
dataset: null,
uploadedFile: null,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle S3 in onboarding progression

When the S3 tab is selected here, the store sets datasetSource to "s3" while clearing both dataset and uploadedFile; however, canProceedForStep still treats every non-upload source as requiring state.dataset !== null. In the onboarding wizard, WizardFooter disables Continue based on s.canProceed(), so a user who enters a valid S3 bucket/credentials on the dataset step cannot advance. Please add an S3 branch to the step-3 progression check that validates s3Config instead of requiring a Hugging Face dataset name.

Useful? React with 👍 / 👎.

self._db_total_steps_set = False
self._db_config = {k: v for k, v in config.items() if k not in {"hf_token", "wandb_token"}}
self._db_config = {
k: v for k, v in config.items() if k not in {"hf_token", "wandb_token", "s3_config"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve enough S3 source state for resume

For stopped S3 runs, this drops the only dataset source from the saved run config, while can_resume_run still advertises any stopped run with trainer state as resumable and the frontend resume path replays this saved config. The resumed request therefore contains no hf_dataset, local_datasets, or s3_config, so the worker reaches dataset loading and fails with No dataset provided; either disable resume for S3 runs or persist/rehydrate a non-secret S3 source marker plus credentials prompt instead of making the resume button fail.

Useful? React with 👍 / 👎.

Comment thread studio/backend/core/training/worker.py Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b25c82c91e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f3c46915c9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +23 to +27
if (
!config.isEmbeddingModel &&
!isRawTextDatasetFormat(config.datasetFormat) &&
!hasRequiredS3Mapping(config)
) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Allow standard S3 formats without manual mapping

When S3 is selected and datasetFormat is left as auto or set to a standard format like alpaca/sharegpt, there is no S3 preview path to populate datasetManualMapping, so this validation disables Start even for datasets with the normal columns that the backend formatter already auto-detects and loads without a custom mapping. This makes common S3 datasets unusable unless the user switches to raw text or somehow imports a saved mapping.

Useful? React with 👍 / 👎.

Comment on lines +92 to +95
<Switch
id="s3-iam"
checked={config.useIamRole ?? false}
onCheckedChange={(useIamRole) => update({ useIamRole })}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear hidden keys when IAM role is selected

If a user enters access keys and then switches on Use IAM Role, this only flips the flag and leaves accessKeyId/secretAccessKey in the store; buildTrainingStartPayload later sends the entire s3Config object, so the hidden secret still goes to the backend/worker despite the IAM-role choice. Clear the key fields here or omit them from the payload whenever useIamRole is true.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7e34325ba2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@wasimysaid

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: fbeae7b166

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@wasimysaid

Copy link
Copy Markdown
Collaborator

Uploading pr6222.png…

@wasimysaid
wasimysaid merged commit aefe904 into unslothai:main Jun 12, 2026
1 of 41 checks passed
lonexreb added a commit to lonexreb/unsloth that referenced this pull request Sep 4, 2026
…st and point the manifest at it

key listing filtered audio files out, every download flattened to its
basename, and a manifest+audio prefix was called a mixed-format error.
So the layout unslothai#4539 asks for -- Whisper finetuning with audio files on
S3 plus a transcription manifest -- could never load: at best the
manifest downloaded alone and training died when datasets.Audio tried
to open paths that were never materialized.

Audio keys under the prefix now download too, preserving their
prefix-relative structure so the manifest's relative references stay
true, and the manifest's audio values are rewritten to the materialized
absolute paths -- matching prefix-relative keys, s3://bucket/key URIs,
the HF undecoded {"path": ...} shape, and manifest-relative paths;
anything unmatched is left exactly as written. The single-format rule
now judges only the manifest files (audio beside one manifest family is
the expected shape; audio with no manifest is an error naming what is
missing), and tabular-only prefixes keep unslothai#6222's flat collision-renamed
layout byte for byte. Since the structured layout joins S3 keys into
filesystem paths and bucket contents are external input, a key carrying
'..' segments refuses the download instead of writing above the
dataset directory.

Credentials handling is untouched from unslothai#6222 (explicit keys or the
default chain/IAM role, never logged or persisted). Parquet manifests
cannot be rewritten without pyarrow; their audio references must
already be absolute, which the module docstring now states.

Closes unslothai#4539.
lonexreb added a commit to lonexreb/unsloth that referenced this pull request Sep 4, 2026
…st and point the manifest at it

key listing filtered audio files out, every download flattened to its
basename, and a manifest+audio prefix was called a mixed-format error.
So the layout unslothai#4539 asks for -- Whisper finetuning with audio files on
S3 plus a transcription manifest -- could never load: at best the
manifest downloaded alone and training died when datasets.Audio tried
to open paths that were never materialized.

Audio keys under the prefix now download too, preserving their
prefix-relative structure so the manifest's relative references stay
true, and the manifest's audio values are rewritten to the materialized
absolute paths -- matching prefix-relative keys, s3://bucket/key URIs,
the HF undecoded {"path": ...} shape, and manifest-relative paths;
anything unmatched is left exactly as written. The single-format rule
now judges only the manifest files (audio beside one manifest family is
the expected shape; audio with no manifest is an error naming what is
missing), and tabular-only prefixes keep unslothai#6222's flat collision-renamed
layout byte for byte. Since the structured layout joins S3 keys into
filesystem paths and bucket contents are external input, a key carrying
'..' segments refuses the download instead of writing above the
dataset directory.

Credentials handling is untouched from unslothai#6222 (explicit keys or the
default chain/IAM role, never logged or persisted). Parquet manifests
cannot be rewritten without pyarrow; their audio references must
already be absolute, which the module docstring now states.

Closes unslothai#4539.
lonexreb added a commit to lonexreb/unsloth that referenced this pull request Sep 4, 2026
…st and point the manifest at it

key listing filtered audio files out, every download flattened to its
basename, and a manifest+audio prefix was called a mixed-format error.
So the layout unslothai#4539 asks for -- Whisper finetuning with audio files on
S3 plus a transcription manifest -- could never load: at best the
manifest downloaded alone and training died when datasets.Audio tried
to open paths that were never materialized.

Audio keys under the prefix now download too, preserving their
prefix-relative structure so the manifest's relative references stay
true, and the manifest's audio values are rewritten to the materialized
absolute paths -- matching prefix-relative keys, s3://bucket/key URIs,
the HF undecoded {"path": ...} shape, and manifest-relative paths;
anything unmatched is left exactly as written. The single-format rule
now judges only the manifest files (audio beside one manifest family is
the expected shape; audio with no manifest is an error naming what is
missing), and tabular-only prefixes keep unslothai#6222's flat collision-renamed
layout byte for byte. Since the structured layout joins S3 keys into
filesystem paths and bucket contents are external input, a key carrying
'..' segments refuses the download instead of writing above the
dataset directory.

Credentials handling is untouched from unslothai#6222 (explicit keys or the
default chain/IAM role, never logged or persisted). Parquet manifests
cannot be rewritten without pyarrow; their audio references must
already be absolute, which the module docstring now states.

Closes unslothai#4539.
lonexreb added a commit to lonexreb/unsloth that referenced this pull request Sep 16, 2026
…st and point the manifest at it

key listing filtered audio files out, every download flattened to its
basename, and a manifest+audio prefix was called a mixed-format error.
So the layout unslothai#4539 asks for -- Whisper finetuning with audio files on
S3 plus a transcription manifest -- could never load: at best the
manifest downloaded alone and training died when datasets.Audio tried
to open paths that were never materialized.

Audio keys under the prefix now download too, preserving their
prefix-relative structure so the manifest's relative references stay
true, and the manifest's audio values are rewritten to the materialized
absolute paths -- matching prefix-relative keys, s3://bucket/key URIs,
the HF undecoded {"path": ...} shape, and manifest-relative paths;
anything unmatched is left exactly as written. The single-format rule
now judges only the manifest files (audio beside one manifest family is
the expected shape; audio with no manifest is an error naming what is
missing), and tabular-only prefixes keep unslothai#6222's flat collision-renamed
layout byte for byte. Since the structured layout joins S3 keys into
filesystem paths and bucket contents are external input, a key carrying
'..' segments refuses the download instead of writing above the
dataset directory.

Credentials handling is untouched from unslothai#6222 (explicit keys or the
default chain/IAM role, never logged or persisted). Parquet manifests
cannot be rewritten without pyarrow; their audio references must
already be absolute, which the module docstring now states.

Closes unslothai#4539.
lonexreb added a commit to lonexreb/unsloth that referenced this pull request Sep 16, 2026
…st and point the manifest at it

key listing filtered audio files out, every download flattened to its
basename, and a manifest+audio prefix was called a mixed-format error.
So the layout unslothai#4539 asks for -- Whisper finetuning with audio files on
S3 plus a transcription manifest -- could never load: at best the
manifest downloaded alone and training died when datasets.Audio tried
to open paths that were never materialized.

Audio keys under the prefix now download too, preserving their
prefix-relative structure so the manifest's relative references stay
true, and the manifest's audio values are rewritten to the materialized
absolute paths -- matching prefix-relative keys, s3://bucket/key URIs,
the HF undecoded {"path": ...} shape, and manifest-relative paths;
anything unmatched is left exactly as written. The single-format rule
now judges only the manifest files (audio beside one manifest family is
the expected shape; audio with no manifest is an error naming what is
missing), and tabular-only prefixes keep unslothai#6222's flat collision-renamed
layout byte for byte. Since the structured layout joins S3 keys into
filesystem paths and bucket contents are external input, a key carrying
'..' segments refuses the download instead of writing above the
dataset directory.

Credentials handling is untouched from unslothai#6222 (explicit keys or the
default chain/IAM role, never logged or persisted). Parquet manifests
cannot be rewritten without pyarrow; their audio references must
already be absolute, which the module docstring now states.

Closes unslothai#4539.
lonexreb added a commit to lonexreb/unsloth that referenced this pull request Sep 16, 2026
…st and point the manifest at it

key listing filtered audio files out, every download flattened to its
basename, and a manifest+audio prefix was called a mixed-format error.
So the layout unslothai#4539 asks for -- Whisper finetuning with audio files on
S3 plus a transcription manifest -- could never load: at best the
manifest downloaded alone and training died when datasets.Audio tried
to open paths that were never materialized.

Audio keys under the prefix now download too, preserving their
prefix-relative structure so the manifest's relative references stay
true, and the manifest's audio values are rewritten to the materialized
absolute paths -- matching prefix-relative keys, s3://bucket/key URIs,
the HF undecoded {"path": ...} shape, and manifest-relative paths;
anything unmatched is left exactly as written. The single-format rule
now judges only the manifest files (audio beside one manifest family is
the expected shape; audio with no manifest is an error naming what is
missing), and tabular-only prefixes keep unslothai#6222's flat collision-renamed
layout byte for byte. Since the structured layout joins S3 keys into
filesystem paths and bucket contents are external input, a key carrying
'..' segments refuses the download instead of writing above the
dataset directory.

Credentials handling is untouched from unslothai#6222 (explicit keys or the
default chain/IAM role, never logged or persisted). Parquet manifests
cannot be rewritten without pyarrow; their audio references must
already be absolute, which the module docstring now states.

Closes unslothai#4539.
lonexreb added a commit to lonexreb/unsloth that referenced this pull request Sep 16, 2026
…st and point the manifest at it

key listing filtered audio files out, every download flattened to its
basename, and a manifest+audio prefix was called a mixed-format error.
So the layout unslothai#4539 asks for -- Whisper finetuning with audio files on
S3 plus a transcription manifest -- could never load: at best the
manifest downloaded alone and training died when datasets.Audio tried
to open paths that were never materialized.

Audio keys under the prefix now download too, preserving their
prefix-relative structure so the manifest's relative references stay
true, and the manifest's audio values are rewritten to the materialized
absolute paths -- matching prefix-relative keys, s3://bucket/key URIs,
the HF undecoded {"path": ...} shape, and manifest-relative paths;
anything unmatched is left exactly as written. The single-format rule
now judges only the manifest files (audio beside one manifest family is
the expected shape; audio with no manifest is an error naming what is
missing), and tabular-only prefixes keep unslothai#6222's flat collision-renamed
layout byte for byte. Since the structured layout joins S3 keys into
filesystem paths and bucket contents are external input, a key carrying
'..' segments refuses the download instead of writing above the
dataset directory.

Credentials handling is untouched from unslothai#6222 (explicit keys or the
default chain/IAM role, never logged or persisted). Parquet manifests
cannot be rewritten without pyarrow; their audio references must
already be absolute, which the module docstring now states.

Closes unslothai#4539.
lonexreb added a commit to lonexreb/unsloth that referenced this pull request Sep 16, 2026
…st and point the manifest at it

key listing filtered audio files out, every download flattened to its
basename, and a manifest+audio prefix was called a mixed-format error.
So the layout unslothai#4539 asks for -- Whisper finetuning with audio files on
S3 plus a transcription manifest -- could never load: at best the
manifest downloaded alone and training died when datasets.Audio tried
to open paths that were never materialized.

Audio keys under the prefix now download too, preserving their
prefix-relative structure so the manifest's relative references stay
true, and the manifest's audio values are rewritten to the materialized
absolute paths -- matching prefix-relative keys, s3://bucket/key URIs,
the HF undecoded {"path": ...} shape, and manifest-relative paths;
anything unmatched is left exactly as written. The single-format rule
now judges only the manifest files (audio beside one manifest family is
the expected shape; audio with no manifest is an error naming what is
missing), and tabular-only prefixes keep unslothai#6222's flat collision-renamed
layout byte for byte. Since the structured layout joins S3 keys into
filesystem paths and bucket contents are external input, a key carrying
'..' segments refuses the download instead of writing above the
dataset directory.

Credentials handling is untouched from unslothai#6222 (explicit keys or the
default chain/IAM role, never logged or persisted). Parquet manifests
cannot be rewritten without pyarrow; their audio references must
already be absolute, which the module docstring now states.

Closes unslothai#4539.
lonexreb added a commit to lonexreb/unsloth that referenced this pull request Sep 27, 2026
…st and point the manifest at it

key listing filtered audio files out, every download flattened to its
basename, and a manifest+audio prefix was called a mixed-format error.
So the layout unslothai#4539 asks for -- Whisper finetuning with audio files on
S3 plus a transcription manifest -- could never load: at best the
manifest downloaded alone and training died when datasets.Audio tried
to open paths that were never materialized.

Audio keys under the prefix now download too, preserving their
prefix-relative structure so the manifest's relative references stay
true, and the manifest's audio values are rewritten to the materialized
absolute paths -- matching prefix-relative keys, s3://bucket/key URIs,
the HF undecoded {"path": ...} shape, and manifest-relative paths;
anything unmatched is left exactly as written. The single-format rule
now judges only the manifest files (audio beside one manifest family is
the expected shape; audio with no manifest is an error naming what is
missing), and tabular-only prefixes keep unslothai#6222's flat collision-renamed
layout byte for byte. Since the structured layout joins S3 keys into
filesystem paths and bucket contents are external input, a key carrying
'..' segments refuses the download instead of writing above the
dataset directory.

Credentials handling is untouched from unslothai#6222 (explicit keys or the
default chain/IAM role, never logged or persisted). Parquet manifests
cannot be rewritten without pyarrow; their audio references must
already be absolute, which the module docstring now states.

Closes unslothai#4539.
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.

3 participants