Instructions to use TOTORONG/extGemma4-40_5B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use TOTORONG/extGemma4-40_5B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="TOTORONG/extGemma4-40_5B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("TOTORONG/extGemma4-40_5B") model = AutoModelForMultimodalLM.from_pretrained("TOTORONG/extGemma4-40_5B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - llama-cpp-python
How to use TOTORONG/extGemma4-40_5B with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="TOTORONG/extGemma4-40_5B", filename="gguf/extGemma4-40_5B._Q4.gguf", )
llm.create_chat_completion( messages = [ { "role": "user", "content": "What is the capital of France?" } ] ) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use TOTORONG/extGemma4-40_5B with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf TOTORONG/extGemma4-40_5B # Run inference directly in the terminal: llama cli -hf TOTORONG/extGemma4-40_5B
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf TOTORONG/extGemma4-40_5B # Run inference directly in the terminal: llama cli -hf TOTORONG/extGemma4-40_5B
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf TOTORONG/extGemma4-40_5B # Run inference directly in the terminal: ./llama-cli -hf TOTORONG/extGemma4-40_5B
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf TOTORONG/extGemma4-40_5B # Run inference directly in the terminal: ./build/bin/llama-cli -hf TOTORONG/extGemma4-40_5B
Use Docker
docker model run hf.co/TOTORONG/extGemma4-40_5B
- LM Studio
- Jan
- vLLM
How to use TOTORONG/extGemma4-40_5B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "TOTORONG/extGemma4-40_5B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "TOTORONG/extGemma4-40_5B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/TOTORONG/extGemma4-40_5B
- SGLang
How to use TOTORONG/extGemma4-40_5B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "TOTORONG/extGemma4-40_5B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "TOTORONG/extGemma4-40_5B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "TOTORONG/extGemma4-40_5B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "TOTORONG/extGemma4-40_5B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use TOTORONG/extGemma4-40_5B with Ollama:
ollama run hf.co/TOTORONG/extGemma4-40_5B
- Unsloth Studio
How to use TOTORONG/extGemma4-40_5B with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for TOTORONG/extGemma4-40_5B to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for TOTORONG/extGemma4-40_5B to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for TOTORONG/extGemma4-40_5B to start chatting
- Pi
How to use TOTORONG/extGemma4-40_5B with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf TOTORONG/extGemma4-40_5B
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "TOTORONG/extGemma4-40_5B" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use TOTORONG/extGemma4-40_5B with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf TOTORONG/extGemma4-40_5B
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default TOTORONG/extGemma4-40_5B
Run Hermes
hermes
- Atomic Chat new
- OpenClaw new
How to use TOTORONG/extGemma4-40_5B with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf TOTORONG/extGemma4-40_5B
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "TOTORONG/extGemma4-40_5B" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
- Docker Model Runner
How to use TOTORONG/extGemma4-40_5B with Docker Model Runner:
docker model run hf.co/TOTORONG/extGemma4-40_5B
- Lemonade
How to use TOTORONG/extGemma4-40_5B with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull TOTORONG/extGemma4-40_5B
Run and chat with the model
lemonade run user.extGemma4-40_5B-{{QUANT_TAG}}List all available models
lemonade list
extGemma4-40.5B
extGemma4-40.5B is a depth-expanded language model built by inserting new transformer layers into a fine-tuned Gemma 4 31B-IT and then healing the model back to health with lightweight training. It grows the network from 60 to 77 layers (~40.5B parameters) without collapse or catastrophic forgetting — the central thing this model is meant to demonstrate.
Why this model exists. Conventional wisdom says that altering the architecture of an already fine-tuned model tends to break it. This model is a counter-example: with careful layer initialization and staged healing on a small dataset, the inserted capacity integrates cleanly and even begins to contribute to reasoning.
What makes it different
Most layer-insertion methods initialize new layers as identity (pass-through) functions. That's safe but starves the new layers of any learning signal — they contribute nothing, so they receive almost no gradient and never learn. An earlier 88-layer attempt by the authors failed exactly this way.
extGemma4-40.5B instead initializes each new layer as an interpolation of its neighbors, so the layer is doing something meaningful from step one and can actually be trained. Combined with careful insertion placement and a two-phase healing schedule (freeze-then-anneal), the surgery heals rather than degrades.
Results
GPQA-Diamond (graduate-level science reasoning, 198 items, CoT)
| Model | GPQA-Diamond (flexible-extract) |
|---|---|
| Original fine-tune (60 layers) | 0.798 |
| Identity-init expansion, healed | 0.596 |
| extGemma4-40.5B (interpolation-init, Phase 1) | 0.641 ± 0.034 |
| extGemma4-40.5B (interpolation-init, Phase 2 / final) | 0.728 ± 0.034 |
The expanded model recovers ~65% of the deficit introduced by the surgery and reaches ~91% of the original model's score, using only selective freezing, QLoRA, and a small (~45k example) STEM + Korean-legal dataset.
Evaluation used a 4,000-token generation budget with greedy decoding. The baseline for comparison was fine-tuned on the same dataset, so the expanded model gets no unfair advantage from data familiarity.
Self-healing of a structural defect
At initialization and after Phase 1, the expanded model had a structural generation flaw: on certain low-probability, jargon-heavy paths it would derail into repeated non-Latin characters and never terminate. This is not a training artifact — it appeared identically before any healing, i.e. it was baked into the freshly-expanded structure.
During Phase 2 annealing the model healed this defect on its own:
| Stage | Behavior on the trigger prompt |
|---|---|
| Before healing | Injects non-Latin tokens, loops, never terminates |
| ~13% into Phase 2 | One malformed token, then self-corrects and finishes |
| ~50% and beyond | Fully fluent, terminates correctly |
Across a 10-domain English probe (physics, biology, history, philosophy, literature, riddle, logic, math proof, economics, medicine), the healed model shows 0/10 collapse and 0/10 cross-script contamination, and terminates cleanly on all 10.
Emergent reasoning: it can out-reason its own parent
On a physics question — comparing the energy of a photon and an electron with equal de Broglie wavelength — the original model answered incorrectly (it omitted the electron's rest-mass energy). extGemma4-40.5B answered correctly, applying the relativistic energy–momentum relation. The newly inserted capacity isn't decorative; on this problem it does reasoning the base model could not.
Intended use
- Research on depth expansion, layer insertion, and model "healing."
- English and Korean text generation and reasoning.
- Korean-legal-flavored assistance (the healing data included Korean legal chain-of-thought).
This is a research artifact demonstrating a method. It is close to, but does not beat, its original parent on general benchmarks — and that was never the goal. The goal was to show the surgery can be survived.
Limitations & notes
- Not a strict upgrade over the base model. It recovers ~91% of the original GPQA score; on most tasks expect parity-or-slightly-below, with occasional pockets (like the physics case above) where the added depth helps.
- Minor rough edges remain in generation (e.g. an occasional clumsy self-correction on under-specified logic puzzles). No collapse, but not flawless polish.
- Inherits the base model's licensing, biases, and knowledge cutoff.
- The chat format and EOS handling follow the base Gemma 4 IT conventions; use the same chat template.
How to use
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_id = "your-org/extGemma4-40.5B"
tok = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
msgs = [{"role": "user", "content": "Explain in two sentences why the sky is blue."}]
ids = tok.apply_chat_template(msgs, add_generation_prompt=True, return_tensors="pt").to(model.device)
out = model.generate(ids, max_new_tokens=512, do_sample=False)
print(tok.decode(out[0][ids.shape[1]:], skip_special_tokens=False))
Method summary (for the curious)
- Interpolation initialization. Each inserted layer starts as a position-aligned blend of its neighboring layers — off-identity but coherent — so gradients flow from the first step.
- Careful placement. Layers are inserted at stable positions within attention blocks, avoiding block boundaries and the block-terminal global-attention layers.
- Two-phase healing. Phase 1 trains only the inserted layers (originals frozen); Phase 2 anneals the whole network. Both use QLoRA on a small STEM + Korean-legal dataset.
A fuller write-up (including why identity initialization silently fails on this architecture, and why certain "obvious" fixes are no-ops) is available separately.
Citation
@misc{extgemma4_2026,
title = {extGemma4-40.5B: Depth Expansion of a Fine-Tuned Gemma 4 via
Interpolation-Based Layer Insertion},
author = {Park, Sungjin and Park, Jungjoon},
year = {2026},
note = {Nextnine},
howpublished = {\url{https://huggingface.co/your-org/extGemma4-40.5B}}
}
Acknowledgements
Built on Google DeepMind's Gemma 4. Thanks to the r/LocalLLaMA community for feedback on the earlier (failed) expansion attempt that motivated this work.
- Downloads last month
- 1,201