fix(engine): offload Gemma to GPU by setting n_gpu_layers=999 (#833)

LlamaModelParams::default() sets n_gpu_layers=0, so even with --features
rocm the model ran entirely on CPU at ~19 t/s. Setting n_gpu_layers to a
large sentinel value asks llama.cpp to offload every layer the model
has; llama.cpp clamps to the real count (27 for Gemma 2 2B). Observed
throughput jumps from 19 t/s to 74 t/s on an RX 9070 once the ROCm
binary is also compiled for gfx1201 (see tooling commit).

Also adds server/sr-voice/.gitignore so locally-built binaries don't
sneak into the worktree. Release binaries ship out-of-tree per #850.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-15 23:11:14 +02:00
co-authored by Claude Opus 4.6
parent fddb8b7544
commit cf8a4e37d8
2 changed files with 13 additions and 1 deletions
+4
View File
@@ -0,0 +1,4 @@
# Built binaries — platform-specific, rebuilt via distrobox + cargo.
# Per #850, release binaries will ship as CI artifacts, not in the repo.
/bin/
/target/
+9 -1
View File
@@ -39,11 +39,19 @@ pub struct InferenceEngine {
impl InferenceEngine {
/// Load a GGUF model from disk.
///
/// Offloads all layers to the GPU via ROCm. The binary is built with
/// llama-cpp-rs + ROCm support (see Makefile `build-sr-voice` target),
/// but `LlamaModelParams::default()` sets `n_gpu_layers = 0`, which
/// runs the entire model on CPU at ~10× lower throughput. Setting
/// `n_gpu_layers` to a large sentinel value (999) asks llama.cpp to
/// offload every layer the model has; it clamps to the real count.
/// For Gemma 2 2B (27 layers) this fully GPU-offloads the model.
pub fn load(config: &InferenceConfig) -> Result<Self, VoiceError> {
let backend =
LlamaBackend::init().map_err(|e| VoiceError::ModelLoadFailed(e.to_string()))?;
let model_params = LlamaModelParams::default();
let model_params = LlamaModelParams::default().with_n_gpu_layers(999);
let model = LlamaModel::load_from_file(
&backend,
Path::new(&config.model_path),