0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Foundry Local でローカルAI推論をやってみる

Posted at

Foundry Local がパブリックプレビュー版で提供されています。

2025年、MicrosoftはFoundry Localをパブリックプレビューとして公開されています。これは、Microsoft Build 2025で紹介されていました。「ネットワーク遅延をなくしたい」、「閉域環境やオンプレでAIを使いたい」といった要件もあるのですが、生成AIで課題になりがちな機密データを外部送信できない問題に対する1つの手段として利用できるものになります。

この記事では、以下の内容を紹介しようと思います。

  • Foundry Localの概要と仕組み
  • 関連技術「Olive」によるモデル変換
  • 実際の導入・推論手順

Foundry Localとは

概要

Foundry Localは、ONNX Runtimeをベースに、クラウド接続なしでAIモデルを手元のデバイスで推論できます。
Foundry LocalはMicrosoft Build 2025でパブリックプレビューとして公開されました。当時この機能はAzure AI Foundryの中でアナウンスがありました。正式にGAされる際にはAzure AI Foundry上で構築したAI エージェントを何らかの形でローカル実行する仕組みまで提供することを想定しているのかもしれません(そうなるとなかなか面白いものになるのですが)。
主な特徴は以下の通りです。モデルとしてonnxを使うところがollamaやlmStudioと異なる点と言えるとおもいます。それ以外の機能のほとんどは従来からあるローカルLLMの概念をカバーしているものになっています。

機能 内容
ONNXモデル対応 ONNX形式のモデルを直接実行可能
オフライン実行 クラウド不要の完全ローカル推論
ハードウェア最適化 GPU/NPUを自動検出して高速化
CLI / SDK / REST対応 開発環境や用途に応じて選択可能

Founry LocalはollamaやLMStudioのようにローカルLLMサービスとして常駐します。ユーザはCLI,SDK,Rest APIを使ってFounry Local上で動作するモデルを利用することが可能です。簡単な処理フローは以下のようになります。

  1. CLIやSDKでコマンドを送信
  2. Foundry Local Serviceが起動しモデルをロード
  3. ONNX Runtimeが推論処理を担当
  4. ハードウェア抽象層を通して最適なデバイスで実行

現時点(2025/10/08)で利用できるモデルのリストは以下のようになります。

モデル一覧(コマンドの出力をそのままコピペ)
Alias                          Device     Task               File Size    License      Model ID
-----------------------------------------------------------------------------------------------
phi-4                          GPU        chat-completion    8.37 GB      MIT          Phi-4-cuda-gpu:1
                               GPU        chat-completion    8.37 GB      MIT          Phi-4-generic-gpu:1
                               CPU        chat-completion    10.16 GB     MIT          Phi-4-generic-cpu:1
----------------------------------------------------------------------------------------------------------
phi-3-mini-128k                GPU        chat-completion    2.13 GB      MIT          Phi-3-mini-128k-instruct-cuda-gpu:1
                               GPU        chat-completion    2.13 GB      MIT          Phi-3-mini-128k-instruct-generic-gpu:1
                               CPU        chat-completion    2.54 GB      MIT          Phi-3-mini-128k-instruct-generic-cpu:2
-----------------------------------------------------------------------------------------------------------------------------
phi-3-mini-4k                  GPU        chat-completion    2.13 GB      MIT          Phi-3-mini-4k-instruct-cuda-gpu:1
                               GPU        chat-completion    2.13 GB      MIT          Phi-3-mini-4k-instruct-generic-gpu:1
                               CPU        chat-completion    2.53 GB      MIT          Phi-3-mini-4k-instruct-generic-cpu:2
---------------------------------------------------------------------------------------------------------------------------
mistral-7b-v0.2                GPU        chat-completion    3.98 GB      apache-2.0   mistralai-Mistral-7B-Instruct-v0-2-cuda-gpu:1
                               GPU        chat-completion    4.07 GB      apache-2.0   mistralai-Mistral-7B-Instruct-v0-2-generic-gpu:1
                               CPU        chat-completion    4.07 GB      apache-2.0   mistralai-Mistral-7B-Instruct-v0-2-generic-cpu:2
---------------------------------------------------------------------------------------------------------------------------------------
phi-3.5-mini                   GPU        chat-completion    2.13 GB      MIT          Phi-3.5-mini-instruct-cuda-gpu:1
                               GPU        chat-completion    2.16 GB      MIT          Phi-3.5-mini-instruct-generic-gpu:1
                               CPU        chat-completion    2.53 GB      MIT          Phi-3.5-mini-instruct-generic-cpu:1
--------------------------------------------------------------------------------------------------------------------------
deepseek-r1-14b                GPU        chat-completion    9.83 GB      MIT          deepseek-r1-distill-qwen-14b-cuda-gpu:3
                               GPU        chat-completion    10.27 GB     MIT          deepseek-r1-distill-qwen-14b-generic-gpu:3
                               CPU        chat-completion    11.51 GB     MIT          deepseek-r1-distill-qwen-14b-generic-cpu:3
---------------------------------------------------------------------------------------------------------------------------------
deepseek-r1-7b                 GPU        chat-completion    5.28 GB      MIT          deepseek-r1-distill-qwen-7b-cuda-gpu:3
                               GPU        chat-completion    5.58 GB      MIT          deepseek-r1-distill-qwen-7b-generic-gpu:3
                               CPU        chat-completion    6.43 GB      MIT          deepseek-r1-distill-qwen-7b-generic-cpu:3
--------------------------------------------------------------------------------------------------------------------------------
qwen2.5-0.5b                   GPU        chat-completion    0.52 GB      apache-2.0   qwen2.5-0.5b-instruct-cuda-gpu:3
                               GPU        chat-completion    0.68 GB      apache-2.0   qwen2.5-0.5b-instruct-generic-gpu:3
                               CPU        chat-completion    0.80 GB      apache-2.0   qwen2.5-0.5b-instruct-generic-cpu:3
--------------------------------------------------------------------------------------------------------------------------
qwen2.5-1.5b                   GPU        chat-completion    1.25 GB      apache-2.0   qwen2.5-1.5b-instruct-cuda-gpu:3
                               GPU        chat-completion    1.51 GB      apache-2.0   qwen2.5-1.5b-instruct-generic-gpu:3
                               CPU        chat-completion    1.78 GB      apache-2.0   qwen2.5-1.5b-instruct-generic-cpu:3
--------------------------------------------------------------------------------------------------------------------------
qwen2.5-coder-7b               GPU        chat-completion    4.73 GB      apache-2.0   qwen2.5-coder-7b-instruct-cuda-gpu:3
                               GPU        chat-completion    4.73 GB      apache-2.0   qwen2.5-coder-7b-instruct-generic-gpu:3
                               CPU        chat-completion    6.16 GB      apache-2.0   qwen2.5-coder-7b-instruct-generic-cpu:3
------------------------------------------------------------------------------------------------------------------------------
qwen2.5-coder-0.5b             GPU        chat-completion    0.52 GB      apache-2.0   qwen2.5-coder-0.5b-instruct-cuda-gpu:3
                               GPU        chat-completion    0.52 GB      apache-2.0   qwen2.5-coder-0.5b-instruct-generic-gpu:3
                               CPU        chat-completion    0.80 GB      apache-2.0   qwen2.5-coder-0.5b-instruct-generic-cpu:3
--------------------------------------------------------------------------------------------------------------------------------
qwen2.5-coder-1.5b             GPU        chat-completion    1.25 GB      apache-2.0   qwen2.5-coder-1.5b-instruct-cuda-gpu:3
                               GPU        chat-completion    1.25 GB      apache-2.0   qwen2.5-coder-1.5b-instruct-generic-gpu:3
                               CPU        chat-completion    1.78 GB      apache-2.0   qwen2.5-coder-1.5b-instruct-generic-cpu:3
--------------------------------------------------------------------------------------------------------------------------------
phi-4-mini                     GPU        chat-completion    3.60 GB      MIT          Phi-4-mini-instruct-cuda-gpu:4
                               GPU        chat-completion    3.72 GB      MIT          Phi-4-mini-instruct-generic-gpu:4
                               CPU        chat-completion    4.80 GB      MIT          Phi-4-mini-instruct-generic-cpu:4
------------------------------------------------------------------------------------------------------------------------
phi-4-mini-reasoning           GPU        chat-completion    3.15 GB      MIT          Phi-4-mini-reasoning-cuda-gpu:2
                               GPU        chat-completion    3.15 GB      MIT          Phi-4-mini-reasoning-generic-gpu:2
                               CPU        chat-completion    4.52 GB      MIT          Phi-4-mini-reasoning-generic-cpu:2
-------------------------------------------------------------------------------------------------------------------------
qwen2.5-14b                    GPU        chat-completion    8.79 GB      apache-2.0   qwen2.5-14b-instruct-cuda-gpu:3
                               CPU        chat-completion    11.06 GB     apache-2.0   qwen2.5-14b-instruct-generic-cpu:3
-------------------------------------------------------------------------------------------------------------------------
qwen2.5-7b                     GPU        chat-completion    4.73 GB      apache-2.0   qwen2.5-7b-instruct-cuda-gpu:3
                               GPU        chat-completion    5.20 GB      apache-2.0   qwen2.5-7b-instruct-generic-gpu:3
                               CPU        chat-completion    6.16 GB      apache-2.0   qwen2.5-7b-instruct-generic-cpu:3
------------------------------------------------------------------------------------------------------------------------
qwen2.5-coder-14b              GPU        chat-completion    8.79 GB      apache-2.0   qwen2.5-coder-14b-instruct-cuda-gpu:3
                               GPU        chat-completion    8.79 GB      apache-2.0   qwen2.5-coder-14b-instruct-generic-gpu:3
                               CPU        chat-completion    11.06 GB     apache-2.0   qwen2.5-coder-14b-instruct-generic-cpu:3
-------------------------------------------------------------------------------------------------------------------------------
gpt-oss-20b                    GPU        chat-completion    9.65 GB      apache-2.0   gpt-oss-20b-cuda-gpu:1

一覧にないものも自身でonnxファイルを用意することでモデルとして利用可能です。例えば、ONNX Model Zooでは様々な用途のモデルをダウンロードできるのですがこういったものも利用可能です。
またHugging faceに登録されているモデルであれば、Oliveをつかってonnxに変換して利用するといった手段も可能です。

関連技術:Oliveとは

Oliveは、Microsoftが開発したAIモデル最適化フレームワークです。 Hugging FaceやPyTorchのモデルをONNX形式に変換し、デバイスに最適化します。

インストール

以下のコマンドを入力して導入します。最適化の方法によって少しインストールするものが変わったりします。以下のコマンドについてはCPUに最適化したonnxを生成する方法です。

PS D:\> python -m venv .venv
PS D:\> .\.venv\scripts\activate
PS D:\> pip install olive-ai[auto-opt]
PS D:\> pip install transformers==4.53.3 trl==0.20.0 onnxruntime-genai

実際にHugging Faceの Phi-4-mini-instruct モデルを最適化してみました。oliveはHugging faceからモデルを取得します。このためあらかじめHugging faceにアカウントを作成しアクセストークンを作成し、コマンドラインからHugging faceにアクセスできるようにしておきます。

PS D:\> huggingface-cli login
    _|    _|  _|    _|    _|_|_|    _|_|_|  _|_|_|  _|      _|    _|_|_|      _|_|_|_|    _|_|      _|_|_|  _|_|_|_|
    _|    _|  _|    _|  _|        _|          _|    _|_|    _|  _|            _|        _|    _|  _|        _|
    _|_|_|_|  _|    _|  _|  _|_|  _|  _|_|    _|    _|  _|  _|  _|  _|_|      _|_|_|    _|_|_|_|  _|        _|_|_|
    _|    _|  _|    _|  _|    _|  _|    _|    _|    _|    _|_|  _|    _|      _|        _|    _|  _|        _|
    _|    _|    _|_|      _|_|_|    _|_|_|  _|_|_|  _|      _|    _|_|_|      _|        _|    _|    _|_|_|  _|_|_|_|

    A token is already saved on your machine. Run `hf auth whoami` to get more information or `hf auth logout` if you want to log out.
    Setting a new token will erase the existing one.
    To log in, `huggingface_hub` requires a token generated from https://huggingface.co/settings/tokens .
Token can be pasted using 'Right-Click'.
Enter your token (input will not be visible):
Add token as git credential? (Y/n) n
Token is valid (permission: fineGrained).
The token `XXXXXXXX` has been saved to /XXXXXXX/huggingface/stored_tokens
Your token has been saved to /XXXXXXX/huggingface/token
Login successful.
PS D:\> olive optimize -m microsoft/Phi-4-mini-instruct -o ./models/phi4_onnx

実行時の出力と生成物

└─models
    └─phi4_onnx
        │  model_config.json
        │
        └─model
                added_tokens.json
                chat_template.jinja
                config.json
                configuration_phi3.py
                genai_config.json
                generation_config.json
                merges.txt
                model.onnx
                model.onnx.data
                modeling_phi3.py
                special_tokens_map.json
                tokenizer.json
                tokenizer_config.json
                vocab.json

現時点でのバージョンでFoundry Localで提供しているモデル以外を利用する場合はモデルキャッシュフォルダを変更後、作成したモデルをロードします。現在のFoundry Localはまだパブリックプレビュー段階のため少し手間がかかる作業がある状況です。

デフォルトのキャッシュフォルダは以下になります。
C:\Users[ユーザ名].foundry\cache\models

foundry cache cd D:\WorkSpaces\olive\models
foundry cache list
foundry model run model

結果:

PS D:\demo> foundry model run model

Interactive Chat. Enter /? or /help for help.
Press Ctrl+C to cancel generation. Type /exit to leave the chat.

Interactive mode, please enter your prompt
> hello
🧠 Thinking...
🤖 Hello! How can I help you today?
>

Getting Started: Foundry Localを動かしてみる

実際にFoudry Loaclを動かしてみましょう。Foudry Local一式はGithubで公開されています。

インストール

Windows:

PS D:\demo> winget install Microsoft.FoundryLocal

MAC:

brew tap microsoft/foundrylocal
brew install foundrylocal

起動と確認

PS D:\demo> foundry service set --show
No settings changed
{
  "defaultLogLevel": 2,
  "serviceSettings": {
    "host": "127.0.0.1",
    "port": 23184,
    "cacheDirectoryPath": "C:\Users\[ユーザ名]\.foundry\cache\models",
    "schema": "http",
    "pipeName": "inference_agent",
    "defaultSecondsForModelTTL": 600,
    "initialConnectionTimeoutInSeconds": 3
  }
}
PS D:\demo> foundry service start
🟢 Service is Started on http://127.0.0.1:xxxxx/, PID 12364!

Foundry Localで提供されているモデル一覧の取得

PS D:\demo> foundry model list
Alias                          Device     Task               File Size    License      Model ID
-----------------------------------------------------------------------------------------------
phi-4                          GPU        chat-completion    8.37 GB      MIT          Phi-4-cuda-gpu:1
...

推論実行

他のローカルLLMの仕組みと同様で、初回にモデルをローカルにキャッシュし、ロードします。
以下のコマンドは簡単な動作確認をするためにプロンプトを引数に渡して処理を行っています。
この時点でサービスとして利用できるようになっているため、OpenAI API準拠のRest APIでも処理可能です。

PS D:\demo> foundry model run phi-4 --device gpu --prompt "Foundry Localとは?"
Downloading Phi-4-cuda-gpu:1...
[####################################] 100.00 % [Time remaining: about 0s]        64.0 MB/s
🕙 Loading model...
🟢 Model Phi-4-cuda-gpu:1 loaded successfully
🧠 Thinking...
🤖 Foundry Localは、ローカル開発環境を管理するためのツールで、特にWordPressサイトの開発に焦点を当てています。これは、ローカルでWordPressサイトをセットアップ、管理、テストするための統合されたプラットフォームを提供することを目的としています。以下は、....

Python SDKによる実行

python用のSDKでも簡単に動作確認が可能です。
ライブラリのインストール

PS D:\demo> pip install foundry-local-sdk
PS D:\demo> pip install openai
import openai
from foundry_local import FoundryLocalManager

alias = "phi-4"

manager = FoundryLocalManager(alias)

client = openai.OpenAI(
    base_url=manager.endpoint,
    api_key=manager.api_key 
)

stream = client.chat.completions.create(
    model=manager.get_model_info(alias).id,
    messages=[{"role": "user", "content": "Foundry Localとは?"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="", flush=True)

まとめ

Foundry LocalはMicorosft Build 2025で登場したパブリックプレビューで紹介された「Azure AI Foundryのローカル実行版」

  • Oliveを使えばHugging Faceモデルを変換して動作可能
  • クラウド不要で低遅延・高セキュリティな推論環境を構築できる

現時点では、Foundry Local用に提供されているonnxもしくは自身で用意したものを利用できるのみです。カンファレンスでのアナウンス内容がそのまま実現するなら、Azure AI Foundryで管理しているエージェントやモデルをローカルで実行する仕組みとしてリリースされる可能性もあるので今後が気になるサービスだと思います。

参考資料

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?