#2034·outlines

outlines with gemma4 output wrong answer

Author: chaowenguoCreated Sep 14, 2026Updated Sep 14, 2026
Labelsbug

Describe the issue as clearly as possible:

I use bitsandbytes to create q4 version of gemma4 and run in kaggle T4 x 2

python3
!python3 -m pip install -U transformers bitsandbytes outlines
import huggingface_hub, transformers, torch, outlines, builtins
huggingface_hub.snapshot_download(repo_id='exact-railcar/gemma', local_dir='/tmp/kaggle')
processor = transformers.Gemma4Processor.from_pretrained('/tmp/kaggle')
model = transformers.Gemma4ForConditionalGeneration.from_pretrained('/tmp/kaggle', device_map='auto', dtype=torch.bfloat16)
messages = [
    {"role": "user", "content": "What is 1 + 1"},
]

# Process input
inputs = processor.apply_chat_template(
    messages,
    tokenize=True,
    return_dict=True,
    return_tensors="pt",
    add_generation_prompt=True,
    enable_thinking=True
).to(model.device)
input_len = inputs["input_ids"].shape[-1]

# Generate output
outputs = model.generate(**inputs, max_new_tokens=1024)
response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)

# Parse output
processor.parse_response(response, prefix=inputs["input_ids"])

the output is:

{'role': 'assistant',
 'thinking': 'The user is asking for the sum of 1 and 1.\nBasic arithmetic. $1 + 1 = 2$.',
 'content': '1 + 1 = 2'}

which is correct

Now I use outline to run

python3
model = outlines.from_transformers(transformers.Gemma4ForConditionalGeneration.from_pretrained('/tmp/kaggle', device_map='auto', dtype=torch.bfloat16), transformers.Gemma4Processor.from_pretrained('/tmp/kaggle'))
model(outlines.inputs.Chat([{"role": "user", "content": "What is 1 + 1"}]), output_type=builtins.int, temperature=0.1, max_new_tokens=1024)

the output is a list of 1, that is '1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'

Steps/code to reproduce the bug:

python
see above

Expected result:

bash
just 2

Error message:

bash

Outlines/Python version information:

Version information outlines-1.3.3 python3.12

Context for the issue:

it make everything not working