Downloads · 30 days
2
15% of all-time downloads
Shreyasrp/texttosql
texttosql is a machine learning model from Shreyasrp. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for peft.
The following bitsandbytes quantization config was used during training: - quantmethod: bitsandbytes - loadin8bit: False - loadin4bit: True - llmint8threshold: 6.0 - llmint8skipmodules: None - llmint8enablefp32cpuoffl…
Downloads · 30 days
2
15% of all-time downloads
All-time downloads
13
Public
Repo size
33.6 MB
Likes
0
Public
Click a slice to open those files.
.bin16.8 MB · 100%
From the Hugging Face model README
The following bitsandbytes quantization config was used during training:
The following bitsandbytes quantization config was used during training:
PEFT 0.5.0
PEFT 0.5.0
!pip install transformers peft
from huggingface_hub import login
token = "Your Key"
login(token)
from peft import PeftModel, PeftConfig
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
from transformers import BitsAndBytesConfig
from peft import prepare_model_for_kbit_training
config = PeftConfig.from_pretrained("Shreyas45/Llama2_Text-to-SQL_Fintuned")
peft_model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b-hf")
peft_model = PeftModel.from_pretrained(peft_model, "Shreyas45/Llama2_Text-to-SQL_Fintuned")
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import prepare_model_for_kbit_training
trained_model_tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path, trust_remote_code=True)
trained_model_tokenizer.pad_token = trained_model_tokenizer.eos_token
query = '''In the table named management with columns (department_id VARCHAR, temporary_acting VARCHAR);
CREATE TABLE department (name VARCHAR, num_employees VARCHAR, department_id VARCHAR),
Show the name and number of employees for the departments managed by heads whose temporary acting value is 'Yes'?'''
prompt = f'''### Instruction: Below is an instruction that describes a task and the schema of the table in the database.
Write a response that generates a request in the form of a SQL query.
Here the schema of the table is mentioned first followed by the question for which the query needs to be generated.
And the question is: {query}
###Output: '''
encodings = trained_model_tokenizer(prompt, return_tensors='pt')
generation_config = peft_model.generation_config
generation_config.max_new_token = 1024
generation_config.temperature = 0.7
generation_config.top_p = 0.7
generation_config.num_return_sequence = 1
generation_config.pad_token_id = trained_model_tokenizer.pad_token_id
generation_config.eos_token_id = trained_model_tokenizer.eos_token_id
with torch.inference_mode():
outputs = peft_model.generate(
input_ids=encodings.input_ids,
attention_mask=encodings.attention_mask,
generation_config=generation_config,
max_new_tokens=100
)
generated_query = trained_model_tokenizer.decode(outputs[0])
print("Generated SQL Query:")
print(generated_query)