generation
Configure Transformers text/chat generation, GenerationConfig, decoding controls, streamers, logits processors, stopping criteria, and continuous batching concepts without requiring model downloads.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- generation
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Configure Transformers text/chat generation, GenerationConfig, decoding controls, streamers, logits processors, stopping criteria, and continuous batching concepts without requiring model downloads.
- disable-model-invocation
- true
02 资源文件 5
- 参考文档references/api-reference.md7.5 KB
- 参考文档references/continuous-batching.md5.3 KB
- 参考文档references/troubleshooting.md5.2 KB
- 参考文档references/workflows.md5.3 KB
- 脚本scripts/generation_config_smoke.py10.7 KB
03 SKILL.md 正文
Generation
Use This Sub-skill When
Use this sub-skill for Transformers workflows that need to design, validate, or troubleshoot text and chat generation behavior without downloading large models.
- Configure
GenerationConfigormodel.generate(...)arguments for greedy, sampling, beam, constrained, or custom generation. - Decide between
max_new_tokens,max_length,do_sample,temperature,top_p,top_k,num_beams,repetition_penalty, EOS, and padding controls. - Format chat messages with tokenizer chat templates before generation.
- Add or reason about
LogitsProcessor,LogitsProcessorList,StoppingCriteria, andStoppingCriteriaList. - Stream generated text with
TextIteratorStreameror related streamer classes. - Explain continuous batching concepts, request lifecycle, paged KV cache, scheduling, compile/offload options, and per-request sampling.
- Validate generation config JSON safely using the bundled smoke script.
Route Elsewhere
- For
pipeline(...)task selection, device placement, and pipeline-only kwargs, use../inference-pipelines/SKILL.md. - For tokenizer loading, padding side, special tokens, processors, and chat-template authoring details, use
../tokenizers-processors/SKILL.md. - For
transformers chat,transformers serve, HTTP serving, and OpenAI-compatible endpoints, use../serving-cli/SKILL.md. - For quantized generation, bitsandbytes, GPTQ, AWQ, Quanto, or device-memory tradeoffs, use
../quantization-integrations/SKILL.md. - For fine-tuning,
Trainer,TrainingArguments, or dataset preprocessing, use../training/SKILL.md. - For adding new model classes or custom architectures, use
../model-extension/SKILL.md.
Fast Generation Checklist
- Prefer
max_new_tokensfor user-facing generation length; avoid relying on defaults. - Choose one decoding family first: greedy (
do_sample=False,num_beams=1), sampling (do_sample=True), beam (num_beams>1), or beam sampling (num_beams>1,do_sample=True). - Only use sampling-only controls such as
temperature,top_p, andtop_kwhendo_sample=True. - Set
pad_token_idfor batched decoder-only generation when the tokenizer has no pad token, commonly toeos_token_idfor inference. - For chat models, pass structured messages through
tokenizer.apply_chat_template(...)instead of raw concatenated strings. - Put durable defaults in
GenerationConfig; use per-call kwargs for one-off overrides. - Treat PyTorch-backed model generation, streamers that consume real model output, and continuous batching as optional-dependency workflows that require
torchand model weights.
Primary APIs
GenerationConfig(**kwargs)stores generation parameters and can be saved/loaded withsave_pretrained(...)andfrom_pretrained(...).GenerationMixin.generate(...)is the generation entrypoint on compatible model classes.TextIteratorStreamer(tokenizer, skip_prompt=False, timeout=None, **decode_kwargs)supports iterator-style streaming from a background generation thread.LogitsProcessorandStoppingCriteriacustomize token selection and stopping rules.ContinuousBatchingConfigandContinuousBatchingManagerconfigure paged-KV continuous batching for serving-like generation.
See references/api-reference.md for parameter groups and API decision notes.
Safe No-download Validation
Use the bundled smoke script to validate config shape and common contradictions without loading a model:
python scripts/generation_config_smoke.py \
--max-new-tokens 64 --do-sample --temperature 0.7 --top-p 0.9
Validate an existing JSON file:
python scripts/generation_config_smoke.py \
--config-json generation_config.json --strict
Expected success signal: the script prints OK generation config validated plus a normalized summary. Expected failure signal: it exits non-zero with ERROR and names the conflicting option.
Common Workflows
- Draft deterministic or creative generation settings:
references/workflows.md#choose-a-decoding-strategy. - Build chat prompts safely:
references/workflows.md#chat-generation-with-templates. - Stream generation without deadlocks:
references/workflows.md#streaming-generation. - Add custom logits or stopping controls:
references/workflows.md#custom-logits-processors-and-stopping-criteria. - Plan continuous batching:
references/continuous-batching.md. - Diagnose warnings and config conflicts:
references/troubleshooting.md.
Integrated Routing Notes
When generation settings appear inside serving, pipeline, quantization, or chat-template requests, keep this sub-skill responsible for decoding semantics and route the outer workflow to the relevant sibling. For example, a serving/chat request with reasoning or chat_template_kwargs needs this sub-skill for GenerationConfig and chat generation choices, plus ../serving-cli/SKILL.md for endpoint behavior.
Optional Dependency Boundary
A minimal Transformers import can inspect GenerationConfig and many config utilities without PyTorch. Real AutoModelForCausalLM, model.generate(...), streamers attached to model execution, logits processors that operate on tensors, and continuous batching require backend dependencies such as torch; missing backends raise optional dependency ImportErrors. When writing agent instructions or tests, keep no-download config validation separate from model-backed generation checks.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).