dgem is a declarative Policy-as-Template engine, CLI assistant, and empirical benchmark harness for Google DeepMind's DiffusionGemma (26B-A4B-it), supporting Local Apple Silicon (macOS Metal), Serverless Cloud Run GPU (NVIDIA L4), and Google Compute Engine (L4 / A100) deployments.
Historically, production engineering teams had to choose between two extremes for automated triage, routing, and guardrails:
- Discriminative Classifiers & Automata (BERT / DeBERTa / C++ WFSTs): Sub-10ms latency, but rigid. Adding a new policy rule or routing category requires curating labeled datasets, retraining weights, and redeploying model binaries.
-
Autoregressive Generative LLMs (Gemini / GPT-4 / Gemma 4): Zero-shot flexible, but architecturally mismatched for discrete decisions—paying
$O(T_{\text{output}})$ serial token generation latency (2–17s), vulnerable to markdown/JSON syntax drift, and lacking calibrated distribution entropy over the decision space.
DiffusionGemma introduces a third architectural category: the Zero-Shot Decision Model.
Instead of generating text left-to-right, dgem compiles declarative .json.tmpl templates into a pre-allocated discrete diffusion canvas (32–256 tokens) with full bidirectional attention. Boolean gates, [A-Z] categorical choices, and ordinal rubrics are resolved simultaneously in a single forward pass (~450–700 ms), returning both 100% schema-guaranteed decisions and calibrated epistemic Shannon entropy (ChaosNLI).
| Architectural Dimension | Discrete Diffusion Decision Model (dgem) |
Discriminative Encoder (DeBERTa-v3 / Llama-Guard) | Autoregressive LLM (Gemini / Gemma 4) | Compiled Rulebook (ecotone C++ WFST) |
|---|---|---|---|---|
| Policy Adaptability |
Zero-Shot Policy-as-Template (edit .json.tmpl in seconds) |
Requires labeled dataset & weight retraining per label change | Zero-shot prompt engineering | Manual grammar authoring & compilation |
| Inference Latency | 425 – 712 ms (1-pass Metal / 458.9 ms Cloud Run L4) | ~5 – 25 ms (single head) | 17,486.6 ms (~17.5s for 3-slot JSON + CoT) |
1.35 – 8.68 ms (1.54 ms p50 over UDS) |
| Latency Scaling Law |
|
|
|
|
| Joint Slot Conditioning |
Bidirectional (slot_1 <-> slot_2) in a single forward pass |
Independent static classification heads | Unidirectional causal bias (left -> right) |
Local sliding window (1–3 tokens) |
| Epistemic Calibration ( |
Monotonic with human disagreement (8.0× ChaosNLI) |
Overconfident logits out-of-distribution | Uncalibrated sequence-level logprobs | Static tropical semiring arc weights |
| Guardrail & Policy Accuracy |
100% AgentDrift hijack, 100% Prompt Injection, 100% RAG Grounding |
Narrow single-task scope (512–8k context) | High accuracy at 15–25× higher latency | 36.7% on semiotic polysemy traps |
dgem is client-agnostic and connects to any OpenAI-compatible or native Jev endpoint:
┌───────────────────────────────┐
│ dgem CLI │
└───────────────┬───────────────┘
│
┌────────────────────────┼────────────────────────┐
▼ ▼ ▼
Local Apple Silicon (Metal) Cloud Run Serverless GPU Cloud GPU on GCE VM
• diffgemma serve (:8080) • 1× NVIDIA L4 (24GB) • 1× L4 (NVFP4) / 2× A100 (bf16)
• 4-bit Q4 Unified Memory • Self-contained container • vLLM PR #57250 nightly wheel
• 32k KV Context • GCS FUSE weight mount • 32k context + Triton Attn
• Zero cloud cost • 459ms avg wall latency • Direct raw completions
Runs fully offline on M-series Macs using the native Rust Metal engine (diffgemma):
# 1. Install diffgemma engine
make setup
# 2. Download the 4-bit model pack (mmastrac/diffgemma-26b-a4b-it-q4)
make download
# 3. Launch background Metal server on port 8080
make serve
# 4. Stop when finished
make stopProvisions automated, production-grade GCE instances with the nightly vLLM wheel (wheels.vllm.ai, matching PR #57250 base commit 133b71e0be) and Triton attention:
# 4-bit NVFP4 on 1× NVIDIA L4 (g2-standard-8, ~$0.70/hr):
export GCP_PROJECT="your-gcp-project"
PRECISION=4 make gce-deploy
# 8-bit FP8-dynamic on 1× NVIDIA A100-40GB (a2-highgpu-1g, ~$3.67/hr):
PRECISION=8 make gce-deploy
# 16-bit unquantized bfloat16 on 2× NVIDIA A100-40GB (a2-highgpu-2g, TP=2, ~$7.34/hr):
export GCP_ZONE="us-central1-b"
PRECISION=16 make gce-deploy
# Mandatory immediate teardown to eliminate idle costs:
make gce-teardownBuilds and deploys a self-contained container image to Google Artifact Registry and runs on Cloud Run with GCS FUSE weight streaming:
export GCP_PROJECT="your-gcp-project"
export GCP_REGION="us-central1"
# 1. Build self-contained image in Artifact Registry via Cloud Build:
make cloudrun-build
# 2. Pre-stage 17.57 GB NVFP4 weights to GCS:
make cloudrun-stage
# 3. Deploy dgemma service on Cloud Run (1× NVIDIA L4, 24GB):
make cloudrun-deploy
# 4. Run discrete decisions or 30-case benchmark:
SERVICE_URL=$(gcloud run services describe dgemma --region=$GCP_REGION --format="value(status.url)")
./bin/dgem decide -u "${SERVICE_URL}/v1" --gcp-auth -t templates/support_triage.json.tmpl -v 'ticket=Emergency outage'
./bin/dgem bench -u "${SERVICE_URL}/v1" --gcp-auth -d benchmarks/eval_dataset.jsonl -M slot -o benchmarks/results_cloudrun.json
# 5. Mandatory immediate teardown to eliminate idle costs:
make cloudrun-teardown# Clone the repository
git clone https://github.com/ghchinoy/dgem.git
cd dgem
# Compile dgem binary into bin/
make buildEvaluate customer tickets, code changes, or security alerts in a single ~750 ms forward pass:
./bin/dgem decide -t templates/support_triage.json.tmpl \
-v 'ticket=I was billed $500 twice for my annual renewal this morning!' \
--statsOutput:
QUESTION | TYPE | VALUE / CHOICE | CONFIDENCE | ENTROPY (H) | AGREEMENT
-----------------------------------------------------------------------------------------
sentiment | score | frustrated | 99.8% | 0.002 nats | 1.00
team | choice | billing | 100.0% | 0.000 nats | 1.00
urgent | boolean | yes | 99.9% | 0.001 nats | 1.00
──────────────────────────────── STATS ────────────────────────────────
Model: nvidia/diffusiongemma-26B-A4B-it-NVFP4
Endpoint: http://34.121.236.110:8080/v1/chat/completions
Total Wall Time: 856 ms
KV Cache Reused: 169 tokens (82.8% hit rate)
Denoise Steps: 1 step (policy: samples=1)
───────────────────────────────────────────────────────────────────────
Standard chat completion with optional thinking mode:
./bin/dgem ask "Explain discrete block diffusion in two sentences."Connect to any remote GCE or Cloud Run GPU service:
./bin/dgem decide \
-u "http://<EXTERNAL_IP>:8080/v1" \
-m "nvidia/diffusiongemma-26B-A4B-it-NVFP4" \
-t templates/support_triage.json.tmpl \
-v 'ticket=Outage: production database cluster unreachable' \
--statsAttach local image paths (automatically base64 encoded) or remote URLs:
./bin/dgem decide -t templates/multimodal/ui_design_review.json.tmpl \
-I fixtures/ui_component.svg \
-v 'component=CheckoutCard' \
--statsdgem includes four first-class empirical benchmark harnesses (tracked in docs/experiments/README.md):
Evaluates 50 items across 11 public datasets (benchmarks/calibration_suite.jsonl), testing declarative policy templates (templates/calibration/*.json.tmpl) across agent trajectory hijacking (AgentDrift), multilingual jailbreaks (deepset/prompt-injections), RAG fact grounding (LLM-AggreFact), retrieval relevance (MS MARCO), toxicity (Jigsaw Civil Comments), and human annotator disagreement (ChaosNLI):
./bin/dgem bench-calibration -u "${SERVICE_URL}/v1" -m "/mnt/gcs/dgemma" --gcp-auth -w 4 \
-o benchmarks/results_calibration_cloudrun.json| Public Dataset / Policy Domain | Cases | Accuracy | Mean |
Mean Entropy |
Avg Latency |
|---|---|---|---|---|---|
AgentDrift (agent_step_drift.json.tmpl — Hijack + 4-Way Step Localization) |
7 | 100.0% (7/7) ⭐ | 0.997 |
0.0186 nats |
693 ms |
deepset/prompt-injections (prompt_injection.json.tmpl — en/de Gate) |
4 | 100.0% (4/4) ⭐ | 0.980 |
0.0817 nats |
669 ms |
LLM-AggreFact & MS MARCO (RAG Grounding & Retrieval Relevance) |
4 | 100.0% (4/4) ⭐ | 0.993 |
0.0403 nats |
728 ms |
CLINC150, Banking77, GoEmotions, BoolQ, Yelp/SST-5 |
20 | 100.0% (20/20) ⭐ | 0.898 |
0.3263 nats |
769 ms |
ChaosNLI Crowd Consensus (low-entropy) |
3 | 100.0% (3/3) | 0.986 |
0.0744 nats (1.0×) |
625 ms |
ChaosNLI Crowd Split (high-entropy) |
3 | 33.3% (1/3) | 0.759 |
0.5932 nats (8.0× spike) ⭐ |
731 ms |
Stage 1 Alone: DiffusionGemma (steps=1, think=0) |
50 | 88.0% (44/50) | 0.925 |
0.2279 nats |
712 ms |
Raw Entropy Cascade (EXP-05a): dgemma [H<0.35] gemini-3.8-flash |
50 | 94.0% (47/50, +6.0%) |
0.959 |
0.1410 nats |
1,824 ms (72% early-exit) |
Normalized + Prior-Guided Cascade (EXP-05b, |
50 |
98.0% (49/50, +10.0%) ⭐ |
0.960 |
0.1416 nats ( |
2,105 ms (66% early-exit) |
Stage 2 Alone: gemini-3.8-flash (100% Frontier LLM) |
50 | 98.0% (49/50) | 0.959 |
0.1347 nats |
3,412 ms (4.8× slower) |
Evaluates 30 multi-field test cases (boolean + choice + score in a single pass) across support, code_review, and security (benchmarks/eval_dataset.jsonl):
./bin/dgem bench -d benchmarks/eval_dataset.jsonl -M slot -o benchmarks/results_cloudrun.jsonEvaluates 49 Text Normalization cases comparing C++ ecotone (OpenFst / Sparrowhawk WFSTs over unix:///tmp/ecotone.sock) against DiffusionGemma across semiotic polysemy traps and deterministic NSWs:
./bin/dgem bench-ecotone -c benchmarks/ecotone/tn_semiotics.jsonl --samples 1 -o benchmarks/results_ecotone.jsonEvaluates 30-way to 151-way intent routing and Out-of-Scope (oos) rejection on PolyAI/banking77 and DeepPavlov/clinc150:
./bin/dgem bench-intents --dataset banking77 --full --workers 16
./bin/dgem bench-intents --dataset clinc150 --full --workers 16- The Journey to Decision Models: Architectural primer contrasting Classical ML, Symbolic WFSTs, Autoregressive LLMs, and Discrete Diffusion Decision Models.
- Experiments & Research Ledger (
docs/experiments/): Structured log of completed empirical studies (EXP-01throughEXP-04) and active architectural investigations (EXP-05Entropy-Gated Cascades,EXP-06Encoder Comparisons,EXP-07Conditional Policy DAGs). - Benchmark Evaluation Report: Full empirical receipts comparing Apple M5 Metal, Cloud Run 1× L4, GCE 1× L4, GCE 2× A100
bfloat16,ChaosNLI, Banking77, and CLINC150. - Template Catalog (
Policy-as-Code): Complete reference of declarative.json.tmpldecision schemas across triage, guardrails, NLU, and multimodal vision. - Ecotone (WFST) vs. DiffusionGemma: Semiotic polysemy taxonomy, head-to-head findings, and the hybrid Cascaded Normalizer architecture.
- Architecture: Discrete Diffusion vs. Autoregression: Mechanical breakdown of 256-token canvas denoising, bidirectional slot readout, and terminology history.
- Cloud Run Lessons Learned & Native CUDA Build Guide: Self-contained Artifact Registry build, GCS FUSE prefetching, and envelope unmarshaling architecture.
- Remote Endpoints & Cloud Deployment: Pointing
dgemto Google Cloud Run, GCE GPU instances, Vertex AI, and hosted vLLM clusters. - Real-World Applications & Production Patterns: Production architectures for agentic dispatch, DevSecOps git hooks, and SIEM alert triage.
- User Guide & Setup & Metal Engine Guide: Full CLI reference and local Apple Silicon serving.
Issues, bug reports, and feature discussions are welcome! However, we are not accepting pull requests (PRs) at this time. If you encounter a bug or have feedback on benchmark methodologies or templates, please open an Issue.
This project is licensed under the Apache-2.0 License.
Caution
This is not an officially supported Google product. This project is not eligible for the Google Open Source Software Vulnerability Rewards Program.