GLM-4.7-Flash at 35 tok/s on M4 Max • OpenAI-Compatible API • Production Ready
Quick Start • Serving • Performance • Docs
GLM-4.7-Flash (35 tok/s on M4 Max)
git clone https://github.com/RESMP-DEV/metal-marlin.git
cd metal-marlin
uv sync --extra all
Start an OpenAI-compatible server at 35 tok/s:
# Start server with optimized config
uv run python scripts/serve_glm47.py \
--model-path ./models/glm47-flash-mmfp4 \
--port 8000 \
--max-batch-size 32
# Test with any OpenAI SDK
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"glm-4.7-flash","messages":[{"role":"user","content":"Hello"}],"max_tokens":50}'
Features:
Full Guide: docs/QUICKSTART_SERVING.md
from metal_marlin.inference.mmfp4_pipeline import MMFP4Pipeline
from metal_marlin.trellis.config import GLM4_TOKENIZER_ID
# Load optimized pipeline (35 tok/s)
pipeline = MMFP4Pipeline.from_pretrained(
"./models/glm47-flash-mmfp4",
device="mps"
)
# Generate
output = pipeline(
"Explain quantum computing",
max_new_tokens=100,
temperature=0.7
)
print(output)
Run end-to-end validation:
# Validate TPS (target: 35 tok/s) and perplexity
./tests/validation/run_all_validation.sh
See Validation Checklist for details.
Start server:
uv run python scripts/serve_glm47.py \
--model-path ./models/glm47-flash-mmfp4 \
--host 0.0.0.0 \
--port 8000
Endpoints:
| Endpoint | Description |
|---|---|
GET /v1/models | List available models |
POST /v1/chat/completions | Chat (supports streaming) |
POST /v1/completions | Text completions |
POST /v1/perplexity | Evaluate text perplexity |
GET /v1/perplexity/stats | Perplexity statistics |
GET /metrics | Prometheus metrics |
GET /health | Health check |
OpenAI SDK Compatible:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="unused")
response = client.chat.completions.create(
model="qwen3_4b_fp4",
messages=[{"role": "user", "content": "Hello!"}],
stream=True
)
for chunk in response:
print(chunk.choices[0].delta.content or "", end="")
Convert models to efficient quantized formats:
# Basic FP4 quantization
metal-marlin quantize Qwen/Qwen3-4B --format fp4 -o qwen3_4b_fp4
# Trellis v2 (recommended for MoE models)
metal-marlin quantize Qwen/Qwen3-30B-A3B --format trellis-v2 -o qwen3_30b_trellis
# Qwen3.5-122B-A10B MMFP4 (CUDA MR-GPTQ)
uv run python scripts/quantize_qwen35_122b_a10b_mmfp4_cuda.py \
--output models/Qwen3.5-122B-A10B-MMFP4
For MoE models, dynamic bit allocation reduces size 40-50% with <1% quality loss. See Quantization Guide for details.
mkdir -p build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j
cp _cpp_ext.cpython-312-darwin.so ../metal_marlin/
Check availability:
from metal_marlin import fast_dispatch_available
print(f"Fast dispatch: {fast_dispatch_available()}") # True if C++ ext built
| Guide | Description |
|---|---|
| Getting Started | Installation and first inference |
| Quantization Guide | FP4/Trellis quantization |
| Trellis Inference | GLM-4.7-Flash inference details |
| MMFP4 Inference | MMFP4-quantized models |
| Architecture | Internal design |
| Fast Dispatch | C++ extension internals |
| Metal Shaders | Precompiled metallib |
| STATUS.md | Implementation status |
uv run pytest tests/ -v # Full test suite
uv run pytest tests/ -v -m smoke # Quick smoke tests
uv run ruff check . # Linting
uv run pyright metal_marlin/ # Type checking
Apache 2.0
Python
68.4%
Metal
19.4%
C++
10.5%
Objective-C++
1.4%
GLM-4.7-Flash at 35 tok/s on M4 Max • OpenAI-Compatible API • Production Ready
Quick Start • Serving • Performance • Docs
GLM-4.7-Flash (35 tok/s on M4 Max)
git clone https://github.com/RESMP-DEV/metal-marlin.git
cd metal-marlin
uv sync --extra all
Start an OpenAI-compatible server at 35 tok/s:
# Start server with optimized config
uv run python scripts/serve_glm47.py \
--model-path ./models/glm47-flash-mmfp4 \
--port 8000 \
--max-batch-size 32
# Test with any OpenAI SDK
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"glm-4.7-flash","messages":[{"role":"user","content":"Hello"}],"max_tokens":50}'
Features:
Full Guide: docs/QUICKSTART_SERVING.md
from metal_marlin.inference.mmfp4_pipeline import MMFP4Pipeline
from metal_marlin.trellis.config import GLM4_TOKENIZER_ID
# Load optimized pipeline (35 tok/s)
pipeline = MMFP4Pipeline.from_pretrained(
"./models/glm47-flash-mmfp4",
device="mps"
)
# Generate
output = pipeline(
"Explain quantum computing",
max_new_tokens=100,
temperature=0.7
)
print(output)
Run end-to-end validation:
# Validate TPS (target: 35 tok/s) and perplexity
./tests/validation/run_all_validation.sh
See Validation Checklist for details.
Start server:
uv run python scripts/serve_glm47.py \
--model-path ./models/glm47-flash-mmfp4 \
--host 0.0.0.0 \
--port 8000
Endpoints:
| Endpoint | Description |
|---|---|
GET /v1/models | List available models |
POST /v1/chat/completions | Chat (supports streaming) |
POST /v1/completions | Text completions |
POST /v1/perplexity | Evaluate text perplexity |
GET /v1/perplexity/stats | Perplexity statistics |
GET /metrics | Prometheus metrics |
GET /health | Health check |
OpenAI SDK Compatible:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="unused")
response = client.chat.completions.create(
model="qwen3_4b_fp4",
messages=[{"role": "user", "content": "Hello!"}],
stream=True
)
for chunk in response:
print(chunk.choices[0].delta.content or "", end="")
Convert models to efficient quantized formats:
# Basic FP4 quantization
metal-marlin quantize Qwen/Qwen3-4B --format fp4 -o qwen3_4b_fp4
# Trellis v2 (recommended for MoE models)
metal-marlin quantize Qwen/Qwen3-30B-A3B --format trellis-v2 -o qwen3_30b_trellis
# Qwen3.5-122B-A10B MMFP4 (CUDA MR-GPTQ)
uv run python scripts/quantize_qwen35_122b_a10b_mmfp4_cuda.py \
--output models/Qwen3.5-122B-A10B-MMFP4
For MoE models, dynamic bit allocation reduces size 40-50% with <1% quality loss. See Quantization Guide for details.
mkdir -p build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j
cp _cpp_ext.cpython-312-darwin.so ../metal_marlin/
Check availability:
from metal_marlin import fast_dispatch_available
print(f"Fast dispatch: {fast_dispatch_available()}") # True if C++ ext built
| Guide | Description |
|---|---|
| Getting Started | Installation and first inference |
| Quantization Guide | FP4/Trellis quantization |
| Trellis Inference | GLM-4.7-Flash inference details |
| MMFP4 Inference | MMFP4-quantized models |
| Architecture | Internal design |
| Fast Dispatch | C++ extension internals |
| Metal Shaders | Precompiled metallib |
| STATUS.md | Implementation status |
uv run pytest tests/ -v # Full test suite
uv run pytest tests/ -v -m smoke # Quick smoke tests
uv run ruff check . # Linting
uv run pyright metal_marlin/ # Type checking
Apache 2.0
Python
68.4%
Metal
19.4%
C++
10.5%
Objective-C++
1.4%