-
Notifications
You must be signed in to change notification settings - Fork 288
Add olive mcp server #2353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
xiaoyu-work
wants to merge
9
commits into
main
Choose a base branch
from
xiaoyu/mcp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add olive mcp server #2353
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b222ef1
Add olive mcp server
xiaoyu-work d6a10bd
fix constants
xiaoyu-work 2939e10
Fix comments
xiaoyu-work f72f41b
Fix format
xiaoyu-work 2b340ed
address comments
xiaoyu-work 0b2f133
fix nit
xiaoyu-work 55f585f
Merge branch 'main' into xiaoyu/mcp
xiaoyu-work b4e764b
reuse olive package
xiaoyu-work 6a7e3d4
fix format
xiaoyu-work File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| .venv/ | ||
| __pycache__/ | ||
| *.pyc | ||
| *.egg-info/ | ||
| dist/ | ||
| build/ | ||
| .olive-mcp/ | ||
| .olive-cache/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "mcpServers": { | ||
| "olive": { | ||
| "command": "uv", | ||
| "args": ["run", "--directory", "/path/to/Olive/mcp", "python", "-m", "olive_mcp"] | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| # Olive MCP Server | ||
|
|
||
| MCP server for Microsoft Olive model optimization. Provides tools for model optimization, quantization, fine-tuning, and benchmarking through the [Model Context Protocol](https://modelcontextprotocol.io/). | ||
|
|
||
| ## Features | ||
|
|
||
| | Tool | Description | | ||
| |------|-------------| | ||
| | `optimize` | End-to-end optimization with automatic pass scheduling | | ||
| | `quantize` | Model quantization (RTN, GPTQ, AWQ, HQQ, and more) | | ||
| | `finetune` | LoRA / QLoRA fine-tuning (including diffusion LoRA for SD 1.5, SDXL, Flux) | | ||
| | `capture_onnx_graph` | Capture ONNX graph via PyTorch Exporter or Model Builder | | ||
| | `benchmark` | Model evaluation using lm-eval tasks | | ||
| | `detect_hardware` | Auto-detect CPU, RAM, GPU, and disk space for smart defaults | | ||
| | `manage_outputs` | List or delete previous optimization outputs | | ||
| | `get_job_status` | Check progress of a running job with structured phase detection | | ||
| | `cancel_job` | Cancel a running background job | | ||
|
|
||
| Each tool runs in an **isolated Python environment** (managed by uv) with the appropriate dependencies, so different onnxruntime variants (CPU, CUDA, DirectML, OpenVINO, etc.) never conflict. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Python 3.10+ | ||
| - [uv](https://docs.astral.sh/uv/) (recommended) or pip | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| git clone https://github.com/microsoft/Olive.git | ||
| cd Olive/mcp | ||
| uv sync | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| All MCP clients use the same server config — only the config file location differs. | ||
|
|
||
| **Server definition:** | ||
|
|
||
| ```json | ||
| { | ||
| "command": "uv", | ||
| "args": ["run", "--directory", "/path/to/Olive/mcp", "python", "-m", "olive_mcp"] | ||
| } | ||
| ``` | ||
|
|
||
| > Replace `/path/to/Olive/mcp` with your actual project path. | ||
|
|
||
| | Client | Config file | Key | | ||
| |--------|------------|-----| | ||
| | **VS Code (Copilot)** | `.vscode/mcp.json` | `servers.olive` | | ||
| | **Claude Desktop** | `%APPDATA%\Claude\claude_desktop_config.json` (Win) / `~/Library/Application Support/Claude/claude_desktop_config.json` (Mac) | `mcpServers.olive` | | ||
| | **Claude Code** | `.mcp.json` in project root | `mcpServers.olive` | | ||
| | **Cursor** | `.cursor/mcp.json` | `mcpServers.olive` | | ||
| | **Windsurf** | `~/.codeium/windsurf/mcp_config.json` | `mcpServers.olive` | | ||
|
|
||
| <details> | ||
| <summary>VS Code example (.vscode/mcp.json)</summary> | ||
|
|
||
| ```json | ||
| { | ||
| "servers": { | ||
| "olive": { | ||
| "type": "stdio", | ||
| "command": "uv", | ||
| "args": ["run", "--directory", "/path/to/Olive/mcp", "python", "-m", "olive_mcp"] | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
| </details> | ||
|
|
||
| <details> | ||
| <summary>Claude Desktop / Claude Code / Cursor / Windsurf example</summary> | ||
|
|
||
| ```json | ||
| { | ||
| "mcpServers": { | ||
| "olive": { | ||
| "command": "uv", | ||
| "args": ["run", "--directory", "/path/to/Olive/mcp", "python", "-m", "olive_mcp"] | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
| </details> | ||
|
|
||
| ## Usage with VS Code Copilot | ||
|
|
||
| 1. Open **Copilot Chat** panel (`Ctrl+Alt+I`) and switch to **Agent** mode | ||
| 2. Click the **Tools** icon to verify the Olive MCP tools are listed | ||
| 3. Ask Copilot, for example: *"Optimize microsoft/Phi-3-mini-4k-instruct for CPU with int4"* | ||
| 4. Copilot will ask for your confirmation before calling each MCP tool | ||
|
|
||
| ## Example Prompts | ||
|
|
||
| ``` | ||
| Optimize microsoft/Phi-3-mini-4k-instruct | ||
|
|
||
| Quantize microsoft/Phi-3-mini-4k-instruct | ||
|
|
||
| Fine-tune microsoft/Phi-3-mini-4k-instruct on nampdn-ai/tiny-codes | ||
|
|
||
| Capture ONNX graph from microsoft/Phi-3-mini-4k-instruct | ||
|
|
||
| Benchmark microsoft/Phi-3-mini-4k-instruct | ||
|
|
||
| Train a LoRA for runwayml/stable-diffusion-v1-5 with dataset linoyts/Tuxemon | ||
|
|
||
| What's the best way to optimize Phi-4-mini for my hardware? | ||
|
|
||
| What passes are available for int4 quantization? | ||
|
|
||
| Help me write a custom Olive config with OnnxQuantization and GraphSurgeries | ||
| ``` | ||
|
|
||
| ## Output | ||
|
|
||
| All optimization outputs are saved to `~/.olive-mcp/outputs/` with timestamped directories. | ||
|
|
||
| Completed jobs include: | ||
| - **Pass summary** — which passes ran and how long each took | ||
| - **File sizes** — output model size (and input model size when available) for before/after comparison | ||
| - **Structured progress** — `get_job_status` returns a `phase` field (e.g. "downloading", "quantizing", "saving") in addition to raw logs | ||
| - **Smart error suggestions** — if a job fails, actionable suggestions are attached (e.g. "Out of GPU memory, try int4" or "CPU does not support fp16") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| [build-system] | ||
| requires = ["hatchling"] | ||
| build-backend = "hatchling.build" | ||
|
|
||
| [project] | ||
| name = "olive-mcp" | ||
| version = "0.1.0" | ||
| description = "MCP server for Microsoft Olive model optimization" | ||
| requires-python = ">=3.10" | ||
| dependencies = [ | ||
| "mcp[cli]", | ||
| "psutil" | ||
| ] | ||
|
|
||
| [project.scripts] | ||
| olive-mcp = "olive_mcp:main" | ||
|
|
||
| [tool.hatch.build.targets.wheel] | ||
| packages = ["src/olive_mcp"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
| # -------------------------------------------------------------------------- | ||
| import olive_mcp.tools # noqa: F401 — registers @mcp.tool() and @mcp.prompt() on import | ||
| from olive_mcp.server import mcp | ||
|
|
||
|
|
||
| def main(): | ||
| mcp.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
| # -------------------------------------------------------------------------- | ||
| from olive_mcp import main | ||
|
|
||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
| # -------------------------------------------------------------------------- | ||
| from enum import StrEnum | ||
| from pathlib import Path | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Paths | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| VENV_BASE = Path.home() / ".olive-mcp" / "venvs" | ||
| OUTPUT_BASE = Path.home() / ".olive-mcp" / "outputs" | ||
| WORKER_PATH = Path(__file__).parent / "worker.py" | ||
|
|
||
| # Auto-purge venvs not used within this many days. | ||
| _VENV_MAX_AGE_DAYS = 14 | ||
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Command names | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| class Command(StrEnum): | ||
| OPTIMIZE = "optimize" | ||
| QUANTIZE = "quantize" | ||
| FINETUNE = "finetune" | ||
| CAPTURE_ONNX_GRAPH = "capture_onnx_graph" | ||
| BENCHMARK = "benchmark" | ||
| DIFFUSION_LORA = "diffusion_lora" | ||
| EXPLORE_PASSES = "explore_passes" | ||
| VALIDATE_CONFIG = "validate_config" | ||
| RUN_CONFIG = "run_config" | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Constants | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| class SupportedProvider(StrEnum): | ||
| CPU = "CPUExecutionProvider" | ||
| CUDA = "CUDAExecutionProvider" | ||
| DML = "DmlExecutionProvider" | ||
| OPENVINO = "OpenVINOExecutionProvider" | ||
| TENSORRT = "TensorrtExecutionProvider" | ||
| ROCM = "ROCMExecutionProvider" | ||
| QNN = "QNNExecutionProvider" | ||
| VITISAI = "VitisAIExecutionProvider" | ||
| WEBGPU = "WebGpuExecutionProvider" | ||
| NV_TENSORRT_RTX = "NvTensorRTRTXExecutionProvider" | ||
|
|
||
|
|
||
| class SupportedPrecision(StrEnum): | ||
| FP32 = "fp32" | ||
| FP16 = "fp16" | ||
| BF16 = "bf16" | ||
| INT4 = "int4" | ||
| INT8 = "int8" | ||
| INT16 = "int16" | ||
| INT32 = "int32" | ||
| UINT4 = "uint4" | ||
| UINT8 = "uint8" | ||
| UINT16 = "uint16" | ||
| UINT32 = "uint32" | ||
|
|
||
|
|
||
| SUPPORTED_QUANT_ALGORITHMS = ["rtn", "gptq", "awq", "hqq"] | ||
|
|
||
| # Maps provider → olive-ai extras key for onnxruntime variant | ||
| PROVIDER_TO_EXTRAS = { | ||
| "CPUExecutionProvider": "cpu", | ||
| "CUDAExecutionProvider": "gpu", | ||
| "TensorrtExecutionProvider": "gpu", | ||
| "ROCMExecutionProvider": "gpu", | ||
| "OpenVINOExecutionProvider": "openvino", | ||
| "DmlExecutionProvider": "directml", | ||
| "QNNExecutionProvider": "qnn", | ||
| } | ||
|
|
||
| # Maps provider → onnxruntime-genai variant (for ModelBuilder pass) | ||
| PROVIDER_TO_GENAI = { | ||
| "CPUExecutionProvider": "onnxruntime-genai", | ||
| "CUDAExecutionProvider": "onnxruntime-genai-cuda", | ||
| "DmlExecutionProvider": "onnxruntime-genai-directml", | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.