A fine-tuned LLaMA-7B wrote ML API calls more accurately than GPT-4 (Gorilla)
Made by Shishir G. Patil and three co-authors
The result
The story
One line of code
Machine-learning developers often need a single line: the call that loads the right pre-trained model from a hub such as TorchHub, TensorFlow Hub or Hugging Face, with the right arguments. Researchers at UC Berkeley and Microsoft Research report that prompted chat models of 2023, GPT-4 included, often invented model names or called the wrong API. Their answer was Gorilla, LLaMA-7B fine-tuned to turn a plain-English request into that one call.

Training data written by GPT-4
The authors turned 1,645 model cards from the three hubs into JSON records and had GPT-4 write ten requests for each, guided by examples written by hand. The requests were then split into training and test sets. A test request is new wording, but on TorchHub the API it asks for had always been seen in training: in the released files, all 78 APIs behind the 186 test requests also appear among the 837 training requests.
Data
APIBench
1,645 API calls (94 TorchHub, 626 TensorFlow Hub v2, 925 Hugging Face) and 16,450 request-call pairs; the TorchHub test has 186 requests
Model cards from the three hubs turned into JSON records; GPT-4 wrote 10 requests per API from 18 hand-written examples
TorchHub and TensorFlow Hub split 80/20 and Hugging Face 90/10 by request; public on GitHub and Hugging Face
Small model
Gorilla 7B (TorchHub)
7B · UC Berkeley (Gorilla project)
Full instruction fine-tune on its hub’s request-call pairs, without documentation in the prompt; one model per hub
- Base
- LLaMA-7B (base model, Meta)
Training
Full instruction fine-tune, one user turn and one answer per pair
A separate model per hub
- Time
- Not reported; 5 epochs, learning rate 2e-5 with cosine decay, batch size 64, max length 2,048
Not reported: cost.
How the answers were graded
The baselines were GPT-4 (gpt-4-0314), GPT-3.5, Claude and the plain LLaMA-7B; in the headline setting none of them gets documentation in the prompt. The script the authors released a day after the preprint sends GPT-4 the request with an instruction to answer in one or two lines, an answer format and the list of allowed domains, at temperature 0. Each answer is parsed into a syntax tree and matched against the hub’s documented calls; a call that matches no documented API counts as a hallucination. On 100 of Gorilla’s answers checked by hand, the matching and the people both found 78% correct.
Large model
GPT-4 (gpt-4-0314)
Size not disclosed · OpenAI
Used as released through the OpenAI API, zero-shot: the request plus format rules and the list of domains, temperature 0
- Base
- General model
Evaluation
186 requests (TorchHub)
- Test set
- APIBench TorchHub test split (headline); TensorFlow Hub and Hugging Face were scored with their own Gorilla models
- Metric
- Overall accuracy by AST sub-tree match, plus hallucination and error rates
- How it was compared
- Same 186 requests and the same AST script for every model on TorchHub; GPT-4 got more instructions than Gorilla. On Hugging Face, every model except Gorilla was only checked for the right domain name.
What came out
On TorchHub, with no documentation, Gorilla got 59.13% of calls right against GPT-4’s 38.70% (GPT-3.5 did better than GPT-4, at 48.38%), and GPT-4 called an API that doesn’t exist in 36.55% of answers against Gorilla’s 6.98%. The gaps on TensorFlow Hub and Hugging Face were wider, though Hugging Face graded the baselines more loosely. With the right documentation pasted into the prompt the gap almost closes: 67.20% against 66.12% on TorchHub. The NeurIPS version adds a table in which GPT-4 with three examples ties Gorilla on TorchHub at 75.80%, with zero-shot scores that differ from the main table; the paper doesn’t explain the difference. Each experiment was run once, and no cost or latency is reported.
All the numbers
Show all numbersHide all numbersEvery model · Cost, latency and energy · 7 more results
Every model on the headline test
Cost, latency and energy, as reported
- Cost
- Not reported
- Latency
- Not reported
- Energy
- Not reported
More from the source
Overall accuracy, TensorFlow Hub, zero-shot
Small model 83.79Large model 18.2 %
Table 1
Overall accuracy, Hugging Face, zero-shot
Small model 71.68Large model 19.8 %
On Hugging Face the paper grades the baselines more leniently than Gorilla: for every model except Gorilla it only checks the domain name (Section 4.1).
Table 1
Hallucination rate, TorchHub, zero-shot
Small model 6.98Large model 36.55 %
Table 1
Hallucination rate, Hugging Face, zero-shot
Small model 10.95Large model 37.16 %
Table 1
Hallucination rate, TensorFlow Hub, zero-shot
Small model 5.4Large model 78.65 %
Table 1
Overall accuracy with the correct documentation given (oracle retriever): TorchHub / Hugging Face / TensorFlow Hub
Small model 67.20 / 91.26 / 94.16Large model 66.12 / 85.07 / 55.91 %
With the oracle retriever GPT-3.5 scores 66.31 / 89.71 / 95.03, so on TensorFlow Hub GPT-3.5 edges out Gorilla in this setting.
Table 1, ‘(Oracle)’ rows
Other zero-shot baselines on TorchHub: GPT-3.5 / Claude (claude-v1) / LLaMA-7B
Small model 59.13Large model 48.38 / 18.81 / 0 %
Table 1
Worth knowing
- The baselines are from 2023 (gpt-4-0314, gpt-3.5-turbo-0301, claude-v1).
- Training and test requests both come from the same GPT-4-written pool, so the test is in-distribution for Gorilla; GPT-4 sees these hubs’ APIs only through what it already knows (or through retrieved documents in the retriever settings).
- With the correct documentation in the prompt (oracle retriever) the gap mostly closes, and GPT-3.5 slightly beats Gorilla on TensorFlow Hub (95.03 vs 94.16).
- Gorilla’s training data was written by GPT-4, the model it is compared against.
2 more caveats
- On Hugging Face the baselines are graded more leniently than Gorilla (domain name only).
- Single run, no error bars.
Weights on Hugging Face
The released v0 checkpoints are per-hub delta weights on top of LLaMA-7B (th = TorchHub, hf = Hugging Face, tf = TensorFlow Hub). The paper does not say which released checkpoint produced Table 1.
Sources
- Patil, Zhang, Wang, Gonzalez, ‘Gorilla: Large Language Model Connected with Massive APIs’, NeurIPS 2024 (proceedings page)
- Same paper, arXiv 2305.15334 (v1, 24 May 2023)
- Gorilla project page
- Gorilla code and data (GitHub)
- arXiv v1, 24 May 2023. Published at NeurIPS 2024 (38th conference); the Table 1 numbers are the same in both versions.