📱

Foundry Localをさわってみた

に公開

きっかけ

公開されてから1か月たちますが、WindowsのローカルPCでカンタンにエッジAIを動かせられるとのことで、興味がでたのでさわってみました。

インストール方法

PowerShellで以下を実行するだけ

winget install Microsoft.FoundryLocal

アーキテクチャ


Foundry Local サービスの特徴として、推論エンジンを操作するための標準インターフェイスを提供する OpenAI 互換の REST サーバーが含まれており、 Foundry Local SDKを使用してアプリケーションと連携させたり、HTTP経由でモデルを実行することが可能です。

またONNXランタイムが入っており、複数のハードウェア プロバイダー (NVIDIA、AMD、Intel、Qualcomm) とデバイスの種類 (NPU、CPU、GPU) と連携が可能です。

使用可能なモデル一覧

以下でモデルカタログを確認できます。
このモデルカタログ上では、量子化のバリエーションまでは選択できなさそうです。

foundry model list

2025/6/27時点では以下が使用できるようです。
phi-4やdeepseekが使えるみたいです。

🟢 Service is Started on http://localhost:5273, PID 22072!
Alias                          Device     Task               File Size    License      Model ID
-----------------------------------------------------------------------------------------------
phi-4                          GPU        chat-completion    8.37 GB      MIT          Phi-4-generic-gpu
                               CPU        chat-completion    10.16 GB     MIT          Phi-4-generic-cpu
--------------------------------------------------------------------------------------------------------
mistral-7b-v0.2                GPU        chat-completion    4.07 GB      apache-2.0   mistralai-Mistral-7B-Instruct-v0-2-generic-gpu
                               CPU        chat-completion    4.07 GB      apache-2.0   mistralai-Mistral-7B-Instruct-v0-2-generic-cpu
-------------------------------------------------------------------------------------------------------------------------------------
phi-3.5-mini                   GPU        chat-completion    2.16 GB      MIT          Phi-3.5-mini-instruct-generic-gpu
                               CPU        chat-completion    2.53 GB      MIT          Phi-3.5-mini-instruct-generic-cpu
------------------------------------------------------------------------------------------------------------------------
phi-3-mini-128k                GPU        chat-completion    2.13 GB      MIT          Phi-3-mini-128k-instruct-generic-gpu
                               CPU        chat-completion    2.54 GB      MIT          Phi-3-mini-128k-instruct-generic-cpu
---------------------------------------------------------------------------------------------------------------------------
phi-3-mini-4k                  GPU        chat-completion    2.13 GB      MIT          Phi-3-mini-4k-instruct-generic-gpu
                               CPU        chat-completion    2.53 GB      MIT          Phi-3-mini-4k-instruct-generic-cpu
-------------------------------------------------------------------------------------------------------------------------
deepseek-r1-14b                GPU        chat-completion    10.27 GB     MIT          deepseek-r1-distill-qwen-14b-generic-gpu
                               CPU        chat-completion    11.51 GB     MIT          deepseek-r1-distill-qwen-14b-generic-cpu
-------------------------------------------------------------------------------------------------------------------------------
deepseek-r1-7b                 GPU        chat-completion    5.58 GB      MIT          deepseek-r1-distill-qwen-7b-generic-gpu
                               CPU        chat-completion    6.43 GB      MIT          deepseek-r1-distill-qwen-7b-generic-cpu
------------------------------------------------------------------------------------------------------------------------------
qwen2.5-0.5b                   GPU        chat-completion    0.68 GB      apache-2.0   qwen2.5-0.5b-instruct-generic-gpu
                               CPU        chat-completion    0.80 GB      apache-2.0   qwen2.5-0.5b-instruct-generic-cpu
------------------------------------------------------------------------------------------------------------------------
qwen2.5-1.5b                   GPU        chat-completion    1.51 GB      apache-2.0   qwen2.5-1.5b-instruct-generic-gpu
                               CPU        chat-completion    1.78 GB      apache-2.0   qwen2.5-1.5b-instruct-generic-cpu
------------------------------------------------------------------------------------------------------------------------
qwen2.5-coder-0.5b             GPU        chat-completion    0.52 GB      apache-2.0   qwen2.5-coder-0.5b-instruct-generic-gpu
                               CPU        chat-completion    0.80 GB      apache-2.0   qwen2.5-coder-0.5b-instruct-generic-cpu
------------------------------------------------------------------------------------------------------------------------------
qwen2.5-coder-7b               GPU        chat-completion    4.73 GB      apache-2.0   qwen2.5-coder-7b-instruct-generic-gpu
                               CPU        chat-completion    6.16 GB      apache-2.0   qwen2.5-coder-7b-instruct-generic-cpu
----------------------------------------------------------------------------------------------------------------------------
qwen2.5-coder-1.5b             GPU        chat-completion    1.25 GB      apache-2.0   qwen2.5-coder-1.5b-instruct-generic-gpu
                               CPU        chat-completion    1.78 GB      apache-2.0   qwen2.5-coder-1.5b-instruct-generic-cpu
------------------------------------------------------------------------------------------------------------------------------
phi-4-mini                     GPU        chat-completion    3.72 GB      MIT          Phi-4-mini-instruct-generic-gpu
                               CPU        chat-completion    4.80 GB      MIT          Phi-4-mini-instruct-generic-cpu
----------------------------------------------------------------------------------------------------------------------
phi-4-mini-reasoning           GPU        chat-completion    3.15 GB      MIT          Phi-4-mini-reasoning-generic-gpu
                               CPU        chat-completion    4.52 GB      MIT          Phi-4-mini-reasoning-generic-cpu
-----------------------------------------------------------------------------------------------------------------------
qwen2.5-14b                    CPU        chat-completion    11.06 GB     apache-2.0   qwen2.5-14b-instruct-generic-cpu
-----------------------------------------------------------------------------------------------------------------------
qwen2.5-7b                     GPU        chat-completion    5.20 GB      apache-2.0   qwen2.5-7b-instruct-generic-gpu
                               CPU        chat-completion    6.16 GB      apache-2.0   qwen2.5-7b-instruct-generic-cpu
----------------------------------------------------------------------------------------------------------------------
qwen2.5-coder-14b              GPU        chat-completion    8.79 GB      apache-2.0   qwen2.5-coder-14b-instruct-generic-gpu
                               CPU        chat-completion    11.06 GB     apache-2.0   qwen2.5-coder-14b-instruct-generic-cpu

ひとまずチャットしてみる

以下のコマンドだけで、モデルのダウンロード&チャットができます。
gpu版かcpu版かは、自動で判定されるみたいです。

foundry model run phi-4-mini

チャットを打ち込んでみます。
phi-4-miniは、2023年時点の情報については、質問出来るようです。

> 現在のアメリカの大統領は?
🤖 2023年の時点で、アメリカの大統領はジョー・バイデンです。彼は2021年1月20日に就任しました。最新の情報を確認するには、信頼できるニュースソースを参照してください。

アプリケーションとの連携

openaiおよびfoundry-local-sdkを使用することにより、簡単にオフラインで実行できるAIアプリケーションが作成できます。

venvやcondaなどで仮想環境を立て、以下でopenaiおよびfoundry-local-sdkをインストールします。

pip install openai
pip install foundry-local-sdk

簡易アプリケーションは以下で実装します。

app.py
import openai
from foundry_local import FoundryLocalManager

# By using an alias, the most suitable model will be downloaded 
# to your end-user's device. 
alias = "phi-4-mini"

# Create a FoundryLocalManager instance. This will start the Foundry
# Local service if it is not already running and load the specified model.
manager = FoundryLocalManager(alias)
# The remaining code uses the OpenAI Python SDK to interact with the local model.
# Configure the client to use the local Foundry service
client = openai.OpenAI(
    base_url=manager.endpoint,
    api_key=manager.api_key  # API key is not required for local usage
)
# Set the model to use and generate a response
response = client.chat.completions.create(
    model=manager.get_model_info(alias).id,
    messages=[{"role": "user", "content": "黄金比とは何ですか?"}]
)
print(response.choices[0].message.content)

以下でアプリケーションを実行します。

pytyon app.py

返答内容が途中までのようですが、以下の結果が返ってきました。

黄金比は、約1.618033988749895の数値であり、古代ギリシャの数学者フィボナッチによって発見されました。黄金比は、長さの2つの部分の比率であり、1つの部分がもう1つの部分の1.618倍であるときに、2つの部分の比率は黄金比に等しいです。この比率は、自然界の美しさと調和を表すと考えられており、芸術、建築、工学などさまざまな分野で使用されてきました。黄金比は、自然界の美しさと調和を表すと考えられており、芸術、建築、工学などさまざまな分野で使用されてきました。黄金比は、自然界の美しさと調和を表す

リソースの消費状況

上記のphi-4-miniで動かした際のタスクマネージャー画面となります。
SLMといえども、phiクラスだとやはりメモリは10数GBは使用されてしまいますね。

体感としてはサクサクチャットに答えてくれます。

Oliveで量子化したONNXモデルが使用できる

以下に記載されておりました。任意のONNX 形式のモデルを使用できるとのこと。
ONNX 形式の最適化にはOliveというライブラリを使用します。
https://learn.microsoft.com/ja-jp/azure/ai-foundry/foundry-local/how-to/how-to-compile-hugging-face-models

所感

サクッとオフラインLLMアプリが作れるのは非常に良さそうです。
ただ、量子化のファイル形式がONNXしかサポートされていなさそうなので、AppleのMLX形式とかに対応してくれるとかなり使えるのではないかと。

ヘッドウォータース

Discussion