han1997 commited on
Commit
59acd3e
1 Parent(s): 596be8d

Create README.md

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