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
Download data/run_generalization_test.py from collision-10M/Collision-1B: direct link, hf CLI and curl.
- Browser
- Download file 3.97 kB
-
https://huggingface.co/collision-10M/Collision-1B/resolve/main/data/run_generalization_test.py
- Command line
-
hf download hf://collision-10M/Collision-1B/data/run_generalization_test.py
-
curl -L -o run_generalization_test.py https://huggingface.co/collision-10M/Collision-1B/resolve/main/data/run_generalization_test.py
3.97 kB
| 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() | |