mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-11 22:51:28 +00:00
* feat(rust_bridge): count budget-check input tokens in Rust on all LLM routes Rust counts input tokens from the raw JSON body with the GIL released inside the existing budget reservation, covering every LLM route the auth dependency guards. It only fires for models on the Anthropic tokenizer when a budget is set, and Python counts whenever Rust is off, missing, or declines a body shape. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * perf(rust): count byte-level BPE tokens without the GPT-2 split regex (#40594) The oniguruma run of the ByteLevel pre-tokenizer regex is about 90% of encode_fast on a 100k token body (100 ms of the ~110 ms Rust admission count in the gateway pod). A hand-written scanner that yields the same pieces, then feeds the model directly, counts the same text in 10 ms. It only engages for tokenizers with the Anthropic shape (optional NFKC, ByteLevel without prefix space, no post-processor) and falls back to the full encoder when the text contains an added token. Parity with encode_fast is tested on random texts, the pieces are compared with the real pre-tokenizer, and the \p{L}/\p{N}/\s tables are checked against oniguruma for every code point. NFKC runs through unicode-normalization-alignments, the crate and Unicode tables NormalizedString::nfkc already uses, so the fast path normalizes exactly what the full encoder would. Using the newer unicode-normalization crate changed the count for 171 code points that gained compatibility decompositions after Unicode 9 (U+32FF, U+A7F1..). The fast normalizer is compared with the tokenizer's for every scalar value and on random texts. The scanner is built without mutable state: byte_char and mapped_len replace the const table builders and the reusable mapped buffer, and iter::successors replaces the stateful piece iterator. byte_chars_match_the_byte_level_alphabet checks the byte mapping against ByteLevel for every scalar value. Co-authored-by: yassin <yassin@berri.ai> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(rust_bridge): bound concurrent token-count encodes and share the Anthropic tokenizer predicate Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: yassin <yassin@berri.ai> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
54 lines
1.7 KiB
TOML
54 lines
1.7 KiB
TOML
[workspace]
|
|
members = [
|
|
"crates/core",
|
|
"crates/token-counter",
|
|
"crates/config",
|
|
"crates/ai-gateway",
|
|
"crates/python-interop",
|
|
"crates/python-bridge",
|
|
]
|
|
resolver = "2"
|
|
|
|
[workspace.package]
|
|
edition = "2024"
|
|
rust-version = "1.88"
|
|
license = "MIT"
|
|
repository = "https://github.com/BerriAI/litellm"
|
|
|
|
[workspace.dependencies]
|
|
tracing = "0.1"
|
|
tracing-subscriber = { version = "0.3", default-features = false, features = ["registry", "std"] }
|
|
litellm-core = { path = "crates/core" }
|
|
litellm-token-counter = { path = "crates/token-counter" }
|
|
litellm-config = { path = "crates/config" }
|
|
litellm-ai-gateway = { path = "crates/ai-gateway", default-features = false }
|
|
litellm-python-interop = { path = "crates/python-interop" }
|
|
axum = "0.7"
|
|
pyo3 = "0.29.2"
|
|
pyo3-async-runtimes = { version = "0.29.0", features = ["tokio-runtime"] }
|
|
pythonize = "0.29.0"
|
|
rand = "0.8"
|
|
reqwest = { version = "0.12", default-features = false, features = ["blocking", "json", "multipart", "rustls-tls", "http2", "stream"] }
|
|
rstest = "0.26.1"
|
|
rustls = { version = "0.23", default-features = false, features = ["ring", "std", "tls12"] }
|
|
rustls-native-certs = "0.8"
|
|
serde = { version = "1.0", features = ["derive"] }
|
|
serde_json = { version = "1.0", features = ["float_roundtrip"] }
|
|
sha2 = "0.10"
|
|
subtle = "2"
|
|
thiserror = "2.0"
|
|
tokio = { version = "1", features = ["rt-multi-thread", "macros", "time", "net"] }
|
|
tokio-tungstenite = { version = "0.24", default-features = false, features = ["connect", "rustls-tls-native-roots"] }
|
|
futures-util = { version = "0.3", default-features = false, features = ["sink", "std"] }
|
|
base64 = "0.22"
|
|
url = "2.5.8"
|
|
criterion = "0.8.2"
|
|
|
|
[profile.release]
|
|
opt-level = 3
|
|
lto = "thin"
|
|
codegen-units = 1
|
|
panic = "unwind"
|
|
debug = false
|
|
incremental = false
|
|
strip = "symbols"
|