LoneStriker commited on
Commit
1a54216
1 Parent(s): c70c34e

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -1,35 +1,5 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz 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
 
1
+ Llama3-ChatQA-1.5-8B-Q3_K_L.gguf filter=lfs diff=lfs merge=lfs -text
2
+ Llama3-ChatQA-1.5-8B-Q4_K_M.gguf filter=lfs diff=lfs merge=lfs -text
3
+ Llama3-ChatQA-1.5-8B-Q5_K_M.gguf filter=lfs diff=lfs merge=lfs -text
4
+ Llama3-ChatQA-1.5-8B-Q6_K.gguf filter=lfs diff=lfs merge=lfs -text
5
+ Llama3-ChatQA-1.5-8B-Q8_0.gguf filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Llama3-ChatQA-1.5-8B-Q3_K_L.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:165f2a7bfe4e131fff9252f04c25f6d0f6d8ae5fe3dfb02da0d85eae27675447
3
+ size 4322468704
Llama3-ChatQA-1.5-8B-Q4_K_M.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:289c2682bcd9399614542d2f291a340c17881c210191cbfe5bdbff3040d8cea2
3
+ size 4921246560
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:64737528183fb4868ee65bf8b93a60fb818354e4aff4054694fb6d38376755cc
3
+ size 5733499744
Llama3-ChatQA-1.5-8B-Q6_K.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5d897bcecb52e25d802b60363a76c7e87e1ac83bf19de7734a1dbffe947ae7fd
3
+ size 6596518752
Llama3-ChatQA-1.5-8B-Q8_0.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2b9825832a0903d85377117d9369eff6b103b39a2f3fa95d7594ae4eb9f1a37b
3
+ size 8541283168
README.md ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ## Model Details
16
+ We introduce Llama3-ChatQA-1.5, which excels at conversational question answering (QA) and retrieval-augumented generation (RAG). Llama3-ChatQA-1.5 is built using the 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). Additionally, we incorporate more conversational QA data to enhance its tabular and arithmatic 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.
17
+
18
+ ## Other Resources
19
+ [Llama3-ChatQA-1.5-70B](https://huggingface.co/nvidia/Llama3-ChatQA-1.5-70B)   [Evaluation Data](https://huggingface.co/datasets/nvidia/ConvRAG-Bench)   [Training Data](https://huggingface.co/datasets/nvidia/ChatQA-Training-Data)   [Retriever](https://huggingface.co/nvidia/dragon-multiturn-query-encoder)
20
+
21
+ ## Benchmark Results
22
+ Results in ConvRAG Bench are as follows:
23
+
24
+ | | 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 |
25
+ | -- |:--:|:--:|:--:|:--:|:--:|:--:|:--:|
26
+ | Doc2Dial | 37.88 | 33.51 | 37.88 | 34.16 | 38.9 | 39.33 | 41.26 |
27
+ | QuAC | 29.69 | 34.16 | 36.96 | 40.29 | 41.82 | 39.73 | 38.82 |
28
+ | QReCC | 46.97 | 49.77 | 51.34 | 52.01 | 48.05 | 49.03 | 51.40 |
29
+ | CoQA | 76.61 | 69.71 | 76.98 | 77.42 | 78.57 | 76.46 | 78.44 |
30
+ | DoQA | 41.57 | 40.67 | 41.24 | 43.39 | 51.94 | 49.6 | 50.67 |
31
+ | ConvFinQA | 51.61 | 71.21 | 76.6 | 81.28 | 73.69 | 78.46 | 81.88 |
32
+ | SQA | 61.87 | 74.07 | 69.61 | 79.21 | 69.14 | 73.28 | 83.82 |
33
+ | TopioCQA | 45.45 | 53.77 | 49.72 | 45.09 | 50.98 | 49.96 | 55.63 |
34
+ | HybriDial* | 54.51 | 46.7 | 48.59 | 49.81 | 56.44 | 65.76 | 68.27 |
35
+ | INSCIT | 30.96 | 35.76 | 36.23 | 36.34 | 31.9 | 30.1 | 32.31 |
36
+ | Average (all) | 47.71 | 50.93 | 52.52 | 53.90 | 54.14 | 55.17 | 58.25 |
37
+ | Average (exclude HybriDial) | 46.96 | 51.40 | 52.95 | 54.35 | 53.89 | 53.99 | 57.14 |
38
+
39
+ 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. We 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 ConvRAG can be found [here](https://huggingface.co/datasets/nvidia/ConvRAG-Bench).
40
+
41
+
42
+ ## Prompt Format
43
+ <pre>
44
+ System: {System}
45
+
46
+ {Context}
47
+
48
+ User: {Question}
49
+
50
+ Assistant: {Response}
51
+
52
+ User: {Question}
53
+
54
+ Assistant:
55
+ </pre>
56
+
57
+
58
+ ## How to use
59
+
60
+ ### take the whole document as context
61
+ 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.
62
+ ```python
63
+ from transformers import AutoTokenizer, AutoModelForCausalLM
64
+ import torch
65
+
66
+ model_id = "nvidia/Llama3-ChatQA-1.5-8B"
67
+
68
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
69
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
70
+
71
+ messages = [
72
+ {"role": "user", "content": "what is the percentage change of the net income from Q4 FY23 to Q4 FY24?"}
73
+ ]
74
+
75
+ 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% |"""
76
+
77
+ def get_formatted_input(messages, context):
78
+ 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."
79
+ instruction = "Please give a full and complete answer for the question."
80
+
81
+ for item in messages:
82
+ if item['role'] == "user":
83
+ ## only apply this instruction for the first user turn
84
+ item['content'] = instruction + " " + item['content']
85
+ break
86
+
87
+ conversation = '\n\n'.join(["User: " + item["content"] if item["role"] == "user" else "Assistant: " + item["content"] for item in messages]) + "\n\nAssistant:"
88
+ formatted_input = system + "\n\n" + context + "\n\n" + conversation
89
+
90
+ return formatted_input
91
+
92
+ formatted_input = get_formatted_input(messages, document)
93
+ tokenized_prompt = tokenizer(tokenizer.bos_token + formatted_input, return_tensors="pt").to(model.device)
94
+
95
+ terminators = [
96
+ tokenizer.eos_token_id,
97
+ tokenizer.convert_tokens_to_ids("<|eot_id|>")
98
+ ]
99
+
100
+ outputs = model.generate(input_ids=tokenized_prompt.input_ids, attention_mask=tokenized_prompt.attention_mask, max_new_tokens=128, eos_token_id=terminators)
101
+
102
+ response = outputs[0][tokenized_prompt.input_ids.shape[-1]:]
103
+ print(tokenizer.decode(response, skip_special_tokens=True))
104
+ ```
105
+
106
+ ### run retrieval to get top-n chunks as context
107
+ 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.
108
+
109
+ ```python
110
+ from transformers import AutoTokenizer, AutoModelForCausalLM, AutoModel
111
+ import torch
112
+ import json
113
+
114
+ ## load ChatQA-1.5 tokenizer and model
115
+ model_id = "nvidia/Llama3-ChatQA-1.5-8B"
116
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
117
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
118
+
119
+ ## load retriever tokenizer and model
120
+ retriever_tokenizer = AutoTokenizer.from_pretrained('nvidia/dragon-multiturn-query-encoder')
121
+ query_encoder = AutoModel.from_pretrained('nvidia/dragon-multiturn-query-encoder')
122
+ context_encoder = AutoModel.from_pretrained('nvidia/dragon-multiturn-context-encoder')
123
+
124
+ ## prepare documents, we take landrover car manual document that we provide as an example
125
+ chunk_list = json.load(open("docs.json"))['landrover']
126
+
127
+ messages = [
128
+ {"role": "user", "content": "how to connect the bluetooth in the car?"}
129
+ ]
130
+
131
+ ### running retrieval
132
+ ## convert query into a format as follows:
133
+ ## user: {user}\nagent: {agent}\nuser: {user}
134
+ formatted_query_for_retriever = '\n'.join([turn['role'] + ": " + turn['content'] for turn in messages]).strip()
135
+
136
+ query_input = retriever_tokenizer(formatted_query_for_retriever, return_tensors='pt')
137
+ ctx_input = retriever_tokenizer(chunk_list, padding=True, truncation=True, max_length=512, return_tensors='pt')
138
+ query_emb = query_encoder(**query_input).last_hidden_state[:, 0, :]
139
+ ctx_emb = context_encoder(**ctx_input).last_hidden_state[:, 0, :]
140
+
141
+ ## Compute similarity scores using dot product and rank the similarity
142
+ similarities = query_emb.matmul(ctx_emb.transpose(0, 1)) # (1, num_ctx)
143
+ ranked_results = torch.argsort(similarities, dim=-1, descending=True) # (1, num_ctx)
144
+
145
+ ## get top-n chunks (n=5)
146
+ retrieved_chunks = [chunk_list[idx] for idx in ranked_results.tolist()[0][:5]]
147
+ context = "\n\n".join(retrieved_chunks)
148
+
149
+ ### running text generation
150
+ formatted_input = get_formatted_input(messages, context)
151
+ tokenized_prompt = tokenizer(tokenizer.bos_token + formatted_input, return_tensors="pt").to(model.device)
152
+
153
+ terminators = [
154
+ tokenizer.eos_token_id,
155
+ tokenizer.convert_tokens_to_ids("<|eot_id|>")
156
+ ]
157
+ outputs = model.generate(input_ids=tokenized_prompt.input_ids, attention_mask=tokenized_prompt.attention_mask, max_new_tokens=128, eos_token_id=terminators)
158
+
159
+ response = outputs[0][tokenized_prompt.input_ids.shape[-1]:]
160
+ print(tokenizer.decode(response, skip_special_tokens=True))
161
+ ```
162
+
163
+ ## Correspondence to
164
+ Zihan Liu (zihanl@nvidia.com), Wei Ping (wping@nvidia.com)
165
+
166
+ ## Citation
167
+ <pre>
168
+ @article{liu2024chatqa,
169
+ title={ChatQA: Building GPT-4 Level Conversational QA Models},
170
+ author={Liu, Zihan and Ping, Wei and Roy, Rajarshi and Xu, Peng and Lee, Chankyu and Shoeybi, Mohammad and Catanzaro, Bryan},
171
+ journal={arXiv preprint arXiv:2401.10225},
172
+ year={2024}}
173
+ </pre>
174
+
175
+
176
+ ## License
177
+ The use of this model is governed by the [META LLAMA 3 COMMUNITY LICENSE AGREEMENT](https://llama.meta.com/llama3/license/)
178
+