Skip to content

fix(tokenizer): support SentencePiece artifacts in hash_tokenizer_config and add unit tests - #184

Open
rishiiicreates wants to merge 1 commit into
AOSSIE-Org:mainfrom
rishiiicreates:fix/hash-tokenizer-config-sentencepiece
Open

rishiiicreates wants to merge 1 commit into
AOSSIE-Org:mainfrom
rishiiicreates:fix/hash-tokenizer-config-sentencepiece

Conversation

@rishiiicreates

Copy link
Copy Markdown

closes #69
closes #77

hash_tokenizer_config() in Legacy/openverifiablellm/tokenizer/train.py previously assumed BPE tokenizer artifacts only (vocab.json and merges.txt). when training a SentencePiece tokenizer, it crashed with FileNotFoundError because SentencePiece writes spm.model and spm.vocab instead of json/txt files. furthermore, unit tests were missing for create_tokenizer and direct load_merkle_proof validation.

this PR updates hash_tokenizer_config() to support both SentencePiece and BPE tokenizers with automatic disk artifact detection and optional explicit type passing. for SentencePiece artifacts, it hashes spm.vocab and spm.model, computes the actual vocabulary size from the vocabulary lines, and sets tokenizer_merges_hash to None while maintaining full backward compatibility for BPE output keys.

also added comprehensive unit tests in Legacy/tests/test_tokenizer.py covering SentencePiece file generation, determinism, config hashing, and error paths for missing models or vocabs. added create_tokenizer factory tests covering BPE, SentencePiece, case-insensitivity, and unsupported types, as well as load_merkle_proof tests in Legacy/tests/test_util.py for valid JSON, missing files, and invalid formats. all 48 tests passing green.

…fig and add unit tests

- Support both SentencePiece (spm.model, spm.vocab) and BPE (vocab.json, merges.txt) in hash_tokenizer_config
- Auto-detect tokenizer type based on artifacts present on disk
- Add unit tests for SentencePiece training, file existence, determinism, and artifact config hashing
- Add unit tests for create_tokenizer factory covering BPE, SentencePiece, case-insensitivity, and error cases
- Add unit tests for load_merkle_proof covering valid JSON, missing file, and malformed JSON

Closes AOSSIE-Org#69
Closes AOSSIE-Org#77
Copilot AI balanced review requested due to automatic review settings October 6, 2026 02:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 43 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f3f16286-27de-43e4-a2e2-5d597b4d9ec7
📥 Commits

Reviewing files that changed from the base of the PR and between 14a21c4 and 1317895.

📒 Files selected for processing (3)
  • Legacy/openverifiablellm/tokenizer/train.py
  • Legacy/tests/test_tokenizer.py
  • Legacy/tests/test_util.py
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants