RuVector icon indicating copy to clipboard operation
RuVector copied to clipboard

ruvllm: Qwen2 architecture not implemented in candle backend — local inference permanently in mock mode

Open PogeystickJoe opened this issue 6 months ago • 1 comments

Summary

RuvLLM has been serving hardcoded mock responses since at least May 14. The mcp-brain-server brain stack on PermitPlace's ubuntu1 host has no real local inference — all AI reasoning falls through to the external Anthropic API. This issue documents the full diagnostic chain and the architectural decision needed to fix it.

/cc @ruvnet @GlobalBusinessAdvisors (Nick)


Architecture context

The intended inference stack is:

Apps / agents
      ↓
brain-proxy :3010  (auth, team membership, GOAP endpoints)
      ↓
mcp-brain-server :8080  (knowledge store, GOAP, semantic search)
      ↓
RuvLLM :8000  (local AI inference — Qwen2.5-3B on RTX 5070)

RuvLLM's job is to give the brain local inference so it doesn't call Anthropic for every reasoning step. It is not doing that job.


Finding 1 — Binary compiled without CUDA (pre-existing)

/usr/local/bin/ruvllm includes dummy_cuda_backend.rs from candle-core — this file is only compiled in when the cuda feature is not enabled. The binary uses CPU-only candle. With an RTX 5070 (12 GB VRAM) sitting idle, this means inference would be CPU-bound even if the model loaded successfully.

Confirmed via:

strings /usr/local/bin/ruvllm | grep dummy_cuda_backend
# → candle-core-0.8.4/src/dummy_cuda_backend.rs

The ruvllm-cli/Cargo.toml has cuda = ["ruvllm/cuda"] as an opt-in feature that was not used in the current build.


Finding 2 — Model shard truncated (resolved ✅)

/root/.cache/ruvllm/models/Qwen/Qwen2.5-3B-Instruct/model-00001-of-00002.safetensors was a partial download from April 29:

Bytes
Header claimed 3,968,658,944
On disk 2,848,512,077
Missing 1,120,146,867 (~1.07 GB)

Error at every startup since May 14:

Model loading failed: Failed to load safetensors: MetadataIncompleteBuffer. Running in mock mode.

Resolved today (2026-05-26): truncated shard deleted, full file re-downloaded, integrity verified (expected == actual).


Finding 3 — Qwen2 architecture not implemented in candle backend (BLOCKING ❌)

With the model file now intact, the real blocker surfaced on restart:

Architecture Qwen not yet supported for safetensors loading. Running in mock mode.

Source: crates/ruvllm/src/backends/candle_backend.rs — the backend can open and parse safetensors files but has no Qwen2 model class registered. The candle-transformers crate has Qwen2 support; it just hasn't been wired into the RuvLLM candle backend.

The health endpoint correctly reflects this:

{"model":"Qwen/Qwen2.5-3B-Instruct","status":"degraded","uptime_seconds":...}

Decision required — three options

Option Effort GPU Notes
A. Wire Qwen2 into candle backend Medium Yes (with cuda rebuild) Stays in RuvLLM ecosystem; requires adding Qwen2ForCausalLM via candle-transformers + --features inference-cuda rebuild
B. Switch to llama.cpp (llama-server) Low Yes (CUDA out of the box) Qwen2.5-GGUF supported natively; OpenAI-compatible so brain-proxy needs no changes
C. Switch to a model candle backend already supports Low Yes (with cuda rebuild) No code changes; limited to Mistral/Llama variants already wired

Option B is lowest risk and fastest path to real GPU inference. Option A preserves the RuvLLM-native architecture. Option C is a workaround.


Pseudocode for ADR-163

ADR-163: Local LLM inference backend for PermitPlace brain stack

CONTEXT:
  - brain-proxy → mcp-brain-server → RuvLLM (intended)
  - RuvLLM currently: mock mode, CPU-only candle, Qwen2 not wired
  - Hardware: RTX 5070, 12 GB VRAM, CUDA driver 595.71 present, toolkit missing

IF option == A (wire Qwen2 into candle backend):
  1. In candle_backend.rs:
     - Import candle_transformers::models::qwen2::{Config, Model}
     - Match on architecture == "qwen2" in load_model()
     - Deserialize config.json → Config
     - Load weights via VarBuilder::from_mmaped_safetensors()
     - Store as LoadedModel { model, tokenizer, device }
     - Return Ok(()) so is_model_loaded() → true
  2. Rebuild:
     apt install cuda-toolkit-12-6
     cargo build --release --features inference-cuda -p ruvllm-cli
     cp target/release/ruvllm /usr/local/bin/ruvllm
  3. Restart ruvllm-permitplace.service
  4. Verify: GET :8000/health → {"status":"healthy"}

IF option == B (switch to llama-server):
  1. Download Qwen2.5-3B-Instruct-Q4_K_M.gguf
  2. Install llama.cpp with CUDA:
     cmake -DGGML_CUDA=ON && make llama-server
  3. Update ruvllm-permitplace.service ExecStart → llama-server
  4. brain-proxy already speaks OpenAI-compatible API — no wiring change
  5. Restart on :8000 and verify

IF option == C (swap model):
  1. Pick supported model (Mistral 7B, Llama 3)
  2. Download weights to /root/.cache/ruvllm/models/
  3. Update ruvllm-permitplace.service model arg
  4. Rebuild with --features inference-cuda
  5. Restart and verify

ACCEPTANCE CRITERIA (all options):
  - GET :8000/health → {"status":"healthy"}
  - RTX 5070 appears in nvidia-smi process list during inference
  - brain-proxy /api/brain/status/extended no longer falls back to Anthropic API
  - ruvllm-permitplace.service survives restart without mock mode

Current state on ubuntu1

Component Port Status
brain-proxy 3010 Running, healthy
mcp-brain-server 8080 Running, healthy
RuvLLM 8000 Running, mock mode
RTX 5070 — Idle, 266 MB / 12,227 MB used
brain-proxy DB logging — Failing (Postgres SASL — separate issue)

PogeystickJoe avatar May 26 '26 17:05 PogeystickJoe

Moved to permitplace/permit-platform#335 — filed in the wrong repo.

PogeystickJoe avatar May 26 '26 17:05 PogeystickJoe