Text Generation
Transformers
Safetensors
English
fabryka_english_base
experimental
base-model
custom-code
custom_code
Instructions to use SlayerLab/fabryka-english-base-250m-e01 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use SlayerLab/fabryka-english-base-250m-e01 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="SlayerLab/fabryka-english-base-250m-e01", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("SlayerLab/fabryka-english-base-250m-e01", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use SlayerLab/fabryka-english-base-250m-e01 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "SlayerLab/fabryka-english-base-250m-e01" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "SlayerLab/fabryka-english-base-250m-e01", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/SlayerLab/fabryka-english-base-250m-e01
- SGLang
How to use SlayerLab/fabryka-english-base-250m-e01 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 "SlayerLab/fabryka-english-base-250m-e01" \ --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": "SlayerLab/fabryka-english-base-250m-e01", "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 "SlayerLab/fabryka-english-base-250m-e01" \ --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": "SlayerLab/fabryka-english-base-250m-e01", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use SlayerLab/fabryka-english-base-250m-e01 with Docker Model Runner:
docker model run hf.co/SlayerLab/fabryka-english-base-250m-e01
Download model.py from SlayerLab/fabryka-english-base-250m-e01: direct link, hf CLI and curl.
- Browser
- Download file 4.87 kB
-
https://huggingface.co/SlayerLab/fabryka-english-base-250m-e01/resolve/main/model.py
- Command line
-
hf download hf://SlayerLab/fabryka-english-base-250m-e01/model.py
-
curl -L -o model.py https://huggingface.co/SlayerLab/fabryka-english-base-250m-e01/resolve/main/model.py
4.87 kB
| """RFC-005 decoder using Transformers' Llama attention, RoPE and generation. | |
| The explicit model class is required when loading: ordinary Llama does not | |
| implement this recipe's parameter-free QK normalization or two-matrix ReLU². | |
| """ | |
| from dataclasses import asdict | |
| import torch | |
| from torch import nn | |
| from torch.nn import functional as F | |
| from transformers import LlamaConfig, LlamaForCausalLM | |
| from .recipe import Architecture | |
| class EnglishBaseConfig(LlamaConfig): | |
| model_type = 'fabryka_english_base' | |
| def __init__(self, recipe=None, qk_norm=True, **kwargs): | |
| architecture = Architecture(**(recipe or {})) | |
| controlled = dict( | |
| vocab_size=architecture.vocab_size, hidden_size=architecture.width, | |
| intermediate_size=architecture.ffn_width, num_hidden_layers=architecture.layers, | |
| num_attention_heads=architecture.query_heads, num_key_value_heads=architecture.kv_heads, | |
| head_dim=architecture.head_dim, max_position_embeddings=architecture.context, | |
| hidden_act='silu', attention_bias=False, mlp_bias=False, | |
| attention_dropout=0.0, tie_word_embeddings=architecture.tied_embeddings, | |
| ) | |
| for key, value in controlled.items(): | |
| if key in kwargs and kwargs[key] != value: | |
| raise ValueError(f'{key} conflicts with recorded architecture') | |
| kwargs[key] = value | |
| if type(qk_norm) is not bool: | |
| raise ValueError('qk_norm must be boolean') | |
| super().__init__(**kwargs) | |
| self.recipe = asdict(architecture) | |
| self.qk_norm = qk_norm | |
| class HeadNormalizedLinear(nn.Linear): | |
| """Project, then normalize each head in FP32 before RoPE; no learned gain.""" | |
| def __init__(self, source, head_dim, eps): | |
| super().__init__(source.in_features, source.out_features, bias=False, | |
| device=source.weight.device, dtype=source.weight.dtype) | |
| self.weight = source.weight | |
| self.head_dim, self.eps = head_dim, eps | |
| def forward(self, x): | |
| projected = F.linear(x, self.weight) | |
| heads = projected.unflatten(-1, (-1, self.head_dim)) | |
| if hasattr(F, 'rms_norm'): | |
| normalized = F.rms_norm(heads.float(), (self.head_dim,), eps=self.eps) | |
| else: | |
| # PyTorch 2.3 compatibility for the pinned DCLM evaluation harness. | |
| values = heads.float() | |
| normalized = values * torch.rsqrt(values.square().mean(-1, keepdim=True) + self.eps) | |
| return normalized.to(projected.dtype).flatten(-2) | |
| class ReluSquaredMLP(nn.Module): | |
| def __init__(self, original): | |
| super().__init__() | |
| self.up_proj = original.up_proj | |
| self.down_proj = original.down_proj | |
| def forward(self, x): | |
| return self.down_proj(F.relu(self.up_proj(x)).square()) | |
| class EnglishBaseForCausalLM(LlamaForCausalLM): | |
| config_class = EnglishBaseConfig | |
| def __init__(self, config): | |
| if not isinstance(config, EnglishBaseConfig): | |
| raise TypeError('EnglishBaseConfig is required; byte/Llama checkpoints are distinct') | |
| super().__init__(config) | |
| for block in self.model.layers: | |
| if config.recipe['activation'] == 'relu2': | |
| block.mlp = ReluSquaredMLP(block.mlp) | |
| if config.qk_norm: | |
| for name in ('q_proj', 'k_proj'): | |
| projection = getattr(block.self_attn, name) | |
| setattr(block.self_attn, name, HeadNormalizedLinear( | |
| projection, config.head_dim, config.rms_norm_eps)) | |
| def parameter_report(self): | |
| total = sum(p.numel() for p in self.parameters()) | |
| expected = Architecture(**self.config.recipe).parameter_count | |
| if total != expected: | |
| raise ValueError(f'Implemented parameter count {total} differs from expected {expected}') | |
| embedding_ids = {id(self.get_input_embeddings().weight), id(self.get_output_embeddings().weight)} | |
| non_embedding = sum(p.numel() for p in self.parameters() if id(p) not in embedding_ids) | |
| return {'total_parameters': total, 'non_embedding_parameters': non_embedding, | |
| 'tied_embeddings': self.get_input_embeddings().weight is self.get_output_embeddings().weight, | |
| 'qk_norm': self.config.qk_norm} | |
| def mark_tied_weights_as_initialized(self, loading_info): | |
| """Preserve parameter-tying missing keys for Transformers 5.3 loading. | |
| This architecture uses parameter tying only, never shared modules. | |
| The remote-code compatibility path in 5.3 removes initialized missing | |
| keys before tie_weights, including the lm_head it has just marked. | |
| Keep that key so the loader ties it to the loaded input embedding. | |
| """ | |
| for name in self.all_tied_weights_keys: | |
| self.get_parameter(name)._is_hf_initialized = True | |