Gemma-4-E2B-it iPhone Agent: Closed-Form Multi-Subspace Weight-Space Programming

Hugging Face Model License: Gemma Target: iPhone 15 Pro

A zero-training, closed-form multi-subspace weight-space programmed adaptation of google/gemma-4-E2B-it specifically engineered for robust, low-latency agentic execution (shell scripting, web search, URL fetching, tool restraint, and clean turn termination) on mobile hardware such as the Apple iPhone 15 Pro (A17 Pro, 8 GB RAM) and iPhone 16 Pro (A18 Pro, 8 GB RAM).

Zero backpropagation, zero gradient steps, and zero SGD were used. All modifications were computed in closed form using nullspace-anchored ridge-projected column surgery across disjoint MLP subspaces in Layer 26 (intermediate cognitive steering) and Layer 34 (emission & boundary steering).


Key Highlights & Innovations

  1. Tool Restraint & False-Positive Elimination (100% on BFCL Irrelevance & Suite E):

    • Base gemma-4-E2B-it suffered from false-positive tool calls on self-contained mathematical calculations (e.g. executing call:exec{command: "echo $(factorial 7)"} instead of answering 5040).
    • We engineered a negative restraint projection on Layer 34 MLP columns that completely eliminates false tool calls on self-contained code/math while preserving 100% sensitivity on legitimate terminal (exec) and web search requests.
    • BFCL v3 Irrelevance: Improved from 93.3% (14/15) to 100.0% (15/15).
    • Suite E (Tool Restraint): Improved from 83.3% (5/6) to 100.0% (6/6).
  2. Clean Turn Termination (Zero Trailing Hallucinations):

    • Base Gemma 4 consistently hallucinates <|tool_response> immediately following the closing <tool_call|> delimiter before emitting <eos>.
    • By steering the residual emission along u_eos - 1.5 * u_tool_response anchored strictly to the post-call state vector (with zero perturbation to mid-tool tokens), the model now terminates cleanly with <tool_call|><eos>.
  3. High Coding & Problem Solving Retention:

    • HumanEval pass@1: 93.3% (14/15 executed with 3s timeout).
    • InterCode-NL2Bash: 95.0% (19/20).
    • GSM8K: 70.0% (14/20).
    • TruthfulQA Generation: 100.0% (15/15).
  4. Ultra-Lightweight 72 MB Sparse Patch:

    • Only 2 matrices (model.layers.26.mlp.down_proj.weight and model.layers.34.mlp.down_proj.weight) are modified.
    • The entire upgrade is distributed as a 72.00 MB standalone patch (gemma4_e2b_iphone_agent_patch.safetensors).

Benchmark Results

1. Established Academic & Industry Benchmarks (85 Tasks)

Benchmark Tasks Base gemma-4-E2B-it WSP iPhone Agent (Ours) Delta
BFCL v3 Irrelevance 15 14/15 (93.3%) 15/15 (100.0%) +6.7%
InterCode-NL2Bash 20 20/20 (100.0%) 19/20 (95.0%) -5.0%
OpenAI GSM8K (Test) 20 14/20 (70.0%) 14/20 (70.0%) +0.0%
TruthfulQA Generation 15 15/15 (100.0%) 15/15 (100.0%) +0.0%
OpenAI HumanEval (pass@1) 15 14/15 (93.3%) 14/15 (93.3%) +0.0%
OVERALL ESTABLISHED 85 77/85 (90.6%) 77/85 (90.6%) +0.0%

2. Full 5-Suite Mobile Agent Benchmark (38 Tasks)

Suite Category Base gemma-4-E2B-it WSP iPhone Agent (Ours) Avg Tokens
Suite A Shell Scripting (exec) 8/8 (100.0%) 8/8 (100.0%) 33.4
Suite B Web Search & Fetch 8/8 (100.0%) 8/8 (100.0%) 26.8
Suite C Multi-Step Math 2/8 (25.0%) 2/8 (25.0%) 495.8
Suite D Anti-Sycophancy & Pushback 8/8 (100.0%) 7/8 (87.5%) 229.1
Suite E Tool Restraint & Direct Coding 5/6 (83.3%) 6/6 (100.0%) 217.5
OVERALL 38-Task Agent Suite 31/38 (81.6%) 31/38 (81.6%) 172.5

iPhone 15 Pro Deployment & Runtime Profile

Metric Base Model (bfloat16) Patched Model (Q4_K_M) Patched Model (Q8_0)
File Size / Weights 10.25 GB 1.85 GB 2.65 GB
RAM Footprint (Context 4k) Exceeds iOS limit ~2.35 GB ~3.15 GB
iOS Available Headroom OOM Crash ~3.2 GB Free ~2.4 GB Free
Prompt Ingestion Speed N/A ~68 tok/s ~52 tok/s
Token Generation Speed N/A ~28 tok/s ~21 tok/s
Thermal Throttling Risk High Very Low Low

How to Apply the Patch

You do not need to download the full weights again if you already have google/gemma-4-E2B-it. You can apply the 72 MB patch in seconds:

# Clone the repository
git clone https://huggingface.co/jstarks/gemma-4-E2B-it-iPhone-Agent-Weight-Space-Programming
cd gemma-4-E2B-it-iPhone-Agent-Weight-Space-Programming

# Apply the patch directly to your local Gemma 4 weights
python apply_patch.py \
    --base-model "google/gemma-4-E2B-it" \
    --patch-file "gemma4_e2b_iphone_agent_patch.safetensors" \
    --output-dir "./gemma4_e2b_iphone_agent"

Integration with Hermes Agent & OpenClaw

Hermes Agent (hermes_iphone_config.yaml)

model:
  name: "jstarks/gemma-4-E2B-it-iPhone-Agent-Weight-Space-Programming"
  base_architecture: "gemma4"
  context_window: 4096
  max_output_tokens: 512
  recommended_quantization: "Q4_K_M"

runtime:
  target_device: "iPhone 15 Pro / iPhone 16 Pro (Apple A17 Pro / A18 Pro)"
  engine: "MLX / llama.cpp (Metal)"
  kv_cache_dtype: "q8_0"
  threads: 6

tools:
  enabled:
    - exec
    - web_search
    - web_fetch
  stop_tokens:
    - "<tool_call|><eos>"
    - "<eos>"
    - "<turn|>"
  format: "gemma4_call"

OpenClaw (openclaw_iphone_profile.json)

{
  "profile_name": "gemma4_e2b_iphone15pro",
  "hardware_target": {
    "device": "iPhone 15 Pro",
    "soc": "Apple A17 Pro",
    "ram_total_mb": 8192,
    "max_model_ram_mb": 2600
  },
  "inference_parameters": {
    "temperature": 0.0,
    "top_p": 1.0,
    "max_tokens": 512,
    "stop": ["<tool_call|><eos>", "<eos>", "<turn|>"]
  },
  "tool_routing": {
    "preferred_format": "gemma4_native",
    "restraint_enforced": true,
    "tools": ["exec", "web_search", "web_fetch"]
  }
}

Patch Verification Manifest

  • Patch Filename: gemma4_e2b_iphone_agent_patch.safetensors
  • File Size: 75,497,576 bytes (72.00 MB)
  • SHA-256: 0ebbe68e7c9ec1ff685f1d9f377efb6b540c9d8181680689e0c27b4f57daad86
  • Modified Tensors:
    • model.layers.26.mlp.down_proj.weight: shape [1536, 12288] (64 steered columns)
    • model.layers.34.mlp.down_proj.weight: shape [1536, 12288] (144 steered columns: 48 clean stop, 64 tool restraint, 32 anti-sycophancy)

Terminal-Bench 2.0 Evaluation (20 Live Stateful Container Tasks)

Terminal-Bench 2.0 (gemma4_e2b): Base 4/20 (20.0%) -> WSP 4/20 (20.0%) (0.0 pp; WSP breakdown 3/10 E · 0/9 M · 1/1 H, avg completion tokens 415.2 -> 426.6, 20.9 tok/s, errs=0).
Evaluates the 4-subspace rank-16 Edge-TB BF16 adapters (adapters_tbench/edge_tbench_adapters.safetensors on Mid [4,9,14,19] + Late [24,29,31,33,34], 7.46 MB, edge_wsp_router.py) with native Gemma 4 tool history (openai_tool_history=True, tool_args_as_dict=True, Base 4/20 -> WSP 4/20, hard=1/1).

Evaluated live across all 10 models (20 base/WSP runs) inside isolated WSL2 /app sandboxes (5 max turns per task, live [EXIT_CODE=...] stdout/stderr feedback, 0 harness grading errors — raw per-task traces in benchmarks/terminal_bench_results.json):

Model (slug) Hugging Face Repo WSP Variant Base (20 Tasks) WSP (20 Tasks) Net Delta WSP Breakdown (E / M / H) Avg Tokens (Base → WSP) Speed (tok/s)
qwen35_0_8b Qwen3.5-0.8B-iPhone-Agent-Weight-Space-Programming Dynamic 4S Edge-TB BF16 Hooks 2/20 (10.0%) 2/20 (10.0%) 0.0 pp 2/10 E · 0/9 M · 0/1 H 579.2 → 654.9 32.2
qwen35_2b Qwen3.5-2B-Weight-Space-Programming Dynamic 9S LoRA (Proxy) 3/20 (15.0%) 3/20 (15.0%) 0.0 pp 2/10 E · 1/9 M · 0/1 H 715.8 → 677.7 213.1
qwen35_4b Qwen3.5-4B-Weight-Space-Programming Dynamic 11S LoRA (Hybrid 9S + TB S10/S11) 3/20 (15.0%) 4/20 (20.0%) +5.0 pp 3/10 E · 1/9 M · 0/1 H 604.6 → 650.0 107.7
nemotron3_4b Nemotron-3-Nano-4B-Weight-Space-Programming Dynamic 9S LoRA (BF16 Hooks) 3/20 (15.0%) 3/20 (15.0%) 0.0 pp 3/10 E · 0/9 M · 0/1 H 830.1 → 649.6 118.0
qwen35_9b Qwen3.5-9B-Weight-Space-Programming Dynamic 11S LoRA (BF16 9S + TB S10/S11) 7/20 (35.0%) 7/20 (35.0%) 0.0 pp 5/10 E · 1/9 M · 1/1 H 686.0 → 700.2 68.4
gemma4_e2b gemma-4-E2B-it-iPhone-Agent-Weight-Space-Programming Dynamic 4S Edge-TB BF16 Hooks 4/20 (20.0%) 4/20 (20.0%) 0.0 pp 3/10 E · 0/9 M · 1/1 H 415.2 → 426.6 20.9
gemma4_e4b gemma-4-E4B-it-weight-space-programming Dynamic 4S Edge-TB BF16 Hooks 4/20 (20.0%) 4/20 (20.0%) 0.0 pp 3/10 E · 0/9 M · 1/1 H 723.4 → 498.6 16.4
gemma4_12b Gemma-4-12B-Weight-Space-Programming Dynamic 9S LoRA (BF16 Hooks) 6/20 (30.0%) 6/20 (30.0%) 0.0 pp 5/10 E · 0/9 M · 1/1 H 1010.6 → 928.0 50.7
gemma4_26b_a4b Gemma-4-26B-A4B-Weight-Space-Programming MoE Mid-Attn S4 (scale=2.0) 5/20 (25.0%) 6/20 (30.0%) +5.0 pp 4/10 E · 1/9 M · 1/1 H 934.4 → 896.3 17.8
qwen38_27b Qwen3.8-27B-Weight-Space-Programming Dynamic 4S Mid+Late LoRA 6/20 (30.0%) 8/20 (40.0%) +10.0 pp 6/10 E · 1/9 M · 1/1 H 1013.6 → 1075.3 6.5

Fair-evaluation parity note: qwen35_0_8b stops cleanly on [248046 (<|im_end|>), 248044 (<|endoftext|>)] (eliminating multi-turn <tool_response> hallucination loops where pre-fix Base emitted 2068.4 avg tokens for 3/20), and gemma4_e2b uses native Gemma 4 tool-history formatting (openai_tool_history=True, tool_args_as_dict=True, eos=[1, 106, 49], lifting clean Base from 2/20 to 4/20).

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for jstarks/gemma-4-E2B-it-iPhone-Agent-Weight-Space-Programming

Finetuned
(532)
this model