Views
No views yet
1import os
2import torch
3from datasets import load_dataset, Dataset, DatasetDict
4import pandas as pd
5import numpy as np
6import json
7from transformers import (
8 AutoModelForCausalLM,
9 AutoTokenizer,
10 BitsAndBytesConfig,
11 TrainingArguments,
12 pipeline
13)
14
15merged_model_id = 'jeromecondere/merged-llama-v3-for-bank'
16
17merged_model = AutoModelForCausalLM.from_pretrained(
18 merged_model_id,
19 torch_dtype=torch.bfloat16,
20 device_map= "cuda"
21)
22tokenizer = AutoTokenizer.from_pretrained(merged_model_id, use_fast=True)
23
24name = 'Yalat Sensei'
25company = 'Google Corp.'
26stock_value = 42.24
27messages = [
28 {'role': 'system', 'content': f'Hi {name}, I\'m your assistant how can I help you\n'},
29 {"role": "user", "content": f"I'd like to buy stocks worth {stock_value:.2f} in {company}.\n"},
30 {"role": "system", "content": f"Sure, we have purchased stocks worth ###StockValue({stock_value:.2f}) in ###Company({company}) for you.\n"},
31 {"role": "user", "content": f"Now I want to see my balance, hurry up!\n"},
32 {"role": "system", "content": f"Sure, here's your balance ###Balance\n"},
33 {"role": "user", "content": f"Again, my balance?\n"},
34 {"role": "system", "content": f"We have your account details. Your balance is: ###Balance"},
35 {"role": "user", "content": f"Okay now, I want my list of stocks"}
36
37]
38# prepare the messages for the model
39input_ids = tokenizer.apply_chat_template(messages, truncation=True, add_generation_prompt=True, return_tensors="pt").to("cuda")
40
41# inference
42outputs = merged_model.generate(
43 input_ids=input_ids,
44 max_new_tokens=120,
45 #do_sample=True,
46 temperature=0.5,
47 top_k=50,
48 top_p=0.95
49)
50print(tokenizer.batch_decode(outputs)[0])