A rust optillm port, for use with just-ever/code (or at least my fork of it)
7
stars
47
commits
Python
primary language
Oct 29, 2025
updated
A Rust monorepo for implementations of optillm optimization techniques for LLMs. Provides multiple optimization strategies with a clear architecture for adding new implementations.
Note: This is a port of the Python OptimLLM library designed to seamlessly integrate advanced LLM optimization strategies into the code project (Codex fork). This Rust implementation enables high-performance deployment of OptimLLM techniques within Rust-based systems while maintaining API compatibility with the original research implementations.
# Build all crates
cargo build --release
# Run checks
cargo check --all
# Build specific implementation
cargo build --release -p optillm-mars
# Build core only
cargo build -p optillm-core
optillm-rs/
├── .claude/
│ ├── AGENTS.md
│ └── settings.local.json
├── .github/
│ └── workflows/
├── .gitignore
├── .prek.yaml
├── Cargo.toml
├── README.md
├── crates/
│ ├── core/
│ └── mars/
├── docs/
│ ├── api/
│ ├── architecture/
│ ├── core/
│ ├── development/
│ ├── faq.md
│ ├── getting-started/
│ ├── index.md
│ ├── integration.md
│ ├── mars/
│ └── strategies/
├── examples/
├── mkdocs.yml
├── modal_benchmark.py
├── references/
│ └── optillm/
├── requirements-docs.txt
├── scratch_pads/
│ ├── CODING_LLM_BENCHMARKS.md
│ ├── COMPREHENSIVE_STRATEGY_BENCHMARK_RESULTS.md
│ ├── MODAL_BENCHMARK_SETUP.md
│ ├── TINYLLAMA_STRATEGY_TEST_RESULTS.md
│ ├── ULTRA_TINY_MODELS.md
│ └── UNIMPLEMENTED_TECHNIQUES.md
├── scripts/
│ └── update_readme_structure.py
└── site/
├── 404.html
├── api/
├── architecture/
├── assets/
├── core/
├── development/
├── faq/
├── getting-started/
├── index.html
├── integration/
├── mars/
├── search/
├── sitemap.xml
├── sitemap.xml.gz
└── strategies/
Shared core library providing interfaces and types for all optillm implementations:
ModelClient trait: Abstract interface for LLM communication with streaming supportOptimizer trait: Interface all implementations must implementPrompt / ResponseEvent types: Unified request/response representationSolution struct: Result containing reasoning and answerProduction-ready MARS (Multi-Agent Reasoning System) implementation achieving 69% improvement on AIME 2025 benchmarks.
Key Features:
Benchmark Results:
See crates/mars/README.md for detailed documentation.
To add a new optimization technique:
Create a new crate in crates/:
cargo new crates/my-optimizer
Implement the Optimizer trait from optillm-core:
use optillm_core::{Optimizer, Solution, ModelClient, Result};
use async_trait::async_trait;
pub struct MyOptimizer {
// your config
}
#[async_trait]
impl Optimizer for MyOptimizer {
async fn optimize(
&self,
query: &str,
client: &dyn ModelClient,
) -> Result<Solution> {
// your implementation
}
fn name(&self) -> &str { "my-optimizer" }
fn description(&self) -> &str { "..." }
}
Add to workspace in root Cargo.toml:
members = [
"crates/core",
"crates/mars",
"crates/my-optimizer", # Add this
]
Make it depend on optillm-core in Cargo.toml:
[dependencies]
optillm-core = { path = "../core" }
All crates share workspace dependencies for consistency. Core dependencies include:
See root Cargo.toml for full dependency list.
# Build all
cargo build --release
# Check all (faster than build)
cargo check --all
# Build specific crate
cargo build -p optillm-mars
# Check specific crate
cargo check -p optillm-core
# Build with all features
cargo build --all-features
optillm-coreoptillm-rs is specifically designed to integrate with the code project, enabling it to leverage advanced OptimLLM reasoning strategies. This integration provides:
// In code's coordinator or agent system
use optillm_mars::MarsCoordinator;
let coordinator = MarsCoordinator::new(config);
let result = coordinator.optimize(query, &code_model_client).await?;
// Result integrates seamlessly with code's reasoning pipeline
optillm-rs integrates litellm-rs for unified LLM API management, providing:
use optillm_mars::provider_config::{ProviderSpec, ProviderRoutingConfig, RoutingStrategy};
// Configure multiple providers
let openai = ProviderSpec::new("openai", "gpt-4o")
.with_api_key(env::var("OPENAI_API_KEY")?)
.with_priority(1);
let anthropic = ProviderSpec::new("anthropic", "claude-3-5-sonnet")
.with_api_key(env::var("ANTHROPIC_API_KEY")?)
.with_priority(2);
let config = ProviderRoutingConfig::multi(openai, vec![anthropic])
.with_strategy(RoutingStrategy::RoundRobin)
.with_fallback(true)
.with_max_retries(2);
// In code's model initialization
use optillm_mars::model_router::ModelClientRouter;
// Wrap code's existing ModelClient with routing capabilities
let router = ModelClientRouter::new();
let coordinator = MarsCoordinator::new(config);
// Now MARS can route through multiple providers
let result = coordinator.optimize(query, &router).await?;
The following strategies are available for integration into code:
| Strategy | Description | Status |
|---|---|---|
| MARS (Multi-Agent Reasoning System) | Multi-agent exploration with cross-verification, aggregation, and iterative improvement for maximum quality. | ✅ Implemented |
| MOA (Mixture of Agents) | Three-phase approach: generate diverse completions, critique each, then synthesize optimal answer. | ✅ Implemented |
| Self-Consistency | Generate multiple diverse reasoning paths and use majority voting to reach consensus answers. | ✅ Implemented |
| Best-of-N | Generate N solutions with different parameters and select the highest quality based on scoring criteria. | ✅ Implemented |
| RSA (Reinforced Self-Aggregation) | Iteratively refine solutions by selecting diverse candidates and synthesizing improvements over multiple rounds. | ✅ Implemented |
| MCTS (Monte Carlo Tree Search) | Explore solution space systematically using UCB-based node selection and random simulation rollouts. | ✅ Implemented |
| CoT Reflection | Generate reasoning with chain-of-thought prompts and refine through self-reflection and error analysis. | ✅ Implemented |
| RTO (Round-Trip Optimization) | Improve answers through round-trip generation: forward pass then backward verification and refinement. | ✅ Implemented |
| PVG (Prover-Verifier Game) | Generate both helpful and adversarial solutions, then verify to identify robust answers. | ✅ Implemented |
| LEAP (Learning from Errors) | Use few-shot examples of corrected errors to adaptively improve solution quality over iterations. | ✅ Implemented |
| PlanSearch | Observation-guided problem solving combining planning phase with implementation and verification. | ✅ Implemented |
| ReRead | Simple but effective strategy of re-reading and refining answers for improved clarity and accuracy. | ✅ Implemented |
| Diverse Sampling | Explore solution space using temperature-varied sampling to balance exploration and exploitation. | ✅ Implemented |
| AutoThink | Query complexity classification with adaptive reasoning depth and temperature adjustment for optimal strategy selection. | ✅ Implemented |
| Deep Thinking | Inference-time scaling that allocates more computation and tokens to harder problems based on difficulty estimation. | ✅ Implemented |
| Entropy Decoding | Entropy-based sampling for controlled diversity, providing fine-grained control over answer quality versus novelty. | ✅ Implemented |
| CoT Decoding | Structured chain-of-thought decoding that guides models to follow step-by-step reasoning patterns for better quality. | ✅ Implemented |
| R Algorithm* | Enhanced Monte Carlo Tree Search with learned value estimates and sophisticated node selection for solution exploration. | ✅ Implemented |
| CePO (Cerebras Planning & Optimization) | Problem decomposition with state tracking and backtracking for systematic exploration of solution space. | ⏳ Planned |
| Z3 Solver Integration | Integration of Z3 SMT solver for constraint satisfaction and logical reasoning problems. | ⏳ Planned |
| LongCePO | Extended CePO with context windowing and recursive decomposition for handling problems with infinite context. | ⏳ Planned |
Add new strategies by implementing the Optimizer trait—perfect for domain-specific optimizations for code's specialized tasks.
To use optillm-rs strategies in a code-based system:
See Integration Guide for detailed instructions.
MIT
Complete documentation is available via MkDocs. Build and serve locally:
# Install dependencies
pip install -r requirements-docs.txt
# Serve documentation locally
mkdocs serve
# Build static site
mkdocs build
View online: Documentation
47 commits
Python
75.8%
Rust
24.0%
A rust optillm port, for use with just-ever/code (or at least my fork of it)
7
stars
47
commits
Python
primary language
Oct 29, 2025
updated
A Rust monorepo for implementations of optillm optimization techniques for LLMs. Provides multiple optimization strategies with a clear architecture for adding new implementations.
Note: This is a port of the Python OptimLLM library designed to seamlessly integrate advanced LLM optimization strategies into the code project (Codex fork). This Rust implementation enables high-performance deployment of OptimLLM techniques within Rust-based systems while maintaining API compatibility with the original research implementations.
# Build all crates
cargo build --release
# Run checks
cargo check --all
# Build specific implementation
cargo build --release -p optillm-mars
# Build core only
cargo build -p optillm-core
optillm-rs/
├── .claude/
│ ├── AGENTS.md
│ └── settings.local.json
├── .github/
│ └── workflows/
├── .gitignore
├── .prek.yaml
├── Cargo.toml
├── README.md
├── crates/
│ ├── core/
│ └── mars/
├── docs/
│ ├── api/
│ ├── architecture/
│ ├── core/
│ ├── development/
│ ├── faq.md
│ ├── getting-started/
│ ├── index.md
│ ├── integration.md
│ ├── mars/
│ └── strategies/
├── examples/
├── mkdocs.yml
├── modal_benchmark.py
├── references/
│ └── optillm/
├── requirements-docs.txt
├── scratch_pads/
│ ├── CODING_LLM_BENCHMARKS.md
│ ├── COMPREHENSIVE_STRATEGY_BENCHMARK_RESULTS.md
│ ├── MODAL_BENCHMARK_SETUP.md
│ ├── TINYLLAMA_STRATEGY_TEST_RESULTS.md
│ ├── ULTRA_TINY_MODELS.md
│ └── UNIMPLEMENTED_TECHNIQUES.md
├── scripts/
│ └── update_readme_structure.py
└── site/
├── 404.html
├── api/
├── architecture/
├── assets/
├── core/
├── development/
├── faq/
├── getting-started/
├── index.html
├── integration/
├── mars/
├── search/
├── sitemap.xml
├── sitemap.xml.gz
└── strategies/
Shared core library providing interfaces and types for all optillm implementations:
ModelClient trait: Abstract interface for LLM communication with streaming supportOptimizer trait: Interface all implementations must implementPrompt / ResponseEvent types: Unified request/response representationSolution struct: Result containing reasoning and answerProduction-ready MARS (Multi-Agent Reasoning System) implementation achieving 69% improvement on AIME 2025 benchmarks.
Key Features:
Benchmark Results:
See crates/mars/README.md for detailed documentation.
To add a new optimization technique:
Create a new crate in crates/:
cargo new crates/my-optimizer
Implement the Optimizer trait from optillm-core:
use optillm_core::{Optimizer, Solution, ModelClient, Result};
use async_trait::async_trait;
pub struct MyOptimizer {
// your config
}
#[async_trait]
impl Optimizer for MyOptimizer {
async fn optimize(
&self,
query: &str,
client: &dyn ModelClient,
) -> Result<Solution> {
// your implementation
}
fn name(&self) -> &str { "my-optimizer" }
fn description(&self) -> &str { "..." }
}
Add to workspace in root Cargo.toml:
members = [
"crates/core",
"crates/mars",
"crates/my-optimizer", # Add this
]
Make it depend on optillm-core in Cargo.toml:
[dependencies]
optillm-core = { path = "../core" }
All crates share workspace dependencies for consistency. Core dependencies include:
See root Cargo.toml for full dependency list.
# Build all
cargo build --release
# Check all (faster than build)
cargo check --all
# Build specific crate
cargo build -p optillm-mars
# Check specific crate
cargo check -p optillm-core
# Build with all features
cargo build --all-features
optillm-coreoptillm-rs is specifically designed to integrate with the code project, enabling it to leverage advanced OptimLLM reasoning strategies. This integration provides:
// In code's coordinator or agent system
use optillm_mars::MarsCoordinator;
let coordinator = MarsCoordinator::new(config);
let result = coordinator.optimize(query, &code_model_client).await?;
// Result integrates seamlessly with code's reasoning pipeline
optillm-rs integrates litellm-rs for unified LLM API management, providing:
use optillm_mars::provider_config::{ProviderSpec, ProviderRoutingConfig, RoutingStrategy};
// Configure multiple providers
let openai = ProviderSpec::new("openai", "gpt-4o")
.with_api_key(env::var("OPENAI_API_KEY")?)
.with_priority(1);
let anthropic = ProviderSpec::new("anthropic", "claude-3-5-sonnet")
.with_api_key(env::var("ANTHROPIC_API_KEY")?)
.with_priority(2);
let config = ProviderRoutingConfig::multi(openai, vec![anthropic])
.with_strategy(RoutingStrategy::RoundRobin)
.with_fallback(true)
.with_max_retries(2);
// In code's model initialization
use optillm_mars::model_router::ModelClientRouter;
// Wrap code's existing ModelClient with routing capabilities
let router = ModelClientRouter::new();
let coordinator = MarsCoordinator::new(config);
// Now MARS can route through multiple providers
let result = coordinator.optimize(query, &router).await?;
The following strategies are available for integration into code:
| Strategy | Description | Status |
|---|---|---|
| MARS (Multi-Agent Reasoning System) | Multi-agent exploration with cross-verification, aggregation, and iterative improvement for maximum quality. | ✅ Implemented |
| MOA (Mixture of Agents) | Three-phase approach: generate diverse completions, critique each, then synthesize optimal answer. | ✅ Implemented |
| Self-Consistency | Generate multiple diverse reasoning paths and use majority voting to reach consensus answers. | ✅ Implemented |
| Best-of-N | Generate N solutions with different parameters and select the highest quality based on scoring criteria. | ✅ Implemented |
| RSA (Reinforced Self-Aggregation) | Iteratively refine solutions by selecting diverse candidates and synthesizing improvements over multiple rounds. | ✅ Implemented |
| MCTS (Monte Carlo Tree Search) | Explore solution space systematically using UCB-based node selection and random simulation rollouts. | ✅ Implemented |
| CoT Reflection | Generate reasoning with chain-of-thought prompts and refine through self-reflection and error analysis. | ✅ Implemented |
| RTO (Round-Trip Optimization) | Improve answers through round-trip generation: forward pass then backward verification and refinement. | ✅ Implemented |
| PVG (Prover-Verifier Game) | Generate both helpful and adversarial solutions, then verify to identify robust answers. | ✅ Implemented |
| LEAP (Learning from Errors) | Use few-shot examples of corrected errors to adaptively improve solution quality over iterations. | ✅ Implemented |
| PlanSearch | Observation-guided problem solving combining planning phase with implementation and verification. | ✅ Implemented |
| ReRead | Simple but effective strategy of re-reading and refining answers for improved clarity and accuracy. | ✅ Implemented |
| Diverse Sampling | Explore solution space using temperature-varied sampling to balance exploration and exploitation. | ✅ Implemented |
| AutoThink | Query complexity classification with adaptive reasoning depth and temperature adjustment for optimal strategy selection. | ✅ Implemented |
| Deep Thinking | Inference-time scaling that allocates more computation and tokens to harder problems based on difficulty estimation. | ✅ Implemented |
| Entropy Decoding | Entropy-based sampling for controlled diversity, providing fine-grained control over answer quality versus novelty. | ✅ Implemented |
| CoT Decoding | Structured chain-of-thought decoding that guides models to follow step-by-step reasoning patterns for better quality. | ✅ Implemented |
| R Algorithm* | Enhanced Monte Carlo Tree Search with learned value estimates and sophisticated node selection for solution exploration. | ✅ Implemented |
| CePO (Cerebras Planning & Optimization) | Problem decomposition with state tracking and backtracking for systematic exploration of solution space. | ⏳ Planned |
| Z3 Solver Integration | Integration of Z3 SMT solver for constraint satisfaction and logical reasoning problems. | ⏳ Planned |
| LongCePO | Extended CePO with context windowing and recursive decomposition for handling problems with infinite context. | ⏳ Planned |
Add new strategies by implementing the Optimizer trait—perfect for domain-specific optimizations for code's specialized tasks.
To use optillm-rs strategies in a code-based system:
See Integration Guide for detailed instructions.
MIT
Complete documentation is available via MkDocs. Build and serve locally:
# Install dependencies
pip install -r requirements-docs.txt
# Serve documentation locally
mkdocs serve
# Build static site
mkdocs build
View online: Documentation
47 commits
Python
75.8%
Rust
24.0%