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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
---
|
4 |
+
language:
|
5 |
+
- en
|
6 |
+
- fr
|
7 |
+
- de
|
8 |
+
- es
|
9 |
+
- it
|
10 |
+
- pt
|
11 |
+
- ja
|
12 |
+
- ko
|
13 |
+
- zh
|
14 |
+
- ar
|
15 |
+
license: cc-by-nc-4.0
|
16 |
+
library_name: transformers
|
17 |
+
tags:
|
18 |
+
- GGUF
|
19 |
+
quantized_by: andrijdavid
|
20 |
+
---
|
21 |
+
# c4ai-command-r-plus-GGUF
|
22 |
+
- Original model: [c4ai-command-r-plus](https://huggingface.co/CohereForAI/c4ai-command-r-plus)
|
23 |
+
|
24 |
+
<!-- description start -->
|
25 |
+
## Description
|
26 |
+
|
27 |
+
This repo contains GGUF format model files for [c4ai-command-r-plus](https://huggingface.co/CohereForAI/c4ai-command-r-plus).
|
28 |
+
|
29 |
+
<!-- description end -->
|
30 |
+
<!-- README_GGUF.md-about-gguf start -->
|
31 |
+
### About GGUF
|
32 |
+
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.
|
33 |
+
Here is an incomplete list of clients and libraries that are known to support GGUF:
|
34 |
+
* [llama.cpp](https://github.com/ggerganov/llama.cpp). This is the source project for GGUF, providing both a Command Line Interface (CLI) and a server option.
|
35 |
+
* [text-generation-webui](https://github.com/oobabooga/text-generation-webui), Known as the most widely used web UI, this project boasts numerous features and powerful extensions, and supports GPU acceleration.
|
36 |
+
* [Ollama](https://github.com/jmorganca/ollama) Ollama is a lightweight and extensible framework designed for building and running language models locally. It features a simple API for creating, managing, and executing models, along with a library of pre-built models for use in various applications
|
37 |
+
* [KoboldCpp](https://github.com/LostRuins/koboldcpp), A comprehensive web UI offering GPU acceleration across all platforms and architectures, particularly renowned for storytelling.
|
38 |
+
* [GPT4All](https://gpt4all.io), This is a free and open source GUI that runs locally, supporting Windows, Linux, and macOS with full GPU acceleration.
|
39 |
+
* [LM Studio](https://lmstudio.ai/) An intuitive and powerful local GUI for Windows and macOS (Silicon), featuring GPU acceleration.
|
40 |
+
* [LoLLMS Web UI](https://github.com/ParisNeo/lollms-webui). A notable web UI with a variety of unique features, including a comprehensive model library for easy model selection.
|
41 |
+
* [Faraday.dev](https://faraday.dev/), An attractive, user-friendly character-based chat GUI for Windows and macOS (both Silicon and Intel), also offering GPU acceleration.
|
42 |
+
* [llama-cpp-python](https://github.com/abetlen/llama-cpp-python), A Python library equipped with GPU acceleration, LangChain support, and an OpenAI-compatible API server.
|
43 |
+
* [candle](https://github.com/huggingface/candle), A Rust-based ML framework focusing on performance, including GPU support, and designed for ease of use.
|
44 |
+
* [ctransformers](https://github.com/marella/ctransformers), A Python library featuring GPU acceleration, LangChain support, and an OpenAI-compatible AI server.
|
45 |
+
* [localGPT](https://github.com/PromtEngineer/localGPT) An open-source initiative enabling private conversations with documents.
|
46 |
+
<!-- README_GGUF.md-about-gguf end -->
|
47 |
+
|
48 |
+
<!-- compatibility_gguf start -->
|
49 |
+
## Explanation of quantisation methods
|
50 |
+
<details>
|
51 |
+
<summary>Click to see details</summary>
|
52 |
+
The new methods available are:
|
53 |
+
|
54 |
+
* GGML_TYPE_Q2_K - "type-1" 2-bit quantization in super-blocks containing 16 blocks, each block having 16 weight. Block scales and mins are quantized with 4 bits. This ends up effectively using 2.5625 bits per weight (bpw)
|
55 |
+
* GGML_TYPE_Q3_K - "type-0" 3-bit quantization in super-blocks containing 16 blocks, each block having 16 weights. Scales are quantized with 6 bits. This end up using 3.4375 bpw.
|
56 |
+
* GGML_TYPE_Q4_K - "type-1" 4-bit quantization in super-blocks containing 8 blocks, each block having 32 weights. Scales and mins are quantized with 6 bits. This ends up using 4.5 bpw.
|
57 |
+
* GGML_TYPE_Q5_K - "type-1" 5-bit quantization. Same super-block structure as GGML_TYPE_Q4_K resulting in 5.5 bpw
|
58 |
+
* GGML_TYPE_Q6_K - "type-0" 6-bit quantization. Super-blocks with 16 blocks, each block having 16 weights. Scales are quantized with 8 bits. This ends up using 6.5625 bpw.
|
59 |
+
</details>
|
60 |
+
<!-- compatibility_gguf end -->
|
61 |
+
|
62 |
+
<!-- README_GGUF.md-how-to-download start -->
|
63 |
+
## How to download GGUF files
|
64 |
+
|
65 |
+
**Note for manual downloaders:** You almost never want to clone the entire repo! Multiple different quantisation formats are provided, and most users only want to pick and download a single folder.
|
66 |
+
|
67 |
+
The following clients/libraries will automatically download models for you, providing a list of available models to choose from:
|
68 |
+
|
69 |
+
* LM Studio
|
70 |
+
* LoLLMS Web UI
|
71 |
+
* Faraday.dev
|
72 |
+
|
73 |
+
### In `text-generation-webui`
|
74 |
+
|
75 |
+
Under Download Model, you can enter the model repo: LiteLLMs/c4ai-command-r-plus-GGUF and below it, a specific filename to download, such as: Q4_0/Q4_0-00001-of-00009.gguf.
|
76 |
+
|
77 |
+
Then click Download.
|
78 |
+
|
79 |
+
### On the command line, including multiple files at once
|
80 |
+
|
81 |
+
I recommend using the `huggingface-hub` Python library:
|
82 |
+
|
83 |
+
```shell
|
84 |
+
pip3 install huggingface-hub
|
85 |
+
```
|
86 |
+
|
87 |
+
Then you can download any individual model file to the current directory, at high speed, with a command like this:
|
88 |
+
|
89 |
+
```shell
|
90 |
+
huggingface-cli download LiteLLMs/c4ai-command-r-plus-GGUF Q4_0/Q4_0-00001-of-00009.gguf --local-dir . --local-dir-use-symlinks False
|
91 |
+
```
|
92 |
+
|
93 |
+
<details>
|
94 |
+
<summary>More advanced huggingface-cli download usage (click to read)</summary>
|
95 |
+
|
96 |
+
You can also download multiple files at once with a pattern:
|
97 |
+
|
98 |
+
```shell
|
99 |
+
huggingface-cli download LiteLLMs/c4ai-command-r-plus-GGUF --local-dir . --local-dir-use-symlinks False --include='*Q4_K*gguf'
|
100 |
+
```
|
101 |
+
|
102 |
+
For more documentation on downloading with `huggingface-cli`, please see: [HF -> Hub Python Library -> Download files -> Download from the CLI](https://huggingface.co/docs/huggingface_hub/guides/download#download-from-the-cli).
|
103 |
+
|
104 |
+
To accelerate downloads on fast connections (1Gbit/s or higher), install `hf_transfer`:
|
105 |
+
|
106 |
+
```shell
|
107 |
+
pip3 install huggingface_hub[hf_transfer]
|
108 |
+
```
|
109 |
+
|
110 |
+
And set environment variable `HF_HUB_ENABLE_HF_TRANSFER` to `1`:
|
111 |
+
|
112 |
+
```shell
|
113 |
+
HF_HUB_ENABLE_HF_TRANSFER=1 huggingface-cli download LiteLLMs/c4ai-command-r-plus-GGUF Q4_0/Q4_0-00001-of-00009.gguf --local-dir . --local-dir-use-symlinks False
|
114 |
+
```
|
115 |
+
|
116 |
+
Windows Command Line users: You can set the environment variable by running `set HF_HUB_ENABLE_HF_TRANSFER=1` before the download command.
|
117 |
+
</details>
|
118 |
+
<!-- README_GGUF.md-how-to-download end -->
|
119 |
+
<!-- README_GGUF.md-how-to-run start -->
|
120 |
+
## Example `llama.cpp` command
|
121 |
+
|
122 |
+
Make sure you are using `llama.cpp` from commit [d0cee0d](https://github.com/ggerganov/llama.cpp/commit/d0cee0d36d5be95a0d9088b674dbb27354107221) or later.
|
123 |
+
|
124 |
+
```shell
|
125 |
+
./main -ngl 35 -m Q4_0/Q4_0-00001-of-00009.gguf --color -c 8192 --temp 0.7 --repeat_penalty 1.1 -n -1 -p "<PROMPT>"
|
126 |
+
```
|
127 |
+
|
128 |
+
Change `-ngl 32` to the number of layers to offload to GPU. Remove it if you don't have GPU acceleration.
|
129 |
+
|
130 |
+
Change `-c 8192` to the desired sequence length. For extended sequence models - eg 8K, 16K, 32K - the necessary RoPE scaling parameters are read from the GGUF file and set by llama.cpp automatically. Note that longer sequence lengths require much more resources, so you may need to reduce this value.
|
131 |
+
|
132 |
+
If you want to have a chat-style conversation, replace the `-p <PROMPT>` argument with `-i -ins`
|
133 |
+
|
134 |
+
For other parameters and how to use them, please refer to [the llama.cpp documentation](https://github.com/ggerganov/llama.cpp/blob/master/examples/main/README.md)
|
135 |
+
|
136 |
+
## How to run in `text-generation-webui`
|
137 |
+
|
138 |
+
Further instructions can be found in the text-generation-webui documentation, here: [text-generation-webui/docs/04 ‐ Model Tab.md](https://github.com/oobabooga/text-generation-webui/blob/main/docs/04%20%E2%80%90%20Model%20Tab.md#llamacpp).
|
139 |
+
|
140 |
+
## How to run from Python code
|
141 |
+
|
142 |
+
You can use GGUF models from Python using the [llama-cpp-python](https://github.com/abetlen/llama-cpp-python) or [ctransformers](https://github.com/marella/ctransformers) libraries. Note that at the time of writing (Nov 27th 2023), ctransformers has not been updated for some time and is not compatible with some recent models. Therefore I recommend you use llama-cpp-python.
|
143 |
+
|
144 |
+
### How to load this model in Python code, using llama-cpp-python
|
145 |
+
|
146 |
+
For full documentation, please see: [llama-cpp-python docs](https://abetlen.github.io/llama-cpp-python/).
|
147 |
+
|
148 |
+
#### First install the package
|
149 |
+
|
150 |
+
Run one of the following commands, according to your system:
|
151 |
+
|
152 |
+
```shell
|
153 |
+
# Base ctransformers with no GPU acceleration
|
154 |
+
pip install llama-cpp-python
|
155 |
+
# With NVidia CUDA acceleration
|
156 |
+
CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python
|
157 |
+
# Or with OpenBLAS acceleration
|
158 |
+
CMAKE_ARGS="-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS" pip install llama-cpp-python
|
159 |
+
# Or with CLBLast acceleration
|
160 |
+
CMAKE_ARGS="-DLLAMA_CLBLAST=on" pip install llama-cpp-python
|
161 |
+
# Or with AMD ROCm GPU acceleration (Linux only)
|
162 |
+
CMAKE_ARGS="-DLLAMA_HIPBLAS=on" pip install llama-cpp-python
|
163 |
+
# Or with Metal GPU acceleration for macOS systems only
|
164 |
+
CMAKE_ARGS="-DLLAMA_METAL=on" pip install llama-cpp-python
|
165 |
+
# In windows, to set the variables CMAKE_ARGS in PowerShell, follow this format; eg for NVidia CUDA:
|
166 |
+
$env:CMAKE_ARGS = "-DLLAMA_OPENBLAS=on"
|
167 |
+
pip install llama-cpp-python
|
168 |
+
```
|
169 |
+
|
170 |
+
#### Simple llama-cpp-python example code
|
171 |
+
|
172 |
+
```python
|
173 |
+
from llama_cpp import Llama
|
174 |
+
# Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system.
|
175 |
+
llm = Llama(
|
176 |
+
model_path="./Q4_0/Q4_0-00001-of-00009.gguf", # Download the model file first
|
177 |
+
n_ctx=32768, # The max sequence length to use - note that longer sequence lengths require much more resources
|
178 |
+
n_threads=8, # The number of CPU threads to use, tailor to your system and the resulting performance
|
179 |
+
n_gpu_layers=35 # The number of layers to offload to GPU, if you have GPU acceleration available
|
180 |
+
)
|
181 |
+
# Simple inference example
|
182 |
+
output = llm(
|
183 |
+
"<PROMPT>", # Prompt
|
184 |
+
max_tokens=512, # Generate up to 512 tokens
|
185 |
+
stop=["</s>"], # Example stop token - not necessarily correct for this specific model! Please check before using.
|
186 |
+
echo=True # Whether to echo the prompt
|
187 |
+
)
|
188 |
+
# Chat Completion API
|
189 |
+
llm = Llama(model_path="./Q4_0/Q4_0-00001-of-00009.gguf", chat_format="llama-2") # Set chat_format according to the model you are using
|
190 |
+
llm.create_chat_completion(
|
191 |
+
messages = [
|
192 |
+
{"role": "system", "content": "You are a story writing assistant."},
|
193 |
+
{
|
194 |
+
"role": "user",
|
195 |
+
"content": "Write a story about llamas."
|
196 |
+
}
|
197 |
+
]
|
198 |
+
)
|
199 |
+
```
|
200 |
+
|
201 |
+
## How to use with LangChain
|
202 |
+
|
203 |
+
Here are guides on using llama-cpp-python and ctransformers with LangChain:
|
204 |
+
|
205 |
+
* [LangChain + llama-cpp-python](https://python.langchain.com/docs/integrations/llms/llamacpp)
|
206 |
+
* [LangChain + ctransformers](https://python.langchain.com/docs/integrations/providers/ctransformers)
|
207 |
+
|
208 |
+
<!-- README_GGUF.md-how-to-run end -->
|
209 |
+
|
210 |
+
<!-- footer end -->
|
211 |
+
|
212 |
+
<!-- original-model-card start -->
|
213 |
+
# Original model card: c4ai-command-r-plus
|
214 |
+
|
215 |
+
|
216 |
+
# Model Card for C4AI Command R+
|
217 |
+
|
218 |
+
🚨 **This model is non-quantized version of C4AI Command R+. You can find the quantized version of C4AI Command R+ using bitsandbytes [here](https://huggingface.co/CohereForAI/c4ai-command-r-plus-4bit)**.
|
219 |
+
|
220 |
+
|
221 |
+
## Model Summary
|
222 |
+
|
223 |
+
C4AI Command R+ is an open weights research release of a 104B billion parameter model with highly advanced capabilities, this includes Retrieval Augmented Generation (RAG) and tool use to automate sophisticated tasks. The tool use in this model generation enables multi-step tool use which allows the model to combine multiple tools over multiple steps to accomplish difficult tasks. C4AI Command R+ is a multilingual model evaluated in 10 languages for performance: English, French, Spanish, Italian, German, Brazilian Portuguese, Japanese, Korean, Arabic, and Simplified Chinese. Command R+ is optimized for a variety of use cases including reasoning, summarization, and question answering.
|
224 |
+
|
225 |
+
C4AI Command R+ is part of a family of open weight releases from Cohere For AI and Cohere. Our smaller companion model is [C4AI Command R](https://huggingface.co/CohereForAI/c4ai-command-r-v01)
|
226 |
+
|
227 |
+
Developed by: [Cohere](https://cohere.com/) and [Cohere For AI](https://cohere.for.ai)
|
228 |
+
|
229 |
+
- Point of Contact: Cohere For AI: [cohere.for.ai](https://cohere.for.ai/)
|
230 |
+
- License: [CC-BY-NC](https://cohere.com/c4ai-cc-by-nc-license), requires also adhering to [C4AI's Acceptable Use Policy](https://docs.cohere.com/docs/c4ai-acceptable-use-policy)
|
231 |
+
- Model: c4ai-command-r-plus
|
232 |
+
- Model Size: 104 billion parameters
|
233 |
+
- Context length: 128K
|
234 |
+
|
235 |
+
**Try C4AI Command R+**
|
236 |
+
|
237 |
+
You can try out C4AI Command R+ before downloading the weights in our hosted [Hugging Face Space](https://huggingface.co/spaces/CohereForAI/c4ai-command-r-plus).
|
238 |
+
|
239 |
+
**Usage**
|
240 |
+
|
241 |
+
Please install `transformers` from the source repository that includes the necessary changes for this model.
|
242 |
+
```python
|
243 |
+
# pip install 'git+https://github.com/huggingface/transformers.git'
|
244 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
245 |
+
|
246 |
+
model_id = "CohereForAI/c4ai-command-r-plus"
|
247 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
248 |
+
model = AutoModelForCausalLM.from_pretrained(model_id)
|
249 |
+
|
250 |
+
# Format message with the command-r-plus chat template
|
251 |
+
messages = [{"role": "user", "content": "Hello, how are you?"}]
|
252 |
+
input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
|
253 |
+
## <BOS_TOKEN><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
|
254 |
+
|
255 |
+
gen_tokens = model.generate(
|
256 |
+
input_ids,
|
257 |
+
max_new_tokens=100,
|
258 |
+
do_sample=True,
|
259 |
+
temperature=0.3,
|
260 |
+
)
|
261 |
+
|
262 |
+
gen_text = tokenizer.decode(gen_tokens[0])
|
263 |
+
print(gen_text)
|
264 |
+
```
|
265 |
+
|
266 |
+
**Quantized model through bitsandbytes, 8-bit precision**
|
267 |
+
|
268 |
+
```python
|
269 |
+
# pip install 'git+https://github.com/huggingface/transformers.git' bitsandbytes accelerate
|
270 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
271 |
+
|
272 |
+
bnb_config = BitsAndBytesConfig(load_in_8bit=True)
|
273 |
+
|
274 |
+
model_id = "CohereForAI/c4ai-command-r-plus"
|
275 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
276 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=bnb_config)
|
277 |
+
|
278 |
+
# Format message with the command-r-plus chat template
|
279 |
+
messages = [{"role": "user", "content": "Hello, how are you?"}]
|
280 |
+
input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
|
281 |
+
## <BOS_TOKEN><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
|
282 |
+
|
283 |
+
gen_tokens = model.generate(
|
284 |
+
input_ids,
|
285 |
+
max_new_tokens=100,
|
286 |
+
do_sample=True,
|
287 |
+
temperature=0.3,
|
288 |
+
)
|
289 |
+
|
290 |
+
gen_text = tokenizer.decode(gen_tokens[0])
|
291 |
+
print(gen_text)
|
292 |
+
```
|
293 |
+
|
294 |
+
**Quantized model through bitsandbytes, 4-bit precision**
|
295 |
+
|
296 |
+
This model is non-quantized version of C4AI Command R+. You can find the quantized version of C4AI Command R+ using bitsandbytes [here](https://huggingface.co/CohereForAI/c4ai-command-r-plus-4bit).
|
297 |
+
|
298 |
+
## Model Details
|
299 |
+
|
300 |
+
**Input**: Models input text only.
|
301 |
+
|
302 |
+
**Output**: Models generate text only.
|
303 |
+
|
304 |
+
**Model Architecture**: This is an auto-regressive language model that uses an optimized transformer architecture. After pretraining, this model uses supervised fine-tuning (SFT) and preference training to align model behavior to human preferences for helpfulness and safety.
|
305 |
+
|
306 |
+
**Languages covered**: The model is optimized to perform well in the following languages: English, French, Spanish, Italian, German, Brazilian Portuguese, Japanese, Korean, Simplified Chinese, and Arabic.
|
307 |
+
|
308 |
+
Pre-training data additionally included the following 13 languages: Russian, Polish, Turkish, Vietnamese, Dutch, Czech, Indonesian, Ukrainian, Romanian, Greek, Hindi, Hebrew, Persian.
|
309 |
+
|
310 |
+
**Context length**: Command R+ supports a context length of 128K.
|
311 |
+
|
312 |
+
## Evaluations
|
313 |
+
|
314 |
+
Command R+ has been submitted to the [Open LLM leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard). We include the results below, along with a direct comparison to the strongest state-of-art open weights models currently available on Hugging Face. We note that these results are only useful to compare when evaluations are implemented for all models in a [standardized way](https://github.com/EleutherAI/lm-evaluation-harness) using publically available code, and hence shouldn't be used for comparison outside of models submitted to the leaderboard or compared to self-reported numbers which can't be replicated in the same way.
|
315 |
+
|
316 |
+
| Model | Average | Arc (Challenge) | Hella Swag | MMLU | Truthful QA | Winogrande | GSM8k |
|
317 |
+
| : | -: | -: |
|
318 |
+
| **CohereForAI/c4ai-command-r-plus** | 74.6 | 70.99 | 88.6 | 75.7 | 56.3 | 85.4 | 70.7 |
|
319 |
+
| [DBRX Instruct](https://huggingface.co/databricks/dbrx-instruct) | 74.5 | 68.9 | 89 | 73.7 | 66.9 | 81.8 | 66.9 |
|
320 |
+
| [Mixtral 8x7B-Instruct](https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1) | 72.7 | 70.1 | 87.6 | 71.4 | 65 | 81.1 | 61.1 |
|
321 |
+
| [Mixtral 8x7B Chat](https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1) | 72.6 | 70.2 | 87.6 | 71.2 | 64.6 | 81.4 | 60.7 |
|
322 |
+
| [CohereForAI/c4ai-command-r-v01](https://huggingface.co/CohereForAI/c4ai-command-r-v01) | 68.5 | 65.5 | 87 | 68.2 | 52.3 | 81.5 | 56.6 |
|
323 |
+
| [Llama 2 70B](https://huggingface.co/meta-llama/Llama-2-70b-hf) | 67.9 | 67.3 | 87.3 | 69.8 | 44.9 | 83.7 | 54.1 |
|
324 |
+
| [Yi-34B-Chat](https://huggingface.co/01-ai/Yi-34B-Chat) | 65.3 | 65.4 | 84.2 | 74.9 | 55.4 | 80.1 | 31.9 |
|
325 |
+
| [Gemma-7B](https://huggingface.co/google/gemma-7b) | 63.8 | 61.1 | 82.2 | 64.6 | 44.8 | 79 | 50.9 |
|
326 |
+
| [LLama 2 70B Chat](https://huggingface.co/meta-llama/Llama-2-70b-chat-hf) | 62.4 | 64.6 | 85.9 | 63.9 | 52.8 | 80.5 | 26.7 |
|
327 |
+
| [Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1) | 61 | 60 | 83.3 | 64.2 | 42.2 | 78.4 | 37.8 |
|
328 |
+
|
329 |
+
We include these metrics here because they are frequently requested, but note that these metrics do not capture RAG, multilingual, tooling performance or the evaluation of open ended generations which we believe Command R+ to be state-of-art at. For evaluations of RAG, multilingual and tooling read more [here](https://txt.cohere.com/command-r-plus-microsoft-azure/). For evaluation of open ended generation, Command R+ is currently being evaluated on the [chatbot arena](https://chat.lmsys.org/).
|
330 |
+
|
331 |
+
### Tool use & multihop capabilities:
|
332 |
+
|
333 |
+
Command R+ has been specifically trained with conversational tool use capabilities. These have been trained into the model via a mixture of supervised fine-tuning and preference fine-tuning, using a specific prompt template. Deviating from this prompt template will likely reduce performance, but we encourage experimentation.
|
334 |
+
|
335 |
+
Command R+’s tool use functionality takes a conversation as input (with an optional user-system preamble), along with a list of available tools. The model will then generate a json-formatted list of actions to execute on a subset of those tools. Command R+ may use one of its supplied tools more than once.
|
336 |
+
|
337 |
+
The model has been trained to recognise a special `directly_answer` tool, which it uses to indicate that it doesn’t want to use any of its other tools. The ability to abstain from calling a specific tool can be useful in a range of situations, such as greeting a user, or asking clarifying questions.
|
338 |
+
We recommend including the `directly_answer` tool, but it can be removed or renamed if required.
|
339 |
+
|
340 |
+
Comprehensive documentation for working with command R+'s tool use prompt template can be found [here](https://docs.cohere.com/docs/prompting-command-r).
|
341 |
+
|
342 |
+
The code snippet below shows a minimal working example on how to render a prompt.
|
343 |
+
|
344 |
+
<details>
|
345 |
+
<summary><b>Usage: Rendering Tool Use Prompts [CLICK TO EXPAND]</b> </summary>
|
346 |
+
|
347 |
+
```python
|
348 |
+
from transformers import AutoTokenizer
|
349 |
+
|
350 |
+
model_id = "CohereForAI/c4ai-command-r-plus"
|
351 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
352 |
+
|
353 |
+
# define conversation input:
|
354 |
+
conversation = [
|
355 |
+
{"role": "user", "content": "Whats the biggest penguin in the world?"}
|
356 |
+
]
|
357 |
+
# Define tools available for the model to use:
|
358 |
+
tools = [
|
359 |
+
{
|
360 |
+
"name": "internet_search",
|
361 |
+
"description": "Returns a list of relevant document snippets for a textual query retrieved from the internet",
|
362 |
+
"parameter_definitions": {
|
363 |
+
"query": {
|
364 |
+
"description": "Query to search the internet with",
|
365 |
+
"type": 'str',
|
366 |
+
"required": True
|
367 |
+
}
|
368 |
+
}
|
369 |
+
},
|
370 |
+
{
|
371 |
+
'name': "directly_answer",
|
372 |
+
"description": "Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history",
|
373 |
+
'parameter_definitions': {}
|
374 |
+
}
|
375 |
+
]
|
376 |
+
|
377 |
+
# render the tool use prompt as a string:
|
378 |
+
tool_use_prompt = tokenizer.apply_tool_use_template(
|
379 |
+
conversation,
|
380 |
+
tools=tools,
|
381 |
+
tokenize=False,
|
382 |
+
add_generation_prompt=True,
|
383 |
+
)
|
384 |
+
print(tool_use_prompt)
|
385 |
+
```
|
386 |
+
|
387 |
+
</details>
|
388 |
+
|
389 |
+
<details>
|
390 |
+
<summary><b>Example Rendered Tool Use Prompt [CLICK TO EXPAND]</b></summary>
|
391 |
+
|
392 |
+
````
|
393 |
+
<BOS_TOKEN><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Safety Preamble
|
394 |
+
The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.
|
395 |
+
|
396 |
+
# System Preamble
|
397 |
+
## Basic Rules
|
398 |
+
You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.
|
399 |
+
|
400 |
+
# User Preamble
|
401 |
+
## Task and Context
|
402 |
+
You help people answer their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You should focus on serving the user's needs as best you can, which will be wide-ranging.
|
403 |
+
|
404 |
+
## Style Guide
|
405 |
+
Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.
|
406 |
+
|
407 |
+
## Available Tools
|
408 |
+
Here is a list of tools that you have available to you:
|
409 |
+
|
410 |
+
```python
|
411 |
+
def internet_search(query: str) -> List[Dict]:
|
412 |
+
"""Returns a list of relevant document snippets for a textual query retrieved from the internet
|
413 |
+
|
414 |
+
Args:
|
415 |
+
query (str): Query to search the internet with
|
416 |
+
"""
|
417 |
+
pass
|
418 |
+
```
|
419 |
+
|
420 |
+
```python
|
421 |
+
def directly_answer() -> List[Dict]:
|
422 |
+
"""Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history
|
423 |
+
"""
|
424 |
+
pass
|
425 |
+
```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Whats the biggest penguin in the world?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Write 'Action:' followed by a json-formatted list of actions that you want to perform in order to produce a good response to the user's last input. You can use any of the supplied tools any number of times, but you should aim to execute the minimum number of necessary actions for the input. You should use the `directly-answer` tool if calling the other tools is unnecessary. The list of actions you want to call should be formatted as a list of json objects, for example:
|
426 |
+
```json
|
427 |
+
[
|
428 |
+
{
|
429 |
+
"tool_name": title of the tool in the specification,
|
430 |
+
"parameters": a dict of parameters to input into the tool as they are defined in the specs, or {} if it takes no parameters
|
431 |
+
}
|
432 |
+
]```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
|
433 |
+
|
434 |
+
````
|
435 |
+
|
436 |
+
</details>
|
437 |
+
|
438 |
+
<details>
|
439 |
+
<summary><b>Example Rendered Tool Use Completion [CLICK TO EXPAND]</b></summary>
|
440 |
+
|
441 |
+
````
|
442 |
+
Action: ```json
|
443 |
+
[
|
444 |
+
{
|
445 |
+
"tool_name": "internet_search",
|
446 |
+
"parameters": {
|
447 |
+
"query": "biggest penguin in the world"
|
448 |
+
}
|
449 |
+
}
|
450 |
+
]
|
451 |
+
```
|
452 |
+
````
|
453 |
+
</details>
|
454 |
+
|
455 |
+
### Grounded Generation and RAG Capabilities:
|
456 |
+
|
457 |
+
Command R+ has been specifically trained with grounded generation capabilities. This means that it can generate responses based on a list of supplied document snippets, and it will include grounding spans (citations) in its response indicating the source of the information. This can be used to enable behaviors such as grounded summarization and the final step of Retrieval Augmented Generation (RAG). This behavior has been trained into the model via a mixture of supervised fine-tuning and preference fine-tuning, using a specific prompt template. Deviating from this prompt template may reduce performance, but we encourage experimentation.
|
458 |
+
|
459 |
+
Command R+’s grounded generation behavior takes a conversation as input (with an optional user-supplied system preamble, indicating task, context and desired output style), along with a list of retrieved document snippets. The document snippets should be chunks, rather than long documents, typically around 100-400 words per chunk. Document snippets consist of key-value pairs. The keys should be short descriptive strings, the values can be text or semi-structured.
|
460 |
+
|
461 |
+
By default, Command R+ will generate grounded responses by first predicting which documents are relevant, then predicting which ones it will cite, then generating an answer. Finally, it will then insert grounding spans into the answer. See below for an example. This is referred to as `accurate` grounded generation.
|
462 |
+
|
463 |
+
The model is trained with a number of other answering modes, which can be selected by prompt changes. A `fast` citation mode is supported in the tokenizer, which will directly generate an answer with grounding spans in it, without first writing the answer out in full. This sacrifices some grounding accuracy in favor of generating fewer tokens.
|
464 |
+
|
465 |
+
Comprehensive documentation for working with Command R+'s grounded generation prompt template can be found [here](https://docs.cohere.com/docs/prompting-command-r).
|
466 |
+
|
467 |
+
The code snippet below shows a minimal working example on how to render a prompt.
|
468 |
+
|
469 |
+
<details>
|
470 |
+
<summary> <b>Usage: Rendering Grounded Generation prompts [CLICK TO EXPAND]</b> </summary>
|
471 |
+
|
472 |
+
````python
|
473 |
+
from transformers import AutoTokenizer
|
474 |
+
|
475 |
+
model_id = "CohereForAI/c4ai-command-r-plus"
|
476 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
477 |
+
|
478 |
+
# define conversation input:
|
479 |
+
conversation = [
|
480 |
+
{"role": "user", "content": "Whats the biggest penguin in the world?"}
|
481 |
+
]
|
482 |
+
# define documents to ground on:
|
483 |
+
documents = [
|
484 |
+
{ "title": "Tall penguins", "text": "Emperor penguins are the tallest growing up to 122 cm in height." },
|
485 |
+
{ "title": "Penguin habitats", "text": "Emperor penguins only live in Antarctica."}
|
486 |
+
]
|
487 |
+
|
488 |
+
# render the tool use prompt as a string:
|
489 |
+
grounded_generation_prompt = tokenizer.apply_grounded_generation_template(
|
490 |
+
conversation,
|
491 |
+
documents=documents,
|
492 |
+
citation_mode="accurate", # or "fast"
|
493 |
+
tokenize=False,
|
494 |
+
add_generation_prompt=True,
|
495 |
+
)
|
496 |
+
print(grounded_generation_prompt)
|
497 |
+
````
|
498 |
+
</details>
|
499 |
+
|
500 |
+
<details>
|
501 |
+
<summary><b>Example Rendered Grounded Generation Prompt [CLICK TO EXPAND]</b></summary>
|
502 |
+
|
503 |
+
````<BOS_TOKEN><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Safety Preamble
|
504 |
+
The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.
|
505 |
+
|
506 |
+
# System Preamble
|
507 |
+
## Basic Rules
|
508 |
+
You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.
|
509 |
+
|
510 |
+
# User Preamble
|
511 |
+
## Task and Context
|
512 |
+
You help people answer their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You should focus on serving the user's needs as best you can, which will be wide-ranging.
|
513 |
+
|
514 |
+
## Style Guide
|
515 |
+
Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Whats the biggest penguin in the world?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><results>
|
516 |
+
Document: 0
|
517 |
+
title: Tall penguins
|
518 |
+
text: Emperor penguins are the tallest growing up to 122 cm in height.
|
519 |
+
|
520 |
+
Document: 1
|
521 |
+
title: Penguin habitats
|
522 |
+
text: Emperor penguins only live in Antarctica.
|
523 |
+
</results><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Carefully perform the following instructions, in order, starting each with a new line.
|
524 |
+
Firstly, Decide which of the retrieved documents are relevant to the user's last input by writing 'Relevant Documents:' followed by comma-separated list of document numbers. If none are relevant, you should instead write 'None'.
|
525 |
+
Secondly, Decide which of the retrieved documents contain facts that should be cited in a good answer to the user's last input by writing 'Cited Documents:' followed a comma-separated list of document numbers. If you dont want to cite any of them, you should instead write 'None'.
|
526 |
+
Thirdly, Write 'Answer:' followed by a response to the user's last input in high quality natural english. Use the retrieved documents to help you. Do not insert any citations or grounding markup.
|
527 |
+
Finally, Write 'Grounded answer:' followed by a response to the user's last input in high quality natural english. Use the symbols <co: doc> and </co: doc> to indicate when a fact comes from a document in the search result, e.g <co: 0>my fact</co: 0> for a fact from document 0.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
|
528 |
+
````
|
529 |
+
|
530 |
+
</details>
|
531 |
+
|
532 |
+
<details>
|
533 |
+
<summary><b>Example Rendered Grounded Generation Completion [CLICK TO EXPAND]</b></summary>
|
534 |
+
|
535 |
+
````
|
536 |
+
Relevant Documents: 0,1
|
537 |
+
Cited Documents: 0,1
|
538 |
+
Answer: The Emperor Penguin is the tallest or biggest penguin in the world. It is a bird that lives only in Antarctica and grows to a height of around 122 centimetres.
|
539 |
+
Grounded answer: The <co: 0>Emperor Penguin</co: 0> is the <co: 0>tallest</co: 0> or biggest penguin in the world. It is a bird that <co: 1>lives only in Antarctica</co: 1> and <co: 0>grows to a height of around 122 centimetres.</co: 0>
|
540 |
+
````
|
541 |
+
</details>
|
542 |
+
|
543 |
+
### Code Capabilities:
|
544 |
+
Command R+ has been optimized to interact with your code, by requesting code snippets, code explanations, or code rewrites. It might not perform well out-of-the-box for pure code completion. For better performance, we also recommend using a low temperature (and even greedy decoding) for code-generation related instructions.
|
545 |
+
|
546 |
+
### Model Card Contact
|
547 |
+
For errors or additional questions about details in this model card, contact [info@for.ai](mailto:info@for.ai).
|
548 |
+
|
549 |
+
### Terms of Use:
|
550 |
+
We hope that the release of this model will make community-based research efforts more accessible, by releasing the weights of a highly performant 104 billion parameter model to researchers all over the world. This model is governed by a [CC-BY-NC](https://cohere.com/c4ai-cc-by-nc-license) License with an acceptable use addendum, and also requires adhering to [C4AI's Acceptable Use Policy](https://docs.cohere.com/docs/c4ai-acceptable-use-policy).
|
551 |
+
|
552 |
+
### Try Chat:
|
553 |
+
You can try Command R+ chat in the playground [here](https://dashboard.cohere.com/playground/chat). You can also use it in our dedicated Hugging Face Space [here](https://huggingface.co/spaces/CohereForAI/c4ai-command-r-plus).
|
554 |
+
|
555 |
+
<!-- original-model-card end -->
|