# Error When Trying to Finetune Llama 2 Chat 13B

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ferror-when-trying-to-finetune-llama-2-chat-13b%2F57130%3E%5C
**Category:** Beginners\
**Created:** [October 2, 2023, 4:12pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ferror-when-trying-to-finetune-llama-2-chat-13b%2F57130 "2023-10-02T16:12:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jscode13](https://avatars.discourse-cdn.com/v4/letter/j/b2d939/32.png) [@jscode13](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fjscode13)%5C
**Post date:** [October 2, 2023, 4:12pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ferror-when-trying-to-finetune-llama-2-chat-13b%2F57130%2F1 "2023-10-02T16:12:34Z")

</div>

dataset = load\_dataset(dataset\_name, split=“train”)

compute\_dtype = getattr(torch, bnb\_4bit\_compute\_dtype)

bnb\_config = BitsAndBytesConfig(  
load\_in\_4bit=use\_4bit,  
bnb\_4bit\_quant\_type=bnb\_4bit\_quant\_type,  
bnb\_4bit\_compute\_dtype=compute\_dtype,  
bnb\_4bit\_use\_double\_quant=use\_nested\_quant,  
)

if compute\_dtype == torch.float16 and use\_4bit:  
major, \_ = torch.cuda.get\_device\_capability()  
if major \>= 8:  
print(“=” \* 80)  
print(“Your GPU supports bfloat16: accelerate training with bf16=True”)  
print(“=” \* 80)

model = AutoModelForCausalLM.from\_pretrained(  
model\_name,  
quantization\_config=bnb\_config,  
device\_map=device\_map  
)  
model.config.use\_cache = False  
model.config.pretraining\_tp = 1

tokenizer = AutoTokenizer.from\_pretrained(model\_name, trust\_remote\_code=True)  
tokenizer.pad\_token = tokenizer.eos\_token  
tokenizer.padding\_side = “right”

peft\_config = LoraConfig(  
lora\_alpha=lora\_alpha,  
lora\_dropout=lora\_dropout,  
r=lora\_r,  
bias=“none”,  
task\_type=“CAUSAL\_LM”,  
)

training\_arguments = TrainingArguments(  
output\_dir=output\_dir,  
num\_train\_epochs=num\_train\_epochs,  
per\_device\_train\_batch\_size=per\_device\_train\_batch\_size,  
gradient\_accumulation\_steps=gradient\_accumulation\_steps,  
optim=optim,  
save\_steps=save\_steps,  
logging\_steps=logging\_steps,  
learning\_rate=learning\_rate,  
weight\_decay=weight\_decay,  
fp16=fp16,  
bf16=bf16,  
max\_grad\_norm=max\_grad\_norm,  
max\_steps=max\_steps,  
warmup\_ratio=warmup\_ratio,  
group\_by\_length=group\_by\_length,  
lr\_scheduler\_type=lr\_scheduler\_type,  
report\_to=“tensorboard”  
)

trainer = SFTTrainer(  
model=model,  
train\_dataset=dataset,  
peft\_config=peft\_config,  
dataset\_text\_field=“text”,  
max\_seq\_length=max\_seq\_length,  
tokenizer=tokenizer,  
args=training\_arguments,  
packing=packing,  
)

trainer.train()

trainer.model.save\_pretrained(new\_model)

ValueError Traceback (most recent call last)  
 in \<cell line: 32\>()  
30  
31 # Load LLaMA tokenizer  
—\> 32 tokenizer = AutoTokenizer.from\_pretrained(model\_name, trust\_remote\_code=True)  
33 tokenizer.pad\_token = tokenizer.eos\_token  
34 tokenizer.padding\_side = “right”

4 frames  
/usr/local/lib/python3.10/dist-packages/transformers/tokenization\_utils\_fast.py in **init** (self, \*args, \*\*kwargs)  
118 fast\_tokenizer = convert\_slow\_tokenizer(slow\_tokenizer)  
119 else:  
 → 120 raise ValueError(  
121 “Couldn’t instantiate the backend tokenizer from one of: \n”  
122 “(1) a `tokenizers` library serialization file, \n”

ValueError: Couldn’t instantiate the backend tokenizer from one of:  
(1) a `tokenizers` library serialization file,  
(2) a slow tokenizer instance to convert or  
(3) an equivalent slow tokenizer class to instantiate and convert.  
You need to have sentencepiece installed to convert a slow tokenizer to a fast one.

This code worked fine with the 7B version of this model. All I did was change it to the 13B version and now I’m getting this error. Please let me know what you think is wrong. Thanks.
