Instructions to use itlrc/gpt2-small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use itlrc/gpt2-small with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="itlrc/gpt2-small", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("itlrc/gpt2-small", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use itlrc/gpt2-small with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "itlrc/gpt2-small" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "itlrc/gpt2-small", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/itlrc/gpt2-small
- SGLang
How to use itlrc/gpt2-small 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 "itlrc/gpt2-small" \ --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": "itlrc/gpt2-small", "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 "itlrc/gpt2-small" \ --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": "itlrc/gpt2-small", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use itlrc/gpt2-small with Docker Model Runner:
docker model run hf.co/itlrc/gpt2-small
GPT-2 Small (124M) treinado do zero
Modelo causal de linguagem com arquitetura equivalente ao GPT-2 Small, treinado do zero sobre o sample-10BT do FineWeb-Edu. O treinamento usou o tokenizer GPT-2 e processou aproximadamente 5,51 bilhões de tokens.
Resultados
| Métrica | Resultado |
|---|---|
| Parâmetros | 124.439.808 |
| Steps | 10.500 |
| Épocas lógicas completas | 42 |
| Train loss | 3,3080 |
| Validation loss | 3,2915 |
| Validation perplexity | 26,88 |
| HellaSwag | 27,68% em 10.042 exemplos |
Arquitetura
- 12 blocos Transformer;
- 12 cabeças de atenção;
- embedding de 768 dimensões;
- contexto máximo de 1.024 tokens;
- vocabulário de 50.257 tokens;
- pesos compartilhados entre embedding e cabeça de linguagem;
- 124.439.808 parâmetros em FP32.
Uso com Transformers
Este repositório inclui código de arquitetura personalizado. Por isso, o carregamento requer trust_remote_code=True.
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
repo_id = "itlrc/gpt2-small"
tokenizer = AutoTokenizer.from_pretrained("gpt2")
model = AutoModelForCausalLM.from_pretrained(
repo_id,
trust_remote_code=True,
torch_dtype=torch.float32,
)
inputs = tokenizer("Hi! I'm a", return_tensors="pt")
with torch.inference_mode():
output = model.generate(
**inputs,
max_new_tokens=64,
do_sample=True,
temperature=0.8,
top_k=50,
)
print(tokenizer.decode(output[0], skip_special_tokens=True))
Substitua SEU_USUARIO/meu-gpt2-small pelo identificador deste repositório no Hub.
Treinamento
- Dataset:
HuggingFaceFW/fineweb-edu, configuraçãosample-10BT; - batch efetivo de 524.288 tokens por step;
- 250 steps por época lógica;
- AdamW com betas
(0.9, 0.95)e weight decay0.1; - gradient clipping em
1.0; - warmup e cosine decay;
- validação em um conjunto fixo de documentos reservados.
- aproximadamente 6 bilhões de tokens
Limitações
O modelo é um experimento educacional e não recebeu instruction tuning, RLHF ou outro alinhamento por preferências. Pode produzir informações falsas, repetições, vieses ou conteúdo inadequado.
- Downloads last month
- 292
