You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

nn_training_ops.h 106 kB

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

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