Views
No views yet
1from peft import PeftModel, PeftConfig
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_name = "TheBloke/Mistral-7B-Instruct-v0.2-GPTQ"
5model = AutoModelForCausalLM.from_pretrained(model_name,
6 device_map="auto",
7 trust_remote_code=False,
8 revision="main")
9
10config = PeftConfig.from_pretrained("saanvi-bot/jayson")
11model = PeftModel.from_pretrained(model, "saanvi-bot/jayson")
12
13# load tokenizer
14tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)
15
16comment = " <your text data> "
17
18intstructions_string = f"""convert into json format \n"""
19prompt_template = lambda comment: f'''[INST] {intstructions_string} \n{comment} \n[/INST]'''
20prompt = prompt_template(comment)
21
22model.eval()
23
24inputs = tokenizer(prompt, return_tensors="pt")
25outputs = model.generate(input_ids=inputs["input_ids"].to("cuda"), max_new_tokens=512)
26
27print(tokenizer.batch_decode(outputs)[0])
28| Training Loss | Epoch | Step | Validation Loss |
|---|---|---|---|
| 0.9042 | 0.9231 | 3 | 0.7967 |
| 0.8196 | 1.8462 | 6 | 0.7345 |
| 0.7337 | 2.7692 | 9 | 0.6936 |
| 0.5122 | 4.0 | 13 | 0.6707 |
| 0.6736 | 4.9231 | 16 | 0.6567 |
| 0.6092 | 5.8462 | 19 | 0.6438 |
| 0.6016 | 6.7692 | 22 | 0.6356 |
| 0.4497 | 8.0 | 26 | 0.6303 |
| 0.5784 | 8.9231 | 29 | 0.6285 |
| 0.3899 | 9.2308 | 30 | 0.6283 |