Files
leleka/crates/tokenizer/examples/bench_encode.rs
T
Pavlo RatushnyiandClaude Sonnet 5.5 b3274c1130
Linux / keyless-cuda-gate (push) Skipped
Rust port / port-typecheck (push) Failing after 8s
Desktop foundation / core (ubuntu-latest) (push) Failing after 11s
Rust port / port-oracles (push) Failing after 11s
Rust port / port-linux-tests (push) Failing after 14s
Rust port / port-fast (push) Failing after 9s
Linux / verify (push) Failing after 17s
Linux / keyless-cuda (push) Skipped
Linux / static-cuda-package (push) Skipped
Linux / hosted-cuda-package (push) Skipped
Linux / linux-static-cli (push) Skipped
Linux / linux-cli-container (push) Skipped
Linux / release-cli (push) Skipped
Merge claude/port-gpu-bringup (CUDA runtime port, upstream sync) into main
Brings the Rust/CUDA port of the Strata mode17 serve path together with the
CPU/iGPU/NPU gpt-oss runtime that main gained meanwhile.

Control plane: the Qwen tokenizer is the implementation behind the Qwen35
variant of codec::TextCodec (qwen(), encode_prompt() widen the trait; QwenCodec
derefs to the tokenizer), so control-token marks, images, chat template, the
runtime backend and vision keep their behavior, while the gpt-oss/Harmony path
and the worker pool keep main's. Config carries the union of fields; extra_workers
is rejected together with runtime, lazy_load, idle_unload_s and vision; the
gpt-oss family refuses top_k/min_p/penalties (its GEN line has no such keys).
leleka-kar-codec takes f16_bits_to_f32 from leleka-quant-core (identical code).
Workspace members and default-members are the union of both sides.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-27 08:32:33 +01:00

44 lines
1.7 KiB
Rust

//! Encode/decode throughput of the tokenizer on a long synthetic prompt (host cost of TTFT and of token publication).
//!
//! `cargo run --release -p leleka-tokenizer --example bench_encode -- TOKENIZER_DIR PROMPTS.txt [REPEAT]`
use std::{env, fs, path::Path, process::ExitCode, time::Instant};
use leleka_tokenizer::Tokenizer;
fn main() -> ExitCode {
let args: Vec<String> = env::args().collect();
if args.len() < 3 {
eprintln!("usage: bench_encode TOKENIZER_DIR PROMPTS.txt [REPEAT]");
return ExitCode::from(2);
}
let tokenizer = Tokenizer::from_assets(Path::new(&args[1])).expect("tokenizer assets");
let corpus = fs::read_to_string(&args[2]).expect("prompts");
let repeat: usize = args.get(3).and_then(|v| v.parse().ok()).unwrap_or(200);
let text: String = (0..repeat)
.map(|_| corpus.as_str())
.collect::<Vec<_>>()
.join("\n");
for _ in 0..2 {
let started = Instant::now();
let ids = tokenizer.encode(&text, true).expect("encode");
let encode = started.elapsed();
let started = Instant::now();
let mut bytes = 0usize;
for &id in &ids {
bytes += tokenizer.decode_bytes(&[id]).expect("decode").len();
}
let decode = started.elapsed();
eprintln!(
"text {} bytes -> {} tokens: encode {:.1} ms ({:.2} Mtok/s); decode_bytes one id at a time {:.2} us/token ({} bytes)",
text.len(),
ids.len(),
encode.as_secs_f64() * 1e3,
ids.len() as f64 / encode.as_secs_f64() / 1e6,
decode.as_secs_f64() * 1e6 / ids.len() as f64,
bytes
);
}
ExitCode::SUCCESS
}