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 106 kB

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