Update README.md
Browse files
README.md
CHANGED
@@ -1,202 +1,158 @@
|
|
1 |
---
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
-
#
|
7 |
|
8 |
-
|
9 |
|
|
|
10 |
|
11 |
|
12 |
-
## Model
|
13 |
|
14 |
-
|
|
|
15 |
|
16 |
-
|
|
|
|
|
17 |
|
|
|
|
|
18 |
|
|
|
19 |
|
20 |
-
|
21 |
-
- **Funded by [optional]:** [More Information Needed]
|
22 |
-
- **Shared by [optional]:** [More Information Needed]
|
23 |
-
- **Model type:** [More Information Needed]
|
24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
25 |
-
- **License:** [More Information Needed]
|
26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
27 |
|
28 |
-
|
29 |
|
30 |
-
<!-- Provide the basic links for the model. -->
|
31 |
|
32 |
-
- **Repository:** [More Information Needed]
|
33 |
-
- **Paper [optional]:** [More Information Needed]
|
34 |
-
- **Demo [optional]:** [More Information Needed]
|
35 |
|
36 |
-
##
|
37 |
|
38 |
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
39 |
|
40 |
-
###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
43 |
-
|
44 |
-
[More Information Needed]
|
45 |
-
|
46 |
-
### Downstream Use [optional]
|
47 |
-
|
48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
49 |
-
|
50 |
-
[More Information Needed]
|
51 |
-
|
52 |
-
### Out-of-Scope Use
|
53 |
-
|
54 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
55 |
-
|
56 |
-
[More Information Needed]
|
57 |
-
|
58 |
-
## Bias, Risks, and Limitations
|
59 |
-
|
60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
61 |
-
|
62 |
-
[More Information Needed]
|
63 |
-
|
64 |
-
### Recommendations
|
65 |
-
|
66 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
67 |
-
|
68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
69 |
-
|
70 |
-
## How to Get Started with the Model
|
71 |
-
|
72 |
-
Use the code below to get started with the model.
|
73 |
-
|
74 |
-
[More Information Needed]
|
75 |
-
|
76 |
-
## Training Details
|
77 |
-
|
78 |
-
### Training Data
|
79 |
-
|
80 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
81 |
-
|
82 |
-
[More Information Needed]
|
83 |
-
|
84 |
-
### Training Procedure
|
85 |
-
|
86 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
87 |
-
|
88 |
-
#### Preprocessing [optional]
|
89 |
-
|
90 |
-
[More Information Needed]
|
91 |
-
|
92 |
-
|
93 |
-
#### Training Hyperparameters
|
94 |
-
|
95 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
96 |
-
|
97 |
-
#### Speeds, Sizes, Times [optional]
|
98 |
-
|
99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
100 |
-
|
101 |
-
[More Information Needed]
|
102 |
|
103 |
## Evaluation
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
### Testing Data, Factors & Metrics
|
108 |
-
|
109 |
-
#### Testing Data
|
110 |
-
|
111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
112 |
-
|
113 |
-
[More Information Needed]
|
114 |
|
115 |
-
#### Factors
|
116 |
|
117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
#### Metrics
|
122 |
-
|
123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
124 |
-
|
125 |
-
[More Information Needed]
|
126 |
-
|
127 |
-
### Results
|
128 |
-
|
129 |
-
[More Information Needed]
|
130 |
-
|
131 |
-
#### Summary
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
## Model Examination [optional]
|
136 |
-
|
137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
138 |
-
|
139 |
-
[More Information Needed]
|
140 |
-
|
141 |
-
## Environmental Impact
|
142 |
-
|
143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
144 |
-
|
145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
146 |
-
|
147 |
-
- **Hardware Type:** [More Information Needed]
|
148 |
-
- **Hours used:** [More Information Needed]
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
-
|
153 |
-
## Technical Specifications [optional]
|
154 |
-
|
155 |
-
### Model Architecture and Objective
|
156 |
-
|
157 |
-
[More Information Needed]
|
158 |
-
|
159 |
-
### Compute Infrastructure
|
160 |
-
|
161 |
-
[More Information Needed]
|
162 |
-
|
163 |
-
#### Hardware
|
164 |
-
|
165 |
-
[More Information Needed]
|
166 |
-
|
167 |
-
#### Software
|
168 |
-
|
169 |
-
[More Information Needed]
|
170 |
-
|
171 |
-
## Citation [optional]
|
172 |
-
|
173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
174 |
-
|
175 |
-
**BibTeX:**
|
176 |
-
|
177 |
-
[More Information Needed]
|
178 |
-
|
179 |
-
**APA:**
|
180 |
-
|
181 |
-
[More Information Needed]
|
182 |
-
|
183 |
-
## Glossary [optional]
|
184 |
-
|
185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
186 |
-
|
187 |
-
[More Information Needed]
|
188 |
|
189 |
-
## More Information [optional]
|
190 |
|
191 |
-
[More Information Needed]
|
192 |
|
193 |
-
|
|
|
194 |
|
195 |
-
[More Information Needed]
|
196 |
|
197 |
-
## Model Card Contact
|
198 |
|
199 |
-
|
200 |
-
### Framework versions
|
201 |
|
202 |
-
|
|
|
|
1 |
---
|
2 |
+
license: apache-2.0
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
pipeline_tag: text-generation
|
6 |
+
library_name: transformers
|
7 |
---
|
8 |
|
9 |
+
# Granite 3.2 8B Instruct - Requirement Checker
|
10 |
|
11 |
+
Welcome to Granite Experiments!
|
12 |
|
13 |
+
Think of Experiments as a preview of what's to come. These projects are still under development, but we wanted to let the open-source community take them for spin! Use them, break them, and help us build what's next for Granite – we'll keep an eye out for feedback and questions in the [Community section](https://huggingface.co/ibm-granite/granite-uncertainty-3.0-8b-lora/discussions). Happy exploring!
|
14 |
|
15 |
|
16 |
+
## Model Summary
|
17 |
|
18 |
+
**Granite 3.2 8b Instruct - Requirement Checker** is an Activated LoRA (aLoRA) adapter for [ibm-granite/granite-3.2-8b-instruct](https://huggingface.co/ibm-granite/granite-3.2-8b-instruct),
|
19 |
+
adding the capability to check if specified requirements were satisfied by the last model generation. Only one requirement is checked at a time (but can be checked in parallel).
|
20 |
|
21 |
+
- **Developer:** IBM Research
|
22 |
+
- **Model type:** Activated LoRA adapter for [ibm-granite/granite-3.2-8b-instruct](https://huggingface.co/ibm-granite/granite-3.2-8b-instruct)
|
23 |
+
- **License:** [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
24 |
|
25 |
+
## Activated LoRA
|
26 |
+
Activated LoRA (aLoRA) is a new low rank adapter architecture that allows for reusing existing base model KV cache for more efficient inference.
|
27 |
|
28 |
+
Whitepaper
|
29 |
|
30 |
+
[IBM Research Blogpost](https://research.ibm.com/blog/inference-friendly-aloras)
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
+
[Github - needed to run inference](https://github.com/IBM/activated-lora)
|
33 |
|
|
|
34 |
|
|
|
|
|
|
|
35 |
|
36 |
+
## Usage
|
37 |
|
38 |
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
39 |
|
40 |
+
### Intended use
|
41 |
+
|
42 |
+
This is an experimental aLoRA testing new functionality being developed for IBM's Granite LLM family. We are welcoming the community to test it out and give us feedback, but we are NOT recommending this model be used for real deployments at this time. Stay tuned for more updates on the Granite roadmap.
|
43 |
+
|
44 |
+
**Usage steps** Given a generation task and a set of requirements:
|
45 |
+
|
46 |
+
1. Use the base model to generate a response as normal (via the `assistant` role), with the prompt describing the task followed by "Requirements:"" and the list of active requirements.
|
47 |
+
2. Repeat the requirement to be checked.
|
48 |
+
3. The Requirement Checker model will respond with "Y" or "N", where "Y" means the requirement is satisfied. Note, any additional text after the "Y/N" can be ignored. You can curb additional generation by setting "max token length" = 1.
|
49 |
+
|
50 |
+
|
51 |
+
### Quickstart Example
|
52 |
+
|
53 |
+
The following code describes how to use the Granite Uncertainty model to answer questions and obtain intrinsic calibrated certainty scores.
|
54 |
+
|
55 |
+
The code required for Activated LoRA is on [Github](https://github.com/IBM/activated-lora)
|
56 |
+
|
57 |
+
Prior to running the code below, either clone the repo or install as
|
58 |
+
|
59 |
+
```
|
60 |
+
pip install git+ssh://[email protected]:IBM/activated-lora.git
|
61 |
+
```
|
62 |
+
|
63 |
+
Note that two generation options are shown - one illustrating the KV cache reuse ability of aLoRA (faster), and another showing the simplest generation call (slower).
|
64 |
+
```python
|
65 |
+
import torch,os
|
66 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, DynamicCache
|
67 |
+
from alora.peft_model_alora import aLoRAPeftModelForCausalLM
|
68 |
+
from alora.config import aLoraConfig
|
69 |
+
from alora.tokenize_alora import tokenize_alora
|
70 |
+
|
71 |
+
REUSE_CACHE = False
|
72 |
+
|
73 |
+
token = os.getenv("HF_MISTRAL_TOKEN")
|
74 |
+
BASE_NAME = "ibm-granite/granite-3.2-8b-instruct"
|
75 |
+
LORA_NAME = "ibm-granite/granite-3.2-8b-alora-requirement-check"
|
76 |
+
device=torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
77 |
+
|
78 |
+
# Load model
|
79 |
+
tokenizer = AutoTokenizer.from_pretrained(BASE_NAME,padding_side='left',trust_remote_code=True, token=token)
|
80 |
+
model_base = AutoModelForCausalLM.from_pretrained(BASE_NAME,device_map="auto")
|
81 |
+
model_req_check = aLoRAPeftModelForCausalLM.from_pretrained(model_base, LORA_NAME)
|
82 |
+
|
83 |
+
question = "What is IBM Research?"
|
84 |
+
print("Question:" + question)
|
85 |
+
question_chat = [
|
86 |
+
{
|
87 |
+
"role": "user",
|
88 |
+
"content": question
|
89 |
+
},
|
90 |
+
]
|
91 |
+
|
92 |
+
# Generate answer with base model
|
93 |
+
input_text = tokenizer.apply_chat_template(question_chat,tokenize=False,add_generation_prompt=True)
|
94 |
+
# Remove default system prompt
|
95 |
+
len_sys = len(input_text.split("<|start_of_role|>user"))
|
96 |
+
input_text = input_text[len_sys:]
|
97 |
+
|
98 |
+
#tokenize
|
99 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
100 |
+
if REUSE_CACHE: #save KV cache for future aLoRA call
|
101 |
+
prompt_cache = DynamicCache()
|
102 |
+
with model_req_check.disable_adapter():
|
103 |
+
output_dict = model_base.generate(inputs["input_ids"].to(device), attention_mask=inputs["attention_mask"].to(device), max_new_tokens=600,past_key_values = prompt_cache, return_dict_in_generate=True)
|
104 |
+
answer_cache = output_dict.past_key_values
|
105 |
+
output = output_dict.sequences
|
106 |
+
else: #simplest call
|
107 |
+
with model_req_check.disable_adapter():
|
108 |
+
output = model_req_check.generate(inputs["input_ids"].to(device), attention_mask=inputs["attention_mask"].to(device), max_new_tokens=600)
|
109 |
+
output_text = tokenizer.decode(output[0])
|
110 |
+
answer = output_text.split("assistant<|end_of_role|>")[1]
|
111 |
+
print("Answer: " + answer)
|
112 |
+
|
113 |
+
# Generate requirement check
|
114 |
+
req_generation_prompt = "<|start_of_role|>check_requirement<|end_of_role|>"
|
115 |
+
req_chat = question_chat + [
|
116 |
+
{
|
117 |
+
"role": "assistant",
|
118 |
+
"content": answer
|
119 |
+
},
|
120 |
+
]
|
121 |
+
|
122 |
+
req_text = tokenizer.apply_chat_template(req_chat,tokenize=False)
|
123 |
+
req_text = req_text[len_sys:]
|
124 |
+
# tokenize and generate
|
125 |
+
inputs, alora_offsets = tokenize_alora(tokenizer,req_text, req_generation_prompt)
|
126 |
+
|
127 |
+
if REUSE_CACHE: #reuse KV cache from earlier answer generation
|
128 |
+
output = model_req_check.generate(inputs["input_ids"].to(device), attention_mask=inputs["attention_mask"].to(device), max_new_tokens=1,alora_offsets=alora_offsets,past_key_values=answer_cache)
|
129 |
+
else: #simplest call
|
130 |
+
output = model_req_check.generate(inputs["input_ids"].to(device), attention_mask=inputs["attention_mask"].to(device), max_new_tokens=1,alora_offsets=alora_offsets)
|
131 |
+
output_text = tokenizer.decode(output[0])
|
132 |
+
|
133 |
+
# Extract score
|
134 |
+
req_score = output_text[-1]
|
135 |
+
print("Requirement Satisfied: " + req_score)
|
136 |
+
```
|
137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
|
139 |
## Evaluation
|
140 |
|
141 |
+
The model was evaluated on held-out synthetic data. Classification error rate is 3.5%.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
|
145 |
+
## Training Details
|
146 |
+
The **Granite Requirement Checker 3.2 8b** model is an aLoRA adapter finetuned to check whether the specified requirement was satisfied by the last assisstant turn generation.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
|
150 |
+
### Training Data
|
151 |
+
Synthetic data generated by Mixtral 8x22b.
|
152 |
|
|
|
153 |
|
|
|
154 |
|
155 |
+
## Model Card Authors
|
|
|
156 |
|
157 |
+
Kristjan Greenewald
|
158 |
+
Bo Wu
|