Views
No views yet
apply_chat_template to show you how to load the tokenizer and model and how to generate contents.1# Import necessary libraries
2from unsloth import FastLanguageModel
3import torch
4
5# Define the model name and other parameters
6model_name = "imsanjoykb/sqlCoder-Qwen2.5-8bit"
7max_seq_length = 2048
8dtype = None
9load_in_4bit = True
10
11# Load the model and tokenizer from Hugging Face
12model, tokenizer = FastLanguageModel.from_pretrained(
13 model_name=model_name,
14 max_seq_length=max_seq_length,
15 dtype=dtype,
16 load_in_4bit=load_in_4bit,
17)
18
19# Enable faster inference
20FastLanguageModel.for_inference(model)
21
22# Define the prompt template
23odoo_text2sql_prompt = """Below is an instruction describing a task related to generating a SQL query specifically for Odoo's database structure. The input provides relevant context about Odoo models or data fields from {db_schema}. Write a SQL query that fulfills the given task using Odoo's database schema.
24
25### Instruction:
26Generate a SQL query in the context of Odoo to {}
27
28### Input:
29{}
30
31### Response:
32{}
33"""
34
35# Optionally, use a TextStreamer for continuous inference
36from transformers import TextStreamer
37
38# Prepare the input text for continuous inference
39instruction = ""
40input_text = "What is the top profitable product?"
41output_text = ""
42
43# Tokenize the input text
44inputs = tokenizer(
45 [
46 odoo_text2sql_prompt.format(instruction, input_text, output_text)
47 ],
48 return_tensors="pt"
49).to("cuda")
50
51# Initialize the TextStreamer
52text_streamer = TextStreamer(tokenizer)
53
54# Generate the output using the model with TextStreamer
55_ = model.generate(**inputs, streamer=text_streamer, max_new_tokens=350)| Model | #Total Params | #Active Params | Context Length | Download |
|---|---|---|---|---|
| sqlCoder-Qwen2.5-8bit | 14B | 2.4B | 128k | 🤗 HuggingFace |