Views
No views yet
1from unsloth import FastLanguageModel
2from unsloth import FastLanguageModel
3import torch
4max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally!
5dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
6load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.
7model, tokenizer = FastLanguageModel.from_pretrained(
8 model_name = "surajgorai/llama_3_8b_text_to_sql_model", # YOUR MODEL YOU USED FOR TRAINING
9 max_seq_length = max_seq_length,
10 dtype = dtype,
11 load_in_4bit = load_in_4bit,
12)
13FastLanguageModel.for_inference(model) # Enable native 2x faster inference
14
15prompt = """You are a powerful text-to-SQL model. Your job is to answer questions about a database. You are given a question and context regarding one or more tables.
16
17You must output the SQL query that answers the question.
18
19### Instruction:
20{}
21
22### Input:
23{}
24
25### Response:
26{}"""
27
28# alpaca_prompt = You MUST copy from above!
29inputs = tokenizer(
30[
31 prompt.format(
32 'Name the result/games for 54741', # instruction
33 'CREATE TABLE table_21436373_11 (result_games VARCHAR, attendance VARCHAR)', # input
34 "", # output - leave this blank for generation!
35 )
36], return_tensors = "pt").to("cuda")
37
38outputs = model.generate(**inputs, max_new_tokens = 64, use_cache = True)
39tokenizer.batch_decode(outputs)
40
41#response :
42#['You are a powerful text-to-SQL model. Your job is to answer questions about a database. You are given a question and context regarding one or more tables.
43#\n\nYou must output the SQL query that answers the question.\n\n### Instruction:\nName the result/games for 54741\n\n### Input:\nCREATE TABLE table_21436373_11 (result_games VARCHAR, attendance VARCHAR)
44#\n\n### Response:\nSELECT result_games FROM table_21436373_11 WHERE attendance = "54741"<|end_of_text|>']
45
46from transformers import TextStreamer
47text_streamer = TextStreamer(tokenizer)
48_ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 128)
49
50#response
51#You are a powerful text-to-SQL model. Your job is to answer questions about a database. You are given a question and context regarding one or more tables.
52#You must output the SQL query that answers the question.
53### Instruction:
54#Name the result/games for 54741
55### Input:
56#CREATE TABLE table_21436373_11 (result_games VARCHAR, attendance VARCHAR)
57## Response:
58#SELECT result_games FROM table_21436373_11 WHERE attendance = "54741"<|end_of_text|>