unparallelled commited on
Commit
89c3154
·
verified ·
1 Parent(s): 693b639

Upload scripts/mix_buckets.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. scripts/mix_buckets.py +18 -5
scripts/mix_buckets.py CHANGED
@@ -79,6 +79,11 @@ def main():
79
  ap.add_argument("--window", type=int, default=65536, help="CP_T")
80
  ap.add_argument("--grad-accum", type=int, default=8)
81
  ap.add_argument("--split", default="train")
 
 
 
 
 
82
  a = ap.parse_args()
83
 
84
  srcs = []
@@ -112,6 +117,8 @@ def main():
112
 
113
  got = {n: 0 for n, _ in srcs}
114
  written = 0
 
 
115
  shard_idx = 0
116
  buf = []
117
  buf_n = 0
@@ -147,12 +154,17 @@ def main():
147
  exhausted.add(pick)
148
  print(f" {pick} exhausted at {got[pick]/1e6:.1f} M tokens")
149
  continue
150
- buf.append(doc)
151
- buf_n += doc.size
152
  got[pick] += doc.size
153
  written += doc.size
154
- if buf_n >= shard_tokens:
155
- flush()
 
 
 
 
 
 
 
156
  flush()
157
 
158
  # --- emulate DataLoaderLite so STEPS is right ---------------------------
@@ -173,7 +185,8 @@ def main():
173
  for n, w in srcs:
174
  print(f" {n:<22} target {w:5.1%} actual {got[n]/written:5.1%} "
175
  f"({got[n]/1e6:.1f} M tokens)")
176
- print(f" total {written/1e6:.1f} M tokens in {len(paths)} shards")
 
177
  print(f"\n USABLE STEPS at window {BT:,} x grad_accum {a.grad_accum}: {steps}")
178
  print(f" (naive total//global_batch would say "
179
  f"{written // (BT * a.grad_accum)} -- use {steps}, it accounts for the")
 
79
  ap.add_argument("--window", type=int, default=65536, help="CP_T")
80
  ap.add_argument("--grad-accum", type=int, default=8)
81
  ap.add_argument("--split", default="train")
82
+ ap.add_argument("--skip-tokens", type=float, default=0,
83
+ help="discard this many tokens of the interleaved stream before "
84
+ "writing. CP_INIT_FROM restarts the loader at token 0 "
85
+ "(skip_batches is bypassed, bluscriptCP.cpp:2047), so a "
86
+ "continuation must skip in the DATA instead.")
87
  a = ap.parse_args()
88
 
89
  srcs = []
 
117
 
118
  got = {n: 0 for n, _ in srcs}
119
  written = 0
120
+ skip = int(a.skip_tokens)
121
+ emitted = 0
122
  shard_idx = 0
123
  buf = []
124
  buf_n = 0
 
154
  exhausted.add(pick)
155
  print(f" {pick} exhausted at {got[pick]/1e6:.1f} M tokens")
156
  continue
 
 
157
  got[pick] += doc.size
158
  written += doc.size
159
+ # The picker is driven by RUNNING SHARES and never references the total,
160
+ # so the document sequence is identical for any --total-tokens. That is
161
+ # what makes a skip equivalent to resuming the same stream.
162
+ if written > skip:
163
+ if emitted == 0 and written - doc.size < skip:
164
+ doc = doc[skip - (written - doc.size):] # partial first document
165
+ buf.append(doc); buf_n += doc.size; emitted += doc.size
166
+ if buf_n >= shard_tokens:
167
+ flush()
168
  flush()
169
 
170
  # --- emulate DataLoaderLite so STEPS is right ---------------------------
 
185
  for n, w in srcs:
186
  print(f" {n:<22} target {w:5.1%} actual {got[n]/written:5.1%} "
187
  f"({got[n]/1e6:.1f} M tokens)")
188
+ print(f" stream {written/1e6:.1f} M tokens; skipped {skip/1e6:.1f} M; "
189
+ f"WROTE {emitted/1e6:.1f} M in {len(paths)} shards")
190
  print(f"\n USABLE STEPS at window {BT:,} x grad_accum {a.grad_accum}: {steps}")
191
  print(f" (naive total//global_batch would say "
192
  f"{written // (BT * a.grad_accum)} -- use {steps}, it accounts for the")