Views
No views yet
1from transformers import AutoTokenizer
2from peft import AutoPeftModelForCausalLM
3import torch
4
5model_id = "argilla/Mistral-7B-v0.1-chat-OIG"
6model = AutoPeftModelForCausalLM.from_pretrained(
7 model_id,
8 torch_dtype=torch.bfloat16,
9 device_map="auto",
10)
11tokenizer = AutoTokenizer.from_pretrained(model_id)
12tokenizer.pad_token_id = tokenizer.eos_token_id
13text = "<human>: What were Nelson Mandela's relations with the ANC? <bot>:"
14inputs = tokenizer(text, return_tensors="pt").to(model.device)
15
16with torch.no_grad():
17 outputs = model.generate(input_ids=inputs["input_ids"], max_new_tokens=250, pad_token_id=tokenizer.pad_token_id)
18print(tokenizer.batch_decode(outputs, skip_special_tokens=False)[0])<s><human>: {prompt} <bot>: Background: {background} <s><human>: {prompt} <bot>: <s><human>: {prompt_1} <bot>: {response_1}</s><s><human>: {prompt_2} <bot>: {response_2}</s><s><human>: {prompt_3} <bot>: Background: {background} <s><human>: {prompt_1} <bot>: {response_1}</s><s><human>: {prompt_2} <bot>: {response_2}</s><s><human>: {prompt_3} <bot>: