Instructions to use royleibov/Jamba-v0.1-ZipNN-Compressed with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use royleibov/Jamba-v0.1-ZipNN-Compressed with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="royleibov/Jamba-v0.1-ZipNN-Compressed", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("royleibov/Jamba-v0.1-ZipNN-Compressed", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("royleibov/Jamba-v0.1-ZipNN-Compressed", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use royleibov/Jamba-v0.1-ZipNN-Compressed with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "royleibov/Jamba-v0.1-ZipNN-Compressed" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "royleibov/Jamba-v0.1-ZipNN-Compressed", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/royleibov/Jamba-v0.1-ZipNN-Compressed
- SGLang
How to use royleibov/Jamba-v0.1-ZipNN-Compressed 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 "royleibov/Jamba-v0.1-ZipNN-Compressed" \ --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": "royleibov/Jamba-v0.1-ZipNN-Compressed", "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 "royleibov/Jamba-v0.1-ZipNN-Compressed" \ --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": "royleibov/Jamba-v0.1-ZipNN-Compressed", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use royleibov/Jamba-v0.1-ZipNN-Compressed with Docker Model Runner:
docker model run hf.co/royleibov/Jamba-v0.1-ZipNN-Compressed
Update LoRA fine-tune example - more target_modules, lower LR, bf16 (#49)
Browse files- Update LoRA fine-tune example - more target_modules, lower LR, bf16 (a69ca0f303d6079e51f4d323a81e2ec76484fc92)
Co-authored-by: Michael Gokhman <michael-go@users.noreply.huggingface.co>
README.md
CHANGED
|
@@ -96,31 +96,40 @@ model = AutoModelForCausalLM.from_pretrained("ai21labs/Jamba-v0.1",
|
|
| 96 |
</details>
|
| 97 |
|
| 98 |
### Fine-tuning example
|
| 99 |
-
Jamba is a base model that can be fine-tuned for custom solutions (including for chat/instruct versions). You can fine-tune it using any technique of your choice. Here is an example of fine-tuning with the [PEFT](https://huggingface.co/docs/peft/index) library:
|
| 100 |
|
| 101 |
```python
|
|
|
|
| 102 |
from datasets import load_dataset
|
| 103 |
-
from trl import SFTTrainer
|
| 104 |
from peft import LoraConfig
|
| 105 |
from transformers import AutoTokenizer, AutoModelForCausalLM, TrainingArguments
|
| 106 |
|
| 107 |
tokenizer = AutoTokenizer.from_pretrained("ai21labs/Jamba-v0.1")
|
| 108 |
-
model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
dataset = load_dataset("Abirate/english_quotes", split="train")
|
| 111 |
-
training_args =
|
| 112 |
output_dir="./results",
|
| 113 |
-
num_train_epochs=
|
| 114 |
per_device_train_batch_size=4,
|
| 115 |
logging_dir='./logs',
|
| 116 |
logging_steps=10,
|
| 117 |
-
learning_rate=
|
| 118 |
-
|
| 119 |
-
lora_config = LoraConfig(
|
| 120 |
-
r=8,
|
| 121 |
-
target_modules=["embed_tokens", "x_proj", "in_proj", "out_proj"],
|
| 122 |
-
task_type="CAUSAL_LM",
|
| 123 |
-
bias="none"
|
| 124 |
)
|
| 125 |
trainer = SFTTrainer(
|
| 126 |
model=model,
|
|
@@ -128,9 +137,7 @@ trainer = SFTTrainer(
|
|
| 128 |
args=training_args,
|
| 129 |
peft_config=lora_config,
|
| 130 |
train_dataset=dataset,
|
| 131 |
-
dataset_text_field="quote",
|
| 132 |
)
|
| 133 |
-
|
| 134 |
trainer.train()
|
| 135 |
```
|
| 136 |
|
|
|
|
| 96 |
</details>
|
| 97 |
|
| 98 |
### Fine-tuning example
|
| 99 |
+
Jamba is a base model that can be fine-tuned for custom solutions (including for chat/instruct versions). You can fine-tune it using any technique of your choice. Here is an example of fine-tuning with the [PEFT](https://huggingface.co/docs/peft/index) library (requires ~120GB GPU RAM, in example 2xA100 80GB):
|
| 100 |
|
| 101 |
```python
|
| 102 |
+
import torch
|
| 103 |
from datasets import load_dataset
|
| 104 |
+
from trl import SFTTrainer, SFTConfig
|
| 105 |
from peft import LoraConfig
|
| 106 |
from transformers import AutoTokenizer, AutoModelForCausalLM, TrainingArguments
|
| 107 |
|
| 108 |
tokenizer = AutoTokenizer.from_pretrained("ai21labs/Jamba-v0.1")
|
| 109 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 110 |
+
"ai21labs/Jamba-v0.1", device_map='auto', torch_dtype=torch.bfloat16)
|
| 111 |
+
|
| 112 |
+
lora_config = LoraConfig(
|
| 113 |
+
r=8,
|
| 114 |
+
target_modules=[
|
| 115 |
+
"embed_tokens",
|
| 116 |
+
"x_proj", "in_proj", "out_proj", # mamba
|
| 117 |
+
"gate_proj", "up_proj", "down_proj", # mlp
|
| 118 |
+
"q_proj", "k_proj", "v_proj" # attention
|
| 119 |
+
],
|
| 120 |
+
task_type="CAUSAL_LM",
|
| 121 |
+
bias="none"
|
| 122 |
+
)
|
| 123 |
|
| 124 |
dataset = load_dataset("Abirate/english_quotes", split="train")
|
| 125 |
+
training_args = SFTConfig(
|
| 126 |
output_dir="./results",
|
| 127 |
+
num_train_epochs=2,
|
| 128 |
per_device_train_batch_size=4,
|
| 129 |
logging_dir='./logs',
|
| 130 |
logging_steps=10,
|
| 131 |
+
learning_rate=1e-5,
|
| 132 |
+
dataset_text_field="quote",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
)
|
| 134 |
trainer = SFTTrainer(
|
| 135 |
model=model,
|
|
|
|
| 137 |
args=training_args,
|
| 138 |
peft_config=lora_config,
|
| 139 |
train_dataset=dataset,
|
|
|
|
| 140 |
)
|
|
|
|
| 141 |
trainer.train()
|
| 142 |
```
|
| 143 |
|