Skip to content

feat: Pool embeddings in parallel - #53

Open
Pringled wants to merge 2 commits into
mainfrom
parallel-pooling
Open

Pringled wants to merge 2 commits into
mainfrom
parallel-pooling

Conversation

@Pringled

@Pringled Pringled commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Tokenization already runs across threads, but pooling ran one text at a time after it. This pools in the same parallel iterator, and sums over a contiguous row slice so the loop vectorizes.

50k Wikipedia paragraphs, samples/s:

Model 1 thread all cores
potion-base-8M 19,372 → 22,958 64,306 → 98,176
potion-code-16M-v2 9,446 → 17,241 15,830 → 124,592
potion-multilingual-128M 9,759 → 9,840 49,704 → 96,951

The single-thread gain comes from the slice change only.

Tokenization already runs across threads, but pooling ran one text at a time
afterwards, so it became the bottleneck on a machine with cores to spare.
Pooling now happens inside the same parallel iterator, using the tokenizers
crate's own helper, so TOKENIZERS_PARALLELISM keeps controlling both and wasm
still builds without threads.

pool_ids also sums over a contiguous row slice instead of an ndarray row
iterator, which lets the loop vectorize.

On 50k Wikipedia paragraphs, samples per second before -> after:

  potion-base-8M            1 thread  18,845 -> 23,193   all cores  64,306 ->  98,176
  potion-code-16M-v2        1 thread   9,712 -> 18,640   all cores  15,830 -> 124,592
  potion-multilingual-128M  1 thread   9,759 ->  9,840   all cores  49,704 ->  96,951

Embeddings are unchanged: identical bytes for potion-base-8M, science-32M,
code-16M-v2 and multilingual-128M and the float16, int8 and vocab-quantized
fixtures, over Wikipedia, ag_news, long and adversarial texts.
@Pringled Pringled changed the title perf: Pool embeddings in parallel and over contiguous rows feat: Pool embeddings in parallel Sep 21, 2026
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