Views
No views yet
N time with different parameter valuesstring, number, boolean, list, tuple, dict parameter datatypes and Any for those not natively supported.byte, short, int, float, double, long, boolean, char, Array, ArrayList, Set, HashMap, Hashtable, Queue, Stack, and Any datatypes.String, Number, Bigint, Boolean, dict (object), Array, Date, and Any datatypes.| Model | Overall Accuracy* |
|---|---|
| GPT-4-0125-Preview | 85.12% |
| Gorilla-OpenFunctions-v2 | 83.67% |
| GPT-3.5-turbo | 82.23% |
| --quantized 🦍 models ⬇-- | --quantized 🦍 evaluation result ⬇-- |
| Gorilla-OpenFunctions-v2-q6_K | 80.30% |
| Gorilla-OpenFunctions-v2-q5_K_M | 80.66% |
| Gorilla-OpenFunctions-v2-q5_K_S | 79.10% |
| Gorilla-OpenFunctions-v2-q4_K_M | 81.02% |
| Gorilla-OpenFunctions-v2-q4_K_S | 79.94% |
| Gorilla-OpenFunctions-v2-q3_K_L | 80.84% |
| Gorilla-OpenFunctions-v2-q3_K_M | 78.80% |
| Gorilla-OpenFunctions-v2-q3_K_S | 78.67% |
| Gorilla-OpenFunctions-v2-q2_K | 74.64% |
| *: Overall Accuracy is defined in Berkeley Function Calling Leaderboard blog, read more details if you are interested! |

huggingface-cli. To download huggingface-cli please follow tutorials in https://huggingface.co/docs/huggingface_hub/main/en/guides/cli.{QUANTIZATION_METHOD} with one of your chosen quantization method)huggingface-cli download gorilla-llm/gorilla-openfunctions-v2-gguf gorilla-openfunctions-v2-{QUANTIZATION_METHOD}.gguf --local-dir gorilla-openfunctions-v2-GGUFgorilla-openfunctions-v2-GGUF.q2_K, q3_K_S, q3_K_M, q3_K_L, q4_K_S, q4_K_M, q5_K_S, q5_K_M, q6_K}.
Please let us know what other quantization methods you would like us to include!llama-cpp-python package installation on your machine.YOUR_DIRECTORY in this code snippet. This script is adapted from https://github.com/abetlen/llama-cpp-python and https://github.com/ShishirPatil/gorilla/tree/main/openfunctions1from llama_cpp import Llama
2import json
3
4llm = Llama(model_path="YOUR_DIRECTORY/gorilla-openfunctions-v2-GGUF/gorilla-openfunctions-v2-q2_K.gguf", n_threads=8, n_gpu_layers=35)
5
6def get_prompt(user_query: str, functions: list = []) -> str:
7 """
8 Generates a conversation prompt based on the user's query and a list of functions.
9
10 Parameters:
11 - user_query (str): The user's query.
12 - functions (list): A list of functions to include in the prompt.
13
14 Returns:
15 - str: The formatted conversation prompt.
16 """
17 system = "You are an AI programming assistant, utilizing the Gorilla LLM model, developed by Gorilla LLM, and you only answer questions related to computer science. For politically sensitive questions, security and privacy issues, and other non-computer science questions, you will refuse to answer."
18 if len(functions) == 0:
19 return f"{system}\n### Instruction: <<question>> {user_query}\n### Response: "
20 functions_string = json.dumps(functions)
21 return f"{system}\n### Instruction: <<function>>{functions_string}\n<<question>>{user_query}\n### Response: "
22
23query = "What's the weather like in the two cities of Boston and San Francisco?"
24functions = [
25 {
26 "name": "get_current_weather",
27 "description": "Get the current weather in a given location",
28 "parameters": {
29 "type": "object",
30 "properties": {
31 "location": {
32 "type": "string",
33 "description": "The city and state, e.g. San Francisco, CA",
34 },
35 "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
36 },
37 "required": ["location"],
38 },
39 }
40]
41
42user_prompt = get_prompt(query, functions)
43
44output = llm(user_prompt,
45 max_tokens=512, # Generate up to 512 tokens
46 stop=["<|EOT|>"],
47 echo=True # Whether to echo the prompt
48)
49
50print("Output: ", output)1❯ python quantized_inference.py
2llama_model_loader: loaded meta data with 22 key-value pairs and 273 tensors from /Users/charliecheng-jieji/Downloads/codebase/quantized_eval/gorilla-openfunctions-v2-GGUF/gorilla-openfunctions-v2-q2_K.gguf (version GGUF V3 (latest))
3llama_model_loader: Dumping metadata keys/values. Note: KV overrides do not apply in this output.
4llama_model_loader: - kv 0: general.architecture str = llama
5llama_model_loader: - kv 1: general.name str = LLaMA v2
6llama_model_loader: - kv 2: llama.context_length u32 = 4096
7llama_model_loader: - kv 3: llama.embedding_length u32 = 4096
8llama_model_loader: - kv 4: llama.block_count u32 = 30
9llama_model_loader: - kv 5: llama.feed_forward_length u32 = 11008
10llama_model_loader: - kv 6: llama.rope.dimension_count u32 = 128
11llama_model_loader: - kv 7: llama.attention.head_count u32 = 32
12llama_model_loader: - kv 8: llama.attention.head_count_kv u32 = 32
13llama_model_loader: - kv 9: llama.attention.layer_norm_rms_epsilon f32 = 0.000001
14llama_model_loader: - kv 10: llama.rope.freq_base f32 = 10000.000000
15llama_model_loader: - kv 11: general.file_type u32 = 10
16llama_model_loader: - kv 12: tokenizer.ggml.model str = gpt2
17llama_model_loader: - kv 13: tokenizer.ggml.tokens arr[str,102400] = ["!", "\"", "#", "$", "%", "&", "'", ...
18llama_model_loader: - kv 14: tokenizer.ggml.scores arr[f32,102400] = [0.000000, 0.000000, 0.000000, 0.0000...
19llama_model_loader: - kv 15: tokenizer.ggml.token_type arr[i32,102400] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...
20llama_model_loader: - kv 16: tokenizer.ggml.merges arr[str,99757] = ["Ġ Ġ", "Ġ t", "Ġ a", "i n", "h e"...
21llama_model_loader: - kv 17: tokenizer.ggml.bos_token_id u32 = 100000
22llama_model_loader: - kv 18: tokenizer.ggml.eos_token_id u32 = 100015
23llama_model_loader: - kv 19: tokenizer.ggml.padding_token_id u32 = 100001
24llama_model_loader: - kv 20: tokenizer.chat_template str = {% if not add_generation_prompt is de...
25llama_model_loader: - kv 21: general.quantization_version u32 = 2
26llama_model_loader: - type f32: 61 tensors
27llama_model_loader: - type q2_K: 121 tensors
28llama_model_loader: - type q3_K: 90 tensors
29llama_model_loader: - type q6_K: 1 tensors
30llm_load_vocab: mismatch in special tokens definition ( 2387/102400 vs 2400/102400 ).
31llm_load_print_meta: format = GGUF V3 (latest)
32llm_load_print_meta: arch = llama
33llm_load_print_meta: vocab type = BPE
34llm_load_print_meta: n_vocab = 102400
35llm_load_print_meta: n_merges = 99757
36llm_load_print_meta: n_ctx_train = 4096
37llm_load_print_meta: n_embd = 4096
38llm_load_print_meta: n_head = 32
39llm_load_print_meta: n_head_kv = 32
40llm_load_print_meta: n_layer = 30
41llm_load_print_meta: n_rot = 128
42llm_load_print_meta: n_embd_head_k = 128
43llm_load_print_meta: n_embd_head_v = 128
44llm_load_print_meta: n_gqa = 1
45llm_load_print_meta: n_embd_k_gqa = 4096
46llm_load_print_meta: n_embd_v_gqa = 4096
47llm_load_print_meta: f_norm_eps = 0.0e+00
48llm_load_print_meta: f_norm_rms_eps = 1.0e-06
49llm_load_print_meta: f_clamp_kqv = 0.0e+00
50llm_load_print_meta: f_max_alibi_bias = 0.0e+00
51llm_load_print_meta: n_ff = 11008
52llm_load_print_meta: n_expert = 0
53llm_load_print_meta: n_expert_used = 0
54llm_load_print_meta: pooling type = 0
55llm_load_print_meta: rope type = 0
56llm_load_print_meta: rope scaling = linear
57llm_load_print_meta: freq_base_train = 10000.0
58llm_load_print_meta: freq_scale_train = 1
59llm_load_print_meta: n_yarn_orig_ctx = 4096
60llm_load_print_meta: rope_finetuned = unknown
61llm_load_print_meta: model type = ?B
62llm_load_print_meta: model ftype = Q2_K - Medium
63llm_load_print_meta: model params = 6.91 B
64llm_load_print_meta: model size = 2.53 GiB (3.14 BPW)
65llm_load_print_meta: general.name = LLaMA v2
66llm_load_print_meta: BOS token = 100000 '<|begin▁of▁sentence|>'
67llm_load_print_meta: EOS token = 100015 '<|EOT|>'
68llm_load_print_meta: PAD token = 100001 '<|end▁of▁sentence|>'
69llm_load_print_meta: LF token = 126 'Ä'
70llm_load_tensors: ggml ctx size = 0.21 MiB
71ggml_backend_metal_buffer_from_ptr: allocated buffer, size = 2457.45 MiB, ( 2457.52 / 10922.67)
72llm_load_tensors: offloading 30 repeating layers to GPU
73llm_load_tensors: offloading non-repeating layers to GPU
74llm_load_tensors: offloaded 31/31 layers to GPU
75llm_load_tensors: CPU buffer size = 131.25 MiB
76llm_load_tensors: Metal buffer size = 2457.45 MiB
77.....................................................................................
78llama_new_context_with_model: n_ctx = 512
79llama_new_context_with_model: freq_base = 10000.0
80llama_new_context_with_model: freq_scale = 1
81ggml_metal_init: allocating
82ggml_metal_init: found device: Apple M1
83ggml_metal_init: picking default device: Apple M1
84ggml_metal_init: default.metallib not found, loading from source
85ggml_metal_init: GGML_METAL_PATH_RESOURCES = nil
86ggml_metal_init: loading '/Users/charliecheng-jieji/miniconda3/envs/public-api/lib/python3.12/site-packages/llama_cpp/ggml-metal.metal'
87ggml_metal_init: GPU name: Apple M1
88ggml_metal_init: GPU family: MTLGPUFamilyApple7 (1007)
89ggml_metal_init: GPU family: MTLGPUFamilyCommon3 (3003)
90ggml_metal_init: GPU family: MTLGPUFamilyMetal3 (5001)
91ggml_metal_init: simdgroup reduction support = true
92ggml_metal_init: simdgroup matrix mul. support = true
93ggml_metal_init: hasUnifiedMemory = true
94ggml_metal_init: recommendedMaxWorkingSetSize = 11453.25 MB
95ggml_backend_metal_buffer_type_alloc_buffer: allocated buffer, size = 240.00 MiB, ( 2699.33 / 10922.67)
96llama_kv_cache_init: Metal KV buffer size = 240.00 MiB
97llama_new_context_with_model: KV self size = 240.00 MiB, K (f16): 120.00 MiB, V (f16): 120.00 MiB
98llama_new_context_with_model: CPU input buffer size = 10.01 MiB
99ggml_backend_metal_buffer_type_alloc_buffer: allocated buffer, size = 208.00 MiB, ( 2907.33 / 10922.67)
100llama_new_context_with_model: Metal compute buffer size = 208.00 MiB
101llama_new_context_with_model: CPU compute buffer size = 8.00 MiB
102llama_new_context_with_model: graph splits (measure): 2
103AVX = 0 | AVX_VNNI = 0 | AVX2 = 0 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | FMA = 0 | NEON = 1 | ARM_FMA = 1 | F16C = 0 | FP16_VA = 1 | WASM_SIMD = 0 | BLAS = 1 | SSE3 = 0 | SSSE3 = 0 | VSX = 0 | MATMUL_INT8 = 0 |
104Model metadata: {'general.quantization_version': '2', 'tokenizer.chat_template': "{% if not add_generation_prompt is defined %}\n{% set add_generation_prompt = false %}\n{% endif %}\n{%- set ns = namespace(found=false) -%}\n{%- for message in messages -%}\n {%- if message['role'] == 'system' -%}\n {%- set ns.found = true -%}\n {%- endif -%}\n{%- endfor -%}\n{{bos_token}}{%- if not ns.found -%}\n{{'You are an AI programming assistant, utilizing the Gorilla LLM model, developed by Gorilla LLM, and you only answer questions related to computer science. For politically sensitive questions, security and privacy issues, and other non-computer science questions, you will refuse to answer\\n'}}\n{%- endif %}\n{%- for message in messages %}\n {%- if message['role'] == 'system' %}\n{{ message['content'] }}\n {%- else %}\n {%- if message['role'] == 'user' %}\n{{'### Instruction:\\n' + message['content'] + '\\n'}}\n {%- else %}\n{{'### Response:\\n' + message['content'] + '\\n<|EOT|>\\n'}}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{% if add_generation_prompt %}\n{{'### Response:'}}\n{% endif %}", 'tokenizer.ggml.padding_token_id': '100001', 'tokenizer.ggml.eos_token_id': '100015', 'tokenizer.ggml.bos_token_id': '100000', 'tokenizer.ggml.model': 'gpt2', 'llama.attention.head_count_kv': '32', 'llama.context_length': '4096', 'llama.attention.head_count': '32', 'llama.rope.freq_base': '10000.000000', 'llama.rope.dimension_count': '128', 'general.file_type': '10', 'llama.feed_forward_length': '11008', 'llama.embedding_length': '4096', 'llama.block_count': '30', 'general.architecture': 'llama', 'llama.attention.layer_norm_rms_epsilon': '0.000001', 'general.name': 'LLaMA v2'}
105Using gguf chat template: {% if not add_generation_prompt is defined %}
106{% set add_generation_prompt = false %}
107{% endif %}
108{%- set ns = namespace(found=false) -%}
109{%- for message in messages -%}
110 {%- if message['role'] == 'system' -%}
111 {%- set ns.found = true -%}
112 {%- endif -%}
113{%- endfor -%}
114{{bos_token}}{%- if not ns.found -%}
115{{'You are an AI programming assistant, utilizing the Gorilla LLM model, developed by Gorilla LLM, and you only answer questions related to computer science. For politically sensitive questions, security and privacy issues, and other non-computer science questions, you will refuse to answer\n'}}
116{%- endif %}
117{%- for message in messages %}
118 {%- if message['role'] == 'system' %}
119{{ message['content'] }}
120 {%- else %}
121 {%- if message['role'] == 'user' %}
122{{'### Instruction:\n' + message['content'] + '\n'}}
123 {%- else %}
124{{'### Response:\n' + message['content'] + '\n<|EOT|>\n'}}
125 {%- endif %}
126 {%- endif %}
127{%- endfor %}
128{% if add_generation_prompt %}
129{{'### Response:'}}
130{% endif %}
131Using chat eos_token: <|EOT|>
132Using chat bos_token: <|begin▁of▁sentence|>
133
134llama_print_timings: load time = 1890.11 ms
135llama_print_timings: sample time = 23.48 ms / 40 runs ( 0.59 ms per token, 1703.94 tokens per second)
136llama_print_timings: prompt eval time = 1889.91 ms / 181 tokens ( 10.44 ms per token, 95.77 tokens per second)
137llama_print_timings: eval time = 2728.54 ms / 39 runs ( 69.96 ms per token, 14.29 tokens per second)
138llama_print_timings: total time = 5162.12 ms / 220 tokensOutput: {'id': 'cmpl-0679223d-578f-42be-bbce-0e307faddd28', 'object': 'text_completion', 'created': 1709525244, 'model': '/Users/charliecheng-jieji/Downloads/codebase/quantized_eval/gorilla-openfunctions-v2-GGUF/gorilla-openfunctions-v2-q2_K.gguf', 'choices': [{'text': 'You are an AI programming assistant, utilizing the Gorilla LLM model, developed by Gorilla LLM, and you only answer questions related to computer science. For politically sensitive questions, security and privacy issues, and other non-computer science questions, you will refuse to answer.\n### Instruction: <<function>>[{"name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": {"type": "object", "properties": {"location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"}, "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}}, "required": ["location"]}}]\n<<question>>What\'s the weather like in the two cities of Boston and San Francisco?\n### Response: <<function>>get_current_weather(location=\'Boston\', unit=\'fahrenheit\')<<function>>get_current_weather(location=\'San Francisco\', unit=\'fahrenheit\')', 'index': 0, 'logprobs': None, 'finish_reason': 'stop'}], 'usage': {'prompt_tokens': 181, 'completion_tokens': 39, 'total_tokens': 220}}