fix: 12 bug fixes from comprehensive review — 51 tok/s verified on RTX 5090
P0 fixes (blocking usability): - FIX-01: thread-local cuBLAS handle (was creating/destroying per matmul) - FIX-16: EOS token no longer leaks into API responses - FIX-17: max_seq_len configurable via --max-seq-len (default 2048, was hardcoded 256) - FIX-18: max_tokens clamped to available seq space, prompt overflow returns 400 P1 fixes (bugs & performance): - FIX-07: CachingAllocator wired into all hot paths (to_device, embedding, rope, concat) - FIX-08: CudaDeviceProp buffer increased to 32KB for CUDA 12.9 safety - FIX-09: tokenizer byte_fallback graceful degradation (was panic) - FIX-19: causal mask uses -INFINITY instead of -1e9 (BF16 supports inf) - FIX-20: LayerNorm rewritten to numerically stable two-pass algorithm - FIX-21: min block size guard (32 threads) for LayerNorm/RMSNorm launches P2 fixes (improvements): - FIX-22: Option<GpuKVCache> + take() eliminates dummy KV cache allocations - FIX-23: RoPE cache no longer artificially capped at 8192 positions Verified on dash5 (RTX 5090): 51 tok/s batch=1, 74 tok/s 2-concurrent, 1.7-3.3x HF transformers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -51,8 +51,6 @@ impl Tokenizer {
|
||||
let tj: TokenizerJson = serde_json::from_str(&data)
|
||||
.unwrap_or_else(|e| panic!("failed to parse tokenizer.json: {e}"));
|
||||
|
||||
let byte_fallback = tj.model.byte_fallback;
|
||||
|
||||
// Build encoder: token bytes → ID
|
||||
// All HF tokenizers use GPT-2 byte-to-unicode mapping for vocab keys.
|
||||
let mut encoder = HashMap::new();
|
||||
@@ -170,16 +168,25 @@ impl Tokenizer {
|
||||
}
|
||||
// Fall back to per-byte encoding
|
||||
let word_bytes: Vec<u8> = word.bytes().collect();
|
||||
let mut token_ids: Vec<u32> = word_bytes.iter().map(|&b| {
|
||||
let mut token_ids: Vec<u32> = word_bytes.iter().filter_map(|&b| {
|
||||
if let Some(&id) = self.encoder.get(&vec![b]) {
|
||||
id
|
||||
Some(id)
|
||||
} else if self.byte_fallback {
|
||||
let hex_token = format!("<0x{:02X}>", b);
|
||||
*self.special_tokens.get(&hex_token).unwrap_or_else(|| {
|
||||
panic!("byte 0x{b:02X} not in vocab and no fallback token {hex_token}")
|
||||
})
|
||||
if let Some(&id) = self.special_tokens.get(&hex_token) {
|
||||
Some(id)
|
||||
} else if let Some(&id) = self.encoder.get(hex_token.as_bytes()) {
|
||||
Some(id)
|
||||
} else if let Some(&unk_id) = self.special_tokens.get("<unk>") {
|
||||
eprintln!("warning: byte 0x{b:02X} not in vocab, using <unk> token");
|
||||
Some(unk_id)
|
||||
} else {
|
||||
eprintln!("warning: byte 0x{b:02X} not in vocab and no fallback token, using token 0");
|
||||
Some(0)
|
||||
}
|
||||
} else {
|
||||
panic!("byte {b} (0x{b:02X}) not in vocab")
|
||||
eprintln!("warning: byte {b} (0x{b:02X}) not in vocab, skipping");
|
||||
None
|
||||
}
|
||||
}).collect();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user