db
commited on
Commit
•
d7c3d1e
1
Parent(s):
31261c9
init
Browse files- .idea/workspace.xml +62 -0
- README.md +0 -12
- sample.py +0 -89
.idea/workspace.xml
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ChangeListManager">
|
4 |
+
<list default="true" id="6f3a79aa-e3bd-440d-b0d9-38be2ab06fa3" name="Changes" comment="init">
|
5 |
+
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" />
|
6 |
+
</list>
|
7 |
+
<option name="SHOW_DIALOG" value="false" />
|
8 |
+
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
9 |
+
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
10 |
+
<option name="LAST_RESOLUTION" value="IGNORE" />
|
11 |
+
</component>
|
12 |
+
<component name="Git.Settings">
|
13 |
+
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
14 |
+
</component>
|
15 |
+
<component name="MarkdownSettingsMigration">
|
16 |
+
<option name="stateVersion" value="1" />
|
17 |
+
</component>
|
18 |
+
<component name="ProjectId" id="2PShOyoyzeDIEvsIv2DVrUZH0Cc" />
|
19 |
+
<component name="ProjectViewState">
|
20 |
+
<option name="hideEmptyMiddlePackages" value="true" />
|
21 |
+
<option name="showLibraryContents" value="true" />
|
22 |
+
</component>
|
23 |
+
<component name="PropertiesComponent">
|
24 |
+
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
25 |
+
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
26 |
+
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
27 |
+
</component>
|
28 |
+
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
29 |
+
<component name="TaskManager">
|
30 |
+
<task active="true" id="Default" summary="Default task">
|
31 |
+
<changelist id="6f3a79aa-e3bd-440d-b0d9-38be2ab06fa3" name="Changes" comment="" />
|
32 |
+
<created>1683456362138</created>
|
33 |
+
<option name="number" value="Default" />
|
34 |
+
<option name="presentableId" value="Default" />
|
35 |
+
<updated>1683456362138</updated>
|
36 |
+
</task>
|
37 |
+
<task id="LOCAL-00001" summary="init">
|
38 |
+
<created>1683456502470</created>
|
39 |
+
<option name="number" value="00001" />
|
40 |
+
<option name="presentableId" value="LOCAL-00001" />
|
41 |
+
<option name="project" value="LOCAL" />
|
42 |
+
<updated>1683456502470</updated>
|
43 |
+
</task>
|
44 |
+
<option name="localTasksCounter" value="2" />
|
45 |
+
<servers />
|
46 |
+
</component>
|
47 |
+
<component name="Vcs.Log.Tabs.Properties">
|
48 |
+
<option name="TAB_STATES">
|
49 |
+
<map>
|
50 |
+
<entry key="MAIN">
|
51 |
+
<value>
|
52 |
+
<State />
|
53 |
+
</value>
|
54 |
+
</entry>
|
55 |
+
</map>
|
56 |
+
</option>
|
57 |
+
</component>
|
58 |
+
<component name="VcsManagerConfiguration">
|
59 |
+
<MESSAGE value="init" />
|
60 |
+
<option name="LAST_COMMIT_MESSAGE" value="init" />
|
61 |
+
</component>
|
62 |
+
</project>
|
README.md
DELETED
@@ -1,12 +0,0 @@
|
|
1 |
-
---
|
2 |
-
title: NanoGPT
|
3 |
-
emoji: 🐠
|
4 |
-
colorFrom: green
|
5 |
-
colorTo: pink
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 3.28.1
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sample.py
DELETED
@@ -1,89 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Sample from a trained model
|
3 |
-
"""
|
4 |
-
import os
|
5 |
-
import pickle
|
6 |
-
from contextlib import nullcontext
|
7 |
-
import torch
|
8 |
-
import tiktoken
|
9 |
-
from model import GPTConfig, GPT
|
10 |
-
|
11 |
-
# -----------------------------------------------------------------------------
|
12 |
-
init_from = 'resume' # either 'resume' (from an out_dir) or a gpt2 variant (e.g. 'gpt2-xl')
|
13 |
-
out_dir = 'out' # ignored if init_from is not 'resume'
|
14 |
-
start = "\n" # or "<|endoftext|>" or etc. Can also specify a file, use as: "FILE:prompt.txt"
|
15 |
-
num_samples = 10 # number of samples to draw
|
16 |
-
max_new_tokens = 500 # number of tokens generated in each sample
|
17 |
-
temperature = 0.8 # 1.0 = no change, < 1.0 = less random, > 1.0 = more random, in predictions
|
18 |
-
top_k = 200 # retain only the top_k most likely tokens, clamp others to have 0 probability
|
19 |
-
seed = 1337
|
20 |
-
device = 'cuda' # examples: 'cpu', 'cuda', 'cuda:0', 'cuda:1', etc.
|
21 |
-
dtype = 'bfloat16' # 'float32' or 'bfloat16' or 'float16'
|
22 |
-
compile = False # use PyTorch 2.0 to compile the model to be faster
|
23 |
-
exec(open('configurator.py').read()) # overrides from command line or config file
|
24 |
-
# -----------------------------------------------------------------------------
|
25 |
-
|
26 |
-
torch.manual_seed(seed)
|
27 |
-
torch.cuda.manual_seed(seed)
|
28 |
-
torch.backends.cuda.matmul.allow_tf32 = True # allow tf32 on matmul
|
29 |
-
torch.backends.cudnn.allow_tf32 = True # allow tf32 on cudnn
|
30 |
-
device_type = 'cuda' if 'cuda' in device else 'cpu' # for later use in torch.autocast
|
31 |
-
ptdtype = {'float32': torch.float32, 'bfloat16': torch.bfloat16, 'float16': torch.float16}[dtype]
|
32 |
-
ctx = nullcontext() if device_type == 'cpu' else torch.amp.autocast(device_type=device_type, dtype=ptdtype)
|
33 |
-
|
34 |
-
# model
|
35 |
-
if init_from == 'resume':
|
36 |
-
# init from a model saved in a specific directory
|
37 |
-
ckpt_path = os.path.join(out_dir, 'ckpt.pt')
|
38 |
-
checkpoint = torch.load(ckpt_path, map_location=device)
|
39 |
-
gptconf = GPTConfig(**checkpoint['model_args'])
|
40 |
-
model = GPT(gptconf)
|
41 |
-
state_dict = checkpoint['model']
|
42 |
-
unwanted_prefix = '_orig_mod.'
|
43 |
-
for k,v in list(state_dict.items()):
|
44 |
-
if k.startswith(unwanted_prefix):
|
45 |
-
state_dict[k[len(unwanted_prefix):]] = state_dict.pop(k)
|
46 |
-
model.load_state_dict(state_dict)
|
47 |
-
elif init_from.startswith('gpt2'):
|
48 |
-
# init from a given GPT-2 model
|
49 |
-
model = GPT.from_pretrained(init_from, dict(dropout=0.0))
|
50 |
-
|
51 |
-
model.eval()
|
52 |
-
model.to(device)
|
53 |
-
if compile:
|
54 |
-
model = torch.compile(model) # requires PyTorch 2.0 (optional)
|
55 |
-
|
56 |
-
# look for the meta pickle in case it is available in the dataset folder
|
57 |
-
load_meta = False
|
58 |
-
if init_from == 'resume' and 'config' in checkpoint and 'dataset' in checkpoint['config']: # older checkpoints might not have these...
|
59 |
-
meta_path = os.path.join('data', checkpoint['config']['dataset'], 'meta.pkl')
|
60 |
-
load_meta = os.path.exists(meta_path)
|
61 |
-
if load_meta:
|
62 |
-
print(f"Loading meta from {meta_path}...")
|
63 |
-
with open(meta_path, 'rb') as f:
|
64 |
-
meta = pickle.load(f)
|
65 |
-
# TODO want to make this more general to arbitrary encoder/decoder schemes
|
66 |
-
stoi, itos = meta['stoi'], meta['itos']
|
67 |
-
encode = lambda s: [stoi[c] for c in s]
|
68 |
-
decode = lambda l: ''.join([itos[i] for i in l])
|
69 |
-
else:
|
70 |
-
# ok let's assume gpt-2 encodings by default
|
71 |
-
print("No meta.pkl found, assuming GPT-2 encodings...")
|
72 |
-
enc = tiktoken.get_encoding("gpt2")
|
73 |
-
encode = lambda s: enc.encode(s, allowed_special={"<|endoftext|>"})
|
74 |
-
decode = lambda l: enc.decode(l)
|
75 |
-
|
76 |
-
# encode the beginning of the prompt
|
77 |
-
if start.startswith('FILE:'):
|
78 |
-
with open(start[5:], 'r', encoding='utf-8') as f:
|
79 |
-
start = f.read()
|
80 |
-
start_ids = encode(start)
|
81 |
-
x = (torch.tensor(start_ids, dtype=torch.long, device=device)[None, ...])
|
82 |
-
|
83 |
-
# run generation
|
84 |
-
with torch.no_grad():
|
85 |
-
with ctx:
|
86 |
-
for k in range(num_samples):
|
87 |
-
y = model.generate(x, max_new_tokens, temperature=temperature, top_k=top_k)
|
88 |
-
print(decode(y[0].tolist()))
|
89 |
-
print('---------------')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|