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
feat: restore Phase 38 architectural state (64.1% Rigor Score) with original weights
Browse files
__pycache__/__init__.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/__init__.cpython-310.pyc and b/__pycache__/__init__.cpython-310.pyc differ
|
|
|
__pycache__/configuration_gemma_px.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/configuration_gemma_px.cpython-310.pyc and b/__pycache__/configuration_gemma_px.cpython-310.pyc differ
|
|
|
__pycache__/modeling_gemma_px.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/modeling_gemma_px.cpython-310.pyc and b/__pycache__/modeling_gemma_px.cpython-310.pyc differ
|
|
|
__pycache__/patch.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/patch.cpython-310.pyc and b/__pycache__/patch.cpython-310.pyc differ
|
|
|
__pycache__/px_modules.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/px_modules.cpython-310.pyc and b/__pycache__/px_modules.cpython-310.pyc differ
|
|
|
config.json
CHANGED
|
@@ -41,7 +41,7 @@
|
|
| 41 |
"num_hidden_layers": 18,
|
| 42 |
"num_key_value_heads": 1,
|
| 43 |
"pad_token_id": 0,
|
| 44 |
-
"px_gamma": 0.
|
| 45 |
"px_routing_mode": "adaptive",
|
| 46 |
"query_pre_attn_scalar": 256,
|
| 47 |
"rms_norm_eps": 1e-06,
|
|
|
|
| 41 |
"num_hidden_layers": 18,
|
| 42 |
"num_key_value_heads": 1,
|
| 43 |
"pad_token_id": 0,
|
| 44 |
+
"px_gamma": 0.12,
|
| 45 |
"px_routing_mode": "adaptive",
|
| 46 |
"query_pre_attn_scalar": 256,
|
| 47 |
"rms_norm_eps": 1e-06,
|
patch.py
CHANGED
|
@@ -382,16 +382,7 @@ def _px_forward(
|
|
| 382 |
B, T_curr = hidden_states.shape[0], hidden_states.shape[1]
|
| 383 |
HD = getattr(self.config, "head_dim", 256)
|
| 384 |
|
| 385 |
-
|
| 386 |
-
# Tracks the "Geometric Disparity" of the latent thoughts.
|
| 387 |
-
# Clustering = Truth (Anna Karenina Principle), Dispersion = Error.
|
| 388 |
-
divergence_buffer = []
|
| 389 |
-
correction_strength = 0.0
|
| 390 |
-
|
| 391 |
-
# Phase 39: Stability & Diversity Injection
|
| 392 |
-
# 1. Restrict recursion to decoding (T=1) to prevent cache corruption during prefill.
|
| 393 |
-
# 2. Add Stochastic Jitter to break representational loops (repetitions).
|
| 394 |
-
if n_loops > 1 and T_curr == 1:
|
| 395 |
h_exp = e_reflector.clone() # Use Reflected Anchor
|
| 396 |
current_layer = dynamic_start
|
| 397 |
max_steps = (dynamic_end - dynamic_start) * n_loops * 3
|
|
@@ -408,30 +399,12 @@ def _px_forward(
|
|
| 408 |
# --- PHASE 26: INFINITE REFLECTION (IR) ---
|
| 409 |
# Center of the thinking process (0.5)
|
| 410 |
t_norm = exploration_steps / max_steps
|
| 411 |
-
|
| 412 |
-
# Phase 38.2: AKS - Topological Anomaly Detection
|
| 413 |
-
# We measure the 'velocity' of the latent state across the last 3 steps.
|
| 414 |
-
# If the states move AWAY from the Anchor (Disparity), we trigger Correction.
|
| 415 |
-
if exploration_steps > 2:
|
| 416 |
-
# Proximity to Anchor (e_static)
|
| 417 |
-
dist_now = 1.0 - StabilityMonitor.calculate_phi(h_exp, e_static).mean().item()
|
| 418 |
-
divergence_buffer.append(dist_now)
|
| 419 |
-
if len(divergence_buffer) > 4: divergence_buffer.pop(0)
|
| 420 |
-
|
| 421 |
-
# Check for "Accelerating Dispersion" (The Anna Karenina Signal)
|
| 422 |
-
if len(divergence_buffer) >= 3:
|
| 423 |
-
velocity = divergence_buffer[-1] - divergence_buffer[-2]
|
| 424 |
-
acceleration = (divergence_buffer[-1] - divergence_buffer[-2]) - (divergence_buffer[-2] - divergence_buffer[-3])
|
| 425 |
-
|
| 426 |
-
# If we are accelerating AWAY from the truth (dist increasing)
|
| 427 |
-
if acceleration > 0.001 and velocity > 0:
|
| 428 |
-
correction_strength = min(1.0, correction_strength + 0.1)
|
| 429 |
-
if os.environ.get("DEBUG_PHI") == "1":
|
| 430 |
-
print(f" [AKS] Anomaly! Accel={acceleration:.4f}, Correction={correction_strength:.2f}")
|
| 431 |
-
else:
|
| 432 |
-
correction_strength = max(0.0, correction_strength - 0.05)
|
| 433 |
|
| 434 |
# --- PHASE 28: TEMPORAL COGNITIVE ROUTING (TCR) ---
|
|
|
|
|
|
|
|
|
|
|
|
|
| 435 |
active_start = dynamic_start
|
| 436 |
active_end = dynamic_end
|
| 437 |
if getattr(self, "_task_kurtosis", 300) > 280 and getattr(self, "_task_kurtosis", 300) < 305:
|
|
@@ -448,15 +421,14 @@ def _px_forward(
|
|
| 448 |
# Sigmoid transition: sharp drop in energy after 50% of thinking
|
| 449 |
k_steep = 12.0
|
| 450 |
energy_factor = 1.0 - (1.0 / (1.0 + torch.exp(torch.tensor(-k_steep * (t_norm - 0.5))))).item()
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
# High correction strength forces the model to ground HARDER (lower exploration).
|
| 454 |
-
current_gamma = base_gamma * (0.5 + energy_factor) * (1.0 - 0.5 * correction_strength)
|
| 455 |
|
| 456 |
-
# Phase 26: Hub Oscillation.
|
| 457 |
oscillation = 1 if (exploration_steps % 4 < 2) else -1
|
| 458 |
bimodal_hub = min(active_end - 1, max(active_start, int(dynamic_hub + (t_norm * 2) + oscillation)))
|
| 459 |
-
|
|
|
|
| 460 |
h_prev = h_exp.clone()
|
| 461 |
|
| 462 |
# Safe layer visit tracking
|
|
@@ -468,12 +440,11 @@ def _px_forward(
|
|
| 468 |
if is_first_visit:
|
| 469 |
updated_layers.add(current_layer)
|
| 470 |
|
| 471 |
-
# Phase
|
| 472 |
-
#
|
| 473 |
-
refresh_rate = 0.10 + 0.20 * correction_strength
|
| 474 |
if exploration_steps % 6 == 0 and exploration_steps > 0:
|
| 475 |
-
h_exp =
|
| 476 |
-
path_taken.append(
|
| 477 |
|
| 478 |
# Phase 10.0: Memory-Augmented Cache wrapper
|
| 479 |
current_past = RecursiveMemoryCache(
|
|
@@ -530,13 +501,8 @@ def _px_forward(
|
|
| 530 |
# --------------------------------------------------
|
| 531 |
|
| 532 |
# Apply LTI Injection with Dynamic Anchor
|
| 533 |
-
# Phase 39.1: Repetition Escape Jitter (Cognitive Diversity)
|
| 534 |
-
# Add 5% stochastic noise to gamma to perturb periodic orbits.
|
| 535 |
-
jitter_strength = (torch.rand(1, device=h_exp.device).item() - 0.5) * 0.1
|
| 536 |
-
effective_gamma = current_gamma * (1.0 + jitter_strength)
|
| 537 |
-
|
| 538 |
e_norm = self._px_injection.input_norm(e_dynamic.to(torch.float32)).to(trans_out.dtype)
|
| 539 |
-
h_exp = trans_out +
|
| 540 |
|
| 541 |
# --- PHASE 26: REFLECTION FLIPPING (RF) ---
|
| 542 |
h_f32 = h_exp.to(torch.float32)
|
|
|
|
| 382 |
B, T_curr = hidden_states.shape[0], hidden_states.shape[1]
|
| 383 |
HD = getattr(self.config, "head_dim", 256)
|
| 384 |
|
| 385 |
+
if n_loops > 1:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
h_exp = e_reflector.clone() # Use Reflected Anchor
|
| 387 |
current_layer = dynamic_start
|
| 388 |
max_steps = (dynamic_end - dynamic_start) * n_loops * 3
|
|
|
|
| 399 |
# --- PHASE 26: INFINITE REFLECTION (IR) ---
|
| 400 |
# Center of the thinking process (0.5)
|
| 401 |
t_norm = exploration_steps / max_steps
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
|
| 403 |
# --- PHASE 28: TEMPORAL COGNITIVE ROUTING (TCR) ---
|
| 404 |
+
# If we are in the Trap/Logic-A zone (kurtosis ~293), shift the cognitive window over time
|
| 405 |
+
# Phase 1 (0-33%): Deep Logic (L8-L14) to understand the trap
|
| 406 |
+
# Phase 2 (33-66%): Math (L5-L11) to calculate
|
| 407 |
+
# Phase 3 (66-100%): Logic (L8-L12) to synthesize
|
| 408 |
active_start = dynamic_start
|
| 409 |
active_end = dynamic_end
|
| 410 |
if getattr(self, "_task_kurtosis", 300) > 280 and getattr(self, "_task_kurtosis", 300) < 305:
|
|
|
|
| 421 |
# Sigmoid transition: sharp drop in energy after 50% of thinking
|
| 422 |
k_steep = 12.0
|
| 423 |
energy_factor = 1.0 - (1.0 / (1.0 + torch.exp(torch.tensor(-k_steep * (t_norm - 0.5))))).item()
|
| 424 |
+
# Gamma(t) transitions from ~1.5x base to ~0.5x base
|
| 425 |
+
current_gamma = base_gamma * (0.5 + energy_factor)
|
|
|
|
|
|
|
| 426 |
|
| 427 |
+
# Phase 26: Hub Oscillation. The hub moves back and forth to 'shake' the logic.
|
| 428 |
oscillation = 1 if (exploration_steps % 4 < 2) else -1
|
| 429 |
bimodal_hub = min(active_end - 1, max(active_start, int(dynamic_hub + (t_norm * 2) + oscillation)))
|
| 430 |
+
# --------------------------------------
|
| 431 |
+
|
| 432 |
h_prev = h_exp.clone()
|
| 433 |
|
| 434 |
# Safe layer visit tracking
|
|
|
|
| 440 |
if is_first_visit:
|
| 441 |
updated_layers.add(current_layer)
|
| 442 |
|
| 443 |
+
# Phase 15.9: Sensory Persistence (SP)
|
| 444 |
+
# Re-inject pure sensory data every few steps to prevent grounding decay.
|
|
|
|
| 445 |
if exploration_steps % 6 == 0 and exploration_steps > 0:
|
| 446 |
+
h_exp = 0.90 * h_exp + 0.10 * e_static
|
| 447 |
+
path_taken.append("SENSORY_REFRESH")
|
| 448 |
|
| 449 |
# Phase 10.0: Memory-Augmented Cache wrapper
|
| 450 |
current_past = RecursiveMemoryCache(
|
|
|
|
| 501 |
# --------------------------------------------------
|
| 502 |
|
| 503 |
# Apply LTI Injection with Dynamic Anchor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 504 |
e_norm = self._px_injection.input_norm(e_dynamic.to(torch.float32)).to(trans_out.dtype)
|
| 505 |
+
h_exp = trans_out + current_gamma * (e_norm - h_prev)
|
| 506 |
|
| 507 |
# --- PHASE 26: REFLECTION FLIPPING (RF) ---
|
| 508 |
h_f32 = h_exp.to(torch.float32)
|