constants.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. '''Copyright The Microsoft DeepSpeed Team'''
  2. """
  3. Copyright (c) Microsoft Corporation
  4. Licensed under the MIT license.
  5. """
  6. #############################################
  7. # Routes
  8. #############################################
  9. ROUTE_TRAIN = "train"
  10. ROUTE_EVAL = "eval"
  11. ROUTE_PREDICT = "predict"
  12. ROUTE_ENCODE = "encode"
  13. #############################################
  14. # Batch size
  15. #############################################
  16. TRAIN_BATCH_SIZE = "train_batch_size"
  17. TRAIN_BATCH_SIZE_DEFAULT = None
  18. #############################################
  19. # Sparse attention
  20. #############################################
  21. SPARSE_ATTENTION = "sparse_attention"
  22. SPARSE_DENSE_MODE = "dense"
  23. SPARSE_FIXED_MODE = "fixed"
  24. SPARSE_VARIABLE_MODE = "variable"
  25. SPARSE_BIGBIRD_MODE = "bigbird"
  26. SPARSE_BSLONGFORMER_MODE = "bslongformer"
  27. SPARSE_MODE = "mode"
  28. SPARSE_MODE_DEFAULT = SPARSE_FIXED_MODE
  29. SPARSE_BLOCK = "block"
  30. SPARSE_BLOCK_DEFAULT = 16
  31. SPARSE_DIFFERENT_LAYOUT_PER_HEAD = "different_layout_per_head"
  32. SPARSE_DIFFERENT_LAYOUT_PER_HEAD_DEFAULT = False
  33. SPARSE_NUM_LOCAL_BLOCKS = "num_local_blocks"
  34. SPARSE_NUM_LOCAL_BLOCKS_DEFAULT = 4
  35. SPARSE_NUM_GLOBAL_BLOCKS = "num_global_blocks"
  36. SPARSE_NUM_GLOBAL_BLOCKS_DEFAULT = 1
  37. SPARSE_ATTENTION_TYPE = "attention"
  38. SPARSE_ATTENTION_TYPE_DEFAULT = "bidirectional"
  39. SPARSE_HORIZONTAL_GLOBAL_ATTENTION = "horizontal_global_attention"
  40. SPARSE_HORIZONTAL_GLOBAL_ATTENTION_DEFAULT = False
  41. SPARSE_NUM_DIFFERENT_GLOBAL_PATTERNS = "num_different_global_patterns"
  42. SPARSE_NUM_DIFFERENT_GLOBAL_PATTERNS_DEFAULT = 1
  43. SPARSE_NUM_RANDOM_BLOCKS = "num_random_blocks"
  44. SPARSE_NUM_RANDOM_BLOCKS_DEFAULT = 0
  45. SPARSE_LOCAL_WINDOW_BLOCKS = "local_window_blocks"
  46. SPARSE_LOCAL_WINDOW_BLOCKS_DEFAULT = [4]
  47. SPARSE_GLOBAL_BLOCK_INDICES = "global_block_indices"
  48. SPARSE_GLOBAL_BLOCK_INDICES_DEFAULT = [0]
  49. SPARSE_GLOBAL_BLOCK_END_INDICES = "global_block_end_indices"
  50. SPARSE_GLOBAL_BLOCK_END_INDICES_DEFAULT = None
  51. SPARSE_NUM_SLIDING_WINDOW_BLOCKS = "num_sliding_window_blocks"
  52. SPARSE_NUM_SLIDING_WINDOW_BLOCKS_DEFAULT = 3
  53. #############################################
  54. # Optimizer and lr scheduler
  55. #############################################
  56. OPTIMIZER = "optimizer"
  57. OPTIMIZER_TYPE_DEFAULT = None
  58. OPTIMIZER_PARAMS = "params"
  59. TYPE = "type"
  60. LEGACY_FUSION = "legacy_fusion"
  61. LEGACY_FUSION_DEFAULT = False
  62. SCHEDULER = "scheduler"
  63. SCHEDULER_TYPE_DEFAULT = None
  64. SCHEDULER_PARAMS = "params"
  65. MAX_GRAD_NORM = 'max_grad_norm'
  66. #############################################
  67. # Optimizer and lr scheduler
  68. #############################################
  69. ZERO_ALLOW_UNTESTED_OPTIMIZER = "zero_allow_untested_optimizer"
  70. ZERO_ALLOW_UNTESTED_OPTIMIZER_DEFAULT = False
  71. # Steps
  72. STEPS_PER_PRINT = "steps_per_print"
  73. STEPS_PER_PRINT_DEFAULT = 10
  74. #########################################
  75. # Training micro batch size per GPU
  76. #########################################
  77. # Batch size for one training step. This is used when the
  78. # TRAIN_BATCH_SIZE cannot fit in GPU memory to determine
  79. # the number of gradient accumulation steps. By default, this
  80. # is set to None. Users can configure in ds_config.json as below example:
  81. TRAIN_MICRO_BATCH_SIZE_PER_GPU = '''
  82. TRAIN_MICRO_BATCH_SIZE_PER_GPU is defined in this format:
  83. "train_micro_batch_size_per_gpu": 1
  84. '''
  85. TRAIN_MICRO_BATCH_SIZE_PER_GPU = "train_micro_batch_size_per_gpu"
  86. TRAIN_MICRO_BATCH_SIZE_PER_GPU_DEFAULT = None
  87. #########################################
  88. # Gradient Accumulation
  89. #########################################
  90. # Gradient accumulation feature. By default, this feature is not enabled.
  91. # Users can configure in ds_config.json as below example:
  92. GRADIENT_ACCUMULATION_FORMAT = '''
  93. Gradient Accumulation should be of the format:
  94. "gradient_accumulation_steps": 1
  95. '''
  96. GRADIENT_ACCUMULATION_STEPS = "gradient_accumulation_steps"
  97. GRADIENT_ACCUMULATION_STEPS_DEFAULT = None
  98. # DeepSpeed CSR gradient sparsity
  99. SPARSE_GRADIENTS = "sparse_gradients"
  100. SPARSE_GRADIENTS_DEFAULT = False
  101. #########################################
  102. # BFLOAT16 support
  103. #########################################
  104. # BFLOAT16 feature. By default, this feature is not enabled.
  105. # Users can configure in ds_config.json as below example:
  106. BFLOAT16_FORMAT = '''
  107. BFLOAT16 parameters should be of the format:
  108. "bf16": {
  109. "enabled": true
  110. }
  111. '''
  112. BFLOAT16 = "bf16"
  113. BFLOAT16_OLD = "bfloat16" # keeping for backwards compatibility
  114. BFLOAT16_ENABLED = "enabled"
  115. BFLOAT16_ENABLED_DEFAULT = False
  116. #########################################
  117. # FP16 support
  118. #########################################
  119. # FP16 feature. By default, this feature is not enabled.
  120. # Users can configure in ds_config.json as below example:
  121. FP16_FORMAT = '''
  122. FP16 parameters should be of the format:
  123. "fp16": {
  124. "enabled": true,
  125. "auto_cast": false,
  126. "loss_scale": 0,
  127. "initial_scale_power": 16,
  128. "loss_scale_window": 1000,
  129. "hysteresis": 2,
  130. "min_loss_scale": 1
  131. }
  132. '''
  133. FP16 = "fp16"
  134. FP16_ENABLED = "enabled"
  135. FP16_ENABLED_DEFAULT = False
  136. # FP16 loss scale, zero means using dynamic scaling
  137. FP16_LOSS_SCALE = "loss_scale"
  138. FP16_LOSS_SCALE_DEFAULT = 0
  139. FP16_AUTO_CAST = "auto_cast"
  140. FP16_AUTO_CAST_DEFAULT = False
  141. # FP16 initial dynamic scale loss power
  142. FP16_INITIAL_SCALE_POWER = "initial_scale_power"
  143. FP16_INITIAL_SCALE_POWER_DEFAULT = 16
  144. # FP16 loss scale window
  145. FP16_LOSS_SCALE_WINDOW = "loss_scale_window"
  146. FP16_LOSS_SCALE_WINDOW_DEFAULT = 1000
  147. # FP16 hysteresis
  148. FP16_HYSTERESIS = "hysteresis"
  149. FP16_HYSTERESIS_DEFAULT = 2
  150. # FP16 min loss scale
  151. FP16_MIN_LOSS_SCALE = "min_loss_scale"
  152. FP16_MIN_LOSS_SCALE_DEFAULT = 1
  153. # FP16 master and grads
  154. FP16_MASTER_WEIGHTS_AND_GRADS = "fp16_master_weights_and_grads"
  155. FP16_MASTER_WEIGHTS_AND_GRADS_DEFAULT = False
  156. #########################################
  157. # Apex AMP support
  158. #########################################
  159. # Use Apex AMP for mixed precision support, all parameters (other than 'enabled') will be passed to
  160. # amp.initialize(model, optimizer, **amp_params)
  161. # See apex documentation for supported parameters/features: https://nvidia.github.io/apex/amp.html#apex.amp.initialize
  162. AMP_FORMAT = '''
  163. "amp" {
  164. "enabled: true,
  165. "opt_level": "O1",
  166. ...
  167. }
  168. '''
  169. AMP = "amp"
  170. AMP_ENABLED = "enabled"
  171. AMP_ENABLED_DEFAULT = False
  172. #########################################
  173. # Gradient clipping
  174. #########################################
  175. # Gradient clipping. By default, this feature is not enabled.
  176. # Users can configure in ds_config.json as below example:
  177. GRADIENT_CLIPPING_FORMAT = '''
  178. Gradient clipping should be enabled as:
  179. "gradient_clipping": 1.0
  180. '''
  181. GRADIENT_CLIPPING = 'gradient_clipping'
  182. GRADIENT_CLIPPING_DEFAULT = 0.
  183. #########################################
  184. # Communication data type
  185. #########################################
  186. # Supported types: ['none', 'fp16', 'fp32']
  187. # By default, this feature is not enabled ('none' value)
  188. # Users can configure in ds_config.json as below example:
  189. COMMUNICATION_DATA_TYPE_FORMAT = '''
  190. Communication data type should be set as:
  191. "communication_data_type": "fp32"
  192. '''
  193. COMMUNICATION_DATA_TYPE = "communication_data_type"
  194. COMMUNICATION_DATA_TYPE_DEFAULT = None
  195. #########################################
  196. # Scale/predivide gradients before allreduce
  197. #########################################
  198. # Prescale gradients. By default, this feature is not enabled.
  199. # Users can configure in ds_config.json as below example:
  200. PRESCALE_GRADIENTS_FORMAT = '''
  201. Gradient prescaling should be enabled as:
  202. "prescale_gradients": true
  203. '''
  204. PRESCALE_GRADIENTS = "prescale_gradients"
  205. PRESCALE_GRADIENTS_DEFAULT = False
  206. GRADIENT_PREDIVIDE_FACTOR_FORMAT = '''
  207. Gradient predivide factor should be enabled as:
  208. "gradient_predivide_factor": 1.0
  209. '''
  210. GRADIENT_PREDIVIDE_FACTOR = "gradient_predivide_factor"
  211. GRADIENT_PREDIVIDE_FACTOR_DEFAULT = 1.0
  212. #########################################
  213. # Disable AllGather
  214. #########################################
  215. # Disable AllGather. By default, this feature is not enabled.
  216. # Users can configure in ds_config.json as below example:
  217. DISABLE_ALLGATHER_FORMAT = '''
  218. Disable AllGather should be enabled as:
  219. "disable_allgather": true
  220. '''
  221. DISABLE_ALLGATHER = "disable_allgather"
  222. DISABLE_ALLGATHER_DEFAULT = False
  223. #########################################
  224. # Dump DeepSpeed state
  225. #########################################
  226. # Dump State. By default, this feature is not enabled.
  227. # Users can configure in ds_config.json as below example:
  228. DUMP_STATE_FORMAT = '''
  229. Dump state should be enabled as:
  230. "dump_state": true
  231. '''
  232. DUMP_STATE = 'dump_state'
  233. DUMP_STATE_DEFAULT = False
  234. #########################################
  235. # Vocabulary size
  236. #########################################
  237. # Vocabulary size.
  238. # Users can configure in ds_config.json as below example:
  239. VOCABULARY_SIZE_FORMAT = '''
  240. Vocabulary size can be specified as:
  241. "vocabulary_size": 1024
  242. '''
  243. VOCABULARY_SIZE = 'vocabulary_size'
  244. VOCABULARY_SIZE_DEFAULT = None
  245. #########################################
  246. # Wall block breakdown
  247. #########################################
  248. # Wall clock breakdown. By default, this feature is not enabled.
  249. # Users can configure in ds_config.json as below example:
  250. WALL_CLOCK_BREAKDOWN_FORMAT = '''
  251. Wall block breakdown should be enabled as:
  252. "wall_clock_breakdown": true
  253. '''
  254. WALL_CLOCK_BREAKDOWN = 'wall_clock_breakdown'
  255. WALL_CLOCK_BREAKDOWN_DEFAULT = False
  256. MEMORY_BREAKDOWN = 'memory_breakdown'
  257. MEMORY_BREAKDOWN_DEFAULT = False
  258. #########################################
  259. # Eigenvalue
  260. #########################################
  261. # Eigenvalue computation. By default, this feature is not enabled.
  262. # Users can configure in ds_config.json as below example:
  263. EIGENVALUE_FORMAT = '''
  264. Tensorboard can be specified as:
  265. "eigenvalue": {
  266. "enabled": true,
  267. "verbose": true,
  268. "max_iter": 100,
  269. "tol": 1e-2,
  270. "stability": 1e-6
  271. }
  272. '''
  273. EIGENVALUE = "eigenvalue"
  274. # Tensorboard enable signal
  275. EIGENVALUE_ENABLED = "enabled"
  276. EIGENVALUE_ENABLED_DEFAULT = False
  277. EIGENVALUE_VERBOSE = "verbose"
  278. EIGENVALUE_VERBOSE_DEFAULT = False
  279. EIGENVALUE_MAX_ITER = "max_iter"
  280. EIGENVALUE_MAX_ITER_DEFAULT = 100
  281. EIGENVALUE_TOL = "tol"
  282. EIGENVALUE_TOL_DEFAULT = 1e-2
  283. EIGENVALUE_STABILITY = "stability"
  284. EIGENVALUE_STABILITY_DEFAULT = 1e-6
  285. EIGENVALUE_GAS_BOUNDARY_RESOLUTION = "gas_boundary_resolution"
  286. EIGENVALUE_GAS_BOUNDARY_RESOLUTION_DEFAULT = 1
  287. EIGENVALUE_LAYER_NAME = "layer_name"
  288. EIGENVALUE_LAYER_NAME_DEFAULT = "bert.encoder.layer"
  289. EIGENVALUE_LAYER_NUM = "layer_num"
  290. EIGENVALUE_LAYER_NUM_DEFAULT = 0
  291. #########################################
  292. # Progressive Layer Drop (PLD)
  293. #########################################
  294. PROGRESSIVE_LAYER_DROP = "progressive_layer_drop"
  295. # PLD enable signal
  296. PLD_ENABLED = "enabled"
  297. PLD_ENABLED_DEFAULT = False
  298. PLD_THETA = "theta"
  299. PLD_THETA_DEFAULT = 1.0
  300. PLD_GAMMA = "gamma"
  301. PLD_GAMMA_DEFAULT = 0.001
  302. #########################################
  303. # Validation modes
  304. #########################################
  305. class ValidationMode:
  306. WARN = "WARN"
  307. IGNORE = "IGNORE"
  308. FAIL = "FAIL"
  309. #########################################
  310. # Checkpoint config params
  311. #########################################
  312. # "checkpoint": {
  313. # tag_validation=["Ignore"|"Warn"|"Fail"]
  314. # load_universal=false
  315. # use_node_local_storage=false
  316. # parallel_write: {
  317. # pipeline_stage: [True|False]
  318. # }
  319. # }
  320. CHECKPOINT = "checkpoint"
  321. CHECKPOINT_TAG_VALIDATION = "tag_validation"
  322. CHECKPOINT_TAG_VALIDATION_DEFAULT = ValidationMode.WARN
  323. CHECKPOINT_TAG_VALIDATION_MODES = [
  324. ValidationMode.WARN,
  325. ValidationMode.IGNORE,
  326. ValidationMode.FAIL
  327. ]
  328. LOAD_UNIVERSAL_CHECKPOINT = "load_universal"
  329. LOAD_UNIVERSAL_CHECKPOINT_DEFAULT = False
  330. USE_NODE_LOCAL_STORAGE_CHECKPOINT = "use_node_local_storage"
  331. USE_NODE_LOCAL_STORAGE_CHECKPOINT_DEFAULT = False
  332. CHECKPOINT_PARALLEL_WRITE = "parallel_write"
  333. CHECKPOINT_PARALLEL_WRITE_PIPELINE_STAGE = "pipeline_stage"
  334. CHECKPOINT_PARALLEL_WRITE_PIPELINE_STAGE_DEFAULT = False
  335. #########################################
  336. # Data types config params
  337. #########################################
  338. # "data_types": {
  339. # grad_accum_dtype=["bf16"|"fp16"|"fp32"]
  340. # }
  341. # }
  342. DATA_TYPES = "data_types"
  343. GRAD_ACCUM_DTYPE = "grad_accum_dtype"
  344. GRAD_ACCUM_DTYPE_DEFAULT = None
  345. #########################################
  346. # Drop the last incomplete Batch
  347. # #########################################
  348. # dataloader_drop_last. By default, this feature is not enabled.
  349. # Users can configure in ds_config.json as below example:
  350. DATALOADER_DROP_LAST_FORMAT = '''
  351. The last incomplete batch can be dropped by setting:
  352. "dataloader_drop_last": True
  353. '''
  354. DATALOADER_DROP_LAST = "dataloader_drop_last"
  355. DATALOADER_DROP_LAST_DEFAULT = False
  356. #########################################
  357. # PIPELINE PARALLELISM
  358. #########################################
  359. PIPE_REPLICATED = 'ds_pipe_replicated'
  360. #########################################
  361. # DATA PARALLELISM
  362. #########################################
  363. DATA_PARALLEL_GROUP = "data_parallel_group"
  364. GLOBAL_RANK = "global_rank"