Text Generation
Transformers
Safetensors
English
gpt2
toy-llm
from-scratch
huggingface
english
casual-lm
educational
text-generation-inference
Instructions to use mehta/CooperLM-354M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mehta/CooperLM-354M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="mehta/CooperLM-354M")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("mehta/CooperLM-354M") model = AutoModelForCausalLM.from_pretrained("mehta/CooperLM-354M") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use mehta/CooperLM-354M with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "mehta/CooperLM-354M" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mehta/CooperLM-354M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/mehta/CooperLM-354M
- SGLang
How to use mehta/CooperLM-354M 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 "mehta/CooperLM-354M" \ --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": "mehta/CooperLM-354M", "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 "mehta/CooperLM-354M" \ --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": "mehta/CooperLM-354M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use mehta/CooperLM-354M with Docker Model Runner:
docker model run hf.co/mehta/CooperLM-354M
🧠 CooperLM-354M
CooperLM-354M is a 354 million parameter GPT-2 based language model trained from scratch on a filtered subset of Wikipedia, BookCorpus, and OpenWebText. It was created as a toy project to explore end-to-end LLM training using Hugging Face’s Transformers and Datasets libraries.
Github Repo: https://github.com/daniel-mehta/CooperLM-354M
🧱 Architecture
- GPT-2 with 24 layers, 16 heads, 1024 hidden size
- 256-token context window
- Trained for 1 epoch on 100k samples (~1.2M sequences)
📊 Training Details
| Setting | Value |
|---|---|
| Model Type | GPT2LMHeadModel |
| Epochs | 1 |
| Precision | fp16 |
| Batch Size (effective) | 16 |
| GPU | RTX 4060 |
| Final Eval Loss | 5.63 |
| Perplexity | ~263 |
📥 Usage
from transformers import GPT2LMHeadModel, GPT2TokenizerFast
model = GPT2LMHeadModel.from_pretrained("mehta/CooperLM-354M")
tokenizer = GPT2TokenizerFast.from_pretrained("mehta/CooperLM-354M")
prompt = "In a distant future,"
inputs = tokenizer(prompt, return_tensors="pt")
output = model.generate(**inputs, max_length=100, do_sample=True, temperature=0.9, top_p=0.95)
print(tokenizer.decode(output[0], skip_special_tokens=True))
📝License
MIT
- Downloads last month
- 6