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<!-- Provide a quick summary of what the model is/does. -->
|
| 8 |
+
|
| 9 |
+
This modelcard aims to be a base template for new models. It has been generated using [this raw template](https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/modelcard_template.md?plain=1).
|
| 10 |
+
|
| 11 |
+
## Model Details
|
| 12 |
+
|
| 13 |
+
### Model Description
|
| 14 |
+
|
| 15 |
+
<!-- Provide a longer summary of what this model is. -->
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
- **Developed by:** [More Information Needed]
|
| 20 |
+
- **Funded by [optional]:** [More Information Needed]
|
| 21 |
+
- **Shared by [optional]:** [More Information Needed]
|
| 22 |
+
- **Model type:** [More Information Needed]
|
| 23 |
+
- **Language(s) (NLP):** [More Information Needed]
|
| 24 |
+
- **License:** [More Information Needed]
|
| 25 |
+
- **Finetuned from model [optional]:** [More Information Needed]
|
| 26 |
+
|
| 27 |
+
### Model Sources [optional]
|
| 28 |
+
|
| 29 |
+
<!-- Provide the basic links for the model. -->
|
| 30 |
+
|
| 31 |
+
- **Repository:** [More Information Needed]
|
| 32 |
+
- **Paper [optional]:** [More Information Needed]
|
| 33 |
+
- **Demo [optional]:** [More Information Needed]
|
| 34 |
+
|
| 35 |
+
## Uses
|
| 36 |
+
|
| 37 |
+
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 38 |
+
|
| 39 |
+
### Direct Use
|
| 40 |
+
|
| 41 |
+
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
| 42 |
+
|
| 43 |
+
[More Information Needed]
|
| 44 |
+
|
| 45 |
+
### Downstream Use [optional]
|
| 46 |
+
|
| 47 |
+
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 48 |
+
|
| 49 |
+
[More Information Needed]
|
| 50 |
+
|
| 51 |
+
### Out-of-Scope Use
|
| 52 |
+
|
| 53 |
+
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
| 54 |
+
|
| 55 |
+
[More Information Needed]
|
| 56 |
+
|
| 57 |
+
## Bias, Risks, and Limitations
|
| 58 |
+
|
| 59 |
+
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
| 60 |
+
|
| 61 |
+
[More Information Needed]
|
| 62 |
+
|
| 63 |
+
### Recommendations
|
| 64 |
+
|
| 65 |
+
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
| 66 |
+
|
| 67 |
+
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 68 |
+
|
| 69 |
+
## How to Get Started with the Model
|
| 70 |
+
|
| 71 |
+
Download the files from the repo and place all the files in the same folder. Then, run the cells in the notebook.
|
| 72 |
+
|
| 73 |
+
Import the model using this cell.
|
| 74 |
+
```python
|
| 75 |
+
import torch
|
| 76 |
+
import torch.nn as nn
|
| 77 |
+
import torch.optim as optim
|
| 78 |
+
import torch.nn.functional as F
|
| 79 |
+
from safetensors import safe_open
|
| 80 |
+
|
| 81 |
+
from model import Transformer as Model
|
| 82 |
+
from transformers import PreTrainedTokenizerFast
|
| 83 |
+
|
| 84 |
+
config = {
|
| 85 |
+
'layers': 24,
|
| 86 |
+
'num_heads': 12,
|
| 87 |
+
'vocab_size': 32768,
|
| 88 |
+
'input_dims': 768,
|
| 89 |
+
'hidden_dims': 3072,
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 93 |
+
|
| 94 |
+
torch.set_default_device(device)
|
| 95 |
+
|
| 96 |
+
model = Model(**config)
|
| 97 |
+
model.zero_grad()
|
| 98 |
+
model.bfloat16()
|
| 99 |
+
|
| 100 |
+
saved_states = {}
|
| 101 |
+
with safe_open("./model.safetensors", framework="pt", device=device) as f:
|
| 102 |
+
for key in f.keys():
|
| 103 |
+
saved_states[key] = f.get_tensor(key)
|
| 104 |
+
model.load_state_dict(saved_states)
|
| 105 |
+
|
| 106 |
+
model.eval()
|
| 107 |
+
|
| 108 |
+
tokenizer = PreTrainedTokenizerFast.from_pretrained("./")
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
Then prompt it to generate a function to compute the n-th Fibonacci number.
|
| 112 |
+
```python
|
| 113 |
+
tokens = tokenizer('''def fibonacci(n: int):''')['input_ids']
|
| 114 |
+
|
| 115 |
+
current = tokenizer.decode(tokens)
|
| 116 |
+
print(current, end="")
|
| 117 |
+
|
| 118 |
+
temperature = 1e-4
|
| 119 |
+
|
| 120 |
+
for _ in range(128):
|
| 121 |
+
|
| 122 |
+
tok = torch.tensor(tokens).reshape(1, -1)
|
| 123 |
+
|
| 124 |
+
logits = model(tok)
|
| 125 |
+
|
| 126 |
+
nxt = torch.multinomial(torch.softmax(logits[:, -1].float()/temperature, dim=-1).squeeze(), num_samples=1).item()
|
| 127 |
+
|
| 128 |
+
tokens += [nxt]
|
| 129 |
+
|
| 130 |
+
print(tokenizer.decode(tokens).replace(current, "", 1), end="")
|
| 131 |
+
|
| 132 |
+
current = tokenizer.decode(tokens)
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
You should see output like this!
|
| 136 |
+
```
|
| 137 |
+
<s> def fibonacci(n: int):
|
| 138 |
+
if n < 2:
|
| 139 |
+
return n
|
| 140 |
+
return fibonacci(n - 1) + fibonacci(n - 2)
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def fibonacci_recursive(n: int):
|
| 144 |
+
if n < 2:
|
| 145 |
+
return n
|
| 146 |
+
return fibonacci_recursive(n - 1) + fibonacci_recursive(n - 2)
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def fibonacci_iterative(n: int):
|
| 150 |
+
if n < 2:
|
| 151 |
+
return n
|
| 152 |
+
return fibonacci_iterative
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
Increase temperature to reduce repetitions and use different prompts to get other interesting results.
|
| 156 |
+
|
| 157 |
+
For example, if we prompt it to generate the digits of pi (using '''Digits of pi:''' as the seed), we see it recite the first 20(!) digits of pi correctly. (temperature=0.0001)
|
| 158 |
+
|
| 159 |
+
```
|
| 160 |
+
<s> Digits of pi:
|
| 161 |
+
|
| 162 |
+
# What is the value of pi?
|
| 163 |
+
|
| 164 |
+
## What is the value of pi?
|
| 165 |
+
|
| 166 |
+
The value of pi is 3.14159265358979323846273284627328462732846273284627328462732846273284627328462732846273284627328462
|
| 167 |
+
```
|
| 168 |
+
|
| 169 |
+
We can also get it to recall the chemical formula for water with the seed prompt '''The chemical formula of water is'''. Setting the temperature to a higher value prevents repetition, and plus we get to see the model's writing ability. (temperature=0.7)
|
| 170 |
+
```
|
| 171 |
+
<s> The chemical formula for water is H2O. What does it mean?
|
| 172 |
+
The chemical formula for water is H2O. What does it mean?
|
| 173 |
+
Water is the purest liquid on Earth. It is the basis of life. Water is found in the soil, rivers, lakes, oceans, and the ocean. Water is also found in our bodies. Water is found in everything we take in on a daily basis. Water is essential for life. Water is found in the cells, tissues, and organs of all living things. Water is a key element of life because it enables the creation and maintenance of the various chemical and physical processes
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
Impressive! Now let's test it on a classic example, '''The purpose of life'''. What does it think the purpose of life is? (temperature=0.8)
|
| 177 |
+
```
|
| 178 |
+
<s> The purpose of life is to build up the body’s strength, endurance, and energy reserves through the accumulation of acquired skills, and to get rid of worn or damaged parts of the body. All of this depends on day’s activities and deeds. The process of building up the body and taking on new challenges, such as accumulating health, will require the use of skills and abilities.
|
| 179 |
+
The main purpose of building up skills and abilities in life is to make new people capable of doing the things that they need to do. This process requires you to develop skills that are applicable to everyday life. Skills can either be formal, or in the
|
| 180 |
+
```
|
| 181 |
+
|
| 182 |
+
Finally, let's see if it can write a section on Charles Darwin. (temperature=0.8)
|
| 183 |
+
```
|
| 184 |
+
<s> Charles Darwin: The Origin of Species
|
| 185 |
+
Suggested Citation: (Author's description, 2007-08-02)
|
| 186 |
+
In the early 1900s the scientific community found that Darwin's theories would provide a mechanism for the further evolutionary history of living beings, assuming there was not been a series of intelligent, representative "histors" of life. Through careful research, Darwin's theory of the Origin of Species proved to be compatible with a single evolutionary process, that of speciation (Darwin, 1886). In other words, Darwin had
|
| 187 |
+
```
|
| 188 |
+
|
| 189 |
+
Unfortunately Charles Darwin died before 1886, but at least it got the name of the book correct!
|
| 190 |
+
|
| 191 |
+
## Training Details
|
| 192 |
+
|
| 193 |
+
### Training Data
|
| 194 |
+
|
| 195 |
+
<!-- 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. -->
|
| 196 |
+
|
| 197 |
+
[More Information Needed]
|
| 198 |
+
|
| 199 |
+
### Training Procedure
|
| 200 |
+
|
| 201 |
+
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
| 202 |
+
|
| 203 |
+
#### Preprocessing [optional]
|
| 204 |
+
|
| 205 |
+
[More Information Needed]
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
#### Training Hyperparameters
|
| 209 |
+
|
| 210 |
+
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
| 211 |
+
|
| 212 |
+
#### Speeds, Sizes, Times [optional]
|
| 213 |
+
|
| 214 |
+
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
| 215 |
+
|
| 216 |
+
[More Information Needed]
|
| 217 |
+
|
| 218 |
+
## Evaluation
|
| 219 |
+
|
| 220 |
+
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 221 |
+
|
| 222 |
+
### Testing Data, Factors & Metrics
|
| 223 |
+
|
| 224 |
+
#### Testing Data
|
| 225 |
+
|
| 226 |
+
<!-- This should link to a Dataset Card if possible. -->
|
| 227 |
+
|
| 228 |
+
[More Information Needed]
|
| 229 |
+
|
| 230 |
+
#### Factors
|
| 231 |
+
|
| 232 |
+
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 233 |
+
|
| 234 |
+
[More Information Needed]
|
| 235 |
+
|
| 236 |
+
#### Metrics
|
| 237 |
+
|
| 238 |
+
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 239 |
+
|
| 240 |
+
[More Information Needed]
|
| 241 |
+
|
| 242 |
+
### Results
|
| 243 |
+
|
| 244 |
+
[More Information Needed]
|
| 245 |
+
|
| 246 |
+
#### Summary
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
## Model Examination [optional]
|
| 251 |
+
|
| 252 |
+
<!-- Relevant interpretability work for the model goes here -->
|
| 253 |
+
|
| 254 |
+
[More Information Needed]
|
| 255 |
+
|
| 256 |
+
## Environmental Impact
|
| 257 |
+
|
| 258 |
+
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 259 |
+
|
| 260 |
+
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).
|
| 261 |
+
|
| 262 |
+
- **Hardware Type:** [More Information Needed]
|
| 263 |
+
- **Hours used:** [More Information Needed]
|
| 264 |
+
- **Cloud Provider:** [More Information Needed]
|
| 265 |
+
- **Compute Region:** [More Information Needed]
|
| 266 |
+
- **Carbon Emitted:** [More Information Needed]
|
| 267 |
+
|
| 268 |
+
## Technical Specifications [optional]
|
| 269 |
+
|
| 270 |
+
### Model Architecture and Objective
|
| 271 |
+
|
| 272 |
+
[More Information Needed]
|
| 273 |
+
|
| 274 |
+
### Compute Infrastructure
|
| 275 |
+
|
| 276 |
+
[More Information Needed]
|
| 277 |
+
|
| 278 |
+
#### Hardware
|
| 279 |
+
|
| 280 |
+
[More Information Needed]
|
| 281 |
+
|
| 282 |
+
#### Software
|
| 283 |
+
|
| 284 |
+
[More Information Needed]
|
| 285 |
+
|
| 286 |
+
## Citation [optional]
|
| 287 |
+
|
| 288 |
+
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 289 |
+
|
| 290 |
+
**BibTeX:**
|
| 291 |
+
|
| 292 |
+
[More Information Needed]
|
| 293 |
+
|
| 294 |
+
**APA:**
|
| 295 |
+
|
| 296 |
+
[More Information Needed]
|
| 297 |
+
|
| 298 |
+
## Glossary [optional]
|
| 299 |
+
|
| 300 |
+
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 301 |
+
|
| 302 |
+
[More Information Needed]
|
| 303 |
+
|
| 304 |
+
## More Information [optional]
|
| 305 |
+
|
| 306 |
+
[More Information Needed]
|
| 307 |
+
|
| 308 |
+
## Model Card Authors [optional]
|
| 309 |
+
|
| 310 |
+
[More Information Needed]
|
| 311 |
+
|
| 312 |
+
## Model Card Contact
|
| 313 |
+
|
| 314 |
+
[More Information Needed]
|