Where On-Device and Cloud LLMs Meet について
Minions は、小型オンデバイスモデルがクラウドのフロンティアモデルと協働できる通信プロトコルです。長い文脈をローカルで処理することで、品質低下を最小限にしながらクラウドコストを削減します。
主な機能
- 01ローカルとクラウド LLM の協働プロトコル
- 02ローカルコンテキスト処理でコスト削減
- 03Ollama と Tokasaurus ローカルサーバー対応
- 04OpenAI と Together AI クラウド統合
- 05ストリーミング出力とカスタムコールバック
活用シーン
- 01大規模アプリケーションのコストと品質のバランス
- 02長いドキュメントのローカル高速処理
- 03複数 LLM プロバイダーの強みを活用
- 04ハイブリッドローカル-クラウド AI アーキテクチャの研究
詳細

オンデバイスと クラウド LLM が出会う場所
これは何ですか? Minions は、小規模なオンデバイスモデルがクラウドのフロンティアモデルと協力できるようにする通信プロトコルです。長いコンテキストをローカルで読み込むだけで、品質低下を最小限に抑えながらクラウドコストを削減できます。このリポジトリはプロトコルのデモンストレーションを提供しています。以下から始めるか、詳細については論文とブログポストをご覧ください。
論文: Minions: Cost-efficient Collaboration Between On-device and Cloud Language Models
ブログポスト: https://hazyresearch.stanford.edu/blog/2025-02-24-minions
セットアップ
以下のセットアップを Mac と Ubuntu で Python 3.10-3.11 でテストしました (注: Python 3.13 はサポートされていません)
オプション: 好みのパッケージマネージャー (例: conda, venv, uv) で仮想環境を作成します
conda create -n minions python=3.11
ステップ 1: リポジトリをクローンして Python パッケージをインストールします。
git clone https://github.com/HazyResearch/minions.git
cd minions
pip install -e . # installs the minions package in editable mode
ステップ 2: ローカルモデルを実行するためのサーバーをインストールします。
ローカルモデルを実行するためのサーバーとして ollama と tokasaurus の 2 つをサポートしています。これらの少なくとも 1 つをインストールする必要があります。
- NVIDIA GPU にアクセスできない場合は
ollamaを使用する必要があります。ここの指示に従ってollamaをインストールしてください。Flash Attention を有効にするには、launchctl setenv OLLAMA_FLASH_ATTENTION 1を実行し、Mac の場合は ollama アプリを再起動してください。 - NVIDIA GPU にアクセスでき、Minions プロトコルを実行する場合は
tokasaurusを使用する必要があります。tokasaurusはtokasaurusの高スループットの利点があります。以下のコマンドでtokasaurusをインストールしてください:
uv pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ tokasaurus==0.0.1.post1
ステップ 3: 次のクラウド LLM プロバイダーの少なくとも 1 つの API キーを設定します。
必要に応じて、クラウドモデルの OpenAI API キーまたは TogetherAI API キーを作成してください。
export OPENAI_API_KEY=<your-openai-api-key>
export TOGETHER_API_KEY=<your-together-api-key>
Minions デモアプリケーション
Minion または Minions プロトコルを試すには、以下のコマンドを実行します:
streamlit run app.py
ollama クライアントに関するエラーが表示されている場合は、
An error occurred: Failed to connect to Ollama. Please check that Ollama is downloaded, running and accessible. https://ollama.com/download
以下のコマンドを実行してみてください:
OLLAMA_FLASH_ATTENTION=1 ollama serve
サンプルコード: Minion (単数)
以下の例は ollama ローカルクライアントと openai リモートクライアント用です。
プロトコルは minion です。
from minions.clients.ollama import OllamaClient
from minions.clients.openai import OpenAIClient
from minions.minion import Minion
local_client = OllamaClient(
model_name="llama3.2",
)
remote_client = OpenAIClient(
model_name="gpt-4o",
)
# Instantiate the Minion object with both clients
minion = Minion(local_client, remote_client)
context = """
Patient John Doe is a 60-year-old male with a history of hypertension. In his latest checkup, his blood pressure was recorded at 160/100 mmHg, and he reported occasional chest discomfort during physical activity.
Recent laboratory results show that his LDL cholesterol level is elevated at 170 mg/dL, while his HDL remains within the normal range at 45 mg/dL. Other metabolic indicators, including fasting glucose and renal function, are unremarkable.
"""
task = "Based on the patient's blood pressure and LDL cholesterol readings in the context, evaluate whether these factors together suggest an increased risk for cardiovascular complications."
# Execute the minion protocol for up to two communication rounds
output = minion(
task=task,
context=[context],
max_rounds=2
)
ストリーミング出力
生成されるにつれてリアルタイムでレスポンス出力をストリーミングするには、stream_output パラメータを使用できます:
from minions.clients.openai import OpenAIClient
from minions.minion import Minion
# Enable streaming in the client
openai_client = OpenAIClient(
model_name="gpt-4o",
stream=True # Enable streaming in the client
)
# Create the minion with streaming enabled
minion = Minion(
local_client=openai_client,
remote_client=openai_client,
stream_output=True # Enable streaming in the Minion
)
# Now responses will print incrementally in real-time
result = minion(
task="Generate a short poem about artificial intelligence",
context=["Make it thoughtful but accessible to general audiences"]
)
ストリーミングコンテンツの表示方法をより細かく制御するためにカスタムコールバック関数を提供することもできます:
def custom_callback(agent_type, chunk, is_streaming=False, is_final=False):
"""Custom callback to handle streaming output."""
if is_streaming:
# Process streaming chunks in real-time
# For example, you could format or colorize the output
pass
elif chunk:
# Handle complete responses
print(f"\n[{agent_type}] COMPLETE RESPONSE: {chunk}\n")
# Create the minion with custom callback
minion = Minion(
local_client=openai_client,
remote_client=openai_client,
callback=custom_callback,
stream_output=True
)
完全な例については examples/stream_example.py ファイルを参照してください。
サンプルコード: Minions (複数)
以下の例は ollama ローカルクライアントと openai リモートクライアント用です。
プロトコルは minions です。
from minions.clients.ollama import OllamaClient
from minions.clients.openai import OpenAIClient
from minions.minions import Minions
from pydantic import BaseModel
class StructuredLocalOutput(BaseModel):
explanation: str
citation: str | None
answer: str | None
local_client = OllamaClient(
model_name="llama3.2",
temperature=0.0,
structured_output_schema=StructuredLocalOutput
)
remote_client = OpenAIClient(
model_name="gpt-4o",
)
# Instantiate the Minion object with both clients
minion = Minions(local_client, remote_client)
context = """
Patient John Doe is a 60-year-old male with a history of hypertension. In his latest checkup, his blood pressure was recorded at 160/100 mmHg, and he reported occasional chest discomfort during physical activity.
Recent laboratory results show that his LDL cholesterol level is elevated at 170 mg/dL, while his HDL remains within the normal range at 45 mg/dL. Other metabolic indicators, including fasting glucose and renal function, are unremarkable.
"""
task = "Based on the patient's blood pressure and LDL cholesterol readings in the context, evaluate whether these factors together suggest an increased risk for cardiovascular complications."
# Execute the minion protocol for up to two communication rounds
output = minion(
task=task,
doc_metadata="Medical Report",
context=[context],
max_rounds=2
)
Python ノートブック
Minion/Minions をノートブックで実行するには、minions.ipynb をチェックアウトしてください。
CLI
Minion/Minions をコマンドラインで実行するには、minions_cli.py をチェックアウトしてください。
minions --help
minions --context <path_to_context> --protocol <minion|minions>
メンテナー
- Avanika Narayan (連絡先: [email protected])
- Dan Biderman (連絡先: [email protected])
- Sabri Eyuboglu (連絡先: [email protected])
ニューラルアーキテクチャサーチを通じた自律的な LLM の改善
このプロジェクトは、Large Language Model が進化的手法を通じて自身のアーキテクチャを自律的に改善することを可能にするニューラルアーキテクチャサーチ (NAS) システムを実装しています。
概要
このシステムは進化的アルゴリズムを使用して、LLM のファインチューニングに最適なハイパーパラメータとアーキテクチャ構成を探索します。自動的に以下を実行します。
- 多様なアーキテクチャ構成の集団を生成
- 各アーキテクチャを訓練・評価
- 最高性能のモデルを選択
- ミューテーションを通じて新世代を生成
- 最適な構成を見つけるために複数世代に対してプロセスを繰り返す
主な機能
- 進化的探索: 選択とミューテーションを使用してアーキテクチャ空間を探索
- パラメータ効率的なファインチューニング: LoRA (Low-Rank Adaptation) 技術を活用
- 自動評価: モデルは自動的に訓練・評価
- 進捗追跡: 各世代の後に結果を保存
- 自己改善: システムは継続的に自身のアーキテクチャを改善
探索空間
NAS は以下のアーキテクチャパラメータを探索します。
- LoRA ランク (r)
- LoRA アルファ値
- ファインチューニング対象モジュール
- 学習率
- バッチサイズ
- グラディエント累積ステップ
- ランク安定化 LoRA の使用
使用方法
NAS システムを実行するには以下を使用します。
python nas.py
nas.py の __main__ セクション内のパラメータを修正して、以下をカスタマイズできます。
- ベースモデル
- ファインチューニング用データセット
- 集団サイズ
- 世代数
- シーケンス長
- 出力ディレクトリ
動作方法
- 初期化: ランダムなアーキテクチャ構成の集団を生成
- 訓練: 各アーキテクチャをデータセット上で訓練
- 評価: モデルをパープレキシティに基づいて評価
- 選択: 次世代のためのトップパフォーマーを選択
- ミューテーション: パラメータをランダムに修正して新しいアーキテクチャを生成
- 繰り返し: 複数世代に対してプロセスを繰り返す
最高性能のモデルは各改善後に保存され、結果の完全な履歴は JSON 形式で保持されます。
コメント
AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。
