Instructions to use dongbobo/adapter-checkpoint with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use dongbobo/adapter-checkpoint with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b-hf") model = PeftModel.from_pretrained(base_model, "dongbobo/adapter-checkpoint") - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,17 +1,19 @@
|
|
| 1 |
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
library_name: peft
|
| 4 |
base_model: meta-llama/Llama-2-7b-hf
|
| 5 |
tags:
|
| 6 |
- lora
|
| 7 |
-
-
|
| 8 |
- causal-lm
|
|
|
|
|
|
|
| 9 |
---
|
| 10 |
|
| 11 |
-
# Adapter Checkpoint β LoRA
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
---
|
| 17 |
|
|
@@ -19,97 +21,78 @@ Load it with [π€ PEFT](https://github.com/huggingface/peft) in a single line
|
|
| 19 |
|
| 20 |
```
|
| 21 |
.
|
| 22 |
-
βββ adapter_config.json
|
| 23 |
-
βββ adapter_model.bin
|
| 24 |
-
βββ README.md
|
| 25 |
βββ examples/
|
| 26 |
βββ chat/
|
| 27 |
βββ zero_shot/
|
| 28 |
-
β βββ prompt.json
|
| 29 |
βββ few_shot/
|
| 30 |
-
βββ prompt.json
|
| 31 |
```
|
| 32 |
|
| 33 |
---
|
| 34 |
|
| 35 |
-
##
|
| 36 |
-
|
| 37 |
-
```python
|
| 38 |
-
from peft import PeftModel, PeftConfig
|
| 39 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 40 |
|
| 41 |
-
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
model.eval()
|
| 48 |
-
```
|
| 49 |
|
| 50 |
---
|
| 51 |
|
| 52 |
-
##
|
| 53 |
-
|
| 54 |
-
Two ready-to-use chat prompt templates are included.
|
| 55 |
-
Load either one and substitute `{{user_message}}` with your query.
|
| 56 |
-
|
| 57 |
-
| Strategy | File |
|
| 58 |
-
|---|---|
|
| 59 |
-
| **Zero-shot** β no in-context examples | [`examples/chat/zero_shot/prompt.json`](examples/chat/zero_shot/prompt.json) |
|
| 60 |
-
| **Few-shot** β three curated demonstrations | [`examples/chat/few_shot/prompt.json`](examples/chat/few_shot/prompt.json) |
|
| 61 |
-
|
| 62 |
-
### Zero-shot usage
|
| 63 |
|
| 64 |
```python
|
| 65 |
-
import
|
|
|
|
|
|
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
)
|
| 76 |
-
```
|
| 77 |
-
|
| 78 |
-
### Few-shot usage
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
"
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
shots = "\n".join(
|
| 87 |
-
f"User: {ex['user']}\nAssistant: {ex['assistant']}"
|
| 88 |
-
for ex in raw["template"]["examples"]
|
| 89 |
-
)
|
| 90 |
-
prompt = (
|
| 91 |
-
raw["template"]["system"] + "\n\n"
|
| 92 |
-
+ shots + "\n\n"
|
| 93 |
-
+ "User: " + "Explain black holes briefly." + "\nAssistant:"
|
| 94 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
```
|
| 96 |
|
| 97 |
---
|
| 98 |
|
| 99 |
-
## Adapter
|
| 100 |
|
| 101 |
| Parameter | Value |
|
| 102 |
|---|---|
|
| 103 |
-
| PEFT type |
|
| 104 |
-
|
|
| 105 |
-
|
|
| 106 |
-
|
|
|
|
|
| 107 |
| Target modules | `q_proj`, `v_proj` |
|
| 108 |
-
|
|
| 109 |
-
| Base model | `meta-llama/Llama-2-7b-hf` |
|
| 110 |
|
| 111 |
---
|
| 112 |
|
| 113 |
## License
|
| 114 |
|
| 115 |
-
Released under the **Apache 2.0**
|
|
|
|
|
|
|
|
|
| 1 |
---
|
|
|
|
| 2 |
library_name: peft
|
| 3 |
base_model: meta-llama/Llama-2-7b-hf
|
| 4 |
tags:
|
| 5 |
- lora
|
| 6 |
+
- peft
|
| 7 |
- causal-lm
|
| 8 |
+
- adapter
|
| 9 |
+
license: apache-2.0
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Adapter Checkpoint β LoRA on Llama-2-7b
|
| 13 |
|
| 14 |
+
This repository contains a **LoRA adapter checkpoint** fine-tuned on top of
|
| 15 |
+
[`meta-llama/Llama-2-7b-hf`](https://huggingface.co/meta-llama/Llama-2-7b-hf)
|
| 16 |
+
using [PEFT](https://github.com/huggingface/peft).
|
| 17 |
|
| 18 |
---
|
| 19 |
|
|
|
|
| 21 |
|
| 22 |
```
|
| 23 |
.
|
| 24 |
+
βββ adapter_config.json # PEFT / LoRA hyper-parameters
|
| 25 |
+
βββ adapter_model.bin # Trained adapter weights
|
| 26 |
+
βββ README.md # This file
|
| 27 |
βββ examples/
|
| 28 |
βββ chat/
|
| 29 |
βββ zero_shot/
|
| 30 |
+
β βββ prompt.json # Zero-shot chat prompt template
|
| 31 |
βββ few_shot/
|
| 32 |
+
βββ prompt.json # Few-shot chat prompt template
|
| 33 |
```
|
| 34 |
|
| 35 |
---
|
| 36 |
|
| 37 |
+
## Prompt templates
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
Two ready-to-use prompt templates are included for chat inference:
|
| 40 |
|
| 41 |
+
| Strategy | Path | Description |
|
| 42 |
+
|---|---|---|
|
| 43 |
+
| Zero-shot | [`examples/chat/zero_shot/prompt.json`](examples/chat/zero_shot/prompt.json) | Single-turn; no demonstrations β the model relies on its instruction-following capability. |
|
| 44 |
+
| Few-shot | [`examples/chat/few_shot/prompt.json`](examples/chat/few_shot/prompt.json) | Prepends three (user, assistant) demonstration turns before the live query. |
|
|
|
|
|
|
|
| 45 |
|
| 46 |
---
|
| 47 |
|
| 48 |
+
## Quick start
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
```python
|
| 51 |
+
from peft import PeftModel, PeftConfig
|
| 52 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 53 |
+
import json, pathlib
|
| 54 |
|
| 55 |
+
# Load adapter config and base model
|
| 56 |
+
config = PeftConfig.from_pretrained("dongbobo/adapter-checkpoint")
|
| 57 |
+
base = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path)
|
| 58 |
+
model = PeftModel.from_pretrained(base, "dongbobo/adapter-checkpoint")
|
| 59 |
+
tok = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
|
| 60 |
|
| 61 |
+
# Load a prompt template
|
| 62 |
+
template = json.loads(
|
| 63 |
+
pathlib.Path("examples/chat/zero_shot/prompt.json").read_text()
|
| 64 |
)
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
+
# Build prompt
|
| 67 |
+
user_msg = "Explain the concept of attention in transformers."
|
| 68 |
+
prompt = (
|
| 69 |
+
f"<s>[INST] <<SYS>>\n{template['template']['system']}\n<</SYS>>\n\n"
|
| 70 |
+
f"{user_msg} [/INST]"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
)
|
| 72 |
+
|
| 73 |
+
inputs = tok(prompt, return_tensors="pt")
|
| 74 |
+
outputs = model.generate(**inputs, max_new_tokens=256)
|
| 75 |
+
print(tok.decode(outputs[0], skip_special_tokens=True))
|
| 76 |
```
|
| 77 |
|
| 78 |
---
|
| 79 |
|
| 80 |
+
## Adapter hyper-parameters
|
| 81 |
|
| 82 |
| Parameter | Value |
|
| 83 |
|---|---|
|
| 84 |
+
| PEFT type | LORA |
|
| 85 |
+
| Task type | CAUSAL\_LM |
|
| 86 |
+
| Rank (`r`) | 16 |
|
| 87 |
+
| LoRA alpha | 32 |
|
| 88 |
+
| LoRA dropout | 0.05 |
|
| 89 |
| Target modules | `q_proj`, `v_proj` |
|
| 90 |
+
| Bias | none |
|
|
|
|
| 91 |
|
| 92 |
---
|
| 93 |
|
| 94 |
## License
|
| 95 |
|
| 96 |
+
Released under the **Apache 2.0** license.
|
| 97 |
+
The base model (`meta-llama/Llama-2-7b-hf`) is subject to its own
|
| 98 |
+
[Llama 2 Community License](https://huggingface.co/meta-llama/Llama-2-7b-hf/blob/main/LICENSE.txt).
|