refactor: extract Qwen tokenizer into Leleka crate
Linux / verify (push) Canceled after 0s
Linux / keyless-cuda (push) Canceled after 0s
Linux / static-cuda-package (push) Canceled after 0s
Linux / hosted-cuda-package (push) Canceled after 0s
Linux / linux-static-cli (push) Canceled after 0s
Linux / linux-cli-container (push) Canceled after 0s
Linux / release-cli (push) Canceled after 0s

This commit is contained in:
Pavlo Ratushnyi
2026-10-05 18:24:43 +02:00
parent 4013e0c9bd
commit fef5fca6fd
8 changed files with 53 additions and 25 deletions
Generated
+11 -2
View File
@@ -1007,6 +1007,16 @@ dependencies = [
name = "leleka-backend-api"
version = "0.1.0"
[[package]]
name = "leleka-tokenizer"
version = "0.1.0"
dependencies = [
"aho-corasick",
"fancy-regex",
"serde",
"serde_json",
]
[[package]]
name = "libc"
version = "0.2.190"
@@ -1988,15 +1998,14 @@ checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
name = "strata-control"
version = "0.1.0"
dependencies = [
"aho-corasick",
"axum",
"cc",
"fancy-regex",
"futures-core",
"hex",
"http-body",
"http-body-util",
"jsonschema",
"leleka-tokenizer",
"libc",
"regex",
"regex-syntax",
+2 -2
View File
@@ -1,7 +1,7 @@
[workspace]
resolver = "3"
members = ["crates/backend-api", "control-plane", "desktop-core"]
default-members = ["crates/backend-api", "control-plane", "desktop-core"]
members = ["crates/backend-api", "crates/tokenizer", "control-plane", "desktop-core"]
default-members = ["crates/backend-api", "crates/tokenizer", "control-plane", "desktop-core"]
[workspace.package]
edition = "2024"
+9 -6
View File
@@ -16,6 +16,8 @@ performance gain is claimed for Leleka until its real-model gates pass.
## Repository layout
- `crates/backend-api/` — Leleka's versioned Rust backend contract.
- `crates/tokenizer/` — the Qwen35 byte-level BPE tokenizer extracted as a
backend-independent Rust crate.
- `desktop/`, `desktop-core/` — current desktop application and its Rust core.
- `control-plane/` — current Rust API, Responses handling, and worker supervisor.
- `engine/strata/` — pinned upstream Strata reference; retained during migration.
@@ -30,12 +32,13 @@ artifacts remain outside Git or under ignored paths.
## Current Leleka scope
The Leleka implementation currently defines a backend contract for model
identity, capability declarations, loading, generation, cancellation, unloading,
typed output events, and exactly-one terminal stream behavior. It has no
inference backend or CUDA integration yet. The repository also contains the
existing Strata Next desktop and control-plane implementations as migration
source; their presence does not mean Leleka can serve a model independently.
Leleka currently has a versioned backend contract and a standalone Qwen35 BPE
tokenizer crate. The existing Rust control plane now consumes that shared
tokenizer crate instead of maintaining a second copy; its oracle-parity tests
remain in the workspace. Leleka still has no independent inference backend or
CUDA integration, so this does not yet serve a model independently. The
desktop app and the rest of the control plane remain available as migration
source in this repository.
## Development
+1 -2
View File
@@ -10,11 +10,10 @@ name = "strata-next"
path = "src/main.rs"
[dependencies]
aho-corasick = "1.1"
axum = "0.8"
fancy-regex = "0.19"
futures-core = "0.3"
hex = "0.4"
leleka-tokenizer = { path = "../crates/tokenizer" }
http-body = "1"
jsonschema = { version = "0.58.4", default-features = false }
libc = "0.2"
+1 -1
View File
@@ -43,7 +43,7 @@ pub mod service_install;
pub mod service_unit;
pub mod stream_parts;
pub mod tensor_export;
pub mod tokenizer;
pub use leleka_tokenizer as tokenizer;
pub mod tokenizer_assets;
pub mod tool_output;
pub mod wire;
+1 -10
View File
@@ -14,16 +14,7 @@ use crate::gguf;
type Result<T> = std::result::Result<T, Box<dyn Error>>;
// Kept byte-for-byte equivalent to the upstream qwen35 oracle pattern.
pub(crate) const QWEN35_PATTERN: &str = concat!(
r"(?:'[sS]|'[tT]|'[rR][eE]|'[vV][eE]|'[mM]|'[lL][lL]|'[dD])",
r"|[^\r\n\p{L}\p{N}]?[\p{L}\p{M}]+",
r"|\p{N}",
r"| ?[^\s\p{L}\p{M}\p{N}]+[\r\n]*",
r"|\s*[\r\n]+",
r"|\s+(?!\S)",
r"|\s+",
);
pub(crate) use leleka_tokenizer::QWEN35_PATTERN;
pub fn extract(gguf_path: &Path, output: &Path) -> Result<PathBuf> {
let metadata = gguf::tokenizer_metadata(gguf_path)?;
+16
View File
@@ -0,0 +1,16 @@
[package]
name = "leleka-tokenizer"
version = "0.1.0"
description = "Native Qwen35 tokenizer implementation for Leleka"
edition.workspace = true
license.workspace = true
rust-version.workspace = true
[dependencies]
aho-corasick = "1.1"
fancy-regex = "0.19"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
[lints]
workspace = true
@@ -12,7 +12,16 @@ use aho_corasick::{AhoCorasick, AhoCorasickBuilder, MatchKind};
use fancy_regex::Regex;
use serde::Deserialize;
use crate::tokenizer_assets::QWEN35_PATTERN;
/// Pre-tokenization expression pinned to the Qwen35 GGUF vocabulary oracle.
pub const QWEN35_PATTERN: &str = concat!(
r"(?:'[sS]|'[tT]|'[rR][eE]|'[vV][eE]|'[mM]|'[lL][lL]|'[dD])",
r"|[^\r\n\p{L}\p{N}]?[\p{L}\p{M}]+",
r"|\p{N}",
r"| ?[^\s\p{L}\p{M}\p{N}]+[\r\n]*",
r"|\s*[\r\n]+",
r"|\s+(?!\S)",
r"|\s+",
);
type Result<T> = std::result::Result<T, Box<dyn Error>>;
@@ -336,7 +345,8 @@ fn literal_matcher(
Ok(Some(LiteralMatcher { search, ids }))
}
pub(crate) fn byte_alphabet() -> ([char; 256], HashMap<char, u8>) {
#[doc(hidden)]
pub fn byte_alphabet() -> ([char; 256], HashMap<char, u8>) {
let mut chars = ['\0'; 256];
for byte in (0x21..=0x7e).chain(0xa1..=0xac).chain(0xae..=0xff) {
chars[byte] = char::from_u32(byte as u32).expect("byte code point");