Text Generation
Transformers
Safetensors
qwen3
custom_generate
conversational
text-generation-inference
Instructions to use transformers-community/dola with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use transformers-community/dola with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="transformers-community/dola") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("transformers-community/dola") model = AutoModelForCausalLM.from_pretrained("transformers-community/dola") 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/dola with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "transformers-community/dola" # 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/dola", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/transformers-community/dola
- SGLang
How to use transformers-community/dola 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/dola" \ --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/dola", "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/dola" \ --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/dola", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use transformers-community/dola with Docker Model Runner:
docker model run hf.co/transformers-community/dola
Fix Transformers v5 cached decoding in DoLa
#2
by lavrenko - opened
- custom_generate/generate.py +17 -2
custom_generate/generate.py
CHANGED
|
@@ -229,9 +229,24 @@ def _dola_decoding(
|
|
| 229 |
if lm_head is None:
|
| 230 |
raise ValueError("DoLa is not supported for models that don't have output embeddings.")
|
| 231 |
|
|
|
|
| 232 |
while model._has_unfinished_sequences(this_peer_finished, synced_gpus, device=input_ids.device):
|
| 233 |
-
#
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
# forward pass to get next token
|
| 237 |
outputs = model(**model_inputs, return_dict=True)
|
|
|
|
| 229 |
if lm_head is None:
|
| 230 |
raise ValueError("DoLa is not supported for models that don't have output embeddings.")
|
| 231 |
|
| 232 |
+
is_first_iteration = True
|
| 233 |
while model._has_unfinished_sequences(this_peer_finished, synced_gpus, device=input_ids.device):
|
| 234 |
+
# Transformers v5 cache protocol: prefill uses the full prompt; later cached
|
| 235 |
+
# steps use only the newest token. Uncached decoding keeps the full prefix.
|
| 236 |
+
next_sequence_length = (
|
| 237 |
+
None
|
| 238 |
+
if is_first_iteration or not model_kwargs.get("use_cache", True)
|
| 239 |
+
else 1
|
| 240 |
+
)
|
| 241 |
+
|
| 242 |
+
model_inputs = model.prepare_inputs_for_generation(
|
| 243 |
+
input_ids,
|
| 244 |
+
next_sequence_length=next_sequence_length,
|
| 245 |
+
is_first_iteration=is_first_iteration,
|
| 246 |
+
**model_kwargs,
|
| 247 |
+
)
|
| 248 |
+
|
| 249 |
+
is_first_iteration = False
|
| 250 |
|
| 251 |
# forward pass to get next token
|
| 252 |
outputs = model(**model_inputs, return_dict=True)
|