arnocandel
commited on
Commit
•
07a1c9f
1
Parent(s):
cf67bde
Upload README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,164 @@
|
|
1 |
---
|
2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
library_name: transformers
|
6 |
+
inference: false
|
7 |
---
|
8 |
+
# h2oGPT Model Card
|
9 |
+
## Summary
|
10 |
+
|
11 |
+
H2O.ai's `h2ogpt-oig-oasst1-256-6.9b` is a 6.9 billion parameter instruction-following large language model licensed for commercial use.
|
12 |
+
|
13 |
+
- Base model: EleutherAI/pythia-6.9b
|
14 |
+
- Fine-tuning dataset: [h2oai/h2ogpt-oig-oasst1-instruct-cleaned-v1](https://huggingface.co/datasets/h2oai/h2ogpt-oig-oasst1-instruct-cleaned-v1)
|
15 |
+
- Data-prep and fine-tuning code: [H2O.ai Github](https://github.com/h2oai/h2ogpt)
|
16 |
+
- Training logs: [zip](https://huggingface.co/h2oai/h2ogpt-oig-oasst1-256-6.9b/blob/main/pythia-6.9b.h2ogpt-oig-oasst1-instruct-cleaned-v1.json.1_epochs.5fc91911bc2bfaaf3b6c2de577c4b0ae45a07a4a.9.zip)
|
17 |
+
|
18 |
+
## Usage
|
19 |
+
|
20 |
+
To use the model with the `transformers` library on a machine with GPUs, first make sure you have the `transformers` and `accelerate` libraries installed.
|
21 |
+
|
22 |
+
```bash
|
23 |
+
pip install transformers==4.28.1
|
24 |
+
```
|
25 |
+
|
26 |
+
```python
|
27 |
+
import torch
|
28 |
+
from transformers import pipeline
|
29 |
+
|
30 |
+
generate_text = pipeline(model="h2oai/h2ogpt-oig-oasst1-256-6.9b", torch_dtype=torch.bfloat16, trust_remote_code=True, device_map="auto")
|
31 |
+
res = generate_text("Why is drinking water so healthy?")
|
32 |
+
print(res[0]["generated_text"])
|
33 |
+
```
|
34 |
+
|
35 |
+
Alternatively, if you prefer to not use `trust_remote_code=True` you can download [instruct_pipeline.py](https://huggingface.co/h2oai/h2ogpt-oig-oasst1-256-6.9b/blob/main/h2oai_pipeline.py),
|
36 |
+
store it alongside your notebook, and construct the pipeline yourself from the loaded model and tokenizer:
|
37 |
+
|
38 |
+
```
|
39 |
+
import torch
|
40 |
+
from h2oai_pipeline import H2OTextGenerationPipeline
|
41 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
42 |
+
tokenizer = AutoTokenizer.from_pretrained("h2oai/h2ogpt-oig-oasst1-256-6.9b", padding_side="left")
|
43 |
+
model = AutoModelForCausalLM.from_pretrained("h2oai/h2ogpt-oig-oasst1-256-6.9b", device_map="auto", torch_dtype=torch.bfloat16)
|
44 |
+
|
45 |
+
generate_text = H2OTextGenerationPipeline(model=model, tokenizer=tokenizer)
|
46 |
+
```
|
47 |
+
|
48 |
+
### LangChain Usage
|
49 |
+
|
50 |
+
To use the pipeline with LangChain, you must set `return_full_text=True`, as LangChain expects the full text to be returned
|
51 |
+
and the default for the pipeline is to only return the new text.
|
52 |
+
|
53 |
+
```
|
54 |
+
import torch
|
55 |
+
from transformers import pipeline
|
56 |
+
|
57 |
+
generate_text = pipeline(model="h2oai/h2ogpt-oig-oasst1-256-6.9b", torch_dtype=torch.bfloat16,
|
58 |
+
trust_remote_code=True, device_map="auto", return_full_text=True)
|
59 |
+
```
|
60 |
+
|
61 |
+
You can create a prompt that either has only an instruction or has an instruction with context:
|
62 |
+
|
63 |
+
```
|
64 |
+
from langchain import PromptTemplate, LLMChain
|
65 |
+
from langchain.llms import HuggingFacePipeline
|
66 |
+
|
67 |
+
# template for an instrution with no input
|
68 |
+
prompt = PromptTemplate(
|
69 |
+
input_variables=["instruction"],
|
70 |
+
template="{instruction}")
|
71 |
+
|
72 |
+
# template for an instruction with input
|
73 |
+
prompt_with_context = PromptTemplate(
|
74 |
+
input_variables=["instruction", "context"],
|
75 |
+
template="{instruction}\n\nInput:\n{context}")
|
76 |
+
|
77 |
+
hf_pipeline = HuggingFacePipeline(pipeline=generate_text)
|
78 |
+
|
79 |
+
llm_chain = LLMChain(llm=hf_pipeline, prompt=prompt)
|
80 |
+
llm_context_chain = LLMChain(llm=hf_pipeline, prompt=prompt_with_context)
|
81 |
+
```
|
82 |
+
|
83 |
+
Example predicting using a simple instruction:
|
84 |
+
|
85 |
+
```
|
86 |
+
print(llm_chain.predict(instruction="Why is drinking water so healthy?").lstrip())
|
87 |
+
```
|
88 |
+
|
89 |
+
Example predicting using an instruction with context:
|
90 |
+
|
91 |
+
```
|
92 |
+
context = """Model A: AUC=0.8
|
93 |
+
Model from Driverless AI: AUC=0.95
|
94 |
+
Model C: AUC=0.6
|
95 |
+
Model D: AUC=0.7
|
96 |
+
"""
|
97 |
+
|
98 |
+
print(llm_context_chain.predict(instruction="Which model performs best?", context=context).lstrip())
|
99 |
+
```
|
100 |
+
|
101 |
+
## Model Architecture
|
102 |
+
|
103 |
+
```
|
104 |
+
GPTNeoXForCausalLM(
|
105 |
+
(gpt_neox): GPTNeoXModel(
|
106 |
+
(embed_in): Embedding(50432, 4096)
|
107 |
+
(layers): ModuleList(
|
108 |
+
(0-31): 32 x GPTNeoXLayer(
|
109 |
+
(input_layernorm): LayerNorm((4096,), eps=1e-05, elementwise_affine=True)
|
110 |
+
(post_attention_layernorm): LayerNorm((4096,), eps=1e-05, elementwise_affine=True)
|
111 |
+
(attention): GPTNeoXAttention(
|
112 |
+
(rotary_emb): RotaryEmbedding()
|
113 |
+
(query_key_value): Linear(in_features=4096, out_features=12288, bias=True)
|
114 |
+
(dense): Linear(in_features=4096, out_features=4096, bias=True)
|
115 |
+
)
|
116 |
+
(mlp): GPTNeoXMLP(
|
117 |
+
(dense_h_to_4h): Linear(in_features=4096, out_features=16384, bias=True)
|
118 |
+
(dense_4h_to_h): Linear(in_features=16384, out_features=4096, bias=True)
|
119 |
+
(act): GELUActivation()
|
120 |
+
)
|
121 |
+
)
|
122 |
+
)
|
123 |
+
(final_layer_norm): LayerNorm((4096,), eps=1e-05, elementwise_affine=True)
|
124 |
+
)
|
125 |
+
(embed_out): Linear(in_features=4096, out_features=50432, bias=False)
|
126 |
+
)
|
127 |
+
```
|
128 |
+
|
129 |
+
## Model Configuration
|
130 |
+
|
131 |
+
```
|
132 |
+
GPTNeoXConfig {
|
133 |
+
"_name_or_path": "h2oai/h2ogpt-oig-oasst1-256-6.9b",
|
134 |
+
"architectures": [
|
135 |
+
"GPTNeoXForCausalLM"
|
136 |
+
],
|
137 |
+
"bos_token_id": 0,
|
138 |
+
"custom_pipelines": {
|
139 |
+
"text-generation": {
|
140 |
+
"impl": "h2oai_pipeline.H2OTextGenerationPipeline",
|
141 |
+
"pt": "AutoModelForCausalLM"
|
142 |
+
}
|
143 |
+
},
|
144 |
+
"eos_token_id": 0,
|
145 |
+
"hidden_act": "gelu",
|
146 |
+
"hidden_size": 4096,
|
147 |
+
"initializer_range": 0.02,
|
148 |
+
"intermediate_size": 16384,
|
149 |
+
"layer_norm_eps": 1e-05,
|
150 |
+
"max_position_embeddings": 2048,
|
151 |
+
"model_type": "gpt_neox",
|
152 |
+
"num_attention_heads": 32,
|
153 |
+
"num_hidden_layers": 32,
|
154 |
+
"rotary_emb_base": 10000,
|
155 |
+
"rotary_pct": 0.25,
|
156 |
+
"tie_word_embeddings": false,
|
157 |
+
"torch_dtype": "float16",
|
158 |
+
"transformers_version": "4.28.1",
|
159 |
+
"use_cache": true,
|
160 |
+
"use_parallel_residual": true,
|
161 |
+
"vocab_size": 50432
|
162 |
+
}
|
163 |
+
|
164 |
+
```
|