-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
opts.py
1990 lines (1897 loc) · 55.4 KB
/
opts.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
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
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
""" Implementation of all available options """
import configargparse
from onmt.modules.sru import CheckSRU
from onmt.transforms import AVAILABLE_TRANSFORMS
from onmt.constants import ModelTask
from onmt.modules.position_ffn import ACTIVATION_FUNCTIONS
from onmt.modules.position_ffn import ActivationFunction
from onmt.constants import DefaultTokens
def config_opts(parser):
group = parser.add_argument_group("Configuration")
group.add(
"-config",
"--config",
required=False,
is_config_file_arg=True,
help="Path of the main YAML config file.",
)
group.add(
"-save_config",
"--save_config",
required=False,
is_write_out_config_file_arg=True,
help="Path where to save the config.",
)
def _add_logging_opts(parser, is_train=True):
group = parser.add_argument_group("Logging")
group.add(
"--log_file",
"-log_file",
type=str,
default="",
help="Output logs to a file under this path.",
)
group.add(
"--log_file_level",
"-log_file_level",
type=str,
action=StoreLoggingLevelAction,
choices=StoreLoggingLevelAction.CHOICES,
default="0",
)
group.add(
"--verbose",
"-verbose",
action="store_true",
help="Print data loading and statistics for all process"
"(default only log the first process shard)"
if is_train
else "Print scores and predictions for each sentence",
)
if is_train:
group.add(
"--valid_metrics",
"-valid_metrics",
default=[],
nargs="+",
help="List of names of additional validation metrics",
)
group.add(
"--scoring_debug",
"-scoring_debug",
action="store_true",
help="Dump the src/ref/pred of the current batch",
)
group.add(
"--dump_preds",
"-dump_preds",
type=str,
default=None,
help="Folder to dump predictions to.",
)
group.add(
"--report_every",
"-report_every",
type=int,
default=50,
help="Print stats at this interval.",
)
group.add(
"--exp_host",
"-exp_host",
type=str,
default="",
help="Send logs to this crayon server.",
)
group.add(
"--exp",
"-exp",
type=str,
default="",
help="Name of the experiment for logging.",
)
# Use Tensorboard for visualization during training
group.add(
"--tensorboard",
"-tensorboard",
action="store_true",
help="Use tensorboard for visualization during training. "
"Must have the library tensorboard >= 1.14.",
)
group.add(
"--tensorboard_log_dir",
"-tensorboard_log_dir",
type=str,
default="runs/onmt",
help="Log directory for Tensorboard. " "This is also the name of the run.",
)
group.add(
"--override_opts",
"-override-opts",
action="store_true",
help="Allow to override some checkpoint opts",
)
else:
# Options only during inference
group.add(
"--attn_debug",
"-attn_debug",
action="store_true",
help="Print best attn for each word",
)
group.add(
"--align_debug",
"-align_debug",
action="store_true",
help="Print best align for each word",
)
group.add(
"--dump_beam",
"-dump_beam",
type=str,
default="",
help="File to dump beam information to.",
)
group.add(
"--n_best",
"-n_best",
type=int,
default=1,
help="If verbose is set, will output the n_best " "decoded sentences",
)
group.add(
"--with_score",
"-with_score",
action="store_true",
help="add a tab separated score to the translation",
)
def _add_reproducibility_opts(parser):
group = parser.add_argument_group("Reproducibility")
group.add(
"--seed",
"-seed",
type=int,
default=-1,
help="Set random seed used for better " "reproducibility between experiments.",
)
def _add_dataset_opts(parser, build_vocab_only=False):
"""Options related to training datasets, type: a list of dictionary."""
group = parser.add_argument_group("Data")
group.add(
"-data",
"--data",
required=True,
help="List of datasets and their specifications. "
"See examples/*.yaml for further details.",
)
group.add(
"-skip_empty_level",
"--skip_empty_level",
default="warning",
choices=["silent", "warning", "error"],
help="Security level when encounter empty examples."
"silent: silently ignore/skip empty example;"
"warning: warning when ignore/skip empty example;"
"error: raise error & stop execution when encouter empty.",
)
group.add(
"-transforms",
"--transforms",
default=[],
nargs="+",
choices=AVAILABLE_TRANSFORMS.keys(),
help="Default transform pipeline to apply to data. "
"Can be specified in each corpus of data to override.",
)
group.add(
"-save_data",
"--save_data",
required=build_vocab_only,
help="Output base path for objects that will "
"be saved (vocab, transforms, embeddings, ...).",
)
group.add(
"-overwrite",
"--overwrite",
action="store_true",
help="Overwrite existing objects if any.",
)
group.add(
"-n_sample",
"--n_sample",
type=int,
default=(5000 if build_vocab_only else 0),
help=("Build vocab using " if build_vocab_only else "Stop after save ")
+ "this number of transformed samples/corpus. Can be [-1, 0, N>0]. "
"Set to -1 to go full corpus, 0 to skip.",
)
if not build_vocab_only:
group.add(
"-dump_transforms",
"--dump_transforms",
action="store_true",
help="Dump transforms `*.transforms.pt` to disk."
" -save_data should be set as saving prefix.",
)
else:
group.add(
"-dump_samples",
"--dump_samples",
action="store_true",
help="Dump samples when building vocab. "
"Warning: this may slow down the process.",
)
group.add(
"-num_threads",
"--num_threads",
type=int,
default=1,
help="Number of parallel threads to build the vocab.",
)
group.add(
"-learn_subwords",
"--learn_subwords",
action="store_true",
help="Learn subwords prior to building vocab",
)
group.add(
"-learn_subwords_size",
"--learn_subwords_size",
type=int,
default=32000,
help="Learn subwords operations",
)
group.add(
"-vocab_sample_queue_size",
"--vocab_sample_queue_size",
type=int,
default=20,
help="Size of queues used in the build_vocab dump path.",
)
def _add_features_opts(parser):
group = parser.add_argument_group("Features")
group.add(
"-n_src_feats",
"--n_src_feats",
type=int,
default=0,
help="Number of source feats.",
)
group.add(
"-src_feats_defaults",
"--src_feats_defaults",
help="Default features to apply in source in case " "there are not annotated",
)
def _add_vocab_opts(parser, build_vocab_only=False):
"""Options related to vocabulary and features.
Add all options relate to vocabulary or features to parser.
"""
group = parser.add_argument_group("Vocab")
group.add(
"-src_vocab",
"--src_vocab",
required=True,
help=("Path to save" if build_vocab_only else "Path to")
+ " src (or shared) vocabulary file. "
"Format: one <word> or <word>\t<count> per line.",
)
group.add(
"-tgt_vocab",
"--tgt_vocab",
help=("Path to save" if build_vocab_only else "Path to")
+ " tgt vocabulary file. "
"Format: one <word> or <word>\t<count> per line.",
)
group.add(
"-share_vocab",
"--share_vocab",
action="store_true",
help="Share source and target vocabulary.",
)
group.add(
"--decoder_start_token",
"-decoder_start_token",
type=str,
default=DefaultTokens.BOS,
help="Default decoder start token "
"for most ONMT models it is <s> = BOS "
"it happens that for some Fairseq model it requires </s> ",
)
group.add(
"--default_specials",
"-default_specials",
nargs="+",
type=str,
default=[
DefaultTokens.UNK,
DefaultTokens.PAD,
DefaultTokens.BOS,
DefaultTokens.EOS,
],
help="default specials used for Vocab initialization"
" UNK, PAD, BOS, EOS will take IDs 0, 1, 2, 3 "
" typically <unk> <blank> <s> </s> ",
)
_add_features_opts(parser)
if not build_vocab_only:
group.add(
"-src_vocab_size",
"--src_vocab_size",
type=int,
default=32768,
help="Maximum size of the source vocabulary.",
)
group.add(
"-tgt_vocab_size",
"--tgt_vocab_size",
type=int,
default=32768,
help="Maximum size of the target vocabulary",
)
group.add(
"-vocab_size_multiple",
"--vocab_size_multiple",
type=int,
default=8,
help="Make the vocabulary size a multiple of this value.",
)
group.add(
"-src_words_min_frequency",
"--src_words_min_frequency",
type=int,
default=0,
help="Discard source words with lower frequency.",
)
group.add(
"-tgt_words_min_frequency",
"--tgt_words_min_frequency",
type=int,
default=0,
help="Discard target words with lower frequency.",
)
# Truncation options, for text corpus
group = parser.add_argument_group("Pruning")
group.add(
"--src_seq_length_trunc",
"-src_seq_length_trunc",
type=int,
default=None,
help="Truncate source sequence length.",
)
group.add(
"--tgt_seq_length_trunc",
"-tgt_seq_length_trunc",
type=int,
default=None,
help="Truncate target sequence length.",
)
group = parser.add_argument_group("Embeddings")
group.add(
"-both_embeddings",
"--both_embeddings",
help="Path to the embeddings file to use "
"for both source and target tokens.",
)
group.add(
"-src_embeddings",
"--src_embeddings",
help="Path to the embeddings file to use for source tokens.",
)
group.add(
"-tgt_embeddings",
"--tgt_embeddings",
help="Path to the embeddings file to use for target tokens.",
)
group.add(
"-embeddings_type",
"--embeddings_type",
choices=["GloVe", "word2vec"],
help="Type of embeddings file.",
)
def _add_transform_opts(parser):
"""Options related to transforms.
Options that specified in the definitions of each transform class
at `onmt/transforms/*.py`.
"""
for name, transform_cls in AVAILABLE_TRANSFORMS.items():
transform_cls.add_options(parser)
def data_prepare_opts(parser, build_vocab_only=False):
"""Options related to data prepare in dynamic mode.
Add all dynamic data prepare related options to parser.
If `build_vocab_only` set to True, then only contains options that
will be used in `onmt/bin/build_vocab.py`.
"""
config_opts(parser)
_add_dataset_opts(parser, build_vocab_only=build_vocab_only)
_add_vocab_opts(parser, build_vocab_only=build_vocab_only)
_add_transform_opts(parser)
if build_vocab_only:
_add_reproducibility_opts(parser)
# as for False, this will be added in _add_train_general_opts
def distributed_opts(parser):
# GPU
group = parser.add_argument_group("Distributed")
group.add(
"--gpu_ranks",
"-gpu_ranks",
default=[],
nargs="*",
type=int,
help="list of ranks of each process.",
)
group.add(
"--world_size",
"-world_size",
default=1,
type=int,
help="total number of distributed processes.",
)
group.add(
"--parallel_mode",
"-parallel_mode",
default="data_parallel",
choices=["tensor_parallel", "data_parallel"],
type=str,
help="Distributed mode.",
)
group.add(
"--gpu_backend",
"-gpu_backend",
default="nccl",
type=str,
help="Type of torch distributed backend",
)
group.add(
"--gpu_verbose_level",
"-gpu_verbose_level",
default=0,
type=int,
help="Gives more info on each process per GPU.",
)
group.add(
"--master_ip",
"-master_ip",
default="localhost",
type=str,
help="IP of master for torch.distributed training.",
)
group.add(
"--master_port",
"-master_port",
default=10000,
type=int,
help="Port of master for torch.distributed training.",
)
group.add(
"--timeout",
"-timeout",
default=60,
type=int,
help="Timeout for one GOU to wait for the others.",
)
def model_opts(parser):
"""
These options are passed to the construction of the model.
Be careful with these as they will be used during translation.
"""
# Embedding Options
group = parser.add_argument_group("Model-Embeddings")
group.add(
"--src_word_vec_size",
"-src_word_vec_size",
type=int,
default=500,
help="Word embedding size for src.",
)
group.add(
"--tgt_word_vec_size",
"-tgt_word_vec_size",
type=int,
default=500,
help="Word embedding size for tgt.",
)
group.add(
"--word_vec_size",
"-word_vec_size",
type=int,
default=-1,
help="Word embedding size for src and tgt.",
)
group.add(
"--share_decoder_embeddings",
"-share_decoder_embeddings",
action="store_true",
help="Use a shared weight matrix for the input and "
"output word embeddings in the decoder.",
)
group.add(
"--share_embeddings",
"-share_embeddings",
action="store_true",
help="Share the word embeddings between encoder "
"and decoder. Need to use shared dictionary for this "
"option.",
)
group.add(
"--position_encoding",
"-position_encoding",
action="store_true",
help="Use a sin to mark relative words positions. "
"Necessary for non-RNN style models.",
)
group.add(
"--position_encoding_type",
"-position_encoding_type",
type=str,
default="SinusoidalInterleaved",
choices=["SinusoidalInterleaved", "SinusoidalConcat"],
help="Type of positional encoding. At the moment: "
"Sinusoidal fixed, Interleaved or Concat",
)
group.add(
"-update_vocab",
"--update_vocab",
action="store_true",
help="Update source and target existing vocabularies",
)
group = parser.add_argument_group("Model-Embedding Features")
group.add(
"--feat_merge",
"-feat_merge",
type=str,
default="concat",
choices=["concat", "sum", "mlp"],
help="Merge action for incorporating features embeddings. "
"Options [concat|sum|mlp].",
)
group.add(
"--feat_vec_size",
"-feat_vec_size",
type=int,
default=-1,
help="If specified, feature embedding sizes "
"will be set to this. Otherwise, feat_vec_exponent "
"will be used.",
)
group.add(
"--feat_vec_exponent",
"-feat_vec_exponent",
type=float,
default=0.7,
help="If -feat_merge_size is not set, feature "
"embedding sizes will be set to N^feat_vec_exponent "
"where N is the number of values the feature takes.",
)
# Model Task Options
group = parser.add_argument_group("Model- Task")
group.add(
"-model_task",
"--model_task",
default=ModelTask.SEQ2SEQ,
choices=[ModelTask.SEQ2SEQ, ModelTask.LANGUAGE_MODEL],
help="Type of task for the model either seq2seq or lm",
)
# Encoder-Decoder Options
group = parser.add_argument_group("Model- Encoder-Decoder")
group.add(
"--model_type",
"-model_type",
default="text",
choices=["text"],
help="Type of source model to use. Allows "
"the system to incorporate non-text inputs. "
"Options are [text].",
)
group.add(
"--model_dtype",
"-model_dtype",
default="fp32",
choices=["fp32", "fp16"],
help="Data type of the model.",
)
group.add(
"--encoder_type",
"-encoder_type",
type=str,
default="rnn",
help="Type of encoder layer to use. Non-RNN layers "
"are experimental. Default options are "
"[rnn|brnn|ggnn|mean|transformer|cnn|transformer_lm].",
)
group.add(
"--decoder_type",
"-decoder_type",
type=str,
default="rnn",
help="Type of decoder layer to use. Non-RNN layers "
"are experimental. Default options are "
"[rnn|transformer|cnn|transformer].",
)
# Freeze Encoder and/or Decoder
group.add(
"--freeze_encoder",
"-freeze_encoder",
action="store_true",
help="Freeze parameters in encoder.",
)
group.add(
"--freeze_decoder",
"-freeze_decoder",
action="store_true",
help="Freeze parameters in decoder.",
)
group.add(
"--layers", "-layers", type=int, default=-1, help="Number of layers in enc/dec."
)
group.add(
"--enc_layers",
"-enc_layers",
type=int,
default=2,
help="Number of layers in the encoder",
)
group.add(
"--dec_layers",
"-dec_layers",
type=int,
default=2,
help="Number of layers in the decoder",
)
group.add(
"--hidden_size",
"-hidden_size",
type=int,
default=-1,
help="Size of rnn hidden states. Overwrites " "enc_hid_size and dec_hid_size",
)
group.add(
"--enc_hid_size",
"-enc_hid_size",
type=int,
default=500,
help="Size of encoder rnn hidden states.",
)
group.add(
"--dec_hid_size",
"-dec_hid_size",
type=int,
default=500,
help="Size of decoder rnn hidden states.",
)
group.add(
"--cnn_kernel_width",
"-cnn_kernel_width",
type=int,
default=3,
help="Size of windows in the cnn, the kernel_size is "
"(cnn_kernel_width, 1) in conv layer",
)
group.add(
"--layer_norm",
"-layer_norm",
type=str,
default="standard",
choices=["standard", "rms"],
help="The type of layer"
" normalization in the transformer architecture. Choices are"
" standard or rms. Default to standard",
)
group.add(
"--norm_eps", "-norm_eps", type=float, default=1e-6, help="Layer norm epsilon"
)
group.add(
"--pos_ffn_activation_fn",
"-pos_ffn_activation_fn",
type=str,
default=ActivationFunction.relu,
choices=ACTIVATION_FUNCTIONS.keys(),
help="The activation"
" function to use in PositionwiseFeedForward layer. Choices are"
f" {ACTIVATION_FUNCTIONS.keys()}. Default to"
f" {ActivationFunction.relu}.",
)
group.add(
"--input_feed",
"-input_feed",
type=int,
default=1,
help="Feed the context vector at each time step as "
"additional input (via concatenation with the word "
"embeddings) to the decoder.",
)
group.add(
"--bridge",
"-bridge",
action="store_true",
help="Have an additional layer between the last encoder "
"state and the first decoder state",
)
group.add(
"--rnn_type",
"-rnn_type",
type=str,
default="LSTM",
choices=["LSTM", "GRU", "SRU"],
action=CheckSRU,
help="The gate type to use in the RNNs",
)
group.add(
"--context_gate",
"-context_gate",
type=str,
default=None,
choices=["source", "target", "both"],
help="Type of context gate to use. " "Do not select for no context gate.",
)
# The following options (bridge_extra_node to n_steps) are used
# for training with --encoder_type ggnn (Gated Graph Neural Network).
group.add(
"--bridge_extra_node",
"-bridge_extra_node",
type=bool,
default=True,
help="Graph encoder bridges only extra node to decoder as input",
)
group.add(
"--bidir_edges",
"-bidir_edges",
type=bool,
default=True,
help="Graph encoder autogenerates bidirectional edges",
)
group.add(
"--state_dim",
"-state_dim",
type=int,
default=512,
help="Number of state dimensions in the graph encoder",
)
group.add(
"--n_edge_types",
"-n_edge_types",
type=int,
default=2,
help="Number of edge types in the graph encoder",
)
group.add(
"--n_node",
"-n_node",
type=int,
default=2,
help="Number of nodes in the graph encoder",
)
group.add(
"--n_steps",
"-n_steps",
type=int,
default=2,
help="Number of steps to advance graph encoder",
)
group.add(
"--src_ggnn_size",
"-src_ggnn_size",
type=int,
default=0,
help="Vocab size plus feature space for embedding input",
)
# Attention options
group = parser.add_argument_group("Model- Attention")
group.add(
"--global_attention",
"-global_attention",
type=str,
default="general",
choices=["dot", "general", "mlp", "none"],
help="The attention type to use: "
"dotprod or general (Luong) or MLP (Bahdanau)",
)
group.add(
"--global_attention_function",
"-global_attention_function",
type=str,
default="softmax",
choices=["softmax", "sparsemax"],
)
group.add(
"--self_attn_type",
"-self_attn_type",
type=str,
default="scaled-dot-flash",
help="Self attention type in Transformer decoder "
'layer -- currently "scaled-dot", "scaled-dot-flash" or "average" ',
)
group.add(
"--max_relative_positions",
"-max_relative_positions",
type=int,
default=0,
help="This setting enable relative position encoding"
"We support two types of encodings:"
"set this -1 to enable Rotary Embeddings"
"more info: https://arxiv.org/abs/2104.09864"
"set this to > 0 (ex: 16, 32) to use"
"Maximum distance between inputs in relative "
"positions representations. "
"more info: https://arxiv.org/pdf/1803.02155.pdf",
)
group.add(
"--relative_positions_buckets",
"-relative_positions_buckets",
type=int,
default=0,
help="This setting enable relative position bias"
"more info: https://github.com/google-research/text-to-text-transfer-transformer",
)
group.add(
"--rotary_interleave",
"-rotary_interleave",
action="store_true",
help="Interleave the head dimensions when rotary"
" embeddings are applied."
" Otherwise the head dimensions are sliced in half."
"True = default Llama from Meta (original)"
"False = used by all Hugging face models",
)
group.add(
"--rotary_theta",
"-rotary_theta",
type=int,
default=10000,
help="Rotary theta base length" "1e4 for Llama2.Mistral" "1e6 for Mixtral",
)
group.add(
"--rotary_dim",
"-rotary_dim",
type=int,
default=0,
help="Rotary dim when model requires it to be different to head dim",
)
group.add(
"--heads",
"-heads",
type=int,
default=8,
help="Number of heads for transformer self-attention",
)
group.add(
"--sliding_window",
"-sliding_window",
type=int,
default=0,
help="sliding window for transformer self-attention",
)
group.add(
"--transformer_ff",
"-transformer_ff",
type=int,
default=2048,
help="Size of hidden transformer feed-forward",
)
group.add(
"--num_experts",
"-num_experts",
type=int,
default=0,
help="Number of experts",
)
group.add(
"--num_experts_per_tok",
"-num_experts_per_tok",
type=int,
default=2,
help="Number of experts per token",
)
group.add(
"--aan_useffn",
"-aan_useffn",
action="store_true",
help="Turn on the FFN layer in the AAN decoder",
)
group.add(
"--add_qkvbias",
"-add_qkvbias",
action="store_true",
help="Add bias to nn.linear of Query/Key/Value in MHA"
"Note: this will add bias to output proj layer too",
)
group.add(
"--multiquery",
"-multiquery",
action="store_true",
help="Use MultiQuery attention" "Note: https://arxiv.org/pdf/1911.02150.pdf",
)
group.add(
"--num_kv",
"-num_kv",
type=int,
default=0,
help="Number of heads for KV in the variant of MultiQuery attention (egs: Falcon 40B)",
)
group.add(
"--add_ffnbias",
"-add_ffnbias",
action="store_true",
help="Add bias to nn.linear of Position_wise FFN",
)
group.add(
"--parallel_residual",
"-parallel_residual",
action="store_true",
help="Use Parallel residual in Decoder Layer"
"Note: this is used by GPT-J / Falcon Architecture",
)
group.add(
"--shared_layer_norm",
"-shared_layer_norm",
action="store_true",
help="Use a shared layer_norm in parallel residual attention"
"Note: must be true for Falcon 7B / false for Falcon 40B"
"same for GPT-J and GPT-NeoX models",
)
# Alignement options
group = parser.add_argument_group("Model - Alignement")
group.add(
"--lambda_align",
"-lambda_align",
type=float,
default=0.0,
help="Lambda value for alignement loss of Garg et al (2019)"
"For more detailed information, see: "
"https://arxiv.org/abs/1909.02074",
)
group.add(
"--alignment_layer",
"-alignment_layer",
type=int,
default=-3,
help="Layer number which has to be supervised.",
)
group.add(
"--alignment_heads",
"-alignment_heads",
type=int,
default=0,