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)# 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
- 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
Support Transformers v5 cache handling
#4
by lavrenko - opened
- custom_generate/generate.py +15 -1
custom_generate/generate.py
CHANGED
|
@@ -304,8 +304,22 @@ def _group_beam_search(
|
|
| 304 |
batch_size * num_beams, dtype=torch.long, device=device
|
| 305 |
)
|
| 306 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
# do one decoder step on all beams of all sentences in batch
|
| 308 |
-
model_inputs = model.prepare_inputs_for_generation(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
|
| 310 |
# prepare variable output controls (note: some models won't accept all output controls)
|
| 311 |
model_inputs.update(
|
|
|
|
| 304 |
batch_size * num_beams, dtype=torch.long, device=device
|
| 305 |
)
|
| 306 |
|
| 307 |
+
# in cached decoding, Transformers v5 expects only the latest token
|
| 308 |
+
# after the first step
|
| 309 |
+
is_first_iteration = cur_len == decoder_prompt_len
|
| 310 |
+
next_sequence_length = (
|
| 311 |
+
None
|
| 312 |
+
if is_first_iteration or not model_kwargs.get("use_cache", True)
|
| 313 |
+
else 1
|
| 314 |
+
)
|
| 315 |
+
|
| 316 |
# do one decoder step on all beams of all sentences in batch
|
| 317 |
+
model_inputs = model.prepare_inputs_for_generation(
|
| 318 |
+
input_ids,
|
| 319 |
+
next_sequence_length=next_sequence_length,
|
| 320 |
+
is_first_iteration=is_first_iteration,
|
| 321 |
+
**model_kwargs,
|
| 322 |
+
)
|
| 323 |
|
| 324 |
# prepare variable output controls (note: some models won't accept all output controls)
|
| 325 |
model_inputs.update(
|