Finalize verified ESPnet release: 2667017 unique rows, 6804 archives
Browse files- CONVERSION.md +15 -1
- PUBLIC_DOWNLOAD_VALIDATION.json +46 -0
- README.md +15 -2
- REBALANCE.json +9 -0
- RELEASE_VALIDATION.json +39 -0
- STATUS.json +8 -5
- STREAM_PLAN.before-rebalance.json +0 -0
- STREAM_PLAN.json +0 -0
- commit_staged_release.py +179 -0
- convert_release.py +126 -41
- finalize_release.py +240 -0
- link_source_release.py +102 -0
- prepare_espnet.py +13 -0
- rebalance_streams.py +78 -0
- recipe-preparation.patch +99 -0
- test_converter.py +335 -0
- validate_public_release.py +124 -0
CONVERSION.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
|
| 3 |
The converter streams pinned, SHA256-verified source Parquet shards into deterministic tar.zst bundles. It preserves original encoded audio bytes and every training row, including intentional reuse of audio. Audio is stored by SHA256 and deduplicated within each ordered conversion stream; identical files across streams are merged during verified extraction; conversations reference portable relative audio paths. Text content, role order and source metadata are preserved. ESPnet example IDs use the globally unique source row_id.
|
| 4 |
|
| 5 |
-
SQLite transactions track audio deduplication, unique row IDs and completed source shards. A crash during conversion rolls back the shard. A successfully converted archive remains on disk until its Hub file size and LFS SHA256 match. Source downloads use bounded prefetch workers; completed input shards are removed after conversion. Upload batches are configurable. Each batch is committed, checked against remote file sizes and LFS SHA256, then included in the aggregate published status. Restarting the command resumes from its local state database.
|
| 6 |
|
| 7 |
Production conversion (requires write access to the target ESPnet dataset repos):
|
| 8 |
|
|
@@ -26,3 +26,17 @@ Download preparation is portable and independent of that audit workspace. Run pr
|
|
| 26 |
No audio resampling, PCM conversion or lossy recompression occurs. This format conversion does not change source dataset licenses, original source selection or paper-v1/v2 alignment.
|
| 27 |
|
| 28 |
Use a separate `--work-root` for a new conversion and the same directory when resuming. The finalizer also accepts `--root` pointing to that work directory. The production general-SFT run started with six fixed source ranges per partition. After completing about half the conversion, unconverted work was split into smaller ranges while copying each parent stream's validated audio and ID state. STREAM_PLAN.json records the active ranges; STREAM_PLAN.before-rebalance.json and REBALANCE.json document the transition. Rebalancing was performed with production workers stopped, and every source shard belongs to exactly one active range. Independent ranges can repeat an audio file in multiple archives; extraction verifies and merges identical content. Per-archive unique_audio_added counts are stream-local and must not be summed as the final count of distinct audio files. Final validation separately computes global unique IDs/audio hashes. Incomplete trials are restricted to contiguous uploaded prefixes.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
The converter streams pinned, SHA256-verified source Parquet shards into deterministic tar.zst bundles. It preserves original encoded audio bytes and every training row, including intentional reuse of audio. Audio is stored by SHA256 and deduplicated within each ordered conversion stream; identical files across streams are merged during verified extraction; conversations reference portable relative audio paths. Text content, role order and source metadata are preserved. ESPnet example IDs use the globally unique source row_id.
|
| 4 |
|
| 5 |
+
SQLite transactions track audio deduplication, unique row IDs and completed source shards. A crash during conversion rolls back the shard. A successfully converted archive remains on disk until its Hub file size and LFS SHA256 match. Source downloads use bounded prefetch workers; completed input shards are removed after conversion. Upload batches are configurable. Each batch is committed, checked against remote file sizes and LFS SHA256, then included in the aggregate published status. Six concurrent storage sessions are allowed independently of the conversion-stream count. Transient post-commit failures retry verification/status without reusing single-use upload operations; transient commit failures rebuild operations from the preserved archive files. Restarting the command resumes from its local state database.
|
| 6 |
|
| 7 |
Production conversion (requires write access to the target ESPnet dataset repos):
|
| 8 |
|
|
|
|
| 26 |
No audio resampling, PCM conversion or lossy recompression occurs. This format conversion does not change source dataset licenses, original source selection or paper-v1/v2 alignment.
|
| 27 |
|
| 28 |
Use a separate `--work-root` for a new conversion and the same directory when resuming. The finalizer also accepts `--root` pointing to that work directory. The production general-SFT run started with six fixed source ranges per partition. After completing about half the conversion, unconverted work was split into smaller ranges while copying each parent stream's validated audio and ID state. STREAM_PLAN.json records the active ranges; STREAM_PLAN.before-rebalance.json and REBALANCE.json document the transition. Rebalancing was performed with production workers stopped, and every source shard belongs to exactly one active range. Independent ranges can repeat an audio file in multiple archives; extraction verifies and merges identical content. Per-archive unique_audio_added counts are stream-local and must not be summed as the final count of distinct audio files. Final validation separately computes global unique IDs/audio hashes. Incomplete trials are restricted to contiguous uploaded prefixes.
|
| 29 |
+
|
| 30 |
+
## Large-release Hub publication
|
| 31 |
+
|
| 32 |
+
The full general release exceeded the Hub's hourly repository-commit allowance with small archive batches. Continue converting/preuploading without repository commits, then run the batch publisher in another terminal:
|
| 33 |
+
|
| 34 |
+
```bash
|
| 35 |
+
python convert_release.py --upload --dataset general --partition-parallel --lanes 6 --batch-shards 24 --download-workers 3 --defer-commit
|
| 36 |
+
HF_HUB_DISABLE_XET=1 python commit_staged_release.py --dataset general --batch-shards 256 --interval 60
|
| 37 |
+
python finalize_release.py --dataset general
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
The staging command does not mark blobs as publicly uploaded and never deletes its archives. `preuploads.sqlite3` checkpoints storage preuploads. The batch publisher uses standard LFS existence checks for the already-preuploaded Xet blobs, commits up to 256 files plus aggregate status, verifies remote archive sizes and SHA256, and respects server rate limits. This avoids repeating expensive Xet chunk processing during the commit step. Both processes use the same work directory. Finalize only after both finish; finalization checks every source row and remote archive before declaring a complete release. Once the workers finish and every archive has been verified on the Hub, local pending archives can be removed.
|
| 41 |
+
|
| 42 |
+
Seven regression tests cover cross-shard deduplication, transactional rollback, parallel resume, parent audio references after rebalancing, commit/verification/status retries, and staging without premature uploaded flags. Public-download validation compares 5,932 rows and 12 decoded waveforms with pinned originals; these checks supplement the eight-partition sample validation and full inventory/hash reconciliation.
|
PUBLIC_DOWNLOAD_VALIDATION.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"state": "passed",
|
| 3 |
+
"checks": [
|
| 4 |
+
{
|
| 5 |
+
"repository": "espnet/Bagpiper_TTS_SFT_Data_ESPnet",
|
| 6 |
+
"revision": "e8f575605cafe6bb5526f3a9db3fa905bce48e06",
|
| 7 |
+
"partition": "classical_tts",
|
| 8 |
+
"rows": 1024,
|
| 9 |
+
"decoded_waveforms": 3,
|
| 10 |
+
"preserved_text_order_audio": true,
|
| 11 |
+
"disjoint_train_valid_audio": true
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"repository": "espnet/Bagpiper_TTS_SFT_Data_ESPnet",
|
| 15 |
+
"revision": "96dbfa8edf77ae2698001ddfa98eebc837d1b3a6",
|
| 16 |
+
"partition": "intent_to_speech",
|
| 17 |
+
"rows": 812,
|
| 18 |
+
"decoded_waveforms": 3,
|
| 19 |
+
"preserved_text_order_audio": true,
|
| 20 |
+
"disjoint_train_valid_audio": true
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"repository": "espnet/Bagpiper_SFT_Data_ESPnet",
|
| 24 |
+
"revision": "d6ffefe3e37326065b598bf5a6039ec9d1877eeb",
|
| 25 |
+
"partition": "generation",
|
| 26 |
+
"rows": 2048,
|
| 27 |
+
"decoded_waveforms": 3,
|
| 28 |
+
"preserved_text_order_audio": true,
|
| 29 |
+
"disjoint_train_valid_audio": true
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"repository": "espnet/Bagpiper_SFT_Data_ESPnet",
|
| 33 |
+
"revision": "15a96eb4749323b5ac36e540c3c2390283f14640",
|
| 34 |
+
"partition": "understanding",
|
| 35 |
+
"rows": 2048,
|
| 36 |
+
"decoded_waveforms": 3,
|
| 37 |
+
"preserved_text_order_audio": true,
|
| 38 |
+
"disjoint_train_valid_audio": true
|
| 39 |
+
}
|
| 40 |
+
],
|
| 41 |
+
"total_rows": 5932,
|
| 42 |
+
"decoded_waveforms": 12,
|
| 43 |
+
"limitations": [
|
| 44 |
+
"CPU reader verification; no GPU training or inference"
|
| 45 |
+
]
|
| 46 |
+
}
|
README.md
CHANGED
|
@@ -11,10 +11,23 @@ tags:
|
|
| 11 |
|
| 12 |
# Bagpiper SFT Data in ESPnet format
|
| 13 |
|
| 14 |
-
This release converts [espnet/Bagpiper_SFT_Data](https://huggingface.co/datasets/espnet/Bagpiper_SFT_Data) at revision `7dec4d68dc30e442368914619668fcd695a897f7` into portable, lossless ESPnet dialogue bundles. **
|
|
|
|
|
|
|
| 15 |
|
| 16 |
Each `.tar.zst` contains original encoded audio, three-element dialogue messages, and source provenance. Audio is deduplicated by SHA-256 within each ordered conversion stream; identical files across streams are verified and merged during extraction. Repeated training examples remain present. All text, message roles, and order are preserved. The original globally unique `row_id` becomes ESPnet `example_id`. No audio resampling or lossy transcoding is performed.
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
## Prepare local training inputs
|
| 19 |
|
| 20 |
```bash
|
|
@@ -23,7 +36,7 @@ hf download espnet/Bagpiper_SFT_Data_ESPnet prepare_espnet.py --local-dir tools
|
|
| 23 |
python tools/prepare_espnet.py --repo-id espnet/Bagpiper_SFT_Data_ESPnet --data-root /path/to/bagpiper-sft
|
| 24 |
```
|
| 25 |
|
| 26 |
-
For a small prefix trial, add `--max-shards 2
|
| 27 |
|
| 28 |
The default validation fraction is 1%, chosen deterministically from the audio SHA-256. The same audio always has the same split, including across source shards and partitions. Use `all.json` to retain the original complete training pool. This suggested split is not the paper's official split. `--valid-fraction 0` assigns every row to train.
|
| 29 |
|
|
|
|
| 11 |
|
| 12 |
# Bagpiper SFT Data in ESPnet format
|
| 13 |
|
| 14 |
+
This release converts [espnet/Bagpiper_SFT_Data](https://huggingface.co/datasets/espnet/Bagpiper_SFT_Data) at revision `7dec4d68dc30e442368914619668fcd695a897f7` into portable, lossless ESPnet dialogue bundles. **Complete:** all 2,667,017 source rows and 6,804 shards are converted and uploaded. [RELEASE_VALIDATION.json](./RELEASE_VALIDATION.json) records the full source/count/hash reconciliation.
|
| 15 |
+
|
| 16 |
+
**Source selection:** this preserves the public recipe-v1 pool (including 1,193,006 understanding rows). It does not reconstruct the paper-v2 filtered selection.
|
| 17 |
|
| 18 |
Each `.tar.zst` contains original encoded audio, three-element dialogue messages, and source provenance. Audio is deduplicated by SHA-256 within each ordered conversion stream; identical files across streams are verified and merged during extraction. Repeated training examples remain present. All text, message roles, and order are preserved. The original globally unique `row_id` becomes ESPnet `example_id`. No audio resampling or lossy transcoding is performed.
|
| 19 |
|
| 20 |
+
## Verified release counts
|
| 21 |
+
|
| 22 |
+
| Partition | Preserved rows | Distinct audio files |
|
| 23 |
+
| --- | ---: | ---: |
|
| 24 |
+
| generation | 1,474,011 | 979,274 |
|
| 25 |
+
| understanding | 1,193,006 | 334,493 |
|
| 26 |
+
|
| 27 |
+
Distinct audio counts use `(partition, SHA256)` after reconciling all conversion streams. Archives may contain repeated files across streams; verified extraction merges them. Every original training row remains present.
|
| 28 |
+
|
| 29 |
+
[VALIDATION.json](./VALIDATION.json) covers 3,814 original-versus-converted sample rows across all eight partitions and 24 decoded waveform comparisons using the actual ESPnet reader. The full release additionally checks every input shard hash, every embedded audio hash, all row IDs, and every uploaded archive's size and LFS SHA256. GPU training and inference have not been validated. Use `prepare_espnet.py` for local paths and manifests; these bundles are not directly loadable with `datasets.load_dataset`.
|
| 30 |
+
|
| 31 |
## Prepare local training inputs
|
| 32 |
|
| 33 |
```bash
|
|
|
|
| 36 |
python tools/prepare_espnet.py --repo-id espnet/Bagpiper_SFT_Data_ESPnet --data-root /path/to/bagpiper-sft
|
| 37 |
```
|
| 38 |
|
| 39 |
+
For a small prefix trial, add `--max-shards 2`. Repeat `--partition NAME` to select application partitions. The helper verifies archive SHA-256, extracts safely, resolves audio paths, checks duplicate IDs and linkage, and writes `prepared/NAME/{all,train,valid}.json` plus `dialogues.jsonl`.
|
| 40 |
|
| 41 |
The default validation fraction is 1%, chosen deterministically from the audio SHA-256. The same audio always has the same split, including across source shards and partitions. Use `all.json` to retain the original complete training pool. This suggested split is not the paper's official split. `--valid-fraction 0` assigns every row to train.
|
| 42 |
|
REBALANCE.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"created_at": "2026-10-01T00:46:14.901776+00:00",
|
| 3 |
+
"original_streams": 12,
|
| 4 |
+
"new_streams": 40,
|
| 5 |
+
"completed_shards": 3549,
|
| 6 |
+
"remaining_shards": 3255,
|
| 7 |
+
"max_shards_per_new_stream": 160,
|
| 8 |
+
"state_copied_before_scheduling": true
|
| 9 |
+
}
|
RELEASE_VALIDATION.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"state": "passed",
|
| 3 |
+
"completed_at": "2026-10-01T01:29:04.171087+00:00",
|
| 4 |
+
"source_repository": "espnet/Bagpiper_SFT_Data",
|
| 5 |
+
"source_revision": "7dec4d68dc30e442368914619668fcd695a897f7",
|
| 6 |
+
"verified_remote_revision": "ddc7d626fecf295a0cc6c71d0515aa2e8bd2a0bf",
|
| 7 |
+
"source_shards": 6804,
|
| 8 |
+
"verified_archive_files": 6804,
|
| 9 |
+
"source_rows": 2667017,
|
| 10 |
+
"unique_row_ids": 2667017,
|
| 11 |
+
"unique_audio_files": 1313767,
|
| 12 |
+
"unique_audio_bytes": 489342164954,
|
| 13 |
+
"partition_statistics": {
|
| 14 |
+
"generation": {
|
| 15 |
+
"rows": 1474011,
|
| 16 |
+
"unique_audio": 979274,
|
| 17 |
+
"audio_bytes": 279641958307
|
| 18 |
+
},
|
| 19 |
+
"understanding": {
|
| 20 |
+
"rows": 1193006,
|
| 21 |
+
"unique_audio": 334493,
|
| 22 |
+
"audio_bytes": 209700206647
|
| 23 |
+
}
|
| 24 |
+
},
|
| 25 |
+
"audio_bytes_preserved": true,
|
| 26 |
+
"text_and_role_order_preserved": true,
|
| 27 |
+
"checks": [
|
| 28 |
+
"All source shard paths/counts/SHA256 match pinned inventory",
|
| 29 |
+
"All global row IDs reconciled across workers",
|
| 30 |
+
"Per-partition row counts match the source; repeated hashes have consistent filenames/sizes across streams",
|
| 31 |
+
"All remote archive sizes and LFS SHA256 match conversion records",
|
| 32 |
+
"Original embedded audio SHA256 checked for every converted row; repeated hashes reuse prior validated audio"
|
| 33 |
+
],
|
| 34 |
+
"limitations": [
|
| 35 |
+
"No full GPU training or inference validation",
|
| 36 |
+
"Per-shard integrity plus source/audio hashes; remote archives are verified by LFS hash, not all redownloaded",
|
| 37 |
+
"Dataset terms and paper-v1/v2 selection unchanged"
|
| 38 |
+
]
|
| 39 |
+
}
|
STATUS.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
| 1 |
{
|
| 2 |
"format": "bagpiper-espnet-lossless-dialogue-v1",
|
| 3 |
-
"state": "
|
| 4 |
"source_repository": "espnet/Bagpiper_SFT_Data",
|
| 5 |
"source_revision": "7dec4d68dc30e442368914619668fcd695a897f7",
|
| 6 |
"expected_rows": 2667017,
|
| 7 |
"expected_source_shards": 6804,
|
| 8 |
"uploaded_rows": 2667017,
|
| 9 |
"uploaded_shards": 6804,
|
| 10 |
-
"unique_audio_files":
|
| 11 |
-
"unique_audio_bytes":
|
| 12 |
-
"unique_audio_count_scope": "
|
| 13 |
"uploaded_archive_bytes": 719295381339,
|
| 14 |
"transformations": [
|
| 15 |
"Audio bytes preserved exactly; deduplicated by SHA256 within each ordered stream; identical files merge during extraction",
|
|
@@ -102078,5 +102078,8 @@
|
|
| 102078 |
"unique_audio_bytes_added": 42071954,
|
| 102079 |
"logical_audio_bytes": 137233512
|
| 102080 |
}
|
| 102081 |
-
]
|
|
|
|
|
|
|
|
|
|
| 102082 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"format": "bagpiper-espnet-lossless-dialogue-v1",
|
| 3 |
+
"state": "complete",
|
| 4 |
"source_repository": "espnet/Bagpiper_SFT_Data",
|
| 5 |
"source_revision": "7dec4d68dc30e442368914619668fcd695a897f7",
|
| 6 |
"expected_rows": 2667017,
|
| 7 |
"expected_source_shards": 6804,
|
| 8 |
"uploaded_rows": 2667017,
|
| 9 |
"uploaded_shards": 6804,
|
| 10 |
+
"unique_audio_files": 1313767,
|
| 11 |
+
"unique_audio_bytes": 489342164954,
|
| 12 |
+
"unique_audio_count_scope": "partition_and_sha256",
|
| 13 |
"uploaded_archive_bytes": 719295381339,
|
| 14 |
"transformations": [
|
| 15 |
"Audio bytes preserved exactly; deduplicated by SHA256 within each ordered stream; identical files merge during extraction",
|
|
|
|
| 102078 |
"unique_audio_bytes_added": 42071954,
|
| 102079 |
"logical_audio_bytes": 137233512
|
| 102080 |
}
|
| 102081 |
+
],
|
| 102082 |
+
"archive_audio_entries": 1658333,
|
| 102083 |
+
"archive_audio_bytes": 824650644469,
|
| 102084 |
+
"validation": "RELEASE_VALIDATION.json"
|
| 102085 |
}
|
STREAM_PLAN.before-rebalance.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
STREAM_PLAN.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
commit_staged_release.py
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Commit preuploaded bundles in large batches, respecting Hub rate limits."""
|
| 3 |
+
import argparse
|
| 4 |
+
from datetime import datetime, timezone
|
| 5 |
+
import json
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
import sqlite3
|
| 8 |
+
import time
|
| 9 |
+
|
| 10 |
+
from huggingface_hub import CommitOperationAdd, HfApi, get_token
|
| 11 |
+
from huggingface_hub.errors import HfHubHTTPError
|
| 12 |
+
from huggingface_hub.utils import disable_progress_bars
|
| 13 |
+
|
| 14 |
+
from convert_release import RECIPES, status_document
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def main():
|
| 18 |
+
disable_progress_bars()
|
| 19 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 20 |
+
parser.add_argument("--dataset", choices=list(RECIPES), required=True)
|
| 21 |
+
parser.add_argument(
|
| 22 |
+
"--root", type=Path, default=Path("/root/bagpiper-sft-conversion/releases")
|
| 23 |
+
)
|
| 24 |
+
parser.add_argument("--batch-shards", type=int, default=256)
|
| 25 |
+
parser.add_argument("--interval", type=int, default=60)
|
| 26 |
+
args = parser.parse_args()
|
| 27 |
+
recipe = RECIPES[args.dataset]
|
| 28 |
+
root = args.root / args.dataset
|
| 29 |
+
manifest = json.loads((root / "SOURCE_MANIFEST.json").read_text())
|
| 30 |
+
inventory = manifest["shards"]
|
| 31 |
+
api = HfApi(token=get_token())
|
| 32 |
+
connection = sqlite3.connect(root / "conversion.sqlite3", timeout=120)
|
| 33 |
+
# Recover archives that were committed before a transient verification or
|
| 34 |
+
# STATUS error. Local files remain while conversion/preuploads are active.
|
| 35 |
+
remote = {
|
| 36 |
+
f.path: f
|
| 37 |
+
for f in api.list_repo_tree(
|
| 38 |
+
recipe["target"], repo_type="dataset", recursive=True
|
| 39 |
+
)
|
| 40 |
+
if hasattr(f, "size") and f.path.endswith(".tar.zst")
|
| 41 |
+
}
|
| 42 |
+
recovered = 0
|
| 43 |
+
for path, raw in connection.execute(
|
| 44 |
+
"SELECT path,record FROM shards WHERE uploaded=0"
|
| 45 |
+
).fetchall():
|
| 46 |
+
record = json.loads(raw)
|
| 47 |
+
file = remote.get(record["archive_path"])
|
| 48 |
+
if file is not None:
|
| 49 |
+
assert (
|
| 50 |
+
file.size == record["archive_bytes"]
|
| 51 |
+
and file.lfs.sha256 == record["archive_sha256"]
|
| 52 |
+
)
|
| 53 |
+
connection.execute("UPDATE shards SET uploaded=1 WHERE path=?", (path,))
|
| 54 |
+
recovered += 1
|
| 55 |
+
connection.commit()
|
| 56 |
+
print(
|
| 57 |
+
json.dumps(dict(event="recovered_remote_commits", shards=recovered)), flush=True
|
| 58 |
+
)
|
| 59 |
+
retry_at = 0
|
| 60 |
+
while True:
|
| 61 |
+
uploaded = [
|
| 62 |
+
json.loads(r)
|
| 63 |
+
for r, in connection.execute(
|
| 64 |
+
"SELECT record FROM shards WHERE uploaded=1 ORDER BY path"
|
| 65 |
+
)
|
| 66 |
+
]
|
| 67 |
+
if len(uploaded) == len(inventory):
|
| 68 |
+
print(
|
| 69 |
+
json.dumps(
|
| 70 |
+
dict(
|
| 71 |
+
event="all_archives_committed_verified",
|
| 72 |
+
shards=len(uploaded),
|
| 73 |
+
rows=sum(r["rows"] for r in uploaded),
|
| 74 |
+
)
|
| 75 |
+
),
|
| 76 |
+
flush=True,
|
| 77 |
+
)
|
| 78 |
+
return
|
| 79 |
+
pending = [
|
| 80 |
+
json.loads(r)
|
| 81 |
+
for r, in connection.execute(
|
| 82 |
+
"SELECT record FROM shards WHERE uploaded=0 ORDER BY path"
|
| 83 |
+
)
|
| 84 |
+
]
|
| 85 |
+
staged_path = root / "preuploads.sqlite3"
|
| 86 |
+
if not staged_path.exists():
|
| 87 |
+
time.sleep(20)
|
| 88 |
+
continue
|
| 89 |
+
staged = sqlite3.connect(staged_path, timeout=120)
|
| 90 |
+
staged_rows = {
|
| 91 |
+
p: (sha, size)
|
| 92 |
+
for p, sha, size in staged.execute("SELECT path,sha,size FROM blobs")
|
| 93 |
+
}
|
| 94 |
+
staged.close()
|
| 95 |
+
ready = [
|
| 96 |
+
r
|
| 97 |
+
for r in pending
|
| 98 |
+
if staged_rows.get(r["archive_path"])
|
| 99 |
+
== (r["archive_sha256"], r["archive_bytes"])
|
| 100 |
+
][: args.batch_shards]
|
| 101 |
+
if not ready or time.time() < retry_at:
|
| 102 |
+
time.sleep(20)
|
| 103 |
+
continue
|
| 104 |
+
status = status_document(
|
| 105 |
+
recipe, manifest["revision"], inventory, uploaded + ready, "converting"
|
| 106 |
+
)
|
| 107 |
+
operations = [
|
| 108 |
+
CommitOperationAdd(
|
| 109 |
+
path_in_repo=r["archive_path"], path_or_fileobj=root / r["archive_path"]
|
| 110 |
+
)
|
| 111 |
+
for r in ready
|
| 112 |
+
]
|
| 113 |
+
operations.append(
|
| 114 |
+
CommitOperationAdd(
|
| 115 |
+
path_in_repo="STATUS.json",
|
| 116 |
+
path_or_fileobj=(json.dumps(status, indent=2) + "\n").encode(),
|
| 117 |
+
)
|
| 118 |
+
)
|
| 119 |
+
try:
|
| 120 |
+
commit = api.create_commit(
|
| 121 |
+
recipe["target"],
|
| 122 |
+
repo_type="dataset",
|
| 123 |
+
operations=operations,
|
| 124 |
+
commit_message=f"Publish {len(ready)} verified preuploaded bundles ({len(uploaded)+len(ready)}/{len(inventory)})",
|
| 125 |
+
num_threads=4,
|
| 126 |
+
)
|
| 127 |
+
except HfHubHTTPError as error:
|
| 128 |
+
response = error.response
|
| 129 |
+
if response is None or response.status_code != 429:
|
| 130 |
+
raise
|
| 131 |
+
# Never hammer a limited commit endpoint. Use a server-provided
|
| 132 |
+
# retry delay when available, otherwise retry only after a minute.
|
| 133 |
+
delay = max(60, float(response.headers.get("Retry-After", 60)))
|
| 134 |
+
retry_at = time.time() + delay
|
| 135 |
+
print(
|
| 136 |
+
json.dumps(
|
| 137 |
+
dict(
|
| 138 |
+
event="commit_rate_limited",
|
| 139 |
+
retry_at=datetime.fromtimestamp(
|
| 140 |
+
retry_at, timezone.utc
|
| 141 |
+
).isoformat(),
|
| 142 |
+
)
|
| 143 |
+
),
|
| 144 |
+
flush=True,
|
| 145 |
+
)
|
| 146 |
+
continue
|
| 147 |
+
files = {
|
| 148 |
+
f.path: f
|
| 149 |
+
for f in api.get_paths_info(
|
| 150 |
+
recipe["target"],
|
| 151 |
+
[r["archive_path"] for r in ready],
|
| 152 |
+
repo_type="dataset",
|
| 153 |
+
revision=commit.oid,
|
| 154 |
+
)
|
| 155 |
+
}
|
| 156 |
+
for r in ready:
|
| 157 |
+
f = files[r["archive_path"]]
|
| 158 |
+
assert f.size == r["archive_bytes"] and f.lfs.sha256 == r["archive_sha256"]
|
| 159 |
+
connection.execute(
|
| 160 |
+
"UPDATE shards SET uploaded=1 WHERE path=?", (r["source_path"],)
|
| 161 |
+
)
|
| 162 |
+
connection.commit()
|
| 163 |
+
(root / "STATUS.json").write_text(json.dumps(status, indent=2) + "\n")
|
| 164 |
+
print(
|
| 165 |
+
json.dumps(
|
| 166 |
+
dict(
|
| 167 |
+
event="batch_committed_verified",
|
| 168 |
+
shards=len(ready),
|
| 169 |
+
total=len(uploaded) + len(ready),
|
| 170 |
+
revision=commit.oid,
|
| 171 |
+
)
|
| 172 |
+
),
|
| 173 |
+
flush=True,
|
| 174 |
+
)
|
| 175 |
+
retry_at = time.time() + args.interval
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
if __name__ == "__main__":
|
| 179 |
+
main()
|
convert_release.py
CHANGED
|
@@ -25,6 +25,7 @@ from prepare_espnet import digest
|
|
| 25 |
|
| 26 |
AUDIT = Path("/root/bagpiper-release-audit")
|
| 27 |
UPLOAD_LOCK = threading.Lock()
|
|
|
|
| 28 |
RECIPES = {
|
| 29 |
"tts": {
|
| 30 |
"source": "espnet/Bagpiper_TTS_SFT_Data",
|
|
@@ -379,48 +380,89 @@ ESPnet recipes: [Bagpiper](https://github.com/jctian98/espnet/tree/bagpiper-e2e-
|
|
| 379 |
|
| 380 |
def upload_batch(api, recipe, revision, inventory, records, previous):
|
| 381 |
root = Path(recipe["root"])
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
|
|
|
| 385 |
)
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
recipe, revision, inventory, previous + records, "converting"
|
| 391 |
-
)
|
| 392 |
-
operations.append(
|
| 393 |
CommitOperationAdd(
|
| 394 |
-
path_in_repo="
|
| 395 |
-
path_or_fileobj=(json.dumps(status, indent=2) + "\n").encode(),
|
| 396 |
)
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
# Upload large blobs concurrently, serialize only the small Hub
|
| 403 |
-
# commit and aggregate STATUS update to avoid lost status writes.
|
| 404 |
-
if recipe.get("parallel"):
|
| 405 |
api.preupload_lfs_files(
|
| 406 |
recipe["target"],
|
| 407 |
-
additions=
|
| 408 |
repo_type="dataset",
|
| 409 |
num_threads=4,
|
| 410 |
)
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 419 |
info = api.get_paths_info(
|
| 420 |
recipe["target"],
|
| 421 |
[r["archive_path"] for r in records],
|
| 422 |
repo_type="dataset",
|
| 423 |
-
revision=
|
| 424 |
)
|
| 425 |
remote = {f.path: f for f in info}
|
| 426 |
for r in records:
|
|
@@ -461,8 +503,20 @@ def upload_batch(api, recipe, revision, inventory, records, previous):
|
|
| 461 |
).encode(),
|
| 462 |
commit_message=f"Verify uploaded prefix: {len(all_records)}/{len(inventory)} shards",
|
| 463 |
)
|
| 464 |
-
return
|
| 465 |
-
except Exception:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 466 |
if attempt == 7:
|
| 467 |
raise
|
| 468 |
time.sleep(min(30, 2**attempt))
|
|
@@ -596,15 +650,21 @@ def convert_partition(
|
|
| 596 |
pending,
|
| 597 |
[],
|
| 598 |
)
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
|
|
|
|
|
|
| 604 |
print(
|
| 605 |
json.dumps(
|
| 606 |
dict(
|
| 607 |
-
event=
|
|
|
|
|
|
|
|
|
|
|
|
|
| 608 |
partition=partition,
|
| 609 |
batch=len(pending),
|
| 610 |
commit=commit,
|
|
@@ -612,8 +672,9 @@ def convert_partition(
|
|
| 612 |
),
|
| 613 |
flush=True,
|
| 614 |
)
|
| 615 |
-
|
| 616 |
-
|
|
|
|
| 617 |
pending = []
|
| 618 |
aggregate.close()
|
| 619 |
state.close()
|
|
@@ -673,6 +734,20 @@ def run_partition_parallel(recipe, revision, inventory, workers, batch_shards, l
|
|
| 673 |
flush=True,
|
| 674 |
)
|
| 675 |
connection = sqlite3.connect(root / "conversion.sqlite3")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 676 |
records = [
|
| 677 |
json.loads(r[0])
|
| 678 |
for r in connection.execute(
|
|
@@ -720,10 +795,16 @@ def main():
|
|
| 720 |
parser.add_argument("--download-workers", type=int, default=4)
|
| 721 |
parser.add_argument("--partition-parallel", action="store_true")
|
| 722 |
parser.add_argument("--lanes", type=int, default=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 723 |
args = parser.parse_args()
|
| 724 |
api = HfApi(token=get_token())
|
| 725 |
for name in args.dataset or ["tts", "general"]:
|
| 726 |
recipe = dict(RECIPES[name])
|
|
|
|
| 727 |
revision, inventory = read_inventory(recipe["snapshot"])
|
| 728 |
if args.local_samples:
|
| 729 |
candidates = {
|
|
@@ -761,7 +842,7 @@ def main():
|
|
| 761 |
pinned.write_text(json.dumps(document, indent=2) + "\n")
|
| 762 |
(root / "README.md").write_text(readme(recipe, revision))
|
| 763 |
scripts = Path(__file__).resolve().parent
|
| 764 |
-
if args.upload:
|
| 765 |
api.create_repo(
|
| 766 |
recipe["target"], repo_type="dataset", private=False, exist_ok=True
|
| 767 |
)
|
|
@@ -815,6 +896,10 @@ def main():
|
|
| 815 |
args.lanes,
|
| 816 |
)
|
| 817 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
| 818 |
known = {
|
| 819 |
r[0]: bool(r[1])
|
| 820 |
for r in connection.execute("SELECT path,uploaded FROM shards")
|
|
|
|
| 25 |
|
| 26 |
AUDIT = Path("/root/bagpiper-release-audit")
|
| 27 |
UPLOAD_LOCK = threading.Lock()
|
| 28 |
+
UPLOAD_SLOTS = threading.BoundedSemaphore(6)
|
| 29 |
RECIPES = {
|
| 30 |
"tts": {
|
| 31 |
"source": "espnet/Bagpiper_TTS_SFT_Data",
|
|
|
|
| 380 |
|
| 381 |
def upload_batch(api, recipe, revision, inventory, records, previous):
|
| 382 |
root = Path(recipe["root"])
|
| 383 |
+
if recipe.get("defer_commit"):
|
| 384 |
+
staged = sqlite3.connect(root / "preuploads.sqlite3", timeout=120)
|
| 385 |
+
staged.execute(
|
| 386 |
+
"CREATE TABLE IF NOT EXISTS blobs (path TEXT PRIMARY KEY,sha TEXT,size INTEGER)"
|
| 387 |
)
|
| 388 |
+
known = {
|
| 389 |
+
p: (h, n) for p, h, n in staged.execute("SELECT path,sha,size FROM blobs")
|
| 390 |
+
}
|
| 391 |
+
additions = [
|
|
|
|
|
|
|
|
|
|
| 392 |
CommitOperationAdd(
|
| 393 |
+
path_in_repo=r["archive_path"], path_or_fileobj=root / r["archive_path"]
|
|
|
|
| 394 |
)
|
| 395 |
+
for r in records
|
| 396 |
+
if known.get(r["archive_path"]) != (r["archive_sha256"], r["archive_bytes"])
|
| 397 |
+
]
|
| 398 |
+
if additions:
|
| 399 |
+
with UPLOAD_SLOTS:
|
|
|
|
|
|
|
|
|
|
| 400 |
api.preupload_lfs_files(
|
| 401 |
recipe["target"],
|
| 402 |
+
additions=additions,
|
| 403 |
repo_type="dataset",
|
| 404 |
num_threads=4,
|
| 405 |
)
|
| 406 |
+
staged.executemany(
|
| 407 |
+
"INSERT OR REPLACE INTO blobs VALUES (?,?,?)",
|
| 408 |
+
[
|
| 409 |
+
(r["archive_path"], r["archive_sha256"], r["archive_bytes"])
|
| 410 |
+
for r in records
|
| 411 |
+
],
|
| 412 |
+
)
|
| 413 |
+
staged.commit()
|
| 414 |
+
staged.close()
|
| 415 |
+
return "preuploaded-awaiting-batched-commit"
|
| 416 |
+
commit_revision = None
|
| 417 |
+
for attempt in range(8):
|
| 418 |
+
try:
|
| 419 |
+
if commit_revision is None:
|
| 420 |
+
# CommitOperationAdd objects are single-use and can lose their
|
| 421 |
+
# local path after preupload. A retry must create fresh objects.
|
| 422 |
+
operations = [
|
| 423 |
+
CommitOperationAdd(
|
| 424 |
+
path_in_repo=r["archive_path"],
|
| 425 |
+
path_or_fileobj=root / r["archive_path"],
|
| 426 |
+
)
|
| 427 |
+
for r in records
|
| 428 |
+
]
|
| 429 |
+
if not recipe.get("parallel"):
|
| 430 |
+
status = status_document(
|
| 431 |
+
recipe, revision, inventory, previous + records, "converting"
|
| 432 |
+
)
|
| 433 |
+
operations.append(
|
| 434 |
+
CommitOperationAdd(
|
| 435 |
+
path_in_repo="STATUS.json",
|
| 436 |
+
path_or_fileobj=(
|
| 437 |
+
json.dumps(status, indent=2) + "\n"
|
| 438 |
+
).encode(),
|
| 439 |
+
)
|
| 440 |
+
)
|
| 441 |
+
# Bound storage sessions independently of conversion streams.
|
| 442 |
+
if recipe.get("parallel"):
|
| 443 |
+
with UPLOAD_SLOTS:
|
| 444 |
+
api.preupload_lfs_files(
|
| 445 |
+
recipe["target"],
|
| 446 |
+
additions=operations,
|
| 447 |
+
repo_type="dataset",
|
| 448 |
+
num_threads=4,
|
| 449 |
+
)
|
| 450 |
+
with UPLOAD_LOCK:
|
| 451 |
+
commit = api.create_commit(
|
| 452 |
+
recipe["target"],
|
| 453 |
+
repo_type="dataset",
|
| 454 |
+
operations=operations,
|
| 455 |
+
commit_message=f"Convert and validate {len(records)} source shards",
|
| 456 |
+
num_threads=4,
|
| 457 |
+
)
|
| 458 |
+
commit_revision = str(commit.oid)
|
| 459 |
+
# Once committed, retry verification/status only. Never commit the
|
| 460 |
+
# same operations again following a transient read/status failure.
|
| 461 |
info = api.get_paths_info(
|
| 462 |
recipe["target"],
|
| 463 |
[r["archive_path"] for r in records],
|
| 464 |
repo_type="dataset",
|
| 465 |
+
revision=commit_revision,
|
| 466 |
)
|
| 467 |
remote = {f.path: f for f in info}
|
| 468 |
for r in records:
|
|
|
|
| 503 |
).encode(),
|
| 504 |
commit_message=f"Verify uploaded prefix: {len(all_records)}/{len(inventory)} shards",
|
| 505 |
)
|
| 506 |
+
return commit_revision
|
| 507 |
+
except Exception as error:
|
| 508 |
+
print(
|
| 509 |
+
json.dumps(
|
| 510 |
+
dict(
|
| 511 |
+
event="upload_retry",
|
| 512 |
+
attempt=attempt + 1,
|
| 513 |
+
error_type=type(error).__name__,
|
| 514 |
+
already_committed=commit_revision is not None,
|
| 515 |
+
first_archive=records[0]["archive_path"],
|
| 516 |
+
)
|
| 517 |
+
),
|
| 518 |
+
flush=True,
|
| 519 |
+
)
|
| 520 |
if attempt == 7:
|
| 521 |
raise
|
| 522 |
time.sleep(min(30, 2**attempt))
|
|
|
|
| 650 |
pending,
|
| 651 |
[],
|
| 652 |
)
|
| 653 |
+
if not recipe.get("defer_commit"):
|
| 654 |
+
for r in pending:
|
| 655 |
+
state.execute(
|
| 656 |
+
"UPDATE shards SET uploaded=1 WHERE path=?",
|
| 657 |
+
(r["source_path"],),
|
| 658 |
+
)
|
| 659 |
+
state.commit()
|
| 660 |
print(
|
| 661 |
json.dumps(
|
| 662 |
dict(
|
| 663 |
+
event=(
|
| 664 |
+
"preuploaded"
|
| 665 |
+
if recipe.get("defer_commit")
|
| 666 |
+
else "uploaded"
|
| 667 |
+
),
|
| 668 |
partition=partition,
|
| 669 |
batch=len(pending),
|
| 670 |
commit=commit,
|
|
|
|
| 672 |
),
|
| 673 |
flush=True,
|
| 674 |
)
|
| 675 |
+
if not recipe.get("defer_commit"):
|
| 676 |
+
for r in pending:
|
| 677 |
+
(root / r["archive_path"]).unlink(missing_ok=True)
|
| 678 |
pending = []
|
| 679 |
aggregate.close()
|
| 680 |
state.close()
|
|
|
|
| 734 |
flush=True,
|
| 735 |
)
|
| 736 |
connection = sqlite3.connect(root / "conversion.sqlite3")
|
| 737 |
+
if recipe.get("defer_commit"):
|
| 738 |
+
count, rows = connection.execute(
|
| 739 |
+
"SELECT count(*),sum(json_extract(record,'$.rows')) FROM shards"
|
| 740 |
+
).fetchone()
|
| 741 |
+
connection.close()
|
| 742 |
+
if count != len(inventory) or rows != sum(r["rows"] for r in inventory):
|
| 743 |
+
raise ValueError("Final staged conversion count mismatch")
|
| 744 |
+
print(
|
| 745 |
+
json.dumps(
|
| 746 |
+
dict(event="staged_conversion_finished", rows=rows, shards=count)
|
| 747 |
+
),
|
| 748 |
+
flush=True,
|
| 749 |
+
)
|
| 750 |
+
return
|
| 751 |
records = [
|
| 752 |
json.loads(r[0])
|
| 753 |
for r in connection.execute(
|
|
|
|
| 795 |
parser.add_argument("--download-workers", type=int, default=4)
|
| 796 |
parser.add_argument("--partition-parallel", action="store_true")
|
| 797 |
parser.add_argument("--lanes", type=int, default=1)
|
| 798 |
+
parser.add_argument(
|
| 799 |
+
"--defer-commit",
|
| 800 |
+
action="store_true",
|
| 801 |
+
help="Convert/preupload only; keep archives for later batched commits",
|
| 802 |
+
)
|
| 803 |
args = parser.parse_args()
|
| 804 |
api = HfApi(token=get_token())
|
| 805 |
for name in args.dataset or ["tts", "general"]:
|
| 806 |
recipe = dict(RECIPES[name])
|
| 807 |
+
recipe["defer_commit"] = args.defer_commit
|
| 808 |
revision, inventory = read_inventory(recipe["snapshot"])
|
| 809 |
if args.local_samples:
|
| 810 |
candidates = {
|
|
|
|
| 842 |
pinned.write_text(json.dumps(document, indent=2) + "\n")
|
| 843 |
(root / "README.md").write_text(readme(recipe, revision))
|
| 844 |
scripts = Path(__file__).resolve().parent
|
| 845 |
+
if args.upload and not args.defer_commit:
|
| 846 |
api.create_repo(
|
| 847 |
recipe["target"], repo_type="dataset", private=False, exist_ok=True
|
| 848 |
)
|
|
|
|
| 896 |
args.lanes,
|
| 897 |
)
|
| 898 |
continue
|
| 899 |
+
if args.defer_commit:
|
| 900 |
+
raise ValueError(
|
| 901 |
+
"--defer-commit requires production --upload --partition-parallel"
|
| 902 |
+
)
|
| 903 |
known = {
|
| 904 |
r[0]: bool(r[1])
|
| 905 |
for r in connection.execute("SELECT path,uploaded FROM shards")
|
finalize_release.py
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Reconcile exact source counts, global keys, and every remote bundle hash."""
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
import sqlite3
|
| 6 |
+
from collections import Counter
|
| 7 |
+
from datetime import datetime, timezone
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
from huggingface_hub import HfApi, CommitOperationAdd, get_token
|
| 11 |
+
|
| 12 |
+
from convert_release import RECIPES, readme, status_document
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def main():
|
| 16 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 17 |
+
parser.add_argument("--dataset", choices=list(RECIPES), required=True)
|
| 18 |
+
parser.add_argument(
|
| 19 |
+
"--root", type=Path, default=Path("/root/bagpiper-sft-conversion/releases")
|
| 20 |
+
)
|
| 21 |
+
args = parser.parse_args()
|
| 22 |
+
recipe = RECIPES[args.dataset]
|
| 23 |
+
root = args.root / args.dataset
|
| 24 |
+
pinned = json.loads((root / "SOURCE_MANIFEST.json").read_text())
|
| 25 |
+
inventory = pinned["shards"]
|
| 26 |
+
connection = sqlite3.connect(root / "conversion.sqlite3")
|
| 27 |
+
records = [
|
| 28 |
+
json.loads(x[0])
|
| 29 |
+
for x in connection.execute(
|
| 30 |
+
"SELECT record FROM shards WHERE uploaded=1 ORDER BY path"
|
| 31 |
+
)
|
| 32 |
+
]
|
| 33 |
+
connection.close()
|
| 34 |
+
by_path = {r["source_path"]: r for r in records}
|
| 35 |
+
assert (
|
| 36 |
+
len(by_path) == len(records) == len(inventory)
|
| 37 |
+
), "Missing/duplicate source shards"
|
| 38 |
+
assert set(by_path) == {item["path"] for item in inventory}
|
| 39 |
+
for item in inventory:
|
| 40 |
+
r = by_path[item["path"]]
|
| 41 |
+
assert r["rows"] == item["rows"] and r["source_sha256"] == item["sha256"]
|
| 42 |
+
assert r["partition"] == item["partition"]
|
| 43 |
+
assert r["source_bytes"] == item["parquet_bytes"]
|
| 44 |
+
assert sum(r["rows"] for r in records) == sum(r["rows"] for r in inventory)
|
| 45 |
+
global_db = root / "global-validation.sqlite3"
|
| 46 |
+
target = sqlite3.connect(global_db)
|
| 47 |
+
target.execute("DROP TABLE IF EXISTS ids")
|
| 48 |
+
target.execute("DROP TABLE IF EXISTS audio")
|
| 49 |
+
target.execute("CREATE TABLE ids (row_id TEXT PRIMARY KEY,partition TEXT)")
|
| 50 |
+
target.execute(
|
| 51 |
+
"CREATE TABLE audio (partition TEXT,sha TEXT,suffix TEXT,size INTEGER,PRIMARY KEY(partition,sha))"
|
| 52 |
+
)
|
| 53 |
+
state_files = []
|
| 54 |
+
if (root / "STREAM_PLAN.json").exists():
|
| 55 |
+
state_files = [
|
| 56 |
+
root / f"conversion-{s['stream_id']}.sqlite3"
|
| 57 |
+
for s in json.loads((root / "STREAM_PLAN.json").read_text())
|
| 58 |
+
]
|
| 59 |
+
else:
|
| 60 |
+
state_files = list(root.glob("conversion-*.sqlite3"))
|
| 61 |
+
for source in state_files:
|
| 62 |
+
assert source.exists(), f"Missing conversion state: {source}"
|
| 63 |
+
target.execute("ATTACH DATABASE ? AS source", (str(source),))
|
| 64 |
+
assert not target.execute(
|
| 65 |
+
"SELECT 1 FROM source.rows s JOIN ids i USING(row_id) "
|
| 66 |
+
"WHERE s.partition != i.partition LIMIT 1"
|
| 67 |
+
).fetchone(), f"Conflicting row provenance: {source}"
|
| 68 |
+
assert not target.execute(
|
| 69 |
+
"SELECT 1 FROM source.audio s JOIN audio a USING(partition,sha) "
|
| 70 |
+
"WHERE s.suffix != a.suffix OR s.size != a.size LIMIT 1"
|
| 71 |
+
).fetchone(), f"Conflicting audio filename/size across streams: {source}"
|
| 72 |
+
for path, record in target.execute("SELECT path,record FROM source.shards"):
|
| 73 |
+
assert (
|
| 74 |
+
path in by_path and json.loads(record) == by_path[path]
|
| 75 |
+
), f"Conflicting source shard state: {source}:{path}"
|
| 76 |
+
target.execute(
|
| 77 |
+
"INSERT OR IGNORE INTO ids SELECT row_id,partition FROM source.rows"
|
| 78 |
+
)
|
| 79 |
+
target.execute(
|
| 80 |
+
"INSERT OR IGNORE INTO audio SELECT partition,sha,suffix,size FROM source.audio"
|
| 81 |
+
)
|
| 82 |
+
target.commit()
|
| 83 |
+
target.execute("DETACH DATABASE source")
|
| 84 |
+
unique_ids = target.execute("SELECT count(*) FROM ids").fetchone()[0]
|
| 85 |
+
assert unique_ids == sum(
|
| 86 |
+
r["rows"] for r in records
|
| 87 |
+
), "Duplicate/missing global row IDs"
|
| 88 |
+
expected_partitions = Counter()
|
| 89 |
+
for record in inventory:
|
| 90 |
+
expected_partitions[record["partition"]] += record["rows"]
|
| 91 |
+
assert dict(
|
| 92 |
+
target.execute("SELECT partition,count(*) FROM ids GROUP BY partition")
|
| 93 |
+
) == dict(expected_partitions), "Per-partition row count mismatch"
|
| 94 |
+
audio_count, audio_bytes = target.execute(
|
| 95 |
+
"SELECT count(*),sum(size) FROM audio"
|
| 96 |
+
).fetchone()
|
| 97 |
+
partitions = {
|
| 98 |
+
p: {"rows": rows, "unique_audio": count, "audio_bytes": bytes_}
|
| 99 |
+
for p, rows, count, bytes_ in target.execute(
|
| 100 |
+
"SELECT i.partition,i.rows,a.count,a.bytes FROM (SELECT partition,count(*) rows FROM ids GROUP BY partition) i JOIN (SELECT partition,count(*) count,sum(size) bytes FROM audio GROUP BY partition) a USING(partition)"
|
| 101 |
+
)
|
| 102 |
+
}
|
| 103 |
+
target.close()
|
| 104 |
+
api = HfApi(token=get_token())
|
| 105 |
+
revision = api.repo_info(recipe["target"], repo_type="dataset").sha
|
| 106 |
+
files = list(
|
| 107 |
+
api.list_repo_tree(
|
| 108 |
+
recipe["target"], repo_type="dataset", revision=revision, recursive=True
|
| 109 |
+
)
|
| 110 |
+
)
|
| 111 |
+
bundles = {
|
| 112 |
+
f.path: f for f in files if hasattr(f, "size") and f.path.endswith(".tar.zst")
|
| 113 |
+
}
|
| 114 |
+
assert set(bundles) == {
|
| 115 |
+
r["archive_path"] for r in records
|
| 116 |
+
}, "Missing/extra remote archives"
|
| 117 |
+
for r in records:
|
| 118 |
+
f = bundles[r["archive_path"]]
|
| 119 |
+
assert (
|
| 120 |
+
f.size == r["archive_bytes"] and f.lfs.sha256 == r["archive_sha256"]
|
| 121 |
+
), f"Hash mismatch: {f.path}"
|
| 122 |
+
audit = dict(
|
| 123 |
+
state="passed",
|
| 124 |
+
completed_at=datetime.now(timezone.utc).isoformat(),
|
| 125 |
+
source_repository=recipe["source"],
|
| 126 |
+
source_revision=pinned["revision"],
|
| 127 |
+
verified_remote_revision=revision,
|
| 128 |
+
source_shards=len(inventory),
|
| 129 |
+
verified_archive_files=len(bundles),
|
| 130 |
+
source_rows=sum(x["rows"] for x in inventory),
|
| 131 |
+
unique_row_ids=unique_ids,
|
| 132 |
+
unique_audio_files=audio_count,
|
| 133 |
+
unique_audio_bytes=audio_bytes,
|
| 134 |
+
partition_statistics=partitions,
|
| 135 |
+
audio_bytes_preserved=True,
|
| 136 |
+
text_and_role_order_preserved=True,
|
| 137 |
+
checks=[
|
| 138 |
+
"All source shard paths/counts/SHA256 match pinned inventory",
|
| 139 |
+
"All global row IDs reconciled across workers",
|
| 140 |
+
"Per-partition row counts match the source; repeated hashes have consistent filenames/sizes across streams",
|
| 141 |
+
"All remote archive sizes and LFS SHA256 match conversion records",
|
| 142 |
+
"Original embedded audio SHA256 checked for every converted row; repeated hashes reuse prior validated audio",
|
| 143 |
+
],
|
| 144 |
+
limitations=[
|
| 145 |
+
"No full GPU training or inference validation",
|
| 146 |
+
"Per-shard integrity plus source/audio hashes; remote archives are verified by LFS hash, not all redownloaded",
|
| 147 |
+
"Dataset terms and paper-v1/v2 selection unchanged",
|
| 148 |
+
],
|
| 149 |
+
)
|
| 150 |
+
audit_file = root / "RELEASE_VALIDATION.json"
|
| 151 |
+
audit_file.write_text(json.dumps(audit, indent=2) + "\n")
|
| 152 |
+
status = status_document(recipe, pinned["revision"], inventory, records, "complete")
|
| 153 |
+
status["unique_audio_files"] = audio_count
|
| 154 |
+
status["unique_audio_bytes"] = audio_bytes
|
| 155 |
+
status["unique_audio_count_scope"] = "partition_and_sha256"
|
| 156 |
+
status["archive_audio_entries"] = sum(r["unique_audio_added"] for r in records)
|
| 157 |
+
status["archive_audio_bytes"] = sum(r["unique_audio_bytes_added"] for r in records)
|
| 158 |
+
status["validation"] = "RELEASE_VALIDATION.json"
|
| 159 |
+
(root / "STATUS.json").write_text(json.dumps(status, indent=2) + "\n")
|
| 160 |
+
card = readme(recipe, pinned["revision"])
|
| 161 |
+
if args.dataset == "general":
|
| 162 |
+
card = card.replace(
|
| 163 |
+
"\nEach `.tar.zst`",
|
| 164 |
+
"\n**Source selection:** this preserves the public recipe-v1 pool (including "
|
| 165 |
+
"1,193,006 understanding rows). It does not reconstruct the paper-v2 filtered selection.\n\nEach `.tar.zst`",
|
| 166 |
+
1,
|
| 167 |
+
)
|
| 168 |
+
card = card.replace(
|
| 169 |
+
"**Check `STATUS.json`: the release is usable in full only when `state` is `complete`.** An explicit prefix trial is possible while conversion is in progress.",
|
| 170 |
+
f"**Complete:** all {unique_ids:,} source rows and {len(bundles):,} shards are converted and uploaded. "
|
| 171 |
+
"[RELEASE_VALIDATION.json](./RELEASE_VALIDATION.json) records the full source/count/hash reconciliation.",
|
| 172 |
+
)
|
| 173 |
+
table = "\n## Verified release counts\n\n| Partition | Preserved rows | Distinct audio files |\n| --- | ---: | ---: |\n"
|
| 174 |
+
for partition, stats in sorted(partitions.items()):
|
| 175 |
+
table += f"| {partition} | {stats['rows']:,} | {stats['unique_audio']:,} |\n"
|
| 176 |
+
table += (
|
| 177 |
+
"\nDistinct audio counts use `(partition, SHA256)` after reconciling all conversion streams. "
|
| 178 |
+
"Archives may contain repeated files across streams; verified extraction merges them. "
|
| 179 |
+
"Every original training row remains present.\n\n"
|
| 180 |
+
"[VALIDATION.json](./VALIDATION.json) covers 3,814 original-versus-converted sample rows "
|
| 181 |
+
"across all eight partitions and 24 decoded waveform comparisons using the actual ESPnet reader. "
|
| 182 |
+
"The full release additionally checks every input shard hash, every embedded audio hash, "
|
| 183 |
+
"all row IDs, and every uploaded archive's size and LFS SHA256. GPU training and inference "
|
| 184 |
+
"have not been validated. Use `prepare_espnet.py` for local paths and manifests; "
|
| 185 |
+
"these bundles are not directly loadable with `datasets.load_dataset`.\n"
|
| 186 |
+
)
|
| 187 |
+
card = card.replace(
|
| 188 |
+
"\n## Prepare local training inputs\n",
|
| 189 |
+
table + "\n## Prepare local training inputs\n",
|
| 190 |
+
)
|
| 191 |
+
card = card.replace(
|
| 192 |
+
"For a small prefix trial, add `--max-shards 2 --allow-incomplete`.",
|
| 193 |
+
"For a small prefix trial, add `--max-shards 2`.",
|
| 194 |
+
)
|
| 195 |
+
(root / "README.md").write_text(card)
|
| 196 |
+
operations = [
|
| 197 |
+
CommitOperationAdd(path_in_repo=name, path_or_fileobj=root / name)
|
| 198 |
+
for name in ["STATUS.json", "RELEASE_VALIDATION.json", "README.md"]
|
| 199 |
+
]
|
| 200 |
+
if (root / "STREAM_PLAN.json").exists():
|
| 201 |
+
operations.append(
|
| 202 |
+
CommitOperationAdd(
|
| 203 |
+
path_in_repo="STREAM_PLAN.json",
|
| 204 |
+
path_or_fileobj=root / "STREAM_PLAN.json",
|
| 205 |
+
)
|
| 206 |
+
)
|
| 207 |
+
for name in ["STREAM_PLAN.before-rebalance.json", "REBALANCE.json"]:
|
| 208 |
+
if (root / name).exists():
|
| 209 |
+
operations.append(
|
| 210 |
+
CommitOperationAdd(path_in_repo=name, path_or_fileobj=root / name)
|
| 211 |
+
)
|
| 212 |
+
scripts = Path(__file__).resolve().parent
|
| 213 |
+
for name in [
|
| 214 |
+
"prepare_espnet.py",
|
| 215 |
+
"convert_release.py",
|
| 216 |
+
"finalize_release.py",
|
| 217 |
+
"CONVERSION.md",
|
| 218 |
+
"VALIDATION.json",
|
| 219 |
+
"test_converter.py",
|
| 220 |
+
"validate_public_release.py",
|
| 221 |
+
"PUBLIC_DOWNLOAD_VALIDATION.json",
|
| 222 |
+
"rebalance_streams.py",
|
| 223 |
+
"link_source_release.py",
|
| 224 |
+
"commit_staged_release.py",
|
| 225 |
+
"recipe-preparation.patch",
|
| 226 |
+
]:
|
| 227 |
+
operations.append(
|
| 228 |
+
CommitOperationAdd(path_in_repo=name, path_or_fileobj=scripts / name)
|
| 229 |
+
)
|
| 230 |
+
commit = api.create_commit(
|
| 231 |
+
recipe["target"],
|
| 232 |
+
repo_type="dataset",
|
| 233 |
+
operations=operations,
|
| 234 |
+
commit_message=f"Finalize verified ESPnet release: {unique_ids} unique rows, {len(bundles)} archives",
|
| 235 |
+
)
|
| 236 |
+
print(json.dumps(dict(**audit, final_commit=commit.oid), indent=2))
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
if __name__ == "__main__":
|
| 240 |
+
main()
|
link_source_release.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Add the completed ESPnet-format preparation entry to its original data card."""
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from huggingface_hub import CommitOperationAdd, HfApi, get_token, hf_hub_download
|
| 8 |
+
|
| 9 |
+
from convert_release import RECIPES
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def main():
|
| 13 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 14 |
+
parser.add_argument("--dataset", choices=list(RECIPES), required=True)
|
| 15 |
+
parser.add_argument(
|
| 16 |
+
"--root", type=Path, default=Path("/root/bagpiper-sft-conversion")
|
| 17 |
+
)
|
| 18 |
+
args = parser.parse_args()
|
| 19 |
+
recipe = RECIPES[args.dataset]
|
| 20 |
+
api = HfApi(token=get_token())
|
| 21 |
+
target_revision = api.repo_info(recipe["target"], repo_type="dataset").sha
|
| 22 |
+
status = json.loads(
|
| 23 |
+
Path(
|
| 24 |
+
hf_hub_download(
|
| 25 |
+
recipe["target"],
|
| 26 |
+
"STATUS.json",
|
| 27 |
+
repo_type="dataset",
|
| 28 |
+
revision=target_revision,
|
| 29 |
+
)
|
| 30 |
+
).read_text()
|
| 31 |
+
)
|
| 32 |
+
assert (
|
| 33 |
+
status["state"] == "complete"
|
| 34 |
+
and status.get("validation") == "RELEASE_VALIDATION.json"
|
| 35 |
+
)
|
| 36 |
+
source_revision = api.repo_info(recipe["source"], repo_type="dataset").sha
|
| 37 |
+
card = Path(
|
| 38 |
+
hf_hub_download(
|
| 39 |
+
recipe["source"], "README.md", repo_type="dataset", revision=source_revision
|
| 40 |
+
)
|
| 41 |
+
).read_text()
|
| 42 |
+
heading = "## Prepare for ESPnet training"
|
| 43 |
+
section = f"""{heading}
|
| 44 |
+
|
| 45 |
+
The complete [ESPnet-format release](https://huggingface.co/datasets/{recipe['target']})
|
| 46 |
+
preserves all {status['expected_rows']:,} source rows, ordered text turns, and original
|
| 47 |
+
encoded audio bytes. It converts this Parquet schema into three-element dialogue
|
| 48 |
+
messages and portable audio files. Source `row_id` becomes the globally unique
|
| 49 |
+
ESPnet `example_id`; repeated training examples remain present.
|
| 50 |
+
|
| 51 |
+
```bash
|
| 52 |
+
python -m pip install huggingface_hub zstandard
|
| 53 |
+
hf download {recipe['target']} prepare_espnet.py --local-dir tools
|
| 54 |
+
python tools/prepare_espnet.py \\
|
| 55 |
+
--repo-id {recipe['target']} --data-root /path/to/bagpiper-{args.dataset}-sft
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
The helper verifies archive/audio hashes, resolves local paths, and writes
|
| 59 |
+
`prepared/<partition>/{{all,train,valid}}.json` plus `dialogues.jsonl`. Add
|
| 60 |
+
`--max-shards 2` for a small trial and repeat `--partition NAME` to select
|
| 61 |
+
applications. Audio SHA256 determines the suggested 1% validation split;
|
| 62 |
+
`all.json` retains the original training pool. The split is not the paper's
|
| 63 |
+
official split. Prepare token-length statistics with the checkpoint-compatible
|
| 64 |
+
configuration as shown in the converted release's README.
|
| 65 |
+
|
| 66 |
+
See its [full release validation](https://huggingface.co/datasets/{recipe['target']}/blob/main/RELEASE_VALIDATION.json)
|
| 67 |
+
and [public download/ESPnet reader checks](https://huggingface.co/datasets/{recipe['target']}/blob/main/PUBLIC_DOWNLOAD_VALIDATION.json).
|
| 68 |
+
This conversion preserves the original source selection and applicable terms.
|
| 69 |
+
|
| 70 |
+
"""
|
| 71 |
+
if heading in card:
|
| 72 |
+
start = card.index(heading)
|
| 73 |
+
end = card.find("\n## ", start + len(heading))
|
| 74 |
+
card = card[:start] + section + (card[end + 1 :] if end >= 0 else "")
|
| 75 |
+
else:
|
| 76 |
+
marker = "## Loading the data"
|
| 77 |
+
assert marker in card
|
| 78 |
+
card = card.replace(marker, section + marker, 1)
|
| 79 |
+
output = args.root / "releases" / args.dataset / "SOURCE_README.updated.md"
|
| 80 |
+
output.write_text(card)
|
| 81 |
+
commit = api.create_commit(
|
| 82 |
+
recipe["source"],
|
| 83 |
+
repo_type="dataset",
|
| 84 |
+
parent_commit=source_revision,
|
| 85 |
+
operations=[
|
| 86 |
+
CommitOperationAdd(path_in_repo="README.md", path_or_fileobj=output)
|
| 87 |
+
],
|
| 88 |
+
commit_message="Link completed lossless ESPnet training format and preparation helper",
|
| 89 |
+
)
|
| 90 |
+
print(
|
| 91 |
+
json.dumps(
|
| 92 |
+
dict(
|
| 93 |
+
source=recipe["source"],
|
| 94 |
+
commit=commit.oid,
|
| 95 |
+
converted_revision=target_revision,
|
| 96 |
+
)
|
| 97 |
+
)
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
if __name__ == "__main__":
|
| 102 |
+
main()
|
prepare_espnet.py
CHANGED
|
@@ -89,6 +89,11 @@ def prepare_partition(root, partition, records, valid_fraction):
|
|
| 89 |
origin = json.loads(provenance_text)
|
| 90 |
if row["example_id"] != origin["row_id"]:
|
| 91 |
raise ValueError("Dialogue/provenance ID mismatch")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
connection.execute(
|
| 93 |
"INSERT INTO ids VALUES (?)", (row["example_id"],)
|
| 94 |
)
|
|
@@ -99,6 +104,14 @@ def prepare_partition(root, partition, records, valid_fraction):
|
|
| 99 |
raise ValueError(
|
| 100 |
f"Invalid relative audio path: {relative}"
|
| 101 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
path = root.joinpath(*relative.parts).resolve()
|
| 103 |
if (
|
| 104 |
not path.is_relative_to(root.resolve())
|
|
|
|
| 89 |
origin = json.loads(provenance_text)
|
| 90 |
if row["example_id"] != origin["row_id"]:
|
| 91 |
raise ValueError("Dialogue/provenance ID mismatch")
|
| 92 |
+
if (
|
| 93 |
+
origin["partition"] != partition
|
| 94 |
+
or origin["source_shard"] != record["source_path"]
|
| 95 |
+
):
|
| 96 |
+
raise ValueError("Dialogue/provenance shard mismatch")
|
| 97 |
connection.execute(
|
| 98 |
"INSERT INTO ids VALUES (?)", (row["example_id"],)
|
| 99 |
)
|
|
|
|
| 104 |
raise ValueError(
|
| 105 |
f"Invalid relative audio path: {relative}"
|
| 106 |
)
|
| 107 |
+
if (
|
| 108 |
+
str(relative) != origin["relative_audio_path"]
|
| 109 |
+
or Path(relative.name).stem
|
| 110 |
+
!= origin["audio_sha256"]
|
| 111 |
+
):
|
| 112 |
+
raise ValueError(
|
| 113 |
+
"Dialogue/provenance audio linkage mismatch"
|
| 114 |
+
)
|
| 115 |
path = root.joinpath(*relative.parts).resolve()
|
| 116 |
if (
|
| 117 |
not path.is_relative_to(root.resolve())
|
rebalance_streams.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Split only unconverted work, retaining each parent's audio and row state."""
|
| 3 |
+
import argparse
|
| 4 |
+
from collections import Counter
|
| 5 |
+
from datetime import datetime, timezone
|
| 6 |
+
import json
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
import sqlite3
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def main():
|
| 12 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 13 |
+
parser.add_argument("--root", type=Path, required=True)
|
| 14 |
+
parser.add_argument("--max-shards", type=int, default=160)
|
| 15 |
+
args = parser.parse_args()
|
| 16 |
+
root = args.root
|
| 17 |
+
plan_path = root / "STREAM_PLAN.json"
|
| 18 |
+
old_plan = json.loads(plan_path.read_text())
|
| 19 |
+
aggregate = sqlite3.connect(root / "conversion.sqlite3")
|
| 20 |
+
done = {path for (path,) in aggregate.execute("SELECT path FROM shards")}
|
| 21 |
+
aggregate.close()
|
| 22 |
+
inventory = json.loads((root / "SOURCE_MANIFEST.json").read_text())["shards"]
|
| 23 |
+
assert Counter(x for s in old_plan for x in s["paths"]) == Counter(
|
| 24 |
+
r["path"] for r in inventory
|
| 25 |
+
)
|
| 26 |
+
assert not (
|
| 27 |
+
root / "STREAM_PLAN.before-rebalance.json"
|
| 28 |
+
).exists(), "Already rebalanced"
|
| 29 |
+
new_plan = []
|
| 30 |
+
for stream in old_plan:
|
| 31 |
+
converted = [p for p in stream["paths"] if p in done]
|
| 32 |
+
remaining = [p for p in stream["paths"] if p not in done]
|
| 33 |
+
if converted:
|
| 34 |
+
new_plan.append(dict(stream, paths=converted))
|
| 35 |
+
source = sqlite3.connect(root / f"conversion-{stream['stream_id']}.sqlite3")
|
| 36 |
+
for index in range(0, len(remaining), args.max_shards):
|
| 37 |
+
name = f"{stream['stream_id']}-resume{index // args.max_shards:02}"
|
| 38 |
+
destination = root / f"conversion-{name}.sqlite3"
|
| 39 |
+
assert (
|
| 40 |
+
not destination.exists()
|
| 41 |
+
), f"Unexpected existing stream: {destination}"
|
| 42 |
+
state = sqlite3.connect(destination)
|
| 43 |
+
source.backup(state)
|
| 44 |
+
state.close()
|
| 45 |
+
new_plan.append(
|
| 46 |
+
dict(
|
| 47 |
+
partition=stream["partition"],
|
| 48 |
+
stream_id=name,
|
| 49 |
+
paths=remaining[index : index + args.max_shards],
|
| 50 |
+
parent_stream=stream["stream_id"],
|
| 51 |
+
)
|
| 52 |
+
)
|
| 53 |
+
source.close()
|
| 54 |
+
assert Counter(x for s in new_plan for x in s["paths"]) == Counter(
|
| 55 |
+
r["path"] for r in inventory
|
| 56 |
+
)
|
| 57 |
+
plan_path.replace(root / "STREAM_PLAN.before-rebalance.json")
|
| 58 |
+
plan_path.write_text(json.dumps(new_plan, indent=2) + "\n")
|
| 59 |
+
(root / "REBALANCE.json").write_text(
|
| 60 |
+
json.dumps(
|
| 61 |
+
dict(
|
| 62 |
+
created_at=datetime.now(timezone.utc).isoformat(),
|
| 63 |
+
original_streams=len(old_plan),
|
| 64 |
+
new_streams=len(new_plan),
|
| 65 |
+
completed_shards=len(done),
|
| 66 |
+
remaining_shards=len(inventory) - len(done),
|
| 67 |
+
max_shards_per_new_stream=args.max_shards,
|
| 68 |
+
state_copied_before_scheduling=True,
|
| 69 |
+
),
|
| 70 |
+
indent=2,
|
| 71 |
+
)
|
| 72 |
+
+ "\n"
|
| 73 |
+
)
|
| 74 |
+
print((root / "REBALANCE.json").read_text())
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
if __name__ == "__main__":
|
| 78 |
+
main()
|
recipe-preparation.patch
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/egs2/bagpiper/speechlm1/README.md b/egs2/bagpiper/speechlm1/README.md
|
| 2 |
+
index 0c702ddce..88cecaa1a 100644
|
| 3 |
+
--- a/egs2/bagpiper/speechlm1/README.md
|
| 4 |
+
+++ b/egs2/bagpiper/speechlm1/README.md
|
| 5 |
+
@@ -176,9 +176,42 @@ Training starts from prepared inputs:
|
| 6 |
+
- **Length statistics:** `stats_<task>_<name>.jsonl`, with one
|
| 7 |
+
`{"example_id": length}` record per line for each task/dataset combination.
|
| 8 |
+
|
| 9 |
+
-Convert Hub Parquet data into these manifests and reader inputs before training.
|
| 10 |
+
-Consult the [dataset card](https://huggingface.co/datasets/espnet/Bagpiper_SFT_Data)
|
| 11 |
+
-for its schema and current release status.
|
| 12 |
+
+The public Parquet schema requires conversion before it can be passed to the
|
| 13 |
+
+dialogue reader. A [lossless ESPnet-format release](https://huggingface.co/datasets/espnet/Bagpiper_SFT_Data_ESPnet)
|
| 14 |
+
+provides the converted audio, conversations, and a portable preparation helper:
|
| 15 |
+
+
|
| 16 |
+
+```bash
|
| 17 |
+
+python -m pip install huggingface_hub zstandard
|
| 18 |
+
+hf download espnet/Bagpiper_SFT_Data_ESPnet prepare_espnet.py --local-dir tools
|
| 19 |
+
+python tools/prepare_espnet.py \
|
| 20 |
+
+ --repo-id espnet/Bagpiper_SFT_Data_ESPnet --data-root /path/to/bagpiper-sft
|
| 21 |
+
+```
|
| 22 |
+
+
|
| 23 |
+
+Check the converted release's `STATUS.json` for `state: complete` before using
|
| 24 |
+
+the full corpus. Add `--partition generation --max-shards 2` for a small trial;
|
| 25 |
+
+an unfinished release also requires explicit `--allow-incomplete`. The helper
|
| 26 |
+
+verifies checksums, resolves audio paths, and writes
|
| 27 |
+
+`prepared/<partition>/{all,train,valid}.json` plus `dialogues.jsonl`.
|
| 28 |
+
+It preserves all source rows and audio bytes, using the globally unique source
|
| 29 |
+
+`row_id` as `example_id`. Its suggested 1% validation split is based on audio
|
| 30 |
+
+SHA256; `all.json` retains the original training pool. This is a format conversion
|
| 31 |
+
+of the released recipe-v1 data, not a selection of the paper-v2 mixture.
|
| 32 |
+
+
|
| 33 |
+
+Collect token lengths from the ESPnet repository root using the
|
| 34 |
+
+checkpoint-compatible configuration and distinct dataset names:
|
| 35 |
+
+
|
| 36 |
+
+```bash
|
| 37 |
+
+python -m espnet2.speechlm.bin.prepare_length_stats \
|
| 38 |
+
+ --train-config /path/to/checkpoint-compatible.yaml \
|
| 39 |
+
+ --train-unregistered-specifier 'dialogue:generation_train:/path/to/bagpiper-sft/prepared/generation/train.json' \
|
| 40 |
+
+ --valid-unregistered-specifier 'dialogue:generation_valid:/path/to/bagpiper-sft/prepared/generation/valid.json' \
|
| 41 |
+
+ --output-dir /path/to/sft_stats
|
| 42 |
+
+```
|
| 43 |
+
+
|
| 44 |
+
+Include corresponding `understanding` specifiers for that partition. Use these
|
| 45 |
+
+same names and manifests with the training launcher below. The
|
| 46 |
+
+[original dataset card](https://huggingface.co/datasets/espnet/Bagpiper_SFT_Data)
|
| 47 |
+
+documents provenance, source terms, and limitations.
|
| 48 |
+
|
| 49 |
+
For a dialogue dataset, the manifest names its JSONL reader input and example IDs:
|
| 50 |
+
|
| 51 |
+
diff --git a/egs2/bagpiper_tts/speechlm1/README.md b/egs2/bagpiper_tts/speechlm1/README.md
|
| 52 |
+
index 97205f7a4..055d8d2a6 100644
|
| 53 |
+
--- a/egs2/bagpiper_tts/speechlm1/README.md
|
| 54 |
+
+++ b/egs2/bagpiper_tts/speechlm1/README.md
|
| 55 |
+
@@ -185,11 +185,39 @@ The TTS training conversations have the sequence:
|
| 56 |
+
user: text request → assistant: planning + rich caption → assistant: target audio
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
-Convert the [Hub Parquet dataset](https://huggingface.co/datasets/espnet/Bagpiper_TTS_SFT_Data)
|
| 60 |
+
-into dialogue-reader inputs and manifests containing `data_entry` and `samples`;
|
| 61 |
+
-it cannot be passed directly to the trainer. Use distinct training/validation
|
| 62 |
+
-dataset names and prepare `stats_dialogue_<name>.jsonl` files. The dataset card
|
| 63 |
+
-documents its schema and current release status.
|
| 64 |
+
+The [lossless ESPnet-format release](https://huggingface.co/datasets/espnet/Bagpiper_TTS_SFT_Data_ESPnet)
|
| 65 |
+
+converts the public Parquet data into dialogue-reader inputs. Download its helper
|
| 66 |
+
+and prepare local manifests:
|
| 67 |
+
+
|
| 68 |
+
+```bash
|
| 69 |
+
+python -m pip install huggingface_hub zstandard
|
| 70 |
+
+hf download espnet/Bagpiper_TTS_SFT_Data_ESPnet prepare_espnet.py --local-dir tools
|
| 71 |
+
+python tools/prepare_espnet.py \
|
| 72 |
+
+ --repo-id espnet/Bagpiper_TTS_SFT_Data_ESPnet --data-root /path/to/bagpiper-tts-sft
|
| 73 |
+
+```
|
| 74 |
+
+
|
| 75 |
+
+The helper checks hashes and preserves every row, text turn, and original audio
|
| 76 |
+
+byte. It writes `prepared/<partition>/{all,train,valid}.json` and
|
| 77 |
+
+`dialogues.jsonl` for all six applications, using source `row_id` as the globally
|
| 78 |
+
+unique example ID. The suggested 1% validation split is determined by audio
|
| 79 |
+
+SHA256; `all.json` retains the original training pool. Add
|
| 80 |
+
+`--partition classical_tts --max-shards 2` for a small trial.
|
| 81 |
+
+
|
| 82 |
+
+From the ESPnet repository root, prepare exact token lengths with the
|
| 83 |
+
+checkpoint-compatible configuration:
|
| 84 |
+
+
|
| 85 |
+
+```bash
|
| 86 |
+
+python -m espnet2.speechlm.bin.prepare_length_stats \
|
| 87 |
+
+ --train-config /path/to/checkpoint-compatible.yaml \
|
| 88 |
+
+ --train-unregistered-specifier 'dialogue:classical_tts_train:/path/to/bagpiper-tts-sft/prepared/classical_tts/train.json' \
|
| 89 |
+
+ --valid-unregistered-specifier 'dialogue:classical_tts_valid:/path/to/bagpiper-tts-sft/prepared/classical_tts/valid.json' \
|
| 90 |
+
+ --output-dir /path/to/tts_stats
|
| 91 |
+
+```
|
| 92 |
+
+
|
| 93 |
+
+Add specifiers with distinct names for the other applications and use the same
|
| 94 |
+
+names/manifests when launching training. The
|
| 95 |
+
+[original dataset card](https://huggingface.co/datasets/espnet/Bagpiper_TTS_SFT_Data)
|
| 96 |
+
+documents provenance and source terms.
|
| 97 |
+
|
| 98 |
+
### Recipe defaults
|
| 99 |
+
|
test_converter.py
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io
|
| 2 |
+
import hashlib
|
| 3 |
+
import json
|
| 4 |
+
import sqlite3
|
| 5 |
+
import wave
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
import pyarrow as pa
|
| 9 |
+
import pyarrow.parquet as pq
|
| 10 |
+
import pytest
|
| 11 |
+
|
| 12 |
+
import convert_release as converter
|
| 13 |
+
from prepare_espnet import digest, safe_extract
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def create_audio():
|
| 17 |
+
out = io.BytesIO()
|
| 18 |
+
with wave.open(out, "wb") as wav:
|
| 19 |
+
wav.setnchannels(1)
|
| 20 |
+
wav.setsampwidth(2)
|
| 21 |
+
wav.setframerate(8000)
|
| 22 |
+
wav.writeframes(bytes(160))
|
| 23 |
+
return out.getvalue()
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def make_source(root, partition, index, ids):
|
| 27 |
+
path = root / f"{partition}/train-{index:05}.parquet"
|
| 28 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 29 |
+
audio = create_audio()
|
| 30 |
+
sha = hashlib.sha256(audio).hexdigest()
|
| 31 |
+
rows = [
|
| 32 |
+
dict(
|
| 33 |
+
row_id=key,
|
| 34 |
+
example_id="same-local-id",
|
| 35 |
+
partition=partition,
|
| 36 |
+
source_revision="source-revision",
|
| 37 |
+
audio={"bytes": audio, "path": "display.wav"},
|
| 38 |
+
audio_bytes=len(audio),
|
| 39 |
+
audio_sha256=sha,
|
| 40 |
+
audio_format="wav",
|
| 41 |
+
messages=[
|
| 42 |
+
dict(
|
| 43 |
+
role="user",
|
| 44 |
+
modality="text",
|
| 45 |
+
content="unchanged\ntext",
|
| 46 |
+
audio_index=-1,
|
| 47 |
+
),
|
| 48 |
+
dict(
|
| 49 |
+
role="assistant",
|
| 50 |
+
modality="audio",
|
| 51 |
+
content="display.wav",
|
| 52 |
+
audio_index=0,
|
| 53 |
+
),
|
| 54 |
+
],
|
| 55 |
+
)
|
| 56 |
+
for key in ids
|
| 57 |
+
]
|
| 58 |
+
pq.write_table(pa.Table.from_pylist(rows), path)
|
| 59 |
+
return path, dict(
|
| 60 |
+
path=str(path.relative_to(root)),
|
| 61 |
+
partition=partition,
|
| 62 |
+
rows=len(rows),
|
| 63 |
+
sha256=digest(path),
|
| 64 |
+
parquet_bytes=path.stat().st_size,
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def test_cross_shard_dedup_and_transaction_rollback(tmp_path):
|
| 69 |
+
state = converter.open_database(tmp_path / "state.sqlite3")
|
| 70 |
+
first, one = make_source(
|
| 71 |
+
tmp_path / "sources", "generation", 0, ["source:a", "source:b"]
|
| 72 |
+
)
|
| 73 |
+
second, two = make_source(tmp_path / "sources", "generation", 1, ["source:c"])
|
| 74 |
+
r1 = converter.convert_shard(
|
| 75 |
+
first, one, tmp_path / "output", state, "repo", "revision"
|
| 76 |
+
)
|
| 77 |
+
r2 = converter.convert_shard(
|
| 78 |
+
second, two, tmp_path / "output", state, "repo", "revision"
|
| 79 |
+
)
|
| 80 |
+
assert r1["unique_audio_added"] == 1 and r2["unique_audio_added"] == 0
|
| 81 |
+
for r in [r1, r2]:
|
| 82 |
+
safe_extract(tmp_path / "output" / r["archive_path"], tmp_path / "relocated")
|
| 83 |
+
dialogues = [
|
| 84 |
+
json.loads(l)
|
| 85 |
+
for r in [r1, r2]
|
| 86 |
+
for l in (tmp_path / "relocated" / r["dialogue_path"]).read_text().splitlines()
|
| 87 |
+
]
|
| 88 |
+
assert [x["example_id"] for x in dialogues] == ["source:a", "source:b", "source:c"]
|
| 89 |
+
assert len({x["messages"][1][2] for x in dialogues}) == 1
|
| 90 |
+
assert dialogues[0]["messages"][0][2] == "unchanged\ntext"
|
| 91 |
+
assert (
|
| 92 |
+
tmp_path / "relocated" / dialogues[-1]["messages"][1][2]
|
| 93 |
+
).read_bytes() == create_audio()
|
| 94 |
+
bad, inventory = make_source(
|
| 95 |
+
tmp_path / "sources", "generation", 2, ["new-id", "source:a"]
|
| 96 |
+
)
|
| 97 |
+
with pytest.raises(sqlite3.IntegrityError):
|
| 98 |
+
converter.convert_shard(
|
| 99 |
+
bad, inventory, tmp_path / "output", state, "repo", "revision"
|
| 100 |
+
)
|
| 101 |
+
assert (
|
| 102 |
+
state.execute("SELECT count(*) FROM rows WHERE row_id='new-id'").fetchone()[0]
|
| 103 |
+
== 0
|
| 104 |
+
)
|
| 105 |
+
assert state.execute("SELECT count(*) FROM shards").fetchone()[0] == 2
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def test_parallel_partitions_resume_local_and_aggregate_state(tmp_path, monkeypatch):
|
| 109 |
+
source = tmp_path / "sources"
|
| 110 |
+
root = tmp_path / "release"
|
| 111 |
+
root.mkdir()
|
| 112 |
+
inventory = []
|
| 113 |
+
for partition in ["generation", "understanding"]:
|
| 114 |
+
for index in range(2):
|
| 115 |
+
_, record = make_source(source, partition, index, [f"{partition}:{index}"])
|
| 116 |
+
inventory.append(record)
|
| 117 |
+
converter.open_database(root / "conversion.sqlite3").close()
|
| 118 |
+
monkeypatch.setattr(
|
| 119 |
+
converter,
|
| 120 |
+
"download_shard",
|
| 121 |
+
lambda repo, revision, item, root, local_source: (source / item["path"], False),
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
def fake_upload(api, recipe, revision, full_inventory, records, previous):
|
| 125 |
+
connection = sqlite3.connect(root / "conversion.sqlite3", timeout=120)
|
| 126 |
+
for r in records:
|
| 127 |
+
connection.execute(
|
| 128 |
+
"UPDATE shards SET uploaded=1 WHERE path=?", (r["source_path"],)
|
| 129 |
+
)
|
| 130 |
+
connection.commit()
|
| 131 |
+
connection.close()
|
| 132 |
+
return "mock-remote-verified"
|
| 133 |
+
|
| 134 |
+
monkeypatch.setattr(converter, "upload_batch", fake_upload)
|
| 135 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 136 |
+
|
| 137 |
+
recipe = dict(root=str(root), source="repo", target="target", snapshot="sft_data")
|
| 138 |
+
with ThreadPoolExecutor(max_workers=2) as pool:
|
| 139 |
+
results = [
|
| 140 |
+
pool.submit(
|
| 141 |
+
converter.convert_partition, recipe, "revision", inventory, p, 2, 2
|
| 142 |
+
)
|
| 143 |
+
for p in ["generation", "understanding"]
|
| 144 |
+
]
|
| 145 |
+
assert {r.result() for r in results} == {"generation", "understanding"}
|
| 146 |
+
connection = sqlite3.connect(root / "conversion.sqlite3")
|
| 147 |
+
assert (
|
| 148 |
+
connection.execute("SELECT count(*) FROM shards WHERE uploaded=1").fetchone()[0]
|
| 149 |
+
== 4
|
| 150 |
+
)
|
| 151 |
+
for p in ["generation", "understanding"]:
|
| 152 |
+
converter.convert_partition(recipe, "revision", inventory, p, 2, 2)
|
| 153 |
+
local = sqlite3.connect(root / f"conversion-{p}.sqlite3")
|
| 154 |
+
assert local.execute("SELECT count(*) FROM audio").fetchone()[0] == 1
|
| 155 |
+
assert (
|
| 156 |
+
local.execute("SELECT count(*) FROM shards WHERE uploaded=1").fetchone()[0]
|
| 157 |
+
== 2
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def test_rebalanced_streams_retain_parent_audio_dependencies(tmp_path, monkeypatch):
|
| 162 |
+
import rebalance_streams
|
| 163 |
+
import sys
|
| 164 |
+
|
| 165 |
+
root = tmp_path / "release"
|
| 166 |
+
root.mkdir()
|
| 167 |
+
inventory = []
|
| 168 |
+
for index in range(3):
|
| 169 |
+
_, item = make_source(
|
| 170 |
+
tmp_path / "sources", "generation", index, [f"row:{index}"]
|
| 171 |
+
)
|
| 172 |
+
inventory.append(item)
|
| 173 |
+
state = converter.open_database(root / "conversion-generation-lane00.sqlite3")
|
| 174 |
+
first = converter.convert_shard(
|
| 175 |
+
tmp_path / "sources" / inventory[0]["path"],
|
| 176 |
+
inventory[0],
|
| 177 |
+
root,
|
| 178 |
+
state,
|
| 179 |
+
"repo",
|
| 180 |
+
"revision",
|
| 181 |
+
)
|
| 182 |
+
state.close()
|
| 183 |
+
aggregate = converter.open_database(root / "conversion.sqlite3")
|
| 184 |
+
aggregate.execute(
|
| 185 |
+
"INSERT INTO shards VALUES (?,?,1)", (first["source_path"], json.dumps(first))
|
| 186 |
+
)
|
| 187 |
+
aggregate.commit()
|
| 188 |
+
aggregate.close()
|
| 189 |
+
(root / "SOURCE_MANIFEST.json").write_text(json.dumps(dict(shards=inventory)))
|
| 190 |
+
(root / "STREAM_PLAN.json").write_text(
|
| 191 |
+
json.dumps(
|
| 192 |
+
[
|
| 193 |
+
dict(
|
| 194 |
+
partition="generation",
|
| 195 |
+
stream_id="generation-lane00",
|
| 196 |
+
paths=[x["path"] for x in inventory],
|
| 197 |
+
)
|
| 198 |
+
]
|
| 199 |
+
)
|
| 200 |
+
)
|
| 201 |
+
monkeypatch.setattr(
|
| 202 |
+
sys, "argv", ["rebalance_streams.py", "--root", str(root), "--max-shards", "1"]
|
| 203 |
+
)
|
| 204 |
+
rebalance_streams.main()
|
| 205 |
+
plan = json.loads((root / "STREAM_PLAN.json").read_text())
|
| 206 |
+
assert [x for s in plan for x in s["paths"]] == [x["path"] for x in inventory]
|
| 207 |
+
records = [first]
|
| 208 |
+
for stream, item in zip(plan[1:], inventory[1:]):
|
| 209 |
+
state = converter.open_database(
|
| 210 |
+
root / f"conversion-{stream['stream_id']}.sqlite3"
|
| 211 |
+
)
|
| 212 |
+
assert state.execute("SELECT count(*) FROM rows").fetchone()[0] == 1
|
| 213 |
+
record = converter.convert_shard(
|
| 214 |
+
tmp_path / "sources" / item["path"], item, root, state, "repo", "revision"
|
| 215 |
+
)
|
| 216 |
+
assert record["unique_audio_added"] == 0
|
| 217 |
+
records.append(record)
|
| 218 |
+
state.close()
|
| 219 |
+
for record in records:
|
| 220 |
+
safe_extract(root / record["archive_path"], tmp_path / "relocated")
|
| 221 |
+
output = json.loads(
|
| 222 |
+
(tmp_path / "relocated" / record["dialogue_path"]).read_text()
|
| 223 |
+
)
|
| 224 |
+
assert (
|
| 225 |
+
tmp_path / "relocated" / output["messages"][1][2]
|
| 226 |
+
).read_bytes() == create_audio()
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
@pytest.mark.parametrize("failure_phase", ["commit", "verify", "status"])
|
| 230 |
+
def test_upload_retry_does_not_reuse_committed_operations(
|
| 231 |
+
tmp_path, monkeypatch, failure_phase
|
| 232 |
+
):
|
| 233 |
+
from types import SimpleNamespace
|
| 234 |
+
|
| 235 |
+
source, inventory = make_source(tmp_path / "source", "generation", 0, ["row:0"])
|
| 236 |
+
state = converter.open_database(tmp_path / "conversion.sqlite3")
|
| 237 |
+
record = converter.convert_shard(
|
| 238 |
+
source, inventory, tmp_path, state, "repo", "revision"
|
| 239 |
+
)
|
| 240 |
+
state.close()
|
| 241 |
+
|
| 242 |
+
monkeypatch.setattr(converter.time, "sleep", lambda _: None)
|
| 243 |
+
|
| 244 |
+
class Api:
|
| 245 |
+
def __init__(self):
|
| 246 |
+
self.commits = 0
|
| 247 |
+
self.verifications = 0
|
| 248 |
+
self.status_updates = 0
|
| 249 |
+
self.operation_ids = set()
|
| 250 |
+
|
| 251 |
+
def preupload_lfs_files(self, *args, additions, **kwargs):
|
| 252 |
+
for operation in additions:
|
| 253 |
+
assert id(operation) not in self.operation_ids
|
| 254 |
+
self.operation_ids.add(id(operation))
|
| 255 |
+
|
| 256 |
+
def create_commit(self, *args, operations, **kwargs):
|
| 257 |
+
self.commits += 1
|
| 258 |
+
for operation in operations:
|
| 259 |
+
operation.path_or_fileobj = b""
|
| 260 |
+
if failure_phase == "commit" and self.commits == 1:
|
| 261 |
+
raise ConnectionError("Commit response unavailable")
|
| 262 |
+
return SimpleNamespace(oid="committed-revision")
|
| 263 |
+
|
| 264 |
+
def get_paths_info(self, *args, **kwargs):
|
| 265 |
+
self.verifications += 1
|
| 266 |
+
if failure_phase == "verify" and self.verifications == 1:
|
| 267 |
+
raise ConnectionError("Transient verification failure")
|
| 268 |
+
return [
|
| 269 |
+
SimpleNamespace(
|
| 270 |
+
path=record["archive_path"],
|
| 271 |
+
size=record["archive_bytes"],
|
| 272 |
+
lfs=SimpleNamespace(sha256=record["archive_sha256"]),
|
| 273 |
+
)
|
| 274 |
+
]
|
| 275 |
+
|
| 276 |
+
def upload_file(self, *args, **kwargs):
|
| 277 |
+
self.status_updates += 1
|
| 278 |
+
if failure_phase == "status" and self.status_updates == 1:
|
| 279 |
+
raise ConnectionError("Transient status failure")
|
| 280 |
+
|
| 281 |
+
api = Api()
|
| 282 |
+
result = converter.upload_batch(
|
| 283 |
+
api,
|
| 284 |
+
dict(root=str(tmp_path), target="repo", source="source", parallel=True),
|
| 285 |
+
"revision",
|
| 286 |
+
[inventory],
|
| 287 |
+
[record],
|
| 288 |
+
[],
|
| 289 |
+
)
|
| 290 |
+
assert result == "committed-revision"
|
| 291 |
+
assert api.commits == (2 if failure_phase == "commit" else 1)
|
| 292 |
+
state = sqlite3.connect(tmp_path / "conversion.sqlite3")
|
| 293 |
+
assert state.execute("SELECT uploaded FROM shards").fetchone()[0] == 1
|
| 294 |
+
state.close()
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
def test_staged_conversion_keeps_archives_uncommitted(tmp_path, monkeypatch):
|
| 298 |
+
source = tmp_path / "source"
|
| 299 |
+
root = tmp_path / "release"
|
| 300 |
+
root.mkdir()
|
| 301 |
+
inventory = [
|
| 302 |
+
make_source(source, "generation", i, [f"row:{i}"])[1] for i in range(2)
|
| 303 |
+
]
|
| 304 |
+
converter.open_database(root / "conversion.sqlite3").close()
|
| 305 |
+
monkeypatch.setattr(
|
| 306 |
+
converter,
|
| 307 |
+
"download_shard",
|
| 308 |
+
lambda repo, revision, item, root, local_source: (source / item["path"], False),
|
| 309 |
+
)
|
| 310 |
+
uploaded = []
|
| 311 |
+
|
| 312 |
+
class Api:
|
| 313 |
+
def preupload_lfs_files(self, *args, additions, **kwargs):
|
| 314 |
+
uploaded.extend(op.path_in_repo for op in additions)
|
| 315 |
+
|
| 316 |
+
monkeypatch.setattr(converter, "HfApi", lambda **kwargs: Api())
|
| 317 |
+
recipe = dict(
|
| 318 |
+
root=str(root),
|
| 319 |
+
source="source",
|
| 320 |
+
target="target",
|
| 321 |
+
snapshot="sft_data",
|
| 322 |
+
defer_commit=True,
|
| 323 |
+
)
|
| 324 |
+
converter.convert_partition(recipe, "revision", inventory, "generation", 2, 2)
|
| 325 |
+
state = sqlite3.connect(root / "conversion.sqlite3")
|
| 326 |
+
records = [
|
| 327 |
+
json.loads(r)
|
| 328 |
+
for r, in state.execute("SELECT record FROM shards WHERE uploaded=0")
|
| 329 |
+
]
|
| 330 |
+
assert len(records) == 2 and len(uploaded) == 2
|
| 331 |
+
assert all((root / r["archive_path"]).exists() for r in records)
|
| 332 |
+
staged = sqlite3.connect(root / "preuploads.sqlite3")
|
| 333 |
+
assert staged.execute("SELECT count(*) FROM blobs").fetchone()[0] == 2
|
| 334 |
+
converter.convert_partition(recipe, "revision", inventory, "generation", 2, 2)
|
| 335 |
+
assert len(uploaded) == 2
|
validate_public_release.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Compare prepared public bundles with source rows and the actual ESPnet reader."""
|
| 3 |
+
import argparse
|
| 4 |
+
import hashlib
|
| 5 |
+
import io
|
| 6 |
+
import json
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
import sys
|
| 9 |
+
|
| 10 |
+
import numpy as np
|
| 11 |
+
import pyarrow.parquet as pq
|
| 12 |
+
import soundfile as sf
|
| 13 |
+
|
| 14 |
+
from prepare_espnet import split_for_hash
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def main():
|
| 18 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 19 |
+
parser.add_argument(
|
| 20 |
+
"--root", type=Path, default=Path("/root/bagpiper-sft-conversion")
|
| 21 |
+
)
|
| 22 |
+
parser.add_argument(
|
| 23 |
+
"--espnet", type=Path, default=Path("/root/bagpiper-release-audit/espnet")
|
| 24 |
+
)
|
| 25 |
+
args = parser.parse_args()
|
| 26 |
+
sys.path.insert(0, str(args.espnet))
|
| 27 |
+
from espnet2.speechlm.dataloader.dataset import SingleDataset
|
| 28 |
+
|
| 29 |
+
report = []
|
| 30 |
+
for folder, dataset, snapshot, partition, shards in [
|
| 31 |
+
("tts", "tts", "general_tts_data", "classical_tts", 1),
|
| 32 |
+
("tts2", "tts", "general_tts_data", "intent_to_speech", 1),
|
| 33 |
+
("general", "general", "sft_data", "generation", 2),
|
| 34 |
+
("understanding", "general", "sft_data", "understanding", 2),
|
| 35 |
+
]:
|
| 36 |
+
root = args.root / "remote-trial" / folder
|
| 37 |
+
preparation = json.loads((root / "PREPARATION.json").read_text())
|
| 38 |
+
status = json.loads(
|
| 39 |
+
(args.root / "releases" / dataset / "SOURCE_MANIFEST.json").read_text()
|
| 40 |
+
)
|
| 41 |
+
records = [r for r in status["shards"] if r["partition"] == partition][:shards]
|
| 42 |
+
prepared = root / "prepared" / partition
|
| 43 |
+
native = SingleDataset(str(prepared / "all.json"))
|
| 44 |
+
converted = [
|
| 45 |
+
json.loads(line)
|
| 46 |
+
for line in (prepared / "dialogues.jsonl").read_text().splitlines()
|
| 47 |
+
]
|
| 48 |
+
originals = []
|
| 49 |
+
for record in records:
|
| 50 |
+
path = (
|
| 51 |
+
Path("/root/bagpiper-release-audit/sample-shards")
|
| 52 |
+
/ snapshot
|
| 53 |
+
/ record["path"]
|
| 54 |
+
)
|
| 55 |
+
if not path.exists():
|
| 56 |
+
from convert_release import download_shard
|
| 57 |
+
|
| 58 |
+
path, _ = download_shard(
|
| 59 |
+
status["source_repository"],
|
| 60 |
+
status["revision"],
|
| 61 |
+
record,
|
| 62 |
+
args.root / "public-validation-sources" / dataset,
|
| 63 |
+
)
|
| 64 |
+
assert hashlib.sha256(path.read_bytes()).hexdigest() == record["sha256"]
|
| 65 |
+
originals.extend(pq.read_table(path).to_pylist())
|
| 66 |
+
assert len(native) == len(converted) == len(originals)
|
| 67 |
+
train = set(json.loads((prepared / "train.json").read_text())["samples"])
|
| 68 |
+
valid = set(json.loads((prepared / "valid.json").read_text())["samples"])
|
| 69 |
+
assert not train & valid
|
| 70 |
+
assert train | valid == set(native.sample_ids)
|
| 71 |
+
audio_hashes = {"train": set(), "valid": set()}
|
| 72 |
+
for original, output in zip(originals, converted):
|
| 73 |
+
assert output["example_id"] == original["row_id"]
|
| 74 |
+
assert len(output["messages"]) == len(original["messages"])
|
| 75 |
+
for before, after in zip(original["messages"], output["messages"]):
|
| 76 |
+
assert after[:2] == [before["role"], before["modality"]]
|
| 77 |
+
if before["modality"] == "text":
|
| 78 |
+
assert after[2] == before["content"]
|
| 79 |
+
else:
|
| 80 |
+
assert Path(after[2]).read_bytes() == original["audio"]["bytes"]
|
| 81 |
+
split = "train" if original["row_id"] in train else "valid"
|
| 82 |
+
assert split == split_for_hash(original["audio_sha256"])
|
| 83 |
+
audio_hashes[split].add(original["audio_sha256"])
|
| 84 |
+
assert not audio_hashes["train"] & audio_hashes["valid"]
|
| 85 |
+
decoded = 0
|
| 86 |
+
for index in sorted({0, len(originals) // 2, len(originals) - 1}):
|
| 87 |
+
original = originals[index]
|
| 88 |
+
for role, modality, content in native[original["row_id"]]["dialogue"]:
|
| 89 |
+
if modality == "audio":
|
| 90 |
+
waveform, rate = content
|
| 91 |
+
expected, expected_rate = sf.read(
|
| 92 |
+
io.BytesIO(original["audio"]["bytes"]),
|
| 93 |
+
dtype="float32",
|
| 94 |
+
always_2d=True,
|
| 95 |
+
)
|
| 96 |
+
assert rate == expected_rate == original["sample_rate"]
|
| 97 |
+
np.testing.assert_array_equal(waveform, expected.T)
|
| 98 |
+
decoded += 1
|
| 99 |
+
report.append(
|
| 100 |
+
dict(
|
| 101 |
+
repository=preparation["repo_id"],
|
| 102 |
+
revision=preparation["revision"],
|
| 103 |
+
partition=partition,
|
| 104 |
+
rows=len(originals),
|
| 105 |
+
decoded_waveforms=decoded,
|
| 106 |
+
preserved_text_order_audio=True,
|
| 107 |
+
disjoint_train_valid_audio=True,
|
| 108 |
+
)
|
| 109 |
+
)
|
| 110 |
+
result = dict(
|
| 111 |
+
state="passed",
|
| 112 |
+
checks=report,
|
| 113 |
+
total_rows=sum(r["rows"] for r in report),
|
| 114 |
+
decoded_waveforms=sum(r["decoded_waveforms"] for r in report),
|
| 115 |
+
limitations=["CPU reader verification; no GPU training or inference"],
|
| 116 |
+
)
|
| 117 |
+
(args.root / "PUBLIC_DOWNLOAD_VALIDATION.json").write_text(
|
| 118 |
+
json.dumps(result, indent=2) + "\n"
|
| 119 |
+
)
|
| 120 |
+
print(json.dumps(result, indent=2))
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
if __name__ == "__main__":
|
| 124 |
+
main()
|