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

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