processor does not have a chat template
I am trying to finetune this model and got this error :
0%| | 0/507 [00:00<?, ?it/s]Traceback (most recent call last):
File "/workspace/train.py", line 304, in
trainer.train()
File "/transformers/src/transformers/trainer.py", line 2238, in train
return inner_training_loop(
File "/transformers/src/transformers/trainer.py", line 2533, in _inner_training_loop
batch_samples, num_items_in_batch = self.get_batch_samples(epoch_iterator, num_batches, args.device)
File "/transformers/src/transformers/trainer.py", line 5355, in get_batch_samples
batch_samples.append(next(epoch_iterator))
File "/usr/local/lib/python3.10/dist-packages/accelerate/data_loader.py", line 564, in iter
current_batch = next(dataloader_iter)
File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py", line 734, in next
data = self._next_data()
File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py", line 790, in _next_data
data = self._dataset_fetcher.fetch(index) # may raise StopIteration
File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py", line 55, in fetch
return self.collate_fn(data)
File "/workspace/train.py", line 243, in collate_fn
text = processor.apply_chat_template(
File "/transformers/src/transformers/utils/deprecation.py", line 172, in wrapped_func
return func(*args, **kwargs)
File "/transformers/src/transformers/processing_utils.py", line 1463, in apply_chat_template
raise ValueError(
ValueError: Cannot use apply_chat_template because this processor does not have a chat template.
0%| | 0/507 [00:00<?, ?it/s]
Hi @Prabhjot410 ,
Welcome to Google's Gemma family of open source models, thanks for bringing this to our attention. The instruction-tuned models (IT) follows a specified kind of role based chat prompt and template, if your prompt or chat template violates any of that template format the model triggers a chat template related exceptions or error. It's highly recommended to use the specified chat templates while working with instruction-tuned (IT) models.
Please find the following sample prompt format:
messages = [
{
"role": "system",
"content": [{"type": "text", "text": "You are a helpful assistant."}]
},
{
"role": "user",
"content": [
{"type": "image", "image": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg"},
{"type": "text", "text": "Describe this image in detail."}
]
}
]
inputs = processor.apply_chat_template(
messages, add_generation_prompt=True, tokenize=True,
return_dict=True, return_tensors="pt"
).to(model.device, dtype=torch.bfloat16)
Thanks.