Skip to content

CUDA BF16 MoE resident cache reuses stale pointers after engine teardown #237

Description

@richiejp

Problem

Repeated LoadedEngine construction and destruction in one CUDA process can reuse a MoeBlockWeights address while MoeBf16ResidentFor retains the previous engine's device-pointer array in a process-lifetime static map. A later engine can therefore execute the BF16 fast MoE path with stale resident pointers.

Reproduction

On current main plus issue #206's exact pretokenized benchmark fixture, run the focused tests in this order:

nix develop .#cuda -c ctest --test-dir build-nix-cuda \
  -R '^(test_engine_core_proc|test_async_llm|test_bench|test_gdn_decode_fused|test_gdn_prefill_conv|test_ops_gdn)$' \
  --output-on-failure

The ordered suite intermittently fails test_bench: later synthetic Qwen3.5 engines emit corrupted or zero output-token IDs. The target case alone passed 50/50. Setting VT_MOE_BF16_FAST=0 made the full test_bench suite pass 50/50, isolating the fault to the fast resident-weight path.

Expected

Resident CUDA MoE state must be owned by, or invalidated with, the engine/weights lifetime. Recreating an engine in the same process must never reuse stale device pointers, and the default fast path must remain enabled.

Scope

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions