Skip to content

feat(local): add LOCAL_ENGINE=turbo-fieldfare support, HTTP adapter, and client/gateway tests - #106

Merged
ghchinoy merged 1 commit into
GoogleCloudPlatform:mainfrom
ghchinoy:feat/local-engine-turbo-fieldfare
Dec 1, 2026
Merged

ghchinoy merged 1 commit into
GoogleCloudPlatform:mainfrom
ghchinoy:feat/local-engine-turbo-fieldfare

Conversation

@ghchinoy

Copy link
Copy Markdown
Collaborator

Summary

Adds opt-in LOCAL_ENGINE=turbo-fieldfare support alongside the default LOCAL_ENGINE=diffgemma for running DiffusionGemma 26B-A4B via SSD-streaming Metal 4 on Apple Silicon Macs (8/16/32 GB, built on drumih/turbo-fieldfare, Apache-2.0):

  1. Structured-Readout Local HTTP Adapter (scripts/turbo_fieldfare_server.py):
    • Runs TurboFieldfareDiffusionProbe as a persistent child process behind a ThreadingHTTPServer (so GET /health, GET /ready, and GET /v1/models remain non-blocking while inference runs).
    • Reuses deploy/cloudrun/server/structured_server.py directly for prompt building (document_first / schema_first), CANVAS_LEN=64 layout, isolate (auto/noul/all), depends_on/ask_if DAGs, and lossless diagnostics.questions[qid].logprobs.
    • Exposes GET /health, GET /ready (503 while loading, 200 once warm), GET /v1/models, POST /v1/chat/completions, and POST /v1/systemone.
    • Enforces X-DGem-Key on POST when DGEM_SERVER_KEY is set, refuses multimodal inputs and think > 0 with 4xx, auto-detects bundled <model>/tokenizer, and auto-selects bimodal expert-cache slots (16 on <= 16 GB Macs, 128 on >= 24 GB Macs; warns on 32/64).
  2. Makefile & scripts/ LOCAL_ENGINE Wiring:
    • Adds LOCAL_ENGINE ?= diffgemma across setup, download, serve, stop, local-up, local-down, local-status, and clean, backed by scripts/{setup,download,serve,stop}_turbo_fieldfare.sh (default diffgemma behavior is unchanged).
  3. Gateway & Client Compatibility (cmd/mcp.go, pkg/client/, cmd/):
    • Updates CheckHealthAndGPUStatusForBackend in cmd/mcp.go to read the served local model ID from /v1/models (falling back to diffgemma-26b-a4b-it-q4).
    • Adds Go -race tests in pkg/client/turbo_fieldfare_test.go and cmd/backend_local_test.go verifying SSD-streaming client/proxy timeouts (>= 60s), lossless diagnostic logprob temperature rescaling, X-DGem-Key, 400 refusal on multimodal requests, concurrent v1ProxyHandler forwarding, and Cloud Run warm-state isolation.
    • Adds scripts/test_turbo_fieldfare_server.py (7 unit tests runnable without Swift binary, weights, or GPU).

Surface & Documentation Checklist

  • CLI, HTTP gateway, MCP server, and Decision Studio stay in parity (all target http://127.0.0.1:8080/v1 via the same local backend contract).
  • docs/ and docs-site/ are synced (follow-up docs & attribution PR will update laptop.md, metal-engine.md, hardware.md, and NOTICE).
  • No real project IDs, endpoint URLs, keys, or build outputs (studio/dist/*) are included.

Verification

  • go vet ./... && go test -race ./... && go -C examples vet ./... && go -C examples test ./...
  • python3 -m unittest scripts/test_turbo_fieldfare_server.py scripts/matrix/test_matrix.py deploy/cloudrun/server/test_*.py (83 tests, 0 failures)
  • bash -n scripts/*_turbo_fieldfare.sh
  • Live end-to-end Apple Silicon smoke check: ./bin/dgem decide -u http://127.0.0.1:18089/v1 -t templates/support_triage.json.tmpl against scripts/turbo_fieldfare_server.py + TurboFieldfareDiffusionProbe (slots=16) returned valid answers, diagnostics.timing, and lossless diagnostics.questions.*.logprobs.

…and client/gateway tests

Adds opt-in LOCAL_ENGINE=turbo-fieldfare support alongside the default
LOCAL_ENGINE=diffgemma for SSD-streaming DiffusionGemma 26B-A4B on Apple
Silicon Macs (based on drumih/turbo-fieldfare, Apache-2.0):
- scripts/turbo_fieldfare_server.py: persistent-subprocess ThreadingHTTPServer
  bridging TurboFieldfareDiffusionProbe to dgem's :8080 contract (/health,
  /ready, /v1/models, /v1/chat/completions, /v1/systemone) by reusing
  structured_server.py's schema, layout, isolation, DAG, and lossless
  slot-logprob math; enforces X-DGem-Key on POST, refuses multimodal/think>0
  with 4xx, auto-selects bundled <model>/tokenizer, and recommends bimodal
  expert cache slots (16 on <=16 GB Macs, 128 on >=24 GB Macs).
- scripts/{setup,download,serve,stop}_turbo_fieldfare.sh + Makefile wiring
  for LOCAL_ENGINE=diffgemma|turbo-fieldfare across setup, download, serve,
  stop, local-up, local-down, local-status, and clean.
- cmd/mcp.go: read actual local model ID from /v1/models in
  CheckHealthAndGPUStatusForBackend instead of hardcoding diffgemma.
- scripts/test_turbo_fieldfare_server.py (7 Python unit tests),
  pkg/client/turbo_fieldfare_test.go, and cmd/backend_local_test.go (-race
  client, lossless logprob temperature scaling, timeout, and gateway proxy
  compatibility tests).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant