Skip to content

Commit 6c3c1d6

Browse files
authored
Merge pull request #19 from codelion/feat-add-llm-config-optimizer
Feat add llm config optimizer
2 parents 63e53ab + 9fc2750 commit 6c3c1d6

File tree

4 files changed

+519
-4
lines changed

4 files changed

+519
-4
lines changed

README.md

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,83 @@ The system combines three key components:
112112
- safetensors ≥ 0.3.1
113113
- faiss-cpu ≥ 1.7.4 (or faiss-gpu for GPU support)
114114

115-
## Benefits of Adaptive Classification in LLM Routing
115+
## Adaptive Classification with LLMs
116+
117+
### LLM Configuration Optimization
118+
119+
The adaptive classifier can also be used to predict optimal configurations for Language Models. Our research shows that model configurations, particularly temperature settings, can significantly impact response quality. Using the adaptive classifier, we can automatically predict the best temperature range for different types of queries:
120+
121+
- **DETERMINISTIC** (T: 0.0-0.1): For queries requiring precise, factual responses
122+
- **FOCUSED** (T: 0.2-0.5): For structured, technical responses with slight flexibility
123+
- **BALANCED** (T: 0.6-1.0): For natural, conversational responses
124+
- **CREATIVE** (T: 1.1-1.5): For more varied and imaginative outputs
125+
- **EXPERIMENTAL** (T: 1.6-2.0): For maximum variability and unconventional responses
126+
127+
Our evaluation on the LLM Arena dataset demonstrates:
128+
- 69.8% success rate in finding optimal configurations
129+
- Consistent response quality (avg. similarity score: 0.64)
130+
- Balanced distribution across temperature classes, with each class finding its appropriate use cases
131+
- BALANCED and CREATIVE temperatures producing the most reliable results (scores: 0.649 and 0.645)
132+
133+
This classifier can be used to automatically optimize LLM configurations based on query characteristics, leading to more consistent and higher-quality responses while reducing the need for manual configuration tuning.
134+
135+
```python
136+
from adaptive_classifier import AdaptiveClassifier
137+
138+
# Load the configuration optimizer
139+
classifier = AdaptiveClassifier.from_pretrained("adaptive-classifier/llm-config-optimizer")
140+
141+
# Get optimal temperature class for a query
142+
predictions = classifier.predict("Your query here")
143+
# Returns: [('BALANCED', 0.85), ('CREATIVE', 0.10), ...]
144+
```
145+
146+
The classifier continuously learns from new examples, adapting its predictions as it processes more queries and observes their performance.
147+
148+
### LLM Router
149+
150+
The adaptive classifier can be used to intelligently route queries between different LLM models based on query complexity and requirements. The classifier learns to categorize queries into:
151+
152+
- **HIGH**: Complex queries requiring advanced reasoning, multi-step problem solving, or deep expertise. Examples include:
153+
- Code generation and debugging
154+
- Complex analysis tasks
155+
- Multi-step mathematical problems
156+
- Technical explanations
157+
- Creative writing tasks
158+
159+
- **LOW**: Straightforward queries that can be handled by smaller, faster models. Examples include:
160+
- Simple factual questions
161+
- Basic clarifications
162+
- Formatting tasks
163+
- Short definitions
164+
- Basic sentiment analysis
165+
166+
The router can be used to optimize costs and latency while maintaining response quality:
167+
168+
```python
169+
from adaptive_classifier import AdaptiveClassifier
170+
171+
# Load the router classifier
172+
classifier = AdaptiveClassifier.from_pretrained("adaptive-classifier/llm-router")
173+
174+
# Get routing prediction for a query
175+
predictions = classifier.predict("Write a function to calculate the Fibonacci sequence")
176+
# Returns: [('HIGH', 0.92), ('LOW', 0.08)]
177+
178+
# Example routing logic
179+
def route_query(query: str, classifier: AdaptiveClassifier):
180+
predictions = classifier.predict(query)
181+
top_class = predictions[0][0]
182+
183+
if top_class == 'HIGH':
184+
return use_advanced_model(query) # e.g., GPT-4
185+
else:
186+
return use_basic_model(query) # e.g., GPT-3.5-Turbo
187+
```
116188

117189
We evaluate the effectiveness of adaptive classification in optimizing LLM routing decisions. Using the arena-hard-auto-v0.1 dataset with 500 queries, we compared routing performance with and without adaptation while maintaining consistent overall success rates.
118190

119-
### Key Results
191+
#### Key Results
120192

121193
| Metric | Without Adaptation | With Adaptation | Impact |
122194
|--------|-------------------|-----------------|---------|
@@ -129,7 +201,7 @@ We evaluate the effectiveness of adaptive classification in optimizing LLM routi
129201

130202
*Cost savings calculation assumes high-cost model is 2x the cost of low-cost model
131203

132-
### Analysis
204+
#### Analysis
133205

134206
The results highlight several key benefits of adaptive classification:
135207

0 commit comments

Comments
 (0)