Skip to content

Studio: find VLM rows without an image or caption from Arrow validity - #15787

Merged
danielhanchen merged 4 commits into
mainfrom
perf/vlm-null-rows
Oct 29, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
perf/vlm-null-rows

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

What changes

Before converting, convert_to_vlm_format drops rows whose image URL or caption is None. It found them by reading the whole column as Python objects (dataset[column]), which costs about 0.7 s per 100k rows per column, even when nothing is null.

_non_null_rows now reads the column's Arrow validity instead: no nulls returns at once; otherwise the valid positions come from pyarrow.compute.is_valid, in row order and respecting select / shuffle / filter index mappings. The selected rows, the select call (same Python int list), and the "Skipping N/M rows" log lines are unchanged. Empty strings and empty lists still count as present, only None is dropped. Image cells are not decoded. A dataset with a numpy, pandas, torch or custom format set (where a null float reads back as NaN and the walk keeps it), and anything without an Arrow view, walks the column as before.

Results

100k caption rows, 3 runs each, same host:

Nulls Column walk (main) Arrow validity (this PR) Same rows
none 684.4 ms (709.6 / 684.4 / 675.1) 2.68 ms (2.68 / 4.14 / 2.33) yes
1% 682.4 ms (682.4 / 757.9 / 670.5) 3.13 ms (4.43 / 3.13 / 2.83) yes

Independent rerun, datasets 4.8.5, two arms each: no nulls 975.0 / 708.8 ms (main, main again) vs 2.15 / 2.21 ms; 1% nulls 807.2 / 724.5 ms vs 2.18 / 2.12 ms; same row indices. The same rows were also checked on datasets 3.4.1 with pyarrow 15.0.2 and datasets 4.3.0 with pyarrow 25.0.1 across strings, large strings, lists, nested structs, list of struct messages, dictionary encoded columns (including a null dictionary value), null typed columns, multi chunk tables, select / shuffle / filter, Image() columns, IterableDataset and plain lists (the last two take the walk, unchanged).

A URL image dataset runs the check on both the image and the caption column, so a 100k row dataset saves about 1.3 s before the first image is fetched, and about 13 s at 1M rows.

Tests

studio/backend/tests/test_vlm_null_row_selection.py:

  • Selected rows match the column walk for strings with None and empty strings, no nulls, all null, empty, lists, structs, selected, shuffled, filtered, multi chunk and Image() typed columns.
  • Image() cells are not decoded.
  • convert_to_vlm_format no longer walks the image or caption column, and keeps the same rows and the same skip log lines. Fails on main (it walks both), passes here.
  • An object without an Arrow view falls back to the walk.
  • A numpy or pandas formatted dataset keeps the walk's rows (NaN kept). Fails without the format check, passes here.

tests/test_vlm_conversion_row_urls.py passes on both arms (same IDs). format_conversion.py compiles on Python 3.9 to 3.14.

Not covered

Timed on Linux only; the change is pure Arrow and Python, nothing platform specific.

@danielhanchen
danielhanchen marked this pull request as ready for review October 29, 2026 09:28
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T09:30:41.100157Z b3eb6c3 Manual request
ℹ️ About Codex in GitHub

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

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

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

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: b3eb6c3439

ℹ️ About Codex in GitHub

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

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

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

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

danielhanchen added a commit to Etherll/unsloth that referenced this pull request Oct 29, 2026
…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).
@danielhanchen
danielhanchen merged commit 5ad31fe into main Oct 29, 2026
1 of 39 checks passed
@danielhanchen
danielhanchen deleted the perf/vlm-null-rows branch October 29, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant