Views
No views yet
1# Install MLX and dependencies
2pip install mlx-lm transformers
3
4# For chat functionality (optional)
5pip install gradio[INST] Your question here [/INST]1from mlx_lm import load, generate
2
3# Load the model
4model, tokenizer = load("your-username/sarvam-m-4bit-mlx")
5
6# Simple generation
7response = generate(
8 model,
9 tokenizer,
10 prompt="What is the capital of India?",
11 max_tokens=50
12)
13print(response)1from mlx_lm import load, generate
2
3model, tokenizer = load("your-username/sarvam-m-4bit-mlx")
4
5# No thinking mode (direct answers)
6messages = [{'role': 'user', 'content': 'What is 2+2?'}]
7prompt = tokenizer.apply_chat_template(
8 messages,
9 tokenize=False,
10 enable_thinking=False
11)
12response = generate(model, tokenizer, prompt=prompt, max_tokens=20)
13print(response) # Output: The sum of 2 and 2 is **4**.
14
15# With thinking mode (shows reasoning)
16messages = [{'role': 'user', 'content': 'Solve: 15 * 23'}]
17prompt = tokenizer.apply_chat_template(
18 messages,
19 tokenize=False,
20 enable_thinking=True
21)
22response = generate(model, tokenizer, prompt=prompt, max_tokens=100)
23print(response) # Output: <think>Let me calculate...</think> The answer is 345.1# Hindi conversation
2messages = [{'role': 'user', 'content': 'भारत की राजधानी क्या है?'}]
3prompt = tokenizer.apply_chat_template(
4 messages,
5 tokenize=False,
6 enable_thinking=False
7)
8response = generate(model, tokenizer, prompt=prompt, max_tokens=50)
9print(response)
10# Output: भारत की राजधानी **नई दिल्ली** है। यह देश की राजनीतिक, प्रशासनिक...1# Code generation
2messages = [{'role': 'user', 'content': 'Write a Python function to calculate fibonacci numbers'}]
3prompt = tokenizer.apply_chat_template(
4 messages,
5 tokenize=False,
6 enable_thinking=False
7)
8response = generate(model, tokenizer, prompt=prompt, max_tokens=150)
9print(response)1# Simple generation
2python -m mlx_lm generate \
3 --model your-username/sarvam-m-4bit-mlx \
4 --prompt "Hello, how are you?" \
5 --max-tokens 50
6
7# Interactive chat
8python -m mlx_lm chat --model your-username/sarvam-m-4bit-mlx| Metric | Value |
|---|---|
| Model Size | ~12GB |
| Peak Memory Usage | ~13.3GB |
| Generation Speed | 18-36 tokens/sec |
| Quantization Bits | 4.5 bits per weight |
| Supported Languages | 11 (English + 10 Indic) |
1@misc{sarvam-m-mlx,
2 title={Sarvam-M 4-bit MLX: Quantized Indian Language Model for Apple Silicon},
3 author={Community Contribution},
4 year={2025},
5 url={https://huggingface.co/your-username/sarvam-m-4bit-mlx}
6}