Text Generation
Transformers
PyTorch
Safetensors
GGUF
English
collision
conversational
rag
reasoning
deepseek-r1-style
system-2
agent
ollama
llama.cpp
fastapi
openai-compatible
slm
edge-ai
cpu-first
in-house-nlp
math
keyphrase-extraction
topic-classification
grammar-correction
reading-comprehension
sentiment-analysis
research
educational
custom_code
Instructions to use collision-10M/Collision-1B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use collision-10M/Collision-1B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="collision-10M/Collision-1B", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("collision-10M/Collision-1B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use collision-10M/Collision-1B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "collision-10M/Collision-1B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "collision-10M/Collision-1B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/collision-10M/Collision-1B
- SGLang
How to use collision-10M/Collision-1B 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 "collision-10M/Collision-1B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "collision-10M/Collision-1B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "collision-10M/Collision-1B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "collision-10M/Collision-1B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use collision-10M/Collision-1B with Docker Model Runner:
docker model run hf.co/collision-10M/Collision-1B
File size: 3,973 Bytes
ddc12cc | 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 | import os
import torch
import yaml
from model.config import ModelConfig
from model.transformer import CollisionTransformer
from data.tokenize import BPETokenizer
def generate_sample(model, tokenizer, prompt, device, max_tokens=50):
model.eval()
ids = tokenizer.encode(prompt, bos=True)
x = torch.tensor([ids], dtype=torch.long, device=device)
with torch.no_grad():
for _ in range(max_tokens):
x_cond = x if x.size(1) <= model.config.max_seq_len else x[:, -model.config.max_seq_len:]
logits, _ = model(x_cond)
next_token_logits = logits[0, -1, :] / 0.8 # temp=0.8
# top_k filtering (k=50)
v, _ = torch.topk(next_token_logits, min(50, next_token_logits.size(-1)))
next_token_logits[next_token_logits < v[-1]] = -float('Inf')
probs = torch.softmax(next_token_logits, dim=-1)
next_token = torch.multinomial(probs, num_samples=1)
x = torch.cat((x, next_token.unsqueeze(0)), dim=1)
if next_token.item() == tokenizer.special_tokens.get("[EOS]", 2):
break
return tokenizer.decode(x[0].tolist())
def load_model(checkpoint_path, config_path, device):
model_config = ModelConfig.from_yaml(config_path)
model = CollisionTransformer(model_config).to(device)
checkpoint = torch.load(checkpoint_path, map_location=device)
# Extract state dict (handle potential nested structure)
state_dict = checkpoint.get("state_dict", checkpoint)
if "model_state_dict" in checkpoint:
state_dict = checkpoint["model_state_dict"]
elif "model" in checkpoint:
state_dict = checkpoint["model"]
model.load_state_dict(state_dict)
return model
def main():
config_path = "configs/collision_1m.yaml"
tokenizer_dir = "artifacts/tokenizer"
device = torch.device("cpu")
# Load Tokenizer
tokenizer = BPETokenizer()
tokenizer.load(tokenizer_dir)
# Checkpoint paths
p5_path = "checkpoints/phase5/collision-1.46m-step-001500.pt"
p6_path = "checkpoints/phase6/collision-1.46m-step-001500.pt"
# Manually curated evaluation prompts
eval_prompts = [
"Why does the Earth orbit the Sun?",
"What is an algorithm?",
"How does machine learning differ from traditional programming?",
"What is the relationship between energy and matter?",
"What is philosophy?"
]
print("Loading Phase 5 Model (Step 1500)...")
p5_model = load_model(p5_path, config_path, device)
print("Loading Phase 6 Model (Step 1500)...")
p6_model = load_model(p6_path, config_path, device)
output_lines = []
output_lines.append("==================================================")
output_lines.append("PHASE 5 VS PHASE 6 GENERALIZATION TEST EVALUATION")
output_lines.append("==================================================")
output_lines.append("")
for prompt in eval_prompts:
output_lines.append(f"PROMPT: {prompt}")
output_lines.append("-" * 40)
# Phase 5 Output
p5_out = generate_sample(p5_model, tokenizer, prompt, device)
output_lines.append("PHASE 5 STEP 1500 OUTPUT:")
output_lines.append(p5_out)
output_lines.append("")
# Phase 6 Output
p6_out = generate_sample(p6_model, tokenizer, prompt, device)
output_lines.append("PHASE 6 STEP 1500 OUTPUT:")
output_lines.append(p6_out)
output_lines.append("=" * 50)
output_lines.append("")
out_path = "experiments/phase6/generalization_test_results.txt"
os.makedirs(os.path.dirname(out_path), exist_ok=True)
with open(out_path, "w", encoding="utf-8") as f:
f.write("\n".join(output_lines))
print(f"Generalization test complete. Results written to {out_path}")
if __name__ == "__main__":
main()
|