LLM Fine-tuning Use Case

Code Generation

Manually writing clean, error-free code can be challenging and time-consuming. Fortunately, large language models (LLMs) can help developers accelerate their coding tasks by translating natural language expressions into code. In this example use case, learn how to fine-tune an open-source LLM to automatically generate high-quality SQL queries.

The Predibase Solution

Generate high quality SQL with LLMs

  • Fine-tune a small language model (Llama-3-8B-Instruct) with high-quality synthetic data
  • Instantly deploy and query your SQL Copilot on a serverless endpoint
  • Save developers hours by automating the creation of SQL queries, which can be readily executed in your database

Inputs

Context: function parameters, table create statements, etc.
Task Types (e.g., reporting, arithmetic, code gen)
User Questions (e.g., “What is the total number of electric vehicle sales in each country?”)
Code Generation with LLMs

Business Value

Reduce the time and effort of writing Python, SQL, etc.
Improve code quality by reducing human error
Enable teams to focus on application logic, rather than perfecting syntax

Fine-tune and Serve your Own LLM for SQL Code Generation

Easily and efficiently fine-tune open-source Meta-Llama-3-8B-Instruct to generate high-quality SQL queries. Instantly serve and prompt your fine-tuned LLM for SQL code generation cost-effectively with endpoints built on top of open-source LoRAX. Read the full tutorial.

# Create the adapter repository
repo = pb.repos.create(
    name="synthetic_text_to_sql_llama-3-8b-instruct", 
    description="Fine-tuning on text-to-SQL synthetic dataset with Predibase.")
)

# Kick off the fine-tuning job
adapter: FinetuningJob = pb.finetuning.jobs.create(
    config={
        "base_model": base_model_id,
        "epochs": 5,
        "learning_rate": 0.0002,
    },
    dataset=dataset,
    repo="synthetic_text_to_sql_llama-3-8b-instruct",
    description='fine-tune "llama-3-8b-instruct" with text-to-SQL synthetic dataset',
)

# Dynamically load fine-tuned adapter for inference
client.generate(
    control_prompt,
    # adapter version 1 is used (corresponds to the number of fine-tuning run)
    adapter_id="synthetic_text_to_sql_llama-3-8b-instruct/1",
    max_new_tokens=256,
).generated_text

Example code in Predibase

Ready to efficiently fine-tune and serve your own LLM?