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