Text Generation
Transformers
Safetensors
bailing_hybrid
webbrain
ling-3.0
bailing-moe
looped-transformer
conversational
custom_code
Instructions to use webbrain-one/WebBrain-LingLoop-8B-A1.3B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use webbrain-one/WebBrain-LingLoop-8B-A1.3B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="webbrain-one/WebBrain-LingLoop-8B-A1.3B", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("webbrain-one/WebBrain-LingLoop-8B-A1.3B", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("webbrain-one/WebBrain-LingLoop-8B-A1.3B", trust_remote_code=True, device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use webbrain-one/WebBrain-LingLoop-8B-A1.3B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "webbrain-one/WebBrain-LingLoop-8B-A1.3B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "webbrain-one/WebBrain-LingLoop-8B-A1.3B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/webbrain-one/WebBrain-LingLoop-8B-A1.3B
- SGLang
How to use webbrain-one/WebBrain-LingLoop-8B-A1.3B 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 "webbrain-one/WebBrain-LingLoop-8B-A1.3B" \ --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": "webbrain-one/WebBrain-LingLoop-8B-A1.3B", "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 "webbrain-one/WebBrain-LingLoop-8B-A1.3B" \ --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": "webbrain-one/WebBrain-LingLoop-8B-A1.3B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use webbrain-one/WebBrain-LingLoop-8B-A1.3B with Docker Model Runner:
docker model run hf.co/webbrain-one/WebBrain-LingLoop-8B-A1.3B
Download looped_bailing.py from webbrain-one/WebBrain-LingLoop-8B-A1.3B: direct link, hf CLI and curl.
- Browser
- Download file 3.94 kB
-
https://huggingface.co/webbrain-one/WebBrain-LingLoop-8B-A1.3B/resolve/main/looped_bailing.py
- Command line
-
hf download hf://webbrain-one/WebBrain-LingLoop-8B-A1.3B/looped_bailing.py
-
curl -L -o looped_bailing.py https://huggingface.co/webbrain-one/WebBrain-LingLoop-8B-A1.3B/resolve/main/looped_bailing.py
3.94 kB
| """Inkling-2-Mini style zero-init gated looped Ring-mini-2.0 (LoopedBailingMoeV2ForCausalLM).""" | |
| from __future__ import annotations | |
| import math | |
| from typing import Dict, List, Optional, Tuple, Union | |
| import torch | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| from torch.utils.checkpoint import checkpoint | |
| from transformers.cache_utils import DynamicCache, DynamicLayer | |
| from transformers.modeling_attn_mask_utils import ( | |
| _prepare_4d_causal_attention_mask, | |
| _prepare_4d_causal_attention_mask_for_sdpa, | |
| ) | |
| def rms_norm_fp32(x: torch.Tensor, eps: float = 1e-6) -> torch.Tensor: | |
| """Parameter-free RMS normalization in FP32.""" | |
| x_f = x.float() | |
| return x_f * torch.rsqrt(x_f.pow(2).mean(dim=-1, keepdim=True) + eps) | |
| class DepthAttentionReader(nn.Module): | |
| """Learned FP32 depth-attention query reading cross-pass message from previous pass states.""" | |
| def __init__(self, hidden_size: int): | |
| super().__init__() | |
| self.hidden_size = hidden_size | |
| self.q = nn.Parameter(torch.zeros(hidden_size, dtype=torch.float32)) | |
| def forward(self, prev_states: torch.Tensor, out_dtype: torch.dtype) -> torch.Tensor: | |
| # prev_states: (B, L, S, D) | |
| keys = rms_norm_fp32(prev_states) | |
| scores = (keys * self.q).sum(dim=-1) / math.sqrt(self.hidden_size) # (B, L, S) | |
| weights = F.softmax(scores, dim=-1) | |
| msg = (weights.unsqueeze(-1) * prev_states.float()).sum(dim=-2) | |
| return msg.to(out_dtype) | |
| def inspect_weights(self, prev_states: torch.Tensor) -> torch.Tensor: | |
| keys = rms_norm_fp32(prev_states) | |
| scores = (keys * self.q).sum(dim=-1) / math.sqrt(self.hidden_size) | |
| return F.softmax(scores, dim=-1) | |
| class CrossPassGate(nn.Module): | |
| """Rank-64 zero-init gated residual merge: x + (-tanh(W_f h)*x + tanh(W_g h)*msg).""" | |
| def __init__(self, hidden_size: int, rank: int = 64): | |
| super().__init__() | |
| self.w_down = nn.Linear(2 * hidden_size, rank, bias=False, dtype=torch.float32) | |
| self.w_forget = nn.Linear(rank, hidden_size, bias=False, dtype=torch.float32) | |
| self.w_gain = nn.Linear(rank, hidden_size, bias=False, dtype=torch.float32) | |
| self.reset_parameters() | |
| def reset_parameters(self) -> None: | |
| nn.init.normal_(self.w_down.weight, mean=0.0, std=0.02) | |
| nn.init.zeros_(self.w_forget.weight) | |
| nn.init.zeros_(self.w_gain.weight) | |
| def forward(self, x: torch.Tensor, msg: torch.Tensor) -> torch.Tensor: | |
| x_norm = rms_norm_fp32(x) | |
| m_norm = rms_norm_fp32(msg) | |
| h = self.w_down(torch.cat([x_norm, m_norm], dim=-1)) | |
| forget = torch.tanh(self.w_forget(h)) | |
| gain = torch.tanh(self.w_gain(h)) | |
| delta = (-forget * x.float() + gain * msg.float()).to(x.dtype) | |
| return x + delta | |
| def gate_stats(self, x: torch.Tensor, msg: torch.Tensor) -> Tuple[float, float]: | |
| h = self.w_down(torch.cat([rms_norm_fp32(x), rms_norm_fp32(msg)], dim=-1)) | |
| f_abs = torch.tanh(self.w_forget(h)).abs().mean().item() | |
| g_abs = torch.tanh(self.w_gain(h)).abs().mean().item() | |
| return f_abs, g_abs | |
| class CrossPassLoopAdapter(nn.Module): | |
| """Shared cross-pass readers and rank-64 gates across core layers (2 sites/layer).""" | |
| def __init__(self, num_core_layers: int, hidden_size: int, rank: int = 64): | |
| super().__init__() | |
| self.num_core_layers = num_core_layers | |
| self.hidden_size = hidden_size | |
| self.rank = rank | |
| self.attn_readers = nn.ModuleList([DepthAttentionReader(hidden_size) for _ in range(num_core_layers)]) | |
| self.attn_gates = nn.ModuleList([CrossPassGate(hidden_size, rank) for _ in range(num_core_layers)]) | |
| self.mlp_readers = nn.ModuleList([DepthAttentionReader(hidden_size) for _ in range(num_core_layers)]) | |
| self.mlp_gates = nn.ModuleList([CrossPassGate(hidden_size, rank) for _ in range(num_core_layers)]) | |