Instructions to use CohereLabs/c4ai-command-r-v01-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use CohereLabs/c4ai-command-r-v01-4bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="CohereLabs/c4ai-command-r-v01-4bit", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("CohereLabs/c4ai-command-r-v01-4bit", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("CohereLabs/c4ai-command-r-v01-4bit", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use CohereLabs/c4ai-command-r-v01-4bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "CohereLabs/c4ai-command-r-v01-4bit" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "CohereLabs/c4ai-command-r-v01-4bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/CohereLabs/c4ai-command-r-v01-4bit
- SGLang
How to use CohereLabs/c4ai-command-r-v01-4bit with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "CohereLabs/c4ai-command-r-v01-4bit" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "CohereLabs/c4ai-command-r-v01-4bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "CohereLabs/c4ai-command-r-v01-4bit" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "CohereLabs/c4ai-command-r-v01-4bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use CohereLabs/c4ai-command-r-v01-4bit with Docker Model Runner:
docker model run hf.co/CohereLabs/c4ai-command-r-v01-4bit
OSError: CohereForAI/c4ai-command-r-v01 does not appear to have a file named configuration_cohere.py
Hi,
When I want to use the model, I got following error:
OSError: CohereForAI/c4ai-command-r-v01 does not appear to have a file named configuration_cohere.py. Checkout 'https://huggingface.co/CohereForAI/c4ai-command-r-v01/main' for available files.
Would you please help me to address this issue?
update transformers to 4.39.1 or higher
@drinkingxi
Thanks. I have used transformers==4.39.3 and python=3.9.16, but I have faced above error. Would you please help me to address it? (In fact, I downloaded the model, about 20 days ago, and then move it from my home/.cache/huggingface/hub to another folder and then when I want to load it from this new address I faced above error. When I remove it completely and want to download it again, I also faced above error.)
same error.
I resolved it by removing the auto_map key from config.json and adding exist_ok=True to the arguments of the register function in the last lines of configuration_cohere.py and tokenization_cohere_fast.py.
I'm not sure why this is happening, but...
@leonaci
Thanks a lot for your help. But, I got following error again (after removing the auto_map key from config.json ):
OSError: It looks like the config file at '/HuggingFace_Models/c4ai/models--CohereForAI--c4ai-command-r-v01-4bit/snapshots/183f6e1182a46c223dde00ebf1ace9194ea221aa/config.json' is not a valid JSON file.
Why is such a fundamental issue still open after a month?