Repository navigation
Studio: fetch ShareGPT+image row images concurrently, in row order - #15786
Conversation
…filename downloads [skip ci]
|
@codex review |
Codex Review SummaryThis 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. |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ 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 |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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". |
…hai#15870) ## What changes For a vision dataset whose image column holds URLs and has more than 200 rows, `convert_to_vlm_format` first probes the first 200 URLs to estimate throughput and the broken-link rate, discards the results, and then the conversion loop downloads and decodes those same 200 images again. The probe now keeps each image it downloaded successfully, keyed by row, and the first conversion batch uses it instead of fetching the URL again. Everything else stays as it was: - A URL whose probe download failed is not cached. The conversion retries it exactly as before, so a transient failure in the probe can still succeed. - The rest of each row's conversion (instruction, caption, `random.choice` for list captions) still runs in both passes, so the number of draws from the global RNG is the same as before. - Converted rows, their order, `failed_count`, the fail-rate gate, the ETA text and the progress messages are all unchanged. - Each cached image is popped when the first batch uses it. Main already kept the 200 probe results (images included) alive through its `futures` dict until the first batch started, and the finished list holds every converted image anyway, so peak memory does not grow. - One behaviour does differ: a URL whose content changes in the seconds between the probe and the first batch is now converted from the probe's download, where main used its second download. Either copy is a snapshot of the same row taken seconds apart, and the row is still downloaded through the same fetch path with the same checks. ## Results I ran a local HTTP server that serves 64x64 JPEGs, returns 404 for every 11th row, and counts GET requests. Each arm ran 3 times. | rows | GETs before | GETs after | converted | output sha256 (texts + pixel bytes) | progress messages | |---|---|---|---|---|---| | 450 | 650 | 469 | 409 / 409 | identical | identical | | 1200 | 1400 | 1219 | 1090 / 1090 | identical | identical | After the change, the GET count is the row count plus the probe rows that failed and get retried. Before the change it was the row count plus 200. Both counts were identical across all repeats. On loopback the wall time is inside run-to-run noise. The saving shows up on real remote URLs: about 200 downloads per dataset, or roughly 200 / (probe throughput) seconds. ## Tests - New `studio/backend/tests/test_vlm_probe_reuses_downloads.py` with 450 and 1200 rows, permanent and transient probe failures. It checks per-URL fetch counts, that transiently failed probe rows still convert, and the captions and pixels of every kept row. It fails before this change (probe rows are fetched twice) and passes after it. - The neighbouring VLM tests (`test_vlm_conversion_row_urls`, `test_vlm_null_caption_rows`, `test_vlm_probe_untrusted_rows`, `test_vlm_question_column`, `test_vlm_repo_relative_image_paths`, `test_vlm_text_only_rows`) give 72 passed both before and after. - `py_compile` passes on Python 3.9 and 3.10. ## Not covered - I did not time it against real remote image hosts. The evidence is the request count plus output parity. - Datasets with 200 rows or fewer skip the probe and are unaffected. - `convert_sharegpt_with_images_to_vlm_format` and `convert_llava_to_vlm_format` have no URL probe, so there was nothing to change there. - Merges cleanly with the open unslothai#15786 (ShareGPT image rows fetched concurrently) and unslothai#15787 (null image or caption rows found from Arrow validity); with all three applied, their tests and this one pass together (26 passed).
#15992) ## Summary `studio/backend/tests/test_sharegpt_image_parallel_fetch.py::test_local_only_dataset_starts_no_threads` (added in #15786) fails whenever it is the first test in its process to create a `tqdm` bar, and passes otherwise. Seen on the `(Python 3.13, rest)` backend shard for #15934, which does not touch this code: ``` tests/test_sharegpt_image_parallel_fetch.py:173: in test_local_only_dataset_starts_no_threads E assert [1] == [] ``` Run on its own it fails every time on main (`pytest tests/test_sharegpt_image_parallel_fetch.py::test_local_only_dataset_starts_no_threads`). The one thread is tqdm's `TMonitor`: `tqdm.__new__` starts it for the first bar in a process (unless `monitor_interval` is 0), and the conversion's progress bar is that first bar when nothing earlier in the xdist worker made one. The product does what the test means to check (a local-only dataset takes the serial path and starts no fetch workers); the test counted a process-global helper as a worker. ## What changed The test sets `tqdm.std.tqdm.monitor_interval = 0` through `monkeypatch` before counting, so the process-wide `Thread.__init__` count and the `active_count()` check stay as strict as before and only the monitor is out of the picture. ## Verification - Base (main): the test alone fails with `assert [1] == []`. - Head: alone 1 passed; whole file 9 passed. - With the serial branch in `convert_sharegpt_with_images_to_vlm_format` forced onto the thread pool (`if num_workers <= 1:` changed to `if False:`), the test fails again with `assert [1] == []`, so it still catches a local-only dataset starting fetch workers.
…in order (unslothai#17029) In image + text datasets, the image column sometimes holds bare file names (`0001.jpg`, `images/0001.jpg`) that point at files in the dataset repo. `convert_to_vlm_format` resolved those with one `hf_hub_download` per row, one row at a time, before training could start. Each call is at least one Hub request (a HEAD even when the file is cached, since no revision is pinned), so 10k rows meant 10k sequential round trips. unslothai#15786 already moved the ShareGPT + image converter onto an in-order pool for the same case. This converter's image + text path was still serial. ## Change For rows whose image is a repo file name, the download and decode run on a thread pool: `min(safe_thread_num_proc(), 8)` workers, the same cap as the ShareGPT converter. Rows are still settled in row order on the calling thread, so the converted list, the `random.choice` pick for list captions, the failure count and the first-failure log line are the same as before. At most 2x workers images are held while waiting. Each task runs in a copy of the caller's context, so the fetch sees the same account and HF cache settings. Rows with local paths, URLs or embedded images are unchanged, and URL datasets keep their own probe-and-batch path. Both converters now share one `_settle_in_order` helper (bounded in-order pool, context copy per task, queued tasks cancelled on interrupt), replacing the ShareGPT converter's inline copy. Net change in `format_conversion.py`: about 40 lines added, 60 removed. ## Results (200 rows, fake Hub with 100 ms per download, 3 alternating runs per side) | | main | this branch | | --- | --- | --- | | `convert_to_vlm_format` | 20.31 to 20.48 s | 2.58 to 2.67 s | | converted rows / output digest | 199 / same | 199 / same | | fetches issued before a Ctrl-C on row 20 stops it | 21 | 31 (queued ones cancelled, no leftover threads) | The gain scales with the per-request latency and the worker count (8 here). ## Tests - New `tests/test_vlm_repo_image_fetch_pool.py`. 48 rows that mix repo-relative and bare names, list captions picked with a fixed seed, and one download that fails: the pooled output equals the serial output, in the same order with the same captions. The same files are fetched, and more than one fetch runs at a time. It fails on main, because fetches run one at a time there. - `tests/test_vlm_*.py` + `tests/test_sharegpt_*.py`: 119 passed (ShareGPT pool tests unchanged and green on the shared helper).
What changes
convert_sharegpt_with_images_to_vlm_formatresolved every row image one at a time, so a ShareGPT+image dataset whose image column holds URLs or bare repo filenames (onehf_hub_downloadper row) waited on the network once per row.When the first row's image needs the network (an
http(s)://URL, or a bare filename found in the repo lookup), rows are now converted on a thread pool ofmin(safe_thread_num_proc(), 8)workers. 8 is the default ofhuggingface_hub's ownsnapshot_download, and lower than the uncappedsafe_thread_num_proc()countconvert_to_vlm_formatalready uses for URL rows, so a many core host does not open dozens of connections to one host.2 * workersrows are in flight or waiting their turn, which bounds the decoded images held in memory.contextvars): the account context var is not inherited by new threads, so this keeps the fetch acting for the caller's account and HF cache settings.Exceptionstill propagates; pending fetches are cancelled on the way out.Results
Fake fetch with 50 ms latency, 200 URL rows, 6 failing, 8 workers, fresh process per run, arms interleaved, 6 runs each:
Real network, 48 image URLs from a public Hugging Face dataset through the real guarded fetcher (base, head, head, base): 17.8 s / 2.4 s / 3.1 s / 16.6 s, identical digest. The digest covers every converted row's text and image pixels.
Tests
studio/backend/tests/test_sharegpt_image_parallel_fetch.py:hf_hub_download. Fails on main, passes here.ValueError; fetches see the caller's context variables; mixed local and URL rows keep row order; a local only dataset creates no threads; a row missing the image key is skipped, not raised. Pass on both.tests/test_vlm_conversion_row_urls.pypasses on both arms. Staging CI on ubuntu-latest, macos-15 and windows-latest is green.