Text Generation
Transformers
Safetensors
English
pollock
causal-lm
gpt2
nanogpt
swiglu
bpe
educational
base-model
custom_code
Eval Results (legacy)
Instructions to use SlayerLab/pollock-mini-lm-125m with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use SlayerLab/pollock-mini-lm-125m with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="SlayerLab/pollock-mini-lm-125m", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("SlayerLab/pollock-mini-lm-125m", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use SlayerLab/pollock-mini-lm-125m with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "SlayerLab/pollock-mini-lm-125m" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "SlayerLab/pollock-mini-lm-125m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/SlayerLab/pollock-mini-lm-125m
- SGLang
How to use SlayerLab/pollock-mini-lm-125m 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/pollock-mini-lm-125m" \ --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/pollock-mini-lm-125m", "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/pollock-mini-lm-125m" \ --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/pollock-mini-lm-125m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use SlayerLab/pollock-mini-lm-125m with Docker Model Runner:
docker model run hf.co/SlayerLab/pollock-mini-lm-125m
File size: 13,912 Bytes
8bda8c7 e780025 8bda8c7 e780025 8bda8c7 e780025 8bda8c7 e780025 8bda8c7 e780025 8bda8c7 e780025 8bda8c7 e780025 8bda8c7 4130d98 8bda8c7 e780025 8bda8c7 4130d98 8bda8c7 4130d98 8bda8c7 e780025 8bda8c7 cd7e692 8bda8c7 | 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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | #!/usr/bin/env python3
"""Generate or verify Pollock's fixed cross-revision inference samples."""
from __future__ import annotations
import argparse
import gc
import hashlib
import json
import platform
from importlib.metadata import version
from pathlib import Path
from typing import Any
import torch
from huggingface_hub import hf_hub_download
from transformers import AutoModelForCausalLM, AutoTokenizer
HERE = Path(__file__).resolve().parent
PACKAGE_NAMES = {
"torch": "torch",
"transformers": "transformers",
"huggingface_hub": "huggingface-hub",
}
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--config", type=Path, default=HERE / "config.json")
parser.add_argument("--output", type=Path, default=HERE / "results.json")
parser.add_argument("--markdown", type=Path, default=HERE / "README.md")
parser.add_argument(
"--check",
action="store_true",
help="Regenerate in memory and require an exact match with --output",
)
parser.add_argument(
"--allow-version-mismatch",
action="store_true",
help="Run even if the Python or package versions differ from config.json",
)
parser.add_argument(
"--render-only",
action="store_true",
help="Render --markdown from the existing --output without inference",
)
return parser.parse_args()
def sha256_file(path: Path) -> str:
digest = hashlib.sha256()
with path.open("rb") as handle:
for chunk in iter(lambda: handle.read(8 * 1024 * 1024), b""):
digest.update(chunk)
return digest.hexdigest()
def sha256_text(text: str) -> str:
return hashlib.sha256(text.encode("utf-8")).hexdigest()
def runtime_environment() -> dict[str, str]:
operating_system = platform.system()
if operating_system == "Darwin":
operating_system = f"macOS {platform.mac_ver()[0]}"
return {
"operating_system": operating_system,
"architecture": platform.machine(),
"python": platform.python_version(),
**{
config_name: version(package_name)
for config_name, package_name in PACKAGE_NAMES.items()
},
}
def validate_environment(config: dict[str, Any], allow_mismatch: bool) -> dict[str, str]:
actual = runtime_environment()
expected = config["environment"]
mismatches = {
name: {"expected": expected[name], "actual": actual[name]}
for name in expected
if actual.get(name) != expected[name]
}
if mismatches and not allow_mismatch:
raise RuntimeError(f"Environment mismatch: {json.dumps(mismatches)}")
return actual
def generate_results(config: dict[str, Any], environment: dict[str, str]) -> dict[str, Any]:
protocol = config["protocol"]
if protocol["device"] != "cpu" or protocol["dtype"] != "float32":
raise ValueError("The fixed suite requires CPU float32 inference")
torch.set_num_threads(protocol["cpu_threads"])
torch.set_num_interop_threads(1)
torch.use_deterministic_algorithms(True)
revision_results = []
for revision in config["revisions"]:
local_path = revision.get("local_path")
if local_path:
model_source = Path(local_path)
if not model_source.is_absolute():
model_source = (HERE / model_source).resolve()
weights_path = model_source / "model.safetensors"
load_kwargs: dict[str, Any] = {}
source_label = str(model_source)
else:
model_source = config["model_id"]
weights_path = Path(
hf_hub_download(
repo_id=config["model_id"],
filename="model.safetensors",
revision=revision["commit"],
token=False,
)
)
load_kwargs = {"revision": revision["commit"], "token": False}
source_label = revision["commit"]
print(
f"Loading {revision['revision_id']} from {source_label}...",
flush=True,
)
actual_model_sha = sha256_file(weights_path)
if actual_model_sha != revision["model_sha256"]:
raise RuntimeError(
f"Weight hash mismatch for {revision['revision_id']}: "
f"{actual_model_sha} != {revision['model_sha256']}"
)
tokenizer = AutoTokenizer.from_pretrained(
model_source,
trust_remote_code=False,
**load_kwargs,
)
model = AutoModelForCausalLM.from_pretrained(
model_source,
dtype=torch.float32,
trust_remote_code=False,
**load_kwargs,
)
model.to("cpu")
model.eval()
prompt_results = []
for prompt in config["prompts"]:
torch.manual_seed(protocol["seed"])
inputs = tokenizer(prompt["text"], return_tensors="pt")
input_length = inputs["input_ids"].shape[1]
with torch.inference_mode():
output = model.generate(
**inputs,
do_sample=protocol["do_sample"],
temperature=protocol["temperature"],
top_k=protocol["top_k"],
top_p=protocol["top_p"],
max_new_tokens=protocol["max_new_tokens"],
num_return_sequences=protocol["num_return_sequences"],
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.eos_token_id,
use_cache=True,
)
full_token_ids = output[0].tolist()
completion_token_ids = full_token_ids[input_length:]
full_text = tokenizer.decode(
full_token_ids,
skip_special_tokens=protocol["skip_special_tokens"],
)
completion_text = tokenizer.decode(
completion_token_ids,
skip_special_tokens=protocol["skip_special_tokens"],
)
prompt_results.append(
{
"prompt_id": prompt["prompt_id"],
"prompt": prompt["text"],
"prompt_token_ids": full_token_ids[:input_length],
"completion_token_ids": completion_token_ids,
"completion_tokens": len(completion_token_ids),
"stopped_on_eos": bool(
completion_token_ids
and completion_token_ids[-1] == tokenizer.eos_token_id
),
"completion": completion_text,
"full_text": full_text,
"full_text_sha256": sha256_text(full_text),
}
)
print(
f" {prompt['prompt_id']}: {len(completion_token_ids)} tokens",
flush=True,
)
revision_results.append(
{
**{key: value for key, value in revision.items() if key != "local_path"},
"loaded_model_version": getattr(model.config, "model_version", None),
"results": prompt_results,
}
)
del model, tokenizer
gc.collect()
return {
"schema_version": 1,
"suite_id": config["suite_id"],
"model_id": config["model_id"],
"environment": environment,
"protocol": protocol,
"revisions": revision_results,
}
def render_markdown(config: dict[str, Any], results: dict[str, Any]) -> str:
protocol = results["protocol"]
environment = results["environment"]
revisions = {item["revision_id"]: item for item in results["revisions"]}
has_pending_commit = any(
item["commit"].startswith("__PENDING_") for item in results["revisions"]
)
lines = [
"# Fixed cross-revision inference samples",
"",
"These samples compare Pollock revisions under one fixed inference "
"protocol. They are behavioral examples, not benchmark scores or factuality claims. "
"Outputs are shown without cherry-picking, including errors and repetition.",
"",
"## Protocol",
"",
f"- Suite: `{results['suite_id']}`",
f"- Runtime: {environment['operating_system']} "
f"{environment['architecture']}, Python {environment['python']}, "
f"PyTorch {environment['torch']}, "
f"Transformers {environment['transformers']}, huggingface_hub "
f"{environment['huggingface_hub']}",
f"- Execution: {protocol['device'].upper()}, `{protocol['dtype']}`, "
f"{protocol['cpu_threads']} PyTorch CPU thread",
f"- Sampling: seed {protocol['seed']} reset before every prompt, temperature "
f"{protocol['temperature']}, top-k {protocol['top_k']}, top-p "
f"{protocol['top_p']}",
f"- Limit: {protocol['max_new_tokens']} new tokens, with the prompt included in "
"each displayed output",
"",
"The older samples embedded in `training-history/r001.md` remain part of the "
"historical record. They differ from this suite because their complete execution "
"environment was not pinned. Only the results below are used for direct "
"cross-revision comparison.",
"",
"Exact token replay was verified in the recorded environment. Sampling may "
"diverge on another operating system or CPU architecture even when package "
"versions and seeds match.",
"",
*(
[
"The r007 outputs currently use the local artifact whose weight hash is "
"shown below. Replay from its immutable publication commit remains pending.",
"",
]
if has_pending_commit
else []
),
"## Revisions",
"",
"| Revision | Release | Immutable weights | `model.safetensors` SHA-256 |",
"|---|---|---|---|",
]
for revision in results["revisions"]:
commit = revision["commit"]
if commit.startswith("__PENDING_"):
weights = "local artifact; immutable commit pending"
else:
commit_url = f"https://huggingface.co/{results['model_id']}/commit/{commit}"
weights = f"[`{commit[:7]}`]({commit_url})"
lines.append(
f"| {revision['revision_id']} | {revision['release']} | "
f"{weights} | `{revision['model_sha256']}` |"
)
lines.extend(
[
"",
"## Results",
"",
]
)
for prompt in config["prompts"]:
lines.extend(
[
f"### {prompt['label']}",
"",
f"Prompt: `{prompt['text']}`",
"",
]
)
for revision_config in config["revisions"]:
revision_id = revision_config["revision_id"]
result = next(
item
for item in revisions[revision_id]["results"]
if item["prompt_id"] == prompt["prompt_id"]
)
lines.extend(
[
f"#### {revision_id} - {revision_config['release']}",
"",
"````text",
result["full_text"],
"````",
"",
f"Output SHA-256: `{result['full_text_sha256']}`",
"",
]
)
lines.extend(
[
"## Reproduce or verify",
"",
"Run from this directory. The check downloads approximately 2.4 GB of "
"published model artifacts if they are not already cached.",
"",
"```bash",
"python -m venv .venv",
"source .venv/bin/activate",
"pip install -r requirements.txt",
"python generate.py --check",
"```",
"",
"`generate.py` rejects package-version mismatches by default, verifies each "
"weight file against `config.json`, and compares both token IDs and rendered "
"text through `results.json`.",
"",
"Machine-readable protocol and outputs: [`config.json`](./config.json) and "
"[`results.json`](./results.json).",
"",
]
)
return "\n".join(lines)
def main() -> None:
args = parse_args()
config = json.loads(args.config.read_text(encoding="utf-8"))
if args.render_only:
if args.check:
raise ValueError("--render-only and --check cannot be combined")
results = json.loads(args.output.read_text(encoding="utf-8"))
args.markdown.write_text(
render_markdown(config, results),
encoding="utf-8",
)
print(f"Wrote {args.markdown}")
return
environment = validate_environment(config, args.allow_version_mismatch)
results = generate_results(config, environment)
markdown = render_markdown(config, results)
if args.check:
expected = json.loads(args.output.read_text(encoding="utf-8"))
if results != expected:
raise RuntimeError(f"Generated results differ from {args.output}")
if markdown != args.markdown.read_text(encoding="utf-8"):
raise RuntimeError(f"Rendered Markdown differs from {args.markdown}")
print(f"Exact match: {args.output} and {args.markdown}")
return
args.output.write_text(
json.dumps(results, indent=2, ensure_ascii=False) + "\n",
encoding="utf-8",
)
args.markdown.write_text(markdown, encoding="utf-8")
print(f"Wrote {args.output} and {args.markdown}")
if __name__ == "__main__":
main()
|