Update README.md
Browse files
README.md
CHANGED
@@ -1,6 +1,45 @@
|
|
1 |
---
|
2 |
library_name: peft
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
## Training procedure
|
5 |
|
6 |
|
|
|
1 |
---
|
2 |
library_name: peft
|
3 |
---
|
4 |
+
|
5 |
+
|
6 |
+
## Model Usage
|
7 |
+
```python
|
8 |
+
import torch
|
9 |
+
import transformers
|
10 |
+
from finetune_peft import get_peft_config, PEFTArguments
|
11 |
+
from peft import get_peft_model
|
12 |
+
|
13 |
+
model_path = 'Salesforce/codegen25-7b-mono'
|
14 |
+
# peft_path = 'models/codegen25_7b/checkpoint'
|
15 |
+
peft_path = '0xk1h0/codegen25-7b-py150k-r20'
|
16 |
+
# peft_path = 'models/alpaca-llama-7b-peft/params.p'
|
17 |
+
|
18 |
+
torch.set_default_tensor_type(torch.cuda.HalfTensor)
|
19 |
+
model = transformers.AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True, cache_dir='models')
|
20 |
+
peft_config = get_peft_config(peft_args=PEFTArguments(peft_mode="lora"))
|
21 |
+
model = get_peft_model(model, peft_config)
|
22 |
+
# model.load_state_dict(torch.load(peft_path), strict=False)
|
23 |
+
torch.set_default_tensor_type(torch.cuda.FloatTensor)
|
24 |
+
|
25 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
26 |
+
batch = tokenizer("""
|
27 |
+
### Generate AES MODE encrypt function.
|
28 |
+
""", return_tensors="pt")
|
29 |
+
|
30 |
+
with torch.no_grad():
|
31 |
+
out = model.generate(
|
32 |
+
input_ids=batch["input_ids"],
|
33 |
+
attention_mask=torch.ones_like(batch["input_ids"]),
|
34 |
+
max_length=256,
|
35 |
+
do_sample=True,
|
36 |
+
temperature = 0.4,
|
37 |
+
top_p=0.95
|
38 |
+
|
39 |
+
)
|
40 |
+
print(tokenizer.decode(out[0]))
|
41 |
+
```
|
42 |
+
|
43 |
## Training procedure
|
44 |
|
45 |
|