Skip to main content
Glama
README.md
# ArmSight

> **Autonomous AI agent for Arm64 ML model inference optimization.**
> Analyzes ONNX models, applies REAL INT8 quantization, and generates Arm64-optimized deployment packages β€” all through an MCP-compatible tool interface that an AI agent can call autonomously.

Built for the **[Arm Create: AI Optimization Challenge](https://arm-ai-optimization-challenge.devpost.com/)** (Cloud AI track).

---

## 🎯 The Problem

Deploying ML models on Arm64 (AWS Graviton, Cortex-A, Neoverse) requires platform-specific knowledge: which quantization scheme to use, how to tune thread parallelism for multi-core, when to leverage NEON SIMD, and how to package everything into an Arm64-optimized container. Most developers ship unoptimized FP32 models and leave significant performance on the table.

## πŸ’‘ The Solution

**ArmSight** is an autonomous AI agent that:
1. **Analyzes** any ONNX model β€” operators, layers, precision, parameter count, input/output shapes
2. **Recommends** Arm64-specific optimizations β€” INT8 quantization, NEON SIMD fusion, thread parallelism, memory layout, ACL provider
3. **Applies** real INT8 dynamic quantization using `onnxruntime.quantization` β€” producing **measurably smaller** models (typically ~4x size reduction)
4. **Benchmarks** before/after β€” real inference latency, throughput, and speedup measurements
5. **Generates** a complete Arm64-optimized deployment package β€” Dockerfile (`linux/arm64`), FastAPI inference server, benchmark script

## πŸ† Unique Angle

> *Unlike generic model optimizers, ArmSight exposes its capabilities as **MCP (Model Context Protocol) tools** that an AI agent can call autonomously β€” `analyze_model`, `optimize_model`, `benchmark_model`, `recommend_optimizations`, `generate_deployment`, `full_pipeline`. This makes ArmSight not just a tool, but an **agent-native** optimization platform.*

## πŸ—οΈ Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        Web UI (HTML/CSS/JS)                  β”‚
β”‚  Upload ONNX β†’ Analyze β†’ Recommend β†’ Quantize β†’ Benchmark    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚ HTTP
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    FastAPI Backend (Python)                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ Analyzer β”‚  β”‚Quantizer β”‚  β”‚  Recomm. β”‚  β”‚  Deployment β”‚  β”‚
β”‚  β”‚ (onnx)   β”‚  β”‚(onnxrt)  β”‚  β”‚  Engine  β”‚  β”‚  Generator  β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β”‚                  β–Ό                                           β”‚
β”‚         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                 β”‚
β”‚         β”‚   MCP Server     β”‚ ← AI agent calls these tools     β”‚
β”‚         β”‚  (tool registry) β”‚   autonomously via MCP protocol  β”‚
β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Vercel (Serverless)                       β”‚
β”‚         FastAPI on Python runtime β€” free tier               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

## ⚑ Quick Start

### Prerequisites
- Python 3.9+
- An ONNX model file (or use the built-in example model generator)

### Setup (< 5 commands)

```bash
# 1. Clone
git clone https://github.com/0xConsole/arm-sight-agent.git
cd arm-sight-agent

# 2. Install dependencies
pip install -r requirements.txt

# 3. Run locally
uvicorn app.main:app --reload --port 8000

# 4. Open the UI
open http://localhost:8000
```

### Use via API / MCP

```bash
# List MCP tools (what an AI agent sees)
curl http://localhost:8000/mcp/tools | python -m json.tool

# Call the full pipeline autonomously (analyze β†’ quantize β†’ benchmark β†’ deploy)
curl -X POST http://localhost:8000/mcp/call \
  -H "Content-Type: application/json" \
  -d '{"name": "analyze_model", "arguments": {"model_path": "examples/example_model.onnx"}}'
```

## πŸ› οΈ Tech Stack

| Component | Technology |
|---|---|
| Backend | Python + FastAPI |
| Model analysis | `onnx` + `onnxruntime` |
| Quantization | `onnxruntime.quantization.quantize_dynamic` (REAL INT8) |
| Agent interface | MCP (Model Context Protocol) tool pattern |
| Frontend | Vanilla HTML/CSS/JS (no framework) |
| Deployment | Vercel serverless (Python runtime) |
| Target platform | linux/arm64 (AWS Graviton, Cortex-A, Neoverse) |

## βœ… What's Real vs. Mocked

| Feature | Status | Notes |
|---|---|---|
| ONNX model analysis | βœ… **REAL** | Uses `onnx` + `onnxruntime` to parse graph, count operators/parameters |
| INT8 quantization | βœ… **REAL** | `onnxruntime.quantization.quantize_dynamic` β€” produces genuinely smaller ONNX files |
| Size measurement | βœ… **REAL** | Byte-level before/after file size comparison |
| Inference benchmarking | βœ… **REAL** | Actual `session.run()` timing on CPU (mean/p50/p95 latency, throughput) |
| Arm64 recommendations | βœ… **REAL** | Based on actual model architecture (operators, precision, param count) |
| Deployment package | βœ… **REAL** | Generates working Dockerfile targeting `linux/arm64` + FastAPI server + benchmark script |
| MCP tool interface | βœ… **REAL** | Tools are callable via `POST /mcp/call` β€” any MCP client can invoke them |

**Nothing is mocked.** Every measurement comes from real ONNX runtime operations.

## πŸ“Š Measurable Improvements (Example)

For a typical FP32 ONNX model:

| Metric | Before (FP32) | After (INT8) | Improvement |
|---|---|---|---|
| Model size | ~4.2 MB | ~1.1 MB | **4.0x reduction** |
| Inference latency | ~2.5 ms | ~1.8 ms | **~28% faster** |
| Throughput | ~400 ops/s | ~550 ops/s | **~37% higher** |

*Actual numbers vary by model. The quantization and benchmarking are real β€” run it on your model to see your results.*

## 🐳 Generated Deployment Package

The `generate_deployment` tool produces:

```
deploy_package/
β”œβ”€β”€ Dockerfile          # linux/arm64 target, ONNX Runtime with NEON
β”œβ”€β”€ server.py           # FastAPI inference server (optimized session options)
β”œβ”€β”€ model.onnx          # Your (optionally quantized) model
β”œβ”€β”€ benchmark.py        # Latency/throughput benchmark script
β”œβ”€β”€ docker-compose.yml  # One-command deployment
└── README.md           # Usage instructions
```

```bash
# Build and run on Arm64
docker buildx build --platform linux/arm64 -t armsight-inference .
docker run --rm -p 8000:8000 armsight-inference
python benchmark.py http://localhost:8000
```

## πŸ”Œ MCP Tool Reference

ArmSight exposes 6 tools via the MCP interface:

| Tool | Description |
|---|---|
| `analyze_model` | Analyze ONNX architecture: operators, precision, params |
| `optimize_model` | Apply INT8 dynamic quantization (real size reduction) |
| `benchmark_model` | Measure inference latency and throughput |
| `recommend_optimizations` | Generate Arm64-specific recommendations |
| `generate_deployment` | Create Arm64 Docker + FastAPI deployment package |
| `full_pipeline` | Run all of the above autonomously |

## πŸ“ Project Structure

```
arm-sight-agent/
β”œβ”€β”€ api/
β”‚   └── index.py          # Vercel serverless entry point
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ main.py           # FastAPI app + routes
β”‚   β”œβ”€β”€ analyzer.py       # ONNX model analysis
β”‚   β”œβ”€β”€ quantizer.py      # INT8 quantization (REAL)
β”‚   β”œβ”€β”€ recommendations.py # Arm64 optimization recommendations
β”‚   β”œβ”€β”€ deployment.py     # Deployment package generator
β”‚   └── mcp_server.py     # MCP tool registry + dispatch
β”œβ”€β”€ static/
β”‚   └── index.html        # Web UI
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ vercel.json
└── README.md
```

## πŸ“œ License

Apache License 2.0 β€” see [LICENSE](LICENSE).

## πŸ”— Links

- **Live Demo:** [https://arm-sight-agent.vercel.app](https://arm-sight-agent.vercel.app)
- **GitHub:** [github.com/0xConsole/arm-sight-agent](https://github.com/0xConsole/arm-sight-agent)
- **Challenge:** [Arm Create: AI Optimization Challenge](https://arm-ai-optimization-challenge.devpost.com/)