Command R7B is a 7-billion-parameter multilingual model developed by Cohere and Cohere For AI, designed for advanced tasks like reasoning, summarization, question answering, and code generation. With a context length of 128K and optimized transformer architecture, it supports both conversational and instruct modes, making it suitable for interactive dialogues and task-focused applications. The model excels in Retrieval Augmented Generation (RAG), tool integration, and enterprise code use cases, offering robust capabilities across 23 languages.
Benchmark Table
Command R7B | Gemma 2 IT 9B | Ministral 8B | Llama 3.1 8B | Qwen 2.5 7B | Tulu 3 8B |
---|
Average | 31.4 | 28.9 | 22 | 28.2 | 26.87 | 26.03 |
IFEval | 77.9 | 74.4 | 58.96 | 78.6 | 75.85 | 82.67 |
BBH | 36.1 | 42.1 | 25.82 | 29.9 | 34.89 | 16.67 |
MATH hard | 26.4 | 0.2 | 6.5 | 19.3 | 0.0 | 19.64 |
GPQA | 7.7 | 14.8 | 4.5 | 2.4 | 5.48 | 6.49 |
MUSR | 11.6 | 9.74 | 10.7 | 8.41 | 8.45 | 10.45 |
MMLU-Pro | 28.5 | 32 | 25.5 | 30.7 | 36.52 | 20.3 |
Model Resource
Hugging Face
Link: https://huggingface.co/CohereForAI/c4ai-command-r7b-12-2024
Ollama
Link: https://ollama.com/library/command-r7b
Prerequisites for Installing Command R7B Model Locally
- GPU:
- Memory (VRAM):
- Minimum: 16GB (with 8-bit or 4-bit quantization).
- Recommended: 24GB for smoother execution.
- Optimal: 48GB for full performance at FP16 precision.
- Type: NVIDIA GPUs with Tensor Cores (e.g., RTX 4090, A6000, A100, H100).
- Disk Space:
- Minimum: 40GB free SSD storage.
- Recommended: 100GB SSD for storing additional checkpoints, logs, and datasets.
- RAM:
- Minimum: 24GB.
- Recommended: 48GB for smoother operation, especially with large datasets.
- CPU:
- Minimum: 16 cores.
- Recommended: 24-48 cores for fast data preprocessing and I/O operations.
Step-by-Step Process to Install Command R7B Model Locally
For the purpose of this tutorial, we will use a GPU-powered Virtual Machine offered by NodeShift; however, you can replicate the same steps with any other cloud provider of your choice. NodeShift provides the most affordable Virtual Machines at a scale that meets GDPR, SOC2, and ISO27001 requirements.
Step 1: Sign Up and Set Up a NodeShift Cloud Account
Visit the NodeShift Platform and create an account. Once you’ve signed up, log into your account.
Follow the account setup process and provide the necessary details and information.
Step 2: Create a GPU Node (Virtual Machine)
GPU Nodes are NodeShift’s GPU Virtual Machines, on-demand resources equipped with diverse GPUs ranging from H100s to A100s. These GPU-powered VMs provide enhanced environmental control, allowing configuration adjustments for GPUs, CPUs, RAM, and Storage based on specific requirements.
Navigate to the menu on the left side. Select the GPU Nodes option, create a GPU Node in the Dashboard, click the Create GPU Node button, and create your first Virtual Machine deployment.
Step 3: Select a Model, Region, and Storage
In the “GPU Nodes” tab, select a GPU Model and Storage according to your needs and the geographical region where you want to launch your model.
We will use 1x RTX A6000 GPU for this tutorial to achieve the fastest performance. However, you can choose a more affordable GPU with less VRAM if that better suits your requirements.
Step 4: Select Authentication Method
There are two authentication methods available: Password and SSH Key. SSH keys are a more secure option. To create them, please refer to our official documentation.
Step 5: Choose an Image
Next, you will need to choose an image for your Virtual Machine. We will deploy Command R7B on an NVIDIA Cuda Virtual Machine. This proprietary, closed-source parallel computing platform will allow you to install Command R7B on your GPU Node.
After choosing the image, click the ‘Create’ button, and your Virtual Machine will be deployed.
Step 6: Virtual Machine Successfully Deployed
You will get visual confirmation that your node is up and running.
Step 7: Connect to GPUs using SSH
NodeShift GPUs can be connected to and controlled through a terminal using the SSH key provided during GPU creation.
Once your GPU Node deployment is successfully created and has reached the ‘RUNNING’ status, you can navigate to the page of your GPU Deployment Instance. Then, click the ‘Connect’ button in the top right corner.
Now open your terminal and paste the proxy SSH IP or direct SSH IP.
Next, if you want to check the GPU details, run the command below:
nvidia-smi
Step 8: Install Ollama
After connecting to the terminal via SSH, it’s now time to install Ollama from the official Ollama website.
Website Link: https://ollama.com/
Run the following command to install the Ollama:
curl -fsSL https://ollama.com/install.sh | sh
Step 9: Serve Ollama
Run the following command to host the Ollama so that it can be accessed and utilized efficiently:
ollama serve
Now, “Ollama is running.”
Step 10: Select command-r7b Model
Link: https://ollama.com/library/command-r7b
Command R7B model is available in only one size: 7B. We will run it on our GPU virtual machine.
Step 11: Connect with SSH
Now, open a new tab in the terminal and reconnect using SSH.
Step 12: Check Commands
Run, the following command to see a list of available commands:
ollama
Step 13: Check Available Models
Run the following command to check if the downloaded model are available:
ollama list
Step 14: Pull Command R7B Model
Run the following command to pull the Command R7B model:
ollama pull command-r7b
Step 15: Run command-r7b Model
Now, you can run the model in the terminal using the following command and interact with your model:
ollama run command-r7b
Note: This is a step-by-step guide for interacting with your model. It covers the first method for installing Command R7B locally using Ollama and running it in the terminal.
Option 1: Using Ollama (Terminal)
- Install Ollama: Download and install the Ollama tool from the official site.
- Pull the Model: Run the following command to download the desired model:
ollama pull command-r7b
- Run the Model: Start the model in the terminal:
ollama run command-r7b
Option 2: Using Open WebUI
- Set Up Open WebUI:
Follow our Open WebUI Setup Guide to configure the interface. Ensure all dependencies are installed and the environment is correctly set up.
- Refresh the Interface:
Confirm that the Command R7B model has been downloaded and is visible in the list of available models on the Open WebUI.
- Select Your Model:
Choose the Command R7B model from the list. This model is available in a single size.
- Start Interaction:
Begin using the model by entering your queries in the interface. The Command R7B is designed for high-quality instruction-based interactions, so input clear and detailed queries for the best results.
Option 3: Using Hugging Face and Jupyter Notebook
- Follow our Jupyter Notebook Setup Guide to configure your notebook environment. Ensure that all required dependencies are installed and that your Jupyter Notebook is set up correctly for optimal use.
When choosing an image for your Virtual Machine, select the Jupyter Notebook image. This open-source platform allows you to install and run the Command R7B model on your GPU node. By running this model on a Jupyter Notebook, you can avoid using the terminal, simplifying the process and reducing setup time. This approach enables you to configure the model in just a few steps and minutes.
Note: NodeShift provides multiple image template options, such as TensorFlow, PyTorch, NVIDIA CUDA, Deepo, Whisper ASR Webservice, and Jupyter Notebook. With these options, you don’t need to install additional libraries or packages to run Jupyter Notebook. You can start Jupyter Notebook in just a few simple clicks.
- Access model from Hugging Face:
Link: https://huggingface.co/CohereForAI/c4ai-command-r7b-12-2024
You need to agree to share your contact information to access this model. Fill in all the mandatory details, such as your name and affiliation, and then wait for approval from Hugging Face and CohereForAI to gain access and use the model.
You will be granted access to this model within an minute, provided you have filled in all the details correctly.
GPU Recommendations
GPU Model | VRAM | Ideal Use Case |
---|
RTX 3090 | 24GB | Suitable for quantized 8-bit/4-bit inference. |
RTX 4090 | 24GB | Excellent for inference and lightweight tasks. |
A6000 | 48GB | Optimal for FP16 inference and fine-tuning. |
A100 (40GB) | 40GB | Great for general training and inference. |
A100 (80GB) | 80GB | Ideal for extended context length (128k). |
H100 (80GB) | 80GB | Best for large-scale fine-tuning and RAG tasks. |
System Configuration Summary
After setting up the VM and running your Jupyter Notebook, start installing the Command R7B model.
1. Install Dependencies
Ensure Python 3.9+ is installed. Then, run the following command to install the dependencies:
pip install torch transformers safetensors
2. Verify GPU
Check GPU availability in Jupyter Notebook:
import torch
print("CUDA available:", torch.cuda.is_available())
print("Device name:", torch.cuda.get_device_name(0))
3. Download the Model
- Log in to Hugging Face:bashCopyEdit
huggingface-cli login --token <your_hugging_face_token>
2. Download the model files:
huggingface-cli download CohereForAI/c4ai-command-r7b-12-2024 --include "original/*" --local-dir c4ai-command-r7b
4. Load the Model
Run this code in your Jupyter Notebook:
from transformers import AutoTokenizer, AutoModelForCausalLM
# Model and tokenizer setup
model_id = "CohereForAI/c4ai-command-r7b-12-2024"
tokenizer = AutoTokenizer.from_pretrained(model_id)
# Load the model
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
torch_dtype=torch.float16
)
# Test input
messages = [{"role": "user", "content": "Hello, how are you?"}]
input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to("cuda")
# Generate response
gen_tokens = model.generate(
input_ids,
max_new_tokens=100,
do_sample=True,
temperature=0.3,
)
gen_text = tokenizer.decode(gen_tokens[0], skip_special_tokens=True)
print(gen_text)
5. Memory Optimization (Optional)
- Quantization: Use 8-bit or 4-bit to reduce memory usage.pythonCopyEdit
from transformers import BitsAndBytesConfig
quantization_config = BitsAndBytesConfig(load_in_8bit=True) # Use `load_in_4bit=True` for 4-bit.
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
torch_dtype=torch.float16,
quantization_config=quantization_config
)
2. Reduce Token Length: Set max_new_tokens
to a lower value for constrained GPUs.
6. Optional: Tool Use
Add external tool capabilities as follows:
# Define a tool function
def get_weather(location: str) -> str:
return f"The weather in {location} is sunny and 25°C."
# Input messages with a tool query
messages = [{"role": "user", "content": "What is the weather in Paris?"}]
# Use the tool in conversation
input_ids = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to("cuda")
gen_tokens = model.generate(input_ids, max_new_tokens=50)
gen_text = tokenizer.decode(gen_tokens[0], skip_special_tokens=True)
print(gen_text)
You’re ready to use the model! 🚀
Conclusion
In conclusion, the Command R7B model stands out as a robust and versatile multilingual model tailored for advanced tasks such as reasoning, summarization, question answering, and code generation. Its exceptional capabilities, including Retrieval Augmented Generation (RAG), tool integration, and support for extended context lengths, make it ideal for both conversational and task-specific applications. With detailed setup guides and compatibility across platforms like Ollama, Open WebUI, and Jupyter Notebook, the model offers flexibility for researchers and developers to explore its full potential in diverse use cases efficiently.