-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathexample.py
44 lines (40 loc) · 1.75 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from reformers import ReformerLM, TFReformerLM, TFLSHAttention
import torch
import tensorflow as tf
model = ReformerLM(
num_tokens= 20000,
emb = 512,
depth = 12,
max_seq_len = 32000,
heads = 8,
lsh_dropout = 0.1,
causal = True, # auto-regressive or not
bucket_size = 64, # average size of qk per bucket, 64 was recommended in paper
n_hashes = 4, # 4 is permissible per author, 8 is the best but slower
ff_chunks = 1600, # number of chunks for feedforward layer, make higher if there are memory issues
weight_tie = False, # tie parameters of each layer for no memory per additional depth
attn_chunks = 8, # process lsh attention in chunks, only way for memory to fit when scaling to 16k tokens
use_full_attn = False # use full self attention, for comparison
)
model_tf = TFReformerLM(
num_tokens= 20000,
emb = 512,
depth = 1,
max_seq_len = 32000,
heads = 8,
lsh_dropout = 0.1,
causal = True, # auto-regressive or not
bucket_size = 64, # average size of qk per bucket, 64 was recommended in paper
n_hashes = 4, # 4 is permissible per author, 8 is the best but slower
ff_chunks = 1600, # number of chunks for feedforward layer, make higher if there are memory issues
weight_tie = False, # tie parameters of each layer for no memory per additional depth
attn_chunks = 8, # process lsh attention in chunks, only way for memory to fit when scaling to 16k tokens
use_full_attn = False # use full self attention, for comparison
)
# x = tf.random.uniform((1, 32000))
model_tf.build(input_shape=(1,32000))
model_tf.summary()
# y = model_tf(x)
# x = torch.randint(0, 20000, (1, 32768)).long()
# y = model(x)
# y.sum().backward()