Repository navigation
Studio: preserve S3 dataset files with colliding names - #16830
Conversation
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 02ea5b037b
ℹ️ 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".
| local_by_key[key] = _unique_local_path( | ||
| os.path.dirname(path), os.path.basename(path), used_paths | ||
| ) |
There was a problem hiding this comment.
Reject audio-path renames for Parquet manifests
For path-backed Parquet audio datasets, this allocator can now rename a referenced recording, but _rewrite_audio_references skips .parquet, leaving the stored path unchanged. On case-sensitive Linux, for example, the previously distinct A.wav/a.wav files become A.wav/a_1.wav, breaking a reference to a.wav. If the destination already contains clip.wav, a Parquet row referencing that path silently reads the old recording while the new recording is downloaded as clip_1.wav. Reject Parquet downloads that require audio-path renames before downloading, or update the Parquet references instead of returning success.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Parquet audio paths are never resolved against the download directory, so renaming a downloaded file cannot change which file a row reads. load_dataset("parquet", ...) returns audio/a.wav exactly as stored, and both Audio.decode_example and _read_mono open a local path relative to the process working directory. Every production caller (trainer.py, worker.py, decision_trainer.py) downloads into a fresh mkdtemp directory that a Parquet file cannot name in advance, so audio/a.wav resolves the same way before and after this change. The existing clip.wav case needs an explicit dest_dir, which only tests pass. The refusal was removed on purpose in 02ea5b0.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 02ea5b037b
ℹ️ 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".
| local_by_key[key] = _unique_local_path( | ||
| os.path.dirname(path), os.path.basename(path), used_paths | ||
| ) |
There was a problem hiding this comment.
Reserve required directories before allocating collision suffixes
On a case-sensitive filesystem, a prefix containing audio/A.wav, audio/a.wav, and audio/a_1.wav/part.wav now allocates audio/a_1.wav to the second recording even though it is also a directory required by the third key. All allocations happen before downloading and only leaf paths are reserved, so _download_structured writes that recording and then raises FileExistsError when creating the third object's parent directory. This dataset downloaded successfully before the change. Reserve the required directory paths before assigning suffixes so generated filenames cannot occupy them.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This needs a prefix that holds a directory named with an audio extension (audio/a_1.wav/) whose name also equals the suffix generated for a case-colliding sibling. Real datasets do not name directories *.wav, and the failure is a clear FileExistsError before training starts, not a wrong recording. I am not adding directory reservation for that case.
There was a problem hiding this comment.
Agreed — the trigger needs a directory literally named with an audio extension and the failure is loud, not silent. Dropped the reservation commit; branch tip is back at 02ea5b0.
|
@codex review |
b488738 to
02ea5b0
Compare
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
I pushed 02ea5b0 to drop the Parquet error: relative Parquet audio paths never reach the temp download folder, so that audio isn't used either way, and the error could only block datasets that work today. I reproduced the mix-up on main, the S3 tests pass on the PR merged with current main, and Mirror CI is clear at 3a0e6f6. |
S3 audio downloads leave paths in Parquet manifests unchanged. A row pointing to `audio/a.wav` still resolves against the process working directory after the recording is downloaded into a fresh `unsloth_s3_dataset_*` directory. Full `s3://` references also bypass the downloaded copy. JSON, JSONL and CSV manifests already use the local paths. The Parquet limitation was noted in [the review of unslothai#16830](unslothai#16830 (comment)). Apply the existing reference resolver to Parquet rows in batches of 1,024, preserving the Arrow schema and Hugging Face feature metadata. Paths use the allocator's actual filenames, including collision suffixes. A completed rewrite replaces the manifest atomically; ambiguity or write errors leave the original intact and remove the staged file. A manifest without matching references stays byte-identical. The S3 fake now writes real Parquet rather than text under a `.parquet` filename, so the existing download and collision tests continue to exercise valid input. Validation on macOS, Python 3.12.4, datasets 4.3.0 and PyArrow 21.0.0: - The initial regression run has 12 failures on unchanged main. - All 138 tests pass across the audio download, general S3, optional-SDK and runtime suites. - Coverage includes string paths, undecoded HF Audio structs, lists, nulls, embedded bytes, prefix/manifest-relative paths, full S3 URIs, colliding keys, later-batch ambiguity, and an injected full-disk error. A real `datasets.load_dataset` round trip preserves Audio features and resolves a WAV whose sample bytes and sample rate are checked. - Repository-pinned Ruff lint and formatting, duplicate-definition and import-hoist checks, and `git diff --check` pass. ```sh python -m pytest studio/backend/tests/test_s3_audio_dataset.py \ studio/backend/tests/test_s3_dataset.py studio/backend/tests/test_s3_optional.py \ studio/backend/tests/test_s3_runtime.py -q --tb=short --timeout=60 ``` S3 transport is faked. No AWS service call, model training, or GPU run. Follow-up fixes on this branch: - Apple Silicon (MLX) training deleted the S3 download right after loading the manifest, before `_mlx_audio_rows` decoded the clips, so S3 audio training there failed for JSON, JSONL, CSV and Parquet manifests alike. The worker now keeps an S3 audio download until the run ends. `test_mlx_s3_audio_download_outlives_the_model_load` fails without this change. - The no-manifest error now lists Parquet among the supported manifest formats. - A test read the rewritten manifest without an encoding, which failed on Windows (cp1252). It now reads UTF-8. --------- Signed-off-by: dimitri <[email protected]> Co-authored-by: Daniel Han <[email protected]>
What was broken
S3 audio datasets can silently pair transcripts with the wrong recording. Distinct object keys can map to one local filename, so the later download replaces the earlier recording while both manifest rows remain. Manifest shards can also overwrite each other, and structured downloads overwrite existing files in an explicitly supplied destination.
Repro
0ab3f0773, prepare an S3 audio dataset containing distinctdatasets/audio/clip.wavanddatasets/audio//clip.wavobjects. Reference each by its full S3 URI in a JSONL manifest.prepare_s3_dataset_download.Fix
Reserve distinct local paths before downloading, using the existing suffix allocator with case-insensitive, Unicode-normalized reservations. Keep the original S3 key-to-path mapping for JSON, JSONL and CSV reference rewriting. Existing local files are preserved.
Parquet references cannot be rewritten here. If an audio filename must change, fail before downloading with guidance instead of returning a dataset bound to the wrong file. Non-colliding Parquet audio paths stay unchanged, and colliding Parquet manifest shards can still be renamed safely.
Test
Thirteen initial regression cases fail on main. Expanded coverage checks recordings and transcripts across JSON, JSONL and CSV, manifest shards, generated suffix collisions, existing files, and Parquet refusal and compatibility paths. Tests use the existing fake S3 client with real local files; no AWS credentials or GPU are needed.
From
studio/backend:All seven repository checks, the pinned formatter and strict i18n parity pass locally. No schema or dependency changes.