Instructions to use ai21labs/Jamba-v0.1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ai21labs/Jamba-v0.1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ai21labs/Jamba-v0.1", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("ai21labs/Jamba-v0.1", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("ai21labs/Jamba-v0.1", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ai21labs/Jamba-v0.1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ai21labs/Jamba-v0.1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ai21labs/Jamba-v0.1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/ai21labs/Jamba-v0.1
- SGLang
How to use ai21labs/Jamba-v0.1 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 "ai21labs/Jamba-v0.1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ai21labs/Jamba-v0.1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "ai21labs/Jamba-v0.1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ai21labs/Jamba-v0.1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use ai21labs/Jamba-v0.1 with Docker Model Runner:
docker model run hf.co/ai21labs/Jamba-v0.1
Fix bias logic to enable QLoRA finetuning
Browse fileswhen using the qlora technique, dt_proj doesn't have a bias attribute, resulting in an AttributeError. This change allows for qlora finetuning with an approximate train loss ~1-ish.
- modeling_jamba.py +10 -4
modeling_jamba.py
CHANGED
|
@@ -943,10 +943,16 @@ class JambaMambaMixer(nn.Module):
|
|
| 943 |
# in order to make quantization work. Quantization code replaces `torch.nn.Linear` layers with quantized
|
| 944 |
# linear layers, and requires to call the forward pass directly.
|
| 945 |
# The original code here was: ```discrete_time_step = self.dt_proj.weight @ time_step.transpose(1, 2)```
|
| 946 |
-
|
| 947 |
-
|
| 948 |
-
|
| 949 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 950 |
|
| 951 |
A = -torch.exp(self.A_log.float())
|
| 952 |
# 3.c perform the recurrence y ← SSM(A, B, C)(x)
|
|
|
|
| 943 |
# in order to make quantization work. Quantization code replaces `torch.nn.Linear` layers with quantized
|
| 944 |
# linear layers, and requires to call the forward pass directly.
|
| 945 |
# The original code here was: ```discrete_time_step = self.dt_proj.weight @ time_step.transpose(1, 2)```
|
| 946 |
+
if hasattr(self.dt_proj, "bias")
|
| 947 |
+
dt_proj_bias = self.dt_proj.bias
|
| 948 |
+
self.dt_proj.bias = None
|
| 949 |
+
discrete_time_step = self.dt_proj(time_step).transpose(1, 2)
|
| 950 |
+
self.dt_proj.bias = dt_proj_bias
|
| 951 |
+
else:
|
| 952 |
+
dt_proj_bias = self.dt_proj.base_layer.bias
|
| 953 |
+
self.dt_proj.base_layer.bias = None
|
| 954 |
+
discrete_time_step = self.dt_proj(time_step).transpose(1, 2)
|
| 955 |
+
self.dt_proj.base_layer.bias = dt_proj_bias
|
| 956 |
|
| 957 |
A = -torch.exp(self.A_log.float())
|
| 958 |
# 3.c perform the recurrence y ← SSM(A, B, C)(x)
|