Initial commit
Browse files- .gitattributes +1 -0
- README.md +142 -0
- config.json +95 -0
- generation_config.json +11 -0
- metadata.pt +3 -0
- model.safetensors +3 -0
- onebit_linear.py +207 -0
- requirements.txt +6 -0
- special_tokens_map.json +34 -0
- tokenizer.json +3 -0
- tokenizer_config.json +360 -0
.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 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
inference: false
|
| 3 |
+
base_model: c4ai/command-a-03-2025
|
| 4 |
+
pipeline_tag: text-generation
|
| 5 |
+
model_type: command-a
|
| 6 |
+
tags:
|
| 7 |
+
- quantization
|
| 8 |
+
- onebit
|
| 9 |
+
- compression
|
| 10 |
+
- command-a
|
| 11 |
+
- text-generation
|
| 12 |
+
library_name: transformers
|
| 13 |
+
language:
|
| 14 |
+
- en
|
| 15 |
+
- ja
|
| 16 |
+
license: cc-by-nc-4.0
|
| 17 |
+
extra_gated_prompt: "By submitting this form, you agree to the [License Agreement](https://cohere.com/c4ai-cc-by-nc-license) and acknowledge that the information you provide will be collected, used, and shared in accordance with Cohere’s [Privacy Policy]( https://cohere.com/privacy). You’ll receive email updates about Cohere Labs and Cohere research, events, products and services. You can unsubscribe at any time."
|
| 18 |
+
extra_gated_fields:
|
| 19 |
+
Name: text
|
| 20 |
+
Affiliation: text
|
| 21 |
+
Country: country
|
| 22 |
+
I agree to use this model for non-commercial use ONLY: checkbox
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
# **Model Card for qep qep 1bit extreme**
|
| 28 |
+
|
| 29 |
+
🚨 **This model is 1bit quantized version of Cohere Labs Command A using QEP.** You can find the unquantized version of Cohere Labs Command A [here](https://huggingface.co/CohereLabs/c4ai-command-a-03-2025).
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
## **Model Summary**
|
| 33 |
+
|
| 34 |
+
An optimized 1-bit quantized version of [c4ai/command-a-03-2025](https://huggingface.co/c4ai/command-a-03-2025) achieving **6.7x compression** with enhanced performance through advanced quantization optimization techniques.
|
| 35 |
+
|
| 36 |
+
## Key Features
|
| 37 |
+
|
| 38 |
+
- **Extreme Compression**: 6.7× smaller (207GB → 30.2GB, -85%), runs even on a single GPU (30B on A100 80GB).
|
| 39 |
+
- **Enhanced Performance**: [Onebit](https://arxiv.org/abs/2402.11295) quantization, enhanced by Fujitsu [QEP](https://arxiv.org/abs/2504.09629) & [QQA](https://iclr.cc/virtual/2025/poster/30713).
|
| 40 |
+
- **Inference Speed Up**: Faster inference via "Bitlinear computation".
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
## Model Details
|
| 44 |
+
|
| 45 |
+
- **Base Model**: c4ai/command-a-03-2025
|
| 46 |
+
- **Quantization Method**: [OneBit](https://openreview.net/forum?id=ZwiG9KjfHV) with Fujitsu [QEP](https://arxiv.org/abs/2504.09629)/[QQA](https://iclr.cc/virtual/2025/poster/30713) optimization
|
| 47 |
+
- **Quantization Bits**: 1-bit for layers 0-61, FP16 for last 2 layers
|
| 48 |
+
- **Optimization Techniques**: Fujitsu [QEP](https://arxiv.org/abs/2504.09629), [QQA](https://iclr.cc/virtual/2025/poster/30713)
|
| 49 |
+
- **Compatible Hardware**: Single GPU (recommended: >= 40GB VRAM)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Developed by: [Fujitsu](https:/fujitsu.com/), [Cohere](https://cohere.com/) and [Cohere Labs](https://cohere.for.ai/)
|
| 53 |
+
|
| 54 |
+
* Point of Contact: [Contact form](https://contactline.jp.fujitsu.com/customform/csque04802/873532/) or [Email]([email protected])
|
| 55 |
+
* License:[CC-BY-NC](https://cohere.com/cohere-labs-cc-by-nc-license), requires also adhering to [Cohere Lab's Acceptable Use Policy](https://docs.cohere.com/docs/cohere-labs-acceptable-use-policy)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
For more details on how this model was developed, check out our [Press Release (English)](https://global.fujitsu/en-global/newsroom/gl/2025/08/29-01), [Press Release (Japanese)](https://global.fujitsu/ja-jp/pr/news/2025/08/29-01) Fujitsu's [Tech Report](https://arxiv.org/abs/2504.09629) and Cohere's [Tech Report](https://arxiv.org/abs/2504.00698).
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
## Usage
|
| 64 |
+
|
| 65 |
+
The base architecture of this model is **Command-A**. To load and use the model, please use the **CommandA model class**:
|
| 66 |
+
|
| 67 |
+
1. Load `model.safetensors`, which contains the quantized weights.
|
| 68 |
+
2. Replace all layers **except the last two** with **bitlinear implementations**.
|
| 69 |
+
3. Keep the **last two layers with non-quantized weights** for optimal performance.
|
| 70 |
+
4. The model requires the included `onebit_linear.py` for proper quantized layer implementation. The weights contain parameters for each of the **OneBit-specific a, S, and b components** necessary for reconstruction.
|
| 71 |
+
5. Depending on the level of performance you wish to maintain, you may keep additional layers near the output unquantized.
|
| 72 |
+
|
| 73 |
+
**Note:** Direct loading support as an extension of the `transformers` package is planned for future releases.
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
## Requirements
|
| 77 |
+
```
|
| 78 |
+
torch>=2.0.0
|
| 79 |
+
transformers>=4.35.0
|
| 80 |
+
safetensors>=0.4.0
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
## Performance
|
| 85 |
+
|
| 86 |
+
- **Memory Usage**: 6.7x reduction overall (207GB → 30.2GB)
|
| 87 |
+
- **Inference Speed**: Optimized for fast generation on single GPU
|
| 88 |
+
- **Quality**: Enhanced performance through [QEP](https://arxiv.org/abs/2504.09629)/[QQA](https://iclr.cc/virtual/2025/poster/30713) optimization
|
| 89 |
+
- **Compatibility**: Single GPU deployment capable
|
| 90 |
+
|
| 91 |
+
## Technical Specifications
|
| 92 |
+
|
| 93 |
+
- **Original Model**: Command-A (c4ai/command-a-03-2025)
|
| 94 |
+
- **Quantized Layers**: 62 layers (0-61) with 1-bit precision
|
| 95 |
+
- **Preserved Layers**: 2 layers (62-63) with FP16 precision
|
| 96 |
+
- **Compression Technique**: [OneBit](https://openreview.net/forum?id=ZwiG9KjfHV) + Fujitsu [QEP](https://arxiv.org/abs/2504.09629)/[QQA](https://iclr.cc/virtual/2025/poster/30713)
|
| 97 |
+
- **Model Size**: 30.2GB (from original 207GB)
|
| 98 |
+
|
| 99 |
+
## Future Plans
|
| 100 |
+
|
| 101 |
+
- **Global and Block-wise Fine-tuning**: Explore fine-tuning strategies, including block-wise methods, to further improve accuracy and robustness.
|
| 102 |
+
- **Complete Usage Examples**: Provide detailed implementation guides for efficient single-GPU deployment.
|
| 103 |
+
- **Optimization Updates**: Enhance performance with next-generation quantization techniques and improved reconstruction methods.
|
| 104 |
+
|
| 105 |
+
Currently, the quantization process preserves the last two layers in **non-quantized weights** to maintain output quality, while applying aggressive **1-bit quantization** to the remaining layers. Future releases will integrate **block-wise fine-tuning** for additional performance gains.
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
## Ethical Considerations
|
| 110 |
+
|
| 111 |
+
This model inherits the capabilities and limitations of the base Command A model. Please refer to the original model's documentation for ethical guidelines and potential biases.
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
## **Model Card Contact**
|
| 115 |
+
|
| 116 |
+
For errors or additional questions about details in this model card, contact [email protected]
|
| 117 |
+
|
| 118 |
+
## **Terms of Use:**
|
| 119 |
+
|
| 120 |
+
We hope that the release of this model will make community-based research efforts more accessible, by releasing the weights of a highly performant model to researchers all over the world. This model is governed by a [CC-BY-NC](https://cohere.com/cohere-labs-cc-by-nc-license), requires also adhering to [Cohere Lab's Acceptable Use Policy](https://docs.cohere.com/docs/cohere-labs-acceptable-use-policy)
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
## **Citation**
|
| 124 |
+
|
| 125 |
+
If you use this model, please cite:
|
| 126 |
+
|
| 127 |
+
```bibtex
|
| 128 |
+
@misc{command-a-onebit-hybrid,
|
| 129 |
+
title={Command-A 111B with QEP-Optimized OneBit Extreme Quantization},
|
| 130 |
+
author={Yuma Ichikawa, Yusei Kawakami, Yoshiyuki Ishii, Keiji Kimura and Akira Sakai},
|
| 131 |
+
year={2025},
|
| 132 |
+
publisher={Hugging Face},
|
| 133 |
+
url={https://huggingface.co/qep/qep-1bit-extreme}
|
| 134 |
+
}
|
| 135 |
+
```
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
## License
|
| 139 |
+
|
| 140 |
+
This quantized model is released under the same license as the base Command A model (CC-BY-NC-4.0).
|
| 141 |
+
|
| 142 |
+
---
|
config.json
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_type": "cohere2",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"Cohere2ForCausalLM"
|
| 5 |
+
],
|
| 6 |
+
|
| 7 |
+
"vocab_size": 256000,
|
| 8 |
+
"max_position_embeddings": 131072,
|
| 9 |
+
"hidden_size": 12288,
|
| 10 |
+
"logit_scale": 0.25,
|
| 11 |
+
"intermediate_size": 36864,
|
| 12 |
+
"num_hidden_layers": 64,
|
| 13 |
+
"num_attention_heads": 96,
|
| 14 |
+
"num_key_value_heads": 8,
|
| 15 |
+
"hidden_act": "silu",
|
| 16 |
+
"initializer_range": 0.02,
|
| 17 |
+
"layer_norm_eps": 1e-05,
|
| 18 |
+
"use_cache": false,
|
| 19 |
+
"rope_theta": 50000,
|
| 20 |
+
"rope_scaling": null,
|
| 21 |
+
"attention_bias": false,
|
| 22 |
+
"attention_dropout": 0.0,
|
| 23 |
+
"sliding_window": 4096,
|
| 24 |
+
"sliding_window_pattern": 4,
|
| 25 |
+
"head_dim": 128,
|
| 26 |
+
"cache_implementation": "hybrid",
|
| 27 |
+
"return_dict": true,
|
| 28 |
+
"output_hidden_states": false,
|
| 29 |
+
"output_attentions": false,
|
| 30 |
+
"torchscript": false,
|
| 31 |
+
"torch_dtype": "float16",
|
| 32 |
+
"use_bfloat16": false,
|
| 33 |
+
"tf_legacy_loss": false,
|
| 34 |
+
"pruned_heads": {},
|
| 35 |
+
"tie_word_embeddings": true,
|
| 36 |
+
"chunk_size_feed_forward": 0,
|
| 37 |
+
"is_encoder_decoder": false,
|
| 38 |
+
"is_decoder": false,
|
| 39 |
+
"cross_attention_hidden_size": null,
|
| 40 |
+
"add_cross_attention": false,
|
| 41 |
+
"tie_encoder_decoder": false,
|
| 42 |
+
"max_length": 20,
|
| 43 |
+
"min_length": 0,
|
| 44 |
+
"do_sample": false,
|
| 45 |
+
"early_stopping": false,
|
| 46 |
+
"num_beams": 1,
|
| 47 |
+
"num_beam_groups": 1,
|
| 48 |
+
"diversity_penalty": 0.0,
|
| 49 |
+
"temperature": 1.0,
|
| 50 |
+
"top_k": 50,
|
| 51 |
+
"top_p": 1.0,
|
| 52 |
+
"typical_p": 1.0,
|
| 53 |
+
"repetition_penalty": 1.0,
|
| 54 |
+
"length_penalty": 1.0,
|
| 55 |
+
"no_repeat_ngram_size": 0,
|
| 56 |
+
"encoder_no_repeat_ngram_size": 0,
|
| 57 |
+
"bad_words_ids": null,
|
| 58 |
+
"num_return_sequences": 1,
|
| 59 |
+
"output_scores": false,
|
| 60 |
+
"return_dict_in_generate": false,
|
| 61 |
+
"forced_bos_token_id": null,
|
| 62 |
+
"forced_eos_token_id": null,
|
| 63 |
+
"remove_invalid_values": false,
|
| 64 |
+
"exponential_decay_length_penalty": null,
|
| 65 |
+
"suppress_tokens": null,
|
| 66 |
+
"begin_suppress_tokens": null,
|
| 67 |
+
"finetuning_task": null,
|
| 68 |
+
"id2label": {
|
| 69 |
+
"0": "LABEL_0",
|
| 70 |
+
"1": "LABEL_1"
|
| 71 |
+
},
|
| 72 |
+
"label2id": {
|
| 73 |
+
"LABEL_0": 0,
|
| 74 |
+
"LABEL_1": 1
|
| 75 |
+
},
|
| 76 |
+
"tokenizer_class": null,
|
| 77 |
+
"prefix": null,
|
| 78 |
+
"bos_token_id": 5,
|
| 79 |
+
"pad_token_id": 0,
|
| 80 |
+
"eos_token_id": 255001,
|
| 81 |
+
"sep_token_id": null,
|
| 82 |
+
"decoder_start_token_id": null,
|
| 83 |
+
"task_specific_params": null,
|
| 84 |
+
"problem_type": null,
|
| 85 |
+
"_name_or_path": "/home/share-hdd/frj/genai/model/c4ai-command-a-03-2025",
|
| 86 |
+
"_attn_implementation_autoset": true,
|
| 87 |
+
"transformers_version": "4.49.0",
|
| 88 |
+
"order_of_interleaved_layers": "local_attn_first",
|
| 89 |
+
"position_embedding_type": "rope_gptj",
|
| 90 |
+
"rotary_pct": 1.0,
|
| 91 |
+
"use_embedding_sharing": true,
|
| 92 |
+
"use_gated_activation": true,
|
| 93 |
+
"use_parallel_block": true,
|
| 94 |
+
"use_parallel_embedding": true
|
| 95 |
+
}
|
generation_config.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 5,
|
| 4 |
+
"eos_token_id": 255001,
|
| 5 |
+
"pad_token_id": 0,
|
| 6 |
+
"max_new_tokens": 1024,
|
| 7 |
+
"temperature": 0.7,
|
| 8 |
+
"top_p": 0.9,
|
| 9 |
+
"do_sample": true,
|
| 10 |
+
"transformers_version": "4.49.0"
|
| 11 |
+
}
|
metadata.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fc252f55f7f5b7c0eee4a4d5dbe4d7c1c84f9bb7c43821c5e3fffc5988ea3aaf
|
| 3 |
+
size 996
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3c22c63cab68d9668814af75e9cda43d8ac3ff6e5ca8869248065a09aa35cfc5
|
| 3 |
+
size 32424145536
|
onebit_linear.py
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torch.nn as nn
|
| 3 |
+
import torch.nn.functional as F
|
| 4 |
+
from typing import Optional, Tuple
|
| 5 |
+
import numpy as np
|
| 6 |
+
import math
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def pack_sign_bits(sign_tensor: torch.Tensor) -> torch.Tensor:
|
| 10 |
+
sign_flat = sign_tensor.flatten()
|
| 11 |
+
sign_uint8 = ((sign_flat == 1).to(torch.uint8))
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
remainder = sign_uint8.numel() % 8
|
| 15 |
+
if remainder != 0:
|
| 16 |
+
padding = 8 - remainder
|
| 17 |
+
sign_uint8 = torch.cat([
|
| 18 |
+
sign_uint8,
|
| 19 |
+
torch.zeros(padding, dtype=torch.uint8, device=sign_uint8.device)
|
| 20 |
+
])
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
sign_uint8 = sign_uint8.reshape(-1, 8)
|
| 24 |
+
shifts = torch.arange(7, -1, -1, device=sign_uint8.device, dtype=torch.uint8)
|
| 25 |
+
packed = (sign_uint8 << shifts.unsqueeze(0)).sum(dim=1)
|
| 26 |
+
|
| 27 |
+
return packed
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def unpack_sign_bits_ultra_fast(packed: torch.Tensor, original_shape: torch.Size) -> torch.Tensor:
|
| 31 |
+
device = packed.device
|
| 32 |
+
dtype = torch.float16
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
int8_tensor = packed.to(torch.int8)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
shifts = torch.arange(8, device=device).view(1, 8)
|
| 39 |
+
expanded_int8 = int8_tensor.unsqueeze(-1)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
unpacked_bits = ((expanded_int8 >> shifts) & 1).to(dtype)
|
| 43 |
+
unpacked_bits = unpacked_bits.view(int8_tensor.shape[0], -1)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
fp16_tensor = -2 * unpacked_bits + 1
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
if isinstance(original_shape, (tuple, list)):
|
| 50 |
+
total_elements = 1
|
| 51 |
+
for dim in original_shape:
|
| 52 |
+
total_elements *= dim
|
| 53 |
+
original_shape = torch.Size(original_shape)
|
| 54 |
+
else:
|
| 55 |
+
total_elements = original_shape.numel()
|
| 56 |
+
|
| 57 |
+
return fp16_tensor.flatten()[:total_elements].reshape(original_shape)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def unpack_sign_bits(packed: torch.Tensor, original_shape: torch.Size) -> torch.Tensor:
|
| 61 |
+
return unpack_sign_bits_ultra_fast(packed, original_shape)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
class OneBitLinear(nn.Module):
|
| 65 |
+
|
| 66 |
+
def __init__(self,
|
| 67 |
+
in_features: int,
|
| 68 |
+
out_features: int,
|
| 69 |
+
a_scale: torch.Tensor = None,
|
| 70 |
+
b_scale: torch.Tensor = None,
|
| 71 |
+
weight_packed: torch.Tensor = None,
|
| 72 |
+
bias: Optional[torch.Tensor] = None,
|
| 73 |
+
device=None,
|
| 74 |
+
dtype=None):
|
| 75 |
+
factory_kwargs = {'device': device, 'dtype': dtype}
|
| 76 |
+
super().__init__()
|
| 77 |
+
|
| 78 |
+
self.in_features = in_features
|
| 79 |
+
self.out_features = out_features
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
if weight_packed is not None:
|
| 83 |
+
|
| 84 |
+
expected_size = out_features * in_features // 8
|
| 85 |
+
if weight_packed.numel() == expected_size:
|
| 86 |
+
weight_2d = weight_packed.view(out_features, in_features // 8).to(torch.int8)
|
| 87 |
+
else:
|
| 88 |
+
|
| 89 |
+
weight_2d = torch.zeros((out_features, in_features // 8), dtype=torch.int8, **factory_kwargs)
|
| 90 |
+
self.register_buffer("weight", weight_2d, persistent=False)
|
| 91 |
+
else:
|
| 92 |
+
|
| 93 |
+
self.register_buffer("weight", torch.zeros((out_features, in_features // 8),
|
| 94 |
+
dtype=torch.int8, **factory_kwargs), persistent=False)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
if a_scale is not None:
|
| 98 |
+
self.register_buffer("input_factor", a_scale.to(torch.float16))
|
| 99 |
+
else:
|
| 100 |
+
self.register_buffer("input_factor", torch.ones(in_features, dtype=torch.float16, **factory_kwargs))
|
| 101 |
+
|
| 102 |
+
if b_scale is not None:
|
| 103 |
+
self.register_buffer("weight_scale", b_scale.to(torch.float16))
|
| 104 |
+
else:
|
| 105 |
+
self.register_buffer("weight_scale", torch.ones(out_features, dtype=torch.float16, **factory_kwargs))
|
| 106 |
+
|
| 107 |
+
# Bias
|
| 108 |
+
if bias is not None:
|
| 109 |
+
self.register_buffer("bias", bias.to(torch.float16))
|
| 110 |
+
else:
|
| 111 |
+
self.bias = None
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
self.layernorm = nn.LayerNorm(out_features, elementwise_affine=False, **factory_kwargs)
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
self._weight_cache = None
|
| 118 |
+
|
| 119 |
+
def int8_to_fp16(self, int8_tensor):
|
| 120 |
+
dtype = self.weight_scale.dtype
|
| 121 |
+
shifts = torch.arange(8, device=int8_tensor.device).view(1, 1, 8)
|
| 122 |
+
|
| 123 |
+
expanded_int8 = int8_tensor.unsqueeze(-1)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
unpacked_bits = ((expanded_int8 >> shifts) & 1).to(dtype)
|
| 127 |
+
unpacked_bits = unpacked_bits.view(int8_tensor.shape[0], -1)
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
fp16_tensor = -2 * unpacked_bits + 1
|
| 131 |
+
return fp16_tensor
|
| 132 |
+
|
| 133 |
+
def forward(self, input):
|
| 134 |
+
input_factor_shape = [1] * len(input.shape)
|
| 135 |
+
input_factor_shape[-1] = self.in_features
|
| 136 |
+
input = input * self.input_factor.view(*input_factor_shape)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
if self._weight_cache is not None:
|
| 140 |
+
weight = self._weight_cache
|
| 141 |
+
else:
|
| 142 |
+
weight = self.int8_to_fp16(self.weight)
|
| 143 |
+
self._weight_cache = weight
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
output = F.linear(input, weight)
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
weight_scale_shape = [1] * len(output.shape)
|
| 150 |
+
weight_scale_shape[-1] = self.out_features
|
| 151 |
+
output *= self.weight_scale.view(*weight_scale_shape)
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
output = self.layernorm(output)
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
if self.bias is not None:
|
| 158 |
+
output += self.bias
|
| 159 |
+
|
| 160 |
+
return output
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
@classmethod
|
| 165 |
+
def from_safetensors(cls, state_dict: dict, layer_idx: int, module_name: str):
|
| 166 |
+
prefix = f"model.layers.{layer_idx}.{module_name}"
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
input_factor_key = f"{prefix}.input_factor"
|
| 170 |
+
weight_scale_key = f"{prefix}.weight_scale"
|
| 171 |
+
weight_key = f"{prefix}.weight"
|
| 172 |
+
bias_key = f"{prefix}.bias"
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
input_factor = None
|
| 176 |
+
if input_factor_key in state_dict:
|
| 177 |
+
input_factor = state_dict[input_factor_key]
|
| 178 |
+
elif f"{prefix}.a_scale" in state_dict:
|
| 179 |
+
input_factor = state_dict[f"{prefix}.a_scale"]
|
| 180 |
+
|
| 181 |
+
weight_scale = None
|
| 182 |
+
if weight_scale_key in state_dict:
|
| 183 |
+
weight_scale = state_dict[weight_scale_key]
|
| 184 |
+
elif f"{prefix}.b_scale" in state_dict:
|
| 185 |
+
weight_scale = state_dict[f"{prefix}.b_scale"]
|
| 186 |
+
weight_packed = None
|
| 187 |
+
if weight_key in state_dict:
|
| 188 |
+
weight_packed = state_dict[weight_key]
|
| 189 |
+
elif f"{prefix}.sign_packed" in state_dict:
|
| 190 |
+
weight_packed = state_dict[f"{prefix}.sign_packed"]
|
| 191 |
+
bias = state_dict.get(bias_key)
|
| 192 |
+
|
| 193 |
+
if input_factor is None or weight_scale is None:
|
| 194 |
+
return None
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
in_features = input_factor.shape[0]
|
| 198 |
+
out_features = weight_scale.shape[0]
|
| 199 |
+
|
| 200 |
+
return cls(
|
| 201 |
+
in_features=in_features,
|
| 202 |
+
out_features=out_features,
|
| 203 |
+
a_scale=input_factor,
|
| 204 |
+
b_scale=weight_scale,
|
| 205 |
+
weight_packed=weight_packed,
|
| 206 |
+
bias=bias
|
| 207 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# OneBit Model Requirements
|
| 2 |
+
torch>=2.0.0
|
| 3 |
+
transformers>=4.35.0
|
| 4 |
+
safetensors>=0.4.0
|
| 5 |
+
numpy>=1.24.0
|
| 6 |
+
accelerate>=0.24.0
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": {
|
| 3 |
+
"content": "<BOS_TOKEN>",
|
| 4 |
+
"lstrip": false,
|
| 5 |
+
"normalized": false,
|
| 6 |
+
"rstrip": false,
|
| 7 |
+
"single_word": false
|
| 8 |
+
},
|
| 9 |
+
"eos_token": {
|
| 10 |
+
"content": "<|END_OF_TURN_TOKEN|>",
|
| 11 |
+
"lstrip": false,
|
| 12 |
+
"normalized": false,
|
| 13 |
+
"rstrip": false,
|
| 14 |
+
"single_word": false
|
| 15 |
+
},
|
| 16 |
+
"pad_token": {
|
| 17 |
+
"content": "<PAD>",
|
| 18 |
+
"lstrip": false,
|
| 19 |
+
"normalized": false,
|
| 20 |
+
"rstrip": false,
|
| 21 |
+
"single_word": false
|
| 22 |
+
},
|
| 23 |
+
"unk_token": {
|
| 24 |
+
"content": "<UNK>",
|
| 25 |
+
"lstrip": false,
|
| 26 |
+
"normalized": false,
|
| 27 |
+
"rstrip": false,
|
| 28 |
+
"single_word": false
|
| 29 |
+
},
|
| 30 |
+
"additional_special_tokens": [
|
| 31 |
+
"<|START_RESPONSE|>",
|
| 32 |
+
"<|END_RESPONSE|>"
|
| 33 |
+
]
|
| 34 |
+
}
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5bad1341109519f60380bdefb784dbe92e1e044390109143baddf1fa53539e47
|
| 3 |
+
size 19597349
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_bos_token": true,
|
| 3 |
+
"add_eos_token": false,
|
| 4 |
+
"add_prefix_space": false,
|
| 5 |
+
"clean_up_tokenization_spaces": false,
|
| 6 |
+
"legacy": true,
|
| 7 |
+
"spaces_between_special_tokens": false,
|
| 8 |
+
"use_default_system_prompt": false,
|
| 9 |
+
"bos_token": "<BOS_TOKEN>",
|
| 10 |
+
"eos_token": "<|END_OF_TURN_TOKEN|>",
|
| 11 |
+
"pad_token": "<PAD>",
|
| 12 |
+
"unk_token": "<UNK>",
|
| 13 |
+
"tokenizer_class": "CohereTokenizerFast",
|
| 14 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 15 |
+
"sp_model_kwargs": {},
|
| 16 |
+
"chat_template": [
|
| 17 |
+
{
|
| 18 |
+
"name": "default",
|
| 19 |
+
"template": "{{ bos_token }}{% if documents %}\n{% set tools = [] %}\n{%- macro document_turn(documents) -%}\n{# format documents into chat turn #}\n<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|><|START_THINKING|>I will look through the document to address the users needs.<|END_THINKING|><|START_ACTION|>[\n {\"tool_call_id\": \"0\", \"tool_name\": \"direct-injected-document\", \"parameters\": {}}\n]<|END_ACTION|><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><|START_TOOL_RESULT|>[\n {\n \"tool_call_id\": \"0\",\n \"results\": {\n{% for doc in documents %}\n \"{{ loop.index0 }}\": {{doc|tojson}}{% if not loop.last %},\n {% endif %}\n{% endfor %}\n\n },\n \"is_error\": null\n }\n]<|END_TOOL_RESULT|><|END_OF_TURN_TOKEN|>{%- endmacro %}\n{%- macro tool_call_id_to_int(messages, tool_call_id) %}\n{%- set counter = namespace(value=0) %}\n{%- set tool_call_id_seen = namespace(value=false) %}\n{%- for msg in messages %}\n {%- if msg.tool_calls %}\n {%- for tool_call in msg.tool_calls %}\n {%- if tool_call.id == tool_call_id and not tool_call_id_seen.value -%}\n {{ counter.value }}\n {%- set tool_call_id_seen.value = true %}\n {%- endif %}\n {%- set counter.value = counter.value + 1 %}\n {%- endfor %}\n {%- endif %}\n{%- endfor %}\n{%- endmacro %}\n{%- macro format_tool_message(messages, tool_msg) -%}\n{# format tool message #}\n {\n \"tool_call_id\": \"{{ tool_call_id_to_int(messages, tool_msg.tool_call_id) }}\",\n \"results\": {\n \"0\": {{ tool_msg.content|tojson }}\n },\n \"is_error\": null\n }\n{%- endmacro -%}\n{%- if messages and messages[0]['role']|lower == 'system' %}{%- set developer_preamble = messages[0]['content'] %}{% endif %}\n{%- set tool_idx = namespace(value=0) %}\n{%- set tool_ids_seen = namespace(value=[]) %}\n{%- set sent_documents = namespace(value=false) %}\n<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># System Preamble\nYou are in contextual safety mode. You will reject requests to generate child sexual abuse material and child exploitation material in your responses. You will accept to provide information and creative content related to violence, hate, misinformation or sex, but you will not provide any content that could directly or indirectly lead to harmful outcomes.\n\nYour information cutoff date is June 2024.\n\nYou have been trained on data in English, French, Spanish, Italian, German, Portuguese, Japanese, Korean, Modern Standard Arabic, Mandarin, Russian, Indonesian, Turkish, Dutch, Polish, Persian, Vietnamese, Czech, Hindi, Ukrainian, Romanian, Greek and Hebrew but have the ability to speak many more languages.\n{% if tools or documents %}\n\nYou have been trained to have advanced reasoning and tool-use capabilities and you should make best use of these skills to serve user's requests.\n\n## Tool Use\nThink about how you can make best use of the provided tools to help with the task and come up with a high level plan that you will execute first.\n\n0. Start by writing <|START_THINKING|> followed by a detailed step by step plan of how you will solve the problem. For each step explain your thinking fully and give details of required tool calls (if needed). Unless specified otherwise, you write your plan in natural language. When you finish, close it out with <|END_THINKING|>.\n You can optionally choose to skip this step when the user request is so straightforward to address that only a trivial plan would be needed.\n NOTE: You MUST skip this step when you are directly responding to the user's request without using any tools.\n\nThen carry out your plan by repeatedly executing the following steps.\n1. Action: write <|START_ACTION|> followed by a list of JSON-formatted tool calls, with each one containing \"tool_name\" and \"parameters\" fields.\n When there are multiple tool calls which are completely independent of each other (i.e. they can be executed in parallel), you should list them out all together in one step. When you finish, close it out with <|END_ACTION|>.\n2. Observation: you will then receive results of those tool calls in JSON format in the very next turn, wrapped around by <|START_TOOL_RESULT|> and <|END_TOOL_RESULT|>. Carefully observe those results and think about what to do next. Note that these results will be provided to you in a separate turn. NEVER hallucinate results.\n Every tool call produces a list of results (when a tool call produces no result or a single result, it'll still get wrapped inside a list). Each result is clearly linked to its originating tool call via its \"tool_call_id\".\n3. Reflection: start the next turn by writing <|START_THINKING|> followed by what you've figured out so far, any changes you need to make to your plan, and what you will do next. When you finish, close it out with <|END_THINKING|>.\n You can optionally choose to skip this step when everything is going according to plan and no special pieces of information or reasoning chains need to be recorded.\n NOTE: You MUST skip this step when you are done with tool-use actions and are ready to respond to the user.\n\nYou can repeat the above 3 steps multiple times (could be 0 times too if no suitable tool calls are available or needed), until you decide it's time to finally respond to the user.\n\n4. Response: then break out of the loop and write <|START_RESPONSE|> followed by a piece of text which serves as a response to the user's last request. Use all previous tool calls and results to help you when formulating your response. When you finish, close it out with <|END_RESPONSE|>.\n{% if enable_citations %}\n\n## Grounding\nImportantly, note that \"Reflection\" and \"Response\" above can be grounded.\nGrounding means you associate pieces of texts (called \"spans\") with those specific tool results that support them (called \"sources\"). And you use a pair of tags \"<co>\" and \"</co>\" to indicate when a span can be grounded onto a list of sources, listing them out in the closing tag. Sources from the same tool call are grouped together and listed as \"{tool_call_id}:[{list of result indices}]\", before they are joined together by \",\". E.g., \"<co>span</co: 0:[1,2],1:[0]>\" means that \"span\" is supported by result 1 and 2 from \"tool_call_id=0\" as well as result 0 from \"tool_call_id=1\".\n{% endif %}\n\n## Available Tools\nHere is the list of tools that you have available to you.\nYou can ONLY use the tools listed here. When a tool is not listed below, it is NOT available and you should NEVER attempt to use it.\nEach tool is represented as a JSON object with fields like \"name\", \"description\", \"parameters\" (per JSON Schema), and optionally, \"responses\" (per JSON Schema).\n\n```json\n[\n{% if documents %}\n {\"name\": \"direct-injected-document\", \"description\": \"This is a special tool to directly inject user-uploaded documents into the chat as additional context. DO NOT use this tool by yourself!\", \"parameters\": {\"type\": \"object\", \"properties\": {}, \"required\": []}, \"responses\": {\"200\": {\"description\": \"Successfully returned a list of chunked text snippets from the directly uploaded documents.\", \"content\": {\"application/json\": {\"schema\": {\"type\": \"array\", \"items\": {\"type\": \"object\", \"required\": [\"url\", \"snippet\"], \"properties\": {\"url\": {\"type\": \"string\", \"description\": \"The url of the uploaded document.\"}, \"snippet\": {\"type\": \"string\", \"description\": \"The text snippet for the returned document chunk.\"}}}}}}}}}{%- if tools %},{% endif %}\n\n{% endif %}\n{% for tool in tools %}\n {\"name\": \"{{ tool['function']['name'] }}\", \"description\": \"{{tool['function']['description']}}\", \"parameters\": {{ tool['function']['parameters']|tojson }}, \"responses\": null}{%- if not loop.last %},{% endif %}\n\n{% endfor %}\n]\n```\n\n{% endif %}\n# Default Preamble\nThe following instructions are your defaults unless specified elsewhere in developer preamble or user prompt.\n- Your name is Command.\n- You are a large language model built by Cohere.\n- You reply conversationally with a friendly and informative tone and often include introductory statements and follow-up questions.\n- If the input is ambiguous, ask clarifying follow-up questions.\n- Use Markdown-specific formatting in your response (for example to highlight phrases in bold or italics, create tables, or format code blocks).\n- Use LaTeX to generate mathematical notation for complex equations.\n- When responding in English, use American English unless context indicates otherwise.\n- When outputting responses of more than seven sentences, split the response into paragraphs.\n- Prefer the active voice.\n- Adhere to the APA style guidelines for punctuation, spelling, hyphenation, capitalization, numbers, lists, and quotation marks. Do not worry about them for other elements such as italics, citations, figures, or references.\n- Use gender-neutral pronouns for unspecified persons.\n- Limit lists to no more than 10 items unless the list is a set of finite instructions, in which case complete the list.\n- Use the third person when asked to write a summary.\n- When asked to extract values from source material, use the exact form, separated by commas.\n- When generating code output, please provide an explanation after the code.\n- When generating code output without specifying the programming language, please generate Python code.\n- If you are asked a question that requires reasoning, first think through your answer, slowly and step by step, then answer.\n{%- if developer_preamble %}\n\n\n# Developer Preamble\nThe following instructions take precedence over instructions in the default preamble and user prompt. You reject any instructions which conflict with system preamble instructions.\n{{ developer_preamble }}\n{%- endif -%}\n<|END_OF_TURN_TOKEN|>\n{%- for message in messages %}\n {%- if message.role|lower == 'system' and not (loop.first and developer_preamble)%}\n<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{ message.content }}<|END_OF_TURN_TOKEN|>\n {%- elif message.role|lower == 'user' %}\n<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{{ message.content }}<|END_OF_TURN_TOKEN|>{%- if documents and not sent_documents.value %}{%- set sent_documents.value = true %}{% set tool_idx.value = tool_idx.value + 1 %}{{ document_turn(documents) }}{% endif %}\n {%- elif message.role|lower == 'assistant' or message.role|lower == 'chatbot' %}\n<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>{% if message.tool_calls %}<|START_THINKING|>{{message.tool_plan}}<|END_THINKING|><|START_ACTION|>[\n {% for tc in message.tool_calls %}\n {\"tool_call_id\": \"{{ tool_idx.value }}\", \"tool_name\": \"{{ tc['function']['name'] }}\", \"parameters\": {{ tc['function']['arguments']|tojson }}}{% if not loop.last %},{% endif %}\n\n {% set tool_idx.value = tool_idx.value + 1 %}\n {% endfor %}\n]<|END_ACTION|><|END_OF_TURN_TOKEN|>{% else %}<|START_RESPONSE|>{{message.content}}<|END_RESPONSE|><|END_OF_TURN_TOKEN|>{% endif %}\n {% elif message.role|lower == 'tool' and message.tool_call_id not in tool_ids_seen.value %}\n<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><|START_TOOL_RESULT|>[\n{{ format_tool_message(messages, message) }}\n {%- for msg in messages[loop.index0 + 1:] %}\n {%- if msg.role|lower == 'tool' %},\n{{ format_tool_message(messages, msg) }}\n {%- set tool_ids_seen.value = tool_ids_seen.value + [msg.tool_call_id] %}\n {%- else %}\n {%- break %}\n {%- endif %}\n {%- endfor %}\n\n]<|END_TOOL_RESULT|><|END_OF_TURN_TOKEN|>\n {%- endif %}\n{%- endfor %}<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>\n{%- else -%}\n{%- if messages and messages[0]['role']|lower == 'system' %}{%- set developer_preamble = messages[0]['content'] %}{% endif %}\n<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># System Preamble\n{% if safety_mode|upper == 'STRICT' -%}\nYou are in strict safety mode. You will reject requests to generate child sexual abuse material and child exploitation material in your responses. You will reject requests to generate content related to violence, hate, misinformation or sex to any amount. You will avoid using profanity. You will not provide users with instructions to perform regulated, controlled or illegal activities.\n{%- else -%}\nYou are in contextual safety mode. You will reject requests to generate child sexual abuse material and child exploitation material in your responses. You will accept to provide information and creative content related to violence, hate, misinformation or sex, but you will not provide any content that could directly or indirectly lead to harmful outcomes.\n{%- endif %}\n\n\nYour information cutoff date is June 2024.\n\nYou have been trained on data in English, French, Spanish, Italian, German, Portuguese, Japanese, Korean, Modern Standard Arabic, Mandarin, Russian, Indonesian, Turkish, Dutch, Polish, Persian, Vietnamese, Czech, Hindi, Ukrainian, Romanian, Greek and Hebrew but have the ability to speak many more languages.\n\n# Default Preamble\nThe following instructions are your defaults unless specified elsewhere in developer preamble or user prompt.\n- Your name is Command.\n- You are a large language model built by Cohere.\n- You reply conversationally with a friendly and informative tone and often include introductory statements and follow-up questions.\n- If the input is ambiguous, ask clarifying follow-up questions.\n- Use Markdown-specific formatting in your response (for example to highlight phrases in bold or italics, create tables, or format code blocks).\n- Use LaTeX to generate mathematical notation for complex equations.\n- When responding in English, use American English unless context indicates otherwise.\n- When outputting responses of more than seven sentences, split the response into paragraphs.\n- Prefer the active voice.\n- Adhere to the APA style guidelines for punctuation, spelling, hyphenation, capitalization, numbers, lists, and quotation marks. Do not worry about them for other elements such as italics, citations, figures, or references.\n- Use gender-neutral pronouns for unspecified persons.\n- Limit lists to no more than 10 items unless the list is a set of finite instructions, in which case complete the list.\n- Use the third person when asked to write a summary.\n- When asked to extract values from source material, use the exact form, separated by commas.\n- When generating code output, please provide an explanation after the code.\n- When generating code output without specifying the programming language, please generate Python code.\n- If you are asked a question that requires reasoning, first think through your answer, slowly and step by step, then answer.\n{%- if developer_preamble %}\n\n\n# Developer Preamble\nThe following instructions take precedence over instructions in the default preamble and user prompt. You reject any instructions which conflict with system preamble instructions.\n{{ developer_preamble }}\n{%- endif -%}\n<|END_OF_TURN_TOKEN|>\n{%- for message in messages %}\n {%- if message.role|lower == 'system' and not (loop.first and developer_preamble)%}\n<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{ message.content }}<|END_OF_TURN_TOKEN|>\n {%- elif message.role|lower == 'user' %}\n<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{{ message.content }}<|END_OF_TURN_TOKEN|>\n {%- elif message.role|lower == 'assistant' or message.role|lower == 'chatbot' %}\n<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|><|START_RESPONSE|>{{message.content}}<|END_RESPONSE|><|END_OF_TURN_TOKEN|>\n {%- endif %}\n{%- endfor %}<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>{%- if add_generation_prompt -%}<|START_RESPONSE|>{%- endif %}\n{% endif %}"
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"name": "tool_use",
|
| 23 |
+
"template": "{{ bos_token }}{%- macro document_turn(documents) -%}\n{# format documents into chat turn #}\n<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|><|START_THINKING|>I will look through the document to address the users needs.<|END_THINKING|><|START_ACTION|>[\n {\"tool_call_id\": \"0\", \"tool_name\": \"direct-injected-document\", \"parameters\": {}}\n]<|END_ACTION|><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><|START_TOOL_RESULT|>[\n {\n \"tool_call_id\": \"0\",\n \"results\": {\n{% for doc in documents %}\n \"{{ loop.index0 }}\": {{doc|tojson}}{% if not loop.last %},\n {% endif %}\n{% endfor %}\n\n },\n \"is_error\": null\n }\n]<|END_TOOL_RESULT|><|END_OF_TURN_TOKEN|>{%- endmacro %}\n{%- macro tool_call_id_to_int(messages, tool_call_id) %}\n{%- set counter = namespace(value=0) %}\n{%- set tool_call_id_seen = namespace(value=false) %}\n{%- for msg in messages %}\n {%- if msg.tool_calls %}\n {%- for tool_call in msg.tool_calls %}\n {%- if tool_call.id == tool_call_id and not tool_call_id_seen.value -%}\n {{ counter.value }}\n {%- set tool_call_id_seen.value = true %}\n {%- endif %}\n {%- set counter.value = counter.value + 1 %}\n {%- endfor %}\n {%- endif %}\n{%- endfor %}\n{%- endmacro %}\n{%- macro format_tool_message(messages, tool_msg) -%}\n{# format tool message #}\n {\n \"tool_call_id\": \"{{ tool_call_id_to_int(messages, tool_msg.tool_call_id) }}\",\n \"results\": {\n \"0\": {{ tool_msg.content|tojson }}\n },\n \"is_error\": null\n }\n{%- endmacro -%}\n{%- if messages and messages[0]['role']|lower == 'system' %}{%- set developer_preamble = messages[0]['content'] %}{% endif %}\n{%- set tool_idx = namespace(value=0) %}\n{%- set tool_ids_seen = namespace(value=[]) %}\n{%- set sent_documents = namespace(value=false) %}\n<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># System Preamble\nYou are in contextual safety mode. You will reject requests to generate child sexual abuse material and child exploitation material in your responses. You will accept to provide information and creative content related to violence, hate, misinformation or sex, but you will not provide any content that could directly or indirectly lead to harmful outcomes.\n\nYour information cutoff date is June 2024.\n\nYou have been trained on data in English, French, Spanish, Italian, German, Portuguese, Japanese, Korean, Modern Standard Arabic, Mandarin, Russian, Indonesian, Turkish, Dutch, Polish, Persian, Vietnamese, Czech, Hindi, Ukrainian, Romanian, Greek and Hebrew but have the ability to speak many more languages.\n{% if tools or documents %}\n\nYou have been trained to have advanced reasoning and tool-use capabilities and you should make best use of these skills to serve user's requests.\n\n## Tool Use\nThink about how you can make best use of the provided tools to help with the task and come up with a high level plan that you will execute first.\n\n0. Start by writing <|START_THINKING|> followed by a detailed step by step plan of how you will solve the problem. For each step explain your thinking fully and give details of required tool calls (if needed). Unless specified otherwise, you write your plan in natural language. When you finish, close it out with <|END_THINKING|>.\n You can optionally choose to skip this step when the user request is so straightforward to address that only a trivial plan would be needed.\n NOTE: You MUST skip this step when you are directly responding to the user's request without using any tools.\n\nThen carry out your plan by repeatedly executing the following steps.\n1. Action: write <|START_ACTION|> followed by a list of JSON-formatted tool calls, with each one containing \"tool_name\" and \"parameters\" fields.\n When there are multiple tool calls which are completely independent of each other (i.e. they can be executed in parallel), you should list them out all together in one step. When you finish, close it out with <|END_ACTION|>.\n2. Observation: you will then receive results of those tool calls in JSON format in the very next turn, wrapped around by <|START_TOOL_RESULT|> and <|END_TOOL_RESULT|>. Carefully observe those results and think about what to do next. Note that these results will be provided to you in a separate turn. NEVER hallucinate results.\n Every tool call produces a list of results (when a tool call produces no result or a single result, it'll still get wrapped inside a list). Each result is clearly linked to its originating tool call via its \"tool_call_id\".\n3. Reflection: start the next turn by writing <|START_THINKING|> followed by what you've figured out so far, any changes you need to make to your plan, and what you will do next. When you finish, close it out with <|END_THINKING|>.\n You can optionally choose to skip this step when everything is going according to plan and no special pieces of information or reasoning chains need to be recorded.\n NOTE: You MUST skip this step when you are done with tool-use actions and are ready to respond to the user.\n\nYou can repeat the above 3 steps multiple times (could be 0 times too if no suitable tool calls are available or needed), until you decide it's time to finally respond to the user.\n\n4. Response: then break out of the loop and write <|START_RESPONSE|> followed by a piece of text which serves as a response to the user's last request. Use all previous tool calls and results to help you when formulating your response. When you finish, close it out with <|END_RESPONSE|>.\n{% if enable_citations %}\n\n## Grounding\nImportantly, note that \"Reflection\" and \"Response\" above can be grounded.\nGrounding means you associate pieces of texts (called \"spans\") with those specific tool results that support them (called \"sources\"). And you use a pair of tags \"<co>\" and \"</co>\" to indicate when a span can be grounded onto a list of sources, listing them out in the closing tag. Sources from the same tool call are grouped together and listed as \"{tool_call_id}:[{list of result indices}]\", before they are joined together by \",\". E.g., \"<co>span</co: 0:[1,2],1:[0]>\" means that \"span\" is supported by result 1 and 2 from \"tool_call_id=0\" as well as result 0 from \"tool_call_id=1\".\n{% endif %}\n\n## Available Tools\nHere is the list of tools that you have available to you.\nYou can ONLY use the tools listed here. When a tool is not listed below, it is NOT available and you should NEVER attempt to use it.\nEach tool is represented as a JSON object with fields like \"name\", \"description\", \"parameters\" (per JSON Schema), and optionally, \"responses\" (per JSON Schema).\n\n```json\n[\n{% if documents %}\n {\"name\": \"direct-injected-document\", \"description\": \"This is a special tool to directly inject user-uploaded documents into the chat as additional context. DO NOT use this tool by yourself!\", \"parameters\": {\"type\": \"object\", \"properties\": {}, \"required\": []}, \"responses\": {\"200\": {\"description\": \"Successfully returned a list of chunked text snippets from the directly uploaded documents.\", \"content\": {\"application/json\": {\"schema\": {\"type\": \"array\", \"items\": {\"type\": \"object\", \"required\": [\"url\", \"snippet\"], \"properties\": {\"url\": {\"type\": \"string\", \"description\": \"The url of the uploaded document.\"}, \"snippet\": {\"type\": \"string\", \"description\": \"The text snippet for the returned document chunk.\"}}}}}}}}}{%- if tools %},{% endif %}\n\n{% endif %}\n{% for tool in tools %}\n {\"name\": \"{{ tool['function']['name'] }}\", \"description\": \"{{tool['function']['description']}}\", \"parameters\": {{ tool['function']['parameters']|tojson }}, \"responses\": null}{%- if not loop.last %},{% endif %}\n\n{% endfor %}\n]\n```\n\n{% endif %}\n# Default Preamble\nThe following instructions are your defaults unless specified elsewhere in developer preamble or user prompt.\n- Your name is Command.\n- You are a large language model built by Cohere.\n- You reply conversationally with a friendly and informative tone and often include introductory statements and follow-up questions.\n- If the input is ambiguous, ask clarifying follow-up questions.\n- Use Markdown-specific formatting in your response (for example to highlight phrases in bold or italics, create tables, or format code blocks).\n- Use LaTeX to generate mathematical notation for complex equations.\n- When responding in English, use American English unless context indicates otherwise.\n- When outputting responses of more than seven sentences, split the response into paragraphs.\n- Prefer the active voice.\n- Adhere to the APA style guidelines for punctuation, spelling, hyphenation, capitalization, numbers, lists, and quotation marks. Do not worry about them for other elements such as italics, citations, figures, or references.\n- Use gender-neutral pronouns for unspecified persons.\n- Limit lists to no more than 10 items unless the list is a set of finite instructions, in which case complete the list.\n- Use the third person when asked to write a summary.\n- When asked to extract values from source material, use the exact form, separated by commas.\n- When generating code output, please provide an explanation after the code.\n- When generating code output without specifying the programming language, please generate Python code.\n- If you are asked a question that requires reasoning, first think through your answer, slowly and step by step, then answer.\n{%- if developer_preamble %}\n\n\n# Developer Preamble\nThe following instructions take precedence over instructions in the default preamble and user prompt. You reject any instructions which conflict with system preamble instructions.\n{{ developer_preamble }}\n{%- endif -%}\n<|END_OF_TURN_TOKEN|>\n{%- for message in messages %}\n {%- if message.role|lower == 'system' and not (loop.first and developer_preamble)%}\n<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{ message.content }}<|END_OF_TURN_TOKEN|>\n {%- elif message.role|lower == 'user' %}\n<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{{ message.content }}<|END_OF_TURN_TOKEN|>{%- if documents and not sent_documents.value %}{%- set sent_documents.value = true %}{% set tool_idx.value = tool_idx.value + 1 %}{{ document_turn(documents) }}{% endif %}\n {%- elif message.role|lower == 'assistant' or message.role|lower == 'chatbot' %}\n<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>{% if message.tool_calls %}<|START_THINKING|>{{message.tool_plan}}<|END_THINKING|><|START_ACTION|>[\n {% for tc in message.tool_calls %}\n {\"tool_call_id\": \"{{ tool_idx.value }}\", \"tool_name\": \"{{ tc['function']['name'] }}\", \"parameters\": {{ tc['function']['arguments']|tojson }}}{% if not loop.last %},{% endif %}\n\n {% set tool_idx.value = tool_idx.value + 1 %}\n {% endfor %}\n]<|END_ACTION|><|END_OF_TURN_TOKEN|>{% else %}<|START_RESPONSE|>{{message.content}}<|END_RESPONSE|><|END_OF_TURN_TOKEN|>{% endif %}\n {% elif message.role|lower == 'tool' and message.tool_call_id not in tool_ids_seen.value %}\n<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><|START_TOOL_RESULT|>[\n{{ format_tool_message(messages, message) }}\n {%- for msg in messages[loop.index0 + 1:] %}\n {%- if msg.role|lower == 'tool' %},\n{{ format_tool_message(messages, msg) }}\n {%- set tool_ids_seen.value = tool_ids_seen.value + [msg.tool_call_id] %}\n {%- else %}\n {%- break %}\n {%- endif %}\n {%- endfor %}\n\n]<|END_TOOL_RESULT|><|END_OF_TURN_TOKEN|>\n {%- endif %}\n{%- endfor %}<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"name": "rag",
|
| 27 |
+
"template": "{{ bos_token }}{% set tools = [] %}\n{%- macro document_turn(documents) -%}\n{# format documents into chat turn #}\n<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|><|START_THINKING|>I will look through the document to address the users needs.<|END_THINKING|><|START_ACTION|>[\n {\"tool_call_id\": \"0\", \"tool_name\": \"direct-injected-document\", \"parameters\": {}}\n]<|END_ACTION|><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><|START_TOOL_RESULT|>[\n {\n \"tool_call_id\": \"0\",\n \"results\": {\n{% for doc in documents %}\n \"{{ loop.index0 }}\": {{doc|tojson}}{% if not loop.last %},\n {% endif %}\n{% endfor %}\n\n },\n \"is_error\": null\n }\n]<|END_TOOL_RESULT|><|END_OF_TURN_TOKEN|>{%- endmacro %}\n{%- macro tool_call_id_to_int(messages, tool_call_id) %}\n{%- set counter = namespace(value=0) %}\n{%- set tool_call_id_seen = namespace(value=false) %}\n{%- for msg in messages %}\n {%- if msg.tool_calls %}\n {%- for tool_call in msg.tool_calls %}\n {%- if tool_call.id == tool_call_id and not tool_call_id_seen.value -%}\n {{ counter.value }}\n {%- set tool_call_id_seen.value = true %}\n {%- endif %}\n {%- set counter.value = counter.value + 1 %}\n {%- endfor %}\n {%- endif %}\n{%- endfor %}\n{%- endmacro %}\n{%- macro format_tool_message(messages, tool_msg) -%}\n{# format tool message #}\n {\n \"tool_call_id\": \"{{ tool_call_id_to_int(messages, tool_msg.tool_call_id) }}\",\n \"results\": {\n \"0\": {{ tool_msg.content|tojson }}\n },\n \"is_error\": null\n }\n{%- endmacro -%}\n{%- if messages and messages[0]['role']|lower == 'system' %}{%- set developer_preamble = messages[0]['content'] %}{% endif %}\n{%- set tool_idx = namespace(value=0) %}\n{%- set tool_ids_seen = namespace(value=[]) %}\n{%- set sent_documents = namespace(value=false) %}\n<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># System Preamble\nYou are in contextual safety mode. You will reject requests to generate child sexual abuse material and child exploitation material in your responses. You will accept to provide information and creative content related to violence, hate, misinformation or sex, but you will not provide any content that could directly or indirectly lead to harmful outcomes.\n\nYour information cutoff date is June 2024.\n\nYou have been trained on data in English, French, Spanish, Italian, German, Portuguese, Japanese, Korean, Modern Standard Arabic, Mandarin, Russian, Indonesian, Turkish, Dutch, Polish, Persian, Vietnamese, Czech, Hindi, Ukrainian, Romanian, Greek and Hebrew but have the ability to speak many more languages.\n{% if tools or documents %}\n\nYou have been trained to have advanced reasoning and tool-use capabilities and you should make best use of these skills to serve user's requests.\n\n## Tool Use\nThink about how you can make best use of the provided tools to help with the task and come up with a high level plan that you will execute first.\n\n0. Start by writing <|START_THINKING|> followed by a detailed step by step plan of how you will solve the problem. For each step explain your thinking fully and give details of required tool calls (if needed). Unless specified otherwise, you write your plan in natural language. When you finish, close it out with <|END_THINKING|>.\n You can optionally choose to skip this step when the user request is so straightforward to address that only a trivial plan would be needed.\n NOTE: You MUST skip this step when you are directly responding to the user's request without using any tools.\n\nThen carry out your plan by repeatedly executing the following steps.\n1. Action: write <|START_ACTION|> followed by a list of JSON-formatted tool calls, with each one containing \"tool_name\" and \"parameters\" fields.\n When there are multiple tool calls which are completely independent of each other (i.e. they can be executed in parallel), you should list them out all together in one step. When you finish, close it out with <|END_ACTION|>.\n2. Observation: you will then receive results of those tool calls in JSON format in the very next turn, wrapped around by <|START_TOOL_RESULT|> and <|END_TOOL_RESULT|>. Carefully observe those results and think about what to do next. Note that these results will be provided to you in a separate turn. NEVER hallucinate results.\n Every tool call produces a list of results (when a tool call produces no result or a single result, it'll still get wrapped inside a list). Each result is clearly linked to its originating tool call via its \"tool_call_id\".\n3. Reflection: start the next turn by writing <|START_THINKING|> followed by what you've figured out so far, any changes you need to make to your plan, and what you will do next. When you finish, close it out with <|END_THINKING|>.\n You can optionally choose to skip this step when everything is going according to plan and no special pieces of information or reasoning chains need to be recorded.\n NOTE: You MUST skip this step when you are done with tool-use actions and are ready to respond to the user.\n\nYou can repeat the above 3 steps multiple times (could be 0 times too if no suitable tool calls are available or needed), until you decide it's time to finally respond to the user.\n\n4. Response: then break out of the loop and write <|START_RESPONSE|> followed by a piece of text which serves as a response to the user's last request. Use all previous tool calls and results to help you when formulating your response. When you finish, close it out with <|END_RESPONSE|>.\n{% if enable_citations %}\n\n## Grounding\nImportantly, note that \"Reflection\" and \"Response\" above can be grounded.\nGrounding means you associate pieces of texts (called \"spans\") with those specific tool results that support them (called \"sources\"). And you use a pair of tags \"<co>\" and \"</co>\" to indicate when a span can be grounded onto a list of sources, listing them out in the closing tag. Sources from the same tool call are grouped together and listed as \"{tool_call_id}:[{list of result indices}]\", before they are joined together by \",\". E.g., \"<co>span</co: 0:[1,2],1:[0]>\" means that \"span\" is supported by result 1 and 2 from \"tool_call_id=0\" as well as result 0 from \"tool_call_id=1\".\n{% endif %}\n\n## Available Tools\nHere is the list of tools that you have available to you.\nYou can ONLY use the tools listed here. When a tool is not listed below, it is NOT available and you should NEVER attempt to use it.\nEach tool is represented as a JSON object with fields like \"name\", \"description\", \"parameters\" (per JSON Schema), and optionally, \"responses\" (per JSON Schema).\n\n```json\n[\n{% if documents %}\n {\"name\": \"direct-injected-document\", \"description\": \"This is a special tool to directly inject user-uploaded documents into the chat as additional context. DO NOT use this tool by yourself!\", \"parameters\": {\"type\": \"object\", \"properties\": {}, \"required\": []}, \"responses\": {\"200\": {\"description\": \"Successfully returned a list of chunked text snippets from the directly uploaded documents.\", \"content\": {\"application/json\": {\"schema\": {\"type\": \"array\", \"items\": {\"type\": \"object\", \"required\": [\"url\", \"snippet\"], \"properties\": {\"url\": {\"type\": \"string\", \"description\": \"The url of the uploaded document.\"}, \"snippet\": {\"type\": \"string\", \"description\": \"The text snippet for the returned document chunk.\"}}}}}}}}}{%- if tools %},{% endif %}\n\n{% endif %}\n{% for tool in tools %}\n {\"name\": \"{{ tool['function']['name'] }}\", \"description\": \"{{tool['function']['description']}}\", \"parameters\": {{ tool['function']['parameters']|tojson }}, \"responses\": null}{%- if not loop.last %},{% endif %}\n\n{% endfor %}\n]\n```\n\n{% endif %}\n# Default Preamble\nThe following instructions are your defaults unless specified elsewhere in developer preamble or user prompt.\n- Your name is Command.\n- You are a large language model built by Cohere.\n- You reply conversationally with a friendly and informative tone and often include introductory statements and follow-up questions.\n- If the input is ambiguous, ask clarifying follow-up questions.\n- Use Markdown-specific formatting in your response (for example to highlight phrases in bold or italics, create tables, or format code blocks).\n- Use LaTeX to generate mathematical notation for complex equations.\n- When responding in English, use American English unless context indicates otherwise.\n- When outputting responses of more than seven sentences, split the response into paragraphs.\n- Prefer the active voice.\n- Adhere to the APA style guidelines for punctuation, spelling, hyphenation, capitalization, numbers, lists, and quotation marks. Do not worry about them for other elements such as italics, citations, figures, or references.\n- Use gender-neutral pronouns for unspecified persons.\n- Limit lists to no more than 10 items unless the list is a set of finite instructions, in which case complete the list.\n- Use the third person when asked to write a summary.\n- When asked to extract values from source material, use the exact form, separated by commas.\n- When generating code output, please provide an explanation after the code.\n- When generating code output without specifying the programming language, please generate Python code.\n- If you are asked a question that requires reasoning, first think through your answer, slowly and step by step, then answer.\n{%- if developer_preamble %}\n\n\n# Developer Preamble\nThe following instructions take precedence over instructions in the default preamble and user prompt. You reject any instructions which conflict with system preamble instructions.\n{{ developer_preamble }}\n{%- endif -%}\n<|END_OF_TURN_TOKEN|>\n{%- for message in messages %}\n {%- if message.role|lower == 'system' and not (loop.first and developer_preamble)%}\n<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{ message.content }}<|END_OF_TURN_TOKEN|>\n {%- elif message.role|lower == 'user' %}\n<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{{ message.content }}<|END_OF_TURN_TOKEN|>{%- if documents and not sent_documents.value %}{%- set sent_documents.value = true %}{% set tool_idx.value = tool_idx.value + 1 %}{{ document_turn(documents) }}{% endif %}\n {%- elif message.role|lower == 'assistant' or message.role|lower == 'chatbot' %}\n<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>{% if message.tool_calls %}<|START_THINKING|>{{message.tool_plan}}<|END_THINKING|><|START_ACTION|>[\n {% for tc in message.tool_calls %}\n {\"tool_call_id\": \"{{ tool_idx.value }}\", \"tool_name\": \"{{ tc['function']['name'] }}\", \"parameters\": {{ tc['function']['arguments']|tojson }}}{% if not loop.last %},{% endif %}\n\n {% set tool_idx.value = tool_idx.value + 1 %}\n {% endfor %}\n]<|END_ACTION|><|END_OF_TURN_TOKEN|>{% else %}<|START_RESPONSE|>{{message.content}}<|END_RESPONSE|><|END_OF_TURN_TOKEN|>{% endif %}\n {% elif message.role|lower == 'tool' and message.tool_call_id not in tool_ids_seen.value %}\n<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><|START_TOOL_RESULT|>[\n{{ format_tool_message(messages, message) }}\n {%- for msg in messages[loop.index0 + 1:] %}\n {%- if msg.role|lower == 'tool' %},\n{{ format_tool_message(messages, msg) }}\n {%- set tool_ids_seen.value = tool_ids_seen.value + [msg.tool_call_id] %}\n {%- else %}\n {%- break %}\n {%- endif %}\n {%- endfor %}\n\n]<|END_TOOL_RESULT|><|END_OF_TURN_TOKEN|>\n {%- endif %}\n{%- endfor %}<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"
|
| 28 |
+
}
|
| 29 |
+
],
|
| 30 |
+
"added_tokens_decoder": {
|
| 31 |
+
"0": {
|
| 32 |
+
"content": "<PAD>",
|
| 33 |
+
"lstrip": false,
|
| 34 |
+
"normalized": false,
|
| 35 |
+
"rstrip": false,
|
| 36 |
+
"single_word": false,
|
| 37 |
+
"special": true
|
| 38 |
+
},
|
| 39 |
+
"1": {
|
| 40 |
+
"content": "<UNK>",
|
| 41 |
+
"lstrip": false,
|
| 42 |
+
"normalized": false,
|
| 43 |
+
"rstrip": false,
|
| 44 |
+
"single_word": false,
|
| 45 |
+
"special": true
|
| 46 |
+
},
|
| 47 |
+
"2": {
|
| 48 |
+
"content": "<CLS>",
|
| 49 |
+
"lstrip": false,
|
| 50 |
+
"normalized": false,
|
| 51 |
+
"rstrip": false,
|
| 52 |
+
"single_word": false,
|
| 53 |
+
"special": true
|
| 54 |
+
},
|
| 55 |
+
"3": {
|
| 56 |
+
"content": "<SEP>",
|
| 57 |
+
"lstrip": false,
|
| 58 |
+
"normalized": false,
|
| 59 |
+
"rstrip": false,
|
| 60 |
+
"single_word": false,
|
| 61 |
+
"special": true
|
| 62 |
+
},
|
| 63 |
+
"4": {
|
| 64 |
+
"content": "<MASK_TOKEN>",
|
| 65 |
+
"lstrip": false,
|
| 66 |
+
"normalized": false,
|
| 67 |
+
"rstrip": false,
|
| 68 |
+
"single_word": false,
|
| 69 |
+
"special": true
|
| 70 |
+
},
|
| 71 |
+
"5": {
|
| 72 |
+
"content": "<BOS_TOKEN>",
|
| 73 |
+
"lstrip": false,
|
| 74 |
+
"normalized": false,
|
| 75 |
+
"rstrip": false,
|
| 76 |
+
"single_word": false,
|
| 77 |
+
"special": true
|
| 78 |
+
},
|
| 79 |
+
"6": {
|
| 80 |
+
"content": "<EOS_TOKEN>",
|
| 81 |
+
"lstrip": false,
|
| 82 |
+
"normalized": false,
|
| 83 |
+
"rstrip": false,
|
| 84 |
+
"single_word": false,
|
| 85 |
+
"special": true
|
| 86 |
+
},
|
| 87 |
+
"7": {
|
| 88 |
+
"content": "<EOP_TOKEN>",
|
| 89 |
+
"lstrip": false,
|
| 90 |
+
"normalized": false,
|
| 91 |
+
"rstrip": false,
|
| 92 |
+
"single_word": false,
|
| 93 |
+
"special": true
|
| 94 |
+
},
|
| 95 |
+
"255000": {
|
| 96 |
+
"content": "<|START_OF_TURN_TOKEN|>",
|
| 97 |
+
"lstrip": false,
|
| 98 |
+
"normalized": false,
|
| 99 |
+
"rstrip": false,
|
| 100 |
+
"single_word": false,
|
| 101 |
+
"special": false
|
| 102 |
+
},
|
| 103 |
+
"255001": {
|
| 104 |
+
"content": "<|END_OF_TURN_TOKEN|>",
|
| 105 |
+
"lstrip": false,
|
| 106 |
+
"normalized": false,
|
| 107 |
+
"rstrip": false,
|
| 108 |
+
"single_word": false,
|
| 109 |
+
"special": false
|
| 110 |
+
},
|
| 111 |
+
"255002": {
|
| 112 |
+
"content": "<|YES_TOKEN|>",
|
| 113 |
+
"lstrip": false,
|
| 114 |
+
"normalized": false,
|
| 115 |
+
"rstrip": false,
|
| 116 |
+
"single_word": false,
|
| 117 |
+
"special": false
|
| 118 |
+
},
|
| 119 |
+
"255003": {
|
| 120 |
+
"content": "<|NO_TOKEN|>",
|
| 121 |
+
"lstrip": false,
|
| 122 |
+
"normalized": false,
|
| 123 |
+
"rstrip": false,
|
| 124 |
+
"single_word": false,
|
| 125 |
+
"special": false
|
| 126 |
+
},
|
| 127 |
+
"255004": {
|
| 128 |
+
"content": "<|GOOD_TOKEN|>",
|
| 129 |
+
"lstrip": false,
|
| 130 |
+
"normalized": false,
|
| 131 |
+
"rstrip": false,
|
| 132 |
+
"single_word": false,
|
| 133 |
+
"special": false
|
| 134 |
+
},
|
| 135 |
+
"255005": {
|
| 136 |
+
"content": "<|BAD_TOKEN|>",
|
| 137 |
+
"lstrip": false,
|
| 138 |
+
"normalized": false,
|
| 139 |
+
"rstrip": false,
|
| 140 |
+
"single_word": false,
|
| 141 |
+
"special": false
|
| 142 |
+
},
|
| 143 |
+
"255006": {
|
| 144 |
+
"content": "<|USER_TOKEN|>",
|
| 145 |
+
"lstrip": false,
|
| 146 |
+
"normalized": false,
|
| 147 |
+
"rstrip": false,
|
| 148 |
+
"single_word": false,
|
| 149 |
+
"special": false
|
| 150 |
+
},
|
| 151 |
+
"255007": {
|
| 152 |
+
"content": "<|CHATBOT_TOKEN|>",
|
| 153 |
+
"lstrip": false,
|
| 154 |
+
"normalized": false,
|
| 155 |
+
"rstrip": false,
|
| 156 |
+
"single_word": false,
|
| 157 |
+
"special": false
|
| 158 |
+
},
|
| 159 |
+
"255008": {
|
| 160 |
+
"content": "<|SYSTEM_TOKEN|>",
|
| 161 |
+
"lstrip": false,
|
| 162 |
+
"normalized": false,
|
| 163 |
+
"rstrip": false,
|
| 164 |
+
"single_word": false,
|
| 165 |
+
"special": false
|
| 166 |
+
},
|
| 167 |
+
"255009": {
|
| 168 |
+
"content": "<|USER_0_TOKEN|>",
|
| 169 |
+
"lstrip": false,
|
| 170 |
+
"normalized": false,
|
| 171 |
+
"rstrip": false,
|
| 172 |
+
"single_word": false,
|
| 173 |
+
"special": false
|
| 174 |
+
},
|
| 175 |
+
"255010": {
|
| 176 |
+
"content": "<|USER_1_TOKEN|>",
|
| 177 |
+
"lstrip": false,
|
| 178 |
+
"normalized": false,
|
| 179 |
+
"rstrip": false,
|
| 180 |
+
"single_word": false,
|
| 181 |
+
"special": false
|
| 182 |
+
},
|
| 183 |
+
"255011": {
|
| 184 |
+
"content": "<|USER_2_TOKEN|>",
|
| 185 |
+
"lstrip": false,
|
| 186 |
+
"normalized": false,
|
| 187 |
+
"rstrip": false,
|
| 188 |
+
"single_word": false,
|
| 189 |
+
"special": false
|
| 190 |
+
},
|
| 191 |
+
"255012": {
|
| 192 |
+
"content": "<|USER_3_TOKEN|>",
|
| 193 |
+
"lstrip": false,
|
| 194 |
+
"normalized": false,
|
| 195 |
+
"rstrip": false,
|
| 196 |
+
"single_word": false,
|
| 197 |
+
"special": false
|
| 198 |
+
},
|
| 199 |
+
"255013": {
|
| 200 |
+
"content": "<|USER_4_TOKEN|>",
|
| 201 |
+
"lstrip": false,
|
| 202 |
+
"normalized": false,
|
| 203 |
+
"rstrip": false,
|
| 204 |
+
"single_word": false,
|
| 205 |
+
"special": false
|
| 206 |
+
},
|
| 207 |
+
"255014": {
|
| 208 |
+
"content": "<|USER_5_TOKEN|>",
|
| 209 |
+
"lstrip": false,
|
| 210 |
+
"normalized": false,
|
| 211 |
+
"rstrip": false,
|
| 212 |
+
"single_word": false,
|
| 213 |
+
"special": false
|
| 214 |
+
},
|
| 215 |
+
"255015": {
|
| 216 |
+
"content": "<|USER_6_TOKEN|>",
|
| 217 |
+
"lstrip": false,
|
| 218 |
+
"normalized": false,
|
| 219 |
+
"rstrip": false,
|
| 220 |
+
"single_word": false,
|
| 221 |
+
"special": false
|
| 222 |
+
},
|
| 223 |
+
"255016": {
|
| 224 |
+
"content": "<|USER_7_TOKEN|>",
|
| 225 |
+
"lstrip": false,
|
| 226 |
+
"normalized": false,
|
| 227 |
+
"rstrip": false,
|
| 228 |
+
"single_word": false,
|
| 229 |
+
"special": false
|
| 230 |
+
},
|
| 231 |
+
"255017": {
|
| 232 |
+
"content": "<|USER_8_TOKEN|>",
|
| 233 |
+
"lstrip": false,
|
| 234 |
+
"normalized": false,
|
| 235 |
+
"rstrip": false,
|
| 236 |
+
"single_word": false,
|
| 237 |
+
"special": false
|
| 238 |
+
},
|
| 239 |
+
"255018": {
|
| 240 |
+
"content": "<|USER_9_TOKEN|>",
|
| 241 |
+
"lstrip": false,
|
| 242 |
+
"normalized": false,
|
| 243 |
+
"rstrip": false,
|
| 244 |
+
"single_word": false,
|
| 245 |
+
"special": false
|
| 246 |
+
},
|
| 247 |
+
"255019": {
|
| 248 |
+
"content": "<|START_THINKING|>",
|
| 249 |
+
"lstrip": false,
|
| 250 |
+
"normalized": false,
|
| 251 |
+
"rstrip": false,
|
| 252 |
+
"single_word": false,
|
| 253 |
+
"special": false
|
| 254 |
+
},
|
| 255 |
+
"255020": {
|
| 256 |
+
"content": "<|END_THINKING|>",
|
| 257 |
+
"lstrip": false,
|
| 258 |
+
"normalized": false,
|
| 259 |
+
"rstrip": false,
|
| 260 |
+
"single_word": false,
|
| 261 |
+
"special": false
|
| 262 |
+
},
|
| 263 |
+
"255021": {
|
| 264 |
+
"content": "<|START_RESPONSE|>",
|
| 265 |
+
"lstrip": false,
|
| 266 |
+
"normalized": false,
|
| 267 |
+
"rstrip": false,
|
| 268 |
+
"single_word": false,
|
| 269 |
+
"special": true
|
| 270 |
+
},
|
| 271 |
+
"255022": {
|
| 272 |
+
"content": "<|END_RESPONSE|>",
|
| 273 |
+
"lstrip": false,
|
| 274 |
+
"normalized": false,
|
| 275 |
+
"rstrip": false,
|
| 276 |
+
"single_word": false,
|
| 277 |
+
"special": true
|
| 278 |
+
},
|
| 279 |
+
"255023": {
|
| 280 |
+
"content": "<|START_ACTION|>",
|
| 281 |
+
"lstrip": false,
|
| 282 |
+
"normalized": false,
|
| 283 |
+
"rstrip": false,
|
| 284 |
+
"single_word": false,
|
| 285 |
+
"special": false
|
| 286 |
+
},
|
| 287 |
+
"255024": {
|
| 288 |
+
"content": "<|END_ACTION|>",
|
| 289 |
+
"lstrip": false,
|
| 290 |
+
"normalized": false,
|
| 291 |
+
"rstrip": false,
|
| 292 |
+
"single_word": false,
|
| 293 |
+
"special": false
|
| 294 |
+
},
|
| 295 |
+
"255025": {
|
| 296 |
+
"content": "<|START_TOOL_RESULT|>",
|
| 297 |
+
"lstrip": false,
|
| 298 |
+
"normalized": false,
|
| 299 |
+
"rstrip": false,
|
| 300 |
+
"single_word": false,
|
| 301 |
+
"special": false
|
| 302 |
+
},
|
| 303 |
+
"255026": {
|
| 304 |
+
"content": "<|END_TOOL_RESULT|>",
|
| 305 |
+
"lstrip": false,
|
| 306 |
+
"normalized": false,
|
| 307 |
+
"rstrip": false,
|
| 308 |
+
"single_word": false,
|
| 309 |
+
"special": false
|
| 310 |
+
},
|
| 311 |
+
"255027": {
|
| 312 |
+
"content": "<|EXTRA_8_TOKEN|>",
|
| 313 |
+
"lstrip": false,
|
| 314 |
+
"normalized": false,
|
| 315 |
+
"rstrip": false,
|
| 316 |
+
"single_word": false,
|
| 317 |
+
"special": false
|
| 318 |
+
},
|
| 319 |
+
"255028": {
|
| 320 |
+
"content": "<|NEW_FILE|>",
|
| 321 |
+
"lstrip": false,
|
| 322 |
+
"normalized": false,
|
| 323 |
+
"rstrip": false,
|
| 324 |
+
"single_word": false,
|
| 325 |
+
"special": true
|
| 326 |
+
},
|
| 327 |
+
"255029": {
|
| 328 |
+
"content": "<|BEGINNING_OF_PREFIX_FIM_TOKEN|>",
|
| 329 |
+
"lstrip": false,
|
| 330 |
+
"normalized": false,
|
| 331 |
+
"rstrip": false,
|
| 332 |
+
"single_word": false,
|
| 333 |
+
"special": false
|
| 334 |
+
},
|
| 335 |
+
"255030": {
|
| 336 |
+
"content": "<|BEGINNING_OF_MIDDLE_FIM_TOKEN|>",
|
| 337 |
+
"lstrip": false,
|
| 338 |
+
"normalized": false,
|
| 339 |
+
"rstrip": false,
|
| 340 |
+
"single_word": false,
|
| 341 |
+
"special": false
|
| 342 |
+
},
|
| 343 |
+
"255031": {
|
| 344 |
+
"content": "<|BEGINNING_OF_SUFFIX_FIM_TOKEN|>",
|
| 345 |
+
"lstrip": false,
|
| 346 |
+
"normalized": false,
|
| 347 |
+
"rstrip": false,
|
| 348 |
+
"single_word": false,
|
| 349 |
+
"special": false
|
| 350 |
+
},
|
| 351 |
+
"255032": {
|
| 352 |
+
"content": "<|END_OF_MIDDLE_FIM_TOKEN|>",
|
| 353 |
+
"lstrip": false,
|
| 354 |
+
"normalized": false,
|
| 355 |
+
"rstrip": false,
|
| 356 |
+
"single_word": false,
|
| 357 |
+
"special": false
|
| 358 |
+
}
|
| 359 |
+
}
|
| 360 |
+
}
|