Views
No views yet

USER: <<question>> {prompt} <<function>> {{function_string}}
ASSISTANT:
apache-2.0, and this quantization has therefore used that same license.desc_act. True results in better quantisation accuracy. Some GPTQ clients have had issues with models that use Act Order plus Group Size, but this is generally resolved now.| Branch | Bits | GS | Act Order | Damp % | GPTQ Dataset | Seq Len | Size | ExLlama | Desc |
|---|---|---|---|---|---|---|---|---|---|
| main | 4 | 128 | Yes | 0.1 | code | 4096 | 3.90 GB | Yes | 4-bit, with Act Order and group size 128g. Uses even less VRAM than 64g, but with slightly lower accuracy. |
| gptq-4bit-32g-actorder_True | 4 | 32 | Yes | 0.1 | code | 4096 | 4.28 GB | Yes | 4-bit, with Act Order and group size 32g. Gives highest possible inference quality, with maximum VRAM usage. |
| gptq-8bit--1g-actorder_True | 8 | None | Yes | 0.1 | code | 4096 | 7.01 GB | No | 8-bit, with Act Order. No group size, to lower VRAM requirements. |
| gptq-8bit-128g-actorder_True | 8 | 128 | Yes | 0.1 | code | 4096 | 7.16 GB | No | 8-bit, with group size 128g for higher inference quality and with Act Order for even higher accuracy. |
| gptq-8bit-32g-actorder_True | 8 | 32 | Yes | 0.1 | code | 4096 | 7.62 GB | No | 8-bit, with group size 32g and Act Order for maximum inference quality. |
| gptq-4bit-64g-actorder_True | 4 | 64 | Yes | 0.1 | code | 4096 | 4.02 GB | Yes | 4-bit, with Act Order and group size 64g. Uses less VRAM than 32g, but with slightly lower accuracy. |
main branch, enter TheBloke/gorilla-openfunctions-v1-GPTQ in the "Download model" box.:branchname to the end of the download name, eg TheBloke/gorilla-openfunctions-v1-GPTQ:gptq-4bit-32g-actorder_Truehuggingface-hub Python library:pip3 install huggingface-hubmain branch to a folder called gorilla-openfunctions-v1-GPTQ:1mkdir gorilla-openfunctions-v1-GPTQ
2huggingface-cli download TheBloke/gorilla-openfunctions-v1-GPTQ --local-dir gorilla-openfunctions-v1-GPTQ --local-dir-use-symlinks False--revision parameter:1mkdir gorilla-openfunctions-v1-GPTQ
2huggingface-cli download TheBloke/gorilla-openfunctions-v1-GPTQ --revision gptq-4bit-32g-actorder_True --local-dir gorilla-openfunctions-v1-GPTQ --local-dir-use-symlinks False--local-dir-use-symlinks False parameter, the files will instead be stored in the central Hugging Face cache directory (default location on Linux is: ~/.cache/huggingface), and symlinks will be added to the specified --local-dir, pointing to their real location in the cache. This allows for interrupted downloads to be resumed, and allows you to quickly clone the repo to multiple places on disk without triggering a download again. The downside, and the reason why I don't list that as the default option, is that the files are then hidden away in a cache folder and it's harder to know where your disk space is being used, and to clear it up if/when you want to remove a download model.HF_HOME environment variable, and/or the --cache-dir parameter to huggingface-cli.huggingface-cli, please see: HF -> Hub Python Library -> Download files -> Download from the CLI.hf_transfer:pip3 install hf_transferHF_HUB_ENABLE_HF_TRANSFER to 1:1mkdir gorilla-openfunctions-v1-GPTQ
2HF_HUB_ENABLE_HF_TRANSFER=1 huggingface-cli download TheBloke/gorilla-openfunctions-v1-GPTQ --local-dir gorilla-openfunctions-v1-GPTQ --local-dir-use-symlinks Falseset HF_HUB_ENABLE_HF_TRANSFER=1 before the download command.git (not recommended)git, use a command like this:git clone --single-branch --branch gptq-4bit-32g-actorder_True https://huggingface.co/TheBloke/gorilla-openfunctions-v1-GPTQhuggingface-hub, and will use twice as much disk space as it has to store the model files twice (it stores every byte both in the intended target folder, and again in the .git folder as a blob.)TheBloke/gorilla-openfunctions-v1-GPTQ.TheBloke/gorilla-openfunctions-v1-GPTQ:gptq-4bit-32g-actorder_Truegorilla-openfunctions-v1-GPTQquantize_config.json.ghcr.io/huggingface/text-generation-inference:1.1.0--model-id TheBloke/gorilla-openfunctions-v1-GPTQ --port 3000 --quantize gptq --max-input-length 3696 --max-total-tokens 4096 --max-batch-prefill-tokens 4096pip3 install huggingface-hub1from huggingface_hub import InferenceClient
2
3endpoint_url = "https://your-endpoint-url-here"
4
5prompt = "Tell me about AI"
6prompt_template=f'''USER: <<question>> {prompt} <<function>> {{function_string}}
7ASSISTANT:
8'''
9
10client = InferenceClient(endpoint_url)
11response = client.text_generation(prompt,
12 max_new_tokens=128,
13 do_sample=True,
14 temperature=0.7,
15 top_p=0.95,
16 top_k=40,
17 repetition_penalty=1.1)
18
19print(f"Model output: {response}")1pip3 install --upgrade transformers optimum
2# If using PyTorch 2.1 + CUDA 12.x:
3pip3 install --upgrade auto-gptq
4# or, if using PyTorch 2.1 + CUDA 11.x:
5pip3 install --upgrade auto-gptq --extra-index-url https://huggingface.github.io/autogptq-index/whl/cu118/1pip3 uninstall -y auto-gptq
2git clone https://github.com/PanQiWei/AutoGPTQ
3cd AutoGPTQ
4git checkout v0.5.1
5pip3 install .1from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
2
3model_name_or_path = "TheBloke/gorilla-openfunctions-v1-GPTQ"
4# To use a different branch, change revision
5# For example: revision="gptq-4bit-32g-actorder_True"
6model = AutoModelForCausalLM.from_pretrained(model_name_or_path,
7 device_map="auto",
8 trust_remote_code=False,
9 revision="main")
10
11tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
12
13prompt = "Tell me about AI"
14prompt_template=f'''USER: <<question>> {prompt} <<function>> {{function_string}}
15ASSISTANT:
16'''
17
18print("\n\n*** Generate:")
19
20input_ids = tokenizer(prompt_template, return_tensors='pt').input_ids.cuda()
21output = model.generate(inputs=input_ids, temperature=0.7, do_sample=True, top_p=0.95, top_k=40, max_new_tokens=512)
22print(tokenizer.decode(output[0]))
23
24# Inference can also be done using transformers' pipeline
25
26print("*** Pipeline:")
27pipe = pipeline(
28 "text-generation",
29 model=model,
30 tokenizer=tokenizer,
31 max_new_tokens=512,
32 do_sample=True,
33 temperature=0.7,
34 top_p=0.95,
35 top_k=40,
36 repetition_penalty=1.1
37)
38
39print(pipe(prompt_template)[0]['generated_text'])| model | functionality |
|---|---|
| gorilla-openfunctions-v0 | Given a function, and user intent, returns properly formatted json with the right arguments |
| gorilla-openfunctions-v1 | + Parallel functions, and can choose between functions |
!pip install openai==0.28.11import openai
2
3def get_gorilla_response(prompt="Call me an Uber ride type \"Plus\" in Berkeley at zipcode 94704 in 10 minutes", model="gorilla-openfunctions-v0", functions=[]):
4 openai.api_key = "EMPTY"
5 openai.api_base = "http://luigi.millennium.berkeley.edu:8000/v1"
6 try:
7 completion = openai.ChatCompletion.create(
8 model="gorilla-openfunctions-v1",
9 temperature=0.0,
10 messages=[{"role": "user", "content": prompt}],
11 functions=functions,
12 )
13 return completion.choices[0].message.content
14 except Exception as e:
15 print(e, model, prompt)1query = "Call me an Uber ride type \"Plus\" in Berkeley at zipcode 94704 in 10 minutes"
2functions = [
3 {
4 "name": "Uber Carpool",
5 "api_name": "uber.ride",
6 "description": "Find suitable ride for customers given the location, type of ride, and the amount of time the customer is willing to wait as parameters",
7 "parameters": [{"name": "loc", "description": "location of the starting place of the uber ride"}, {"name":"type", "enum": ["plus", "comfort", "black"], "description": "types of uber ride user is ordering"}, {"name": "time", "description": "the amount of time in minutes the customer is willing to wait"}]
8 }
9]
10get_gorilla_response(query, functions=functions)uber.ride(loc="berkeley", type="plus", time=10)1import json
2import torch
3from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
4
5def get_prompt(user_query: str, functions: list = []) -> str:
6 """
7 Generates a conversation prompt based on the user's query and a list of functions.
8
9 Parameters:
10 - user_query (str): The user's query.
11 - functions (list): A list of functions to include in the prompt.
12
13 Returns:
14 - str: The formatted conversation prompt.
15 """
16 if len(functions) == 0:
17 return f"USER: <<question>> {user_query}\nASSISTANT: "
18 functions_string = json.dumps(functions)
19 return f"USER: <<question>> {user_query} <<function>> {functions_string}\nASSISTANT: "
20
21# Device setup
22device : str = "cuda:0" if torch.cuda.is_available() else "cpu"
23torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
24
25# Model and tokenizer setup
26model_id : str = "gorilla-llm/gorilla-openfunctions-v1"
27tokenizer = AutoTokenizer.from_pretrained(model_id)
28model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True)
29
30# Move model to device
31model.to(device)
32
33# Pipeline setup
34pipe = pipeline(
35 "text-generation",
36 model=model,
37 tokenizer=tokenizer,
38 max_new_tokens=128,
39 batch_size=16,
40 torch_dtype=torch_dtype,
41 device=device,
42)
43
44# Example usage
45query: str = "Call me an Uber ride type \"Plus\" in Berkeley at zipcode 94704 in 10 minutes"
46functions = [
47 {
48 "name": "Uber Carpool",
49 "api_name": "uber.ride",
50 "description": "Find suitable ride for customers given the location, type of ride, and the amount of time the customer is willing to wait as parameters",
51 "parameters": [
52 {"name": "loc", "description": "Location of the starting place of the Uber ride"},
53 {"name": "type", "enum": ["plus", "comfort", "black"], "description": "Types of Uber ride user is ordering"},
54 {"name": "time", "description": "The amount of time in minutes the customer is willing to wait"}
55 ]
56 }
57]
58
59# Generate prompt and obtain model output
60prompt = get_prompt(query, functions=functions)
61output = pipe(prompt)
62
63print(output)