This repository demonstrates how to fine-tune the DeepSeek-R1-Distill-Llama-8B model for medical reasoning tasks on Apple Silicon (M1/M2/M3) Macs. The implementation is optimized for machines with 16GB+ RAM and includes both training and testing workflows.
.
├── README.md # Project documentation
├── requirements.txt # Python dependencies
├── deepseek_finetune.py # Training script
├── test_model.py # Testing script
└── .gitignore # Git ignore file
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
wandb login
python deepseek_finetune.py
The training script includes:
# Dataset
dataset_size = 0.05 # 5% of dataset (~1,268 examples)
max_length = 1024 # Sequence length
# Training
batch_size = 2
gradient_accumulation_steps = 4
learning_rate = 1e-4
num_epochs = 1
# LoRA Parameters
lora_r = 4 # LoRA rank
lora_alpha = 16
lora_dropout = 0.1
After training completes, test your model:
python test_model.py
The testing script includes:
# Generation Settings
max_new_tokens = 512
temperature = 0.6 # DeepSeek recommended
top_p = 0.95
repetition_penalty = 1.15
Both scripts include optimizations for Apple Silicon:
During Training:
During Testing:
Out of Memory Errors:
Slow Training:
Poor Loss Convergence:
For production use, consider:
# Dataset
dataset_size = 0.2 # at least 20% of dataset
max_length = 2048 # Full sequence length
# Training
batch_size = 1
gradient_accumulation_steps = 8
learning_rate = 5e-5
num_epochs = 2
# LoRA Parameters
lora_r = 8 # Higher rank
This project is licensed under the MIT License - see the LICENSE file for details.
5 commits
Python
100.0%
This repository demonstrates how to fine-tune the DeepSeek-R1-Distill-Llama-8B model for medical reasoning tasks on Apple Silicon (M1/M2/M3) Macs. The implementation is optimized for machines with 16GB+ RAM and includes both training and testing workflows.
.
├── README.md # Project documentation
├── requirements.txt # Python dependencies
├── deepseek_finetune.py # Training script
├── test_model.py # Testing script
└── .gitignore # Git ignore file
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
wandb login
python deepseek_finetune.py
The training script includes:
# Dataset
dataset_size = 0.05 # 5% of dataset (~1,268 examples)
max_length = 1024 # Sequence length
# Training
batch_size = 2
gradient_accumulation_steps = 4
learning_rate = 1e-4
num_epochs = 1
# LoRA Parameters
lora_r = 4 # LoRA rank
lora_alpha = 16
lora_dropout = 0.1
After training completes, test your model:
python test_model.py
The testing script includes:
# Generation Settings
max_new_tokens = 512
temperature = 0.6 # DeepSeek recommended
top_p = 0.95
repetition_penalty = 1.15
Both scripts include optimizations for Apple Silicon:
During Training:
During Testing:
Out of Memory Errors:
Slow Training:
Poor Loss Convergence:
For production use, consider:
# Dataset
dataset_size = 0.2 # at least 20% of dataset
max_length = 2048 # Full sequence length
# Training
batch_size = 1
gradient_accumulation_steps = 8
learning_rate = 5e-5
num_epochs = 2
# LoRA Parameters
lora_r = 8 # Higher rank
This project is licensed under the MIT License - see the LICENSE file for details.
5 commits
Python
100.0%