Commit eea33cd
committed
counting: vectorize dynamic_window="prob", bit-identically
2.6x faster (0.910s -> 0.355s on 200k tokens at window=5), and -- the
part that matters more -- bit-identical to the frozen reference, so every
number ever recorded with this configuration still reproduces.
The equivalence gate asserted the opposite. Its docstring said
bit-identity was "not achievable" for randomized configurations because
"any sensible vectorization draws a whole array up front from a numpy
generator". The premise was the mistake, not the conclusion drawn from
it: iterate_tokens draws exactly one randint(1, window) per token in
token order, and a comprehension over the flattened chunk draws the same
numbers in the same order. Measured, the draws are not the expensive part
anyway -- 0.08s per 200k tokens against the ~0.9s of emission they gate.
So the gate now holds this configuration to assert_array_equal across all
four windows and both seeds, and its docstring records why the old claim
was wrong rather than quietly dropping it.
subsample="prob"/"dirty" stay on the loop, and the measurement is the
reason: they discard so many tokens that they are already the FASTEST
configurations there are -- 0.12-0.13s against 0.31s for the vectorized
deterministic default, because so few pairs survive. Vectorizing them
would optimize the cheap case and buy a second implementation to keep in
sync. Their draw streams also interleave in a way the prob window does
not (subsampling draws precede window draws, and under the clean variant
a dropped token consumes one but not the other), so it would be the
delicate work as well as the pointless kind.1 parent bfba90d commit eea33cd
3 files changed
Lines changed: 143 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
7 | 25 | | |
8 | 26 | | |
9 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
348 | 373 | | |
349 | 374 | | |
350 | 375 | | |
| |||
354 | 379 | | |
355 | 380 | | |
356 | 381 | | |
357 | | - | |
358 | | - | |
| 382 | + | |
| 383 | + | |
359 | 384 | | |
360 | 385 | | |
361 | 386 | | |
| |||
376 | 401 | | |
377 | 402 | | |
378 | 403 | | |
379 | | - | |
| 404 | + | |
380 | 405 | | |
381 | 406 | | |
382 | 407 | | |
383 | 408 | | |
384 | 409 | | |
385 | 410 | | |
386 | 411 | | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
392 | 422 | | |
393 | 423 | | |
394 | 424 | | |
| |||
428 | 458 | | |
429 | 459 | | |
430 | 460 | | |
431 | | - | |
432 | | - | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
433 | 473 | | |
434 | 474 | | |
435 | 475 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
45 | 60 | | |
46 | 61 | | |
47 | 62 | | |
| |||
892 | 907 | | |
893 | 908 | | |
894 | 909 | | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
0 commit comments