dongbobo commited on
Commit
1c54602
Β·
verified Β·
1 Parent(s): 70858c1

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +49 -66
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
- - adapter
8
  - causal-lm
 
 
9
  ---
10
 
11
- # Adapter Checkpoint β€” LoRA fine-tune on Llama-2-7b
12
 
13
- A lightweight **LoRA** adapter trained on top of `meta-llama/Llama-2-7b-hf` for conversational tasks.
14
- Load it with [πŸ€— PEFT](https://github.com/huggingface/peft) in a single line β€” no full model retraining required.
 
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 # PEFT / LoRA hyper-parameters
23
- β”œβ”€β”€ adapter_model.bin # Trained adapter weights
24
- β”œβ”€β”€ README.md
25
  └── examples/
26
  └── chat/
27
  β”œβ”€β”€ zero_shot/
28
- β”‚ └── prompt.json # Zero-shot chat prompt template
29
  └── few_shot/
30
- └── prompt.json # Few-shot chat prompt template
31
  ```
32
 
33
  ---
34
 
35
- ## Quick start
36
-
37
- ```python
38
- from peft import PeftModel, PeftConfig
39
- from transformers import AutoModelForCausalLM, AutoTokenizer
40
 
41
- repo_id = "dongbobo/adapter-checkpoint"
42
 
43
- config = PeftConfig.from_pretrained(repo_id)
44
- tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
45
- base = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path)
46
- model = PeftModel.from_pretrained(base, repo_id)
47
- model.eval()
48
- ```
49
 
50
  ---
51
 
52
- ## Prompt templates
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 json, requests
 
 
66
 
67
- raw = requests.get(
68
- "https://huggingface.co/dongbobo/adapter-checkpoint/resolve/main/"
69
- "examples/chat/zero_shot/prompt.json"
70
- ).json()
 
71
 
72
- prompt = (
73
- raw["template"]["system"] + "\n\n"
74
- + raw["template"]["user"].replace("{{user_message}}", "Explain black holes briefly.")
75
  )
76
- ```
77
-
78
- ### Few-shot usage
79
 
80
- ```python
81
- raw = requests.get(
82
- "https://huggingface.co/dongbobo/adapter-checkpoint/resolve/main/"
83
- "examples/chat/few_shot/prompt.json"
84
- ).json()
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 configuration
100
 
101
  | Parameter | Value |
102
  |---|---|
103
- | PEFT type | `LORA` |
104
- | Rank (`r`) | 8 |
105
- | Alpha | 16 |
106
- | Dropout | 0.05 |
 
107
  | Target modules | `q_proj`, `v_proj` |
108
- | Task type | `CAUSAL_LM` |
109
- | Base model | `meta-llama/Llama-2-7b-hf` |
110
 
111
  ---
112
 
113
  ## License
114
 
115
- Released under the **Apache 2.0** licence. See [LICENSE](https://www.apache.org/licenses/LICENSE-2.0) for details.
 
 
 
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).