Skip to content

Add encode_batch_ids and make Tokenizer a PythonCall wrapper - #15

Merged
AntonOresten merged 1 commit into
MurrellGroup:mainfrom
CarloLucibello:cl/encode-batch-ids
Oct 20, 2026
Merged

AntonOresten merged 1 commit into
MurrellGroup:mainfrom
CarloLucibello:cl/encode-batch-ids

Conversation

@CarloLucibello

Copy link
Copy Markdown
Collaborator

Fixes #13.

  • encode_batch_ids(tok, texts; T=UInt32, kwargs...) calls encode_batch_fast and returns a view per text into one Vector{T} (parent(ids[1])). Python writes the ids straight into Julia-allocated memory via the buffer protocol, so no numpy dependency and no per-Encoding Julia wrappers. Ids that don't fit in T throw an OverflowError.
  • Tokenizer defines PythonCall.ispy and Py, so it can be passed to Python code directly.
  • CondaPkg.toml requires tokenizers >= 0.20 (first release with encode_batch_fast).

10k docs (47 MB, 21.5M GPT-2 tokens), T=UInt16, same batch run 5 times:

time per batch RSS increase after batch 1 → 5
encode_batch 8.7–12.3 s +3.9 → +6.8 GB
encode_batch_ids 1.3 s +1.6 → +2.2 GB
bare encode_batch_fast 0.8 s +1.6 → +2.5 GB

🤖 Generated with Claude Code

@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c1d9954) to head (0e202b4).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #15   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines           21        36   +15     
=========================================
+ Hits            21        36   +15     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

encode_batch_ids calls encode_batch_fast and writes the ids of all texts
into one Julia vector through the buffer protocol, returning a view per
text. Tokenizer now defines ispy and Py, so it can be passed to Python.

Fixes MurrellGroup#13

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AntonOresten

Copy link
Copy Markdown
Member

Thanks!

@AntonOresten
AntonOresten merged commit 2ade791 into MurrellGroup:main Oct 20, 2026
5 checks passed
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.

Fast ids-only batch encoding (encode_batch is 4x slower and 10x more memory)

2 participants