Text Generation
Transformers
Safetensors
gemma_3_px
gemma
px-inference
recurrent-depth-transformer
open-mythos
math
reasoning
latent-thoughts
conversational
custom_code
Instructions to use neuralworm/gemma-3-270m-it-p2.8 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use neuralworm/gemma-3-270m-it-p2.8 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="neuralworm/gemma-3-270m-it-p2.8", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("neuralworm/gemma-3-270m-it-p2.8", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use neuralworm/gemma-3-270m-it-p2.8 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "neuralworm/gemma-3-270m-it-p2.8" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "neuralworm/gemma-3-270m-it-p2.8", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/neuralworm/gemma-3-270m-it-p2.8
- SGLang
How to use neuralworm/gemma-3-270m-it-p2.8 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 "neuralworm/gemma-3-270m-it-p2.8" \ --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": "neuralworm/gemma-3-270m-it-p2.8", "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 "neuralworm/gemma-3-270m-it-p2.8" \ --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": "neuralworm/gemma-3-270m-it-p2.8", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use neuralworm/gemma-3-270m-it-p2.8 with Docker Model Runner:
docker model run hf.co/neuralworm/gemma-3-270m-it-p2.8
Upload folder using huggingface_hub
Browse files- README.md +10 -29
- config.json +6 -6
- configuration_gemma_px.py +11 -0
- modeling_gemma_px.py +25 -0
README.md
CHANGED
|
@@ -1,17 +1,6 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: gemma
|
| 3 |
-
base_model: google/gemma-3-270m-it
|
| 4 |
-
tags:
|
| 5 |
-
- gemma-3
|
| 6 |
-
- open-mythos
|
| 7 |
-
- recursive-transformer
|
| 8 |
-
- cognitive-routing
|
| 9 |
-
- experimental
|
| 10 |
-
---
|
| 11 |
-
|
| 12 |
-
# Gemma-3 270M-IT "Open-Mythos" (Phase 2.8)
|
| 13 |
|
| 14 |
-
This is an experimental architectural modification of the **Google Gemma-3 270M-IT** base model. It implements the
|
| 15 |
|
| 16 |
## ⚠️ Transparency Notice
|
| 17 |
**This is not a standard fine-tune.** It is a structural mod that changes how the transformer processes tokens at inference time.
|
|
@@ -21,23 +10,18 @@ This is an experimental architectural modification of the **Google Gemma-3 270M-
|
|
| 21 |
## 🚀 Key Innovations
|
| 22 |
|
| 23 |
### 1. Recursive Computational Headroom (PX)
|
| 24 |
-
Unlike standard transformers that pass through each layer once,
|
| 25 |
|
| 26 |
### 2. Fluid Gaussian Cognitive Routing
|
| 27 |
-
The model dynamically analyzes the "cognitive signature" (Kurtosis) of each prompt during the prefill phase
|
| 28 |
-
- **Math Mode:** Optimized for numerical precision
|
| 29 |
-
- **Logic Mode:** Optimized for multi-step reasoning
|
| 30 |
-
- **Creative Mode:** Optimized for semantic drift and metaphor
|
| 31 |
-
- **Synthesis Mode:** Optimized for extraction and summarization
|
| 32 |
-
|
| 33 |
-
Transitions between these modes are **continuous and fluid** using Gaussian blending, allowing the model to self-determine its reasoning path.
|
| 34 |
-
|
| 35 |
-
### 3. Numerical Stability (RMSNorm Fix)
|
| 36 |
-
Implements a surgical fix for the Gemma-3 RMSNorm scaling (`1.0 + weight`) to prevent signal collapse during deep recursion, ensuring vocabulary integrity across high-entropy generations.
|
| 37 |
|
| 38 |
## 💻 Usage
|
| 39 |
|
| 40 |
-
To use this model, you **must** set `trust_remote_code=True`
|
| 41 |
|
| 42 |
```python
|
| 43 |
import torch
|
|
@@ -61,8 +45,5 @@ outputs = model.generate(**inputs, max_new_tokens=100)
|
|
| 61 |
print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))
|
| 62 |
```
|
| 63 |
|
| 64 |
-
## 📊 Performance
|
| 65 |
-
Open-Mythos (Phase 2.8) significantly improves zero-shot performance on "Logical Traps" and multi-step reasoning compared to the pure 270M baseline, while remaining multimodal-ready and regression-free for standard NLP tasks.
|
| 66 |
-
|
| 67 |
---
|
| 68 |
-
*
|
|
|
|
| 1 |
+
# Gemma-3 270M-IT-PX (Phase 2.8)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
This is an experimental architectural modification of the **Google Gemma-3 270M-IT** base model. It implements the **PX (Recursive Computational Headroom)** architecture and **Fluid Gaussian Cognitive Routing**.
|
| 4 |
|
| 5 |
## ⚠️ Transparency Notice
|
| 6 |
**This is not a standard fine-tune.** It is a structural mod that changes how the transformer processes tokens at inference time.
|
|
|
|
| 10 |
## 🚀 Key Innovations
|
| 11 |
|
| 12 |
### 1. Recursive Computational Headroom (PX)
|
| 13 |
+
Unlike standard transformers that pass through each layer once, Gemma-3-PX allows the model to "re-read" and "think" through specific layers multiple times. This effectively increases the depth of the model for complex tasks without adding new parameters.
|
| 14 |
|
| 15 |
### 2. Fluid Gaussian Cognitive Routing
|
| 16 |
+
The model dynamically analyzes the "cognitive signature" (Kurtosis) of each prompt during the prefill phase and automatically routes the task through a specific "Cognitive Envelope":
|
| 17 |
+
- **Math Mode:** Optimized for numerical precision.
|
| 18 |
+
- **Logic Mode:** Optimized for multi-step reasoning.
|
| 19 |
+
- **Creative Mode:** Optimized for semantic drift and metaphor.
|
| 20 |
+
- **Synthesis Mode:** Optimized for extraction and summarization.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
## 💻 Usage
|
| 23 |
|
| 24 |
+
To use this model, you **must** set `trust_remote_code=True`.
|
| 25 |
|
| 26 |
```python
|
| 27 |
import torch
|
|
|
|
| 45 |
print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))
|
| 46 |
```
|
| 47 |
|
|
|
|
|
|
|
|
|
|
| 48 |
---
|
| 49 |
+
*Developed by neuralworm (2026).*
|
config.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
{
|
| 2 |
"_sliding_window_pattern": 6,
|
| 3 |
"architectures": [
|
| 4 |
-
"
|
| 5 |
],
|
| 6 |
"attention_bias": false,
|
| 7 |
"attention_dropout": 0.0,
|
|
@@ -36,7 +36,7 @@
|
|
| 36 |
"full_attention"
|
| 37 |
],
|
| 38 |
"max_position_embeddings": 32768,
|
| 39 |
-
"model_type": "
|
| 40 |
"num_attention_heads": 4,
|
| 41 |
"num_hidden_layers": 18,
|
| 42 |
"num_key_value_heads": 1,
|
|
@@ -62,8 +62,8 @@
|
|
| 62 |
"use_cache": true,
|
| 63 |
"vocab_size": 262144,
|
| 64 |
"auto_map": {
|
| 65 |
-
"AutoConfig": "
|
| 66 |
-
"AutoModelForCausalLM": "
|
| 67 |
-
"AutoModel": "
|
| 68 |
}
|
| 69 |
-
}
|
|
|
|
| 1 |
{
|
| 2 |
"_sliding_window_pattern": 6,
|
| 3 |
"architectures": [
|
| 4 |
+
"Gemma3PXForCausalLM"
|
| 5 |
],
|
| 6 |
"attention_bias": false,
|
| 7 |
"attention_dropout": 0.0,
|
|
|
|
| 36 |
"full_attention"
|
| 37 |
],
|
| 38 |
"max_position_embeddings": 32768,
|
| 39 |
+
"model_type": "gemma_3_px",
|
| 40 |
"num_attention_heads": 4,
|
| 41 |
"num_hidden_layers": 18,
|
| 42 |
"num_key_value_heads": 1,
|
|
|
|
| 62 |
"use_cache": true,
|
| 63 |
"vocab_size": 262144,
|
| 64 |
"auto_map": {
|
| 65 |
+
"AutoConfig": "configuration_gemma_px.Gemma3PXConfig",
|
| 66 |
+
"AutoModelForCausalLM": "modeling_gemma_px.Gemma3PXForCausalLM",
|
| 67 |
+
"AutoModel": "modeling_gemma_px.Gemma3PXModel"
|
| 68 |
}
|
| 69 |
+
}
|
configuration_gemma_px.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import PretrainedConfig
|
| 2 |
+
from transformers.models.gemma3.configuration_gemma3 import Gemma3TextConfig
|
| 3 |
+
|
| 4 |
+
class Gemma3PXConfig(Gemma3TextConfig):
|
| 5 |
+
model_type = "gemma_3_px"
|
| 6 |
+
|
| 7 |
+
def __init__(self, **kwargs):
|
| 8 |
+
super().__init__(**kwargs)
|
| 9 |
+
# Default config for 270m
|
| 10 |
+
self.px_routing_mode = kwargs.get("px_routing_mode", "adaptive")
|
| 11 |
+
self.px_gamma = kwargs.get("px_gamma", 0.10)
|
modeling_gemma_px.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers.models.gemma3.modeling_gemma3 import Gemma3ForCausalLM, Gemma3Model
|
| 2 |
+
from .configuration_gemma_px import Gemma3PXConfig
|
| 3 |
+
from .patch import apply_px_patch
|
| 4 |
+
|
| 5 |
+
class Gemma3PXForCausalLM(Gemma3ForCausalLM):
|
| 6 |
+
config_class = Gemma3PXConfig
|
| 7 |
+
|
| 8 |
+
def __init__(self, config):
|
| 9 |
+
super().__init__(config)
|
| 10 |
+
# We apply the patch immediately after initialization
|
| 11 |
+
# Extract default parameters from the config if they exist
|
| 12 |
+
routing_mode = getattr(config, "px_routing_mode", "adaptive")
|
| 13 |
+
gamma = getattr(config, "px_gamma", 0.10)
|
| 14 |
+
|
| 15 |
+
# We MUST start the initial prelude at Layer 5 so the Kurtosis probe
|
| 16 |
+
# (which is calibrated for L5) reads the correct tensor.
|
| 17 |
+
# The router will fast-forward the remaining layers if dynamic_start > 5.
|
| 18 |
+
apply_px_patch(self, recur_start=5, recur_end=12, routing_mode=routing_mode, gamma=gamma)
|
| 19 |
+
|
| 20 |
+
# For safety, if they instantiate the base model directly:
|
| 21 |
+
class Gemma3PXModel(Gemma3Model):
|
| 22 |
+
config_class = Gemma3PXConfig
|
| 23 |
+
|
| 24 |
+
def __init__(self, config):
|
| 25 |
+
super().__init__(config)
|