Shishir1807 commited on
Commit
7aa0174
1 Parent(s): fd2a22f

Upload model card

Browse files
Files changed (1) hide show
  1. README.md +194 -0
README.md ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: [meta-llama/Llama-2-7b-hf](https://huggingface.co/meta-llama/Llama-2-7b-hf)
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="Shishir1807/M1_llama",
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
+ "Shishir1807/M1_llama",
75
+ use_fast=True,
76
+ padding_side="left",
77
+ trust_remote_code=True,
78
+ )
79
+ model = AutoModelForCausalLM.from_pretrained(
80
+ "Shishir1807/M1_llama",
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 = "Shishir1807/M1_llama" # 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
+ LlamaForCausalLM(
151
+ (model): LlamaModel(
152
+ (embed_tokens): Embedding(32000, 4096, padding_idx=0)
153
+ (layers): ModuleList(
154
+ (0-31): 32 x LlamaDecoderLayer(
155
+ (self_attn): LlamaAttention(
156
+ (q_proj): Linear(in_features=4096, out_features=4096, bias=False)
157
+ (k_proj): Linear(in_features=4096, out_features=4096, bias=False)
158
+ (v_proj): Linear(in_features=4096, out_features=4096, bias=False)
159
+ (o_proj): Linear(in_features=4096, out_features=4096, bias=False)
160
+ (rotary_emb): LlamaRotaryEmbedding()
161
+ )
162
+ (mlp): LlamaMLP(
163
+ (gate_proj): Linear(in_features=4096, out_features=11008, bias=False)
164
+ (down_proj): Linear(in_features=11008, out_features=4096, bias=False)
165
+ (up_proj): Linear(in_features=4096, out_features=11008, bias=False)
166
+ (act_fn): SiLUActivation()
167
+ )
168
+ (input_layernorm): LlamaRMSNorm()
169
+ (post_attention_layernorm): LlamaRMSNorm()
170
+ )
171
+ )
172
+ (norm): LlamaRMSNorm()
173
+ )
174
+ (lm_head): Linear(in_features=4096, out_features=32000, bias=False)
175
+ )
176
+ ```
177
+
178
+ ## Model Configuration
179
+
180
+ 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.
181
+
182
+
183
+ ## Disclaimer
184
+
185
+ 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.
186
+
187
+ - 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.
188
+ - 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.
189
+ - 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.
190
+ - 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.
191
+ - 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.
192
+ - 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.
193
+
194
+ 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.