Text Generation
Transformers
Safetensors
PyTorch
English
pebble_50m
pebble
base-model
mamba
mamba2
hybrid
custom-architecture
custom_code
Instructions to use basically-experimental/Pebble-50M-beta with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use basically-experimental/Pebble-50M-beta with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="basically-experimental/Pebble-50M-beta", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("basically-experimental/Pebble-50M-beta", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use basically-experimental/Pebble-50M-beta with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "basically-experimental/Pebble-50M-beta" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "basically-experimental/Pebble-50M-beta", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/basically-experimental/Pebble-50M-beta
- SGLang
How to use basically-experimental/Pebble-50M-beta 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 "basically-experimental/Pebble-50M-beta" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "basically-experimental/Pebble-50M-beta", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "basically-experimental/Pebble-50M-beta" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "basically-experimental/Pebble-50M-beta", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use basically-experimental/Pebble-50M-beta with Docker Model Runner:
docker model run hf.co/basically-experimental/Pebble-50M-beta
Update modeling_pebble.py
Browse files- modeling_pebble.py +2 -13
modeling_pebble.py
CHANGED
|
@@ -97,7 +97,6 @@ class PurePyTorchMamba2(nn.Module):
|
|
| 97 |
self.out_proj = nn.Linear(self.d_inner, d_model, bias=False)
|
| 98 |
self.norm = RMSNorm(self.d_inner, eps=config.rms_norm_eps)
|
| 99 |
|
| 100 |
-
# Conv1d takes x, B, and C combined (d_inner + 2 * d_state)
|
| 101 |
conv_in_channels = self.d_inner + 2 * d_state
|
| 102 |
self.conv1d = nn.Conv1d(
|
| 103 |
in_channels=conv_in_channels,
|
|
@@ -116,14 +115,12 @@ class PurePyTorchMamba2(nn.Module):
|
|
| 116 |
B, T, C = x.shape
|
| 117 |
xzbc = self.in_proj(x)
|
| 118 |
|
| 119 |
-
# Split into x, z, B, C, dt
|
| 120 |
x, z, B_p, C_p, dt = torch.split(
|
| 121 |
xzbc,
|
| 122 |
[self.d_inner, self.d_inner, self.d_state, self.d_state, self.nheads],
|
| 123 |
dim=-1
|
| 124 |
)
|
| 125 |
|
| 126 |
-
# Apply conv1d to x, B, C combined
|
| 127 |
xbc = torch.cat([x, B_p, C_p], dim=-1)
|
| 128 |
xbc = xbc.transpose(1, 2)
|
| 129 |
xbc = self.conv1d(xbc)[:, :, :T]
|
|
@@ -135,29 +132,20 @@ class PurePyTorchMamba2(nn.Module):
|
|
| 135 |
dim=-1
|
| 136 |
)
|
| 137 |
|
| 138 |
-
# Activation
|
| 139 |
x = F.silu(x)
|
| 140 |
-
|
| 141 |
-
# Norm
|
| 142 |
x = self.norm(x)
|
| 143 |
z = self.norm(z)
|
| 144 |
|
| 145 |
-
# Discretization
|
| 146 |
dt = F.softplus(dt + self.dt_bias)
|
| 147 |
A = -torch.exp(self.A_log)
|
| 148 |
|
| 149 |
-
# Reshape for multi-head SSM
|
| 150 |
x = x.view(B, T, self.nheads, self.headdim)
|
| 151 |
-
z = z.view(B, T, self.nheads, self.headdim)
|
| 152 |
|
| 153 |
-
# B and C are (B, T, d_state) -> (B, T, 1, 1, d_state) to broadcast across heads
|
| 154 |
B_p = B_p.view(B, T, 1, 1, self.d_state)
|
| 155 |
C_p = C_p.view(B, T, 1, 1, self.d_state)
|
| 156 |
-
|
| 157 |
-
# A is (nheads,) -> (1, nheads, 1, 1)
|
| 158 |
A = A.view(1, self.nheads, 1, 1)
|
| 159 |
|
| 160 |
-
# SSM Scan (Naive loop)
|
| 161 |
h = torch.zeros(B, self.nheads, self.d_state, self.headdim, device=x.device)
|
| 162 |
ys = []
|
| 163 |
|
|
@@ -179,6 +167,7 @@ class PurePyTorchMamba2(nn.Module):
|
|
| 179 |
D = self.D.view(1, 1, self.nheads, 1)
|
| 180 |
y = y + (x * D).view(B, T, self.d_inner)
|
| 181 |
|
|
|
|
| 182 |
out = y * z
|
| 183 |
out = self.out_proj(out)
|
| 184 |
return out
|
|
|
|
| 97 |
self.out_proj = nn.Linear(self.d_inner, d_model, bias=False)
|
| 98 |
self.norm = RMSNorm(self.d_inner, eps=config.rms_norm_eps)
|
| 99 |
|
|
|
|
| 100 |
conv_in_channels = self.d_inner + 2 * d_state
|
| 101 |
self.conv1d = nn.Conv1d(
|
| 102 |
in_channels=conv_in_channels,
|
|
|
|
| 115 |
B, T, C = x.shape
|
| 116 |
xzbc = self.in_proj(x)
|
| 117 |
|
|
|
|
| 118 |
x, z, B_p, C_p, dt = torch.split(
|
| 119 |
xzbc,
|
| 120 |
[self.d_inner, self.d_inner, self.d_state, self.d_state, self.nheads],
|
| 121 |
dim=-1
|
| 122 |
)
|
| 123 |
|
|
|
|
| 124 |
xbc = torch.cat([x, B_p, C_p], dim=-1)
|
| 125 |
xbc = xbc.transpose(1, 2)
|
| 126 |
xbc = self.conv1d(xbc)[:, :, :T]
|
|
|
|
| 132 |
dim=-1
|
| 133 |
)
|
| 134 |
|
|
|
|
| 135 |
x = F.silu(x)
|
|
|
|
|
|
|
| 136 |
x = self.norm(x)
|
| 137 |
z = self.norm(z)
|
| 138 |
|
|
|
|
| 139 |
dt = F.softplus(dt + self.dt_bias)
|
| 140 |
A = -torch.exp(self.A_log)
|
| 141 |
|
| 142 |
+
# Reshape x for multi-head SSM
|
| 143 |
x = x.view(B, T, self.nheads, self.headdim)
|
|
|
|
| 144 |
|
|
|
|
| 145 |
B_p = B_p.view(B, T, 1, 1, self.d_state)
|
| 146 |
C_p = C_p.view(B, T, 1, 1, self.d_state)
|
|
|
|
|
|
|
| 147 |
A = A.view(1, self.nheads, 1, 1)
|
| 148 |
|
|
|
|
| 149 |
h = torch.zeros(B, self.nheads, self.d_state, self.headdim, device=x.device)
|
| 150 |
ys = []
|
| 151 |
|
|
|
|
| 167 |
D = self.D.view(1, 1, self.nheads, 1)
|
| 168 |
y = y + (x * D).view(B, T, self.d_inner)
|
| 169 |
|
| 170 |
+
# z is already (B, T, d_inner), so it multiplies perfectly!
|
| 171 |
out = y * z
|
| 172 |
out = self.out_proj(out)
|
| 173 |
return out
|