[GH-ISSUE #4445] [Engine] RAZOR #1983

Closed
opened 2026-11-04 01:55:46 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @ladno64 on GitHub (Oct 28, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4445

[Engine] Runtime expert exclusion with per-workload masks

Problem

Strata currently keeps every expert resident somewhere — all 24,576 experts are pinned in RAM (or in the low-RAM mirror), and the expert cache only decides which subset also sits in VRAM. This is the right default for a general-purpose inference engine, but it creates a hard floor on host memory and on SSD traffic that many workloads do not actually need.

For domain-specific deployments (code-only, chat-only, a single-language assistant, an embedded appliance), a large fraction of experts are never routed on the target distribution. Yet Strata still allocates RAM for them, still includes them in the placement plan, and still carries them in the checkpoint footprint. The only way to shed that cost today is to prune the checkpoint offline with a method like RAZOR — which is irreversible, degrades quality globally, and requires a separate checkpoint per domain.

A second, smaller problem: even the "faster answers on 12 GB cards" change, where the router prefers experts already on the card, still assumes every expert is reachable in RAM. It reduces page-ins, not the resident set.

Proposal

Add an opt-in runtime expert exclusion mode. The user supplies a per-layer mask of excluded experts. Excluded experts are:

· not loaded into VRAM,
· not pinned in RAM (or included in the low-RAM mirror),
· not read from SSD during decode.

The checkpoint is not modified. The router applies the mask before top-k: logits of excluded experts are set to -inf, and a configurable fallback restores a valid top-k. Because the mask is external and reversible, the same checkpoint can serve different profiles (code, chat, medical, edge) by switching the mask file.

This is deliberately not a silent change. It is off by default, it is explicit in configuration, and it is reported in the placement plan and at startup. That keeps it consistent with Strata's stated invariants — "precision, routing, expert count and top-k come from the checkpoint and never change silently" — because the exclusion is user-declared, not inferred.

Mechanism

  1. Mask file. A JSON file maps layer indices to excluded expert indices:
    {
      "layer_0": [3, 7, 12, 45],
      "layer_1": [2, 8, 19],
      "...": []
    }
    
  2. Router masking. Before top-k, excluded logits are set to -inf. This belongs in the router path, upstream of the expert-source contract that include/strata/core/expert_source.hpp already documents between the session loop, the router and the CPU pool.
  3. Fallback. One of:
    · renormalize — renormalize the surviving selected experts;
    · refill — promote the next candidate by rank and renormalize (the same semantics RAZOR models during saliency);
    · shared — route the token to the shared expert;
    · skip — skip the expert contribution (not recommended; provided only for controlled experiments).
  4. Placement. expert_layout and expert_cache skip excluded (layer, expert) pairs entirely. They never enter the admission plan, the pinned RAM mirror, or the VRAM cache. This is the part that turns the mask into actual memory savings.
  5. Reporting. The startup placement plan and the JSON admission report (--admission-only --json) should show excluded counts per layer and the effective expert count, so the user can see exactly what was dropped.

Configuration

{
  "expert_exclusion": {
    "enabled": true,
    "fallback": "refill",
    "mask_file": "masks/code_profile.json"
  }
}

CLI equivalent (naming to be aligned with docs/cli.md):

--exclude-experts masks/code_profile.json --exclude-fallback refill

Why this belongs in Strata rather than a fork

· It composes with the existing tiers. The expert cache, the low-RAM mode and the CPU pool already treat (layer, expert) as the unit of placement. Exclusion is the natural fourth state: resident, cached, streamed, excluded.
· It preserves the checkpoint contract. Strata already refuses to silently cut experts or top-k. A user-supplied mask is explicit and auditable, which is the opposite of silent degradation.
· It is reversible. A fork that prunes weights cannot A/B the same checkpoint across domains; a mask can.
· It targets the RAM floor, not just VRAM. The expert cache already addresses VRAM pressure. Exclusion addresses the host-memory floor and SSD read volume, which the cache does not.

Tradeoffs and risks

· Quality. If the mask excludes an expert that the target distribution actually needs, quality drops. This is the same loss as pruning those experts offline, because the fallback computes what the pruned model would compute. The difference is that the loss is scoped to a profile and reversible.
· Fallback correctness. refill and renormalize must match the semantics used during calibration, or the measured quality will not transfer. This should be documented and covered by tests.
· Shared experts. The shared expert should probably be excluded from masking by default, but the decision needs to be explicit.
· Low-RAM mode interaction. In low-RAM mode only the non-VRAM experts are pinned; exclusion must compose cleanly with that set arithmetic.
· Quantization and MTP. Exclusion should be orthogonal to weight quantization and to the MTP draft layer, but this needs verification on at least one quantized checkpoint.

Calibration (optional, but expected in practice)

A small tool that runs a corpus through the existing saliency-style forward pass and emits a mask file:

strata-calibrate-exclusion \
  --model /path/to/checkpoint \
  --data path/to/corpus.json \
  --threshold 0.0001 \
  --out masks/my_profile.json

This does not need to be part of the first PR; a hand-written mask plus documentation is enough to prove the mechanism.

Suggested implementation plan

  1. Parse and validate the mask file; add it to the configuration schema.
  2. Apply masking in the router before top-k; implement renormalize and refill first, gate shared and skip behind explicit flags.
  3. Teach expert_layout / expert_cache to skip excluded pairs and to report excluded counts in the placement plan.
  4. Add a calibration helper (can be a follow-up PR).
  5. Documentation: mask format, fallback semantics, interaction with low-RAM mode, measured memory savings on Qwen3.8-Flash-Next.

Alternatives considered

· Offline pruning (RAZOR-style). Rejected for the default path: irreversible, global, one checkpoint per domain. Still valid as an external preprocessing step for users who want the smaller checkpoint.
· Router bias only (prefer on-card experts). Already present for 12 GB cards; it reduces page-ins but keeps every expert resident in RAM. It does not address the RAM floor.
· Rely on --stream-experts or SSD streaming alone. These keep the full expert set reachable; they trade RAM for latency but do not let a workload fit on a machine that cannot hold the full set at all.

Open questions for maintainers

  1. Is per-deployment masking enough, or is per-request masking (different masks in one batch) expected? I would start with per-deployment.
  2. Should the shared expert be maskable? My default would be no.
  3. Where should the mask live: engine config, a separate file referenced by config, or both?
  4. Is there an existing saliency/activation-counting path in expert_source that a calibration helper could reuse, or would it need a new forward-only harness?
Originally created by @ladno64 on GitHub (Oct 28, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4445 [Engine] Runtime expert exclusion with per-workload masks Problem Strata currently keeps every expert resident somewhere — all 24,576 experts are pinned in RAM (or in the low-RAM mirror), and the expert cache only decides which subset also sits in VRAM. This is the right default for a general-purpose inference engine, but it creates a hard floor on host memory and on SSD traffic that many workloads do not actually need. For domain-specific deployments (code-only, chat-only, a single-language assistant, an embedded appliance), a large fraction of experts are never routed on the target distribution. Yet Strata still allocates RAM for them, still includes them in the placement plan, and still carries them in the checkpoint footprint. The only way to shed that cost today is to prune the checkpoint offline with a method like RAZOR — which is irreversible, degrades quality globally, and requires a separate checkpoint per domain. A second, smaller problem: even the "faster answers on 12 GB cards" change, where the router prefers experts already on the card, still assumes every expert is reachable in RAM. It reduces page-ins, not the resident set. Proposal Add an opt-in runtime expert exclusion mode. The user supplies a per-layer mask of excluded experts. Excluded experts are: · not loaded into VRAM, · not pinned in RAM (or included in the low-RAM mirror), · not read from SSD during decode. The checkpoint is not modified. The router applies the mask before top-k: logits of excluded experts are set to -inf, and a configurable fallback restores a valid top-k. Because the mask is external and reversible, the same checkpoint can serve different profiles (code, chat, medical, edge) by switching the mask file. This is deliberately not a silent change. It is off by default, it is explicit in configuration, and it is reported in the placement plan and at startup. That keeps it consistent with Strata's stated invariants — "precision, routing, expert count and top-k come from the checkpoint and never change silently" — because the exclusion is user-declared, not inferred. Mechanism 1. Mask file. A JSON file maps layer indices to excluded expert indices: ```json { "layer_0": [3, 7, 12, 45], "layer_1": [2, 8, 19], "...": [] } ``` 2. Router masking. Before top-k, excluded logits are set to -inf. This belongs in the router path, upstream of the expert-source contract that include/strata/core/expert_source.hpp already documents between the session loop, the router and the CPU pool. 3. Fallback. One of: · renormalize — renormalize the surviving selected experts; · refill — promote the next candidate by rank and renormalize (the same semantics RAZOR models during saliency); · shared — route the token to the shared expert; · skip — skip the expert contribution (not recommended; provided only for controlled experiments). 4. Placement. expert_layout and expert_cache skip excluded (layer, expert) pairs entirely. They never enter the admission plan, the pinned RAM mirror, or the VRAM cache. This is the part that turns the mask into actual memory savings. 5. Reporting. The startup placement plan and the JSON admission report (--admission-only --json) should show excluded counts per layer and the effective expert count, so the user can see exactly what was dropped. Configuration ```json { "expert_exclusion": { "enabled": true, "fallback": "refill", "mask_file": "masks/code_profile.json" } } ``` CLI equivalent (naming to be aligned with docs/cli.md): ```bash --exclude-experts masks/code_profile.json --exclude-fallback refill ``` Why this belongs in Strata rather than a fork · It composes with the existing tiers. The expert cache, the low-RAM mode and the CPU pool already treat (layer, expert) as the unit of placement. Exclusion is the natural fourth state: resident, cached, streamed, excluded. · It preserves the checkpoint contract. Strata already refuses to silently cut experts or top-k. A user-supplied mask is explicit and auditable, which is the opposite of silent degradation. · It is reversible. A fork that prunes weights cannot A/B the same checkpoint across domains; a mask can. · It targets the RAM floor, not just VRAM. The expert cache already addresses VRAM pressure. Exclusion addresses the host-memory floor and SSD read volume, which the cache does not. Tradeoffs and risks · Quality. If the mask excludes an expert that the target distribution actually needs, quality drops. This is the same loss as pruning those experts offline, because the fallback computes what the pruned model would compute. The difference is that the loss is scoped to a profile and reversible. · Fallback correctness. refill and renormalize must match the semantics used during calibration, or the measured quality will not transfer. This should be documented and covered by tests. · Shared experts. The shared expert should probably be excluded from masking by default, but the decision needs to be explicit. · Low-RAM mode interaction. In low-RAM mode only the non-VRAM experts are pinned; exclusion must compose cleanly with that set arithmetic. · Quantization and MTP. Exclusion should be orthogonal to weight quantization and to the MTP draft layer, but this needs verification on at least one quantized checkpoint. Calibration (optional, but expected in practice) A small tool that runs a corpus through the existing saliency-style forward pass and emits a mask file: ```bash strata-calibrate-exclusion \ --model /path/to/checkpoint \ --data path/to/corpus.json \ --threshold 0.0001 \ --out masks/my_profile.json ``` This does not need to be part of the first PR; a hand-written mask plus documentation is enough to prove the mechanism. Suggested implementation plan 1. Parse and validate the mask file; add it to the configuration schema. 2. Apply masking in the router before top-k; implement renormalize and refill first, gate shared and skip behind explicit flags. 3. Teach expert_layout / expert_cache to skip excluded pairs and to report excluded counts in the placement plan. 4. Add a calibration helper (can be a follow-up PR). 5. Documentation: mask format, fallback semantics, interaction with low-RAM mode, measured memory savings on Qwen3.8-Flash-Next. Alternatives considered · Offline pruning (RAZOR-style). Rejected for the default path: irreversible, global, one checkpoint per domain. Still valid as an external preprocessing step for users who want the smaller checkpoint. · Router bias only (prefer on-card experts). Already present for 12 GB cards; it reduces page-ins but keeps every expert resident in RAM. It does not address the RAM floor. · Rely on --stream-experts or SSD streaming alone. These keep the full expert set reachable; they trade RAM for latency but do not let a workload fit on a machine that cannot hold the full set at all. Open questions for maintainers 1. Is per-deployment masking enough, or is per-request masking (different masks in one batch) expected? I would start with per-deployment. 2. Should the shared expert be maskable? My default would be no. 3. Where should the mask live: engine config, a separate file referenced by config, or both? 4. Is there an existing saliency/activation-counting path in expert_source that a calibration helper could reuse, or would it need a new forward-only harness?
Author
Owner

@github-actions[bot] commented on GitHub (Oct 28, 2026):

Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing:

  • Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] decode stops after 2 minutes".

Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment /reopen.

Details: CONTRIBUTING.md

<!-- gh-comment-id:6466935765 --> @github-actions[bot] commented on GitHub (Oct 28, 2026): Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing: - [ ] Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] decode stops after 2 minutes". Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment `/reopen`. Details: [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md)
Author
Owner

@github-actions[bot] commented on GitHub (Oct 28, 2026):

Thanks, this follows the format now.

<!-- gh-comment-id:6467129401 --> @github-actions[bot] commented on GitHub (Oct 28, 2026): Thanks, this follows the format now.
Author
Owner

@Niko1221 commented on GitHub (Nov 5, 2026):

Thanks for taking the time to report this.

Strata has changed a lot since this was opened, and 0.2.11 is out now, so many older reports no longer apply. We're closing issues older than a week that have had no new reports in the last week. Closed here does not mean rejected.

To reopen it takes about two minutes:

  1. Re-test on 0.2.11. It may already be fixed. Write down what you see.
  2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other].
  3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system.
  4. Comment /reopen. A check runs and either reopens the issue or lists what is still missing.

The rules are in CONTRIBUTING.md.

<!-- gh-comment-id:6660449047 --> @Niko1221 commented on GitHub (Nov 5, 2026): Thanks for taking the time to report this. Strata has changed a lot since this was opened, and 0.2.11 is out now, so many older reports no longer apply. We're closing issues older than a week that have had no new reports in the last week. Closed here does not mean rejected. To reopen it takes about two minutes: 1. Re-test on 0.2.11. It may already be fixed. Write down what you see. 2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other]. 3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system. 4. Comment `/reopen`. A check runs and either reopens the issue or lists what is still missing. The rules are in [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#1983
No description provided.