Text Generation
Transformers
Safetensors
qwen3
custom_generate
conversational
text-generation-inference
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)# pip install -U transformers accelerate # 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", device_map="auto") 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- 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
Guard shared prefill for non-standard input expansion
Browse filesOnly enable shared prefill when beam expansion can be safely reversed. Fall back to the original beam-shaped forward path for models with custom input expansion or tensors whose leading dimension does not match the expanded beam batch.
- custom_generate/generate.py +16 -1
custom_generate/generate.py
CHANGED
|
@@ -241,6 +241,20 @@ def _group_beam_search(
|
|
| 241 |
device = input_ids.device
|
| 242 |
|
| 243 |
batch_beam_size, cur_len = input_ids.shape
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
# Does not exist anymore in recent versions!
|
| 245 |
if hasattr(model, "_get_initial_cache_position"):
|
| 246 |
model_kwargs = model._get_initial_cache_position(cur_len, input_ids.device, model_kwargs)
|
|
@@ -314,9 +328,10 @@ def _group_beam_search(
|
|
| 314 |
)
|
| 315 |
|
| 316 |
# prefill one prompt per batch item before beams diverge
|
| 317 |
-
# keep the original path when
|
| 318 |
shared_prefill = (
|
| 319 |
is_first_iteration
|
|
|
|
| 320 |
and not model.config.is_encoder_decoder
|
| 321 |
and not (output_attentions or output_hidden_states or output_logits)
|
| 322 |
)
|
|
|
|
| 241 |
device = input_ids.device
|
| 242 |
|
| 243 |
batch_beam_size, cur_len = input_ids.shape
|
| 244 |
+
|
| 245 |
+
# Shared prefill can only undo the standard beam expansion when every
|
| 246 |
+
# non-scalar tensor is expanded along the leading batch dimension.
|
| 247 |
+
can_share_prefill = (
|
| 248 |
+
type(model)._expand_inputs_for_generation
|
| 249 |
+
is GenerationMixin._expand_inputs_for_generation
|
| 250 |
+
and all(
|
| 251 |
+
not isinstance(value, torch.Tensor)
|
| 252 |
+
or value.ndim == 0
|
| 253 |
+
or value.shape[0] == batch_beam_size
|
| 254 |
+
for value in model_kwargs.values()
|
| 255 |
+
)
|
| 256 |
+
)
|
| 257 |
+
|
| 258 |
# Does not exist anymore in recent versions!
|
| 259 |
if hasattr(model, "_get_initial_cache_position"):
|
| 260 |
model_kwargs = model._get_initial_cache_position(cur_len, input_ids.device, model_kwargs)
|
|
|
|
| 328 |
)
|
| 329 |
|
| 330 |
# prefill one prompt per batch item before beams diverge
|
| 331 |
+
# keep the original path when beam expansion cannot be safely undone
|
| 332 |
shared_prefill = (
|
| 333 |
is_first_iteration
|
| 334 |
+
and can_share_prefill
|
| 335 |
and not model.config.is_encoder_decoder
|
| 336 |
and not (output_attentions or output_hidden_states or output_logits)
|
| 337 |
)
|