Views
No views yet
transformers version 4.40.0 or higher (version 4.39.0 or higher is required):pip install transformers>=4.40.0mamba-ssm and causal-conv1d:pip install mamba-ssm causal-conv1d>=1.2.0use_mamba_kernels=False when loading the model.1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model = AutoModelForCausalLM.from_pretrained("ai21labs/Jamba-v0.1")
4tokenizer = AutoTokenizer.from_pretrained("ai21labs/Jamba-v0.1")
5
6input_ids = tokenizer("In the recent Super Bowl LVIII,", return_tensors='pt').to(model.device)["input_ids"]
7
8outputs = model.generate(input_ids, max_new_tokens=216)
9
10print(tokenizer.batch_decode(outputs))
11# ["<|startoftext|>In the recent Super Bowl LVIII, the Kansas City Chiefs emerged victorious, defeating the San Francisco 49ers in a thrilling overtime showdown. The game was a nail-biter, with both teams showcasing their skills and determination.\n\nThe Chiefs, led by their star quarterback Patrick Mahomes, displayed their offensive prowess, while the 49ers, led by their strong defense, put up a tough fight. The game went into overtime, with the Chiefs ultimately securing the win with a touchdown.\n\nThe victory marked the Chiefs' second Super Bowl win in four years, solidifying their status as one of the top teams in the NFL. The game was a testament to the skill and talent of both teams, and a thrilling end to the NFL season.\n\nThe Super Bowl is not just about the game itself, but also about the halftime show and the commercials. This year's halftime show featured a star-studded lineup, including Usher, Alicia Keys, and Lil Jon. The show was a spectacle of music and dance, with the performers delivering an energetic and entertaining performance.\n"]transformers<4.40.0, trust_remote_code=True is required for running the new Jamba architecture.torch_dtype:1from transformers import AutoModelForCausalLM
2import torch
3model = AutoModelForCausalLM.from_pretrained("ai21labs/Jamba-v0.1",
4 torch_dtype=torch.bfloat16) # you can also use torch_dtype=torch.float161from transformers import AutoModelForCausalLM
2import torch
3model = AutoModelForCausalLM.from_pretrained("ai21labs/Jamba-v0.1",
4 torch_dtype=torch.bfloat16,
5 attn_implementation="flash_attention_2",
6 device_map="auto")1from transformers import AutoModelForCausalLM, BitsAndBytesConfig
2quantization_config = BitsAndBytesConfig(load_in_8bit=True,
3 llm_int8_skip_modules=["mamba"])
4model = AutoModelForCausalLM.from_pretrained("ai21labs/Jamba-v0.1",
5 torch_dtype=torch.bfloat16,
6 attn_implementation="flash_attention_2",
7 quantization_config=quantization_config)1import torch
2from datasets import load_dataset
3from trl import SFTTrainer, SFTConfig
4from peft import LoraConfig
5from transformers import AutoTokenizer, AutoModelForCausalLM, TrainingArguments
6
7tokenizer = AutoTokenizer.from_pretrained("ai21labs/Jamba-v0.1")
8model = AutoModelForCausalLM.from_pretrained(
9 "ai21labs/Jamba-v0.1", device_map='auto', torch_dtype=torch.bfloat16)
10
11lora_config = LoraConfig(
12 r=8,
13 target_modules=[
14 "embed_tokens",
15 "x_proj", "in_proj", "out_proj", # mamba
16 "gate_proj", "up_proj", "down_proj", # mlp
17 "q_proj", "k_proj", "v_proj" # attention
18 ],
19 task_type="CAUSAL_LM",
20 bias="none"
21)
22
23dataset = load_dataset("Abirate/english_quotes", split="train")
24training_args = SFTConfig(
25 output_dir="./results",
26 num_train_epochs=2,
27 per_device_train_batch_size=4,
28 logging_dir='./logs',
29 logging_steps=10,
30 learning_rate=1e-5,
31 dataset_text_field="quote",
32)
33trainer = SFTTrainer(
34 model=model,
35 tokenizer=tokenizer,
36 args=training_args,
37 peft_config=lora_config,
38 train_dataset=dataset,
39)
40trainer.train()| Benchmark | Score |
|---|---|
| HellaSwag | 87.1% |
| Arc Challenge | 64.4% |
| WinoGrande | 82.5% |
| PIQA | 83.2% |
| MMLU | 67.4% |
| BBH | 45.4% |
| TruthfulQA | 46.4% |
| GSM8K (CoT) | 59.9% |