Skip to content

Use i64 pair counts and add optional min_freq pruning - #8

Open
1023097618 wants to merge 1 commit into
karpathy:masterfrom
1023097618:i64-counts-min-freq
Open

1023097618 wants to merge 1 commit into
karpathy:masterfrom
1023097618:i64-counts-min-freq

Conversation

@1023097618

Copy link
Copy Markdown

Summary

Two changes to train_from_iterator that came up while training a tokenizer on a large Chinese corpus:

  1. i64 counts. Chunk counts and pair counts were i32. On large corpora the
    aggregated pair counts can exceed i32::MAX and overflow. They are now i64
    (count_pairs_parallel, train_core_incremental, merge delta updates).

  2. Optional min_freq argument (default 1, so existing behavior is unchanged).
    Chunks seen fewer than min_freq times are dropped before training. On CJK text,
    where the regex split produces many long one-off chunks, min_freq=2 cuts
    memory a lot. The number of kept/dropped chunks is logged.

Testing

  • cargo test, cargo fmt --check and cargo clippy -D warnings pass
  • New Python test test_min_freq; the existing quick Python tests pass

🤖 Generated with Claude Code

- Pair counts and chunk counts are now i64, so large corpora no longer
  overflow i32 during training.
- train_from_iterator gains an optional min_freq argument (default 1,
  i.e. no change in behavior). Chunks seen fewer than min_freq times are
  dropped before training, which greatly reduces memory on large corpora,
  especially CJK text where most long chunks are singletons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1023097618 added a commit to 1023097618/train_llm that referenced this pull request Oct 13, 2026
- environment.yml: Python 3.11 and the project's pip dependencies
- setup_env.sh: creates/updates the env, installs PyTorch (CUDA build
  selectable), builds the modified rustbpe from the fork
  (karpathy/rustbpe#8), registers a Jupyter
  kernel and runs a sanity check
- train_token.py: pass min_freq=2 explicitly, since the fork defaults to 1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant