Instructions to use ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4 with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4", dtype="auto") - llama-cpp-python
How to use ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4 with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4", filename="unsloth.F16.gguf", )
output = llm( "Once upon a time,", max_tokens=512, echo=True ) print(output)
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- llama.cpp
How to use ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4 with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4:F16 # Run inference directly in the terminal: llama-cli -hf ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4:F16
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4:F16 # Run inference directly in the terminal: llama-cli -hf ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4:F16
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4:F16 # Run inference directly in the terminal: ./llama-cli -hf ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4:F16
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4:F16 # Run inference directly in the terminal: ./build/bin/llama-cli -hf ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4:F16
Use Docker
docker model run hf.co/ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4:F16
- LM Studio
- Jan
- Ollama
How to use ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4 with Ollama:
ollama run hf.co/ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4:F16
- Unsloth Studio new
How to use ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4 with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4 to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4 to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4 to start chatting
- Docker Model Runner
How to use ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4 with Docker Model Runner:
docker model run hf.co/ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4:F16
- Lemonade
How to use ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4 with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4:F16
Run and chat with the model
lemonade run user.Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4-F16
List all available models
lemonade list
Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4
This model is a fine-tuned version of ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL for Text-to-SQL generation. It is designed to convert natural language queries into SQL commands, optimized for efficient inference using GGUF (Grouped Quantization for Uniform Format).
Model Details
- Base Model: ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL
- Task: Text-to-SQL generation
- Quantization: GGUF (Q4, 4-bit quantization)
- License: Apache-2.0
Installation
To use this model, you need to install llama-cpp-python and huggingface_hub for downloading and running the quantized model.
Step 1: Install Required Packages
# Install llama-cpp-python from the appropriate repository
!pip install llama-cpp-python \
--extra-index-url https://abetlen.github.io/llama-cpp-python/whl/12.1 \
--force-reinstall --upgrade --no-cache-dir --verbose
# Install huggingface_hub to download models from Hugging Face
!pip install huggingface_hub hf_transfer
Step 2: Set up Hugging Face Hub and Download the Model
Ensure that Hugging Face's transfer feature is enabled and download the quantized model from Hugging Face using the huggingface-cli.
import os
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
!huggingface-cli download \
ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4 \
unsloth.Q4_K_M.gguf \
--local-dir . \
--local-dir-use-symlinks False
Make sure the downloaded model is stored in the local directory. Set the model path as follows:
MODEL_PATH = "/content/unsloth.Q4_K_M.gguf"
Usage Example
Here is an example that demonstrates how to generate an SQL query from a natural language prompt using the quantized GGUF model and the llama_cpp library.
Step 1: Define the User Query and Prompt
The user provides a natural language query, and we format the prompt using an Alpaca-style template.
user_query = "Seleziona tutte le colonne della tabella table1 dove la colonna anni è uguale a 2020"
alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
### Instruction:
{}
### Input:
{}
### Response:
"""
prompt = alpaca_prompt.format(
"Provide the SQL query",
user_query
)
Step 2: Load the Model and Generate SQL Query
To load the quantized model and perform inference, you will need the llama_cpp library.
from llama_cpp import Llama
import os
# Get the current directory
current_directory = os.getcwd()
# Construct the full model path
MODEL_PATH = os.path.join(current_directory, "unsloth.Q4_K_M.gguf")
# Ensure the model path exists
assert os.path.exists(MODEL_PATH), f"Model path {MODEL_PATH} does not exist."
# Create the prompt for SQL query generation
B_INST, E_INST = "<s>[INST]", "[/INST]"
B_SYS, E_SYS = "<<SYS>>\n", "\n<</SYS>>\n\n"
DEFAULT_SYSTEM_PROMPT = """\
Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
"""
SYSTEM_PROMPT = B_SYS + DEFAULT_SYSTEM_PROMPT + E_SYS
def create_prompt(user_query):
instruction = f"Provide the SQL query. User asks: {user_query}\n"
prompt = B_INST + SYSTEM_PROMPT + instruction + E_INST
return prompt.strip()
# Define user query
user_query = "Seleziona tutte le colonne della tabella table1 dove la colonna anni è uguale a 2020"
prompt = create_prompt(user_query)
print(f"Prompt created:\n{prompt}")
# Load the model
try:
llm = Llama(model_path=MODEL_PATH, n_gpu_layers=1) # Adjust GPU layers as per your hardware
except AssertionError as e:
raise RuntimeError(f"Failed to load the model. Check that the model is in the correct format: {e}")
# Perform inference
try:
result = llm(
prompt=prompt,
max_tokens=200,
echo=False
)
print(result['choices'][0]['text'])
except Exception as e:
print(f"Error during inference: {e}")
Expected Output
The model will return the following SQL query:
SELECT * FROM table1 WHERE anni = 2020
Additional Notes
- Quantization: The model is quantized using GGUF to enable efficient inference, especially on systems with limited memory.
- Prompt: The prompt follows an Alpaca instruction style, which helps guide the model in generating SQL queries based on user input.
- Inference: The
llama_cpplibrary is used to perform inference with this GGUF model. Adjustn_gpu_layersandmax_tokensbased on your hardware capabilities and the complexity of the SQL query.
License
This model is released under the Apache-2.0 license.
For more detailed information, visit the model card on Hugging Face.
- Downloads last month
- 111
4-bit
16-bit
Model tree for ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL-GGUF-q4
Base model
ruslanmv/Meta-Llama-3.1-8B-Text-to-SQL