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)# pip install -U transformers accelerate # 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
Update modeling_jamba.py - LoRA support in Mamba
#6
by tomeras1 - opened
- modeling_jamba.py +12 -4
modeling_jamba.py
CHANGED
|
@@ -943,14 +943,22 @@ 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 |
discrete_time_step = self.dt_proj(time_step).transpose(1, 2)
|
| 949 |
-
self.dt_proj
|
|
|
|
|
|
|
|
|
|
| 950 |
|
| 951 |
A = -torch.exp(self.A_log.float())
|
| 952 |
# 3.c perform the recurrence y ← SSM(A, B, C)(x)
|
| 953 |
-
time_proj_bias =
|
| 954 |
if cache_params is not None and cache_params.seqlen_offset > 0:
|
| 955 |
scan_outputs = selective_state_update(
|
| 956 |
cache_params.ssm_states[self.layer_idx],
|
|
|
|
| 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, "base_layer"):
|
| 947 |
+
# In case of LoRA, we need to access the base layer to get the weight
|
| 948 |
+
time_proj_bias = self.dt_proj.base_layer.bias
|
| 949 |
+
self.dt_proj.base_layer.bias = None
|
| 950 |
+
else:
|
| 951 |
+
time_proj_bias = self.dt_proj.bias
|
| 952 |
+
self.dt_proj.bias = None
|
| 953 |
discrete_time_step = self.dt_proj(time_step).transpose(1, 2)
|
| 954 |
+
if hasattr(self.dt_proj, "base_layer"):
|
| 955 |
+
self.dt_proj.base_layer.bias = time_proj_bias
|
| 956 |
+
else:
|
| 957 |
+
self.dt_proj.bias = time_proj_bias
|
| 958 |
|
| 959 |
A = -torch.exp(self.A_log.float())
|
| 960 |
# 3.c perform the recurrence y ← SSM(A, B, C)(x)
|
| 961 |
+
time_proj_bias = time_proj_bias.float() if time_proj_bias is not None else None
|
| 962 |
if cache_params is not None and cache_params.seqlen_offset > 0:
|
| 963 |
scan_outputs = selective_state_update(
|
| 964 |
cache_params.ssm_states[self.layer_idx],
|