Text Generation
The official LLM inference entry is PreTrainedModel.generate() (Pipeline text-generation calls it). Settings live on GenerationConfig. Always set max_new_tokens explicitly—the default is often too small.
Minimal generate()
device_map="auto" and dtype="auto" are the official low-friction load tips.
Greedy vs sampling
Chat assistants usually sample; exams or strict JSON prefer greedy or low temperature.
Instruct models (Qwen)
For Chinese, prefer Qwen / DeepSeek Instruct weights over English DistilGPT2:
Slicing out[0][prompt.shape[-1]:] prints new tokens only, not the whole prompt.
0.5B usually fits 4–8 GB VRAM; CPU is slow. Larger Qwen / DeepSeek cards list memory on the model card.
GenerationConfig and common knobs
You can model.generation_config.save_pretrained("./gen-cfg") and upload it with the model.
vs Ollama
This site’s Ollama tutorial bundles quantization, chat templates, and an HTTP API—best for “chat on my laptop.” Transformers generate() is for paper-faithful decoding, custom logits processors, and later LoRA. Keep both: daily chat on Ollama, experiments here.