v1.0.0-rc.2: canonicalize_file rejects ByteLevel add_prefix_space=true supported by 0.23.2
Summary
The published Rust tokenizers = 1.0.0-rc.2 rejects a ByteLevel BPE tokenizer with add_prefix_space: true in canonicalize_file, returning ByteLevelAddPrefixSpace. The same configuration loads and encodes with 0.23.2.
This affects our RoBERTa NER tokenizer migration. The example below reduces the problem to the public GPT-2 tokenizer with one pre-tokenizer setting changed, so no model weights or application code are required.
This may be a known RC feature gap; I could not find a dedicated issue. Reporting it to track compatibility with existing supported tokenizer configurations. No segfault is involved.
Reproduction
Environment: Linux x86_64, Rust 1.93.1. Tested the published crates, with the regex fallback enabled for v1.
Cargo.toml:
[package]
name = "tokenizers-v1-load-repro"
version = "0.1.0"
edition = "2021"
[dependencies]
v023 = { package = "tokenizers", version = "=0.23.2", default-features = false, features = ["onig"] }
v1 = { package = "tokenizers", version = "=1.0.0-rc.2", default-features = false, features = ["regex"] }src/main.rs:
fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let path = std::env::args().nth(1).expect("pass tokenizer.json path");
let old = v023::Tokenizer::from_file(&path)?;
println!("0.23.2 loaded and encoded: {:?}", old.encode("Hello world", true)?.get_ids());
let canonical = v1::canonicalize_file(&path)?;
match v1::from_json(&canonical) {
Ok(_) => println!("1.0.0-rc.2 loaded"),
Err(e) => eprintln!("1.0.0-rc.2 load error: {e}"),
}
Ok(())
}Create the input:
import json
import urllib.request
with urllib.request.urlopen(
"https://huggingface.co/openai-community/gpt2/resolve/main/tokenizer.json"
) as response:
tokenizer = json.load(response)
tokenizer["pre_tokenizer"]["add_prefix_space"] = True
with open("prefix-space.json", "w") as f:
json.dump(tokenizer, f)Run:
cargo run --release -- prefix-space.jsonActual output (exit status 1):
0.23.2 loaded and encoded: [18435, 995]
Error: ByteLevelAddPrefixSpacecanonicalize_file returns before from_json is reached. Its display message in our larger harness is:
a `ByteLevel` pre-tokenizer with `add_prefix_space: true` is not supportedExpected
Load the supported ByteLevel configuration and preserve add_prefix_space: true token IDs (for this input, [18435, 995]). Turning the flag off changes tokenization semantics, so it is not an equivalent workaround.
Source: huggingface/tokenizers