Skip to main content

Adaptive-K SDK

Entropy-guided dynamic expert selection for Mixture-of-Experts models
Reduce inference costs by 30-50% with proven methodology.

PyPI License Python


🚀 Quick Start

pip install adaptive-k-routing
from adaptive_k import AdaptiveKRouter

# Load pre-calibrated router
router = AdaptiveKRouter.from_pretrained("mixtral-8x7b")

# Route tokens
indices, weights, metrics = router.route(router_logits, return_metrics=True)

print(f"Compute savings: {metrics.compute_savings:.1%}")
# Output: Compute savings: 47.2%

With Observability Support

pip install adaptive-k-routing[observability]

📊 Proven Results

Model Savings Quality Retained
Mixtral 8x7B 52.5% 99.8%
Qwen-MoE 32.4% 99.9%
OLMoE-1B-7B 24.7% 99.7%

💡 How It Works

Adaptive-K dynamically selects the number of experts (K) based on routing entropy:

Low entropy (confident) → K=1 → 87.5% compute saved
Medium entropy         → K=2 → 75% compute saved  
High entropy (uncertain) → K=4 → Full routing

The key insight: when the router is confident, fewer experts are needed.


📖 Usage

Basic Routing

from adaptive_k import AdaptiveKRouter

router = AdaptiveKRouter.from_pretrained("mixtral-8x7b")

# Your MoE router logits (batch_size, num_experts)
router_logits = model.router(hidden_states)

# Adaptive-K routing
expert_indices, expert_weights, _ = router.route(router_logits)

# Use selected experts
output = execute_experts(hidden_states, expert_indices, expert_weights)

Custom Calibration

from adaptive_k import Calibrator

calibrator = Calibrator(
    target_savings=0.40,      # 40% target savings
    quality_threshold=0.99    # Max 1% quality loss
)

result = calibrator.calibrate(
    model=your_model,
    dataset=calibration_data
)

print(f"Optimal thresholds: {result.optimal_thresholds}")
print(f"Expected savings: {result.expected_savings:.1%}")

Check Statistics

# After processing many tokens
print(router.stats)
# {
#   'tokens_processed': 1_234_567,
#   'average_savings': 0.472,
#   'estimated_cost_reduction': '47.2%'
# }

🔧 Configuration

from adaptive_k import AdaptiveKRouter, RoutingConfig

config = RoutingConfig(
    k_values=[1, 2, 4],           # Available K values
    entropy_thresholds=[0.6, 1.2], # H < 0.6 → K=1, H < 1.2 → K=2, else K=4
    num_experts=8
)

router = AdaptiveKRouter(config=config)

🔌 Integrations

HuggingFace Transformers

# Coming in v0.2.0
router = AdaptiveKRouter.from_pretrained("mixtral-8x7b")
model = router.patch(model)  # Automatic integration

vLLM

# Coming in v0.3.0
from adaptive_k.integrations import vllm_patch
model = vllm_patch(model, router)

TensorRT-LLM

See our TensorRT-LLM PR #10672 for native integration.


📈 Benchmarking

# CLI benchmark
adaptive-k benchmark --model mixtral-8x7b --dataset wikitext-2

# Output:
# Model: mixtral-8x7b
# Dataset: wikitext-2
# Baseline perplexity: 5.42
# Adaptive-K perplexity: 5.44 (+0.4%)
# Compute savings: 47.2%

📄 License

Apache 2.0 - Free for commercial use.


🔗 Links


📞 Support


Made with ❤️ by Vertex Data

Metadata

Release files for adaptive-k-routing 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for adaptive-k-routing 0.1.5
File Size Uploaded Provenance Actions
adaptive_k_routing-0.1.5.tar.gz 23.0 kB Without provenance Details for adaptive_k_routing-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for adaptive-k-routing 0.1.5
File Interpreter ABI Platform Actions
adaptive_k_routing-0.1.5-py3-none-any.whl Python 3 none any Details for adaptive_k_routing-0.1.5-py3-none-any.whl

Total release size: 45.3 kB

Release files / adaptive_k_routing-0.1.5.tar.gz

Download URL adaptive_k_routing-0.1.5.tar.gz
Size 23.0 kB
Tags Source
SHA-256 checksum
How to use checksums
46ea52add0a9037ddd15f0cc1c2bf906a767982deb1b75ebf5935d37a91b792a
BLAKE2b-256 checksum
How to use checksums
33a951631b7117d51219997a1740f34fd6bb3b74dd6118098437731d34516451
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / adaptive_k_routing-0.1.5-py3-none-any.whl

Download URL adaptive_k_routing-0.1.5-py3-none-any.whl
Size 22.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4b0aba72bcb03984df33e3ba70dfa49d3801f2336cd31e7425a988d792b669f5
BLAKE2b-256 checksum
How to use checksums
f39ba6464d2fce3ee7226d266c3ce32e821fbe8ef832b2da75b0b06c0d5b7b3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Security for adaptive-k-routing 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page