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.

nn_training_ops.h 105 kB

5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
3 years ago
3 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*!
  17. * \file nn_training_ops.h
  18. * \brief
  19. */
  20. #ifndef OPS_BUILT_IN_OP_PROTO_INC_NN_TRAINING_OPS_H_
  21. #define OPS_BUILT_IN_OP_PROTO_INC_NN_TRAINING_OPS_H_
  22. #include "graph/operator_reg.h"
  23. namespace ge {
  24. /**
  25. *@brief Updates "var" according to the AdaMax algorithm.
  26. * t-1 mean previous period.
  27. * m_t <- beta1 * m{t-1} + (1 - beta1) * grad
  28. * v_t <- max(beta2 * v{t-1}, abs(grad))
  29. * var <- var - lr / (1 - beta1^t) * m_t / (v_t + epsilon)
  30. *
  31. *@attention Constraints:
  32. * the input tensors must have the same shape.
  33. *
  34. *@par Inputs:
  35. *@li var: A mutable tensor. Must be one of the following types: TensorType::NumberType().
  36. * Should be from a Variable().
  37. *@li m: A mutable tensor. Has the same type as "var".
  38. * Should be from a Variable().
  39. *@li v: A mutable tensor. Has the same type as "var".
  40. * Should be from a Variable().
  41. *@li beta1_power: A scalar. Has the same type as "var".
  42. *@li lr: learning_rate. A scalar. Has the same type as "var".
  43. *@li beta1: A scalar. Has the same type as "var".
  44. *@li beta2: A scalar. Has the same type as "var".
  45. *@li epsilon: A scalar. Has the same type as "var".
  46. *@li grad: A tensor for the gradient. Has the same type as "var".
  47. *
  48. *@par Attributes:
  49. * use_locking: An optional bool. Defaults to "False".
  50. * If "True", updating of the "var", "ms", and "mom" tensors is protected
  51. * by a lock; otherwise the behavior is undefined, but may exhibit less
  52. * contention.
  53. *
  54. *@par Outputs:
  55. * var: A mutable tensor. Has the same type as input "var".
  56. *
  57. *@par Third-party framework compatibility
  58. *Compatible with the TensorFlow operator ApplyAdaMax.
  59. *
  60. */
  61. REG_OP(ApplyAdaMax)
  62. .INPUT(var, TensorType::NumberType())
  63. .INPUT(m, TensorType::NumberType())
  64. .INPUT(v, TensorType::NumberType())
  65. .INPUT(beta1_power, TensorType::NumberType())
  66. .INPUT(lr, TensorType::NumberType())
  67. .INPUT(beta1, TensorType::NumberType())
  68. .INPUT(beta2, TensorType::NumberType())
  69. .INPUT(epsilon, TensorType::NumberType())
  70. .INPUT(grad, TensorType::NumberType())
  71. .OUTPUT(var, TensorType::NumberType())
  72. .ATTR(use_locking, Bool, false)
  73. .OP_END_FACTORY_REG(ApplyAdaMax)
  74. /**
  75. *@brief Updates "var" according to the AdaMax algorithm.
  76. * t-1 mean previous period.
  77. * m_t <- beta1 * m{t-1} + (1 - beta1) * grad
  78. * v_t <- max(beta2 * v{t-1}, abs(grad))
  79. * var <- var - lr / (1 - beta1^t) * m_t / (v_t + epsilon)
  80. *
  81. *@attention Constraints:
  82. * the input tensors must have the same shape.
  83. *
  84. *@par Inputs:
  85. *@li var: A mutable tensor. Must be one of the following types: TensorType::NumberType().
  86. * Should be from a Variable().
  87. *@li m: A mutable tensor. Has the same type as "var".
  88. * Should be from a Variable().
  89. *@li v: A mutable tensor. Has the same type as "var".
  90. * Should be from a Variable().
  91. *@li beta1_power: A scalar. Has the same type as "var".
  92. *@li lr: learning_rate. A scalar. Has the same type as "var".
  93. *@li beta1: A scalar. Has the same type as "var".
  94. *@li beta2: A scalar. Has the same type as "var".
  95. *@li epsilon: A scalar. Has the same type as "var".
  96. *@li grad: A tensor for the gradient. Has the same type as "var".
  97. *
  98. *@par Attributes:
  99. * use_locking: An optional bool. Defaults to "False".
  100. * If "True", updating of the "var", "ms", and "mom" tensors is protected
  101. * by a lock; otherwise the behavior is undefined, but may exhibit less
  102. * contention.
  103. *
  104. *@par Outputs:
  105. *@li var: A mutable tensor. Has the same type as input "var".
  106. *@li m: A mutable tensor. Has the same type as input "m".
  107. *@li v: A mutable tensor. Has the same type as input "v".
  108. *
  109. *@par Third-party framework compatibility
  110. *Compatible with the TensorFlow operator ApplyAdaMax.
  111. *
  112. * @par Restrictions:
  113. * Warning: THIS FUNCTION IS DEPRECATED. Please use ApplyAdaMax instead.
  114. */
  115. REG_OP(ApplyAdaMaxD)
  116. .INPUT(var, TensorType::NumberType())
  117. .INPUT(m, TensorType::NumberType())
  118. .INPUT(v, TensorType::NumberType())
  119. .INPUT(beta1_power, TensorType::NumberType())
  120. .INPUT(lr, TensorType::NumberType())
  121. .INPUT(beta1, TensorType::NumberType())
  122. .INPUT(beta2, TensorType::NumberType())
  123. .INPUT(epsilon, TensorType::NumberType())
  124. .INPUT(grad, TensorType::NumberType())
  125. .OUTPUT(var, TensorType::NumberType())
  126. .OUTPUT(m, TensorType::NumberType())
  127. .OUTPUT(v, TensorType::NumberType())
  128. .ATTR(use_locking, Bool, false)
  129. .OP_END_FACTORY_REG(ApplyAdaMaxD)
  130. /**
  131. *@brief Updates relevant entries in "var" and "accum" according to the adagrad scheme . \n
  132. *@par Inputs:
  133. * Five inputs, including:
  134. *@li var: An NCHW, NHWC, or ND Tensor of type float32.
  135. *@li accum: An NCHW, NHWC, or ND Tensor of type float32.
  136. *@li lr: An NCHW, NHWC, or ND Tensor of type float32.
  137. *@li grad: An NCHW, NHWC, or ND Tensor of type float32.
  138. *@li indices: An NCHW, NHWC, or ND Tensor of type float32 . \n
  139. *@par Attributes:
  140. *@li use_locking: An optional bool. Defaults to "False". If "True", the operation will be protected by a lock.
  141. *@li update_slots: An optional bool. Defaults to "True". If "True", the calcution will be different as "False" . \n
  142. *@par Outputs:
  143. *var: A Tensor. Has the same type and format as input "var" . \n
  144. *@par Third-party framework compatibility
  145. * Compatible with the TensorFlow operator SparseApplyAdagrad.
  146. */
  147. REG_OP(SparseApplyAdagrad)
  148. .INPUT(var, TensorType({DT_FLOAT}))
  149. .INPUT(accum, TensorType({DT_FLOAT}))
  150. .INPUT(lr, TensorType({DT_FLOAT}))
  151. .INPUT(grad, TensorType({DT_FLOAT}))
  152. .INPUT(indices, TensorType({DT_INT32}))
  153. .OUTPUT(var, TensorType({DT_FLOAT}))
  154. .ATTR(use_locking, Bool, false)
  155. .ATTR(update_slots, Bool, true)
  156. .OP_END_FACTORY_REG(SparseApplyAdagrad)
  157. /**
  158. *@brief Updates relevant entries in "var" and "accum" according to the adagrad scheme . \n
  159. *@par Inputs:
  160. * Four inputs, including:
  161. *@li var: An NCHW, NHWC, or ND Tensor of type float32.
  162. *@li accum: An NCHW, NHWC, or ND Tensor of type float32.
  163. *@li grad: An NCHW, NHWC, or ND Tensor of type float32.
  164. *@li indices: An NCHW, NHWC, or ND Tensor of type int32 . \n
  165. *@par Attributes:
  166. *@li lr: Required, used for computation.
  167. *@li use_locking: An optional bool. Defaults to "False". If "True", the operation will be protected by a lock.
  168. *@li update_slots: An optional bool. Defaults to "True". If "True", the calcution will be different as "False" . \n
  169. *@par Outputs:
  170. *@li var: A Tensor. Has the same type and format as input "var".
  171. *@li accum: A Tensor. Has the same type and format as input "var" . \n
  172. *@par Third-party framework compatibility
  173. * Compatible with the TensorFlow operator SparseApplyAdagrad. \n
  174. *
  175. *@par Restrictions:
  176. *Warning: THIS FUNCTION IS DEPRECATED. Please use SparseApplyAdagrad instead.
  177. */
  178. REG_OP(SparseApplyAdagradD)
  179. .INPUT(var, TensorType({DT_FLOAT}))
  180. .INPUT(accum, TensorType({DT_FLOAT}))
  181. .INPUT(grad, TensorType({DT_FLOAT}))
  182. .INPUT(indices, TensorType({DT_INT32}))
  183. .OUTPUT(var, TensorType({DT_FLOAT}))
  184. .OUTPUT(accum, TensorType({DT_FLOAT}))
  185. .REQUIRED_ATTR(lr, Float)
  186. .ATTR(use_locking, Bool, false)
  187. .ATTR(update_slots, Bool, true)
  188. .OP_END_FACTORY_REG(SparseApplyAdagradD)
  189. /**
  190. *@brief Updates relevant entries in "var" and "accum" according to the adagrad scheme . \n
  191. *@par Inputs:
  192. *Six inputs, including:
  193. *@li var: An NCHW, NHWC, or ND Tensor of type float32.
  194. *@li accum: An NCHW, NHWC, or ND Tensor of type float32.
  195. *@li lr: An NCHW, NHWC, or ND Tensor of type float32.
  196. *@li epsilon: An NCHW, NHWC, or ND Tensor of type float32.
  197. *@li grad: An NCHW, NHWC, or ND Tensor of type float32.
  198. *@li indices: An NCHW, NHWC, or ND Tensor of type float32 . \n
  199. *@par Attributes:
  200. *@li use_locking: An optional bool. Defaults to "False". If "True", the operation will be protected by a lock.
  201. *@li update_slots: An optional bool. Defaults to "True". If "False", the computation logic will be different . \n
  202. *@par Outputs:
  203. *var: A Tensor. Has the same type and format as input "var" . \n
  204. *@par Third-party framework compatibility
  205. *Compatible with the TensorFlow operator SparseApplyAdagradV2.
  206. */
  207. REG_OP(SparseApplyAdagradV2)
  208. .INPUT(var, TensorType({DT_FLOAT}))
  209. .INPUT(accum, TensorType({DT_FLOAT}))
  210. .INPUT(lr, TensorType({DT_FLOAT}))
  211. .INPUT(epsilon, TensorType({DT_FLOAT}))
  212. .INPUT(grad, TensorType({DT_FLOAT}))
  213. .INPUT(indices, TensorType({DT_INT32}))
  214. .OUTPUT(var, TensorType({DT_FLOAT}))
  215. .ATTR(use_locking, Bool, false)
  216. .ATTR(update_slots, Bool, true)
  217. .OP_END_FACTORY_REG(SparseApplyAdagradV2)
  218. /**
  219. *@brief Updates relevant entries in "var" and "accum" according to the adagrad scheme . \n
  220. *@par Inputs:
  221. *Four inputs, including:
  222. *@li var: An NCHW, NHWC, or ND Tensor of type float32.
  223. *@li accum: An NCHW, NHWC, or ND Tensor of type float32.
  224. *@li grad: An NCHW, NHWC, or ND Tensor of type float32.
  225. *@li indices: An NCHW, NHWC, or ND Tensor of type int32 . \n
  226. *@par Attributes:
  227. *@li lr: Required, used for computation.
  228. *@li epsilon: Required, used for computation.
  229. *@li use_locking: An optional bool. Defaults to "False". If "True", the operation will be protected by a lock.
  230. *@li update_slots: An optional bool. Defaults to "True". If "False", the computation logic will be different . \n
  231. *@par Outputs:
  232. *@li var: A Tensor. Has the same type and format as input "var".
  233. *@li accum: A Tensor. Has the same type and format as input "accum" . \n
  234. *@par Third-party framework compatibility
  235. *Compatible with the TensorFlow operator SparseApplyAdagradV2. \n
  236. *
  237. *@par Restrictions:
  238. *Warning: THIS FUNCTION IS DEPRECATED. Please use SparseApplyAdagradV2 instead.
  239. */
  240. REG_OP(SparseApplyAdagradV2D)
  241. .INPUT(var, TensorType({DT_FLOAT}))
  242. .INPUT(accum, TensorType({DT_FLOAT}))
  243. .INPUT(grad, TensorType({DT_FLOAT}))
  244. .INPUT(indices, TensorType({DT_INT32}))
  245. .OUTPUT(var, TensorType({DT_FLOAT}))
  246. .OUTPUT(accum, TensorType({DT_FLOAT}))
  247. .REQUIRED_ATTR(lr, Float)
  248. .REQUIRED_ATTR(epsilon, Float)
  249. .ATTR(use_locking, Bool, false)
  250. .ATTR(update_slots, Bool, true)
  251. .OP_END_FACTORY_REG(SparseApplyAdagradV2D)
  252. /**
  253. *@brief Updates "var" according to the momentum scheme. Set use_nesterov = True if you
  254. * want to use Nesterov momentum.
  255. * computing process:
  256. * accum = accum * momentum + grad
  257. * var -= lr * accum
  258. *
  259. *@attention Constraints:
  260. * the input tensors must have the same shape.
  261. *
  262. *@par Inputs:
  263. *@li var: A mutable tensor. Should be from a Variable().
  264. *@li accum: A mutable tensor. Has the same type as "var".
  265. * Should be from a Variable().
  266. *@li lr: A scalar. Has the same type as "var".
  267. *@li grad: A tensor for the gradient. Has the same type as "var".
  268. *
  269. *@par Attributes:
  270. *@li use_nesterov: An optional bool. Defaults to "False".
  271. * If "True", the tensor passed to compute grad will be
  272. * var - lr * momentum * accum, so in the end, the var you get is actually
  273. * var - lr * momentum * accum.
  274. *
  275. *@li use_locking: An optional bool. Defaults to "False".
  276. * If "True", updating of the "var", "ms", and "mom" tensors is protected by a lock;
  277. * otherwise the behavior is undefined, but may exhibit less contention.
  278. *
  279. *@par Outputs:
  280. * var: A mutable tensor. Has the same type as input "var".
  281. *
  282. *@par Third-party framework compatibility
  283. *Compatible with the TensorFlow operator ApplyMomentum.
  284. *
  285. */
  286. REG_OP(ApplyMomentum)
  287. .INPUT(var, TensorType::NumberType())
  288. .INPUT(accum, TensorType::NumberType())
  289. .INPUT(lr, TensorType::NumberType())
  290. .INPUT(grad, TensorType::NumberType())
  291. .INPUT(momentum, TensorType::NumberType())
  292. .OUTPUT(var, TensorType::NumberType())
  293. .ATTR(use_nesterov, Bool, false)
  294. .ATTR(use_locking, Bool, false)
  295. .OP_END_FACTORY_REG(ApplyMomentum)
  296. /**
  297. *@brief Updates "var" according to the momentum scheme. Set use_nesterov = True if you
  298. * want to use Nesterov momentum.
  299. * computing process:
  300. * accum = accum * momentum + grad
  301. * var -= lr * accum
  302. *
  303. *@attention Constraints:
  304. * the input tensors must have the same shape.
  305. *
  306. *@par Inputs:
  307. *@li var: A mutable tensor. Should be from a Variable().
  308. *@li accum: A mutable tensor. Has the same type as "var".
  309. * Should be from a Variable().
  310. *@li lr: A scalar. Has the same type as "var".
  311. *@li grad: A tensor for the gradient. Has the same type as "var".
  312. *
  313. *@par Attributes:
  314. *@li use_nesterov: An optional bool. Defaults to "False".
  315. * If "True", the tensor passed to compute grad will be
  316. * var - lr * momentum * accum, so in the end, the var you get is actually
  317. * var - lr * momentum * accum.
  318. *
  319. *@li use_locking: An optional bool. Defaults to "False".
  320. * If "True", updating of the "var", "ms", and "mom" tensors is protected by a lock;
  321. * otherwise the behavior is undefined, but may exhibit less contention.
  322. *
  323. *@par Outputs:
  324. * var: A mutable tensor. Has the same type as input "var".
  325. * accum: A mutable tensor. Has the same type as input "accum".
  326. *@par Third-party framework compatibility
  327. *Compatible with the TensorFlow operator ApplyMomentum.
  328. *
  329. * @par Restrictions:
  330. * Warning: THIS FUNCTION IS DEPRECATED. Please use ApplyMomentum instead.
  331. */
  332. REG_OP(ApplyMomentumD)
  333. .INPUT(var, TensorType::NumberType())
  334. .INPUT(accum, TensorType::NumberType())
  335. .INPUT(lr, TensorType::NumberType())
  336. .INPUT(grad, TensorType::NumberType())
  337. .INPUT(momentum, TensorType::NumberType())
  338. .OUTPUT(var, TensorType::NumberType())
  339. .OUTPUT(accum, TensorType::NumberType())
  340. .ATTR(use_nesterov, Bool, false)
  341. .ATTR(use_locking, Bool, false)
  342. .OP_END_FACTORY_REG(ApplyMomentumD)
  343. /**
  344. *@brief Updates '*var' according to the momentum scheme.
  345. * accum = accum * momentum - grad * lr
  346. * if use_nesterov is True:
  347. * var += accum * momentum - grad * lr
  348. * else:
  349. * var += accum
  350. *
  351. *@par Inputs:
  352. *@li var: A mutable tensor. Must be one of the data types defined in
  353. * TensorType::NumberType(). Should be from a Variable().
  354. *@li accum: A mutable tensor. Has the same type as "var". Should be from a
  355. * Variable().
  356. *@li lr: A tensor for the learning rate. Has the same type as "var". Should be
  357. * from a Variable().
  358. *@li grad: A tensor for the gradient. Has the same type as "var". Should be
  359. * from a Variable().
  360. *@li momentum: A scalar. Has the same type as "var".
  361. *
  362. *@par Attributes:
  363. *@li use_nesterov: An optional bool. Defaults to "False".
  364. * If "True", var will be updated by using Nesterov momentum.
  365. *@li use_locking: An optional bool. Defaults to "False".
  366. * If "True", updating of the "var" tensor is protected by a lock;
  367. * otherwise the behavior is undefined, but may exhibit less contention.
  368. *
  369. *@par Outputs:
  370. * var: A mutable tensor. Has the same type as input "var".
  371. *
  372. *@attention Constraints:
  373. * The input tensors must have the same shape.
  374. *
  375. *@par Third-party framework compatibility
  376. * Compatible with the TensorFlow operator ResourceApplyKerasMomentum.
  377. *
  378. */
  379. REG_OP(ApplyKerasMomentum)
  380. .INPUT(var, TensorType::NumberType())
  381. .INPUT(accum, TensorType::NumberType())
  382. .INPUT(lr, TensorType::NumberType())
  383. .INPUT(grad, TensorType::NumberType())
  384. .INPUT(momentum, TensorType::NumberType())
  385. .OUTPUT(var, TensorType::NumberType())
  386. .ATTR(use_locking, Bool, false)
  387. .ATTR(use_nesterov, Bool, false)
  388. .OP_END_FACTORY_REG(ApplyKerasMomentum)
  389. /**
  390. *@brief Updates '*var' according to the momentum scheme.
  391. * accum = accum * momentum - grad * lr
  392. * if use_nesterov is True:
  393. * var += accum * momentum - grad * lr
  394. * else:
  395. * var += accum
  396. *
  397. *@par Inputs:
  398. *@li var: A mutable tensor. Must be one of the data types defined in
  399. * TensorType::NumberType(). Should be from a Variable().
  400. *@li accum: A mutable tensor. Has the same type as "var". Should be from a
  401. * Variable().
  402. *@li lr: A tensor for the learning rate. Has the same type as "var". Should be
  403. * from a Variable().
  404. *@li grad: A tensor for the gradient. Has the same type as "var". Should be
  405. * from a Variable().
  406. *@li momentum: A scalar. Has the same type as "var". Should be from a
  407. * Variable().
  408. *
  409. *@par Attributes:
  410. *@li use_nesterov: An optional bool. Defaults to "False".
  411. * If "True", var will be updated by using nesterov momentum
  412. *@li use_locking: An optional bool. Defaults to "False".
  413. * If "True", updating of the "var" tensor is protected by a lock;
  414. * otherwise the behavior is undefined, but may exhibit less contention.
  415. *
  416. *@par Outputs:
  417. *@li var: A mutable tensor. Has the same type as input "var".
  418. *@li accum: A mutable tensor. Has the same type as input "var"
  419. *
  420. *@attention Constraints:
  421. * The input tensors must have the same shape.
  422. *
  423. *@par Third-party framework compatibility
  424. * Compatible with the TensorFlow operator ResourceApplyKerasMomentum.
  425. *
  426. *@par Restrictions:
  427. *Warning: THIS FUNCTION IS DEPRECATED. Please use ApplyKerasMomentum instead.
  428. */
  429. REG_OP(ApplyKerasMomentumD)
  430. .INPUT(var, TensorType::NumberType())
  431. .INPUT(accum, TensorType::NumberType())
  432. .INPUT(lr, TensorType::NumberType())
  433. .INPUT(grad, TensorType::NumberType())
  434. .INPUT(momentum, TensorType::NumberType())
  435. .OUTPUT(var, TensorType::NumberType())
  436. .OUTPUT(accum, TensorType::NumberType())
  437. .ATTR(use_locking, Bool, false)
  438. .ATTR(use_nesterov, Bool, false)
  439. .OP_END_FACTORY_REG(ApplyKerasMomentumD)
  440. /**
  441. *@brief Updates '*var' according to the Adam algorithm.
  442. * lr_t := {learning_rate} * sqrt{1 - beta_2^t} / (1 - beta_1^t)
  443. * m_t := beta_1 * m_{t-1} + (1 - beta_1) * g
  444. * v_t := beta_2 * v_{t-1} + (1 - beta_2) * g * g
  445. * vhat_t := max{vhat_{t-1}, v_t}
  446. * variable := variable - lr_t * m_t / (sqrt{vhat_t} + epsilon)
  447. *
  448. *@par Inputs:
  449. *@li var: A mutable tensor. Must be one of the data types defined in
  450. * TensorType::NumberType(). Should be from a Variable().
  451. *@li m: A mutable tensor. Has the same type as "var". Should be from a
  452. * Variable().
  453. *@li v: A mutable tensor. Has the same type as "var". Should be from a
  454. * Variable().
  455. *@li vhat: A mutable tensor. Has the same type as "var". Should be from a
  456. * Variable().
  457. *@li beta1_power: A mutable tensor. Has the same type as "var". Should be from a
  458. * Variable().
  459. *@li beta2_power: A mutable tensor. Has the same type as "var". Should be from a
  460. * Variable().
  461. *@li lr: A tensor for the learning rate. Has the same type as "var". Should be
  462. * from a Variable().
  463. *@li grad: A tensor for the gradient. Has the same type as "var". Should be
  464. * from a Variable().
  465. *
  466. *@par Attributes:
  467. *@li beta1: A scalar. Has the same type as "var".
  468. *@li beta2: A scalar. Has the same type as "var".
  469. *@li epsilon: A scalar. Has the same type as "var".
  470. *@li use_locking: An optional bool. Defaults to "False".
  471. * If "True", updating of the "var" tensor is protected by a lock;
  472. * otherwise the behavior is undefined, but may exhibit less contention.
  473. *
  474. *@par Outputs:
  475. *@li var: A mutable tensor. Has the same type as input "var".
  476. *@li m: A mutable tensor. Has the same type as input "var"
  477. *@li v: A mutable tensor. Has the same type as input "var"
  478. *@li vhat: A mutable tensor. Has the same type as input "var"
  479. *
  480. *@attention Constraints:
  481. * The input tensors must have the same shape.
  482. *
  483. *@par Third-party framework compatibility
  484. * Compatible with the TensorFlow operator ResourceApplyKerasMomentum.
  485. *
  486. *@par Restrictions:
  487. *Warning: THIS FUNCTION IS DEPRECATED. Please use ApplyAdamWithAmsgrad instead.
  488. *
  489. */
  490. REG_OP(ApplyAdamWithAmsgradD)
  491. .INPUT(var, TensorType::NumberType())
  492. .INPUT(m, TensorType::NumberType())
  493. .INPUT(v, TensorType::NumberType())
  494. .INPUT(vhat, TensorType::NumberType())
  495. .INPUT(beta1_power, TensorType::NumberType())
  496. .INPUT(beta2_power, TensorType::NumberType())
  497. .INPUT(lr, TensorType::NumberType())
  498. .INPUT(grad, TensorType::NumberType())
  499. .OUTPUT(var, TensorType::NumberType())
  500. .OUTPUT(m, TensorType::NumberType())
  501. .OUTPUT(v, TensorType::NumberType())
  502. .OUTPUT(vhat, TensorType::NumberType())
  503. .REQUIRED_ATTR(beta1, Float)
  504. .REQUIRED_ATTR(beta2, Float)
  505. .REQUIRED_ATTR(epsilon, Float)
  506. .ATTR(use_locking, Bool, false)
  507. .OP_END_FACTORY_REG(ApplyAdamWithAmsgradD)
  508. /**
  509. *@brief Updates '*var' according to the Adam algorithm..
  510. * lr_t := {learning_rate} * sqrt{1 - beta_2^t} / (1 - beta_1^t)
  511. * m_t := beta_1 * m_{t-1} + (1 - beta_1) * g
  512. * v_t := beta_2 * v_{t-1} + (1 - beta_2) * g * g
  513. * vhat_t := max{vhat_{t-1}, v_t}
  514. * variable := variable - lr_t * m_t / (sqrt{vhat_t} + epsilon)
  515. *
  516. *@par Inputs:
  517. *@li var: A mutable tensor. Must be one of the data types defined in
  518. * TensorType::NumberType(). Should be from a Variable().
  519. *@li m: A mutable tensor. Has the same type as "var". Should be from a
  520. * Variable().
  521. *@li v: A mutable tensor. Has the same type as "var". Should be from a
  522. * Variable().
  523. *@li vhat: A mutable tensor. Has the same type as "var". Should be from a
  524. * Variable().
  525. *@li beta1_power: A mutable tensor. Has the same type as "var". Should be from a
  526. * Variable().
  527. *@li beta2_power: A mutable tensor. Has the same type as "var". Should be from a
  528. * Variable().
  529. *@li lr: A tensor for the learning rate. Has the same type as "var". Should be
  530. * from a Variable().
  531. *@li grad: A tensor for the gradient. Has the same type as "var". Should be
  532. * from a Variable().
  533. *
  534. *@par Attributes:
  535. *@li beta1: A scalar. Has the same type as "var".
  536. *@li beta2: A scalar. Has the same type as "var".
  537. *@li epsilon: A scalar. Has the same type as "var".
  538. *@li use_locking: An optional bool. Defaults to "False".
  539. * If "True", updating of the "var" tensor is protected by a lock;
  540. * otherwise the behavior is undefined, but may exhibit less contention.
  541. *
  542. *@par Outputs:
  543. *@li var: A mutable tensor. Has the same type as input "var".
  544. *@li m: A mutable tensor. Has the same type as input "var"
  545. *@li v: A mutable tensor. Has the same type as input "var"
  546. *@li vhat: A mutable tensor. Has the same type as input "var"
  547. *
  548. *@attention Constraints:
  549. * The input tensors must have the same shape.
  550. *
  551. *@par Third-party framework compatibility
  552. * Compatible with the TensorFlow operator ResourceApplyKerasMomentum.
  553. *
  554. */
  555. REG_OP(ApplyAdamWithAmsgrad)
  556. .INPUT(var, TensorType::NumberType())
  557. .INPUT(m, TensorType::NumberType())
  558. .INPUT(v, TensorType::NumberType())
  559. .INPUT(vhat, TensorType::NumberType())
  560. .INPUT(beta1_power, TensorType::NumberType())
  561. .INPUT(beta2_power, TensorType::NumberType())
  562. .INPUT(lr, TensorType::NumberType())
  563. .INPUT(beta1, TensorType::NumberType())
  564. .INPUT(beta2, TensorType::NumberType())
  565. .INPUT(epsilon, TensorType::NumberType())
  566. .INPUT(grad, TensorType::NumberType())
  567. .OUTPUT(var, TensorType::NumberType())
  568. .ATTR(use_locking, Bool, false)
  569. .OP_END_FACTORY_REG(ApplyAdamWithAmsgrad)
  570. /**
  571. *@brief Updates "var" according to the AddSign update.
  572. * t-1 mean previous period.
  573. * m_t <- beta1 * m_{t-1} + (1 - beta1) * grad
  574. * update <- exp(logbase * sign_decay * sign(grad) * sign(m_t)) * grad
  575. * var <- var - lr * update
  576. *
  577. *@attention Constraints:
  578. * the input tensors must have the same shape.
  579. *
  580. *@par Inputs:
  581. *@li var: A mutable tensor. Should be from a Variable().
  582. *@li m: A mutable tensor. Has the same type as "var".
  583. * Should be from a Variable().
  584. *@li lr: A scalar. Has the same type as "var".
  585. *@li logbase: A scalar. Has the same type as "var".
  586. *@li sign_decay: A scalar. Has the same type as "var".
  587. *@li beta: A scalar. Has the same type as "var".
  588. *@li grad: A tensor for the gradient. Has the same type as "var".
  589. *
  590. *@par Attributes:
  591. * use_locking: An optional bool. Defaults to "False".
  592. * If "True", updating of the "var", "ms", and "mom" tensors is protected
  593. * by a lock; otherwise the behavior is undefined, but may exhibit less
  594. * contention.
  595. *
  596. *@par Outputs:
  597. * var: A mutable tensor. Has the same type as input "var".
  598. *
  599. *@par Third-party framework compatibility
  600. *Compatible with the TensorFlow operator ApplyPowerSign.
  601. *
  602. */
  603. REG_OP(ApplyPowerSign)
  604. .INPUT(var, TensorType::NumberType())
  605. .INPUT(m, TensorType::NumberType())
  606. .INPUT(lr, TensorType::NumberType())
  607. .INPUT(logbase, TensorType::NumberType())
  608. .INPUT(sign_decay, TensorType::NumberType())
  609. .INPUT(beta, TensorType::NumberType())
  610. .INPUT(grad, TensorType::NumberType())
  611. .OUTPUT(var, TensorType::NumberType())
  612. .ATTR(use_locking, Bool, false)
  613. .OP_END_FACTORY_REG(ApplyPowerSign)
  614. /**
  615. *@brief Updates "var" according to the AddSign update.
  616. * t-1 mean previous period.
  617. * m_t <- beta1 * m_{t-1} + (1 - beta1) * grad
  618. * update <- exp(logbase * sign_decay * sign(grad) * sign(m_t)) * grad
  619. * var <- var - lr * update
  620. *
  621. *@attention Constraints:
  622. * the input tensors must have the same shape.
  623. *
  624. *@par Inputs:
  625. *@li var: A mutable tensor. Should be from a Variable().
  626. *@li m: A mutable tensor. Has the same type as "var".
  627. * Should be from a Variable().
  628. *@li lr: A scalar. Has the same type as "var".
  629. *@li logbase: A scalar. Has the same type as "var".
  630. *@li sign_decay: A scalar. Has the same type as "var".
  631. *@li beta: A scalar. Has the same type as "var".
  632. *@li grad: A tensor for the gradient. Has the same type as "var".
  633. *
  634. *@par Attributes:
  635. * use_locking: An optional bool. Defaults to "False".
  636. * If "True", updating of the "var", "ms", and "mom" tensors is protected
  637. * by a lock; otherwise the behavior is undefined, but may exhibit less
  638. * contention.
  639. *
  640. *@par Outputs:
  641. *@li var: A mutable tensor. Has the same type as input "var".
  642. *@li m: A mutable tensor. Has the same type as input "var".
  643. *
  644. *@par Third-party framework compatibility
  645. *Compatible with the TensorFlow operator ApplyPowerSign.
  646. *
  647. * @par Restrictions:
  648. * Warning: THIS FUNCTION IS DEPRECATED. Please use ApplyPowerSign instead.
  649. */
  650. REG_OP(ApplyPowerSignD)
  651. .INPUT(var, TensorType::NumberType())
  652. .INPUT(m, TensorType::NumberType())
  653. .INPUT(lr, TensorType::NumberType())
  654. .INPUT(logbase, TensorType::NumberType())
  655. .INPUT(sign_decay, TensorType::NumberType())
  656. .INPUT(beta, TensorType::NumberType())
  657. .INPUT(grad, TensorType::NumberType())
  658. .OUTPUT(var, TensorType::NumberType())
  659. .OUTPUT(m, TensorType::NumberType())
  660. .ATTR(use_locking, Bool, false)
  661. .OP_END_FACTORY_REG(ApplyPowerSignD)
  662. /**
  663. *@brief Updates "var" as FOBOS algorithm with fixed learning rate.
  664. * prox_v = var - alpha * delta
  665. * var = sign(prox_v)/(1+alpha*l2) * max{|prox_v|-alpha*l1,0}
  666. *
  667. *@attention Constraints:
  668. * the input tensors must have the same shape.
  669. *
  670. *@par Inputs:
  671. *@li var: A mutable tensor. Should be from a Variable().
  672. *@li alpha: A scalar. Has the same type as "var".
  673. *@li l1: A scalar. Has the same type as "var".
  674. *@li l2: A scalar. Has the same type as "var".
  675. *@li delta: A tensor. Has the same type as "var". The change.
  676. *
  677. *@par Attributes:
  678. * use_locking: An optional bool. Defaults to "False".
  679. * If "True", updating of the "var", "ms", and "mom" tensors is protected
  680. * by a lock; otherwise the behavior is undefined, but may exhibit less
  681. * contention.
  682. *
  683. *@par Outputs:
  684. * var: A mutable tensor. Has the same type as input "var".
  685. *
  686. *@par Third-party framework compatibility
  687. *Compatible with the TensorFlow operator ApplyProximalGradientDescent.
  688. *
  689. */
  690. REG_OP(ApplyProximalGradientDescent)
  691. .INPUT(var, TensorType::NumberType())
  692. .INPUT(alpha, TensorType::NumberType())
  693. .INPUT(l1, TensorType::NumberType())
  694. .INPUT(l2, TensorType::NumberType())
  695. .INPUT(delta, TensorType::NumberType())
  696. .OUTPUT(var, TensorType::NumberType())
  697. .ATTR(use_locking, Bool, false)
  698. .OP_END_FACTORY_REG(ApplyProximalGradientDescent)
  699. /**
  700. *@brief Updates "var" according to the AddSign update . \n
  701. *@par Inputs:
  702. *Seven inputs, including:
  703. * @li var: A mutable Tensor of type TensorType::NumberType().
  704. * Should be a Variable Tensor.
  705. * @li m: A mutable Tensor of the same type as "var".
  706. * Should be a Variable Tensor.
  707. * @li lr: A Tensor of the same type as "var", for the scaling factor. Must be a scalar.
  708. * @li alpha: A Tensor of the same type as "var". Must be a scalar.
  709. * @li sign_decay: A Tensor of the same type as "var". Must be a scalar.
  710. * @li beta: A Tensor of the same type as "var". Must be a scalar.
  711. * @li grad: A Tensor of the same type as "var", for the gradient.
  712. *@par Attributes:
  713. *use_locking: An optional bool. Defaults to "False".
  714. * If "True", updating of the "var" and "m" tensors will be
  715. * protected by a lock; otherwise the behavior is undefined,
  716. * but may exhibit less contention . \n
  717. *@par Outputs:
  718. *var: A mutable Tensor. Has the same type as "var" . \n
  719. *@par Third-party framework compatibility
  720. * Compatible with the TensorFlow operator ApplyAddSign.
  721. */
  722. REG_OP(ApplyAddSign)
  723. .INPUT(var, TensorType::NumberType())
  724. .INPUT(m, TensorType::NumberType())
  725. .INPUT(lr, TensorType::NumberType())
  726. .INPUT(alpha, TensorType::NumberType())
  727. .INPUT(sign_decay, TensorType::NumberType())
  728. .INPUT(beta, TensorType::NumberType())
  729. .INPUT(grad, TensorType::NumberType())
  730. .OUTPUT(var, TensorType::NumberType())
  731. .ATTR(use_locking, Bool, false)
  732. .OP_END_FACTORY_REG(ApplyAddSign)
  733. /**
  734. *@brief Updates "var" according to the AddSign update . \n
  735. *@par Inputs:
  736. *Seven inputs, including:
  737. * @li var: A mutable Tensor of type TensorType::NumberType().
  738. * Should be a Variable Tensor.
  739. * @li m: A mutable Tensor of the same type as "var".
  740. * Should be a Variable Tensor.
  741. * @li lr: A Tensor of the same type as "var", for the scaling factor. Must be a scalar.
  742. * @li alpha: A Tensor of the same type as "var". Must be a scalar.
  743. * @li sign_decay: A Tensor of the same type as "var". Must be a scalar.
  744. * @li beta: A Tensor of the same type as "var". Must be a scalar.
  745. * @li grad: A Tensor of the same type as "var", for the gradient.
  746. *@par Attributes:
  747. *use_locking: An optional bool. Defaults to "False".
  748. * If "True", updating of the "var" and "m" tensors will be
  749. * protected by a lock; otherwise the behavior is undefined,
  750. * but may exhibit less contention . \n
  751. *@par Outputs:
  752. *@li var: A mutable Tensor. Has the same type as "var".
  753. *@li m: A mutable Tensor. Has the same type as "m" . \n
  754. *@par Third-party framework compatibility
  755. * Compatible with the TensorFlow operator ApplyAddSign.
  756. *
  757. * @par Restrictions:
  758. * Warning: THIS FUNCTION IS DEPRECATED. Please use ApplyAddSign instead.
  759. */
  760. REG_OP(ApplyAddSignD)
  761. .INPUT(var, TensorType::NumberType())
  762. .INPUT(m, TensorType::NumberType())
  763. .INPUT(lr, TensorType::NumberType())
  764. .INPUT(alpha, TensorType::NumberType())
  765. .INPUT(sign_decay, TensorType::NumberType())
  766. .INPUT(beta, TensorType::NumberType())
  767. .INPUT(grad, TensorType::NumberType())
  768. .OUTPUT(var, TensorType::NumberType())
  769. .OUTPUT(m, TensorType::NumberType())
  770. .ATTR(use_locking, Bool, false)
  771. .OP_END_FACTORY_REG(ApplyAddSignD)
  772. /**
  773. *@brief Updates "var" according to the centered RMSProp algorithm.
  774. * The centered RMSProp algorithm uses an estimate of the centered second moment
  775. * (i.e., the variance) for normalization, as opposed to regular RMSProp, which
  776. * uses the (uncentered) second moment. This often helps with training, but is
  777. * slightly more expensive in terms of computation and memory.
  778. *
  779. * t-1 mean previous period.
  780. * mg <- rho * mg{t-1} + (1-rho) * grad
  781. * ms <- rho * ms{t-1} + (1-rho) * grad * grad
  782. * mom <- momentum * mom{t-1} + lr * grad / sqrt(ms - mg * mg + epsilon)
  783. * var <- var - mom
  784. *
  785. *@attention Constraints:
  786. *@li in dense implementation of this algorithm, mg, ms, and mom will
  787. * update even if the grad is zero, but in this sparse implementation, mg, ms,
  788. * and mom will not update in iterations during which the grad is zero.
  789. *@li the input tensors must have the same shape.
  790. *
  791. *@par Inputs:
  792. *@li var: A mutable tensor. Should be from a Variable().
  793. *@li mg: A mutable tensor. Has the same type as "var".
  794. * Should be from a Variable().
  795. *@li ms: A mutable tensor. Has the same type as "var".
  796. * Should be from a Variable().
  797. *@li mom: A mutable tensor. Has the same type as "var".
  798. * Should be from a Variable().
  799. *@li lr: A scalar. Has the same type as "var".
  800. *@li rho: A scalar. Has the same type as "var".
  801. *@li momentum: A tensor. Has the same type as "var".
  802. *@li epsilon: A scalar. Has the same type as "var".
  803. *@li grad: A tensor for the gradient. Has the same type as "var".
  804. *
  805. *@par Attributes:
  806. * use_locking: An optional bool. Defaults to "False".
  807. * If "True", updating of the "var", "ms", and "mom" tensors is protected
  808. * by a lock; otherwise the behavior is undefined, but may exhibit less
  809. * contention.
  810. *
  811. *@par Outputs:
  812. * var: A mutable tensor. Has the same type as input "var".
  813. *
  814. *@par Third-party framework compatibility
  815. *Compatible with the TensorFlow operator ApplyCenteredRMSProp.
  816. *
  817. */
  818. REG_OP(ApplyCenteredRMSProp)
  819. .INPUT(var, TensorType::NumberType())
  820. .INPUT(mg, TensorType::NumberType())
  821. .INPUT(ms, TensorType::NumberType())
  822. .INPUT(mom, TensorType::NumberType())
  823. .INPUT(lr, TensorType::NumberType())
  824. .INPUT(rho, TensorType::NumberType())
  825. .INPUT(momentum, TensorType::NumberType())
  826. .INPUT(epsilon, TensorType::NumberType())
  827. .INPUT(grad, TensorType::NumberType())
  828. .OUTPUT(var, TensorType::NumberType())
  829. .ATTR(use_locking, Bool, false)
  830. .OP_END_FACTORY_REG(ApplyCenteredRMSProp)
  831. /**
  832. *@brief Updates "var" according to the centered RMSProp algorithm.
  833. * The centered RMSProp algorithm uses an estimate of the centered second moment
  834. * (i.e., the variance) for normalization, as opposed to regular RMSProp, which
  835. * uses the (uncentered) second moment. This often helps with training, but is
  836. * slightly more expensive in terms of computation and memory.
  837. *
  838. * t-1 mean previous period.
  839. * mg <- rho * mg{t-1} + (1-rho) * grad
  840. * ms <- rho * ms{t-1} + (1-rho) * grad * grad
  841. * mom <- momentum * mom{t-1} + lr * grad / sqrt(ms - mg * mg + epsilon)
  842. * var <- var - mom
  843. *
  844. *@attention Constraints:
  845. *@li in dense implementation of this algorithm, mg, ms, and mom will
  846. * update even if the grad is zero, but in this sparse implementation, mg, ms,
  847. * and mom will not update in iterations during which the grad is zero.
  848. *@li the input tensors must have the same shape.
  849. *
  850. *@par Inputs:
  851. *@li var: A mutable tensor. Should be from a Variable().
  852. *@li mg: A mutable tensor. Has the same type as "var".
  853. * Should be from a Variable().
  854. *@li ms: A mutable tensor. Has the same type as "var".
  855. * Should be from a Variable().
  856. *@li mom: A mutable tensor. Has the same type as "var".
  857. * Should be from a Variable().
  858. *@li lr: A scalar. Has the same type as "var".
  859. *@li rho: A scalar. Has the same type as "var".
  860. *@li momentum: A tensor. Has the same type as "var".
  861. *@li epsilon: A scalar. Has the same type as "var".
  862. *@li grad: A tensor for the gradient. Has the same type as "var".
  863. *
  864. *@par Attributes:
  865. * use_locking: An optional bool. Defaults to "False".
  866. * If "True", updating of the "var", "ms", and "mom" tensors is protected
  867. * by a lock; otherwise the behavior is undefined, but may exhibit less
  868. * contention.
  869. *
  870. *@par Outputs:
  871. *@li var: A mutable Tensor. Has the same type as "var".
  872. *@li mg: A mutable Tensor. Has the same type as "mg".
  873. *@li ms: A mutable Tensor. Has the same type as "ms".
  874. *@li mom: A mutable Tensor. Has the same type as "mom" . \n
  875. *@par Third-party framework compatibility
  876. *Compatible with the TensorFlow operator ApplyCenteredRMSPropD.
  877. *
  878. * @par Restrictions:
  879. * Warning: THIS FUNCTION IS DEPRECATED. Please use ApplyCenteredRMSProp instead.
  880. */
  881. REG_OP(ApplyCenteredRMSPropD)
  882. .INPUT(var, TensorType::NumberType())
  883. .INPUT(mg, TensorType::NumberType())
  884. .INPUT(ms, TensorType::NumberType())
  885. .INPUT(mom, TensorType::NumberType())
  886. .INPUT(lr, TensorType::NumberType())
  887. .INPUT(rho, TensorType::NumberType())
  888. .INPUT(momentum, TensorType::NumberType())
  889. .INPUT(epsilon, TensorType::NumberType())
  890. .INPUT(grad, TensorType::NumberType())
  891. .OUTPUT(var, TensorType::NumberType())
  892. .OUTPUT(mg, TensorType::NumberType())
  893. .OUTPUT(ms, TensorType::NumberType())
  894. .OUTPUT(mom, TensorType::NumberType())
  895. .ATTR(use_locking, Bool, false)
  896. .OP_END_FACTORY_REG(ApplyCenteredRMSPropD)
  897. /**
  898. *@brief Updates "var" by subtracting 'alpha' * 'delta' from it.
  899. * var -= delta * alpha
  900. *
  901. *@attention Constraints:
  902. * the input tensors must have the same shape.
  903. *
  904. *@par Inputs:
  905. *@li var: A mutable tensor. Should be from a Variable().
  906. *@li alpha: A scalar. Has the same type as "var".
  907. *@li delta: A tensor for the change. Has the same type as "var".
  908. *
  909. *@par Attributes:
  910. * use_locking: An optional bool. Defaults to "False".
  911. * If "True", updating of the "var" tensors is protected
  912. * by a lock; otherwise the behavior is undefined, but may exhibit less
  913. * contention.
  914. *
  915. *@par Outputs:
  916. * var: A mutable tensor. Has the same type as input "var".
  917. *
  918. *@par Third-party framework compatibility
  919. *Compatible with the TensorFlow operator ApplyGradientDescent.
  920. *
  921. */
  922. REG_OP(ApplyGradientDescent)
  923. .INPUT(var, TensorType::NumberType())
  924. .INPUT(alpha, TensorType::NumberType())
  925. .INPUT(delta, TensorType::NumberType())
  926. .OUTPUT(var, TensorType::NumberType())
  927. .ATTR(use_locking, Bool, false)
  928. .OP_END_FACTORY_REG(ApplyGradientDescent)
  929. /**
  930. *@brief Updates "var" according to the adagrad scheme.
  931. * accum += grad * grad
  932. * var -= lr * grad * (1 / sqrt(accum))
  933. *
  934. *@attention Constraints:
  935. * the input tensors must have the same shape.
  936. *
  937. *@par Inputs:
  938. *@li var: A mutable tensor. Should be from a Variable().
  939. *@li accum: A mutable tensor. Has the same type as "var".
  940. * Should be from a Variable().
  941. *@li lr: A scalar. Has the same type as "var".
  942. *@li grad: A tensor for the gradient. Has the same type as "var".
  943. *
  944. *@par Attributes:
  945. *@li update_slots: An optional bool. Defaults to "True". If "True", the calcution will be different as "False".
  946. *@li use_locking: An optional bool. Defaults to "False".
  947. * If "True", updating of the "var", "ms", and "mom" tensors is protected
  948. * by a lock; otherwise the behavior is undefined, but may exhibit less
  949. * contention.
  950. *
  951. *@par Outputs:
  952. * var: A mutable tensor. Has the same type as input "var".
  953. *
  954. *@par Third-party framework compatibility
  955. *Compatible with the TensorFlow operator ApplyAdagrad.
  956. *
  957. */
  958. REG_OP(ApplyAdagrad)
  959. .INPUT(var, TensorType::NumberType())
  960. .INPUT(accum, TensorType::NumberType())
  961. .INPUT(lr, TensorType::NumberType())
  962. .INPUT(grad, TensorType::NumberType())
  963. .OUTPUT(var, TensorType::NumberType())
  964. .ATTR(update_slots, Bool, true)
  965. .ATTR(use_locking, Bool, false)
  966. .OP_END_FACTORY_REG(ApplyAdagrad)
  967. /**
  968. *@brief Updates "var" according to the adagrad scheme.
  969. * accum += grad * grad
  970. * var -= lr * grad * (1 / sqrt(accum))
  971. *
  972. *@attention Constraints:
  973. * the input tensors must have the same shape.
  974. *
  975. *@par Inputs:
  976. *@li var: A mutable tensor. Should be from a Variable().
  977. *@li accum: A mutable tensor. Has the same type as "var".
  978. * Should be from a Variable().
  979. *@li lr: A scalar. Has the same type as "var".
  980. *@li grad: A tensor for the gradient. Has the same type as "var".
  981. *
  982. *@par Attributes:
  983. *@li update_slots: An optional bool. Defaults to "True". If "True", the calcution will be different as "False".
  984. *@li use_locking: An optional bool. Defaults to "False".
  985. * If "True", updating of the "var", "ms", and "mom" tensors is protected
  986. * by a lock; otherwise the behavior is undefined, but may exhibit less
  987. * contention.
  988. *
  989. *@par Outputs:
  990. *@li var: A mutable tensor. Has the same type as input "var".
  991. *@li accum: A mutable tensor. Has the same type as input "var".
  992. *
  993. *@par Third-party framework compatibility
  994. *Compatible with the TensorFlow operator ApplyAdagrad.
  995. *
  996. * @par Restrictions:
  997. * Warning: THIS FUNCTION IS DEPRECATED. Please use ApplyAdagrad instead.
  998. */
  999. REG_OP(ApplyAdagradD)
  1000. .INPUT(var, TensorType::NumberType())
  1001. .INPUT(accum, TensorType::NumberType())
  1002. .INPUT(lr, TensorType::NumberType())
  1003. .INPUT(grad, TensorType::NumberType())
  1004. .OUTPUT(var, TensorType::NumberType())
  1005. .OUTPUT(accum, TensorType::NumberType())
  1006. .ATTR(update_slots, Bool, true)
  1007. .ATTR(use_locking, Bool, false)
  1008. .OP_END_FACTORY_REG(ApplyAdagradD)
  1009. /**
  1010. * @brief Updates "var" according to the adagradv2 scheme.
  1011. * accum += grad * grad
  1012. * var -= lr * grad * (1 / sqrt(accum) + epsilon)
  1013. *
  1014. * @par Inputs:
  1015. * @li var: A mutable tensor. Must be one of the data types defined in
  1016. * TensorType::NumberType(). Should be from a Variable().
  1017. * @li accum: A mutable tensor. Has the same type as "var". Should be from a
  1018. * Variable().
  1019. * @li lr: A tensor for the learning rate. Has the same type as "var". Should be
  1020. * from a Variable().
  1021. * @li grad: A tensor for the gradient. Has the same type as "var". Should be
  1022. * from a Variable().
  1023. * @li epsilon: A scalar. Has the same type as "var".
  1024. *
  1025. * @par Attributes:
  1026. * @li update_slots: An optional bool. Defaults to "True".
  1027. * If "True", "accum" will be updated
  1028. * @li use_locking: An optional bool. Defaults to "False".
  1029. * If "True", updating of the "var" tensor is protected by a lock;
  1030. * otherwise the behavior is undefined, but may exhibit less contention.
  1031. *
  1032. * @par Outputs:
  1033. * var: A mutable tensor. Has the same type as input "var".
  1034. *
  1035. * @attention Constraints:
  1036. * The input tensors must have the same shape.
  1037. *
  1038. * @par Third-party framework compatibility
  1039. * Compatible with the TensorFlow operator ApplyAdagrad.
  1040. *
  1041. */
  1042. REG_OP(ApplyAdagradV2)
  1043. .INPUT(var, TensorType::NumberType())
  1044. .INPUT(accum, TensorType::NumberType())
  1045. .INPUT(lr, TensorType::NumberType())
  1046. .INPUT(epsilon, TensorType::NumberType())
  1047. .INPUT(grad, TensorType::NumberType())
  1048. .OUTPUT(var, TensorType::NumberType())
  1049. .ATTR(update_slots, Bool, true)
  1050. .ATTR(use_locking, Bool, false)
  1051. .OP_END_FACTORY_REG(ApplyAdagradV2)
  1052. /**
  1053. * @brief Updates "var" according to the adagradv2 scheme.
  1054. * accum += grad * grad
  1055. * var -= lr * grad * (1 / sqrt(accum) + epsilon)
  1056. *
  1057. * @par Inputs:
  1058. * @li var: A mutable tensor. Must be one of the data types defined in
  1059. * TensorType::NumberType(). Should be from a Variable().
  1060. * @li accum: A mutable tensor. Has the same type as "var". Should be from a
  1061. * Variable().
  1062. * @li lr: A tensor for the learning rate. Has the same type as "var". Should be
  1063. * from a Variable().
  1064. * @li grad: A tensor for the gradient. Has the same type as "var". Should be
  1065. * from a Variable().
  1066. *
  1067. * @par Attributes:
  1068. * @li epsilon: A scalar. Has the same type as "var".
  1069. * @li update_slots: An optional bool. Defaults to "True".
  1070. * If "True", "accum" will be updated
  1071. * @li use_locking: An optional bool. Defaults to "False".
  1072. * If "True", updating of the "var" tensor is protected by a lock;
  1073. * otherwise the behavior is undefined, but may exhibit less contention.
  1074. *
  1075. * @par Outputs:
  1076. * var: A mutable tensor. Has the same type as input "var".
  1077. *
  1078. * @attention Constraints:
  1079. * The input tensors must have the same shape.
  1080. *
  1081. * @par Third-party framework compatibility
  1082. * Compatible with the TensorFlow operator ApplyAdagrad.
  1083. *
  1084. *@par Restrictions:
  1085. *Warning: THIS FUNCTION IS DEPRECATED. Please use ApplyAdagradV2 instead.
  1086. */
  1087. REG_OP(ApplyAdagradV2D)
  1088. .INPUT(var, TensorType::NumberType())
  1089. .INPUT(accum, TensorType::NumberType())
  1090. .INPUT(lr, TensorType::NumberType())
  1091. .INPUT(grad, TensorType::NumberType())
  1092. .OUTPUT(var, TensorType::NumberType())
  1093. .OUTPUT(accum, TensorType::NumberType())
  1094. .REQUIRED_ATTR(epsilon, Float)
  1095. .ATTR(update_slots, Bool, true)
  1096. .ATTR(use_locking, Bool, false)
  1097. .OP_END_FACTORY_REG(ApplyAdagradV2D)
  1098. /**
  1099. *@brief Updates "var" according to the proximal adagrad scheme . \n
  1100. *@par Inputs:
  1101. *Eight inputs, including:
  1102. * @li var: A mutable Tensor. Must be one of the following types:
  1103. * TensorType::NumberType(). Should be a Variable Tensor.
  1104. * @li gradient_accumulator: A mutable Tensor. Must have the same
  1105. * type as "var". Should be a Variable Tensor.
  1106. * @li gradient_squared_accumulator: A mutable Tensor of the same type as "var".
  1107. * Should be a Variable Tensor.
  1108. * @li grad: A Tensor of the same type as "var", for the gradient.
  1109. * @li lr: A Tensor of the same type as "var".
  1110. * Scaling factor. Must be a scalar.
  1111. * @li l1: A Tensor of the same type as "var".
  1112. * L1 regulariation. Must be a scalar.
  1113. * @li l2: A Tensor of the same type as "var".
  1114. * L2 regulariation. Must be a scalar.
  1115. * @li global_step: A Tensor of type int32 or int64.
  1116. * Training step number. Must be a scalar . \n
  1117. *@par Attributes:
  1118. *use_locking: An optional bool. Defaults to "False".
  1119. * If "True", updating of the var and accum tensors will be
  1120. * protected by a lock; otherwise the behavior is undefined,
  1121. * but may exhibit less contention . \n
  1122. *@par Outputs:
  1123. *var: A mutable Tensor. Has the same type as "var" . \n
  1124. *@par Third-party framework compatibility
  1125. *Compatible with the TensorFlow operator ApplyAdagradDA.
  1126. */
  1127. REG_OP(ApplyAdagradDA)
  1128. .INPUT(var, TensorType::NumberType())
  1129. .INPUT(gradient_accumulator, TensorType::NumberType())
  1130. .INPUT(gradient_squared_accumulator, TensorType::NumberType())
  1131. .INPUT(grad, TensorType::NumberType())
  1132. .INPUT(lr, TensorType::NumberType())
  1133. .INPUT(l1, TensorType::NumberType())
  1134. .INPUT(l2, TensorType::NumberType())
  1135. .INPUT(global_step, TensorType({DT_INT32, DT_INT64}))
  1136. .OUTPUT(var, TensorType::NumberType())
  1137. .ATTR(use_locking, Bool, false)
  1138. .OP_END_FACTORY_REG(ApplyAdagradDA)
  1139. /**
  1140. *@brief Updates "var" according to the proximal adagrad scheme . \n
  1141. *@par Inputs:
  1142. *Eight inputs, including:
  1143. * @li var: A mutable Tensor. Must be one of the following types:
  1144. * TensorType::NumberType(). Should be a Variable Tensor.
  1145. * @li gradient_accumulator: A mutable Tensor. Must have the same
  1146. * type as "var". Should be a Variable Tensor.
  1147. * @li gradient_squared_accumulator: A mutable Tensor of the same type as "var".
  1148. * Should be a Variable Tensor.
  1149. * @li grad: A Tensor of the same type as "var", for the gradient.
  1150. * @li lr: A Tensor of the same type as "var".
  1151. * Scaling factor. Must be a scalar.
  1152. * @li l1: A Tensor of the same type as "var".
  1153. * L1 regulariation. Must be a scalar.
  1154. * @li l2: A Tensor of the same type as "var".
  1155. * L2 regulariation. Must be a scalar.
  1156. * @li global_step: A Tensor of type int32 or int64.
  1157. * Training step number. Must be a scalar . \n
  1158. *@par Attributes:
  1159. *use_locking: An optional bool. Defaults to "False".
  1160. * If "True", updating of the var and accum tensors will be
  1161. * protected by a lock; otherwise the behavior is undefined,
  1162. * but may exhibit less contention . \n
  1163. *@par Outputs:
  1164. *var: A mutable Tensor. Has the same type as "var".
  1165. *gradient_accumulator: A mutable Tensor. Has the same type as "var".
  1166. *gradient_squared_accumulator: A mutable Tensor. Has the same type as "var" . \n
  1167. *@par Third-party framework compatibility
  1168. *Compatible with the TensorFlow operator ApplyAdagradDA.
  1169. *
  1170. * @par Restrictions:
  1171. * Warning: THIS FUNCTION IS DEPRECATED. Please use ApplyAdagradDA instead.
  1172. */
  1173. REG_OP(ApplyAdagradDAD)
  1174. .INPUT(var, TensorType::NumberType())
  1175. .INPUT(gradient_accumulator, TensorType::NumberType())
  1176. .INPUT(gradient_squared_accumulator, TensorType::NumberType())
  1177. .INPUT(grad, TensorType::NumberType())
  1178. .INPUT(lr, TensorType::NumberType())
  1179. .INPUT(l1, TensorType::NumberType())
  1180. .INPUT(l2, TensorType::NumberType())
  1181. .INPUT(global_step, TensorType({DT_INT32, DT_INT64}))
  1182. .OUTPUT(var, TensorType::NumberType())
  1183. .OUTPUT(gradient_accumulator, TensorType::NumberType())
  1184. .OUTPUT(gradient_squared_accumulator, TensorType::NumberType())
  1185. .ATTR(use_locking, Bool, false)
  1186. .OP_END_FACTORY_REG(ApplyAdagradDAD)
  1187. /**
  1188. *@brief Returns the dimension index in the destination data format given the one in
  1189. * the source data format.
  1190. *
  1191. *@par Inputs:
  1192. * x: A tensor of type int32 or int64.
  1193. * A Tensor with each element as a dimension index in source data format.
  1194. * Must be in the range [-4, 4).
  1195. *
  1196. *@par Attributes:
  1197. *@li src_format: An optional string. Defaults to NHWC.
  1198. * source data format. Must of length 4.
  1199. *@li dst_format: An optional string. Defaults to NCHW.
  1200. * destination data format. Must of length 4.
  1201. *
  1202. *@par Outputs:
  1203. * y: A tensor. Has the same type as "x". Must be in the range [0, 4).
  1204. *
  1205. *@par Third-party framework compatibility
  1206. *Compatible with the TensorFlow operator DataFormatDimMap.
  1207. *
  1208. */
  1209. REG_OP(DataFormatDimMap)
  1210. .INPUT(x, TensorType::IndexNumberType())
  1211. .ATTR(src_format, String, "NHWC")
  1212. .ATTR(dst_format, String, "NCHW")
  1213. .OUTPUT(y, TensorType::IndexNumberType())
  1214. .OP_END_FACTORY_REG(DataFormatDimMap)
  1215. /**
  1216. * @brief Implements stochastic gradient descent (optionally with momentum).
  1217. * Nesterov momentum is based on the formula from
  1218. * On the importance of initialization and momentum in deep learning.
  1219. * @par Inputs:
  1220. * @li parameters: A mutable tensor of type float16 or float32.
  1221. * Specifies the iterable of parameters to optimize or dicts defining parameter
  1222. * groups.
  1223. * @li gradient: A tensor of type float16 or float32.
  1224. * Specifies the gradient of training step.
  1225. * @li learning_rate: A tensor of type float16 or float32.
  1226. * Specifies the learing_rate of training step.
  1227. * @li accum: A tensor of type float16 or float32.
  1228. * Specifies the velocity of training step.
  1229. * @li momentum: A tensor of type float16 or float32.
  1230. * Specifies the momentum factor.
  1231. * @li stat: A tensor of type float16 or float32.
  1232. * Specifies the status representing the first step or not . \n
  1233. * @par Attributes:
  1234. * @li dampening: An optional float, specifying the dampening for momentum.
  1235. * Defaults to "0.0".
  1236. * @li weight_decay: An optional float, specifying the L2 penalty. Defaults to
  1237. * "0.0".
  1238. * @li nesterov: An optional bool, specifying whether to enable Nesterov
  1239. * momentum. Defaults to "False" . \n
  1240. * @par Outputs:
  1241. * parameters: A mutable tensor same as input "parameters" . \n
  1242. * @see ApplyMomentum()
  1243. * @par Third-party framework compatibility
  1244. * @li Compatible with the PyTorch operator SGD.
  1245. */
  1246. REG_OP(SGD)
  1247. .INPUT(parameters, TensorType(DT_FLOAT, DT_FLOAT16))
  1248. .INPUT(gradient, TensorType(DT_FLOAT, DT_FLOAT16))
  1249. .INPUT(learning_rate, TensorType(DT_FLOAT, DT_FLOAT16))
  1250. .INPUT(accum, TensorType(DT_FLOAT, DT_FLOAT16))
  1251. .INPUT(momentum, TensorType(DT_FLOAT, DT_FLOAT16))
  1252. .INPUT(stat, TensorType(DT_FLOAT, DT_FLOAT16))
  1253. .OUTPUT(parameters, TensorType(DT_FLOAT, DT_FLOAT16))
  1254. .ATTR(dampening, Float, 0.0)
  1255. .ATTR(weight_decay, Float, 0.0)
  1256. .ATTR(nesterov, Bool, false)
  1257. .OP_END_FACTORY_REG(SGD)
  1258. /**
  1259. * @brief Updates "var" according to the RMSProp algorithm.
  1260. * mean_square = decay * mean_square + (1-decay) * gradient ** 2
  1261. * Delta = learning_rate * gradient / sqrt(mean_square + epsilon)
  1262. * ms <- rho * ms_{t-1} + (1-rho) * grad * grad
  1263. * mom <- momentum * mom_{t-1} + lr * grad / sqrt(ms + epsilon)
  1264. * var <- var - mom
  1265. *
  1266. * @par Inputs:
  1267. * @li var: A mutable tensor. Must be one of the data types defined in
  1268. * TensorType::NumberType(). Should be from a Variable().
  1269. * @li ms: A mutable tensor. Must have the same type as "var". Should be from a
  1270. * Variable().
  1271. * @li mom: A mutable tensor. Must have the same type as "var". Should be from a
  1272. * Variable().
  1273. * @li lr: A scalar. Must have the same type as "var".
  1274. * @li rho: A scalar. Must have the same type as "var".
  1275. * @li momentum: A scalar. Must have the same type as "var".
  1276. * @li epsilon: A scalar. Must have the same type as "var".
  1277. * @li grad: A tensor, specifying the gradient. Must have the same type as "var".
  1278. *
  1279. * @par Attributes:
  1280. * use_locking: An optional "bool". Defaults to "False". If "True", updating of
  1281. * the "var", "ms", and "mom" tensors will be protected by a lock; otherwise the
  1282. * behavior is undefined, but may exhibit less contention.
  1283. *
  1284. * @par Outputs:
  1285. * var: A mutable tensor. Has the same type as input "var".
  1286. *
  1287. * @attention Constraints:
  1288. * @li Note that in dense implementation of this algorithm, "ms" and "mom" will
  1289. * update even if "grad" is 0, but in this sparse implementation, "ms" and "mom"
  1290. * will not update in iterations during which "grad" is 0.
  1291. * @li The input tensors "var", "ms", "mom" and "grad" must have the same shape.
  1292. *
  1293. * @par Third-party framework compatibility
  1294. * @li Compatible with the TensorFlow operator ApplyRMSProp.
  1295. */
  1296. REG_OP(ApplyRMSProp)
  1297. .INPUT(var, TensorType::NumberType())
  1298. .INPUT(ms, TensorType::NumberType())
  1299. .INPUT(mom, TensorType::NumberType())
  1300. .INPUT(lr, TensorType::NumberType())
  1301. .INPUT(rho, TensorType::NumberType())
  1302. .INPUT(momentum, TensorType::NumberType())
  1303. .INPUT(epsilon, TensorType::NumberType())
  1304. .INPUT(grad, TensorType::NumberType())
  1305. .OUTPUT(var, TensorType::NumberType())
  1306. .ATTR(use_locking, Bool, false)
  1307. .OP_END_FACTORY_REG(ApplyRMSProp)
  1308. /**
  1309. * @brief Updates "var" according to the RMSProp algorithm, a const input will be
  1310. * considered as an attribute.
  1311. * mean_square = decay * mean_square + (1-decay) * gradient ** 2
  1312. * Delta = learning_rate * gradient / sqrt(mean_square + epsilon)
  1313. * ms <- rho * ms_{t-1} + (1-rho) * grad * grad
  1314. * mom <- momentum * mom_{t-1} + lr * grad / sqrt(ms + epsilon)
  1315. * var <- var - mom
  1316. *
  1317. * @par Inputs:
  1318. * @li var: A mutable tensor. Must be one of the data types defined in
  1319. * TensorType::NumberType(). Should be from a Variable().
  1320. * @li ms: A mutable tensor. Must have the same type as "var". Should be from a
  1321. * Variable().
  1322. * @li mom: A mutable tensor. Must have the same type as "var". Should be from a
  1323. * Variable().
  1324. * @li lr: A scalar. Must have the same type as "var".
  1325. * @li grad: A tensor, specifying the gradient. Must have the same type as "var".
  1326. *
  1327. * @par Attributes:
  1328. * @li use_locking: An optional "bool". Defaults to "False". If "True", updating
  1329. * of the "var", "ms", and "mom" tensors will be protected by a lock;
  1330. * otherwise the behavior is undefined, but may exhibit less contention.
  1331. * @li rho: A required scalar. Must have the same type as "var".
  1332. * @li momentum: A required scalar. Must have the same type as "var".
  1333. * @li epsilon: A required scalar. Must have the same type as "var".
  1334. *
  1335. * @par Outputs:
  1336. * var: A mutable tensor. Must have the same type as input "var".
  1337. *
  1338. * @attention Constraints:
  1339. * @li Note that in dense implementation of this algorithm, "ms" and "mom" will
  1340. * update even if "grad" is 0, but in this sparse implementation, "ms" and "mom"
  1341. * will not update in iterations during which "grad" is 0.
  1342. * @li The input tensors "var", "ms", "mom" and "grad" must have the same shape.
  1343. *
  1344. * @par Third-party framework compatibility
  1345. * @li Compatible with the TensorFlow operator ApplyRMSProp.
  1346. *
  1347. *@par Restrictions:
  1348. *Warning: THIS FUNCTION IS DEPRECATED. Please use ApplyRMSProp instead.
  1349. */
  1350. REG_OP(ApplyRMSPropD)
  1351. .INPUT(var, TensorType::NumberType())
  1352. .INPUT(ms, TensorType::NumberType())
  1353. .INPUT(mom, TensorType::NumberType())
  1354. .INPUT(lr, TensorType::NumberType())
  1355. .INPUT(grad, TensorType::NumberType())
  1356. .OUTPUT(var, TensorType::NumberType())
  1357. .OUTPUT(ms, TensorType::NumberType())
  1358. .OUTPUT(mom, TensorType::NumberType())
  1359. .REQUIRED_ATTR(rho, Float)
  1360. .REQUIRED_ATTR(momentum, Float)
  1361. .REQUIRED_ATTR(epsilon, Float)
  1362. .ATTR(use_locking, Bool, false)
  1363. .OP_END_FACTORY_REG(ApplyRMSPropD)
  1364. /**
  1365. *@brief Update "var" and "accum" according to FOBOS with Adagrad learning rate . \n
  1366. *@par Inputs:
  1367. *Six inputs, including:
  1368. * @li var: A mutable Tensor of type TensorType::NumberType().
  1369. * Should be from a Variable().
  1370. * @li accum: A mutable Tensor of the same type as "var". Should be from a Variable().
  1371. * @li lr: A Tensor of the same type as "var", for the scaling factor. Must be a scalar.
  1372. * @li l1: A Tensor of the same type as "var", for L1 regulariation. Must be a scalar.
  1373. * @li l2: A Tensor of the same type as "var", for L2 regulariation. Must be a scalar.
  1374. * @li grad: A Tensor of the same type as "var", for the gradient . \n
  1375. *@par Attributes:
  1376. *use_locking: An optional bool. Defaults to "False". If "True", updating of the "var" and "accum" *tensors will be protected by a lock; otherwise the behavior is undefined, but may exhibit less *contention . \n
  1377. *@par Outputs:
  1378. *var: A mutable tensor. Must have the same type as input "var" . \n
  1379. *@par Third-party framework compatibility
  1380. *Compatible with the TensorFlow operator ApplyProximalAdagrad.
  1381. */
  1382. REG_OP(ApplyProximalAdagrad)
  1383. .INPUT(var, TensorType::NumberType())
  1384. .INPUT(accum, TensorType::NumberType())
  1385. .INPUT(lr, TensorType::NumberType())
  1386. .INPUT(l1, TensorType::NumberType())
  1387. .INPUT(l2, TensorType::NumberType())
  1388. .INPUT(grad, TensorType::NumberType())
  1389. .OUTPUT(var, TensorType::NumberType())
  1390. .ATTR(use_locking, Bool, false)
  1391. .OP_END_FACTORY_REG(ApplyProximalAdagrad)
  1392. /**
  1393. *@brief Update "var" and "accum" according to FOBOS with Adagrad learning rate . \n
  1394. *@par Inputs:
  1395. *Six inputs, including:
  1396. * @li var: A mutable Tensor of type TensorType::NumberType().
  1397. * Should be from a Variable().
  1398. * @li accum: A mutable Tensor of the same type as "var". Should be from a Variable().
  1399. * @li lr: A Tensor of the same type as "var", for the scaling factor. Must be a scalar.
  1400. * @li l1: A Tensor of the same type as "var", for L1 regulariation. Must be a scalar.
  1401. * @li l2: A Tensor of the same type as "var", for L2 regulariation. Must be a scalar.
  1402. * @li grad: A Tensor of the same type as "var", for the gradient . \n
  1403. *@par Attributes:
  1404. *use_locking: An optional bool. Defaults to "False". If "True", updating of the "var" and "accum" *tensors will be protected by a lock; otherwise the behavior is undefined, but may exhibit less *contention . \n
  1405. *@par Outputs:
  1406. * @li var: A mutable Tensor. Has the same type as "var".
  1407. * @li accum: A mutable Tensor. Has the same type as "var" . \n
  1408. *@par Third-party framework compatibility
  1409. *Compatible with the TensorFlow operator ApplyProximalAdagradD.
  1410. *
  1411. * @par Restrictions:
  1412. * Warning: THIS FUNCTION IS DEPRECATED. Please use ApplyProximalAdagrad instead.
  1413. */
  1414. REG_OP(ApplyProximalAdagradD)
  1415. .INPUT(var, TensorType::NumberType())
  1416. .INPUT(accum, TensorType::NumberType())
  1417. .INPUT(lr, TensorType::NumberType())
  1418. .INPUT(l1, TensorType::NumberType())
  1419. .INPUT(l2, TensorType::NumberType())
  1420. .INPUT(grad, TensorType::NumberType())
  1421. .OUTPUT(var, TensorType::NumberType())
  1422. .OUTPUT(accum, TensorType::NumberType())
  1423. .ATTR(use_locking, Bool, false)
  1424. .OP_END_FACTORY_REG(ApplyProximalAdagradD)
  1425. /**
  1426. *@brief Updates entries in 'var' and 'accum' according to the Proximal Adagrad algorithm.
  1427. * Compared with op ApplyProximalAdagrad, an additional index tensor is input,
  1428. * Only the indices into the first dimensions of "var" and "accum" are updated . \n
  1429. *@par Inputs:
  1430. * Seven inputs, including:
  1431. * @li var: A mutable Tensor.
  1432. * TensorType::NumberType(). Should be a Variable Tensor.
  1433. * @li accum: A mutable Tensor of the same type as "var".
  1434. * Should be a Variable Tensor. Should be greater than or equal to zero.
  1435. * Accum and grad cannot be equal to zero at the same time.
  1436. * @li lr: A Tensor of the same type as "var".
  1437. * Scaling factor. Must be a scalar. Should be greater than zero.
  1438. * @li l1: A Tensor of the same type as "var".
  1439. * L1 regulariation. Must be a scalar. Should be greater than or equal to zero.
  1440. * @li l2: A Tensor of the same type as "var".
  1441. * L2 regulariation. Must be a scalar. Should be greater than or equal to zero.
  1442. * @li grad: A Tensor. Has the same type as "var".
  1443. * The gradient.
  1444. * @li indices: A vector of indices into the first dimension of "var" and "accum".
  1445. * TensorType::IndexNumberType(). Can contain duplicate values . \n
  1446. *@par Attributes:
  1447. *use_locking: An optional bool. Defaults to "False".
  1448. * If "True", updating of the var and accum tensors will be protected by a lock;
  1449. * If "False", the behavior is undefined, but may exhibit less contention.
  1450. *@par Outputs:
  1451. *var: A mutable Tensor. Has the same type as "var" . \n
  1452. *@par Third-party framework compatibility
  1453. *Compatible with the TensorFlow operator SparseApplyProximalAdagrad.
  1454. */
  1455. REG_OP(SparseApplyProximalAdagrad)
  1456. .INPUT(var, TensorType::NumberType())
  1457. .INPUT(accum, TensorType::NumberType())
  1458. .INPUT(lr, TensorType::NumberType())
  1459. .INPUT(l1, TensorType::NumberType())
  1460. .INPUT(l2, TensorType::NumberType())
  1461. .INPUT(grad, TensorType::NumberType())
  1462. .INPUT(indices, TensorType::IndexNumberType())
  1463. .OUTPUT(var, TensorType::NumberType())
  1464. .ATTR(use_locking, Bool, false)
  1465. .OP_END_FACTORY_REG(SparseApplyProximalAdagrad)
  1466. /**
  1467. *@brief Updates entries in 'var' and 'accum' according to the Proximal Adagrad algorithm.\ n
  1468. * Compared with op ApplyProximalAdagrad, an additional index tensor is input,
  1469. * Only the indices into the first dimensions of "var" and "accum" are updated . \n
  1470. *@par Inputs:
  1471. * Seven inputs, including:
  1472. * @li var: A mutable Tensor.
  1473. * TensorType::NumberType(). Should be a Variable Tensor.
  1474. * @li accum: A mutable Tensor of the same type as "var".
  1475. * Should be a Variable Tensor. Should be greater than or equal to zero.
  1476. * Accum and grad cannot be equal to zero at the same time.
  1477. * @li lr: A Tensor of the same type as "var".
  1478. * Scaling factor. Must be a scalar. Should be greater than zero.
  1479. * @li l1: A Tensor of the same type as "var".
  1480. * L1 regulariation. Must be a scalar. Should be greater than or equal to zero.
  1481. * @li l2: A Tensor of the same type as "var".
  1482. * L2 regulariation. Must be a scalar. Should be greater than or equal to zero.
  1483. * @li grad: A Tensor. Has the same type as "var".
  1484. * The gradient.
  1485. * @li indices: A vector of indices into the first dimension of "var" and "accum".
  1486. * TensorType::IndexNumberType(). Can contain duplicate values . \n
  1487. *@par Attributes:
  1488. *use_locking: An optional bool. Defaults to "False".
  1489. * If "True", updating of the var and accum tensors will be protected by a lock;
  1490. * If "False", the behavior is undefined, but may exhibit less contention . \n
  1491. *@par Outputs:
  1492. *@li var: A mutable Tensor. Has the same type as "var".
  1493. *@li accum: A mutable Tensor. Has the same type as "var" . \n
  1494. *@par Third-party framework compatibility
  1495. *Compatible with the TensorFlow operator SparseApplyProximalAdagrad.
  1496. * @par Restrictions:
  1497. * Warning: THIS FUNCTION IS DEPRECATED. Please use SparseApplyProximalAdagrad instead.
  1498. */
  1499. REG_OP(SparseApplyProximalAdagradD)
  1500. .INPUT(var, TensorType::NumberType())
  1501. .INPUT(accum, TensorType::NumberType())
  1502. .INPUT(lr, TensorType::NumberType())
  1503. .INPUT(l1, TensorType::NumberType())
  1504. .INPUT(l2, TensorType::NumberType())
  1505. .INPUT(grad, TensorType::NumberType())
  1506. .INPUT(indices, TensorType::IndexNumberType())
  1507. .OUTPUT(var, TensorType::NumberType())
  1508. .OUTPUT(accum, TensorType::NumberType())
  1509. .ATTR(use_locking, Bool, false)
  1510. .OP_END_FACTORY_REG(SparseApplyProximalAdagradD)
  1511. /**
  1512. *@brief Updates "var" according to the Ftrl-proximal scheme . \n
  1513. *@par Inputs:
  1514. *Eight inputs, including:
  1515. * @li var: A mutable Tensor. Must be of type TensorType::NumberType().
  1516. * Should be a Variable Tensor.
  1517. * @li accum: A mutable Tensor of the same type as "var".
  1518. * Should be a Variable Tensor.
  1519. * @li linear: A mutable Tensor of the same type as "var".
  1520. * Should be a Variable Tensor.
  1521. * @li grad: A Tensor of the same type as "var", for the gradient.
  1522. * @li lr: A Tensor of the same type as "var", for the scaling factor. Must be a scalar.
  1523. * @li l1: A Tensor of the same type as "var", for L1 regulariation. Must be a scalar.
  1524. * @li l2: A Tensor of the same type as "var", for L2 regulariation. Must be a scalar.
  1525. * @li lr_power: A Tensor of the same type as "var", for the scaling factor. Must be a scalar . \n
  1526. *@par Attributes:
  1527. *use_locking: An optional bool. Defaults to "False".
  1528. * If "True", updating of the "var" and "accum" tensors will be
  1529. * protected by a lock; otherwise the behavior is undefined,
  1530. * but may exhibit less contention . \n
  1531. *@par Outputs:
  1532. *var: A mutable Tensor. Has the same type as "var" . \n
  1533. *@par Third-party framework compatibility
  1534. *Compatible with the TensorFlow operator ApplyFtrl.
  1535. */
  1536. REG_OP(ApplyFtrl)
  1537. .INPUT(var, TensorType::NumberType())
  1538. .INPUT(accum, TensorType::NumberType())
  1539. .INPUT(linear, TensorType::NumberType())
  1540. .INPUT(grad, TensorType::NumberType())
  1541. .INPUT(lr, TensorType::NumberType())
  1542. .INPUT(l1, TensorType::NumberType())
  1543. .INPUT(l2, TensorType::NumberType())
  1544. .INPUT(lr_power, TensorType::NumberType())
  1545. .OUTPUT(var, TensorType::NumberType())
  1546. .ATTR(use_locking, Bool, false)
  1547. .OP_END_FACTORY_REG(ApplyFtrl)
  1548. /**
  1549. *@brief Updates "var" according to the Ftrl-proximal scheme . \n
  1550. *@par Inputs:
  1551. *Eight inputs, including:
  1552. * @li var: A mutable Tensor. Must be of type TensorType::NumberType().
  1553. * Should be a Variable Tensor.
  1554. * @li accum: A mutable Tensor of the same type as "var".
  1555. * Should be a Variable Tensor.
  1556. * @li linear: A mutable Tensor of the same type as "var".
  1557. * Should be a Variable Tensor.
  1558. * @li grad: A Tensor of the same type as "var", for the gradient.
  1559. * @li lr: A Tensor of the same type as "var", for the scaling factor. Must be a scalar.
  1560. * @li l1: A Tensor of the same type as "var", for L1 regulariation. Must be a scalar.
  1561. * @li l2: A Tensor of the same type as "var", for L2 regulariation. Must be a scalar.
  1562. * @li lr_power: A Tensor of the same type as "var", for the scaling factor. Must be a scalar . \n
  1563. *@par Attributes:
  1564. *use_locking: An optional bool. Defaults to "False".
  1565. * If "True", updating of the "var" and "accum" tensors will be
  1566. * protected by a lock; otherwise the behavior is undefined,
  1567. * but may exhibit less contention . \n
  1568. *@par Outputs:
  1569. *@li var: A mutable Tensor. Has the same type as "var".
  1570. *@li accum: A mutable Tensor. Has the same type as "accum".
  1571. *@li linear: A mutable Tensor. Has the same type as "linear" . \n
  1572. *@par Third-party framework compatibility
  1573. *Compatible with the TensorFlow operator ApplyFtrl.
  1574. *
  1575. * @par Restrictions:
  1576. * Warning: THIS FUNCTION IS DEPRECATED. Please use ApplyFtrl instead.
  1577. */
  1578. REG_OP(ApplyFtrlD)
  1579. .INPUT(var, TensorType::NumberType())
  1580. .INPUT(accum, TensorType::NumberType())
  1581. .INPUT(linear, TensorType::NumberType())
  1582. .INPUT(grad, TensorType::NumberType())
  1583. .INPUT(lr, TensorType::NumberType())
  1584. .INPUT(l1, TensorType::NumberType())
  1585. .INPUT(l2, TensorType::NumberType())
  1586. .INPUT(lr_power, TensorType::NumberType())
  1587. .OUTPUT(var, TensorType::NumberType())
  1588. .OUTPUT(accum, TensorType::NumberType())
  1589. .OUTPUT(linear, TensorType::NumberType())
  1590. .ATTR(use_locking, Bool, false)
  1591. .OP_END_FACTORY_REG(ApplyFtrlD)
  1592. /**
  1593. *@brief Update "var" according to the Ftrl-proximal scheme . \n
  1594. *@par Inputs:
  1595. *Nine inputs, including:
  1596. * @li var: A mutable Tensor. Must be of type TensorType::NumberType().
  1597. * Should be a Variable Tensor.
  1598. * @li accum: A mutable Tensor of the same type as "var".
  1599. * Should be a Variable Tensor.
  1600. * @li linear: A mutable Tensor of the same type as "var".
  1601. * Should be a Variable Tensor.
  1602. * @li grad: A Tensor of the same type as "var", for the gradient.
  1603. * @li lr: A Tensor of the same type as "var", for the scaling factor. Must be a scalar.
  1604. * @li l1: A Tensor of the same type as "var", for L1 regulariation. Must be a scalar.
  1605. * @li l2: A Tensor of the same type as "var", for L2 regulariation. Must be a scalar.
  1606. * @li l2_shrinkage: A Tensor of the same type as "var".
  1607. * @li lr_power: A Tensor of the same type as "var", for the scaling factor. Must be a scalar . \n
  1608. *@par Attributes:
  1609. *use_locking: An optional bool. Defaults to "False".
  1610. * If "True", updating of the "var" and "accum" tensors will be
  1611. * protected by a lock; otherwise the behavior is undefined,
  1612. * but may exhibit less contention . \n
  1613. *@par Outputs:
  1614. *var: A mutable Tensor. Has the same type as "var" . \n
  1615. *@par Third-party framework compatibility
  1616. *Compatible with the TensorFlow operator ApplyFtrlV2.
  1617. */
  1618. REG_OP(ApplyFtrlV2)
  1619. .INPUT(var, TensorType::NumberType())
  1620. .INPUT(accum, TensorType::NumberType())
  1621. .INPUT(linear, TensorType::NumberType())
  1622. .INPUT(grad, TensorType::NumberType())
  1623. .INPUT(lr, TensorType::NumberType())
  1624. .INPUT(l1, TensorType::NumberType())
  1625. .INPUT(l2, TensorType::NumberType())
  1626. .INPUT(l2_shrinkage, TensorType::NumberType())
  1627. .INPUT(lr_power, TensorType::NumberType())
  1628. .OUTPUT(var, TensorType::NumberType())
  1629. .ATTR(use_locking, Bool, false)
  1630. .OP_END_FACTORY_REG(ApplyFtrlV2)
  1631. /**
  1632. *@brief Update "var" according to the Ftrl-proximal scheme . \n
  1633. *@par Inputs:
  1634. *Nine inputs, including:
  1635. * @li var: A mutable Tensor. Must be of type TensorType::NumberType().
  1636. * Should be a Variable Tensor.
  1637. * @li accum: A mutable Tensor of the same type as "var".
  1638. * Should be a Variable Tensor.
  1639. * @li linear: A mutable Tensor of the same type as "var".
  1640. * Should be a Variable Tensor.
  1641. * @li grad: A Tensor of the same type as "var", for the gradient.
  1642. * @li lr: A Tensor of the same type as "var", for the scaling factor. Must be a scalar.
  1643. * @li l1: A Tensor of the same type as "var", for L1 regulariation. Must be a scalar.
  1644. * @li l2: A Tensor of the same type as "var", for L2 regulariation. Must be a scalar.
  1645. * @li l2_shrinkage: A Tensor of the same type as "var".
  1646. * @li lr_power: A Tensor of the same type as "var", for the scaling factor. Must be a scalar . \n
  1647. *@par Attributes:
  1648. *use_locking: An optional bool. Defaults to "False".
  1649. * If "True", updating of the "var" and "accum" tensors will be
  1650. * protected by a lock; otherwise the behavior is undefined,
  1651. * but may exhibit less contention . \n
  1652. *@par Outputs:
  1653. *var: A mutable Tensor. Has the same type as "var".
  1654. *accum: A mutable Tensor. Has the same type as "accum".
  1655. *linear: A mutable Tensor. Has the same type as "linear" . \n
  1656. *@par Third-party framework compatibility
  1657. *Compatible with the TensorFlow operator ApplyFtrlV2.
  1658. *
  1659. * @par Restrictions:
  1660. * Warning: THIS FUNCTION IS DEPRECATED. Please use ApplyFtrlV2 instead.
  1661. */
  1662. REG_OP(ApplyFtrlV2D)
  1663. .INPUT(var, TensorType::NumberType())
  1664. .INPUT(accum, TensorType::NumberType())
  1665. .INPUT(linear, TensorType::NumberType())
  1666. .INPUT(grad, TensorType::NumberType())
  1667. .INPUT(lr, TensorType::NumberType())
  1668. .INPUT(l1, TensorType::NumberType())
  1669. .INPUT(l2, TensorType::NumberType())
  1670. .INPUT(l2_shrinkage, TensorType::NumberType())
  1671. .INPUT(lr_power, TensorType::NumberType())
  1672. .OUTPUT(var, TensorType::NumberType())
  1673. .OUTPUT(accum, TensorType::NumberType())
  1674. .OUTPUT(linear, TensorType::NumberType())
  1675. .ATTR(use_locking, Bool, false)
  1676. .OP_END_FACTORY_REG(ApplyFtrlV2D)
  1677. /**
  1678. *@brief Updates "var" according to the Adam algorithm.
  1679. * lr_t <- text{learning\_rate} * sqrt{1 - beta_2^t} / (1 - beta_1^t)
  1680. * m_t <- beta_1 * m_{t-1} + (1 - beta_1) * g
  1681. * v_t <- max(beta2 * v{t-1}, abs(g))
  1682. * variable <- variable - lr_t * m_t / (sqrt{v_t} + epsilon)
  1683. *
  1684. *@attention Constraints:
  1685. * *The input tensors must have the same shape.*
  1686. *
  1687. *@par Inputs:
  1688. *@li var: A mutable Tensor of the type TensorType::NumberType().
  1689. * Should be from a Variable().
  1690. *@li m: A mutable Tensor of the same type as "var".
  1691. * Should be from a Variable().
  1692. *@li v: A mutable Tensor of the same type as "var".
  1693. * Should be from a Variable().
  1694. *@li beta1_power: A scalar of the same type as "var".
  1695. *@li beta2_power: A scalar of the same type as "var".
  1696. *@li lr: learning_rate. A scalar of the same type as "var".
  1697. *@li beta1: A scalar of the same type as "var".
  1698. *@li beta2: A scalar of the same type as "var".
  1699. *@li epsilon: A scalar of the same type as "var".
  1700. *@li grad: A Tensor of the same type as "var", for the gradient.
  1701. *
  1702. *@par Attributes:
  1703. *@li use_locking: An optional bool. Defaults to "False".
  1704. * If "True", updating of the "var", m", and "v" tensors will be protected
  1705. * by a lock; otherwise the behavior is undefined, but may exhibit less
  1706. * contention.
  1707. *@li use_nesterov: An optional bool. Defaults to "False".
  1708. If "True", uses the nesterov update.
  1709. *
  1710. *@par Outputs:
  1711. * var: A mutable Tensor. Has the same type as intput "var" . \n
  1712. *@par Third-party framework compatibility
  1713. *Compatible with the TensorFlow operator ApplyAdam.
  1714. */
  1715. REG_OP(ApplyAdam)
  1716. .INPUT(var, TensorType::NumberType())
  1717. .INPUT(m, TensorType::NumberType())
  1718. .INPUT(v, TensorType::NumberType())
  1719. .INPUT(beta1_power, TensorType::NumberType())
  1720. .INPUT(beta2_power, TensorType::NumberType())
  1721. .INPUT(lr, TensorType::NumberType())
  1722. .INPUT(beta1, TensorType::NumberType())
  1723. .INPUT(beta2, TensorType::NumberType())
  1724. .INPUT(epsilon, TensorType::NumberType())
  1725. .INPUT(grad, TensorType::NumberType())
  1726. .OUTPUT(var, TensorType::NumberType())
  1727. .ATTR(use_locking, Bool, false)
  1728. .ATTR(use_nesterov, Bool, false)
  1729. .OP_END_FACTORY_REG(ApplyAdam)
  1730. /**
  1731. *@brief Updates "var" according to the Adam algorithm.
  1732. * lr_t <- text{learning\_rate} * sqrt{1 - beta_2^t} / (1 - beta_1^t)
  1733. * m_t <- beta_1 * m_{t-1} + (1 - beta_1) * g
  1734. * v_t <- max(beta2 * v{t-1}, abs(g))
  1735. * variable <- variable - lr_t * m_t / (sqrt{v_t} + epsilon)
  1736. *
  1737. *@attention Constraints:
  1738. * *The input tensors must have the same shape.*
  1739. *
  1740. *@par Inputs:
  1741. *@li var: A mutable Tensor of the type TensorType::NumberType().
  1742. * Should be from a Variable().
  1743. *@li m: A mutable Tensor of the same type as "var".
  1744. * Should be from a Variable().
  1745. *@li v: A mutable Tensor of the same type as "var".
  1746. * Should be from a Variable().
  1747. *@li beta1_power: A scalar of the same type as "var".
  1748. *@li beta2_power: A scalar of the same type as "var".
  1749. *@li lr: learning_rate. A scalar of the same type as "var".
  1750. *@li beta1: A scalar of the same type as "var".
  1751. *@li beta2: A scalar of the same type as "var".
  1752. *@li epsilon: A scalar of the same type as "var".
  1753. *@li grad: A Tensor of the same type as "var", for the gradient.
  1754. *
  1755. *@par Attributes:
  1756. *@li use_locking: An optional bool. Defaults to "False".
  1757. * If "True", updating of the "var", m", and "v" tensors will be protected
  1758. * by a lock; otherwise the behavior is undefined, but may exhibit less
  1759. * contention.
  1760. *@li use_nesterov: An optional bool. Defaults to "False".
  1761. If "True", uses the nesterov update.
  1762. *
  1763. *@par Outputs:
  1764. *@li var: A mutable tensor. Has the same type as input "var".
  1765. *@li m: A mutable tensor. Has the same type as input "m".
  1766. *@li v: A mutable tensor. Has the same type as input "v" . \n
  1767. *@par Third-party framework compatibility
  1768. *Compatible with the TensorFlow operator ApplyAdam.
  1769. *
  1770. * @par Restrictions:
  1771. * Warning: THIS FUNCTION IS DEPRECATED. Please use ApplyAdam instead.
  1772. */
  1773. REG_OP(ApplyAdamD)
  1774. .INPUT(var, TensorType::NumberType())
  1775. .INPUT(m, TensorType::NumberType())
  1776. .INPUT(v, TensorType::NumberType())
  1777. .INPUT(beta1_power, TensorType::NumberType())
  1778. .INPUT(beta2_power, TensorType::NumberType())
  1779. .INPUT(lr, TensorType::NumberType())
  1780. .INPUT(beta1, TensorType::NumberType())
  1781. .INPUT(beta2, TensorType::NumberType())
  1782. .INPUT(epsilon, TensorType::NumberType())
  1783. .INPUT(grad, TensorType::NumberType())
  1784. .OUTPUT(var, TensorType::NumberType())
  1785. .OUTPUT(m, TensorType::NumberType())
  1786. .OUTPUT(v, TensorType::NumberType())
  1787. .ATTR(use_locking, Bool, false)
  1788. .ATTR(use_nesterov, Bool, false)
  1789. .OP_END_FACTORY_REG(ApplyAdamD)
  1790. /**
  1791. *@brief Updates "var" according to the proximal adadelta scheme . \n
  1792. *@par Inputs:
  1793. *Seven inputs, including:
  1794. * @li var: A mutable Tensor of type TensorType::NumberType().
  1795. * Should be a Variable Tensor.
  1796. * @li accum: A mutable Tensor of the same type as "var".
  1797. * Should be a Variable Tensor.
  1798. * @li accum_update: A mutable Tensor of the same type as "var".
  1799. * Should be a Variable Tensor.
  1800. * @li lr: A scalar of the same type as "var", for the scaling factor.
  1801. * @li rho: A scalar of the same type as "var", for the decay factor.
  1802. * @li epsilon: A scalar of the same type as "var", for the constant factor.
  1803. * @li grad: A Tensor of the same type as "var", for the gradient . \n
  1804. *@par Attributes:
  1805. *use_locking: An optional bool. Defaults to "False".
  1806. * If "True", updating of the "var", "accum" and "accum_update" tensors will be
  1807. * protected by a lock; otherwise the behavior is undefined,
  1808. * but may exhibit less contention . \n
  1809. *@par Outputs:
  1810. *var: A mutable Tensor. Has the same type as "var" . \n
  1811. *@par Third-party framework compatibility
  1812. * Compatible with the TensorFlow operator ApplyAdadelta.
  1813. */
  1814. REG_OP(ApplyAdadelta)
  1815. .INPUT(var, TensorType::NumberType())
  1816. .INPUT(accum, TensorType::NumberType())
  1817. .INPUT(accum_update, TensorType::NumberType())
  1818. .INPUT(lr, TensorType::NumberType())
  1819. .INPUT(rho, TensorType::NumberType())
  1820. .INPUT(epsilon, TensorType::NumberType())
  1821. .INPUT(grad, TensorType::NumberType())
  1822. .OUTPUT(var, TensorType::NumberType())
  1823. .ATTR(use_locking, Bool, false)
  1824. .OP_END_FACTORY_REG(ApplyAdadelta)
  1825. /**
  1826. *@brief Updates "var" according to the proximal adadelta scheme . \n
  1827. *@par Inputs:
  1828. *Seven inputs, including:
  1829. * @li var: A mutable Tensor of type TensorType::NumberType().
  1830. * Should be a Variable Tensor.
  1831. * @li accum: A mutable Tensor of the same type as "var".
  1832. * Should be a Variable Tensor.
  1833. * @li accum_update: A mutable Tensor of the same type as "var".
  1834. * Should be a Variable Tensor.
  1835. * @li lr: A scalar of the same type as "var", for the scaling factor.
  1836. * @li rho: A scalar of the same type as "var", for the decay factor.
  1837. * @li epsilon: A scalar of the same type as "var", for the constant factor.
  1838. * @li grad: A Tensor of the same type as "var", for the gradient . \n
  1839. *@par Attributes:
  1840. *use_locking: An optional bool. Defaults to "False".
  1841. * If "True", updating of the "var", "accum" and "accum_update" tensors will be
  1842. * protected by a lock; otherwise the behavior is undefined,
  1843. * but may exhibit less contention . \n
  1844. *@par Outputs:
  1845. *@li var: A mutable Tensor. Has the same type as "var".
  1846. *@li accum: A mutable Tensor. Has the same type as "var".
  1847. *@li accum_update: A mutable Tensor. Has the same type as "var" . \n
  1848. *@par Third-party framework compatibility
  1849. * Compatible with the TensorFlow operator ApplyAdadelta.
  1850. * @par Restrictions:
  1851. * Warning: THIS FUNCTION IS DEPRECATED. Please use ApplyAdadelta instead.
  1852. */
  1853. REG_OP(ApplyAdadeltaD)
  1854. .INPUT(var, TensorType::NumberType())
  1855. .INPUT(accum, TensorType::NumberType())
  1856. .INPUT(accum_update, TensorType::NumberType())
  1857. .INPUT(lr, TensorType::NumberType())
  1858. .INPUT(rho, TensorType::NumberType())
  1859. .INPUT(epsilon, TensorType::NumberType())
  1860. .INPUT(grad, TensorType::NumberType())
  1861. .OUTPUT(var, TensorType::NumberType())
  1862. .OUTPUT(accum, TensorType::NumberType())
  1863. .OUTPUT(accum_update, TensorType::NumberType())
  1864. .ATTR(use_locking, Bool, false)
  1865. .OP_END_FACTORY_REG(ApplyAdadeltaD)
  1866. /**
  1867. * @brief Updates "var" according to the ApplyMomentum algorithm.
  1868. * accum = accum * momentum + x1 * x2
  1869. * if use_nesterov is True:
  1870. * var -= x1 * x2 * lr + accum * momentum * lr
  1871. * else:
  1872. * var -= accum * lr
  1873. *
  1874. * @par Inputs:
  1875. * Six inputs, including:
  1876. * @li var: A mutable Tensor has type TensorType::NumberType().
  1877. * Should be a Variable Tensor.
  1878. * @li accum: A mutable Tensor has the same type as "var".
  1879. * Should be a Variable Tensor.
  1880. * @li lr: A scalar has the same type as "var", for the scaling factor.
  1881. * @li x1: A Tensor has type TensorType::NumberType().
  1882. * @li momentum: A scalar has the same type as "var".
  1883. * @li x2: A scalar has the same type as "var".
  1884. *
  1885. * @par Attributes:
  1886. * Two attributes, including:
  1887. * @li use_nesterov: An optional bool. Defaults to "False".
  1888. * If True, the tensor passed to compute grad will be var - lr * momentum * accum,
  1889. * so in the end, the var you get is actually var - lr * momentum * accum.
  1890. * @li use_locking: An optional bool. Defaults to "False".
  1891. * If "True", updating of the "var", m", and "v" tensors will be protected
  1892. * by a lock; otherwise the behavior is undefined, but may exhibit less contention.
  1893. *
  1894. * @par Outputs:
  1895. * Two outputs, including:
  1896. * @li var: A mutable Tensor has the same type as "var".
  1897. * @li accum: A mutable Tensor has the same type as "var".
  1898. *@par Restrictions:
  1899. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  1900. */
  1901. REG_OP(FusedMulApplyMomentum)
  1902. .INPUT(var, TensorType::NumberType())
  1903. .INPUT(accum, TensorType::NumberType())
  1904. .INPUT(lr, TensorType::NumberType())
  1905. .INPUT(x1, TensorType::NumberType())
  1906. .INPUT(momentum, TensorType::NumberType())
  1907. .INPUT(x2, TensorType::NumberType())
  1908. .OUTPUT(var, TensorType::NumberType())
  1909. .OUTPUT(accum, TensorType::NumberType())
  1910. .ATTR(use_nesterov, Bool, false)
  1911. .ATTR(use_locking, Bool, false)
  1912. .OP_END_FACTORY_REG(FusedMulApplyMomentum)
  1913. /**
  1914. * @brief Updates "var" according to the ApplyMomentum algorithm.
  1915. * accum = accum * momentum + x1 * x2
  1916. * if use_nesterov is True:
  1917. * var -= x1 * x2 * lr + accum * momentum * lr
  1918. * else:
  1919. * var -= accum * lr
  1920. *
  1921. * @par Inputs:
  1922. * Seven inputs, including:
  1923. * @li var: A mutable Tensor of type float32.
  1924. * Should be a Variable Tensor.
  1925. * @li accum: A mutable Tensor has type TensorType::NumberType().
  1926. * Should be a Variable Tensor.
  1927. * @li lr: A scalar has the same type as "accum", for the scaling factor.
  1928. * @li x1: A Tensor has the same type as "accum".
  1929. * @li momentum: A scalar has the same type as "accum".
  1930. * @li x2: A scalar has the same type as "accum".
  1931. * @li var_copy: A Tensor has type float16.
  1932. *
  1933. * @par Attributes:
  1934. * Two Attributes, including:
  1935. * @li use_nesterov: An optional bool. Defaults to "False".
  1936. * If True, the tensor passed to compute grad will be var - lr * momentum * accum,
  1937. * so in the end, the var you get is actually var - lr * momentum * accum.
  1938. * @li use_locking: An optional bool. Defaults to "False".
  1939. * If "True", updating of the "var", m", and "v" tensors will be protected
  1940. * by a lock; otherwise the behavior is undefined, but may exhibit less contention.
  1941. *
  1942. * @par Outputs:
  1943. * Three outputs, including:
  1944. * @li var: A Tensor has the type float32.
  1945. * @li var_copy: A Tensor has the type float16.
  1946. * @li accum: A Tensor has the same type as input "accum".
  1947. *@par Restrictions:
  1948. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  1949. */
  1950. REG_OP(FusedMulApplyMomentumExtern)
  1951. .INPUT(var, TensorType(DT_FLOAT))
  1952. .INPUT(accum, TensorType::NumberType())
  1953. .INPUT(lr, TensorType::NumberType())
  1954. .INPUT(x1, TensorType::NumberType())
  1955. .INPUT(momentum, TensorType::NumberType())
  1956. .INPUT(x2, TensorType::NumberType())
  1957. .INPUT(var_copy, TensorType(DT_FLOAT16))
  1958. .OUTPUT(var, TensorType(DT_FLOAT))
  1959. .OUTPUT(var_copy, TensorType(DT_FLOAT16))
  1960. .OUTPUT(accum, TensorType::NumberType())
  1961. .ATTR(use_nesterov, Bool, false)
  1962. .ATTR(use_locking, Bool, false)
  1963. .OP_END_FACTORY_REG(FusedMulApplyMomentumExtern)
  1964. /**
  1965. *@brief Updates '*var' according to the momentum scheme.
  1966. * accum = accum * momentum - x1 * x2 * lr
  1967. * if use_nesterov is True:
  1968. * var += accum * momentum - x1 * x2 * lr
  1969. * else:
  1970. * var += accum
  1971. *
  1972. *@par Inputs:
  1973. *@li var: A mutable tensor. Must be one of the data types defined in
  1974. * TensorType::NumberType(). Should be from a Variable().
  1975. *@li accum: A mutable tensor. Has the same type as "var". Should be from a
  1976. * Variable().
  1977. *@li lr: A tensor for the learning rate. Has the same type as "var". Should be
  1978. * from a Variable().
  1979. *@li x1: A Tensor has type TensorType::NumberType().
  1980. *@li momentum: A scalar. Has the same type as "var".
  1981. *@li x2: A scalar has the same type as "var".
  1982. *
  1983. *@par Attributes:
  1984. *@li use_nesterov: An optional bool. Defaults to "False".
  1985. * If "True", var will be updated by using Nesterov momentum.
  1986. *@li use_locking: An optional bool. Defaults to "False".
  1987. * If "True", updating of the "var" tensor is protected by a lock;
  1988. * otherwise the behavior is undefined, but may exhibit less contention.
  1989. *
  1990. *@par Outputs:
  1991. * var: A mutable tensor. Has the same type as input "var".
  1992. *
  1993. *@attention Constraints:
  1994. * The input tensors must have the same shape.
  1995. *
  1996. *@par Third-party framework compatibility
  1997. * Compatible with the TensorFlow operator ResourceApplyKerasMomentum.
  1998. *
  1999. */
  2000. REG_OP(FusedMulApplyKerasMomentum)
  2001. .INPUT(var, TensorType::NumberType())
  2002. .INPUT(accum, TensorType::NumberType())
  2003. .INPUT(lr, TensorType::NumberType())
  2004. .INPUT(x1, TensorType::NumberType())
  2005. .INPUT(momentum, TensorType::NumberType())
  2006. .INPUT(x2, TensorType::NumberType())
  2007. .OUTPUT(var, TensorType::NumberType())
  2008. .OUTPUT(accum, TensorType::NumberType())
  2009. .ATTR(use_locking, Bool, false)
  2010. .ATTR(use_nesterov, Bool, false)
  2011. .OP_END_FACTORY_REG(FusedMulApplyKerasMomentum)
  2012. /**
  2013. *@brief Update "g" according to the LARS algorithm . \n
  2014. *@par Inputs:
  2015. *Four inputs, including:
  2016. * @li w: A Tensor. Must be of type TensorType::DT_FLOAT.
  2017. * @li g: A Tensor of the same type and shape as "w".
  2018. * @li weight_decay: A Tensor of the same type as "w", Must be a scalar.
  2019. * @li learning_rate: A Tensor of the same type as "w", Must be a scalar . \n
  2020. *@par Attributes:
  2021. *Three Attributes, including:
  2022. * @li hyperpara: An optional float. Default value is 0.001.
  2023. * @li epsilon: An optional float. Default value is 1e-5.Avoid denominator is 0.
  2024. * @li use_clip: An optional bool. Defaults to "False".
  2025. * If "True", updating learning rate . \n
  2026. *@par Outputs:
  2027. *g_new: Tensor of the same type as "w".
  2028. */
  2029. REG_OP(LarsV2)
  2030. .INPUT(w, TensorType(DT_FLOAT))
  2031. .INPUT(g, TensorType(DT_FLOAT))
  2032. .INPUT(weight_decay, TensorType(DT_FLOAT))
  2033. .INPUT(learning_rate, TensorType(DT_FLOAT))
  2034. .OUTPUT(g_new, TensorType(DT_FLOAT))
  2035. .ATTR(hyperpara, Float, 0.001)
  2036. .ATTR(epsilon, Float, 0.00001)
  2037. .ATTR(use_clip, Bool, false)
  2038. .OP_END_FACTORY_REG(LarsV2)
  2039. /**
  2040. *@brief Update "g" according to the LARS algorithm . \n
  2041. *@par Inputs:
  2042. *Six inputs, including:
  2043. * @li w: A Tensor. Must be of type TensorType::DT_FLOAT.
  2044. * @li g: A Tensor of the same type and shape as "w".
  2045. * @li w_square_sum: A Tensor of square_sum(w), has the same type as "w", Must be a scalar.
  2046. * @li g_square_sum: A Tensor of square(g), has the same type as "w", Must be a scalar.
  2047. * @li weight_decay: A Tensor of the same type as "w", Must be a scalar.
  2048. * @li learning_rate: A Tensor of the same type as "w", Must be a scalar . \n
  2049. *@par Attributes:
  2050. *Three Attributes, including:
  2051. * @li hyperpara: An optional float. Default value is 0.001.
  2052. * @li epsilon: An optional float. Default value is 1e-5.Avoid denominator is 0.
  2053. * @li use_clip: An optional bool. Defaults to "False".
  2054. * If "True", updating learning rate . \n
  2055. *@par Outputs:
  2056. *g_new: Tensor of the same type as "w".
  2057. */
  2058. REG_OP(LarsV2Update)
  2059. .INPUT(w, TensorType(DT_FLOAT))
  2060. .INPUT(g, TensorType(DT_FLOAT))
  2061. .INPUT(w_square_sum, TensorType(DT_FLOAT))
  2062. .INPUT(g_square_sum, TensorType(DT_FLOAT))
  2063. .INPUT(weight_decay, TensorType(DT_FLOAT))
  2064. .INPUT(learning_rate, TensorType(DT_FLOAT))
  2065. .OUTPUT(g_new, TensorType(DT_FLOAT))
  2066. .ATTR(hyperpara, Float, 0.001)
  2067. .ATTR(epsilon, Float, 0.00001)
  2068. .ATTR(use_clip, Bool, false)
  2069. .OP_END_FACTORY_REG(LarsV2Update)
  2070. /**
  2071. * @brief Update relevant entries in '*var' according to the Ftrl-proximal scheme . \n
  2072. * @par Inputs:
  2073. * Nine inputs, including:
  2074. * @li var: A mutable Tensor. Must be of type TensorType::NumberType().
  2075. * Should be a Variable Tensor.
  2076. * @li accum: A mutable Tensor of the same type as "var".
  2077. * Should be a Variable Tensor. The value of accum must be greater than 0.
  2078. * @li linear: A mutable Tensor of the same type as "var".
  2079. * Should be a Variable Tensor.
  2080. * @li grad: A Tensor of the same type as "var", for the gradient.
  2081. * @li indices: A vector of indices into the first dimension of var and accum.
  2082. * The value of indices must be unique. Otherwise, the result is unpredictable.
  2083. * @li lr: A Tensor of the same type as "var", for the scaling factor. Must be a scalar.
  2084. * @li l1: A Tensor of the same type as "var", for L1 regulariation. Must be a scalar.
  2085. * @li l2: A Tensor of the same type as "var", for L2 regulariation. Must be a scalar.
  2086. * @li lr_power: A Tensor of the same type as "var", for the scaling factor. Must be a scalar . \n
  2087. * @par Attributes:
  2088. * use_locking: An optional bool. Defaults to "False".
  2089. * If "True", updating of the "var" and "accum" tensors will be
  2090. * protected by a lock; otherwise the behavior is undefined,
  2091. * but may exhibit less contention . \n
  2092. * @par Outputs:
  2093. * var: A Tensor. Has the same type and format as input "var" . \n
  2094. * @par Third-party framework compatibility
  2095. * Compatible with the TensorFlow operator SparseApplyFtrl.
  2096. */
  2097. REG_OP(SparseApplyFtrl)
  2098. .INPUT(var, TensorType({DT_FLOAT}))
  2099. .INPUT(accum, TensorType({DT_FLOAT}))
  2100. .INPUT(linear, TensorType({DT_FLOAT}))
  2101. .INPUT(grad, TensorType({DT_FLOAT}))
  2102. .INPUT(indices, TensorType({DT_INT32}))
  2103. .INPUT(lr, TensorType({DT_FLOAT}))
  2104. .INPUT(l1, TensorType({DT_FLOAT}))
  2105. .INPUT(l2, TensorType({DT_FLOAT}))
  2106. .INPUT(lr_power, TensorType({DT_FLOAT}))
  2107. .OUTPUT(var, TensorType({DT_FLOAT}))
  2108. .ATTR(use_locking, Bool, false)
  2109. .OP_END_FACTORY_REG(SparseApplyFtrl)
  2110. /**
  2111. * @brief Update relevant entries in '*var' according to the Ftrl-proximal scheme . \n
  2112. * @par Inputs:
  2113. * Five inputs, including:
  2114. * @li var: A mutable Tensor. Must be of type TensorType::NumberType().
  2115. * Should be a Variable Tensor.
  2116. * @li accum: A mutable Tensor of the same type as "var".
  2117. * Should be a Variable Tensor. The value of accum must be greater than 0.
  2118. * @li linear: A mutable Tensor of the same type as "var".
  2119. * Should be a Variable Tensor.
  2120. * @li grad: A Tensor of the same type as "var", for the gradient.
  2121. * @li indices: A vector of indices into the first dimension of var and accum.
  2122. * The value of indices must be unique. Otherwise, the result is unpredictable . \n
  2123. * @par Attributes:
  2124. * @li lr: A Tensor of the same type as "var", for the scaling factor. Must be a scalar.
  2125. * @li l1: A Tensor of the same type as "var", for L1 regulariation. Must be a scalar.
  2126. * @li l2: A Tensor of the same type as "var", for L2 regulariation. Must be a scalar.
  2127. * @li lr_power: A Tensor of the same type as "var", for the scaling factor. Must be a scalar.
  2128. * @li use_locking: An optional bool. Defaults to "False".
  2129. * If "True", updating of the "var" and "accum" tensors will be
  2130. * protected by a lock; otherwise the behavior is undefined,
  2131. * but may exhibit less contention . \n
  2132. * @par Outputs:
  2133. * @li var: A Tensor. Has the same type and format as input "var".
  2134. * @li accum: A Tensor. Has the same type and format as input "accum".
  2135. * @li linear: A Tensor. Has the same type and format as input "linear" . \n
  2136. * @par Third-party framework compatibility
  2137. * Compatible with the TensorFlow operator SparseApplyFtrl.
  2138. *
  2139. *@par Restrictions:
  2140. *Warning: THIS FUNCTION IS DEPRECATED. Please use SparseApplyFtrl instead.
  2141. */
  2142. REG_OP(SparseApplyFtrlD)
  2143. .INPUT(var, TensorType({DT_FLOAT}))
  2144. .INPUT(accum, TensorType({DT_FLOAT}))
  2145. .INPUT(linear, TensorType({DT_FLOAT}))
  2146. .INPUT(grad, TensorType({DT_FLOAT}))
  2147. .INPUT(indices, TensorType({DT_INT32}))
  2148. .OUTPUT(var, TensorType({DT_FLOAT}))
  2149. .OUTPUT(accum, TensorType({DT_FLOAT}))
  2150. .OUTPUT(linear, TensorType({DT_FLOAT}))
  2151. .REQUIRED_ATTR(lr, Float)
  2152. .REQUIRED_ATTR(l1, Float)
  2153. .REQUIRED_ATTR(l2, Float)
  2154. .REQUIRED_ATTR(lr_power, Float)
  2155. .ATTR(use_locking, Bool, false)
  2156. .OP_END_FACTORY_REG(SparseApplyFtrlD)
  2157. /**
  2158. * @brief Updates relevant entries in '*var' according to the Ftrl-proximal scheme.
  2159. * That is for rows we have grad for, "var", "accum" and "linear" are updated . \n
  2160. * @par Inputs:
  2161. * Ten inputs, including:
  2162. * @li var: A mutable Tensor. Must be of type TensorType::NumberType().
  2163. * Should be a Variable Tensor.
  2164. * @li accum: A mutable Tensor of the same type as "var".
  2165. * Should be a Variable Tensor.
  2166. * @li linear: A mutable Tensor of the same type as "var".
  2167. * Should be a Variable Tensor.
  2168. * @li grad: A Tensor of the same type as "var", for the gradient.
  2169. * @li indices: A vector of indices into the first dimension of "var" and "accum".
  2170. * @li lr: A Tensor of the same type as "var", for the scaling factor. Must be a scalar.
  2171. * @li l1: A Tensor of the same type as "var", for L1 regulariation. Must be a scalar.
  2172. * @li l2: A Tensor of the same type as "var", for L2 regulariation. Must be a scalar.
  2173. * @li l2_shrinkage: A Tensor of the same type as "var", L2 shrinkage regulariation. Must be a scalar.
  2174. * @li lr_power: A Tensor of the same type as "var", for the scaling factor. Must be a scalar . \n
  2175. * @par Attributes:
  2176. * use_locking: An optional bool. Defaults to "False".
  2177. * If "True", updating of the "var" and "accum" tensors will be
  2178. * protected by a lock; otherwise the behavior is undefined,
  2179. * but may exhibit less contention . \n
  2180. * @par Outputs:
  2181. * var: A Tensor. Has the same type and format as input "var" . \n
  2182. * @par Third-party framework compatibility
  2183. * Compatible with the TensorFlow operator SparseApplyFtrlV2.
  2184. */
  2185. REG_OP(SparseApplyFtrlV2)
  2186. .INPUT(var, TensorType({DT_FLOAT}))
  2187. .INPUT(accum, TensorType({DT_FLOAT}))
  2188. .INPUT(linear, TensorType({DT_FLOAT}))
  2189. .INPUT(grad, TensorType({DT_FLOAT}))
  2190. .INPUT(indices, TensorType({DT_INT32}))
  2191. .INPUT(lr, TensorType({DT_FLOAT}))
  2192. .INPUT(l1, TensorType({DT_FLOAT}))
  2193. .INPUT(l2, TensorType({DT_FLOAT}))
  2194. .INPUT(l2_shrinkage, TensorType({DT_FLOAT}))
  2195. .INPUT(lr_power, TensorType({DT_FLOAT}))
  2196. .OUTPUT(var, TensorType({DT_FLOAT}))
  2197. .ATTR(use_locking, Bool, false)
  2198. .OP_END_FACTORY_REG(SparseApplyFtrlV2)
  2199. /**
  2200. * @brief Updates relevant entries in '*var' according to the Ftrl-proximal scheme.
  2201. * That is for rows we have grad for, "var", "accum" and "linear" are updated . \n
  2202. * @par Inputs:
  2203. * Five inputs, including:
  2204. * @li var: A mutable Tensor. Must be of type TensorType::NumberType().
  2205. * Should be a Variable Tensor.
  2206. * @li accum: A mutable Tensor of the same type as "var".
  2207. * Should be a Variable Tensor.
  2208. * @li linear: A mutable Tensor of the same type as "var".
  2209. * Should be a Variable Tensor.
  2210. * @li grad: A Tensor of the same type as "var", for the gradient.
  2211. * @li indices: A vector of indices into the first dimension of "var" and "accum" . \n
  2212. * @par Attributes:
  2213. * @li lr: A Tensor of the same type as "var", for the scaling factor. Must be a scalar.
  2214. * @li l1: A Tensor of the same type as "var", for L1 regulariation. Must be a scalar.
  2215. * @li l2: A Tensor of the same type as "var", for L2 regulariation. Must be a scalar.
  2216. * @li l2_shrinkage: A Tensor of the same type as "var", L2 shrinkage regulariation. Must be a scalar.
  2217. * @li lr_power: A Tensor of the same type as "var", for the scaling factor. Must be a scalar.
  2218. * @li use_locking: An optional bool. Defaults to "False".
  2219. * If "True", updating of the "var" and "accum" tensors will be
  2220. * protected by a lock; otherwise the behavior is undefined,
  2221. * but may exhibit less contention . \n
  2222. * @par Outputs:
  2223. * @li var: A Tensor. Has the same type and format as input "var".
  2224. * @li accum: A Tensor. Has the same type and format as input "accum".
  2225. * @li linear: A Tensor. Has the same type and format as input "linear" . \n
  2226. * @par Third-party framework compatibility
  2227. * Compatible with the TensorFlow operator SparseApplyFtrlV2D.
  2228. *
  2229. * @par Restrictions:
  2230. * Warning: THIS FUNCTION IS DEPRECATED. Please use SparseApplyFtrlV2 instead.
  2231. */
  2232. REG_OP(SparseApplyFtrlV2D)
  2233. .INPUT(var, TensorType({DT_FLOAT}))
  2234. .INPUT(accum, TensorType({DT_FLOAT}))
  2235. .INPUT(linear, TensorType({DT_FLOAT}))
  2236. .INPUT(grad, TensorType({DT_FLOAT}))
  2237. .INPUT(indices, TensorType({DT_INT32}))
  2238. .OUTPUT(var, TensorType({DT_FLOAT}))
  2239. .OUTPUT(accum, TensorType({DT_FLOAT}))
  2240. .OUTPUT(linear, TensorType({DT_FLOAT}))
  2241. .REQUIRED_ATTR(lr, Float)
  2242. .REQUIRED_ATTR(l1, Float)
  2243. .REQUIRED_ATTR(l2, Float)
  2244. .REQUIRED_ATTR(l2_shrinkage, Float)
  2245. .REQUIRED_ATTR(lr_power, Float)
  2246. .ATTR(use_locking, Bool, false)
  2247. .OP_END_FACTORY_REG(SparseApplyFtrlV2D)
  2248. /**
  2249. * @brief Updates "var" in specified index according to the RMSProp algorithm.
  2250. * mean_square = decay * mean_square + (1-decay) * gradient ** 2
  2251. * Delta = learning_rate * gradient / sqrt(mean_square + epsilon)
  2252. * ms <- rho * ms_{t-1} + (1-rho) * grad * grad
  2253. * mom <- momentum * mom_{t-1} + lr * grad / sqrt(ms + epsilon)
  2254. * var <- var - mom
  2255. *
  2256. * @par Inputs:
  2257. * Nine inputs, including:
  2258. * @li var: A mutable tensor. Must be one of the data types defined in
  2259. * TensorType::NumberType(). Should be from a Variable().
  2260. * @li ms: A mutable tensor. Must have the same type as "var". Should be from a
  2261. * Variable().
  2262. * @li mom: A mutable tensor. Must have the same type as "var". Should be from a
  2263. * Variable().
  2264. * @li lr: A scalar. Must have the same type as "var".
  2265. * @li rho: A scalar. Must have the same type as "var".
  2266. * @li momentum: A scalar. Must have the same type as "var".
  2267. * @li epsilon: A scalar. Must have the same type as "var".
  2268. * @li grad: A tensor, specifying the gradient.
  2269. * @li indices: A vector of indices into the first dimension of "var", "mom" and "ms".
  2270. *
  2271. * @par Attributes:
  2272. * use_locking: An optional "bool". Defaults to "False". If "True", updating of
  2273. * the "var", "ms", and "mom" tensors will be protected by a lock; otherwise the
  2274. * behavior is undefined, but may exhibit less contention.
  2275. *
  2276. * @par Outputs:
  2277. * var: A mutable tensor. Has the same type as input "var".
  2278. *
  2279. * @attention Constraints:
  2280. * @li Note that in this sparse implementation, "ms" and "mom" will not update
  2281. * in iterations during which "grad" is 0.
  2282. * @li The input tensors "var", "ms", and "mom" must have the same shape.
  2283. *
  2284. * @par Third-party framework compatibility
  2285. * Compatible with the TensorFlow operator SparseApplyRMSProp.
  2286. */
  2287. REG_OP(SparseApplyRMSProp)
  2288. .INPUT(var, TensorType::NumberType())
  2289. .INPUT(ms, TensorType::NumberType())
  2290. .INPUT(mom, TensorType::NumberType())
  2291. .INPUT(lr, TensorType::NumberType())
  2292. .INPUT(rho, TensorType::NumberType())
  2293. .INPUT(momentum, TensorType::NumberType())
  2294. .INPUT(epsilon, TensorType::NumberType())
  2295. .INPUT(grad, TensorType::NumberType())
  2296. .INPUT(indices, TensorType::IndexNumberType())
  2297. .OUTPUT(var, TensorType::NumberType())
  2298. .ATTR(use_locking, Bool, false)
  2299. .OP_END_FACTORY_REG(SparseApplyRMSProp)
  2300. /**
  2301. * @brief Updates "var" in specified index according to the RMSProp algorithm.
  2302. * a const input will be considered as an attribute.
  2303. * mean_square = decay * mean_square + (1-decay) * gradient ** 2
  2304. * Delta = learning_rate * gradient / sqrt(mean_square + epsilon)
  2305. * ms <- rho * ms_{t-1} + (1-rho) * grad * grad
  2306. * mom <- momentum * mom_{t-1} + lr * grad / sqrt(ms + epsilon)
  2307. * var <- var - mom
  2308. *
  2309. * @par Inputs:
  2310. * Six inputs, including:
  2311. * @li var: A mutable tensor. Must be one of the data types defined in
  2312. * TensorType::NumberType(). Should be from a Variable().
  2313. * @li ms: A mutable tensor. Must have the same type as "var". Should be from a
  2314. * Variable().
  2315. * @li mom: A mutable tensor. Must have the same type as "var". Should be from a
  2316. * Variable().
  2317. * @li lr: A scalar. Must have the same type as "var".
  2318. * @li grad: A tensor, specifying the gradient.
  2319. *
  2320. * @par Attributes:
  2321. * @li use_locking: An optional "bool". Defaults to "False". If "True",
  2322. * updating of the "var", "ms", and "mom" tensors will be protected by a lock;
  2323. * otherwise the behavior is undefined, but may exhibit less contention.
  2324. * @li rho: A required scalar. Must have the same type as "var".
  2325. * @li momentum: A required scalar. Must have the same type as "var".
  2326. * @li epsilon: A required scalar. Must have the same type as "var".
  2327. *
  2328. * @par Outputs:
  2329. * @li var: A mutable tensor. Must have the same type as input "var".
  2330. * @li ms: A mutable tensor. Must have the same type as input "ms".
  2331. * @li mom: A mutable tensor. Must have the same type as input "mom".
  2332. *
  2333. * @attention Constraints:
  2334. * @li Note that in this sparse implementation, "ms" and "mom" will not update
  2335. * in iterations during which "grad" is 0.
  2336. * @li The input tensors "var", "ms" and "mom" must have the same shape.
  2337. *
  2338. * @par Restrictions:
  2339. * Warning: THIS FUNCTION IS DEPRECATED. Please use SparseApplyRMSProp instead.
  2340. */
  2341. REG_OP(SparseApplyRMSPropD)
  2342. .INPUT(var, TensorType::NumberType())
  2343. .INPUT(ms, TensorType::NumberType())
  2344. .INPUT(mom, TensorType::NumberType())
  2345. .INPUT(lr, TensorType::NumberType())
  2346. .INPUT(grad, TensorType::NumberType())
  2347. .INPUT(indices, TensorType::IndexNumberType())
  2348. .OUTPUT(var, TensorType::NumberType())
  2349. .OUTPUT(ms, TensorType::NumberType())
  2350. .OUTPUT(mom, TensorType::NumberType())
  2351. .REQUIRED_ATTR(rho, Float)
  2352. .REQUIRED_ATTR(momentum, Float)
  2353. .REQUIRED_ATTR(epsilon, Float)
  2354. .ATTR(use_locking, Bool, false)
  2355. .OP_END_FACTORY_REG(SparseApplyRMSPropD)
  2356. /**
  2357. * @brief Updates "var" in specified index according to the Adadelta algorithm.
  2358. * accum <- rho * accum + (1 - rho) * grad.square()
  2359. * update <- (accum_update + epsilon).sqrt() * (accum + epsilon()).rsqrt() * grad
  2360. * var <- var - update * lr
  2361. * accum_update <- rho() * accum_update + (1 - rho()) * update.square()
  2362. *
  2363. * @par Inputs:
  2364. * Eight inputs, including:
  2365. * @li var: A mutable tensor. Must be one of the data types defined in
  2366. * TensorType::NumberType(). Should be from a Variable().
  2367. * @li accum: A mutable tensor. Must have the same type as "var". Should be from a
  2368. * Variable().
  2369. * @li accum_update: A mutable tensor. Must have the same type as "var". Should be from a
  2370. * Variable().
  2371. * @li lr: A scalar. Must have the same type as "var".
  2372. * @li rho: A scalar. Must have the same type as "var".
  2373. * @li epsilon: A scalar. Must have the same type as "var".
  2374. * @li grad: A tensor, specifying the gradient.
  2375. * @li indices: A vector of indices into the first dimension of "var", "accum" and "accum_update".
  2376. *
  2377. * @par Attributes:
  2378. * use_locking: An optional "bool". Defaults to "False". If "True", updating of
  2379. * the "var", "accum", and "accum_update" tensors will be protected by a lock; otherwise the
  2380. * behavior is undefined, but may exhibit less contention.
  2381. *
  2382. * @par Outputs:
  2383. * var: A mutable tensor. Has the same type as input "var".
  2384. *
  2385. * @attention Constraints:
  2386. * @li Note that in this sparse implementation, "accum" and "accum_update" will not update
  2387. * in iterations during which "grad" is 0.
  2388. * @li The input tensors "var", "accum", and "accum_update" must have the same shape.
  2389. *
  2390. * @par Third-party framework compatibility
  2391. * Compatible with the TensorFlow operator SparseApplyAdadelta.
  2392. */
  2393. REG_OP(SparseApplyAdadelta)
  2394. .INPUT(var, TensorType::NumberType())
  2395. .INPUT(accum, TensorType::NumberType())
  2396. .INPUT(accum_update, TensorType::NumberType())
  2397. .INPUT(lr, TensorType::NumberType())
  2398. .INPUT(rho, TensorType::NumberType())
  2399. .INPUT(epsilon, TensorType::NumberType())
  2400. .INPUT(grad, TensorType::NumberType())
  2401. .INPUT(indices, TensorType::IndexNumberType())
  2402. .OUTPUT(var, TensorType::NumberType())
  2403. .ATTR(use_locking, Bool, false)
  2404. .OP_END_FACTORY_REG(SparseApplyAdadelta)
  2405. /**
  2406. * @brief Updates "var" in specified index according to the Adadelta algorithm.
  2407. * a const input will be considered as an attribute.
  2408. * accum <- rho * accum + (1 - rho) * grad.square()
  2409. * update <- (accum_update + epsilon).sqrt() * (accum + epsilon()).rsqrt() * grad
  2410. * var <- var - update * lr
  2411. * accum_update <- rho() * accum_update + (1 - rho()) * update.square()
  2412. *
  2413. * @par Inputs:
  2414. * Seven inputs, including:
  2415. * @li var: A mutable tensor. Must be one of the data types defined in
  2416. * TensorType::NumberType(). Should be from a Variable().
  2417. * @li accum: A mutable tensor. Must have the same type as "var". Should be from a
  2418. * Variable().
  2419. * @li accum_update: A mutable tensor. Must have the same type as "var". Should be from a
  2420. * Variable().
  2421. * @li lr: A scalar. Must have the same type as "var".
  2422. * @li rho: A scalar. Must have the same type as "var".
  2423. * @li grad: A tensor, specifying the gradient.
  2424. * @li indices: A vector of indices into the first dimension of "var", "accum" and "accum_update".
  2425. *
  2426. * @par Attributes:
  2427. * @li use_locking: An optional "bool". Defaults to "False". If "True",
  2428. * updating of the "var", "accum", and "accum_update" tensors will be protected by a lock;
  2429. * otherwise the behavior is undefined, but may exhibit less contention.
  2430. * @li epsilon: A required scalar. Must have the same type as "var".
  2431. *
  2432. * @par Outputs:
  2433. * @li var: A mutable tensor. Must have the same type as input "var".
  2434. * @li accum: A mutable tensor. Must have the same type as input "accum".
  2435. * @li accum_update: A mutable tensor. Must have the same type as input "accum_update".
  2436. *
  2437. * @attention Constraints:
  2438. * @li Note that in this sparse implementation, "accum" and "accum_update" will not update
  2439. * in iterations during which "grad" is 0.
  2440. * @li The input tensors "var", "accum" and "accum_update" must have the same shape.
  2441. *
  2442. * @par Restrictions:
  2443. * Warning: THIS FUNCTION IS DEPRECATED. Please use SparseApplyAdadelta instead.
  2444. */
  2445. REG_OP(SparseApplyAdadeltaD)
  2446. .INPUT(var, TensorType::NumberType())
  2447. .INPUT(accum, TensorType::NumberType())
  2448. .INPUT(accum_update, TensorType::NumberType())
  2449. .INPUT(lr, TensorType::NumberType())
  2450. .INPUT(rho, TensorType::NumberType())
  2451. .INPUT(grad, TensorType::NumberType())
  2452. .INPUT(indices, TensorType::IndexNumberType())
  2453. .OUTPUT(var, TensorType::NumberType())
  2454. .OUTPUT(accum, TensorType::NumberType())
  2455. .OUTPUT(accum_update, TensorType::NumberType())
  2456. .REQUIRED_ATTR(epsilon, Float)
  2457. .ATTR(use_locking, Bool, false)
  2458. .OP_END_FACTORY_REG(SparseApplyAdadeltaD)
  2459. /**
  2460. *@brief Clean memory of workspace list . \n
  2461. *@par Attributes:
  2462. * @li automic_add_mem_size: sizes of workspaces . \n
  2463. *@par Restrictions:
  2464. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  2465. */
  2466. REG_OP(AtomicAddrClean)
  2467. .ATTR(automic_add_mem_size, ListInt, {})
  2468. .OP_END_FACTORY_REG(AtomicAddrClean)
  2469. } // namespace ge
  2470. #endif // OPS_BUILT_IN_OP_PROTO_INC_NN_TRAINING_OPS_H_

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示