Instructions to use transformers-community/group-beam-search with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use transformers-community/group-beam-search with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="transformers-community/group-beam-search") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("transformers-community/group-beam-search") model = AutoModelForCausalLM.from_pretrained("transformers-community/group-beam-search") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- Local Apps Settings
- vLLM
How to use transformers-community/group-beam-search with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "transformers-community/group-beam-search" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "transformers-community/group-beam-search", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/transformers-community/group-beam-search
- SGLang
How to use transformers-community/group-beam-search 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 "transformers-community/group-beam-search" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "transformers-community/group-beam-search", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "transformers-community/group-beam-search" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "transformers-community/group-beam-search", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use transformers-community/group-beam-search with Docker Model Runner:
docker model run hf.co/transformers-community/group-beam-search
Support Transformers v5 cache handling
Fixes cached decoding with recent Transformers versions by passing next_sequence_length to prepare_inputs_for_generation during non-first cached decoding steps.
This addresses the cache-related deterministic-output corruption reported in #3.
A more detailed explanation and local test results are included in the discussion below.
Summary
Fix cached decoding with recent Transformers versions.
This updates the custom generation loop to pass next_sequence_length into prepare_inputs_for_generation. In cached decoding, Transformers v5 expects the decode loop to explicitly indicate that only the latest token should be forwarded after the first step. Without this, the cached path may forward the full growing sequence together with past_key_values, which can corrupt deterministic group beam outputs.
What changed
- Detect whether the loop is on the first decoding iteration.
- Use
next_sequence_length=Nonefor the prefill step and foruse_cache=False, preserving the existing full-sequence behavior. - Use
next_sequence_length=1for cached non-first decoding steps, matching the expected Transformers v5 cache behavior. - Pass
is_first_iterationthrough toprepare_inputs_for_generation.
This keeps use_cache=True supported instead of forcing use_cache=False.
Motivation
This addresses the issue discussed in #3: deterministic group beam search could produce different and sometimes corrupted outputs depending on whether cache was enabled.
Cache should be an optimization and should not materially change deterministic generation semantics.
Tested
I tested the updated custom generation locally with:
transformers==4.57.1transformers==5.12.1
using the Qwen/Qwen2.5-0.5B-Instruct reproducer from discussion #3 with deterministic grouped beam search.
Addresses #3
Ah nice, thanks for checking it. That PR indeed must have been breaking, we'd ideally check and update other generation methods as well. Feel free to check and PR if you want, otherwise I will look a bit later (low prio π )