llm-worker-rbee#
Candle-based Llama inference worker daemon
Created by: TEAM-000 (Foundation)
TEAM-009 Update: Complete rewrite using candle-transformers Llama directly
Overview#
llm-worker-rbee is a Llama inference worker with three feature-gated binaries:
TEAM-009 Implementation (Current)#
- ✅ Uses
candle-transformers::models::llama::Llamadirectly - ✅ Three binaries: CPU, CUDA, Metal
- ✅ SafeTensors model loading with VarBuilder
- ✅ HuggingFace tokenizers integration
- ✅ Streaming token generation with sampling
- ✅ Device residency logging
- ✅ Production-ready inference in ~340 lines
Why this approach? (TEAM-008 recommendation)
- 🚀 4-6 hours to working inference vs 20-30 hours building from scratch
- 🎯 Production-ready Llama implementation from Candle team
- ⚡ Optimized for GPU/CPU with GQA, RoPE scaling, quantization support
- 🔧 Minimal code - focus on worker integration, not layer implementation
Original Plan (TEAM-000)#
- Pure ndarray for CPU (checkpoint validation, educational value)
- Candle kernels for CUDA acceleration (optional, performance)
- Checkpoint-driven development
Status: TEAM-009 pivoted to use candle-transformers directly per TEAM-008 handoff
Architecture#
TEAM-009 Architecture (Current)#
┌─────────────────────────────────────────┐
│ llm-worker-rbee Worker │
├─────────────────────────────────────────┤
│ HTTP Server (worker-http) │
│ ├─ GET /health │
│ └─ POST /execute │
├─────────────────────────────────────────┤
│ CandleInferenceBackend (TEAM-009) │
│ ├─ candle-transformers::Llama │
│ ├─ tokenizers::Tokenizer │
│ ├─ Device (CPU/CUDA/Metal) │
│ └─ Sampling (greedy/temperature) │
├─────────────────────────────────────────┤
│ Model Loading │
│ ├─ SafeTensors: VarBuilder + mmap │
│ ├─ GGUF: Not yet implemented │
│ └─ Config: Default 7B (TODO: parse) │
├─────────────────────────────────────────┤
│ Compute Backend (feature-gated) │
│ ├─ CPU: Device::Cpu │
│ ├─ CUDA: Device::new_cuda(idx) │
│ └─ Metal: Device::Metal(id) (macOS) │
└─────────────────────────────────────────┘
Three Binaries#
| Binary | Feature | Device | Use Case |
|---|---|---|---|
llorch-cpu-candled | cpu | CPU | x86 Linux/Windows, macOS CPU |
llorch-cuda-candled | cuda | CUDA | NVIDIA GPU |
llorch-metal-candled | metal | Metal GPU | Apple Silicon GPU (macOS) |
Key Differences from llorch-cpud#
| Aspect | llorch-cpud | llm-worker-rbee (TEAM-009) |
|---|---|---|
| Model | GPT-2 Medium | Llama (any size) |
| Implementation | Custom layers | candle-transformers |
| Format | GGUF | SafeTensors (GGUF TODO) |
| Tokenizer | worker-tokenizer | HuggingFace tokenizers |
| Backends | CPU only | CPU/CUDA/Metal |
| Code size | ~2000 lines | ~340 lines |
Features#
TEAM-009 Implementation#
- ✅ Three backends: CPU, CUDA, Metal (feature-gated)
- ✅ SafeTensors loading: Memory-mapped for efficiency
- ✅ Streaming generation: Token-by-token with sampling
- ✅ Device residency: Logging to prevent RAM↔VRAM leaks
- ✅ Worker integration: Full worker-http + worker-common support
- ⏳ GGUF support: Deferred (use SafeTensors for now)
Original Features (TEAM-000)#
- Checkpoint-driven development: Each component validated independently
- Educational: Learn Llama architecture from scratch
- Worker crates integration: Reuses 99% of existing infrastructure
Quick Start#
TEAM-009 Update: Three feature-gated binaries using candle-transformers Llama directly.
Build#
CPU-only (x86, or fallback on macOS):
bashcd bin/llm-worker-rbeecargo build --release --features cpu --bin llorch-cpu-candled
CUDA (NVIDIA GPU):
bashcargo build --release --features cuda --bin llorch-cuda-candled
Metal (Apple Silicon GPU):
bashcargo build --release --features metal --bin llorch-metal-candled
Run#
Requirements:
- SafeTensors format model (GGUF not yet supported)
tokenizer.jsonin same directory as modelconfig.jsonin same directory as model
CPU:
bash./target/release/llorch-cpu-candled \--worker-id test-worker \--model /path/to/llama-2-7b/ \--port 8080 \--callback-url http://localhost:9999
CUDA:
bash./target/release/llorch-cuda-candled \--worker-id test-worker \--model /path/to/llama-2-7b/ \--port 8080 \--cuda-device 0 \--callback-url http://localhost:9999
Metal:
bash./target/release/llorch-metal-candled \--worker-id test-worker \--model /path/to/llama-2-7b/ \--port 8080 \--metal-device 0 \--callback-url http://localhost:9999
Test#
bash# Run all tests (CPU)cargo test --features cpu# Run TEAM-009 smoke testscargo test --test team_009_smoke --features cpu# Run with CUDA (requires GPU)cargo test --features cuda# Run ignored integration test (requires model)LLORCH_TEST_MODEL_PATH=/path/to/model cargo test test_device_residency_enforcement --features cpu -- --ignored
Development Roadmap#
Week 1: Foundation (Checkpoint 0)#
- Project structure
- HTTP server integration
- Worker crates wiring
- Compilation validation
Week 2: Core Layers#
- Checkpoint 1: RMSNorm
- Checkpoint 1B: RoPE
- Checkpoint 2: Separate QKV
- Checkpoint 3: KV Cache
- Checkpoint 6: SwiGLU
Week 3: Full Model#
- Checkpoint 4: Attention Scores
- Checkpoint 5: Attention Output
- Checkpoint 7: First Block
- Checkpoint 8: Full Logits
Week 4: Validation & Optimization#
- Checkpoints 9-11: Sampling
- Checkpoint 12: End-to-End
- CUDA kernel integration
- Performance benchmarking
Checkpoints#
All checkpoints are documented in .specs/checkpoints/:
| Checkpoint | Component | Status |
|---|---|---|
| 0 | Foundation Setup | ⬜ Not Started |
| 1 | RMSNorm | ⬜ Not Started |
| 1B | RoPE Application | ⬜ Not Started |
| 2 | QKV Projection | ⬜ Not Started |
| 3 | KV Cache | ⬜ Not Started |
| 4 | Attention Scores | ⬜ Not Started |
| 5 | Attention Output | ⬜ Not Started |
| 6 | SwiGLU FFN | ⬜ Not Started |
| 7 | First Block | ⬜ Not Started |
| 8 | Full Logits | ⬜ Not Started |
| 9 | Selected Logits | ⬜ Not Started |
| 10 | Argmax Sampling | ⬜ Not Started |
| 11 | Softmax Probs | ⬜ Not Started |
| 12 | End-to-End | ⬜ Not Started |
Dependencies#
Worker Crates (100% reusable)#
worker-common: SamplingConfig, InferenceResult, startup callbacksworker-http: HTTP server, SSE streaming, InferenceBackend traitworker-tokenizer: BPE tokenization, GGUF supportworker-models: Model configs and adaptersworker-gguf: GGUF file format parser
Compute#
ndarray: CPU tensor operations (primary)candle-kernels: CUDA kernels (optional, feature-gated)cudarc: CUDA runtime (optional, feature-gated)
Utilities#
tokio: Async runtime (single-threaded!)tracing: Structured loggingclap: CLI argument parsinganyhow,thiserror: Error handling
Candle Integration#
Following CANDLE_INTEGRATION_HANDOFF.md, we use kernels only:
What We Use ✅#
candle-kernels: Optimized CUDA kernels- RmsNorm (from
reduce.cu) - SiLU (from
unary.cu) - Quantization (from
quantized.cu)
- RmsNorm (from
What We DON'T Use ❌#
candle-core: Too much abstractioncandle-nn: We build our own layerscandle-transformers: Defeats learning purpose
Why This Approach?#
- ✅ Best performance (optimized CUDA kernels)
- ✅ Keep our architecture
- ✅ Keep checkpoint validation
- ✅ Educational value maintained
- ✅ Minimal dependencies
Testing#
Unit Tests#
bashcargo test --lib
Integration Tests#
bashcargo test --test '*'
Checkpoint Validation#
bash# Run specific checkpointcargo test checkpoint_01_rms_norm -- --nocapture# Compare with llama.cpp referencecargo test checkpoint_01_rms_norm -- --show-output
Benchmarks#
bashcargo bench --features benchmark
Performance#
CPU (ndarray)#
- Purpose: Validation, checkpoint testing
- Speed: ~10-20 tokens/sec (Llama-2 7B)
- Memory: ~7GB (Q8_0 model)
CUDA (Candle kernels)#
- Purpose: Production inference
- Speed: ~50-100 tokens/sec (depends on GPU)
- Memory: ~7GB VRAM (Q8_0 model)
References#
Documentation#
.specs/CANDLE_INTEGRATION_HANDOFF.md: Integration strategy.specs/checkpoints/: All checkpoint specificationsreference/candle/: Candle source codereference/mistral.rs/: Reference implementation
Related Workers#
llorch-cpud: GPT-2 CPU worker (predecessor)worker-orcd: Production GPU worker
Team#
TEAM-000 (Foundation)
- Mission: Build the foundation for all future workers
- Focus: Checkpoint-driven, educational, reusable
- Motto: "The foundation of them all"
License#
GPL-3.0-or-later
Contributing#
- Follow checkpoint-driven development
- Add TEAM-000 signatures to code changes
- Validate with reference implementation (llama.cpp)
- Keep CPU path working (CUDA is optional)
- Update checkpoint docs when needed
Status: 🚧 In Development
Version: 0.1.0
Last Updated: 2025-10-08

LLM Worker rbee
by rbee
v0.1.0
Install
Installation coming soon