Instructions to use dbmdz/german-gpt2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use dbmdz/german-gpt2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="dbmdz/german-gpt2")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("dbmdz/german-gpt2") model = AutoModelForCausalLM.from_pretrained("dbmdz/german-gpt2", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use dbmdz/german-gpt2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "dbmdz/german-gpt2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "dbmdz/german-gpt2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/dbmdz/german-gpt2
- SGLang
How to use dbmdz/german-gpt2 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 "dbmdz/german-gpt2" \ --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": "dbmdz/german-gpt2", "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 "dbmdz/german-gpt2" \ --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": "dbmdz/german-gpt2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use dbmdz/german-gpt2 with Docker Model Runner:
docker model run hf.co/dbmdz/german-gpt2
Usable context seems to be 512 tokens, not 1024
Hi,
a heads-up for users of this model: although config.json declares n_positions=1024, the per-token loss rises 5–30× from position 512 on (e.g. Kafka's Die Verwandlung: perplexity ~20–90 at positions 0–511, ~180–1,280 at 512–1,023, consistently across five windows). The model card refers to the JAX/FLAX example hyperparameters, which use block_size=512, so the model was probably trained on 512-token sequences.
Practical consequences:
- Perplexity or surprisal computed with windows longer than 512 tokens is inflated.
- The tokenizer reports model_max_length = 1e30, so truncation=True does not protect against inputs over 1,024 tokens.
Workaround for long texts: sliding windows of at most 512 tokens.
Details, numbers and a reproduction script: https://github.com/stefan-it/german-gpt2/issues/20
Jochen Laubrock