Text Generation
Transformers
Safetensors
dat
babylm
babylm-2026
causal-lm
dual-attention-transformer
nextlat
ema
custom-code
custom_code
Instructions to use abe123/babylm-dat-strict-nextlat-final with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use abe123/babylm-dat-strict-nextlat-final with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="abe123/babylm-dat-strict-nextlat-final", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("abe123/babylm-dat-strict-nextlat-final", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use abe123/babylm-dat-strict-nextlat-final with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "abe123/babylm-dat-strict-nextlat-final" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "abe123/babylm-dat-strict-nextlat-final", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/abe123/babylm-dat-strict-nextlat-final
- SGLang
How to use abe123/babylm-dat-strict-nextlat-final 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 "abe123/babylm-dat-strict-nextlat-final" \ --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": "abe123/babylm-dat-strict-nextlat-final", "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 "abe123/babylm-dat-strict-nextlat-final" \ --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": "abe123/babylm-dat-strict-nextlat-final", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use abe123/babylm-dat-strict-nextlat-final with Docker Model Runner:
docker model run hf.co/abe123/babylm-dat-strict-nextlat-final
File size: 3,342 Bytes
2719787 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | """MLM head for the hybrid MLM/CLM objective.
Ported from temp/gpt-bert-main/pretraining/model.py MaskClassifier, but
configurable to match the trunk's customizability:
- norm_type: "layernorm" or "rmsnorm" (reuses the existing field).
- ffn_activation: "gelu", "swiglu", "relu", or "identity" (reuses the
existing field). The head's nonlinearity follows this choice.
- use_bias_ffn: whether the linear layers in the head use bias.
- weight tying: the final linear is tied to the word embedding, matching
gpt-bert's MaskClassifier and our lm_head.
The head is controlled by model config (mlm_head_enabled) so checkpoint
loading and HF export remain strict and honest.
"""
import torch
import torch.nn as nn
from .transformer_components import RMSNorm, FeedForward
def _create_norm(norm_type: str, hidden_dim: int) -> nn.Module:
if norm_type == "layernorm":
return nn.LayerNorm(hidden_dim)
if norm_type == "rmsnorm":
return RMSNorm(hidden_dim)
raise ValueError(f"Unsupported norm_type: {norm_type}")
class MaskClassifier(nn.Module):
"""MLM prediction head with configurable norm and activation.
Architecture (matching gpt-bert's MaskClassifier):
norm -> FeedForward (activation, bias configurable) -> norm -> dropout -> linear (tied)
The final linear is tied to the word embedding weight, matching
gpt-bert's MaskClassifier and our lm_head.
Args:
hidden_dim: Model hidden dimension.
vocab_size: Vocabulary size for the output projection.
norm_type: "layernorm" or "rmsnorm".
ffn_activation: "gelu", "swiglu", "relu", or "identity".
use_bias_ffn: Whether the intermediate linear layers use bias.
dropout: Dropout probability.
word_embedding: The word embedding weight to tie the final linear to.
"""
def __init__(
self,
hidden_dim: int,
vocab_size: int,
norm_type: str,
ffn_activation: str,
use_bias_ffn: bool,
dropout: float,
word_embedding: nn.Parameter,
):
super().__init__()
self.hidden_dim = hidden_dim
self.vocab_size = vocab_size
self.norm_type = norm_type
self.ffn_activation = ffn_activation
self.use_bias_ffn = use_bias_ffn
self.dropout_p = dropout
self.norm1 = _create_norm(norm_type, hidden_dim)
self.feed_forward = FeedForward(
input_dim=hidden_dim,
hidden_dim=hidden_dim,
dropout=dropout,
activation=ffn_activation,
use_bias=use_bias_ffn,
)
self.norm2 = _create_norm(norm_type, hidden_dim)
self.dropout = nn.Dropout(dropout)
self.linear_out = nn.Linear(hidden_dim, vocab_size, bias=False)
self.linear_out.weight = word_embedding
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""Apply the MLM head to contextualized embeddings.
Args:
x: Contextualized embeddings [batch, seq_len, hidden_dim] or
flattened [num_masked, hidden_dim].
Returns:
Logits [batch, seq_len, vocab_size] or [num_masked, vocab_size].
"""
x = self.norm1(x)
x = self.feed_forward(x)
x = self.norm2(x)
x = self.dropout(x)
x = self.linear_out(x)
return x
|