From efb0ae7ed3ad099975ae1b86b35db4e1441b1b78 Mon Sep 17 00:00:00 2001 From: OceanLi <122793010+ohdearquant@users.noreply.github.com> Date: Mon, 6 Jul 2026 13:16:24 -0400 Subject: [PATCH] fix(ruvllm): detect tied word embeddings for Llama 3.2 in candle backend Llama 3.2 1B/3B tie the output projection to the input embeddings, so the checkpoint has no separate lm_head.weight tensor. The candle backend hardcoded tie_word_embeddings: false, which fails to load these models. Detect the tie from tensor presence instead. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/ruvllm/src/backends/candle_backend.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/ruvllm/src/backends/candle_backend.rs b/crates/ruvllm/src/backends/candle_backend.rs index 758effcd1f..5c46427d38 100644 --- a/crates/ruvllm/src/backends/candle_backend.rs +++ b/crates/ruvllm/src/backends/candle_backend.rs @@ -886,6 +886,10 @@ mod candle_impl { LoadedModelInner::Mistral(model) } ModelArchitecture::Llama => { + // Llama 3.2 1B/3B tie the output projection to the input + // embeddings (no lm_head.weight tensor in the checkpoint); + // detect from tensor presence instead of hardcoding. + let tie_word_embeddings = !vb.contains_tensor("lm_head.weight"); let llama_config = llama_model::Config { hidden_size, intermediate_size, @@ -900,7 +904,7 @@ mod candle_impl { eos_token_id: None, rope_scaling: None, max_position_embeddings: config.max_sequence_length, - tie_word_embeddings: false, + tie_word_embeddings, }; let model = llama_model::Llama::load(vb, &llama_config).map_err(|e| {