Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +2 -2
- better_transformer.py +4 -5
app.py
CHANGED
@@ -66,7 +66,7 @@ def main():
|
|
66 |
|
67 |
# model_version = st.radio("Which model would you like to use?", ["smoll", "beeg"])
|
68 |
# small_model = load_casey_model(tokenizer, device)
|
69 |
-
model = load_big_model(tokenizer,
|
70 |
|
71 |
|
72 |
|
@@ -83,7 +83,7 @@ def main():
|
|
83 |
|
84 |
|
85 |
with st.spinner(""):
|
86 |
-
result = generate(model, tokenizer,
|
87 |
p_nucleus=specified_nucleus, temp=specified_temperature, max_new_tokens=max_tokens,
|
88 |
cond=user_input, deterministic=user_seed)
|
89 |
|
|
|
66 |
|
67 |
# model_version = st.radio("Which model would you like to use?", ["smoll", "beeg"])
|
68 |
# small_model = load_casey_model(tokenizer, device)
|
69 |
+
model = load_big_model(tokenizer, 'cuda')
|
70 |
|
71 |
|
72 |
|
|
|
83 |
|
84 |
|
85 |
with st.spinner(""):
|
86 |
+
result = generate(model, tokenizer, 'cuda', method=generation_method, k=specified_k,
|
87 |
p_nucleus=specified_nucleus, temp=specified_temperature, max_new_tokens=max_tokens,
|
88 |
cond=user_input, deterministic=user_seed)
|
89 |
|
better_transformer.py
CHANGED
@@ -139,9 +139,8 @@ class BetterTransformer(nn.Module):
|
|
139 |
self.seq_length = seq_length
|
140 |
self.pad_idx = pad_idx
|
141 |
self.eos_token_id = eos_token_id
|
142 |
-
self.device =
|
143 |
self.init_params()
|
144 |
-
st.title(f"Device: {device}")
|
145 |
|
146 |
# optional weight initialization (e.g. Xavier uniform)
|
147 |
def init_params(self, default_initialization=False):
|
@@ -295,7 +294,7 @@ def load_tokenizer(device):
|
|
295 |
tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-1.3B")
|
296 |
if tokenizer.pad_token is None:
|
297 |
tokenizer.add_special_tokens({'pad_token': '[PAD]'})
|
298 |
-
EMPTY_TOKENS = torch.full((1,1), tokenizer.bos_token_id, dtype=torch.long).to(
|
299 |
return tokenizer, EMPTY_TOKENS
|
300 |
|
301 |
|
@@ -363,7 +362,7 @@ def generate(model, tokenizer, device, method=None, k=None,
|
|
363 |
|
364 |
cond_tokens = tokenizer(cond).input_ids
|
365 |
|
366 |
-
gen_tokens = model.generate(torch.tensor(cond_tokens).unsqueeze(0).long().to(
|
367 |
method=method, k=k, p_nucleus=p_nucleus, temp=temp,
|
368 |
max_new_tokens=max_new_tokens)[0]
|
369 |
|
@@ -379,7 +378,7 @@ def generate(model, tokenizer, device, method=None, k=None,
|
|
379 |
|
380 |
|
381 |
else:
|
382 |
-
empty_tokens = torch.full((1,1), tokenizer.bos_token_id, dtype=torch.long).to(
|
383 |
|
384 |
res = tokenizer.batch_decode(model.generate(empty_tokens,
|
385 |
method=method, k=k,
|
|
|
139 |
self.seq_length = seq_length
|
140 |
self.pad_idx = pad_idx
|
141 |
self.eos_token_id = eos_token_id
|
142 |
+
self.device = 'cuda'
|
143 |
self.init_params()
|
|
|
144 |
|
145 |
# optional weight initialization (e.g. Xavier uniform)
|
146 |
def init_params(self, default_initialization=False):
|
|
|
294 |
tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-1.3B")
|
295 |
if tokenizer.pad_token is None:
|
296 |
tokenizer.add_special_tokens({'pad_token': '[PAD]'})
|
297 |
+
EMPTY_TOKENS = torch.full((1,1), tokenizer.bos_token_id, dtype=torch.long).to('cuda')
|
298 |
return tokenizer, EMPTY_TOKENS
|
299 |
|
300 |
|
|
|
362 |
|
363 |
cond_tokens = tokenizer(cond).input_ids
|
364 |
|
365 |
+
gen_tokens = model.generate(torch.tensor(cond_tokens).unsqueeze(0).long().to('cuda'),
|
366 |
method=method, k=k, p_nucleus=p_nucleus, temp=temp,
|
367 |
max_new_tokens=max_new_tokens)[0]
|
368 |
|
|
|
378 |
|
379 |
|
380 |
else:
|
381 |
+
empty_tokens = torch.full((1,1), tokenizer.bos_token_id, dtype=torch.long).to('cuda')
|
382 |
|
383 |
res = tokenizer.batch_decode(model.generate(empty_tokens,
|
384 |
method=method, k=k,
|