Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

fconv.py 21 KB

You have to be logged in to leave a comment. Sign In
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
  1. # Copyright (c) 2017-present, Facebook, Inc.
  2. # All rights reserved.
  3. #
  4. # This source code is licensed under the license found in the LICENSE file in
  5. # the root directory of this source tree. An additional grant of patent rights
  6. # can be found in the PATENTS file in the same directory.
  7. import math
  8. import torch
  9. import torch.nn as nn
  10. import torch.nn.functional as F
  11. from fairseq import utils
  12. from fairseq.data import LanguagePairDataset
  13. from fairseq.modules import BeamableMM, GradMultiply, LearnedPositionalEmbedding, LinearizedConvolution
  14. from . import FairseqEncoder, FairseqIncrementalDecoder, FairseqModel, register_model, register_model_architecture
  15. @register_model('fconv')
  16. class FConvModel(FairseqModel):
  17. def __init__(self, encoder, decoder):
  18. super().__init__(encoder, decoder)
  19. self.encoder.num_attention_layers = sum(layer is not None for layer in decoder.attention)
  20. @staticmethod
  21. def add_args(parser):
  22. """Add model-specific arguments to the parser."""
  23. parser.add_argument('--dropout', default=0.1, type=float, metavar='D',
  24. help='dropout probability')
  25. parser.add_argument('--encoder-embed-dim', type=int, metavar='N',
  26. help='encoder embedding dimension')
  27. parser.add_argument('--encoder-embed-path', default=None, type=str, metavar='STR',
  28. help='path to pre-trained encoder embedding')
  29. parser.add_argument('--encoder-layers', type=str, metavar='EXPR',
  30. help='encoder layers [(dim, kernel_size), ...]')
  31. parser.add_argument('--decoder-embed-dim', type=int, metavar='N',
  32. help='decoder embedding dimension')
  33. parser.add_argument('--decoder-embed-path', default=None, type=str, metavar='STR',
  34. help='path to pre-trained decoder embedding')
  35. parser.add_argument('--decoder-layers', type=str, metavar='EXPR',
  36. help='decoder layers [(dim, kernel_size), ...]')
  37. parser.add_argument('--decoder-out-embed-dim', type=int, metavar='N',
  38. help='decoder output embedding dimension')
  39. parser.add_argument('--decoder-attention', type=str, metavar='EXPR',
  40. help='decoder attention [True, ...]')
  41. parser.add_argument('--share-input-output-embed', action='store_true',
  42. help='share input and output embeddings (requires'
  43. ' --decoder-out-embed-dim and --decoder-embed-dim'
  44. ' to be equal)')
  45. @classmethod
  46. def build_model(cls, args, src_dict, dst_dict):
  47. """Build a new model instance."""
  48. if not hasattr(args, 'max_source_positions'):
  49. args.max_source_positions = args.max_positions
  50. args.max_target_positions = args.max_positions
  51. if not hasattr(args, 'share_input_output_embed'):
  52. args.share_input_output_embed = False
  53. if not hasattr(args, 'encoder_embed_path'):
  54. args.encoder_embed_path = None
  55. if not hasattr(args, 'decoder_embed_path'):
  56. args.decoder_embed_path = None
  57. encoder_embed_dict = None
  58. if args.encoder_embed_path:
  59. encoder_embed_dict = utils.parse_embedding(args.encoder_embed_path)
  60. utils.print_embed_overlap(encoder_embed_dict, src_dict)
  61. decoder_embed_dict = None
  62. if args.decoder_embed_path:
  63. decoder_embed_dict = utils.parse_embedding(args.decoder_embed_path)
  64. utils.print_embed_overlap(decoder_embed_dict, dst_dict)
  65. encoder = FConvEncoder(
  66. src_dict,
  67. embed_dim=args.encoder_embed_dim,
  68. embed_dict=encoder_embed_dict,
  69. convolutions=eval(args.encoder_layers),
  70. dropout=args.dropout,
  71. max_positions=args.max_source_positions,
  72. )
  73. decoder = FConvDecoder(
  74. dst_dict,
  75. embed_dim=args.decoder_embed_dim,
  76. embed_dict=decoder_embed_dict,
  77. convolutions=eval(args.decoder_layers),
  78. out_embed_dim=args.decoder_out_embed_dim,
  79. attention=eval(args.decoder_attention),
  80. dropout=args.dropout,
  81. max_positions=args.max_target_positions,
  82. share_embed=args.share_input_output_embed
  83. )
  84. return FConvModel(encoder, decoder)
  85. class FConvEncoder(FairseqEncoder):
  86. """Convolutional encoder"""
  87. def __init__(self, dictionary, embed_dim=512, embed_dict=None,
  88. max_positions=1024, convolutions=((512, 3),) * 20, dropout=0.1):
  89. super().__init__(dictionary)
  90. self.dropout = dropout
  91. self.num_attention_layers = None
  92. num_embeddings = len(dictionary)
  93. self.padding_idx = dictionary.pad()
  94. self.embed_tokens = Embedding(num_embeddings, embed_dim, self.padding_idx)
  95. self.embed_positions = PositionalEmbedding(
  96. max_positions,
  97. embed_dim,
  98. self.padding_idx,
  99. left_pad=LanguagePairDataset.LEFT_PAD_SOURCE,
  100. )
  101. in_channels = convolutions[0][0]
  102. self.fc1 = Linear(embed_dim, in_channels, dropout=dropout)
  103. self.projections = nn.ModuleList()
  104. self.convolutions = nn.ModuleList()
  105. for (out_channels, kernel_size) in convolutions:
  106. self.projections.append(Linear(in_channels, out_channels)
  107. if in_channels != out_channels else None)
  108. if kernel_size % 2 == 1:
  109. padding = kernel_size // 2
  110. else:
  111. padding = 0
  112. self.convolutions.append(
  113. ConvTBC(in_channels, out_channels * 2, kernel_size,
  114. dropout=dropout, padding=padding)
  115. )
  116. in_channels = out_channels
  117. self.fc2 = Linear(in_channels, embed_dim)
  118. def forward(self, src_tokens, src_lengths):
  119. # embed tokens and positions
  120. x = self.embed_tokens(src_tokens) + self.embed_positions(src_tokens)
  121. x = F.dropout(x, p=self.dropout, training=self.training)
  122. input_embedding = x
  123. # project to size of convolution
  124. x = self.fc1(x)
  125. # used to mask padding in input
  126. encoder_padding_mask = src_tokens.eq(self.padding_idx).t() # -> T x B
  127. if not encoder_padding_mask.any():
  128. encoder_padding_mask = None
  129. # B x T x C -> T x B x C
  130. x = x.transpose(0, 1)
  131. # temporal convolutions
  132. for proj, conv in zip(self.projections, self.convolutions):
  133. residual = x if proj is None else proj(x)
  134. if encoder_padding_mask is not None:
  135. x = x.masked_fill(encoder_padding_mask.unsqueeze(-1), 0)
  136. x = F.dropout(x, p=self.dropout, training=self.training)
  137. if conv.kernel_size[0] % 2 == 1:
  138. # padding is implicit in the conv
  139. x = conv(x)
  140. else:
  141. padding_l = (conv.kernel_size[0] - 1) // 2
  142. padding_r = conv.kernel_size[0] // 2
  143. x = F.pad(x, (0, 0, 0, 0, padding_l, padding_r))
  144. x = conv(x)
  145. x = F.glu(x, dim=2)
  146. x = (x + residual) * math.sqrt(0.5)
  147. # T x B x C -> B x T x C
  148. x = x.transpose(1, 0)
  149. # project back to size of embedding
  150. x = self.fc2(x)
  151. if encoder_padding_mask is not None:
  152. encoder_padding_mask = encoder_padding_mask.t() # -> B x T
  153. x = x.masked_fill(encoder_padding_mask.unsqueeze(-1), 0)
  154. # scale gradients (this only affects backward, not forward)
  155. x = GradMultiply.apply(x, 1.0 / (2.0 * self.num_attention_layers))
  156. # add output to input embedding for attention
  157. y = (x + input_embedding) * math.sqrt(0.5)
  158. return {
  159. 'encoder_out': (x, y),
  160. 'encoder_padding_mask': encoder_padding_mask, # B x T
  161. }
  162. def max_positions(self):
  163. """Maximum input length supported by the encoder."""
  164. return self.embed_positions.max_positions()
  165. class AttentionLayer(nn.Module):
  166. def __init__(self, conv_channels, embed_dim, bmm=None):
  167. super().__init__()
  168. # projects from output of convolution to embedding dimension
  169. self.in_projection = Linear(conv_channels, embed_dim)
  170. # projects from embedding dimension to convolution size
  171. self.out_projection = Linear(embed_dim, conv_channels)
  172. self.bmm = bmm if bmm is not None else torch.bmm
  173. def forward(self, x, target_embedding, encoder_out, encoder_padding_mask):
  174. residual = x
  175. # attention
  176. x = (self.in_projection(x) + target_embedding) * math.sqrt(0.5)
  177. x = self.bmm(x, encoder_out[0])
  178. # don't attend over padding
  179. if encoder_padding_mask is not None:
  180. x = x.float().masked_fill(
  181. encoder_padding_mask.unsqueeze(1),
  182. float('-inf')
  183. ).type_as(x) # FP16 support: cast to float and back
  184. # softmax over last dim
  185. sz = x.size()
  186. x = F.softmax(x.view(sz[0] * sz[1], sz[2]), dim=1)
  187. x = x.view(sz)
  188. attn_scores = x
  189. x = self.bmm(x, encoder_out[1])
  190. # scale attention output (respecting potentially different lengths)
  191. s = encoder_out[1].size(1)
  192. if encoder_padding_mask is None:
  193. x = x * (s * math.sqrt(1.0 / s))
  194. else:
  195. s = s - encoder_padding_mask.type_as(x).sum(dim=1, keepdim=True) # exclude padding
  196. s = s.unsqueeze(-1)
  197. x = x * (s * s.rsqrt())
  198. # project back
  199. x = (self.out_projection(x) + residual) * math.sqrt(0.5)
  200. return x, attn_scores
  201. def make_generation_fast_(self, beamable_mm_beam_size=None, **kwargs):
  202. """Replace torch.bmm with BeamableMM."""
  203. if beamable_mm_beam_size is not None:
  204. del self.bmm
  205. self.add_module('bmm', BeamableMM(beamable_mm_beam_size))
  206. class FConvDecoder(FairseqIncrementalDecoder):
  207. """Convolutional decoder"""
  208. def __init__(self, dictionary, embed_dim=512,
  209. embed_dict=None, out_embed_dim=256,
  210. max_positions=1024, convolutions=((512, 3),) * 20,
  211. attention=True, dropout=0.1, share_embed=False):
  212. super().__init__(dictionary)
  213. self.register_buffer('version', torch.Tensor([2]))
  214. self.dropout = dropout
  215. in_channels = convolutions[0][0]
  216. if isinstance(attention, bool):
  217. # expand True into [True, True, ...] and do the same with False
  218. attention = [attention] * len(convolutions)
  219. if not isinstance(attention, list) or len(attention) != len(convolutions):
  220. raise ValueError('Attention is expected to be a list of booleans of '
  221. 'length equal to the number of layers.')
  222. num_embeddings = len(dictionary)
  223. padding_idx = dictionary.pad()
  224. self.embed_tokens = Embedding(num_embeddings, embed_dim, padding_idx)
  225. if embed_dict:
  226. self.embed_tokens = utils.load_embedding(embed_dict, self.dictionary, self.embed_tokens)
  227. self.embed_positions = PositionalEmbedding(
  228. max_positions,
  229. embed_dim,
  230. padding_idx,
  231. left_pad=LanguagePairDataset.LEFT_PAD_TARGET,
  232. )
  233. self.fc1 = Linear(embed_dim, in_channels, dropout=dropout)
  234. self.projections = nn.ModuleList()
  235. self.convolutions = nn.ModuleList()
  236. self.attention = nn.ModuleList()
  237. for i, (out_channels, kernel_size) in enumerate(convolutions):
  238. self.projections.append(Linear(in_channels, out_channels)
  239. if in_channels != out_channels else None)
  240. self.convolutions.append(
  241. LinearizedConv1d(in_channels, out_channels * 2, kernel_size,
  242. padding=(kernel_size - 1), dropout=dropout)
  243. )
  244. self.attention.append(AttentionLayer(out_channels, embed_dim)
  245. if attention[i] else None)
  246. in_channels = out_channels
  247. self.fc2 = Linear(in_channels, out_embed_dim)
  248. if share_embed:
  249. assert out_embed_dim == embed_dim, \
  250. "Shared embed weights implies same dimensions " \
  251. " out_embed_dim={} vs embed_dim={}".format(out_embed_dim, embed_dim)
  252. self.fc3 = nn.Linear(out_embed_dim, num_embeddings)
  253. self.fc3.weight = self.embed_tokens.weight
  254. else:
  255. self.fc3 = Linear(out_embed_dim, num_embeddings, dropout=dropout)
  256. def forward(self, prev_output_tokens, encoder_out_dict, incremental_state=None):
  257. encoder_out = encoder_out_dict['encoder_out']
  258. encoder_padding_mask = encoder_out_dict['encoder_padding_mask']
  259. # split and transpose encoder outputs
  260. encoder_a, encoder_b = self._split_encoder_out(encoder_out, incremental_state)
  261. # embed tokens and combine with positional embeddings
  262. pos_embed = self.embed_positions(prev_output_tokens, incremental_state)
  263. if incremental_state is not None:
  264. prev_output_tokens = prev_output_tokens[:, -1:]
  265. x = self._embed_tokens(prev_output_tokens, incremental_state)
  266. x += pos_embed
  267. x = F.dropout(x, p=self.dropout, training=self.training)
  268. target_embedding = x
  269. # project to size of convolution
  270. x = self.fc1(x)
  271. # B x T x C -> T x B x C
  272. x = self._transpose_if_training(x, incremental_state)
  273. # temporal convolutions
  274. avg_attn_scores = None
  275. num_attn_layers = len(self.attention)
  276. for proj, conv, attention in zip(self.projections, self.convolutions, self.attention):
  277. residual = x if proj is None else proj(x)
  278. x = F.dropout(x, p=self.dropout, training=self.training)
  279. x = conv(x, incremental_state)
  280. x = F.glu(x, dim=2)
  281. # attention
  282. if attention is not None:
  283. x = self._transpose_if_training(x, incremental_state)
  284. x, attn_scores = attention(x, target_embedding, (encoder_a, encoder_b), encoder_padding_mask)
  285. attn_scores = attn_scores / num_attn_layers
  286. if avg_attn_scores is None:
  287. avg_attn_scores = attn_scores
  288. else:
  289. avg_attn_scores.add_(attn_scores)
  290. x = self._transpose_if_training(x, incremental_state)
  291. # residual
  292. x = (x + residual) * math.sqrt(0.5)
  293. # T x B x C -> B x T x C
  294. x = self._transpose_if_training(x, incremental_state)
  295. # project back to size of vocabulary
  296. x = self.fc2(x)
  297. x = F.dropout(x, p=self.dropout, training=self.training)
  298. x = self.fc3(x)
  299. return x, avg_attn_scores
  300. def reorder_incremental_state(self, incremental_state, new_order):
  301. super().reorder_incremental_state(incremental_state, new_order)
  302. encoder_out = utils.get_incremental_state(self, incremental_state, 'encoder_out')
  303. if encoder_out is not None:
  304. encoder_out = tuple(eo.index_select(0, new_order) for eo in encoder_out)
  305. utils.set_incremental_state(self, incremental_state, 'encoder_out', encoder_out)
  306. def reorder_encoder_out(self, encoder_out_dict, new_order):
  307. if encoder_out_dict['encoder_padding_mask'] is not None:
  308. encoder_out_dict['encoder_padding_mask'] = \
  309. encoder_out_dict['encoder_padding_mask'].index_select(0, new_order)
  310. return encoder_out_dict
  311. def max_positions(self):
  312. """Maximum output length supported by the decoder."""
  313. return self.embed_positions.max_positions()
  314. def upgrade_state_dict(self, state_dict):
  315. if state_dict.get('decoder.version', torch.Tensor([1]))[0] < 2:
  316. # old models use incorrect weight norm dimension
  317. for i, conv in enumerate(self.convolutions):
  318. # reconfigure weight norm
  319. nn.utils.remove_weight_norm(conv)
  320. self.convolutions[i] = nn.utils.weight_norm(conv, dim=0)
  321. state_dict['decoder.version'] = torch.Tensor([1])
  322. return state_dict
  323. def _embed_tokens(self, tokens, incremental_state):
  324. if incremental_state is not None:
  325. # keep only the last token for incremental forward pass
  326. tokens = tokens[:, -1:]
  327. return self.embed_tokens(tokens)
  328. def _split_encoder_out(self, encoder_out, incremental_state):
  329. """Split and transpose encoder outputs.
  330. This is cached when doing incremental inference.
  331. """
  332. cached_result = utils.get_incremental_state(self, incremental_state, 'encoder_out')
  333. if cached_result is not None:
  334. return cached_result
  335. # transpose only once to speed up attention layers
  336. encoder_a, encoder_b = encoder_out
  337. encoder_a = encoder_a.transpose(1, 2).contiguous()
  338. result = (encoder_a, encoder_b)
  339. if incremental_state is not None:
  340. utils.set_incremental_state(self, incremental_state, 'encoder_out', result)
  341. return result
  342. def _transpose_if_training(self, x, incremental_state):
  343. if incremental_state is None:
  344. x = x.transpose(0, 1)
  345. return x
  346. def Embedding(num_embeddings, embedding_dim, padding_idx):
  347. m = nn.Embedding(num_embeddings, embedding_dim, padding_idx=padding_idx)
  348. nn.init.normal(m.weight, 0, 0.1)
  349. nn.init.constant(m.weight[padding_idx], 0)
  350. return m
  351. def PositionalEmbedding(num_embeddings, embedding_dim, padding_idx, left_pad):
  352. m = LearnedPositionalEmbedding(num_embeddings, embedding_dim, padding_idx, left_pad)
  353. nn.init.normal(m.weight, 0, 0.1)
  354. nn.init.constant(m.weight[padding_idx], 0)
  355. return m
  356. def Linear(in_features, out_features, dropout=0):
  357. """Weight-normalized Linear layer (input: N x T x C)"""
  358. m = nn.Linear(in_features, out_features)
  359. m.weight.data.normal_(mean=0, std=math.sqrt((1 - dropout) / in_features))
  360. m.bias.data.zero_()
  361. return nn.utils.weight_norm(m)
  362. def LinearizedConv1d(in_channels, out_channels, kernel_size, dropout=0, **kwargs):
  363. """Weight-normalized Conv1d layer optimized for decoding"""
  364. m = LinearizedConvolution(in_channels, out_channels, kernel_size, **kwargs)
  365. std = math.sqrt((4 * (1.0 - dropout)) / (m.kernel_size[0] * in_channels))
  366. m.weight.data.normal_(mean=0, std=std)
  367. m.bias.data.zero_()
  368. return nn.utils.weight_norm(m, dim=2)
  369. def ConvTBC(in_channels, out_channels, kernel_size, dropout=0, **kwargs):
  370. """Weight-normalized Conv1d layer"""
  371. from fairseq.modules import ConvTBC
  372. m = ConvTBC(in_channels, out_channels, kernel_size, **kwargs)
  373. std = math.sqrt((4 * (1.0 - dropout)) / (m.kernel_size[0] * in_channels))
  374. m.weight.data.normal_(mean=0, std=std)
  375. m.bias.data.zero_()
  376. return nn.utils.weight_norm(m, dim=2)
  377. @register_model_architecture('fconv', 'fconv')
  378. def base_architecture(args):
  379. args.encoder_embed_dim = getattr(args, 'encoder_embed_dim', 512)
  380. args.encoder_layers = getattr(args, 'encoder_layers', '[(512, 3)] * 20')
  381. args.decoder_embed_dim = getattr(args, 'decoder_embed_dim', 512)
  382. args.decoder_layers = getattr(args, 'decoder_layers', '[(512, 3)] * 20')
  383. args.decoder_out_embed_dim = getattr(args, 'decoder_out_embed_dim', 256)
  384. args.decoder_attention = getattr(args, 'decoder_attention', 'True')
  385. args.share_input_output_embed = getattr(args, 'share_input_output_embed', False)
  386. @register_model_architecture('fconv', 'fconv_iwslt_de_en')
  387. def fconv_iwslt_de_en(args):
  388. base_architecture(args)
  389. args.encoder_embed_dim = 256
  390. args.encoder_layers = '[(256, 3)] * 4'
  391. args.decoder_embed_dim = 256
  392. args.decoder_layers = '[(256, 3)] * 3'
  393. args.decoder_out_embed_dim = 256
  394. @register_model_architecture('fconv', 'fconv_wmt_en_ro')
  395. def fconv_wmt_en_ro(args):
  396. base_architecture(args)
  397. args.encoder_embed_dim = 512
  398. args.encoder_layers = '[(512, 3)] * 20'
  399. args.decoder_embed_dim = 512
  400. args.decoder_layers = '[(512, 3)] * 20'
  401. args.decoder_out_embed_dim = 512
  402. @register_model_architecture('fconv', 'fconv_wmt_en_de')
  403. def fconv_wmt_en_de(args):
  404. base_architecture(args)
  405. convs = '[(512, 3)] * 9' # first 9 layers have 512 units
  406. convs += ' + [(1024, 3)] * 4' # next 4 layers have 1024 units
  407. convs += ' + [(2048, 1)] * 2' # final 2 layers use 1x1 convolutions
  408. args.encoder_embed_dim = 768
  409. args.encoder_layers = convs
  410. args.decoder_embed_dim = 768
  411. args.decoder_layers = convs
  412. args.decoder_out_embed_dim = 512
  413. @register_model_architecture('fconv', 'fconv_wmt_en_fr')
  414. def fconv_wmt_en_fr(args):
  415. base_architecture(args)
  416. convs = '[(512, 3)] * 6' # first 6 layers have 512 units
  417. convs += ' + [(768, 3)] * 4' # next 4 layers have 768 units
  418. convs += ' + [(1024, 3)] * 3' # next 3 layers have 1024 units
  419. convs += ' + [(2048, 1)] * 1' # next 1 layer uses 1x1 convolutions
  420. convs += ' + [(4096, 1)] * 1' # final 1 layer uses 1x1 convolutions
  421. args.encoder_embed_dim = 768
  422. args.encoder_layers = convs
  423. args.decoder_embed_dim = 768
  424. args.decoder_layers = convs
  425. args.decoder_out_embed_dim = 512
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...