Repository navigation
Mix lens corpora by weight and spread unshuffled ones over their files - #60
Merged
Merged
Conversation
A lens fit could read one Hub dataset's head. That is a fair sample only of a globally shuffled dataset, and the shuffled ones on offer are English-only, while Qwen's workspace often reads in Chinese. The Chinese web corpora on the Hub are ordered: fineweb-2 cmn_Hani opens on its 2013-14 dumps, SkyPile on one 2020 crawl, Fineweb-Edu-Chinese on one score band of one source. - --hf-corpus takes per-source options, REPO[:CONFIG][@rev][,KEY=VALUE...]: text_field, files, seed, weight. text_field replaces #59's --text-field flag, and the fit route's hf_corpus becomes a list of these sources. - files=K reads round-robin from K of the train split's data files, ordered by a seed-keyed sha256 of their repository paths. The selection is stable across Python and datasets versions, and needs no row-level shuffle. - Repeating --hf-corpus makes a LensCorpusMix, interleaved by smooth weighted round-robin (weights 3,1 read A A B A ...; ties go to the earlier corpus; a corpus that runs dry leaves the schedule). Neither schedule depends on N, so the first N documents of a longer read are those of a shorter one, and top-up and resume keep working by token-id prefix. - Specs: a source gains ;files=K;seed=S when spread; a mix records mix:W*SPEC|W*SPEC in schedule order. Specs without the new options are unchanged. - An interleave reads its streams on up to 8 threads. Opening a Hub data file costs seconds of latency, and each stream's documents are fixed by the data, so the concurrency cannot change the result.
a9lim
enabled auto-merge
October 28, 2026 21:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
#59 let a lens fit read the head of any pinned Hub dataset. That head is a fair sample only when the dataset is globally shuffled, and the shuffled candidates (FineWeb-Edu's sample is not, dclm_100BT-shuffled is) are English-only. Qwen's workspace often reads in Chinese. I probed the broad Chinese web corpora on the Hub, and none is shuffled:
HuggingFaceFW/fineweb-2cmn_Hani(370 files)Skywork/SkyPile-150B(437 files)2020-40_zh_head_0000.jsonlopencsg/Fineweb-Edu-Chinese-V2.1(29k files)2_3score band, every row from sourceCCI3A bilingual fit therefore needs two things: a mix, and a way to spread the sample over a dataset whose rows are ordered.
Change
--hf-corpus REPO[:CONFIG][@REV][,KEY=VALUE…]takestext_field,files,seedandweight.text_field=replaces the--text-fieldflag from Fit lenses on any commit-pinned Hugging Face dataset #59 (merged earlier today, no alias), and the fit route'shf_corpusbecomes a list of these sources. I used commas because a;separator would split the command in an unquoted shell line.files=Kreads round-robin from K of the train split's data files. The files are ordered bysha256("{seed}:{path}")over their repository paths, so the selection is stable across Python anddatasetsversions and needs no row-level shuffle. On FineWeb-2cmn_Hani, 64 files span all five file groups. Its row groups hold 1,000 rows (about 2 MB of text), so each file costs one small fetch.--hf-corpusbuilds aLensCorpusMix, interleaved by smooth weighted round-robin. With weights 3,1 the order isA A B A A A B A …, ties go to the earlier corpus, and a corpus that runs dry leaves the schedule. Neither schedule depends on N, so the first N documents of a longer read are exactly those of a shorter one, and top-up, resume and the no-op preflight keep working by token-id prefix. The interleave assumes every stream is long enough, caps any stream that comes up short, and redraws the schedule. That gives the same result as drawing lazily, without holding every stream open at once.;files=K;seed=S, and a mix recordsmix:W*SPEC|W*SPECin schedule order. Specs without the new options are unchanged, so existing fits still no-op.Tests
files=0, aseedwithoutfiles, a negative seed, and aweighton a single corpus.[3,1]gives0 0 1 0 0 0 1 0, and equal weights are plain round-robin. A dry stream leaves the schedule. On 200 random weight and cap sets, every prefix of the schedule equals the longer schedule cut short.data_filesoverride; reading round-robins them and outlasts a dry file; every prefix is stable.mix:spec.--hf-corpusis pinned once as a mix and reaches the preflight and the stream unchanged. Route: a listhf_corpusreaches the streamer, and a bare string, an empty list or the oldtext_fieldfield gets a 400.Verification
eeZerepeating (Chinese share 0.25), and the process exits cleanly.hf-internal-testing/tiny-random-LlamaForCausalLM, isolatedDROWSE_HOME, the same mix):--prompts 20fits in 38 s.--prompts 40resumes from 20 ("20 remaining") in 161 s. Rerunning 40 is a 5 s model-free no-op.lens showreports the fullmix:spec. The network was slow during these runs, with some Hub requests timing out and retrying.pytest -m "not gpu": 3980 passed. The 2 failures are the browser affine-Fisher fixture and sampling-fixturecase2, the same Mac-numerics failures as on cleanmain. ruff and pyright are clean.Cost to expect
The read is latency-bound. Each spread file opens with a few seconds of Hub round trips and one row-group fetch. At
--prompts 1000with the mix above, the Chinese side opens all 64 files once, eight at a time; on this network, expect minutes. That is small next to a Qwen3-8B fit but noticeable in the web UI.Not in this PR
files=Kspreads across files, but documents within a file stay in file order, so each file contributes a contiguous run. A larger K spreads further.sae train --hf-corpus. It shares the corpus path, so adding the flag would be small.