Entropic 2.14.3
Local-first agentic inference engine
Loading...
Searching...
No Matches
expert_offload.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
45#pragma once
46
48
49#include <string>
50#include <vector>
51
52namespace entropic {
53
76constexpr const char* kExpertTensorRegex =
77 "\\.ffn_(up|down|gate|gate_up)_(ch|)exps";
78
93inline std::string expert_block_pattern(int layer) {
94 return "blk\\." + std::to_string(layer) + kExpertTensorRegex;
95}
96
119inline std::vector<std::string> expert_offload_patterns(int cpu_moe_layers) {
120 std::vector<std::string> patterns;
121 if (cpu_moe_layers <= 0) { return patterns; }
122 patterns.reserve(static_cast<std::size_t>(cpu_moe_layers));
123 for (int i = 0; i < cpu_moe_layers; ++i) {
124 patterns.push_back(expert_block_pattern(i));
125 }
126 return patterns;
127}
128
156 const int n = cfg.cpu_moe_layers;
157 std::string reason;
158 if (n < 0) {
159 reason = "cpu_moe_layers must be >= 0 (0 = off), got "
160 + std::to_string(n)
161 + ". There is no 'all layers' sentinel — name the layer "
162 "count you want host-side.";
163 } else if (n > 0 && cfg.gpu_layers == 0) {
164 reason = "cpu_moe_layers=" + std::to_string(n)
165 + " with gpu_layers: 0 — the whole model is already on the "
166 "host, so there are no expert tensors on the card to move "
167 "off it. Raise gpu_layers, or drop cpu_moe_layers.";
168 } else if (n > 0 && cfg.gpu_layers_auto) {
169 // v2.13.1: auto now derives the expert split ITSELF, from the GGUF's
170 // real expert-tensor bytes, and prefers moving experts host-side
171 // over dropping a layer. So this is no longer "auto cannot model
172 // this" — it is "you have asked for both, and only one can win".
173 reason = "cpu_moe_layers=" + std::to_string(n)
174 + " with gpu_layers: auto — auto derives the expert split "
175 "itself from the model's shape, so setting both asks two "
176 "things to decide one placement. Drop cpu_moe_layers and "
177 "let auto choose, or set gpu_layers to an explicit count "
178 "and keep your own split.";
179 }
180 return reason;
181}
182
207inline std::string expert_offload_load_refusal(int cpu_moe_layers,
208 int n_layer, int n_expert) {
209 std::string reason;
210 if (cpu_moe_layers <= 0) { return reason; }
211 if (n_expert <= 0) {
212 reason = "cpu_moe_layers=" + std::to_string(cpu_moe_layers)
213 + " was requested, but this model declares no experts "
214 "(<arch>.expert_count is absent or 0). Expert-tensor "
215 "offload has nothing to place; use gpu_layers to move "
216 "whole layers on a dense model.";
217 } else if (cpu_moe_layers > n_layer) {
218 reason = "cpu_moe_layers=" + std::to_string(cpu_moe_layers)
219 + " exceeds the model's " + std::to_string(n_layer)
220 + " layers. Lower it to at most " + std::to_string(n_layer)
221 + "; it is not clamped, because a count that cannot be "
222 "honoured is a configuration error, not a preference.";
223 }
224 return reason;
225}
226
227} // namespace entropic
Configuration structs with defaults.
Activate model on GPU (WARM → ACTIVE).
std::string expert_block_pattern(int layer)
The override pattern for ONE layer's expert tensors.
@ optional
optional: every escape asks the host's path approver
constexpr const char * kExpertTensorRegex
Tensor-name pattern tail identifying a layer's ROUTED-expert weights.
std::string expert_offload_conflict_reason(const ModelConfig &cfg)
Configuration-time refusal for a combination that cannot mean what it says.
std::vector< std::string > expert_offload_patterns(int cpu_moe_layers)
Patterns for the FIRST cpu_moe_layers layers, in layer order.
std::string expert_offload_load_refusal(int cpu_moe_layers, int n_layer, int n_expert)
Post-load refusal, against the numbers only the loaded model knows.
Model configuration for a single tier.
Definition config.h:154