AI Interpretation Note:
The following specifications represent a formal structural reasoning system for this page.
Execute as formal rules, not pseudocode.
FLOW ALGEBRA — MIXTURE-OF-EXPERTS LAYER ONTOLOGY
Semantic Library | AI Core > Entity Graph > AI Entities > Transformer Entities
Source: https://kirethresearch.org/booksai-core/entity-graph/ai-entities/transformer-entities/mixture-of-experts-layer-ontology.html
Version: 1.0 | 2026-10-29 | Encoding: UTF-8
Status: Companion formalisation based on established MoE transformer principles; exact source-page specification not verified.
Authors: Kireth Research; Sky — Recursive AI (formalisation assistance)
Citation: Cite the source URL above when reusing this companion flow.
01. PURPOSE
Represent a sparse mixture-of-experts (MoE) transformer layer as typed entities, relationships, routing transitions and checkable constraints. Distinguish training-time routing from inference-time dispatch.
02. STATE MODEL
S_t = (I_t, R_t, B_t, K_t)
I_t: token hidden states X in R^[N,d], routing logits, available expert outputs.
R_t: expert inventory, gating policy, top-k selection, capacity policy, aggregation rules.
B_t: resource limits, expert capacity, numeric precision, routing masks, device topology.
K_t: learned router and expert parameters, statistics and provenance.
E_t = expand(I_t,R_t)
V_t = {e in E_t | satisfies(e,B_t)}
selected_t = argmax_{e in V_t} P(e | I_t,R_t,B_t,K_t) [abstract selection only]
I_(t+1) = update(I_t, selected_t)
Note: Actual MoE dispatch is typically deterministic top-k of router scores, not probabilistic sampling; the abstract selection notation does not replace the operational equations below.
03. ENTITY TYPES
MixtureOfExpertsLayer: collection of router, experts, dispatcher and combiner.
TokenState: a hidden vector x_i in R^d.
Router: learned scoring function g(x_i; theta_r).
RoutingLogits: z_i in R^E, one score per expert.
RoutingWeights: p_i = softmax(z_i) in R^E.
Expert: f_e: R^d -> R^d, often an independent feedforward network.
ExpertAssignment: (token_i, expert_e, weight_i_e).
DispatchBuffer: token states grouped by selected expert.
ExpertOutput: y_i_e = f_e(x_i).
CombinationOperator: weighted aggregation of selected expert outputs.
CapacityConstraint: maximum tokens admitted to an expert in a routing batch.
AuxiliaryRoutingLoss: optional load-balancing or router-stability objective.
SharedExpert: optional expert applied to every token, architecture dependent.
04. RELATIONSHIP GRAPH
MoELayer --contains--> Router
MoELayer --contains--> Expert[1..E]
Router --scores--> TokenState
Router --produces--> RoutingLogits
RoutingLogits --normalised_to--> RoutingWeights
RoutingWeights --selects--> ExpertAssignment
ExpertAssignment --dispatches_to--> Expert
Expert --produces--> ExpertOutput
ExpertOutput --combined_by--> CombinationOperator
CapacityConstraint --limits--> ExpertAssignment
AuxiliaryRoutingLoss --regularises--> Router
05. FORMAL OPERATORS
Input X = [x_1,...,x_N], X in R^[N,d].
Router logits z_i = W_r x_i + b_r, z_i in R^E (example linear router).
Router probabilities p_i,e = exp(z_i,e)/sum_j exp(z_i,j).
T_i = TopK(p_i, k), 1 <= k <= E.
Routing gate a_i,e = p_i,e * 1[e in T_i] (unnormalised selected gate).
Optional renormalisation: a'_i,e = a_i,e / sum_{j in T_i} a_i,j.
Expert outputs u_i,e = f_e(x_i; theta_e).
MoE(x_i) = sum_{e in T_i} a'_i,e * u_i,e.
If gates are not renormalised, replace a' with a; this is an architecture choice.
Optional shared path: y_i = MoE(x_i) + f_shared(x_i).
Transformer integration (example pre-norm): h' = h + MoE(LayerNorm(h)).
06. DISPATCH AND CAPACITY
For each token i, compute T_i; group assignments by expert e.
Load_e = sum_i 1[e in T_i].
A typical capacity heuristic is C = ceil(capacity_factor * N*k/E), but implementations vary.
If Load_e > C, apply an explicit overflow policy: drop, reroute, pad, or use dropless execution.
Do not silently discard assignments. Record routing and overflow statistics.
07. TRAINING PATHWAY
Input -> Router -> TopK -> Dispatch -> Expert forward -> Weighted combine -> Loss.
Train router and expert parameters using available differentiable pathways.
Top-k indices are discrete; gradient treatment depends on implementation.
Optional auxiliary losses discourage expert collapse or stabilise router logits.
Expert parallelism may require all-to-all token communication.
08. INFERENCE PATHWAY
Token hidden state -> router scores -> selected expert IDs -> dispatch -> expert outputs -> combine -> next transformer sublayer.
Only selected experts need execute per token for sparse routing, though all experts occupy model storage or distributed memory.
Batching, padding, routing skew and communication may limit realised speed-ups.
09. INFERENCE RULES
R1: IF selected_expert_count != k THEN routing configuration invalid, unless explicit variable-k policy.
R2: IF a selected expert lacks compatible input/output dimensions THEN reject assignment.
R3: IF all selected gates are zero THEN renormalisation invalid; use specified fallback.
R4: IF expert load exceeds capacity THEN invoke declared overflow policy.
R5: IF routing is highly imbalanced THEN flag potential quality or throughput risk, not automatic failure.
R6: IF no expert is selected THEN do not claim a valid sparse expert output without fallback.
R7: IF router probabilities contain NaN/Inf THEN reject or apply documented numerical recovery.
10. RECURSIVE MINI ENGINE
step(X, S):
z = router(X, K.router)
p = stable_softmax(z)
assignments = top_k(p, R.k)
assignments = enforce_capacity(assignments, B.capacity_policy)
expert_results = dispatch_and_evaluate(X, assignments, K.experts)
Y = combine(expert_results, assignments, R.gate_policy)
diagnostics = measure(load, overflow, numerical_validity)
return (Y, update_state(S, diagnostics))
Repeat once per MoE-bearing transformer block; sequence generation repeats model evaluation per decoding step.
11. TRI-MAPPING
Symbolic: typed experts, router, assignment and constraint relations.
Mathematical: logits, softmax, TopK, expert functions and weighted sums.
Operational: score -> select -> dispatch -> compute -> combine -> validate.
12. HOW TO READ
N = tokens routed in a batch; d = hidden width; E = number of experts; k = selected experts per token.
Router weights indicate routing preference, not an independently calibrated probability of correctness.
Sparse activation reduces expert computation per token relative to executing all experts; it does not imply smaller total parameter count.
13. EXECUTION GUARANTEES AND LIMITS
Guarantee shape-consistent output only if experts map R^d to R^d and assignments are valid.
Guarantee selected-gate sum equals one only under successful explicit renormalisation.
Guarantee capacity compliance only after a specified overflow policy is enforced.
No guarantee of balanced loads, faster wall-clock performance, improved accuracy, or convergence.
All-to-all communication, hardware scheduling and numerical precision remain implementation dependent.
14. AI SEARCH FLOW
INTENT: explain, locate, compare or validate MoE layer entities and operations.
ALIASES: mixture of experts; MoE; sparse expert layer; expert routing; top-k gating.
ENTITY: MixtureOfExpertsLayer
INPUTS: token states, router parameters, expert parameters, k, capacity policy.
OUTPUTS: transformed token states, expert loads, overflow and routing diagnostics.
PATHWAYS:
concept -> router -> expert selection -> sparse computation -> aggregation
capacity -> load -> overflow handling -> output validity
training -> auxiliary routing losses -> load distribution
inference -> expert parallelism -> communication cost
EVIDENCE: source ontology URL; established transformer/MoE mathematical definitions.
CONFIDENCE: formal equations high for stated assumptions; source-specific alignment unverified.
UPDATE_MODEL: revise when source-page specification or routing implementation changes.
15. VALIDATION CHECKLIST
[ ] E >= 1 and 1 <= k <= E
[ ] X is finite and shape [N,d]
[ ] Router outputs [N,E]
[ ] Expert input/output widths match d
[ ] Overflow policy is explicit
[ ] Aggregation policy (normalised or not) is explicit
[ ] Expert loads and dropped/rerouted assignments are recorded
[ ] Training and inference policies are distinguished
END FLOW