﻿# llama.cpp prefetch repair: a cache bank can be allocated before its contents are ready

The b12328 prefetch fix preserves expert-bank write ordering and rejects an unsupported cached matmul path instead of using stale data.

Author: Retrivium team
Updated: 2026-11-15
Canonical URL: https://retrivium.ai/journal/week46-engine-moe-prefetch-before-callback-write/
Language: en

llama.cpp b12328 restricts scheduler prefetch to inputs computed by earlier splits and guards MoE-cache use by operation support. Upstream explains a stale-expert read caused by prefetch running before a copy callback uploaded missed experts. This is a producer-ordering problem, not simply a shortage of memory bandwidth.

## A valid address can contain old experts

The PR describes the next split’s bank being read before the current split’s callback uploaded the required experts. The address and allocation could be valid while the contents belonged to an earlier state. Bounds checking alone cannot detect that semantic mismatch. The changed prefetch policy narrows which tensors are read early, preserving the intended relationship between production of data and its consumption by another backend.

## Capability checks affect the route

Upstream also checks whether the cache device supports the cached MUL_MAT_ID operation and uses an uncached path otherwise. That matters because a fallback can turn a device bank into an input of a different backend’s split, exposing the ordering issue. Treating every successful allocation as proof that the cache device can execute the full cached operation is insufficient. Capability and memory placement must agree with the scheduled computation.

## Force a change in cached contents

A proposed regression should alternate selections that require different experts, ensuring that a stale bank differs from the expected bank. Repeating one already-cached selection can hide the defect. Include a supported cache-device configuration and a deliberately unsupported operation route where test facilities allow it. Compare numerical outputs with the uncached reference, then use scheduling traces to explain any mismatch rather than judging only whether execution completes.

## Reported evidence and proposed checks

The PR contains upstream scheduler and architecture tests demonstrating the repaired case. Those are attributed upstream results, not measurements newly performed here. A local deployment still needs its own device and graph coverage, especially when fallback support differs. The release is valuable because it ties a numerical error to a concrete ordering boundary and supplies a safer route when the cache operation cannot run on its assigned device. Keep a case where the missed expert's new weights differ substantially from the previous resident expert. If old and new bank contents happen to match, even a consistently premature prefetch can pass the numerical test and hide the ordering defect.

## Sources

- [llama.cpp b12328 release](https://github.com/ggml-org/llama.cpp/releases/tag/b12328)
- [llama.cpp pull request #32100](https://github.com/ggml-org/llama.cpp/pull/32100)

## Related reading

- [CUDA event dependencies: connecting producer and consumer streams](/journal/learn-cross-stream-event-dependency/)
- [ONNX Runtime provider order: graph partition priority is not request failover](/journal/fg2-onnxruntime-provider-priority-subgraph-partition/)
