Views
No views yet
pip install zipnn1# Use a pipeline as a high-level helper
2from transformers import pipeline
3from zipnn import zipnn_hf
4
5zipnn_hf()
6
7pipe = pipeline("text-generation", model="royleibov/Jamba-v0.1-ZipNN-Compressed")1# Load model directly
2from transformers import AutoTokenizer, AutoModelForCausalLM
3from zipnn import zipnn_hf
4
5zipnn_hf()
6
7tokenizer = AutoTokenizer.from_pretrained("royleibov/Jamba-v0.1-ZipNN-Compressed")
8model = AutoModelForCausalLM.from_pretrained("royleibov/Jamba-v0.1-ZipNN-Compressed")python zipnn_compress_path.py safetensors --model royleibov/Jamba-v0.1-ZipNN-Compressed --hf_cachezipnn_hf() is added at the top of the file like in the example above.python zipnn_decompress_path.py --model royleibov/Jamba-v0.1-ZipNN-Compressed --hf_cachetransformers 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
2from zipnn import zipnn_hf
3
4zipnn_hf()
5
6model = AutoModelForCausalLM.from_pretrained("royleibov/Jamba-v0.1-ZipNN-Compressed")
7tokenizer = AutoTokenizer.from_pretrained("royleibov/Jamba-v0.1-ZipNN-Compressed")
8
9input_ids = tokenizer("In the recent Super Bowl LVIII,", return_tensors='pt').to(model.device)["input_ids"]
10
11outputs = model.generate(input_ids, max_new_tokens=216)
12
13print(tokenizer.batch_decode(outputs))
14# ["<|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
3from zipnn import zipnn_hf
4
5zipnn_hf()
6
7model = AutoModelForCausalLM.from_pretrained("royleibov/Jamba-v0.1-ZipNN-Compressed",
8 torch_dtype=torch.bfloat16) # you can also use torch_dtype=torch.float161from transformers import AutoModelForCausalLM
2from zipnn import zipnn_hf
3
4zipnn_hf()
5
6import torch
7model = AutoModelForCausalLM.from_pretrained("royleibov/Jamba-v0.1-ZipNN-Compressed",
8 torch_dtype=torch.bfloat16,
9 attn_implementation="flash_attention_2",
10 device_map="auto")1from transformers import AutoModelForCausalLM, BitsAndBytesConfig
2from zipnn import zipnn_hf
3
4zipnn_hf()
5
6quantization_config = BitsAndBytesConfig(load_in_8bit=True,
7 llm_int8_skip_modules=["mamba"])
8model = AutoModelForCausalLM.from_pretrained("royleibov/Jamba-v0.1-ZipNN-Compressed",
9 torch_dtype=torch.bfloat16,
10 attn_implementation="flash_attention_2",
11 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
6from zipnn import zipnn_hf
7
8zipnn_hf()
9
10tokenizer = AutoTokenizer.from_pretrained("royleibov/Jamba-v0.1-ZipNN-Compressed")
11model = AutoModelForCausalLM.from_pretrained("royleibov/Jamba-v0.1-ZipNN-Compressed",
12 device_map='auto', torch_dtype=torch.bfloat16)
13
14lora_config = LoraConfig(
15 r=8,
16 target_modules=[
17 "embed_tokens",
18 "x_proj", "in_proj", "out_proj", # mamba
19 "gate_proj", "up_proj", "down_proj", # mlp
20 "q_proj", "k_proj", "v_proj" # attention
21 ],
22 task_type="CAUSAL_LM",
23 bias="none"
24)
25
26dataset = load_dataset("Abirate/english_quotes", split="train")
27training_args = SFTConfig(
28 output_dir="./results",
29 num_train_epochs=2,
30 per_device_train_batch_size=4,
31 logging_dir='./logs',
32 logging_steps=10,
33 learning_rate=1e-5,
34 dataset_text_field="quote",
35)
36trainer = SFTTrainer(
37 model=model,
38 tokenizer=tokenizer,
39 args=training_args,
40 peft_config=lora_config,
41 train_dataset=dataset,
42)
43trainer.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% |