RichardErkhov
commited on
Commit
•
d2e7168
1
Parent(s):
fd51590
uploaded readme
Browse files
README.md
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Quantization made by Richard Erkhov.
|
2 |
+
|
3 |
+
[Github](https://github.com/RichardErkhov)
|
4 |
+
|
5 |
+
[Discord](https://discord.gg/pvy7H8DZMG)
|
6 |
+
|
7 |
+
[Request more models](https://github.com/RichardErkhov/quant_request)
|
8 |
+
|
9 |
+
|
10 |
+
mamba-1.4b-hf - bnb 8bits
|
11 |
+
- Model creator: https://huggingface.co/state-spaces/
|
12 |
+
- Original model: https://huggingface.co/state-spaces/mamba-1.4b-hf/
|
13 |
+
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
Original model description:
|
18 |
+
---
|
19 |
+
library_name: transformers
|
20 |
+
tags: []
|
21 |
+
---
|
22 |
+
|
23 |
+
# Mamba
|
24 |
+
|
25 |
+
<!-- Provide a quick summary of what the model is/does. -->
|
26 |
+
This repository contains the `transfromers` compatible `mamba-2.8b`. The checkpoints are untouched, but the full `config.json` and tokenizer are pushed to this repo.
|
27 |
+
|
28 |
+
# Usage
|
29 |
+
|
30 |
+
You need to install `transformers` from `main` until `transformers=4.39.0` is released.
|
31 |
+
```bash
|
32 |
+
pip install git+https://github.com/huggingface/transformers@main
|
33 |
+
```
|
34 |
+
|
35 |
+
We also recommend you to install both `causal_conv_1d` and `mamba-ssm` using:
|
36 |
+
|
37 |
+
```bash
|
38 |
+
pip install causal-conv1d>=1.2.0
|
39 |
+
pip install mamba-ssm
|
40 |
+
```
|
41 |
+
|
42 |
+
If any of these two is not installed, the "eager" implementation will be used. Otherwise the more optimised `cuda` kernels will be used.
|
43 |
+
|
44 |
+
## Generation
|
45 |
+
You can use the classic `generate` API:
|
46 |
+
```python
|
47 |
+
>>> from transformers import MambaConfig, MambaForCausalLM, AutoTokenizer
|
48 |
+
>>> import torch
|
49 |
+
|
50 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("state-spaces/mamba-1.4b-hf")
|
51 |
+
>>> model = MambaForCausalLM.from_pretrained("state-spaces/mamba-1.4b-hf")
|
52 |
+
>>> input_ids = tokenizer("Hey how are you doing?", return_tensors="pt")["input_ids"]
|
53 |
+
|
54 |
+
>>> out = model.generate(input_ids, max_new_tokens=10)
|
55 |
+
>>> print(tokenizer.batch_decode(out))
|
56 |
+
["Hey how are you doing?\n\nI'm doing great.\n\nI"]
|
57 |
+
```
|
58 |
+
|
59 |
+
## PEFT finetuning example
|
60 |
+
In order to finetune using the `peft` library, we recommend keeping the model in float32!
|
61 |
+
|
62 |
+
```python
|
63 |
+
from datasets import load_dataset
|
64 |
+
from trl import SFTTrainer
|
65 |
+
from peft import LoraConfig
|
66 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, TrainingArguments
|
67 |
+
tokenizer = AutoTokenizer.from_pretrained("state-spaces/mamba-1.4b-hf")
|
68 |
+
model = AutoModelForCausalLM.from_pretrained("state-spaces/mamba-1.4b-hf")
|
69 |
+
dataset = load_dataset("Abirate/english_quotes", split="train")
|
70 |
+
training_args = TrainingArguments(
|
71 |
+
output_dir="./results",
|
72 |
+
num_train_epochs=3,
|
73 |
+
per_device_train_batch_size=4,
|
74 |
+
logging_dir='./logs',
|
75 |
+
logging_steps=10,
|
76 |
+
learning_rate=2e-3
|
77 |
+
)
|
78 |
+
lora_config = LoraConfig(
|
79 |
+
r=8,
|
80 |
+
target_modules=["x_proj", "embeddings", "in_proj", "out_proj"],
|
81 |
+
task_type="CAUSAL_LM",
|
82 |
+
bias="none"
|
83 |
+
)
|
84 |
+
trainer = SFTTrainer(
|
85 |
+
model=model,
|
86 |
+
tokenizer=tokenizer,
|
87 |
+
args=training_args,
|
88 |
+
peft_config=lora_config,
|
89 |
+
train_dataset=dataset,
|
90 |
+
dataset_text_field="quote",
|
91 |
+
)
|
92 |
+
trainer.train()
|
93 |
+
```
|
94 |
+
|