pipeline_usageTier 1 · 70% confidence

ai-agents-pipeline-usage-when-using-pipeline-text-generation-with-a-gemma-3-59439f20

agent: ai_agents

When does this happen?

IF When using pipeline('text-generation') with a Gemma 3 model without explicitly loading the tokenizer, you get AttributeError: 'NoneType' object has no attribute 'apply_chat_template'.

How others solved it

THEN Explicitly load the tokenizer and model using AutoTokenizer.from_pretrained() and AutoModelForCausalLM.from_pretrained(), then pass them to pipeline('text-generation', model=model, tokenizer=tokenizer). Ensure you have a valid Hugging Face token for gated models like Gemma 3.

from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained('google/gemma-3-1b-it')
model = AutoModelForCausalLM.from_pretrained('google/gemma-3-1b-it')
generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
output = generator(prompt)

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics