A sophisticated framework for intelligent model selection and routing based on query content. The MOM framework trains an orchestrator model to predict which specialized model will perform best for a given input question, then routes queries to the most appropriate model.
The MOM framework implements an intelligent routing system that:
MOM/
βββ src/ # Source code
β βββ train.py # Orchestrator model training script
β βββ inference_pipeline.py # Main inference pipeline
β βββ label_formatter.py # Data preprocessing and labeling
β βββ requirements.txt # Python dependencies
βββ eval/ # Evaluation scripts and results
βββ eval.sh # Evaluation automation script
βββ eval_hf.sh # HuggingFace evaluation script
βββ eval_vllm.sh # vLLM evaluation script
βββ output/ # Evaluation results samples
βββ agieval/ # AGIEval benchmark
βββ arc/ # ARC benchmark
βββ csqa/ # CommonsenseQA
βββ hellaswag/ # HellaSwag
βββ humaneval/ # HumanEval
βββ logiqa/ # LogiQA
βββ mathqa/ # MathQA
βββ medmcqa/ # MedMCQA
βββ mgsm/ # MGSM
βββ mmlu/ # MMLU
# Install dependencies
pip install -r src/requirements.txt
# Set GPU device
export CUDA_VISIBLE_DEVICES=0
All model evaluations were conducted using the lm-evaluation-harness library for consistent and reproducible results.
The framework provides two automated evaluation scripts:
eval/eval_hf.sh: Evaluates models using HuggingFace backendeval/eval_vllm.sh: Evaluates models using vLLM backend for faster inference# Run HuggingFace evaluation
. eval_hf.sh
# Run vLLM evaluation
. eval_vllm.sh
# Install lm-evaluation-harness
git clone https://github.com/EleutherAI/lm-evaluation-harness
cd lm-evaluation-harness
pip install -e .
# Evaluate a model
lm_eval --model hf \
--model_args pretrained=meta-llama/Llama-3.1-8B-Instruct \
--tasks mmlu,mathqa,medmcqa \
--device cuda:0 \
--batch_size 8
For custom datasets, Read a below documents:
python src/label_formatter.py --model_ids 12 16 19 \
--include_mmlu --mmlu_categories stem social_sciences
python src/train.py \
--model_name "answerdotai/ModernBERT-base" \
--data_path "./labeled_data/12_16_19.jsonl" \
--output_dir "./ckpt/modern" \
--gpu "0"
python src/inference_pipeline.py \
--orchestrator_path "./ckpt/modern" \
--query "What is the derivative of x^2 + 3x + 1?"
All model evaluations were conducted using the lm-evaluation-harness library for consistent and reproducible results.
The label_formatter.py script processes evaluation results from lm-evaluation-harness to create training data for the orchestrator model.
The script works by:
# Generate training data from specific models
python src/label_formatter.py --model_ids 1 2 3
The framework supports 27 models with the following ID mapping:
| ID | Model | Domain |
|---|---|---|
| 1-10 | General models (Llama, Mistral, Gemma, Qwen) | General |
| 11-14 | Math specialists (DeepSeek-Math, Qwen2.5-Math, etc.) | Mathematics |
| 15-19 | Medical specialists (BioMistral, OpenBioLLM, etc.) | Medicine |
| 20-21 | Legal specialists (Saul-7B, AdaptLLM-Law) | Law |
| 22-23 | Finance specialists (FinLlama, AdaptLLM-Finance) | Finance |
| 24-27 | Additional general models | General |
The label_formatter.py script accepts the following command line arguments:
Required Arguments:
--model_ids: Space-separated list of model IDs to use for labeling (e.g., 1 2 3)
Optional Arguments:
--datasets: List of datasets to include in training data generation
["mathqa", "pubmedqa", "logiqa"]mathqa, medmcqa, csqa, pubmedqa, arc, hellaswag, logiqa, mmlu--include_mmlu: Flag to add MMLU dataset to the dataset list
--mmlu_categories: MMLU subject categories to include when processing MMLU
["stem"]stem, humanities, social_sciences, other--base_path: Root directory where evaluation results are stored
/mnt/raid6/hst/kt/paper/eval/confidence/output--output_dir: Directory where generated training data will be saved
./labeled_dataThe train.py script trains a classification model that learns to predict the best model for each input question.
# ModernBERT (recommended)
python src/train.py --model_name "answerdotai/ModernBERT-base"
# BERT
python src/train.py --model_name "bert-base-uncased"
python src/train.py \
--model_name "answerdotai/ModernBERT-base" \
--data_path "./labeled_data/training.jsonl" \
--output_dir "./ckpt/modern" \
--batch_size 128 \ # Training batch size
--eval_batch_size 64 \ # Evaluation batch size
--epochs 3 \ # Number of training epochs
--learning_rate 1e-4 \ # Learning rate
--max_length 256 \ # Maximum input sequence length
--test_size 0.1 \ # Validation split ratio
--gradient_accumulation_steps 2 \ # Gradient accumulation
--seed 42 \ # Random seed
--gpu "0" # GPU device
The inference_pipeline.py provides both command-line and programmatic interfaces for using the trained orchestrator.
# Basic inference
python src/inference_pipeline.py \
--orchestrator_path "./ckpt/modern" \
--query "Solve the equation: 2x + 5 = 13"
# With custom models
python src/inference_pipeline.py \
--orchestrator_path "./ckpt/deberta" \
--query "What are the symptoms of pneumonia?"
from src.inference_pipeline import MoMInferencePipeline
# Initialize the pipeline
pipeline = MoMInferencePipeline(
orchestrator_path="./ckpt/modern",
available_models={
"meta-llama__Llama-3.1-8B-Instruct": "meta-llama/Llama-3.1-8B-Instruct",
"Qwen__Qwen2.5-Math-7B-Instruct": "Qwen/Qwen2.5-Math-7B-Instruct",
"BioMistral__BioMistral-7B": "BioMistral/BioMistral-7B",
# Add more models as needed
}
)
# Process single query
result = pipeline.process_query("What is the limit of (sin x)/x as x approaches 0?")
print(f"Selected Model: {result['selected_model']}")
print(f"Response: {result['response']}")
# Batch processing
queries = [
"Calculate the derivative of e^(2x)",
"What causes diabetes?",
"Explain contract law basics"
]
for query in queries:
result = pipeline.process_query(query)
print(f"Query: {query}")
print(f"Model: {result['selected_model']}")
print(f"Answer: {result['response'][:100]}...")
print("-" * 50)
Edit src/label_formatter.py to add new models:
models = {
"28": "new-organization/new-model-name",
"29": "another-org/specialized-model",
# Add more models...
}
Key hyperparameters in src/train.py:
# Model settings
MAX_LENGTH = 256 # Input sequence length
NUM_LABELS = len(models) # Number of model classes
# Training settings
BATCH_SIZE = 128 # Training batch size
LEARNING_RATE = 1e-4 # Optimizer learning rate
EPOCHS = 2 # Training epochs
WEIGHT_DECAY = 0.01 # L2 regularization
# Evaluation settings
EVAL_STEPS = 0.9 # Evaluation frequency
SAVE_STEPS = 0.9 # Model saving frequency
| ID | Model | Size |
|---|---|---|
| 1 | Llama-3.2-1B-Instruct | 1B |
| 2 | Llama-3.2-3B-Instruct | 3B |
| 3 | Llama-3.1-8B-Instruct | 8B |
| 4 | Ministral-8B-Instruct | 8B |
| 5 | Mistral-7B-Instruct | 7B |
| 6 | Gemma-2-2B-IT | 2B |
| 7 | Gemma-2-9B-IT | 9B |
| 8 | Qwen2.5-7B-Instruct | 7B |
| 9 | Gemma-3-1B-IT | 1B |
| 10 | Gemma-3-4B-IT | 4B |
| ID | Model |
|---|---|
| 11 | DeepSeek-Math-7B-Instruct |
| 12 | Qwen2.5-Math-7B-Instruct |
| 13 | OpenMath2-Llama3.1-8B |
| 14 | MathCoder-CL-7B |
| ID | Model |
|---|---|
| 15 | BioMistral-7B |
| 16 | Llama3-OpenBioLLM-8B |
| 17 | MMed-Llama-3-8B |
| 18 | AdaptLLM-Medicine-Chat |
| 19 | MedGemma-4B-IT |
| ID | Model |
|---|---|
| 20 | AdaptLLM-Law-Chat |
| 21 | Saul-7B-Instruct-v1 |
| ID | Model |
|---|---|
| 22 | FinLlama3-8B |
| 23 | AdaptLLM-Finance-Chat |
A sophisticated framework for intelligent model selection and routing based on query content. The MOM framework trains an orchestrator model to predict which specialized model will perform best for a given input question, then routes queries to the most appropriate model.
The MOM framework implements an intelligent routing system that:
MOM/
βββ src/ # Source code
β βββ train.py # Orchestrator model training script
β βββ inference_pipeline.py # Main inference pipeline
β βββ label_formatter.py # Data preprocessing and labeling
β βββ requirements.txt # Python dependencies
βββ eval/ # Evaluation scripts and results
βββ eval.sh # Evaluation automation script
βββ eval_hf.sh # HuggingFace evaluation script
βββ eval_vllm.sh # vLLM evaluation script
βββ output/ # Evaluation results samples
βββ agieval/ # AGIEval benchmark
βββ arc/ # ARC benchmark
βββ csqa/ # CommonsenseQA
βββ hellaswag/ # HellaSwag
βββ humaneval/ # HumanEval
βββ logiqa/ # LogiQA
βββ mathqa/ # MathQA
βββ medmcqa/ # MedMCQA
βββ mgsm/ # MGSM
βββ mmlu/ # MMLU
# Install dependencies
pip install -r src/requirements.txt
# Set GPU device
export CUDA_VISIBLE_DEVICES=0
All model evaluations were conducted using the lm-evaluation-harness library for consistent and reproducible results.
The framework provides two automated evaluation scripts:
eval/eval_hf.sh: Evaluates models using HuggingFace backendeval/eval_vllm.sh: Evaluates models using vLLM backend for faster inference# Run HuggingFace evaluation
. eval_hf.sh
# Run vLLM evaluation
. eval_vllm.sh
# Install lm-evaluation-harness
git clone https://github.com/EleutherAI/lm-evaluation-harness
cd lm-evaluation-harness
pip install -e .
# Evaluate a model
lm_eval --model hf \
--model_args pretrained=meta-llama/Llama-3.1-8B-Instruct \
--tasks mmlu,mathqa,medmcqa \
--device cuda:0 \
--batch_size 8
For custom datasets, Read a below documents:
python src/label_formatter.py --model_ids 12 16 19 \
--include_mmlu --mmlu_categories stem social_sciences
python src/train.py \
--model_name "answerdotai/ModernBERT-base" \
--data_path "./labeled_data/12_16_19.jsonl" \
--output_dir "./ckpt/modern" \
--gpu "0"
python src/inference_pipeline.py \
--orchestrator_path "./ckpt/modern" \
--query "What is the derivative of x^2 + 3x + 1?"
All model evaluations were conducted using the lm-evaluation-harness library for consistent and reproducible results.
The label_formatter.py script processes evaluation results from lm-evaluation-harness to create training data for the orchestrator model.
The script works by:
# Generate training data from specific models
python src/label_formatter.py --model_ids 1 2 3
The framework supports 27 models with the following ID mapping:
| ID | Model | Domain |
|---|---|---|
| 1-10 | General models (Llama, Mistral, Gemma, Qwen) | General |
| 11-14 | Math specialists (DeepSeek-Math, Qwen2.5-Math, etc.) | Mathematics |
| 15-19 | Medical specialists (BioMistral, OpenBioLLM, etc.) | Medicine |
| 20-21 | Legal specialists (Saul-7B, AdaptLLM-Law) | Law |
| 22-23 | Finance specialists (FinLlama, AdaptLLM-Finance) | Finance |
| 24-27 | Additional general models | General |
The label_formatter.py script accepts the following command line arguments:
Required Arguments:
--model_ids: Space-separated list of model IDs to use for labeling (e.g., 1 2 3)
Optional Arguments:
--datasets: List of datasets to include in training data generation
["mathqa", "pubmedqa", "logiqa"]mathqa, medmcqa, csqa, pubmedqa, arc, hellaswag, logiqa, mmlu--include_mmlu: Flag to add MMLU dataset to the dataset list
--mmlu_categories: MMLU subject categories to include when processing MMLU
["stem"]stem, humanities, social_sciences, other--base_path: Root directory where evaluation results are stored
/mnt/raid6/hst/kt/paper/eval/confidence/output--output_dir: Directory where generated training data will be saved
./labeled_dataThe train.py script trains a classification model that learns to predict the best model for each input question.
# ModernBERT (recommended)
python src/train.py --model_name "answerdotai/ModernBERT-base"
# BERT
python src/train.py --model_name "bert-base-uncased"
python src/train.py \
--model_name "answerdotai/ModernBERT-base" \
--data_path "./labeled_data/training.jsonl" \
--output_dir "./ckpt/modern" \
--batch_size 128 \ # Training batch size
--eval_batch_size 64 \ # Evaluation batch size
--epochs 3 \ # Number of training epochs
--learning_rate 1e-4 \ # Learning rate
--max_length 256 \ # Maximum input sequence length
--test_size 0.1 \ # Validation split ratio
--gradient_accumulation_steps 2 \ # Gradient accumulation
--seed 42 \ # Random seed
--gpu "0" # GPU device
The inference_pipeline.py provides both command-line and programmatic interfaces for using the trained orchestrator.
# Basic inference
python src/inference_pipeline.py \
--orchestrator_path "./ckpt/modern" \
--query "Solve the equation: 2x + 5 = 13"
# With custom models
python src/inference_pipeline.py \
--orchestrator_path "./ckpt/deberta" \
--query "What are the symptoms of pneumonia?"
from src.inference_pipeline import MoMInferencePipeline
# Initialize the pipeline
pipeline = MoMInferencePipeline(
orchestrator_path="./ckpt/modern",
available_models={
"meta-llama__Llama-3.1-8B-Instruct": "meta-llama/Llama-3.1-8B-Instruct",
"Qwen__Qwen2.5-Math-7B-Instruct": "Qwen/Qwen2.5-Math-7B-Instruct",
"BioMistral__BioMistral-7B": "BioMistral/BioMistral-7B",
# Add more models as needed
}
)
# Process single query
result = pipeline.process_query("What is the limit of (sin x)/x as x approaches 0?")
print(f"Selected Model: {result['selected_model']}")
print(f"Response: {result['response']}")
# Batch processing
queries = [
"Calculate the derivative of e^(2x)",
"What causes diabetes?",
"Explain contract law basics"
]
for query in queries:
result = pipeline.process_query(query)
print(f"Query: {query}")
print(f"Model: {result['selected_model']}")
print(f"Answer: {result['response'][:100]}...")
print("-" * 50)
Edit src/label_formatter.py to add new models:
models = {
"28": "new-organization/new-model-name",
"29": "another-org/specialized-model",
# Add more models...
}
Key hyperparameters in src/train.py:
# Model settings
MAX_LENGTH = 256 # Input sequence length
NUM_LABELS = len(models) # Number of model classes
# Training settings
BATCH_SIZE = 128 # Training batch size
LEARNING_RATE = 1e-4 # Optimizer learning rate
EPOCHS = 2 # Training epochs
WEIGHT_DECAY = 0.01 # L2 regularization
# Evaluation settings
EVAL_STEPS = 0.9 # Evaluation frequency
SAVE_STEPS = 0.9 # Model saving frequency
| ID | Model | Size |
|---|---|---|
| 1 | Llama-3.2-1B-Instruct | 1B |
| 2 | Llama-3.2-3B-Instruct | 3B |
| 3 | Llama-3.1-8B-Instruct | 8B |
| 4 | Ministral-8B-Instruct | 8B |
| 5 | Mistral-7B-Instruct | 7B |
| 6 | Gemma-2-2B-IT | 2B |
| 7 | Gemma-2-9B-IT | 9B |
| 8 | Qwen2.5-7B-Instruct | 7B |
| 9 | Gemma-3-1B-IT | 1B |
| 10 | Gemma-3-4B-IT | 4B |
| ID | Model |
|---|---|
| 11 | DeepSeek-Math-7B-Instruct |
| 12 | Qwen2.5-Math-7B-Instruct |
| 13 | OpenMath2-Llama3.1-8B |
| 14 | MathCoder-CL-7B |
| ID | Model |
|---|---|
| 15 | BioMistral-7B |
| 16 | Llama3-OpenBioLLM-8B |
| 17 | MMed-Llama-3-8B |
| 18 | AdaptLLM-Medicine-Chat |
| 19 | MedGemma-4B-IT |
| ID | Model |
|---|---|
| 20 | AdaptLLM-Law-Chat |
| 21 | Saul-7B-Instruct-v1 |
| ID | Model |
|---|---|
| 22 | FinLlama3-8B |
| 23 | AdaptLLM-Finance-Chat |