All benchmarks

  Company blog

A fine-tuned Llama-2 7B wrote correct SQL more often than GPT-4 (Anyscale, 2023)

Made by Kourosh Hakhamaneshi and Rehaan Ahmad

On the Anyscale blog

The result

  • Quality

    SQL accuracy: the generated query returns the same result as the reference query on a small test table. Small model: Llama-2-7B, fully fine-tuned. Large model: GPT-4.

    86%vs 79%

    Ahead by 7 points

    Llama-2 7B, fine-tuned86%
    GPT-479%

    SQL accuracy · higher is better

The story

Is GPT-4 more than the job needs?

In August 2023 Anyscale, which sells fine-tuning and model serving built on Ray, tested a claim: general models like GPT-4 are often more than a narrow business task needs. Its engineers fine-tuned Meta’s open Llama-2 models on three tasks and compared them with GPT-4. This case is about one of them, writing SQL.

The model gets a question in plain English plus the CREATE TABLE statements for the tables involved, and has to write the SQL query that answers it.

Fixing the data first

Data

b-mc2/sql-create-context

78,577 examples; about 45,000 after filtering

Built from the WikiSQL and Spider datasets, on Hugging Face

Queries that treated text columns as numbers were dropped; the blog says this cut the data from 70k to 45k points.

The public dataset had a flaw: many reference queries treated columns declared as text as if they held numbers. The SQL engine used for testing couldn’t check types, so the authors dropped every query that assumed an integer, leaving about 45,000 examples.

Small model

Llama-2-7B

7B · Meta (base model); fine-tuned by Anyscale

Full-parameter fine-tune

Base
meta-llama/Llama-2-7b-hf (the base model, not the chat version)
meta-llama/Llama-2-7b-hf

Training

16x NVIDIA A10G GPUs
Method
Full-parameter fine-tune with Ray Train and DeepSpeed ZeRO stage 3 (optimizer state offloaded to CPU); up to 10 epochs, keeping the checkpoint with the lowest validation perplexity

Not reported: time and cost.

Every weight of the model was trained, not an adapter, on 16 NVIDIA A10G GPUs. Instead of a long instruction, each example was wrapped in a few special tokens, so the tuned model needs no prompt beyond the question and the tables.

Grading by running the query

Comparing SQL text character by character would mark correct but differently written queries as wrong. So the team had GPT-3.5 write a small ten-row table for a few hundred examples, ran both the reference query and the model’s query on it, and compared the results. Tables on which the reference query returned nothing, or the whole table, were thrown out: about half of them.

Evaluation

Test set
A few hundred dataset examples, each with a ten-row table written by GPT-3.5; about half were dropped
Metric
Share of generated queries that return the same result as the reference query on the test table
Items
Not reported exactly
How it was compared
Same tables and check for all models. GPT-4 got the same task prompt as the Llama chat models; its snapshot and temperature are not stated.

Large model

GPT-4

Size not disclosed · OpenAI

Used as released, prompted with the task instructions

Base
OpenAI API (snapshot not stated)

Before fine-tuning, the 7B Llama-2 chat model, given the same prompt, got 3% of the queries right. Fine-tuned, the 7B base model got 86%, ahead of GPT-4 at 79% and of Llama-2-70B-chat. The blog adds that some questions in the dataset are not in good English, which it says likely cost GPT-4 a little, while tuned models pick up such quirks. On grade-school math (GSM8k), another task in the study, fine-tuning helped but GPT-4 stayed ahead.

All the numbers

Show all numbersHide all numbersEvery model · Cost, latency and energy · 4 more results

Every model on the headline test

Cost, latency and energy, as reported

Cost
Not reported
Latency
Not reported
Not measured. The blog notes the Llama chat models often added hundreds of unneeded tokens, which slowed them down.
Energy
Not reported

More from the source

  • Llama-2-7B before fine-tuning, SQL

    Small model 3Large model 79 %

    Same test: the gain comes from fine-tuning.

    Nishihara’s post on X

  • Llama-2-13B after fine-tuning, SQL

    Small model 89Large model 79 %

    The blog’s 42% starting point for 13B does not match its own chart, where the 13B chat bar is much lower.

    Blog introduction (13B: 42% to 89% on SQL); GPT-4 from Nishihara’s post

  • Turning a sentence into a structured ‘functional representation’ (ViGGO), Llama-2-13B before and after fine-tuning

    58 to 98 %

    GPT-4’s ViGGO score is only drawn in charts without values. The blog says the fine-tuned models stay above 90% whether or not the required attribute order is checked, while GPT-4’s accuracy drops sharply when it is.

    Blog introduction; ViGGO results

  • Where the large model wins: GSM8k math, Llama-2-13B before and after fine-tuning

    28 to 47 %

    The blog says fine-tuned models improve but still don’t reach GPT-4 on math reasoning. GPT-4’s GSM8k value is only drawn in a chart.

    Blog introduction; GSM8k section

Worth knowing

  • Vendor marketing post: Anyscale sells the fine-tuning platform it used, and ran every model itself.
  • Small test set: a few hundred examples before about half were discarded, with test tables generated by GPT-3.5.
  • The fine-tuned model was trained on the same dataset it was tested on (held-out items), while GPT-4 was prompted without examples of the dataset’s quirks.
  • 2023 models: the GPT-4 snapshot is not stated, and today’s general models are stronger.
2 more caveats
  • The blog’s charts have no value labels. The exact 7B and GPT-4 numbers (3%, 79%, 86%) come from a post on X, not from the blog text; they agree with the blog’s charts.
  • Fine-tuned weights were not published.

Weights on Hugging Face

Base model on Hugging Face

Base model only (gated, Llama 2 licence). Anyscale’s fine-tuned checkpoints were not found on Hugging Face (no repos under ‘anyscale’, checked 3 Oct 2026).

Sources

  1. Kourosh Hakhamaneshi and Rehaan Ahmad, ‘Fine-Tuning Llama-2: A Comprehensive Case Study for Tailoring Models to Unique Applications’, Anyscale blog, 11 Aug 2023
  2. Robert Nishihara, post on X with the exact SQL numbers, 11 Aug 2023
  3. b-mc2/sql-create-context dataset (Hugging Face)
  4. Anyscale blog post by Kourosh Hakhamaneshi and Rehaan Ahmad, 11 Aug 2023. Robert Nishihara’s post with the exact numbers is from the same day.
Share this benchmark

Drawing the image…

Post text