Repository navigation
Avoid full-batch rescans in pretraining masking - #327
Conversation
Change mapObserved bottleneck: guaranteeing a loss-bearing token looped over examples and searched the full event/token matrix for each, even when no fallback was needed. The direct fix retains existing masking semantics and replaces only that guarantee implementation.
Verification: 48 focused tests passed (one local CUDA skip); Ruff, formatting and diff checks passed. Separate CPU/CUDA and real-data parity checks plus warm loader measurements are summarized in the description. Stop at this two-file repair; no trainer, tokenizer, native loader, API or dependency work is included. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Summary
mask_event_valueschecked each example by repeatedly scanning the entire batch's event/token matrix. Replace that loop with grouped minimum-position reductions, retaining the same first-valid/first-selected fallback, random draws, corruption and loss targets. Skip the guarantee work whenensure_at_least_one=False.On a retained real-data workload (32,768 anchors, 80 batches, 1.67M events), warm masking time falls 15.657s → 1.271s (12.32×) and complete loader time 18.441s → 4.034s (4.57×). Peak RSS remains about 107 GiB. These are loader-only measurements, not end-to-end training speedups.
Testing
Change map
#327 (comment)