Ketak-ZoomRx commited on
Commit
6c6a032
1 Parent(s): 73ae6f9

Upload model card

Browse files
Files changed (1) hide show
  1. README.md +193 -0
README.md ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ library_name: transformers
5
+ tags:
6
+ - gpt
7
+ - llm
8
+ - large language model
9
+ - h2o-llmstudio
10
+ inference: false
11
+ thumbnail: https://h2o.ai/etc.clientlibs/h2o/clientlibs/clientlib-site/resources/images/favicon.ico
12
+ ---
13
+ # Model Card
14
+ ## Summary
15
+
16
+ This model was trained using [H2O LLM Studio](https://github.com/h2oai/h2o-llmstudio).
17
+ - Base model: [facebook/opt-2.7b](https://huggingface.co/facebook/opt-2.7b)
18
+
19
+
20
+ ## Usage
21
+
22
+ To use the model with the `transformers` library on a machine with GPUs, first make sure you have the `transformers`, `accelerate` and `torch` libraries installed.
23
+
24
+ ```bash
25
+ pip install transformers==4.29.2
26
+ pip install einops==0.6.1
27
+ pip install accelerate==0.19.0
28
+ pip install torch==2.0.0
29
+ ```
30
+
31
+ ```python
32
+ import torch
33
+ from transformers import pipeline
34
+
35
+ generate_text = pipeline(
36
+ model="Ketak-ZoomRx/fb_trial",
37
+ torch_dtype="auto",
38
+ trust_remote_code=True,
39
+ use_fast=True,
40
+ device_map={"": "cuda:0"},
41
+ )
42
+
43
+ res = generate_text(
44
+ "Why is drinking water so healthy?",
45
+ min_new_tokens=2,
46
+ max_new_tokens=256,
47
+ do_sample=False,
48
+ num_beams=1,
49
+ temperature=float(0.0),
50
+ repetition_penalty=float(1.2),
51
+ renormalize_logits=True
52
+ )
53
+ print(res[0]["generated_text"])
54
+ ```
55
+
56
+ You can print a sample prompt after the preprocessing step to see how it is feed to the tokenizer:
57
+
58
+ ```python
59
+ print(generate_text.preprocess("Why is drinking water so healthy?")["prompt_text"])
60
+ ```
61
+
62
+ ```bash
63
+ <|prompt|>Why is drinking water so healthy?</s><|answer|>
64
+ ```
65
+
66
+ Alternatively, you can download [h2oai_pipeline.py](h2oai_pipeline.py), store it alongside your notebook, and construct the pipeline yourself from the loaded model and tokenizer. If the model and the tokenizer are fully supported in the `transformers` package, this will allow you to set `trust_remote_code=False`.
67
+
68
+ ```python
69
+ import torch
70
+ from h2oai_pipeline import H2OTextGenerationPipeline
71
+ from transformers import AutoModelForCausalLM, AutoTokenizer
72
+
73
+ tokenizer = AutoTokenizer.from_pretrained(
74
+ "Ketak-ZoomRx/fb_trial",
75
+ use_fast=True,
76
+ padding_side="left",
77
+ trust_remote_code=True,
78
+ )
79
+ model = AutoModelForCausalLM.from_pretrained(
80
+ "Ketak-ZoomRx/fb_trial",
81
+ torch_dtype="auto",
82
+ device_map={"": "cuda:0"},
83
+ trust_remote_code=True,
84
+ )
85
+ generate_text = H2OTextGenerationPipeline(model=model, tokenizer=tokenizer)
86
+
87
+ res = generate_text(
88
+ "Why is drinking water so healthy?",
89
+ min_new_tokens=2,
90
+ max_new_tokens=256,
91
+ do_sample=False,
92
+ num_beams=1,
93
+ temperature=float(0.0),
94
+ repetition_penalty=float(1.2),
95
+ renormalize_logits=True
96
+ )
97
+ print(res[0]["generated_text"])
98
+ ```
99
+
100
+
101
+ You may also construct the pipeline from the loaded model and tokenizer yourself and consider the preprocessing steps:
102
+
103
+ ```python
104
+ from transformers import AutoModelForCausalLM, AutoTokenizer
105
+
106
+ model_name = "Ketak-ZoomRx/fb_trial" # either local folder or huggingface model name
107
+ # Important: The prompt needs to be in the same format the model was trained with.
108
+ # You can find an example prompt in the experiment logs.
109
+ prompt = "<|prompt|>How are you?</s><|answer|>"
110
+
111
+ tokenizer = AutoTokenizer.from_pretrained(
112
+ model_name,
113
+ use_fast=True,
114
+ trust_remote_code=True,
115
+ )
116
+ model = AutoModelForCausalLM.from_pretrained(
117
+ model_name,
118
+ torch_dtype="auto",
119
+ device_map={"": "cuda:0"},
120
+ trust_remote_code=True,
121
+ )
122
+ model.cuda().eval()
123
+ inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False).to("cuda")
124
+
125
+ # generate configuration can be modified to your needs
126
+ tokens = model.generate(
127
+ input_ids=inputs["input_ids"],
128
+ attention_mask=inputs["attention_mask"],
129
+ min_new_tokens=2,
130
+ max_new_tokens=256,
131
+ do_sample=False,
132
+ num_beams=1,
133
+ temperature=float(0.0),
134
+ repetition_penalty=float(1.2),
135
+ renormalize_logits=True
136
+ )[0]
137
+
138
+ tokens = tokens[inputs["input_ids"].shape[1]:]
139
+ answer = tokenizer.decode(tokens, skip_special_tokens=True)
140
+ print(answer)
141
+ ```
142
+
143
+ ## Quantization and sharding
144
+
145
+ You can load the models using quantization by specifying ```load_in_8bit=True``` or ```load_in_4bit=True```. Also, sharding on multiple GPUs is possible by setting ```device_map=auto```.
146
+
147
+ ## Model Architecture
148
+
149
+ ```
150
+ OPTForCausalLM(
151
+ (model): OPTModel(
152
+ (decoder): OPTDecoder(
153
+ (embed_tokens): Embedding(50272, 2560, padding_idx=1)
154
+ (embed_positions): OPTLearnedPositionalEmbedding(2050, 2560)
155
+ (final_layer_norm): LayerNorm((2560,), eps=1e-05, elementwise_affine=True)
156
+ (layers): ModuleList(
157
+ (0-31): 32 x OPTDecoderLayer(
158
+ (self_attn): OPTAttention(
159
+ (k_proj): Linear(in_features=2560, out_features=2560, bias=True)
160
+ (v_proj): Linear(in_features=2560, out_features=2560, bias=True)
161
+ (q_proj): Linear(in_features=2560, out_features=2560, bias=True)
162
+ (out_proj): Linear(in_features=2560, out_features=2560, bias=True)
163
+ )
164
+ (activation_fn): ReLU()
165
+ (self_attn_layer_norm): LayerNorm((2560,), eps=1e-05, elementwise_affine=True)
166
+ (fc1): Linear(in_features=2560, out_features=10240, bias=True)
167
+ (fc2): Linear(in_features=10240, out_features=2560, bias=True)
168
+ (final_layer_norm): LayerNorm((2560,), eps=1e-05, elementwise_affine=True)
169
+ )
170
+ )
171
+ )
172
+ )
173
+ (lm_head): Linear(in_features=2560, out_features=50272, bias=False)
174
+ )
175
+ ```
176
+
177
+ ## Model Configuration
178
+
179
+ This model was trained using H2O LLM Studio and with the configuration in [cfg.yaml](cfg.yaml). Visit [H2O LLM Studio](https://github.com/h2oai/h2o-llmstudio) to learn how to train your own large language models.
180
+
181
+
182
+ ## Disclaimer
183
+
184
+ Please read this disclaimer carefully before using the large language model provided in this repository. Your use of the model signifies your agreement to the following terms and conditions.
185
+
186
+ - Biases and Offensiveness: The large language model is trained on a diverse range of internet text data, which may contain biased, racist, offensive, or otherwise inappropriate content. By using this model, you acknowledge and accept that the generated content may sometimes exhibit biases or produce content that is offensive or inappropriate. The developers of this repository do not endorse, support, or promote any such content or viewpoints.
187
+ - Limitations: The large language model is an AI-based tool and not a human. It may produce incorrect, nonsensical, or irrelevant responses. It is the user's responsibility to critically evaluate the generated content and use it at their discretion.
188
+ - Use at Your Own Risk: Users of this large language model must assume full responsibility for any consequences that may arise from their use of the tool. The developers and contributors of this repository shall not be held liable for any damages, losses, or harm resulting from the use or misuse of the provided model.
189
+ - Ethical Considerations: Users are encouraged to use the large language model responsibly and ethically. By using this model, you agree not to use it for purposes that promote hate speech, discrimination, harassment, or any form of illegal or harmful activities.
190
+ - Reporting Issues: If you encounter any biased, offensive, or otherwise inappropriate content generated by the large language model, please report it to the repository maintainers through the provided channels. Your feedback will help improve the model and mitigate potential issues.
191
+ - Changes to this Disclaimer: The developers of this repository reserve the right to modify or update this disclaimer at any time without prior notice. It is the user's responsibility to periodically review the disclaimer to stay informed about any changes.
192
+
193
+ By using the large language model provided in this repository, you agree to accept and comply with the terms and conditions outlined in this disclaimer. If you do not agree with any part of this disclaimer, you should refrain from using the model and any content generated by it.