MoMonir commited on
Commit
6510fc5
1 Parent(s): f5b6d32

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ llama3-chatqa-1.5-8b.Q5_K_M.gguf filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: llama3
3
+ language:
4
+ - en
5
+ pipeline_tag: text-generation
6
+ tags:
7
+ - nvidia
8
+ - chatqa-1.5
9
+ - chatqa
10
+ - llama-3
11
+ - pytorch
12
+ ---
13
+
14
+
15
+ # MoMonir/Phi-3-mini-128k-instruct-GGUF
16
+ This model was converted to GGUF format from [`microsoft/Phi-3-mini-128k-instruct`](https://huggingface.co/microsoft/Phi-3-mini-128k-instruct)
17
+ Refer to the [original model card](https://huggingface.co/microsoft/Phi-3-mini-128k-instruct) for more details on the model.
18
+
19
+ <!-- README_GGUF.md-about-gguf start -->
20
+ ### About GGUF ([TheBloke](https://huggingface.co/TheBloke) Description)
21
+
22
+ GGUF is a new format introduced by the llama.cpp team on August 21st 2023. It is a replacement for GGML, which is no longer supported by llama.cpp.
23
+
24
+ Here is an incomplete list of clients and libraries that are known to support GGUF:
25
+
26
+ * [llama.cpp](https://github.com/ggerganov/llama.cpp). The source project for GGUF. Offers a CLI and a server option.
27
+ * [text-generation-webui](https://github.com/oobabooga/text-generation-webui), the most widely used web UI, with many features and powerful extensions. Supports GPU acceleration.
28
+ * [KoboldCpp](https://github.com/LostRuins/koboldcpp), a fully featured web UI, with GPU accel across all platforms and GPU architectures. Especially good for story telling.
29
+ * [GPT4All](https://gpt4all.io/index.html), a free and open source local running GUI, supporting Windows, Linux and macOS with full GPU accel.
30
+ * [LM Studio](https://lmstudio.ai/), an easy-to-use and powerful local GUI for Windows and macOS (Silicon), with GPU acceleration. Linux available, in beta as of 27/11/2023.
31
+ * [LoLLMS Web UI](https://github.com/ParisNeo/lollms-webui), a great web UI with many interesting and unique features, including a full model library for easy model selection.
32
+ * [Faraday.dev](https://faraday.dev/), an attractive and easy to use character-based chat GUI for Windows and macOS (both Silicon and Intel), with GPU acceleration.
33
+ * [llama-cpp-python](https://github.com/abetlen/llama-cpp-python), a Python library with GPU accel, LangChain support, and OpenAI-compatible API server.
34
+ * [candle](https://github.com/huggingface/candle), a Rust ML framework with a focus on performance, including GPU support, and ease of use.
35
+ * [ctransformers](https://github.com/marella/ctransformers), a Python library with GPU accel, LangChain support, and OpenAI-compatible AI server. Note, as of time of writing (November 27th 2023), ctransformers has not been updated in a long time and does not support many recent models.
36
+
37
+ <!-- README_GGUF.md-about-gguf end -->
38
+
39
+
40
+ ## Model Details
41
+ We introduce Llama3-ChatQA-1.5, which excels at conversational question answering (QA) and retrieval-augmented generation (RAG). Llama3-ChatQA-1.5 is developed using an improved training recipe from [ChatQA (1.0)](https://arxiv.org/abs/2401.10225), and it is built on top of [Llama-3 base model](https://huggingface.co/meta-llama/Meta-Llama-3-8B). Specifically, we incorporate more conversational QA data to enhance its tabular and arithmetic calculation capability. Llama3-ChatQA-1.5 has two variants: Llama3-ChatQA-1.5-8B and Llama3-ChatQA-1.5-70B. Both models were originally trained using [Megatron-LM](https://github.com/NVIDIA/Megatron-LM), we converted the checkpoints to Hugging Face format.
42
+
43
+ ## Other Resources
44
+ [Llama3-ChatQA-1.5-70B](https://huggingface.co/nvidia/Llama3-ChatQA-1.5-70B) &ensp; [Evaluation Data](https://huggingface.co/datasets/nvidia/ChatRAG-Bench) &ensp; [Training Data](https://huggingface.co/datasets/nvidia/ChatQA-Training-Data) &ensp; [Retriever](https://huggingface.co/nvidia/dragon-multiturn-query-encoder)
45
+
46
+ ## Benchmark Results
47
+ Results in [ChatRAG Bench](https://huggingface.co/datasets/nvidia/ChatRAG-Bench) are as follows:
48
+
49
+ | | ChatQA-1.0-7B | Command-R-Plus | Llama-3-instruct-70b | GPT-4-0613 | ChatQA-1.0-70B | ChatQA-1.5-8B | ChatQA-1.5-70B |
50
+ | -- |:--:|:--:|:--:|:--:|:--:|:--:|:--:|
51
+ | Doc2Dial | 37.88 | 33.51 | 37.88 | 34.16 | 38.9 | 39.33 | 41.26 |
52
+ | QuAC | 29.69 | 34.16 | 36.96 | 40.29 | 41.82 | 39.73 | 38.82 |
53
+ | QReCC | 46.97 | 49.77 | 51.34 | 52.01 | 48.05 | 49.03 | 51.40 |
54
+ | CoQA | 76.61 | 69.71 | 76.98 | 77.42 | 78.57 | 76.46 | 78.44 |
55
+ | DoQA | 41.57 | 40.67 | 41.24 | 43.39 | 51.94 | 49.6 | 50.67 |
56
+ | ConvFinQA | 51.61 | 71.21 | 76.6 | 81.28 | 73.69 | 78.46 | 81.88 |
57
+ | SQA | 61.87 | 74.07 | 69.61 | 79.21 | 69.14 | 73.28 | 83.82 |
58
+ | TopioCQA | 45.45 | 53.77 | 49.72 | 45.09 | 50.98 | 49.96 | 55.63 |
59
+ | HybriDial* | 54.51 | 46.7 | 48.59 | 49.81 | 56.44 | 65.76 | 68.27 |
60
+ | INSCIT | 30.96 | 35.76 | 36.23 | 36.34 | 31.9 | 30.1 | 32.31 |
61
+ | Average (all) | 47.71 | 50.93 | 52.52 | 53.90 | 54.14 | 55.17 | 58.25 |
62
+ | Average (exclude HybriDial) | 46.96 | 51.40 | 52.95 | 54.35 | 53.89 | 53.99 | 57.14 |
63
+
64
+ Note that ChatQA-1.5 is built based on Llama-3 base model, and ChatQA-1.0 is built based on Llama-2 base model. ChatQA-1.5 used some samples from the HybriDial training dataset. To ensure fair comparison, we also compare average scores excluding HybriDial. The data and evaluation scripts for ChatRAG Bench can be found [here](https://huggingface.co/datasets/nvidia/ChatRAG-Bench).
65
+
66
+
67
+ ## Prompt Format
68
+ <pre>
69
+ System: {System}
70
+
71
+ {Context}
72
+
73
+ User: {Question}
74
+
75
+ Assistant: {Response}
76
+
77
+ User: {Question}
78
+
79
+ Assistant:
80
+ </pre>
81
+
82
+
83
+ ## How to use
84
+
85
+ ### take the whole document as context
86
+ This can be applied to the scenario where the whole document can be fitted into the model, so that there is no need to run retrieval over the document.
87
+ ```python
88
+ from transformers import AutoTokenizer, AutoModelForCausalLM
89
+ import torch
90
+
91
+ model_id = "nvidia/Llama3-ChatQA-1.5-8B"
92
+
93
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
94
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
95
+
96
+ messages = [
97
+ {"role": "user", "content": "what is the percentage change of the net income from Q4 FY23 to Q4 FY24?"}
98
+ ]
99
+
100
+ document = """NVIDIA (NASDAQ: NVDA) today reported revenue for the fourth quarter ended January 28, 2024, of $22.1 billion, up 22% from the previous quarter and up 265% from a year ago.\nFor the quarter, GAAP earnings per diluted share was $4.93, up 33% from the previous quarter and up 765% from a year ago. Non-GAAP earnings per diluted share was $5.16, up 28% from the previous quarter and up 486% from a year ago.\nQ4 Fiscal 2024 Summary\nGAAP\n| $ in millions, except earnings per share | Q4 FY24 | Q3 FY24 | Q4 FY23 | Q/Q | Y/Y |\n| Revenue | $22,103 | $18,120 | $6,051 | Up 22% | Up 265% |\n| Gross margin | 76.0% | 74.0% | 63.3% | Up 2.0 pts | Up 12.7 pts |\n| Operating expenses | $3,176 | $2,983 | $2,576 | Up 6% | Up 23% |\n| Operating income | $13,615 | $10,417 | $1,257 | Up 31% | Up 983% |\n| Net income | $12,285 | $9,243 | $1,414 | Up 33% | Up 769% |\n| Diluted earnings per share | $4.93 | $3.71 | $0.57 | Up 33% | Up 765% |"""
101
+
102
+ def get_formatted_input(messages, context):
103
+ system = "System: This is a chat between a user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions based on the context. The assistant should also indicate when the answer cannot be found in the context."
104
+ instruction = "Please give a full and complete answer for the question."
105
+
106
+ for item in messages:
107
+ if item['role'] == "user":
108
+ ## only apply this instruction for the first user turn
109
+ item['content'] = instruction + " " + item['content']
110
+ break
111
+
112
+ conversation = '\n\n'.join(["User: " + item["content"] if item["role"] == "user" else "Assistant: " + item["content"] for item in messages]) + "\n\nAssistant:"
113
+ formatted_input = system + "\n\n" + context + "\n\n" + conversation
114
+
115
+ return formatted_input
116
+
117
+ formatted_input = get_formatted_input(messages, document)
118
+ tokenized_prompt = tokenizer(tokenizer.bos_token + formatted_input, return_tensors="pt").to(model.device)
119
+
120
+ terminators = [
121
+ tokenizer.eos_token_id,
122
+ tokenizer.convert_tokens_to_ids("<|eot_id|>")
123
+ ]
124
+
125
+ outputs = model.generate(input_ids=tokenized_prompt.input_ids, attention_mask=tokenized_prompt.attention_mask, max_new_tokens=128, eos_token_id=terminators)
126
+
127
+ response = outputs[0][tokenized_prompt.input_ids.shape[-1]:]
128
+ print(tokenizer.decode(response, skip_special_tokens=True))
129
+ ```
130
+
131
+ ### run retrieval to get top-n chunks as context
132
+ This can be applied to the scenario when the document is very long, so that it is necessary to run retrieval. Here, we use our [Dragon-multiturn](https://huggingface.co/nvidia/dragon-multiturn-query-encoder) retriever which can handle conversatinoal query. In addition, we provide a few [documents](https://huggingface.co/nvidia/Llama3-ChatQA-1.5-8B/tree/main/docs) for users to play with.
133
+
134
+ ```python
135
+ from transformers import AutoTokenizer, AutoModelForCausalLM, AutoModel
136
+ import torch
137
+ import json
138
+
139
+ ## load ChatQA-1.5 tokenizer and model
140
+ model_id = "nvidia/Llama3-ChatQA-1.5-8B"
141
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
142
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
143
+
144
+ ## load retriever tokenizer and model
145
+ retriever_tokenizer = AutoTokenizer.from_pretrained('nvidia/dragon-multiturn-query-encoder')
146
+ query_encoder = AutoModel.from_pretrained('nvidia/dragon-multiturn-query-encoder')
147
+ context_encoder = AutoModel.from_pretrained('nvidia/dragon-multiturn-context-encoder')
148
+
149
+ ## prepare documents, we take landrover car manual document that we provide as an example
150
+ chunk_list = json.load(open("docs.json"))['landrover']
151
+
152
+ messages = [
153
+ {"role": "user", "content": "how to connect the bluetooth in the car?"}
154
+ ]
155
+
156
+ ### running retrieval
157
+ ## convert query into a format as follows:
158
+ ## user: {user}\nagent: {agent}\nuser: {user}
159
+ formatted_query_for_retriever = '\n'.join([turn['role'] + ": " + turn['content'] for turn in messages]).strip()
160
+
161
+ query_input = retriever_tokenizer(formatted_query_for_retriever, return_tensors='pt')
162
+ ctx_input = retriever_tokenizer(chunk_list, padding=True, truncation=True, max_length=512, return_tensors='pt')
163
+ query_emb = query_encoder(**query_input).last_hidden_state[:, 0, :]
164
+ ctx_emb = context_encoder(**ctx_input).last_hidden_state[:, 0, :]
165
+
166
+ ## Compute similarity scores using dot product and rank the similarity
167
+ similarities = query_emb.matmul(ctx_emb.transpose(0, 1)) # (1, num_ctx)
168
+ ranked_results = torch.argsort(similarities, dim=-1, descending=True) # (1, num_ctx)
169
+
170
+ ## get top-n chunks (n=5)
171
+ retrieved_chunks = [chunk_list[idx] for idx in ranked_results.tolist()[0][:5]]
172
+ context = "\n\n".join(retrieved_chunks)
173
+
174
+ ### running text generation
175
+ formatted_input = get_formatted_input(messages, context)
176
+ tokenized_prompt = tokenizer(tokenizer.bos_token + formatted_input, return_tensors="pt").to(model.device)
177
+
178
+ terminators = [
179
+ tokenizer.eos_token_id,
180
+ tokenizer.convert_tokens_to_ids("<|eot_id|>")
181
+ ]
182
+ outputs = model.generate(input_ids=tokenized_prompt.input_ids, attention_mask=tokenized_prompt.attention_mask, max_new_tokens=128, eos_token_id=terminators)
183
+
184
+ response = outputs[0][tokenized_prompt.input_ids.shape[-1]:]
185
+ print(tokenizer.decode(response, skip_special_tokens=True))
186
+ ```
187
+
188
+ ## Correspondence to
189
+ Zihan Liu (zihanl@nvidia.com), Wei Ping (wping@nvidia.com)
190
+
191
+ ## Citation
192
+ <pre>
193
+ @article{liu2024chatqa,
194
+ title={ChatQA: Building GPT-4 Level Conversational QA Models},
195
+ author={Liu, Zihan and Ping, Wei and Roy, Rajarshi and Xu, Peng and Lee, Chankyu and Shoeybi, Mohammad and Catanzaro, Bryan},
196
+ journal={arXiv preprint arXiv:2401.10225},
197
+ year={2024}}
198
+ </pre>
199
+
200
+
201
+ ## License
202
+ The use of this model is governed by the [META LLAMA 3 COMMUNITY LICENSE AGREEMENT](https://llama.meta.com/llama3/license/)
203
+
llama3-chatqa-1.5-8b.Q5_K_M.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:06a58391e6a93e3533f7fb3fad478a10e118d42a482c62ec8812ec1e7595255c
3
+ size 5733499744
llama3-chatqa-1.5-8b.fp16.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2d705f1e9a081bb884cd5df7e83473478f2261fc87a08b089912388b91d87d1a
3
+ size 16069403424
pytorch_model-00001-of-00002.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cf7b98bc9e3c34110edf822580331370d5d99d2f147a705541bb44309921c32b
3
+ size 9976569035
pytorch_model-00002-of-00002.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e1739c78a93c82cf4e43b8dece94e6a474e29800c886d33b1bf8d6a2c98b0f96
3
+ size 6084065129