ingeniumacademy/reuters_articles
Viewer โข Updated โข 21.6k โข 319
How to use sehandi/gpt2-reuters-from-scratch with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="sehandi/gpt2-reuters-from-scratch") # pip install -U transformers accelerate
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("sehandi/gpt2-reuters-from-scratch")
model = AutoModelForCausalLM.from_pretrained("sehandi/gpt2-reuters-from-scratch", device_map="auto")How to use sehandi/gpt2-reuters-from-scratch with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "sehandi/gpt2-reuters-from-scratch"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "sehandi/gpt2-reuters-from-scratch",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/sehandi/gpt2-reuters-from-scratch
How to use sehandi/gpt2-reuters-from-scratch with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "sehandi/gpt2-reuters-from-scratch" \
--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": "sehandi/gpt2-reuters-from-scratch",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'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 "sehandi/gpt2-reuters-from-scratch" \
--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": "sehandi/gpt2-reuters-from-scratch",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use sehandi/gpt2-reuters-from-scratch with Docker Model Runner:
docker model run hf.co/sehandi/gpt2-reuters-from-scratch
CS4681 Assignment 02. Randomly initialised GPT-2 (no pretrained weights), trained with next-token prediction on
title + "\n\n" + body of the Reuters articles dataset, using the tokenizer ingeniumacademy/gpt2-reuters-tokenizer.
| main model (repo root) | |
|---|---|
| layers / hidden / heads | 6 / 384 / 6 |
| context length | 256 |
| parameters | 30,713,856 |
| epochs / lr / batch | 5 / 6e-4 (cosine) / 32 |
| training time (T4) | 11.3 min |
| validation loss (ppl) | 4.2574 (70.6) |
| test loss (ppl) | 4.0567 (57.8) |
Sub-folders: run_2_epochs/ (2 epochs), run_small_model_5_epochs/ (3 layers, 256 hidden, 4 heads).
Also: training_results.json, generated_samples.json, figures/.
from transformers import AutoTokenizer, GPT2LMHeadModel
tok = AutoTokenizer.from_pretrained("sehandi/gpt2-reuters-from-scratch")
model = GPT2LMHeadModel.from_pretrained("sehandi/gpt2-reuters-from-scratch")