This repo includes two types of quantized models:
GGUF and
AWQ, for our Octopus V2 model at
NexaAIDev/Octopus-v2
To run the models, please download them to your local machine using either git clone or
Hugging Face Hub
1git clone https://github.com/ggerganov/llama.cpp
2cd llama.cpp
3# Compile the source code:
4make
Since our models have not been uploaded to the Ollama server, please download the models and manually import them into Ollama by following these steps:
1from transformers import AutoTokenizer
2from awq import AutoAWQForCausalLM
3import torch
4import time
5import numpy as np
6def inference(input_text):
7 start_time = time.time()
8 input_ids = tokenizer(input_text, return_tensors="pt").to('cuda')
9 input_length = input_ids["input_ids"].shape[1]
10 generation_output = model.generate(
11 input_ids["input_ids"],
12 do_sample=False,
13 max_length=1024
14 )
15 end_time = time.time()
16 # Decode only the generated part
17 generated_sequence = generation_output[:, input_length:].tolist()
18 res = tokenizer.decode(generated_sequence[0])
19 latency = end_time - start_time
20 num_output_tokens = len(generated_sequence[0])
21 throughput = num_output_tokens / latency
22 return {"output": res, "latency": latency, "throughput": throughput}
23# Initialize tokenizer and model
24model_id = "/path/to/Octopus-v2-AWQ-NexaAIDev"
25tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=False)
26model = AutoAWQForCausalLM.from_quantized(model_id, fuse_layers=True,
27 trust_remote_code=False, safetensors=True)
28prompts = ["Below is the query from the users, please call the correct function and generate the parameters to call the function.\n\nQuery: Can you take a photo using the back camera and save it to the default location? \n\nResponse:"]
29avg_throughput = []
30for prompt in prompts:
31 out = inference(prompt)
32 avg_throughput.append(out["throughput"])
33 print("nexa model result:\n", out["output"])
34print("avg throughput:", np.mean(avg_throughput))
Acknowledgement:
We sincerely thank our community members,
Mingyuan,
Zoey,
Brian,
Perry,
Qi,
David for their extraordinary contributions to this quantization effort.