[FEATURE] Add speculative decoding to the decoder algorithm family

Abierto
#798 1 comentario 0 reacciones 0 asignados Ver en GitHub

@mohityadav8 ya está trabajando en esto.

Desde el 23/11/2026.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
42/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
huggingface, python

Línea de trabajo

Start by reading kvpress.py and the existing zipar decoder algorithm to learn how algorithms register with AlgorithmTag.DECODER, then trace how SAVE_FUNCTIONS.reapply, model_check_fn and compatible_before are wired. Read the decoder tests in tests/algorithms/testers/ and test_compatibility_symmetry.py to see the expected coverage. Done means a registered speculative_decoding wrapper around generate with both drafting modes, plus passing tests for identical greedy output, save/load, diffusers rejection and compatibility symmetry on llama_3_tiny_random.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

enhancement

Is your feature request related to a problem? Please describe.

Pruna has no speculative decoding algorithm. The decoder family added in 0.3.2 only contains zipar, which supports Janus LlamaGen image models only, so ordinary causal LLMs can't get a faster decoding strategy through Pruna. The April 2025 optimization techniques post said speculative decoding wasn't implemented yet, and I couldn't find an implementation, open PR or branch for it in the repo.

Describe the solution you'd like

Add a speculative_decoding algorithm tagged AlgorithmTag.DECODER for causal LMs and transformers text-generation pipelines. It is lossless: the target model verifies every drafted token, so greedy outputs stay identical.

from pruna import SmashConfig, smash

# base_model = AutoModelForCausalLM.from_pretrained("HuggingFaceTB/SmolLM-1.7B")
smash_config = SmashConfig(["speculative_decoding"])
smash_config.add({
    "speculative_decoding_method": "draft_model",  # or "prompt_lookup" (default)
    "speculative_decoding_draft_model": "HuggingFaceTB/SmolLM-135M",
    "speculative_decoding_num_draft_tokens": 5,
})
smashed_model = smash(model=base_model, smash_config=smash_config)

Design, modelled on kvpress.py:

  • Two drafting methods, both using transformers' built-in assisted generation (no new dependency). prompt_lookup needs no extra model. draft_model passes a smaller model with the same tokenizer as assistant_model.
  • _apply wraps model.generate, keeps the original, and only injects the options when the caller hasn't set them. Assisted generation doesn't support batched inputs, so those fall back to plain generate with a log message.
  • model_check_fn: is_causal_lm(model) or is_transformers_pipeline_with_causal_lm(model). save_fn = SAVE_FUNCTIONS.reapply.
  • compatible_before: the LLM quantizers that pass the combination tests (candidates: awq, gptq, half, hqq, llm_int8, quanto, torchao), mirrored in their compatible_after so test_compatibility_symmetry.py passes. torch_compile stays out of the first PR unless its combination tests pass.
  • Tests in tests/algorithms/testers/ on llama_3_tiny_random: wrapper applied, identical greedy output with and without the algorithm, save/load round trip, diffusers models rejected.
  • A short tutorial comparing latency, throughput and energy with EvaluationAgent.

Out of scope, possible follow-ups: trained draft heads (EAGLE-style), universal assisted decoding for mismatched tokenizers, batched speculative decoding.

Additional context

A few questions before I start:

  1. Do you want speculative decoding in the open-source package, or is it planned for Pruna Pro?
  2. Is prompt_lookup an acceptable default, since it needs no extra weights?
  3. For draft_model, is reapply with the draft referenced by id/path fine, or should the draft weights be saved with the target?

I'd like to implement this myself. Could I be assigned? I'll follow the AI contribution policy: test locally, reuse existing utilities, and mark the PR as AI-assisted if it applies.

Lenguaje dominante
Python
Estrellas
1.4k
Forks
129
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de PrunaAI/pruna

Todos los issues de PrunaAI/pruna

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.