AGENT SKILL

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

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 GenerationConfig or model.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, and StoppingCriteriaList.
  • Stream generated text with TextIteratorStreamer or 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

  1. Prefer max_new_tokens for user-facing generation length; avoid relying on defaults.
  2. 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).
  3. Only use sampling-only controls such as temperature, top_p, and top_k when do_sample=True.
  4. Set pad_token_id for batched decoder-only generation when the tokenizer has no pad token, commonly to eos_token_id for inference.
  5. For chat models, pass structured messages through tokenizer.apply_chat_template(...) instead of raw concatenated strings.
  6. Put durable defaults in GenerationConfig; use per-call kwargs for one-off overrides.
  7. Treat PyTorch-backed model generation, streamers that consume real model output, and continuous batching as optional-dependency workflows that require torch and model weights.

Primary APIs

  • GenerationConfig(**kwargs) stores generation parameters and can be saved/loaded with save_pretrained(...) and from_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.
  • LogitsProcessor and StoppingCriteria customize token selection and stopping rules.
  • ContinuousBatchingConfig and ContinuousBatchingManager configure 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

VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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).

★ 351