Skip to content

Conversation

@pc0618
Copy link

@pc0618 pc0618 commented Mar 26, 2025

Added a module in minions/utils/minion_autotrain.py that automatically identifies local hardware capabilities, selects a suitable finetuning strategy, and finetunes an SLM from huggingface on minion_logs/ which should contain all conversations between a local SLM and a remote LLM. I encode constraints on model selection and finetuning strategy selection so as to select the most powerful model and finetuning strategy to fit in device memory. This script makes general optimizations based on hardware constraints; a user could identify a performance metric for a downstream task and make minor adjustments to hyperparameters like lora_r, lora_alpha, and lora_dropout, num_epochs , learning_rate etc. if they feel this is necessary (although empirically dramatic differences from the default values in the script generally do not yield worthwhile gains).

minions/utils/minion_autotrain.py:
-Automatically detects hardware capabilities (GPU, CPU, MPS/Apple Silicon)
-Selects the optimal open-source LLM based on hardware specs. Right now we hardcode "TinyLlama/TinyLlama-1.1B-Chat-v1.0", "meta-llama/Llama-3.2-1B", "meta-llama/Llama-3.2-3B", and "microsoft/phi-4" (14.7B) as available models and select the largest model that will fit in system memory
-Chooses the best training protocol (QLoRA, LoRA, or Full-Finetuning) based on the intuition that full-finetuning (in BF16) is the most performant on downstream task performance, followed by LoRA (8 bit), then QLoRA (4 bit)
-Optimizes some hyperparameters such as batch size for the selected model and hardware. Others such as lora_r, lora_alpha, and lora_dropout are fixed following current practices for optimizing downstream task accuracy but can be changed in class HyperparameterOptimizer
-Processes minion logs to extract training pairs where we only use the "assistant" outputs from the minion logs for training
-Implements a training pipeline using Hugging Face Transformers and PEFT

Updated minions/utils/init.py to expose the auto_train_minion function.

To test this utility, run python -m minions.utils.minion_autotrain --model-name default which will make use of TinyLlama-1.1B-Chat-v1.0 , one of the smallest models that does not require the appropriate Huggingface permissions.

To have the utility automatically select the largest model that will fit into system memory, simply run python -m minions.utils.minion_autotrain which will first detect your hardware capabilities, then select the optimal model and training approach, process your minion logs to create a training dataset, train the model with the best hyperparameters for your setup, save the trained model to the specified output directory. We use argparse to provide defaults for log directory and saved model directory.

@guynich
Copy link
Contributor

guynich commented Apr 25, 2025

This is interesting!
If I understand correctly this workflow will fine-tune a local model based on logs generated from previous runs of the minion communication protocol with a non fine-tuned local model.
I have several questions:

  1. should the minion_logs used for the fine-tuning come from a local model running on the same local hardware?
  2. would the fine-tuned local model then be suitable for use with the more performant minions communication protocol?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants