Views
No views yet
transformers version 4.39.0 or higher:pip install transformers>=4.39.0mamba-ssm and causal-conv1d:pip install mamba-ssm causal-conv1d>=1.2.0use_mamba_kernels=False when loading the model.trust_remote_code=True is required for running the new Jamba architecture.1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model = AutoModelForCausalLM.from_pretrained("ai21labs/Jamba-v0.1",
4 trust_remote_code=True)
5tokenizer = AutoTokenizer.from_pretrained("ai21labs/Jamba-v0.1")
6
7input_ids = tokenizer("In the recent Super Bowl LVIII,", return_tensors='pt').to(model.device)["input_ids"]
8
9outputs = model.generate(input_ids, max_new_tokens=216)
10
11print(tokenizer.batch_decode(outputs))
12# ["<|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"]torch_dtype:1from transformers import AutoModelForCausalLM
2import torch
3model = AutoModelForCausalLM.from_pretrained("ai21labs/Jamba-v0.1",
4 trust_remote_code=True,
5 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 trust_remote_code=True,
5 torch_dtype=torch.bfloat16,
6 attn_implementation="flash_attention_2",
7 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 trust_remote_code=True,
6 torch_dtype=torch.bfloat16,
7 attn_implementation="flash_attention_2",
8 quantization_config=quantization_config)1from datasets import load_dataset
2from trl import SFTTrainer
3from peft import LoraConfig
4from transformers import AutoTokenizer, AutoModelForCausalLM, TrainingArguments
5
6tokenizer = AutoTokenizer.from_pretrained("ai21labs/Jamba-v0.1")
7model = AutoModelForCausalLM.from_pretrained("ai21labs/Jamba-v0.1", trust_remote_code=True, device_map='auto')
8
9dataset = load_dataset("Abirate/english_quotes", split="train")
10training_args = TrainingArguments(
11 output_dir="./results",
12 num_train_epochs=3,
13 per_device_train_batch_size=4,
14 logging_dir='./logs',
15 logging_steps=10,
16 learning_rate=2e-3
17)
18lora_config = LoraConfig(
19 r=8,
20 target_modules=["embed_tokens", "x_proj", "in_proj", "out_proj"],
21 task_type="CAUSAL_LM",
22 bias="none"
23)
24trainer = SFTTrainer(
25 model=model,
26 tokenizer=tokenizer,
27 args=training_args,
28 peft_config=lora_config,
29 train_dataset=dataset,
30 dataset_text_field="quote",
31)
32
33trainer.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% |