han1997 commited on
Commit
d7ea68a
·
verified ·
1 Parent(s): d194b95

Update README.md

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