Hard routing is a paradigm in Mixture of Experts models where each input token is discretely assigned to a specific, sparse subset of experts. Unlike soft routing which blends expert outputs using continuous weights, hard routing uses a deterministic selection mechanism like top-k gating or argmax to send each token exclusively to the k experts with the highest router scores. This creates a conditional computational graph where only the selected experts' parameters are activated, enabling massive model scale with manageable inference cost.
Glossary
Hard Routing

What is Hard Routing?
A core routing mechanism in Mixture of Experts (MoE) architectures that determines which specialized sub-networks process each input.
The primary advantage of hard routing is computational sparsity, as it activates only a fraction of the model's total parameters per token. Key implementation challenges include load balancing to prevent expert underutilization and managing all-to-all communication overhead in expert parallelism. Systems like Switch Transformers (top-1) and Mixtral (top-2) employ hard routing, requiring optimized fused MoE kernels and careful capacity factor tuning to minimize dropped tokens and router latency during inference.
Key Characteristics of Hard Routing
Hard routing is a deterministic, discrete assignment mechanism in Mixture of Experts (MoE) models. It contrasts with soft routing by enforcing sparse, non-fuzzy expert selection, which has distinct system-level implications.
Discrete Token Assignment
Hard routing makes a deterministic selection of one or more experts per token, typically via an argmax or top-k operation on the router's logits. This creates a sparse computational graph where only the weights of the selected experts are activated. For example, in a top-2 routing policy, each token's hidden state is processed by exactly two expert networks, and their outputs are combined (e.g., summed). This is fundamentally different from soft routing, where outputs might be blended using continuous attention-like scores.
Implementation via Top-k Gating
The most common hard routing mechanism is Top-k Gating. A lightweight gating network (router) computes a score for each expert. For each input token, the router selects the k experts with the highest scores. In practice, k is small (1 or 2) to maintain sparsity. The process is:
- Compute router logits for the token.
- Select top k experts.
- Route the token's hidden state only to those experts.
- Compute and combine the expert outputs. This ensures a fixed, predictable FLOPs cost per token, proportional to k, not the total number of experts.
System Efficiency & Challenges
Hard routing enables conditional computation, activating only a fraction of the model's total parameters. This allows for gigantic models (e.g., trillion-parameter) with feasible inference costs. However, it introduces significant system complexity:
- Load Balancing: The router can develop favorites, causing some experts to be overloaded while others are idle. This is mitigated by auxiliary loss functions during training.
- All-to-All Communication: In expert-parallel distributed training and inference, tokens must be scattered to the devices hosting their assigned experts and gathered afterward, creating a communication bottleneck.
- Expert Capacity: Each expert has a fixed capacity (number of tokens it can process per batch). Tokens exceeding an expert's capacity are dropped, potentially harming model quality.
Expert Specialization
Through training, hard routing encourages token-expert affinity, where experts naturally specialize in processing specific types of tokens. For instance, in a language model, one expert might specialize in mathematical symbols, another in proper nouns, and another in syntactic function words. This specialization emerges because the router learns to assign semantically or syntactically similar tokens to the same subset of experts, making the overall model more compositional and efficient. The discrete nature of the assignment reinforces this specialization more sharply than soft routing.
Contrast with Soft Routing
Hard routing is defined in opposition to soft routing. Key differences:
- Hard Routing: Discrete, sparse selection (e.g., top-k). Outputs are combined via a weighted sum based on the router scores for the selected experts only.
- Soft Routing: Continuous, dense blending. All experts receive the token, and their outputs are combined using a full set of attention-like weights, resulting in a denser, more computationally expensive operation. Hard routing is preferred in large-scale MoE (e.g., Switch Transformer, Mixtral) for its computational sparsity. Soft routing is more common in older, smaller mixture-of-experts models and is analogous to multi-head attention.
Key Architectural Examples
Several landmark models exemplify hard routing:
- Switch Transformer: Uses top-1 routing (Switch Routing), where each token is sent to exactly one expert. This maximizes sparsity and simplifies system design.
- Mixtral 8x7B: Employs top-2 routing. Each layer has 8 expert FFNs, and each token is processed by 2, giving it the effective capacity of a ~47B parameter dense model for only ~13B active parameters.
- GLaM (Google): A generalist language model using top-2 routing with a massive 1.2 trillion total parameters, demonstrating the scalability of the paradigm. These models rely on fused MoE kernels and optimized expert parallelism to make the routing and sparse computation efficient on GPU clusters.
How Hard Routing Works: Mechanism and Implementation
A technical overview of the deterministic routing mechanism used in Mixture of Experts models, contrasting it with soft routing and detailing its core computational implementation.
Hard routing is a deterministic gating mechanism in Mixture of Experts (MoE) models where each input token is discretely assigned to one or a fixed number of top-scoring experts, as selected by a gating network (router). This contrasts with soft routing, where expert outputs are blended using continuous weights. The primary implementations are top-k gating, where the router selects the k experts with the highest scores, and its special case top-1 (or Switch) routing, where each token is sent to exactly one expert. This discrete assignment creates a sparse computational graph, activating only a subset of the model's total parameters per token.
Implementation requires efficient handling of the all-to-all communication pattern in distributed settings, where tokens are scattered to devices hosting their assigned experts. Optimized fused MoE kernels combine routing logic and sparse matrix multiplication to minimize overhead. A critical hyperparameter is the expert capacity, which sets a limit on tokens per expert to enable batched computation; tokens exceeding an expert's capacity are dropped. This paradigm enables massive model scale with conditional computation, but introduces router latency and load balancing challenges during training.
Examples and Real-World Applications
Hard routing is a foundational technique for conditional computation, enabling massive model scale with sparse activation. Its deterministic nature makes it critical for high-performance, predictable inference in production systems.
Mixtral 8x7B (Top-2 Routing)
Mistral AI's Mixtral 8x7B is a state-of-the-art open-source model that uses hard top-2 routing. For each token, the router selects the two highest-scoring experts out of eight per layer. Despite having 47B total parameters, it activates only about 13B parameters per token, matching the inference cost of a much smaller dense model. This architecture demonstrates how hard routing enables high-quality, cost-effective inference for open-weight LLMs.
- Model Family: Mixtral 8x7B, Mixtral 8x22B
- Routing Policy: Top-2
- Key Benefit: Dense 13B model latency with 47B parameter knowledge.
Load Balancing via Auxiliary Loss
A core challenge in training hard-routed MoEs is load imbalance, where the router may collapse to always selecting the same few experts. To prevent this, an auxiliary load balancing loss is added during training. For top-2 routing, this loss encourages the mean routing probability across experts to be uniform and minimizes the squared coefficient of variation of the number of tokens assigned to each expert. This technique is critical for ensuring all 47B parameters in a model like Mixtral are effectively utilized.
Hard vs. Soft Routing in Production
The choice between hard and soft routing has direct engineering implications:
Hard Routing (e.g., Top-k)
- Pros: Sparse, deterministic computation; efficient expert parallelism; lower memory bandwidth (no blending coefficients).
- Cons: Discontinuous gradients; requires load balancing losses; risk of dropped tokens if expert capacity is exceeded.
Soft Routing (e.g., Mixture)
- Pros: Continuous, differentiable operation; natural load balancing.
- Cons: Dense computation (all experts are weighted); higher memory and compute cost; complex to scale.
In production LLM serving, hard routing dominates due to its superior computational efficiency and predictable latency.
Hard Routing vs. Soft Routing: A Technical Comparison
A comparison of the two primary paradigms for distributing tokens to experts in a Mixture of Experts (MoE) architecture, focusing on implementation, performance, and system characteristics.
| Feature / Metric | Hard Routing | Soft Routing |
|---|---|---|
Routing Decision | Discrete (e.g., Top-k, Argmax) | Continuous (Weighted Blending) |
Token Assignment | Each token assigned to 1 or k specific experts. | Each token's output is a weighted sum of all expert outputs. |
Computational Sparsity | High. Only the selected experts' parameters are activated. | Low or None. All experts are computed, then outputs are blended. |
Inference Throughput | Higher. Enables conditional computation and expert parallelism. | Lower. Requires full forward pass through all experts. |
Router Latency Overhead | Low. Simple selection logic (e.g., sorting). | Higher. Requires computing scores for and blending from all experts. |
Model Specialization | Encouraged. Experts can learn distinct, specialized functions. | Discouraged. Experts learn blended, generalized representations. |
Training Stability | Requires careful tuning (load balancing, auxiliary loss). | More stable, akin to training a dense network. |
Gradient Flow | Sparse. Gradients only flow to the selected experts per token. | Dense. Gradients flow to all experts for every token. |
Memory Access Pattern | Sparse, irregular. Requires efficient all-to-all communication. | Dense, regular. Predictable memory access. |
System Complexity | High. Requires expert parallelism, token permutation, capacity management. | Low. Similar to serving a standard dense model. |
Representative Architectures | Switch Transformer, Mixtral, GShard | Early MoE models, Mixture-of-Soft-Experts variants |
Frequently Asked Questions
Hard routing is a fundamental paradigm in Mixture of Experts (MoE) models that determines how computational workload is distributed. These questions address its core mechanics, trade-offs, and implementation.
Hard routing is a deterministic, discrete assignment mechanism in a Mixture of Experts (MoE) model where each input token is routed to a specific, sparse subset of experts based on a selection function like top-k or argmax. Unlike soft routing, which blends expert outputs using continuous weights, hard routing activates only the chosen experts for computation, creating a conditional execution graph. This paradigm is central to achieving sparse activation, where a model can have a massive total parameter count (e.g., hundreds of billions) while only using a small fraction (e.g., 2 out of 8 experts per token) during any single forward pass, dramatically reducing computational cost.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Hard routing is a core mechanism within Mixture of Experts architectures. These related concepts define the surrounding system components, optimization strategies, and implementation patterns.
Mixture of Experts (MoE)
A neural network architecture where the model is composed of multiple sub-networks (experts), and a routing mechanism dynamically selects a sparse subset of these experts to process each input. This enables massive parameter counts (e.g., trillions) with a conditional, much lower computational cost per token, as only a few experts are active for any given input.
Gating Network (Router)
A small, trainable neural network component within a MoE model that receives an input token or hidden state and outputs a set of scores or logits. This network is responsible for the routing decision. In hard routing paradigms, it uses functions like argmax or top-k to make discrete, non-differentiable assignments of tokens to specific experts.
Top-k Gating
The most common hard routing strategy. For each input token, the gating network computes scores for all experts, selects the k experts with the highest scores, and routes the token's representation exclusively to those experts. The outputs of the selected experts are then combined, typically via a weighted sum based on the gating scores. This enforces a fixed, predictable computational budget per token.
Load Balancing
A critical challenge in MoE training. Without intervention, the router can collapse, always selecting the same few popular experts. Load balancing techniques prevent this, ensuring uniform computational load. Key methods include:
- Auxiliary Loss (Load Loss): An added training loss term that penalizes imbalance.
- Noise Top-k Gating: Adds tunable noise to router logits to encourage exploration.
- Expert Capacity: A hard limit on tokens per expert per batch.
Expert Parallelism
A model parallelism strategy designed for MoE models at scale. Different expert networks are placed on different devices (e.g., GPUs). The routing decision triggers an all-to-all communication pattern:
- Tokens are scattered from all devices to the devices hosting their assigned experts.
- Experts process their assigned tokens in parallel.
- Results are gathered back to the original devices. This is essential for distributing the massive parameter count of MoE models across a hardware cluster.
Sparse Activation
The defining computational property enabled by hard routing. In a sparsely activated MoE model, only a small, dynamically chosen subset of the model's total parameters (the selected experts) is involved in the forward pass for a given input. This contrasts with dense models (like standard transformers), where every parameter is used for every input. Sparse activation is the key to the efficiency vs. parameter count trade-off.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us