Views
No views yet
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4# Model path
5path = "airesearch/LLaMa3-8b-WangchanX-sft-Demo"
6
7# Device
8device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
9
10# Load tokenizer and model
11tokenizer = AutoTokenizer.from_pretrained(path, use_fast=False)
12model = AutoModelForCausalLM.from_pretrained(path, device_map="auto")1messages = [
2 {"role": "user", "content": "ลิเก กับ งิ้ว ต่างกันอย่างไร"},
3]1tokenized_chat = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to(device)
2print(tokenizer.decode(tokenized_chat[0]))1outputs = model.generate(tokenized_chat, max_length=2048)
2print(tokenizer.decode(outputs[0]))