(bencher: divan::Bencher, seq_len: usize)
| 354 | /// GPU transformer block: uses CudaBackend for all fused ops. |
| 355 | #[divan::bench(args = [1, 8, 64])] |
| 356 | fn transformer_block_forward_gpu(bencher: divan::Bencher, seq_len: usize) { |
| 357 | use cake_core::models::common::{Transformer, Cache}; |
| 358 | use std::collections::HashMap; |
| 359 | let dev = gpu_device(); |
| 360 | let cfg = super::bench_helpers::test_config(); |
| 361 | // Rebuild VarBuilder with tensors on GPU device |
| 362 | let h = cfg.hidden_size; |
| 363 | let head_dim = cfg.head_dim.unwrap_or(h / cfg.num_attention_heads); |
| 364 | let size_q = head_dim * cfg.num_attention_heads; |
| 365 | let size_kv = head_dim * cfg.num_key_value_heads; |
| 366 | let i = cfg.intermediate_size; |
| 367 | let mut map: HashMap<String, Tensor> = HashMap::new(); |
| 368 | map.insert("input_layernorm.weight".into(), Tensor::ones(h, DType::F32, &dev).unwrap()); |
| 369 | map.insert("post_attention_layernorm.weight".into(), Tensor::ones(h, DType::F32, &dev).unwrap()); |
| 370 | map.insert("self_attn.q_proj.weight".into(), make_gpu_tensor(&[size_q, h], 30)); |
| 371 | map.insert("self_attn.k_proj.weight".into(), make_gpu_tensor(&[size_kv, h], 31)); |
| 372 | map.insert("self_attn.v_proj.weight".into(), make_gpu_tensor(&[size_kv, h], 32)); |
| 373 | map.insert("self_attn.o_proj.weight".into(), make_gpu_tensor(&[h, size_q], 33)); |
| 374 | map.insert("mlp.gate_proj.weight".into(), make_gpu_tensor(&[i, h], 36)); |
| 375 | map.insert("mlp.up_proj.weight".into(), make_gpu_tensor(&[i, h], 37)); |
| 376 | map.insert("mlp.down_proj.weight".into(), make_gpu_tensor(&[h, i], 38)); |
| 377 | let vb = candle_nn::VarBuilder::from_tensors(map, DType::F32, &dev); |
| 378 | let backend = cake_core::backends::create_backend(&dev); |
| 379 | let block = Transformer::load_for_vibevoice(vb, &cfg, backend).unwrap(); |
| 380 | let mut cache = Cache::new(true, DType::F32, &cfg, &dev).unwrap(); |
| 381 | let x = make_gpu_tensor(&[1, seq_len, cfg.hidden_size], 800); |
| 382 | bencher.bench_local(|| block.forward_with_cache(&x, 0, 0, &mut cache).unwrap()); |
| 383 | } |
| 384 | |
| 385 | // ── Native dtype backend load benchmark ────────────────────────────── |
| 386 |
nothing calls this directly
no test coverage detected