Text Generation
Transformers
Safetensors
PyTorch
English
pebble_50m
pebble
base-model
mamba
mamba2
hybrid
custom-architecture
custom_code
Run this model with HF Jobs
Run basically-experimental/Pebble-50M-beta on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/basically-experimental/Pebble-50M-beta. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/basically-experimental/Pebble-50M-beta on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/basically-experimental/Pebble-50M-beta. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/basically-experimental/Pebble-50M-beta. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
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
Create modeling_pebble.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152import mathimport torchimport torch.nn as nnimport torch.nn.functional as Ffrom transformers import PreTrainedModel, GenerationMixinfrom transformers.modeling_outputs import CausalLMOutputWithPastCrossAttentionsfrom .configuration_pebble import PebbleConfig
# Try to import the fast CUDA Mamba2. If it fails, we fallback to HF's pure PyTorch version.try: from mamba_ssm import Mamba2 HAS_MAMBA_SSM = Trueexcept ImportError: HAS_MAMBA_SSM = False
class RMSNorm(nn.Module): def __init__(self, dim, eps=1e-6): super().__init__() self.eps = eps self.weight = nn.Parameter(torch.ones(dim))
def forward(self, x): dt = x.dtype xf = x.float() xf = xf * torch.rsqrt(xf.pow(2).mean(-1, keepdim=True) + self.eps) return self.weight * xf.to(dt)
class AttentionBlock(nn.Module): def __init__(self, dim, n_heads, hidden, rope_theta=10000.0): super().__init__() assert dim % n_heads == 0 self.nh, self.hd = n_heads, dim // n_heads self.rope_theta = rope_theta self.wqkv = nn.Linear(dim, 3 * dim, bias=False) self.wo = nn.Linear(dim, dim, bias=False) self.fc1 = nn.Linear(dim, hidden, bias=False) self.fc2 = nn.Linear(hidden, dim, bias=False) self.ln1 = RMSNorm(dim) self.ln2 = RMSNorm(dim)
def forward(self, x): B, T, C = x.shape h = self.ln1(x) qkv = self.wqkv(h).view(B, T, 3, self.nh, self.hd).permute(2, 0, 3, 1, 4) q, k, v = qkv[0], qkv[1], qkv[2]
half = self.hd // 2 invf = 1.0 / (self.rope_theta ** ( torch.arange(0, half, device=x.device, dtype=torch.float32) * 2.0 / self.hd)) ang = torch.outer(torch.arange(T, device=x.device, dtype=torch.float32), invf) cos, sin = ang.cos()[None, None], ang.sin()[None, None]
q1, q2 = q.float()[..., :half], q.float()[..., half:] k1, k2 = k.float()[..., :half], k.float()[..., half:] q = torch.cat([q1 * cos - q2 * sin, q1 * sin + q2 * cos], dim=-1).to(v.dtype) k = torch.cat([k1 * cos - k2 * sin, k1 * sin + k2 * cos], dim=-1).to(v.dtype)
y = F.scaled_dot_product_attention(q, k, v, is_causal=True) y = y.transpose(1, 2).reshape(B, T, C) x = x + self.wo(y) x = x + self.fc2(F.gelu(self.fc1(self.ln2(x)))) return x
class MambaBlock(nn.Module): def __init__(self, config, layer_idx): super().__init__() if HAS_MAMBA_SSM and torch.cuda.is_available(): # Fast CUDA path for NVIDIA GPUs self.ln = RMSNorm(config.d_model) self.mixer = Mamba2( d_model=config.d_model, d_state=config.mamba_d_state, d_conv=config.mamba_d_conv, expand=config.mamba_expand, headdim=config.mamba_headdim, use_mem_eff_path=True, ) self.use_hf_fallback = False else: # Pure PyTorch fallback for Macs / CPUs / AMD GPUs from transformers.models.mamba2.configuration_mamba2 import Mamba2Config from transformers.models.mamba2.modeling_mamba2 import Mamba2Block mamba_cfg = Mamba2Config( hidden_size=config.d_model, state_size=config.mamba_d_state, conv_kernel=config.mamba_d_conv, expand=config.mamba_expand, head_dim=config.mamba_headdim, n_groups=1, use_bias=False, use_conv_bias=True, layer_norm_epsilon=1e-6, pad_token_id=None ) self.block = Mamba2Block(mamba_cfg, layer_idx) self.use_hf_fallback = True
def forward(self, x): if self.use_hf_fallback: return self.block(x) else: return x + self.mixer(self.ln(x))
class PebbleLM(PreTrainedModel, GenerationMixin): config_class = PebbleConfig _no_split_modules = ["MambaBlock", "AttentionBlock"]
def __init__(self, config): super().__init__(config) self.config = config self.wte = nn.Embedding(config.vocab_size, config.d_model) self.blocks = nn.ModuleList([ MambaBlock(config, i) if i % 4 < 3 else AttentionBlock(config.d_model, config.n_heads, config.att_hidden, config.rope_theta) for i in range(config.n_blocks) ]) self.lnf = RMSNorm(config.d_model) self.lm_head = nn.Linear(config.d_model, config.vocab_size, bias=False) self.lm_head.weight = self.wte.weight # Weight sharing
self.post_init()
def forward(self, input_ids, targets=None, **kwargs): x = self.wte(input_ids) for blk in self.blocks: x = blk(x) logits = self.lm_head(self.lnf(x))
loss = None if targets is not None: loss = F.cross_entropy(logits.view(-1, logits.size(-1)), targets.view(-1))
return CausalLMOutputWithPastCrossAttentions( loss=loss, logits=logits )
def prepare_inputs_for_generation(self, input_ids, past_key_values=None, attention_mask=None, **kwargs): # We ignore past_key_values to keep it simple for this custom architecture return {"input_ids": input_ids}
def _reorder_cache(self, past_key_values, beam_idx): return past_key_valuesmodeling_pebble.pyAdded+152