You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

config.py 3.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """
  16. network config setting, will be used in dataset.py, run_pretrain.py
  17. """
  18. from easydict import EasyDict as edict
  19. import mindspore.common.dtype as mstype
  20. from .bert_model import BertConfig
  21. cfg = edict({
  22. 'bert_network': 'base',
  23. 'loss_scale_value': 65536,
  24. 'scale_factor': 2,
  25. 'scale_window': 1000,
  26. 'optimizer': 'Lamb',
  27. 'AdamWeightDecayDynamicLR': edict({
  28. 'learning_rate': 3e-5,
  29. 'end_learning_rate': 1e-10,
  30. 'power': 5.0,
  31. 'weight_decay': 1e-5,
  32. 'eps': 1e-6,
  33. 'warmup_steps': 10000,
  34. }),
  35. 'Lamb': edict({
  36. 'start_learning_rate': 3e-5,
  37. 'end_learning_rate': 1e-10,
  38. 'power': 10.0,
  39. 'warmup_steps': 10000,
  40. 'weight_decay': 0.01,
  41. 'eps': 1e-6,
  42. }),
  43. 'Momentum': edict({
  44. 'learning_rate': 2e-5,
  45. 'momentum': 0.9,
  46. }),
  47. })
  48. '''
  49. Including two kinds of network: \
  50. base: Goole BERT-base(the base version of BERT model).
  51. large: BERT-NEZHA(a Chinese pretrained language model developed by Huawei, which introduced a improvement of \
  52. Functional Relative Posetional Encoding as an effective positional encoding scheme).
  53. '''
  54. if cfg.bert_network == 'base':
  55. bert_net_cfg = BertConfig(
  56. batch_size=32,
  57. seq_length=128,
  58. vocab_size=21128,
  59. hidden_size=768,
  60. num_hidden_layers=12,
  61. num_attention_heads=12,
  62. intermediate_size=3072,
  63. hidden_act="gelu",
  64. hidden_dropout_prob=0.1,
  65. attention_probs_dropout_prob=0.1,
  66. max_position_embeddings=512,
  67. type_vocab_size=2,
  68. initializer_range=0.02,
  69. use_relative_positions=False,
  70. input_mask_from_dataset=True,
  71. token_type_ids_from_dataset=True,
  72. dtype=mstype.float32,
  73. compute_type=mstype.float16
  74. )
  75. if cfg.bert_network == 'nezha':
  76. bert_net_cfg = BertConfig(
  77. batch_size=32,
  78. seq_length=128,
  79. vocab_size=21128,
  80. hidden_size=1024,
  81. num_hidden_layers=24,
  82. num_attention_heads=16,
  83. intermediate_size=4096,
  84. hidden_act="gelu",
  85. hidden_dropout_prob=0.1,
  86. attention_probs_dropout_prob=0.1,
  87. max_position_embeddings=512,
  88. type_vocab_size=2,
  89. initializer_range=0.02,
  90. use_relative_positions=True,
  91. input_mask_from_dataset=True,
  92. token_type_ids_from_dataset=True,
  93. dtype=mstype.float32,
  94. compute_type=mstype.float16
  95. )
  96. if cfg.bert_network == 'large':
  97. bert_net_cfg = BertConfig(
  98. batch_size=16,
  99. seq_length=512,
  100. vocab_size=30522,
  101. hidden_size=1024,
  102. num_hidden_layers=24,
  103. num_attention_heads=16,
  104. intermediate_size=4096,
  105. hidden_act="gelu",
  106. hidden_dropout_prob=0.1,
  107. attention_probs_dropout_prob=0.1,
  108. max_position_embeddings=512,
  109. type_vocab_size=2,
  110. initializer_range=0.02,
  111. use_relative_positions=False,
  112. input_mask_from_dataset=True,
  113. token_type_ids_from_dataset=True,
  114. dtype=mstype.float32,
  115. compute_type=mstype.float16,
  116. enable_fused_layernorm=True
  117. )