Skip to content

perf(weights): index requested experts before scanning cached slots - #267

Closed
Afloat16 wants to merge 1 commit into
Edge0-AI:mainfrom
Afloat16:perf/expert-pool-hit-lookup
Closed

Afloat16 wants to merge 1 commit into
Edge0-AI:mainfrom
Afloat16:perf/expert-pool-hit-lookup

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

What & why

Each ExpertPool::prepare scans the cached slots separately for every requested expert, constructing the same gate binding key again inside that loop. A fully cached request still pays this demand-by-slot cost on every layer and decode step.

Build the requested gate-key index once and scan the published slots once. Keep the existing projection-consistency checks and protect every hit before choosing a replacement. The mappings remain in expert order, duplicate demand is still collapsed, and cache misses use the existing empty/LRU policy. Reserve the snapshot vector's known size as part of the same lookup path.

Area

  • Engine, CLI or server (edge0-infer/)

How was it tested?

Base bc2dc409d420097b4e864d511901180d7c2c6bac; Linux, GCC 14.2, CMake 4.4.5, CPU preset.

  • The new allocation regression uses 128 populated slots and 32 hits. Before: 4,539 main-thread allocations, failing the linear allocation budget. After: 995, with the same expert-to-slot mapping, all hits and no additional file reads. A long valid layer ID keeps the test keys outside small-string storage on both standard libraries.
  • A separate microbenchmark links the actual weight and execution libraries, uses layer 35, 128 populated slots and experts 96–127, warms 100 calls, then measures seven trials of 500 prepare + await_ready calls. Median time per call: 285.1 microseconds before, 57.5 microseconds after (4.96x). This measures that cached CPU operation, not end-to-end model throughput; timing is environment-dependent.
  • The existing slot test still passes hit protection, empty/LRU replacement, duplicate demand, pending/current preparation handling, group protection, isolation, and bitwise mul_mat_id comparison with resident weights.
  • CPU build passed. Full ctest --preset cpu -L "L0|L1" --output-on-failure -j 4: 97 passed, 3 Vulkan tests skipped, 4 existing failures. The failures are the previously reproduced moe_test_app_generation temporary-file environment issue, moe_test_platform_memory Linux expectation, and the extreme-float cases in moe_test_ordered_json / moe_test_template_tools.
  • Four CPU L2 checks passed: moe_test_weights_compute, moe_test_weights_group_compute, moe_test_edge0_35b_slots, and moe_test_edge0_35b_slots_failure. The tiny random-weight model was generated from the three source text files after their registered SHA-256 hashes passed. Its slot checks compare all cache/read modes and resident execution, with and without LoRA, across three prompts; tokens/logits remain bitwise equal. Failure checks verify writer draining, isolation and healthy reload.
  • Public CLI smoke: edge0-infer bench --model TINY/tiny-a --tokens tests/fixtures/answers/tiny-base-cpu-flash-split/chat-intro/tokens.json --device cpu --threads 2 --prefill-threads 2 --warmup 2 --ntok 8 --runs 2 --model-option routing=actual. Selected summary fields below are from the random-weight tiny fixture, not a 35B measurement or a before/after throughput comparison:
{"type":"summary","runs":2,"input_count":17,"prefill_seconds":0.027988131,"decode_seconds":0.047301014,"decode_forwards":16,"decode_tokens_per_second":338.2591333031465,"cpu_threads":2,"cpu_prefill_threads":2}
  • git diff --check passed. GPU/device execution and the real 35B model were not available.

Checklist

  • Added a bounded-allocation regression with mapping and read-count controls.
  • Ran CPU L0/L1 and affected L2 computation/failure checks.
  • Measured the changed operation against the unmodified base.
  • Full L0/L1 is green (four existing failures above).
  • Real-model/device performance has been measured (CPU microbenchmark and tiny functional checks only).

@shuk777

shuk777 commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Closing as part of clearing this pre-hygiene queue; see #298 (comment) for the note on the updated review process. Thank you again.

@shuk777 shuk777 closed this Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants