Skip to content

Commit 17313a4

Browse files
Fix cuda memory error for Qwen3 non-quantized (huggingface#2987)
* Update KvCache initialization in Qwen3 model to use a fixed max position embedding value of 512 * add doc
1 parent 0224a74 commit 17313a4

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

candle-transformers/src/models/qwen3.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ impl Qwen3Attention {
157157
// Necessary because the hidden_size in the config isn't always accurate
158158
let hidden_size = head_dim * cfg.num_attention_heads;
159159

160-
let kv_cache = KvCache::new(2, cfg.max_position_embeddings);
160+
// Initialize KV cache with 512 tokens capacity to reduce initial memory allocation.
161+
// The cache will grow in chunks of 512 tokens when needed.
162+
let kv_cache = KvCache::new(2, 512);
161163

162164
Ok(Self {
163165
q_proj,

0 commit comments

Comments
 (0)