igovet/ gemma4:31b-opencode

24 3 days ago

cloud
ollama run igovet/gemma4:31b-opencode

Details

3 days ago

cfa2d5488e48 · 444B ·

{ "min_p": 0.05, "num_ctx": 262144, "num_predict": 16384, "repeat_last_n": 2048,

Readme

Gemma4 31B — OpenCode (Ollama Cloud)

Modelfile & provider preset tuned for stable work inside OpenCode over Ollama Cloud.


Background

When using Ollama Cloud models from OpenCode, several issues surface out of the box:

  • Stream stalls — the response repeatedly pauses mid-token.
  • Stream freezes → timeout — long stalls trip the upstream timeout.
  • Same issues on plain HTTP — disabling streaming does not make them go away.
  • Reasoning loops — some models (notably DeepSeek) get stuck inside their own reasoning trace and never escape.

The settings below were arrived at empirically and raise the stability of Ollama Cloud + OpenCode to roughly 95%. The remaining edge cases look like Ollama Cloud throughput / model overload bugs, not configuration problems.

⚠️ These settings are experimental. They are not endorsed by Ollama or OpenCode — they are what happened to work best in our environment.


TL;DR

Field Value
Base model gemma4:31b-cloud
Context window 262144
Output limit (in OpenCode) 262144 (equals context)
Temperature 0.7
Top-p / Top-k / Min-p 0.95 / 50 / 0.05
Repeat penalty 1.1 (last 2048 tokens)
Variants high / medium / low / none

Modelfile

FROM gemma4:31b-cloud

PARAMETER num_ctx         262144
PARAMETER num_predict     16384
PARAMETER temperature     0.7
PARAMETER top_p           0.95
PARAMETER top_k           50
PARAMETER min_p           0.05
PARAMETER repeat_penalty  1.1
PARAMETER repeat_last_n   2048

OpenCode configuration

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Ollama",
      "options": {
        "baseURL": "http://localhost:11434/v1",
        "timeout": 1200000,
        "headerTimeout": 1200000
      },
      "models": {
        "igovet/gemma4:31b-opencode": {
          "_launch": false,
          "name": "Gemma4 31b OpenCode",
          "limit": {
            "context": 262144,
            "output":  262144
          },
          "variants": {
            "high":   { "reasoningEffort": "high"   },
            "medium": { "reasoningEffort": "medium" },
            "low":    { "reasoningEffort": "low"    },
            "none":   { "reasoningEffort": "none"   }
          }
        }
      }
    }
  }
}

Notes

Why output is set equal to context

Ollama does not honor a separate output (max output tokens) reliably through the OpenAI-compatible surface that @ai-sdk/openai-compatible speaks to. If you set output near 16384 you will see the stream cut off mid-response with no error.

The workaround used here is to make output formally equal to context. The model still decides when to stop on its own; we just stop clipping it on the client side.

Long timeouts

timeout and headerTimeout are bumped to 20 minutes (1200000 ms). Cloud models occasionally queue for several minutes during peak load, and the default AI SDK timeouts will fire long before that.

Sampling (Gemma-specific)

Gemma models are sensitive to top-k/min-p defaults. The values here (top_k 50, min_p 0.05) match the recommended setup from the Gemma 4 release notes and noticeably reduce degenerate repetition on long generations.


Reasoning effort — when to pick what

OpenCode variant Use it for
high Multi-file refactors, architecture-level reasoning, debugging subtle cross-module issues. Best when the orchestrator is delegating complex work.
medium Default for sub-agents (backend-developer, full-stack-developer) on a well-scoped task.
low Quick reads — code-reviewer, security-auditor on small diffs, explore agent.
none Inline completions, classification, or short replies where reasoning adds latency without value.