Repository navigation
Cap a streamed eval split once per evaluate() call - #19244
Conversation
evaluate() and get_eval_dataloader both run the late eval cap, and a datasets.IterableDataset has no _fingerprint, so the second pass rejected the mark the first one set, re-probed one more upstream batch (re-tokenizing up to the whole eval split) and stacked a second slice + filter. Trust the stream view _cap built itself, as _CappedBase wrappers already are; a caller's own stream and map-style copies are unchanged.
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Swish! 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". |
[skip ci]
[skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
## Problem On runners with 16 GB of RAM, 35 llama.cpp placement tests fail across `(Python 3.13, g-l)` and `(Python 3.13, m-r)`. The staging runs for #19113, #19181 and #19244 all show them, for example: ``` test_llama_cpp_placement.py::test_the_moe_cache_stays_off[ram_cannot_pin_experts-] assert _load_mode(cmd) == "none" (None == 'none') Load mode: keeping mmap; pinning the host-side weights plus the 9.0 GB llama-server grows into would hold more than 50% of the 15.3 GB of RAM, which the OS cannot page out. ``` They pass on larger runners and locally, so this only shows up on some runners. ## Cause #19231 (price llama-server host RAM growth before pinning a spilled load) is correct. A pinned launch (`--load-mode none`) now also checks that the pinned host-side weights plus llama-server's growth stay under a safe share of total RAM. That total comes from `_host_memory_capacity_mib()`, which reads the real `MemTotal` and the cgroup limit. The placement tests fake the GPUs and, where they care, the available RAM. They never pin the total, so each launch decided against whatever machine ran it. Reproduced locally by stubbing `_total_system_memory_mib` to 15667 MiB: 35 failed, 770 passed in the three files below. ## Fix - `test_llama_cpp_placement.py` gets an autouse fixture, `_pinned_host_ram`. It pins `LlamaCppBackend._total_system_memory_mib` to 256 GiB and `_cgroup_memory_limit_mib` to `None`, so every launch sees the same host on any runner. - `test_lookup_table_fit.py` and `test_prompt_cache_sized_to_context.py` launch through that file's helpers, so they import the fixture. - Tests that are about host RAM still set their own total in the test body, which overrides the fixture. ## Verification - The three files on this branch: 805 passed. - With the host forced to 15.3 GB (a plugin stubbing `_total_system_memory_mib`): 805 passed on this branch, and 35 failed on main. - All 34 test files that import `test_llama_cpp_placement`: 2365 passed and 24 skipped. - One test failed: `test_cached_gguf_routes.py::test_pipeline_class_guard_passes_every_shipped_family`. - It fails identically on main, because this host has diffusers 0.41.0.dev0 and the test needs 0.42.0. It is unrelated to this change.
Problem
When the eval split is a streaming
datasets.IterableDataset, the late eval cap (_wrap_sft_evaluate_cap) runs_captwice on everyevaluate()call.evaluate()caps the split, then Transformers callsget_eval_dataloader, which is wrapped too and sees the capped object. A stream has no_fingerprint, so_mutation_tokenreturns None and_cap_still_holdsrejects the mark the first pass just set. The second pass then:_column_namesprobe,next(iter(ds)), which pulls one whole batched-map batch through every upstream map (the tokenizer map included). With the default batch size of 1000, an eval split of up to 1000 rows is re-streamed and re-tokenized in full just to read one row;mapand supervisionfilteron the chain the dataloader iterates.This happens at every eval step during training (stored split) and for
evaluate(eval_dataset = stream).Change
_capmarks a stream view it built itself withmap/filter(own__dict__flag), and_cap_still_holdstrusts that view the same way it already trusts_CappedBasewrappers: by cap anddrop_unsupervisedonly. That object is a fresh lazy view nobody else holds, and every row it yields passes through the slice and filter it was built with, so the mark cannot go stale.Unchanged on purpose:
drop_unsupervisedstill rescans.This is a runtime wrapper, not part of the generated trainer source, so the compiled cache is not involved.
Results
Local streaming split (
IterableDataset.from_generator+ batched tokenize map, batch size 1000 as zoo's_iterable_batch_size), cap 16, 3 calls each via stored split and viaevaluate(eval_dataset = stream), measured through the real wrappers:Total upstream work per eval call (cap plus the eval read itself) drops from 900 to 600 source rows at 300 rows, and from 4500 to 3500 at 2500 rows. Yielded rows are identical in order and content across both arms and all six consecutive calls.
Tests
test_a_streamed_eval_split_is_capped_once_per_evaluate: four consecutive evaluations (stored and passed) probe the stream once each, stack exactly one slice and filter, restore the stored split and yield identical rows.test_only_a_stream_the_cap_built_is_trusted_without_a_fingerprint: a caller's marked stream is still rechecked, only the literal flag counts, a different cap or mode rescans, and a map-style copy stays on the fingerprint path.tests/version_compat/test_trl_padding_free_max_length.pypasses.