Instructions to use sarvamai/sarvam-m with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use sarvamai/sarvam-m with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="sarvamai/sarvam-m") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("sarvamai/sarvam-m") model = AutoModelForCausalLM.from_pretrained("sarvamai/sarvam-m", device_map="auto") 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]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use sarvamai/sarvam-m with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "sarvamai/sarvam-m" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sarvamai/sarvam-m", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/sarvamai/sarvam-m
- SGLang
How to use sarvamai/sarvam-m 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 "sarvamai/sarvam-m" \ --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": "sarvamai/sarvam-m", "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 "sarvamai/sarvam-m" \ --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": "sarvamai/sarvam-m", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use sarvamai/sarvam-m with Docker Model Runner:
docker model run hf.co/sarvamai/sarvam-m
Update README.md
Browse files
README.md
CHANGED
|
@@ -98,7 +98,7 @@ print("content:", content)
|
|
| 98 |
> For thinking mode, we recommend `temperature=0.4`; for no-think mode, `temperature=0.2`.
|
| 99 |
|
| 100 |
|
| 101 |
-
#
|
| 102 |
|
| 103 |
```python
|
| 104 |
from openai import OpenAI
|
|
@@ -120,7 +120,7 @@ messages = [
|
|
| 120 |
response1 = client.chat.completions.create(
|
| 121 |
model=model_name,
|
| 122 |
messages=messages,
|
| 123 |
-
reasoning_effort="medium", # Enable thinking mode
|
| 124 |
max_completion_tokens=4096,
|
| 125 |
)
|
| 126 |
print("First response:", response1.choices[0].message.content)
|
|
@@ -151,9 +151,9 @@ Refer to API docs here: [sarvam API docs](https://docs.sarvam.ai/api-reference-d
|
|
| 151 |
|
| 152 |
# VLLM Deployment
|
| 153 |
|
| 154 |
-
For easy deployment, we can use `vllm>=0.8.5` and create an OpenAI-compatible API endpoint with `vllm serve sarvamai/sarvam-m`
|
| 155 |
|
| 156 |
-
|
| 157 |
|
| 158 |
```python
|
| 159 |
from openai import OpenAI
|
|
@@ -172,7 +172,7 @@ model = models.data[0].id
|
|
| 172 |
|
| 173 |
messages = [{"role": "user", "content": "Why is 42 the best number?"}]
|
| 174 |
|
| 175 |
-
# By default,
|
| 176 |
# If you want to disable thinking, add:
|
| 177 |
# extra_body={"chat_template_kwargs": {"enable_thinking": False}}
|
| 178 |
response = client.chat.completions.create(model=model, messages=messages)
|
|
@@ -196,13 +196,9 @@ messages.append(
|
|
| 196 |
|
| 197 |
# Running the model on a CPU
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
You can use the model using cli as explained in docs https://github.com/ggml-org/llama.cpp/tree/master/tools/main
|
| 202 |
|
| 203 |
Example Command:
|
| 204 |
```
|
| 205 |
-
./build/bin/llama-cli -i -m /
|
| 206 |
-
```
|
| 207 |
-
|
| 208 |
-
We got about 4 tokens per second on 16 cores with q8 model.
|
|
|
|
| 98 |
> For thinking mode, we recommend `temperature=0.4`; for no-think mode, `temperature=0.2`.
|
| 99 |
|
| 100 |
|
| 101 |
+
# With Sarvam APIs
|
| 102 |
|
| 103 |
```python
|
| 104 |
from openai import OpenAI
|
|
|
|
| 120 |
response1 = client.chat.completions.create(
|
| 121 |
model=model_name,
|
| 122 |
messages=messages,
|
| 123 |
+
reasoning_effort="medium", # Enable thinking mode. `None` for disable.
|
| 124 |
max_completion_tokens=4096,
|
| 125 |
)
|
| 126 |
print("First response:", response1.choices[0].message.content)
|
|
|
|
| 151 |
|
| 152 |
# VLLM Deployment
|
| 153 |
|
| 154 |
+
For easy deployment, we can use `vllm>=0.8.5` and create an OpenAI-compatible API endpoint with `vllm serve sarvamai/sarvam-m`.
|
| 155 |
|
| 156 |
+
If you want to use vLLM with python, you can do the following.
|
| 157 |
|
| 158 |
```python
|
| 159 |
from openai import OpenAI
|
|
|
|
| 172 |
|
| 173 |
messages = [{"role": "user", "content": "Why is 42 the best number?"}]
|
| 174 |
|
| 175 |
+
# By default, thinking mode is enabled.
|
| 176 |
# If you want to disable thinking, add:
|
| 177 |
# extra_body={"chat_template_kwargs": {"enable_thinking": False}}
|
| 178 |
response = client.chat.completions.create(model=model, messages=messages)
|
|
|
|
| 196 |
|
| 197 |
# Running the model on a CPU
|
| 198 |
|
| 199 |
+
This repo contains quantized (q8) version of the model as well. You can use the model on your local machine (without gpu) as explained [here](docs https://github.com/ggml-org/llama.cpp/tree/master/tools/main).
|
|
|
|
|
|
|
| 200 |
|
| 201 |
Example Command:
|
| 202 |
```
|
| 203 |
+
./build/bin/llama-cli -i -m /your/folder/path/sarvam-m-q8_0.gguf -c 8192 -t 16
|
| 204 |
+
```
|
|
|
|
|
|