This project demonstrates model merging techniques using SLERP (Spherical Linear Interpolation) to combine two language models: Breeze-7B (Traditional Chinese) and WizardMath-7B (Mathematical reasoning). The merged model is evaluated on multiple benchmarks to assess its performance compared to the baseline models.
This project aims to:
Benchmark Datasets:
All dependencies are listed below and can be installed via pip.
cd /path/to/Machine_Learning_Final_Project
python3 -m venv venv
source venv/bin/activate # On Linux/Mac
# OR
venv\Scripts\activate # On Windows
pip install torch transformers mergekit pyyaml tqdm bitsandbytes pillow accelerate huggingface_hub
Library Descriptions:
torch: PyTorch deep learning frameworktransformers: Hugging Face transformers librarymergekit: Model merging toolkitpyyaml: YAML configuration parsertqdm: Progress bar utilitybitsandbytes: 4-bit quantization supportpillow: Image processing library (compatibility)accelerate: Distributed training and inferencehuggingface_hub: Hugging Face Hub API for model downloadspython3 -c "import torch; print('PyTorch version:', torch.__version__)"
python3 -c "import transformers; print('Transformers version:', transformers.__version__)"
Machine_Learning_Final_Project/
├── models/ # (Optional) Local model storage
│ ├── Breeze-7B/ # Breeze-7B model files (if downloaded locally)
│ └── WizardMath-7B/ # WizardMath-7B model files (if downloaded locally)
├── baseline_Breeze_GSM8K.py # Baseline: Breeze on GSM8K
├── baseline_Breeze_DRCD.py # Baseline: Breeze on DRCD
├── baseline_Breeze_Math23k.py # Baseline: Breeze on Math23k
├── baseline_Wizard_GSM8K.py # Baseline: WizardMath on GSM8K
├── baseline_Wizard_DRCD.py # Baseline: WizardMath on DRCD
├── baseline_Wizard_Math23k.py # Baseline: WizardMath on Math23k
├── run_merge_SLERP.py # Model merging script
├── repair_model.py # Model alignment/repair script
├── check_answer.py # Re-evaluate results with improved detection
├── benchmark_Merged_GSM8K.py # Merged model evaluation on GSM8K
├── benchmark_Merged_DRCD.py # Merged model evaluation on DRCD
├── benchmark_Merged_Math23k.py # Merged model evaluation on Math23k
├── GSM8K_dataset.csv # GSM8K test dataset
├── DRCD_test.json # DRCD test dataset (if available)
├── math_tw.json # Math23k dataset
└── README.md # This file
Before merging, establish baseline performance for both models on all three datasets.
# GSM8K benchmark
python3 baseline_Breeze_GSM8K.py
# DRCD benchmark
python3 baseline_Breeze_DRCD.py
# Math23k benchmark
python3 baseline_Breeze_Math23k.py
# GSM8K benchmark
python3 baseline_Wizard_GSM8K.py
# DRCD benchmark
python3 baseline_Wizard_DRCD.py
# Math23k benchmark
python3 baseline_Wizard_Math23k.py
Expected Output:
GSM8K_results_Breeze.json)Note: Each baseline evaluation may take 30-60 minutes depending on your hardware.
Use SLERP (Spherical Linear Interpolation) to merge Breeze-7B and WizardMath-7B.
python3 run_merge_SLERP.py
What happens during merging:
MediaTek-Research/Breeze-7B-Instruct-v1_0WizardLM/WizardMath-7B-V1.1self_attn layers: [0, 0.5, 0.5, 0.6, 0.7]mlp layers: [1, 0.5, 0.7, 0.3, 0.2]0.5 (default)./merged_model/Note: If you prefer to use local models, you can modify the paths in run_merge_SLERP.py (lines 20-21)
Expected Output:
📍 Current Workspace: /path/to/project
📦 Breeze Model: MediaTek-Research/Breeze-7B-Instruct-v1_0
📦 Wizard Model: WizardLM/WizardMath-7B-V1.1
🚀 Starting model merging... (The progress bar finishing means it's done)
✅ Confirmed X weight files exist.
🔧 Handling tokenizer files...
Downloading tokenizer from Hugging Face...
✅ Tokenizer downloaded and saved
🔧 Rebuilding config.json...
✅ Fix completed: vocab_size 32001 -> 32000
✨ All rescue operations successful!
Output Directory: ./merged_model/
Notes:
~/.cache/huggingface/hub/ by defaultAfter merging, run the repair script to align tokenizer and configuration files.
python3 repair_model.py
What happens during repair:
config.json to ensure vocab_size = 32000"mistral"Expected Output:
🔧 Starting repair for: ./merged_model
⬇️ Downloading standard Mistral/WizardMath tokenizer...
✅ Tokenizer files replaced.
📝 Patching config.json...
✅ Config fixed: vocab_size 32001 -> 32000
✨ Repair complete.
Why is this step necessary?
Note: This step requires internet connection to download tokenizer files from Hugging Face Hub.
Evaluate the merged model on all three benchmarks.
# GSM8K benchmark
python3 benchmark_Merged_GSM8K.py
# DRCD benchmark
python3 benchmark_Merged_DRCD.py
# Math23k benchmark
python3 benchmark_Merged_Math23k.py
Expected Output:
GSM8K_results_Merged.json)Note: Make sure the MODEL_PATH in each benchmark script matches your merged model directory.
Important: Only run these benchmarks after completing Step 3 (model repair).
GSM8K_dataset.csv)question, answerDRCD_test.json)math_tw.json)Results are saved as JSON files in the project root directory:
GSM8K_results_Breeze.jsonGSM8K_results_WizardMath.jsonDRCD_results_Breeze.jsonDRCD_results_WizardMath.jsonMath23k_results_Breeze.jsonMath23k_results_WizardMath.jsonGSM8K_results_Merged.jsonDRCD_results_Merged.jsonMath23k_results_Merged.jsonEach results file contains:
is_correct: true/false)check_answer.pyThe automated correctness detection in the benchmark scripts may have some inaccuracies, particularly with percentage handling and numerical format variations. Use check_answer.py to re-evaluate results with improved answer matching logic.
What check_answer.py fixes:
Usage:
Edit check_answer.py and modify line 206 to specify your results file:
INPUT_FILE = "Math23k_results_Merged.json" # Change to your target file
Optionally change the output file name on line 209:
OUTPUT_FILE = "Math23k_results_Merged_percentage_fix.json"
Run the script:
python3 check_answer.py
Output:
*_percentage_fix.json: Updated results file with corrected evaluations*_percentage_fix_changes.json: Detailed log of all evaluation changesRecommendation: Run this on all Math23k results, as they frequently have percentage-related issues.
Solution:
TEST_LIMIT in the evaluation scripts (e.g., set to 50 instead of 100)Solution:
export HTTP_PROXY="http://your-proxy:port"
export HTTPS_PROXY="https://your-proxy:port"
run_merge_SLERP.py to use local directoriesSolution:
run_merge_SLERP.py completed successfully./merged_model/)MODEL_PATH in benchmark scripts if neededSolution:
GSM8K_dataset.csv, DRCD_test.json, and math_tw.json are in the project rootSolution:
# Reinstall dependencies
pip install --upgrade torch transformers mergekit pyyaml tqdm bitsandbytes pillow accelerate
# Verify CUDA availability
python3 -c "import torch; print('CUDA available:', torch.cuda.is_available())"
Solution:
# Make scripts executable
chmod +x baseline_*.py benchmark_*.py run_merge_SLERP.py
For questions or issues related to this project, please contact the project maintainer.
Python
100.0%
This project demonstrates model merging techniques using SLERP (Spherical Linear Interpolation) to combine two language models: Breeze-7B (Traditional Chinese) and WizardMath-7B (Mathematical reasoning). The merged model is evaluated on multiple benchmarks to assess its performance compared to the baseline models.
This project aims to:
Benchmark Datasets:
All dependencies are listed below and can be installed via pip.
cd /path/to/Machine_Learning_Final_Project
python3 -m venv venv
source venv/bin/activate # On Linux/Mac
# OR
venv\Scripts\activate # On Windows
pip install torch transformers mergekit pyyaml tqdm bitsandbytes pillow accelerate huggingface_hub
Library Descriptions:
torch: PyTorch deep learning frameworktransformers: Hugging Face transformers librarymergekit: Model merging toolkitpyyaml: YAML configuration parsertqdm: Progress bar utilitybitsandbytes: 4-bit quantization supportpillow: Image processing library (compatibility)accelerate: Distributed training and inferencehuggingface_hub: Hugging Face Hub API for model downloadspython3 -c "import torch; print('PyTorch version:', torch.__version__)"
python3 -c "import transformers; print('Transformers version:', transformers.__version__)"
Machine_Learning_Final_Project/
├── models/ # (Optional) Local model storage
│ ├── Breeze-7B/ # Breeze-7B model files (if downloaded locally)
│ └── WizardMath-7B/ # WizardMath-7B model files (if downloaded locally)
├── baseline_Breeze_GSM8K.py # Baseline: Breeze on GSM8K
├── baseline_Breeze_DRCD.py # Baseline: Breeze on DRCD
├── baseline_Breeze_Math23k.py # Baseline: Breeze on Math23k
├── baseline_Wizard_GSM8K.py # Baseline: WizardMath on GSM8K
├── baseline_Wizard_DRCD.py # Baseline: WizardMath on DRCD
├── baseline_Wizard_Math23k.py # Baseline: WizardMath on Math23k
├── run_merge_SLERP.py # Model merging script
├── repair_model.py # Model alignment/repair script
├── check_answer.py # Re-evaluate results with improved detection
├── benchmark_Merged_GSM8K.py # Merged model evaluation on GSM8K
├── benchmark_Merged_DRCD.py # Merged model evaluation on DRCD
├── benchmark_Merged_Math23k.py # Merged model evaluation on Math23k
├── GSM8K_dataset.csv # GSM8K test dataset
├── DRCD_test.json # DRCD test dataset (if available)
├── math_tw.json # Math23k dataset
└── README.md # This file
Before merging, establish baseline performance for both models on all three datasets.
# GSM8K benchmark
python3 baseline_Breeze_GSM8K.py
# DRCD benchmark
python3 baseline_Breeze_DRCD.py
# Math23k benchmark
python3 baseline_Breeze_Math23k.py
# GSM8K benchmark
python3 baseline_Wizard_GSM8K.py
# DRCD benchmark
python3 baseline_Wizard_DRCD.py
# Math23k benchmark
python3 baseline_Wizard_Math23k.py
Expected Output:
GSM8K_results_Breeze.json)Note: Each baseline evaluation may take 30-60 minutes depending on your hardware.
Use SLERP (Spherical Linear Interpolation) to merge Breeze-7B and WizardMath-7B.
python3 run_merge_SLERP.py
What happens during merging:
MediaTek-Research/Breeze-7B-Instruct-v1_0WizardLM/WizardMath-7B-V1.1self_attn layers: [0, 0.5, 0.5, 0.6, 0.7]mlp layers: [1, 0.5, 0.7, 0.3, 0.2]0.5 (default)./merged_model/Note: If you prefer to use local models, you can modify the paths in run_merge_SLERP.py (lines 20-21)
Expected Output:
📍 Current Workspace: /path/to/project
📦 Breeze Model: MediaTek-Research/Breeze-7B-Instruct-v1_0
📦 Wizard Model: WizardLM/WizardMath-7B-V1.1
🚀 Starting model merging... (The progress bar finishing means it's done)
✅ Confirmed X weight files exist.
🔧 Handling tokenizer files...
Downloading tokenizer from Hugging Face...
✅ Tokenizer downloaded and saved
🔧 Rebuilding config.json...
✅ Fix completed: vocab_size 32001 -> 32000
✨ All rescue operations successful!
Output Directory: ./merged_model/
Notes:
~/.cache/huggingface/hub/ by defaultAfter merging, run the repair script to align tokenizer and configuration files.
python3 repair_model.py
What happens during repair:
config.json to ensure vocab_size = 32000"mistral"Expected Output:
🔧 Starting repair for: ./merged_model
⬇️ Downloading standard Mistral/WizardMath tokenizer...
✅ Tokenizer files replaced.
📝 Patching config.json...
✅ Config fixed: vocab_size 32001 -> 32000
✨ Repair complete.
Why is this step necessary?
Note: This step requires internet connection to download tokenizer files from Hugging Face Hub.
Evaluate the merged model on all three benchmarks.
# GSM8K benchmark
python3 benchmark_Merged_GSM8K.py
# DRCD benchmark
python3 benchmark_Merged_DRCD.py
# Math23k benchmark
python3 benchmark_Merged_Math23k.py
Expected Output:
GSM8K_results_Merged.json)Note: Make sure the MODEL_PATH in each benchmark script matches your merged model directory.
Important: Only run these benchmarks after completing Step 3 (model repair).
GSM8K_dataset.csv)question, answerDRCD_test.json)math_tw.json)Results are saved as JSON files in the project root directory:
GSM8K_results_Breeze.jsonGSM8K_results_WizardMath.jsonDRCD_results_Breeze.jsonDRCD_results_WizardMath.jsonMath23k_results_Breeze.jsonMath23k_results_WizardMath.jsonGSM8K_results_Merged.jsonDRCD_results_Merged.jsonMath23k_results_Merged.jsonEach results file contains:
is_correct: true/false)check_answer.pyThe automated correctness detection in the benchmark scripts may have some inaccuracies, particularly with percentage handling and numerical format variations. Use check_answer.py to re-evaluate results with improved answer matching logic.
What check_answer.py fixes:
Usage:
Edit check_answer.py and modify line 206 to specify your results file:
INPUT_FILE = "Math23k_results_Merged.json" # Change to your target file
Optionally change the output file name on line 209:
OUTPUT_FILE = "Math23k_results_Merged_percentage_fix.json"
Run the script:
python3 check_answer.py
Output:
*_percentage_fix.json: Updated results file with corrected evaluations*_percentage_fix_changes.json: Detailed log of all evaluation changesRecommendation: Run this on all Math23k results, as they frequently have percentage-related issues.
Solution:
TEST_LIMIT in the evaluation scripts (e.g., set to 50 instead of 100)Solution:
export HTTP_PROXY="http://your-proxy:port"
export HTTPS_PROXY="https://your-proxy:port"
run_merge_SLERP.py to use local directoriesSolution:
run_merge_SLERP.py completed successfully./merged_model/)MODEL_PATH in benchmark scripts if neededSolution:
GSM8K_dataset.csv, DRCD_test.json, and math_tw.json are in the project rootSolution:
# Reinstall dependencies
pip install --upgrade torch transformers mergekit pyyaml tqdm bitsandbytes pillow accelerate
# Verify CUDA availability
python3 -c "import torch; print('CUDA available:', torch.cuda.is_available())"
Solution:
# Make scripts executable
chmod +x baseline_*.py benchmark_*.py run_merge_SLERP.py
For questions or issues related to this project, please contact the project maintainer.
Python
100.0%