keating 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/README.md +334 -0
  2. package/SYSTEM.md +33 -0
  3. package/bin/keating.js +31 -0
  4. package/dist/src/cli/main.js +357 -0
  5. package/dist/src/cli/setup.js +197 -0
  6. package/dist/src/cli/web.js +84 -0
  7. package/dist/src/core/animation.js +304 -0
  8. package/dist/src/core/ax-optimizer.js +81 -0
  9. package/dist/src/core/ax-prompt-learner.js +59 -0
  10. package/dist/src/core/ax-trial.js +181 -0
  11. package/dist/src/core/benchmark.js +253 -0
  12. package/dist/src/core/commands.js +57 -0
  13. package/dist/src/core/config.js +120 -0
  14. package/dist/src/core/engagement.js +235 -0
  15. package/dist/src/core/env.js +9 -0
  16. package/dist/src/core/evolution.js +242 -0
  17. package/dist/src/core/flashcards.js +133 -0
  18. package/dist/src/core/learner-state.js +108 -0
  19. package/dist/src/core/lesson-plan.js +155 -0
  20. package/dist/src/core/map-elites.js +228 -0
  21. package/dist/src/core/map.js +89 -0
  22. package/dist/src/core/mastery.js +207 -0
  23. package/dist/src/core/paths.js +100 -0
  24. package/dist/src/core/pi-agent.js +82 -0
  25. package/dist/src/core/policy.js +79 -0
  26. package/dist/src/core/project.js +337 -0
  27. package/dist/src/core/projects.js +281 -0
  28. package/dist/src/core/prompt-evolution.js +344 -0
  29. package/dist/src/core/quiz.js +194 -0
  30. package/dist/src/core/random.js +19 -0
  31. package/dist/src/core/self-improve.js +425 -0
  32. package/dist/src/core/speech.js +54 -0
  33. package/dist/src/core/terminal.js +117 -0
  34. package/dist/src/core/theme.js +101 -0
  35. package/dist/src/core/topics.js +620 -0
  36. package/dist/src/core/types.js +1 -0
  37. package/dist/src/core/util.js +30 -0
  38. package/dist/src/core/verification.js +162 -0
  39. package/dist/src/pi/hyperteacher-extension.js +573 -0
  40. package/dist/src/runtime/pi.js +343 -0
  41. package/package.json +78 -0
  42. package/pi/prompts/bridge.md +14 -0
  43. package/pi/prompts/diagnose.md +15 -0
  44. package/pi/prompts/improve.md +39 -0
  45. package/pi/prompts/learn.md +21 -0
  46. package/pi/prompts/quiz.md +14 -0
  47. package/pi/skills/adaptive-teaching/SKILL.md +33 -0
  48. package/scripts/install/install.sh +308 -0
  49. package/web/dist/.well-known/llms.txt +44 -0
  50. package/web/dist/apple-touch-icon.svg +10 -0
  51. package/web/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  52. package/web/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  53. package/web/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  54. package/web/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  55. package/web/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  56. package/web/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  57. package/web/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  58. package/web/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  59. package/web/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  60. package/web/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  61. package/web/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  62. package/web/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  63. package/web/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  64. package/web/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  65. package/web/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  66. package/web/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  67. package/web/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  68. package/web/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  69. package/web/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  70. package/web/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  71. package/web/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  72. package/web/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  73. package/web/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  74. package/web/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  75. package/web/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  76. package/web/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  77. package/web/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  78. package/web/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  79. package/web/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  80. package/web/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  81. package/web/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  82. package/web/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  83. package/web/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  84. package/web/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  85. package/web/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  86. package/web/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  87. package/web/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  88. package/web/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  89. package/web/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  90. package/web/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  91. package/web/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  92. package/web/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  93. package/web/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  94. package/web/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  95. package/web/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  96. package/web/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  97. package/web/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  98. package/web/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  99. package/web/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  100. package/web/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  101. package/web/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  102. package/web/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  103. package/web/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  104. package/web/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  105. package/web/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  106. package/web/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  107. package/web/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  108. package/web/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  109. package/web/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  110. package/web/dist/assets/_baseFor-B_cjfMB6.js +1 -0
  111. package/web/dist/assets/anthropic-BT6Vfzb1.js +36 -0
  112. package/web/dist/assets/arc-x2nTilpc.js +1 -0
  113. package/web/dist/assets/architecture-YZFGNWBL-B1hlUWjX.js +1 -0
  114. package/web/dist/assets/architectureDiagram-Q4EWVU46-CMApWFyw.js +36 -0
  115. package/web/dist/assets/array-B9UHiPd-.js +1 -0
  116. package/web/dist/assets/azure-openai-responses-CommX3YJ.js +1 -0
  117. package/web/dist/assets/blockDiagram-DXYQGD6D-DOQbsNRY.js +132 -0
  118. package/web/dist/assets/c4Diagram-AHTNJAMY-VFfRZWWA.js +10 -0
  119. package/web/dist/assets/channel-KY2Tg8Ba.js +1 -0
  120. package/web/dist/assets/chunk-2KRD3SAO-B-AqvS0u.js +1 -0
  121. package/web/dist/assets/chunk-336JU56O-DlYgPyl6.js +2 -0
  122. package/web/dist/assets/chunk-426QAEUC-CsVoBkfR.js +1 -0
  123. package/web/dist/assets/chunk-4BX2VUAB-0Z13aFAn.js +1 -0
  124. package/web/dist/assets/chunk-4TB4RGXK-DqC0Zwm7.js +206 -0
  125. package/web/dist/assets/chunk-55IACEB6-CWE_u-IY.js +1 -0
  126. package/web/dist/assets/chunk-5FUZZQ4R-CApli0xX.js +62 -0
  127. package/web/dist/assets/chunk-5PVQY5BW-Cbzhfhln.js +2 -0
  128. package/web/dist/assets/chunk-67CJDMHE-Cx7uJS4d.js +1 -0
  129. package/web/dist/assets/chunk-7N4EOEYR-CYPNsFus.js +1 -0
  130. package/web/dist/assets/chunk-AA7GKIK3-rU0uhR_u.js +1 -0
  131. package/web/dist/assets/chunk-BSJP7CBP-5VmcfR4-.js +1 -0
  132. package/web/dist/assets/chunk-Bj-mKKzh.js +1 -0
  133. package/web/dist/assets/chunk-CIAEETIT-CHJ-L8H1.js +1 -0
  134. package/web/dist/assets/chunk-EDXVE4YY-DZHAJjMI.js +1 -0
  135. package/web/dist/assets/chunk-ENJZ2VHE-DbUDFa7w.js +10 -0
  136. package/web/dist/assets/chunk-FMBD7UC4-BsYE5e_h.js +15 -0
  137. package/web/dist/assets/chunk-FOC6F5B3-Cm6aoTv7.js +1 -0
  138. package/web/dist/assets/chunk-ICPOFSXX-C5eNZ4L6.js +123 -0
  139. package/web/dist/assets/chunk-K5T4RW27-R7dAJ4rq.js +94 -0
  140. package/web/dist/assets/chunk-KGLVRYIC-MO99YZXL.js +1 -0
  141. package/web/dist/assets/chunk-LIHQZDEY-DUJ656sT.js +1 -0
  142. package/web/dist/assets/chunk-ORNJ4GCN-DXuuEC1n.js +1 -0
  143. package/web/dist/assets/chunk-OYMX7WX6-pJlEprWq.js +231 -0
  144. package/web/dist/assets/chunk-QZHKN3VN-_pQxbbiW.js +1 -0
  145. package/web/dist/assets/chunk-U2HBQHQK-Mh_l9PLe.js +70 -0
  146. package/web/dist/assets/chunk-X2U36JSP-BOeiJW0w.js +1 -0
  147. package/web/dist/assets/chunk-XPW4576I-fQ9SDvr_.js +32 -0
  148. package/web/dist/assets/chunk-YZCP3GAM-eboO4P5S.js +1 -0
  149. package/web/dist/assets/chunk-ZZ45TVLE-Cky0eqlr.js +1 -0
  150. package/web/dist/assets/classDiagram-6PBFFD2Q-DEPsZSU3.js +1 -0
  151. package/web/dist/assets/classDiagram-v2-HSJHXN6E-DhmIOEpX.js +1 -0
  152. package/web/dist/assets/clone-DeTzYqo8.js +1 -0
  153. package/web/dist/assets/cose-bilkent-S5V4N54A-N4zWUJ7C.js +1 -0
  154. package/web/dist/assets/cytoscape.esm-BBMd0vGm.js +321 -0
  155. package/web/dist/assets/dagre-IpK1aoMm.js +1 -0
  156. package/web/dist/assets/dagre-KV5264BT-DCytJuju.js +4 -0
  157. package/web/dist/assets/defaultLocale-5eAKkKJC.js +1 -0
  158. package/web/dist/assets/diagram-5BDNPKRD-Cv4miBae.js +10 -0
  159. package/web/dist/assets/diagram-G4DWMVQ6-CtICKUFi.js +24 -0
  160. package/web/dist/assets/diagram-MMDJMWI5-Cn7aGorh.js +43 -0
  161. package/web/dist/assets/diagram-TYMM5635-CCUWDPsC.js +24 -0
  162. package/web/dist/assets/dist-Dm98VvTW.js +1 -0
  163. package/web/dist/assets/env-api-keys-BNlMKqxw.js +1 -0
  164. package/web/dist/assets/erDiagram-SMLLAGMA-uT88sBlT.js +85 -0
  165. package/web/dist/assets/event-stream-D33K9rpL.js +1 -0
  166. package/web/dist/assets/flatten-C-u5nd5-.js +1 -0
  167. package/web/dist/assets/flowDiagram-DWJPFMVM-Bl3O7S1m.js +162 -0
  168. package/web/dist/assets/ganttDiagram-T4ZO3ILL-B1FhwV45.js +292 -0
  169. package/web/dist/assets/gitGraph-7Q5UKJZL-Bc_7vzer.js +1 -0
  170. package/web/dist/assets/gitGraphDiagram-UUTBAWPF-DfW6svMS.js +106 -0
  171. package/web/dist/assets/github-copilot-headers-L39QqneT.js +1 -0
  172. package/web/dist/assets/google-BdYNeCP_.js +1 -0
  173. package/web/dist/assets/google-gemini-cli-DpxAL3K4.js +2 -0
  174. package/web/dist/assets/google-shared-DyQdgtsI.js +2 -0
  175. package/web/dist/assets/google-vertex-CKRybaXj.js +1 -0
  176. package/web/dist/assets/graphlib-CMTVFyOZ.js +1 -0
  177. package/web/dist/assets/hash-kZ2KD_no.js +1 -0
  178. package/web/dist/assets/index-Bdb7P7gx.css +2 -0
  179. package/web/dist/assets/index-DNxepp8B.js +2891 -0
  180. package/web/dist/assets/info-OMHHGYJF-BGcxeaZt.js +1 -0
  181. package/web/dist/assets/infoDiagram-42DDH7IO-BbES7X_c.js +2 -0
  182. package/web/dist/assets/init-DlZdxViB.js +1 -0
  183. package/web/dist/assets/isEmpty-DssUW35f.js +1 -0
  184. package/web/dist/assets/ishikawaDiagram-UXIWVN3A-DxQ28rho.js +70 -0
  185. package/web/dist/assets/journeyDiagram-VCZTEJTY-D0X8qQ0P.js +139 -0
  186. package/web/dist/assets/json-parse-C6tSeIxX.js +2 -0
  187. package/web/dist/assets/kanban-definition-6JOO6SKY-DWYfSlpl.js +89 -0
  188. package/web/dist/assets/katex-CyM-5LlM.js +265 -0
  189. package/web/dist/assets/line-CuHce5JG.js +1 -0
  190. package/web/dist/assets/linear-Ca0Vkwuj.js +1 -0
  191. package/web/dist/assets/mermaid-parser.core-Cy4iY_Dy.js +4 -0
  192. package/web/dist/assets/mermaid.core-6PGkQdYc.js +11 -0
  193. package/web/dist/assets/mindmap-definition-QFDTVHPH-BBnKdtQh.js +96 -0
  194. package/web/dist/assets/mistral-BWaUMIgd.js +7 -0
  195. package/web/dist/assets/openai-D4NSaQIs.js +16 -0
  196. package/web/dist/assets/openai-codex-responses-CHBgKhmb.js +7 -0
  197. package/web/dist/assets/openai-completions-kcXmmaHI.js +5 -0
  198. package/web/dist/assets/openai-responses-Cqq3H3p3.js +1 -0
  199. package/web/dist/assets/openai-responses-shared-CTNuo9ci.js +10 -0
  200. package/web/dist/assets/ordinal-_K3x1fkz.js +1 -0
  201. package/web/dist/assets/ort-wasm-simd-threaded.jsep-B0T3yYHD.wasm +0 -0
  202. package/web/dist/assets/packet-4T2RLAQJ-D35ZLSBH.js +1 -0
  203. package/web/dist/assets/path-6uRLdFF7.js +1 -0
  204. package/web/dist/assets/pdf.worker.min-Cpi8b8z3.mjs +28 -0
  205. package/web/dist/assets/pie-ZZUOXDRM-DRoETpJX.js +1 -0
  206. package/web/dist/assets/pieDiagram-DEJITSTG-DfMjfTQz.js +30 -0
  207. package/web/dist/assets/preload-helper-DSXbuxSR.js +1 -0
  208. package/web/dist/assets/quadrantDiagram-34T5L4WZ-DfBSEept.js +7 -0
  209. package/web/dist/assets/radar-PYXPWWZC-DLKxRJ0V.js +1 -0
  210. package/web/dist/assets/reduce-836A2NiQ.js +1 -0
  211. package/web/dist/assets/requirementDiagram-MS252O5E-BPkxJQkz.js +84 -0
  212. package/web/dist/assets/rough.esm-Djo4Abte.js +1 -0
  213. package/web/dist/assets/sankeyDiagram-XADWPNL6-He3x9tNT.js +10 -0
  214. package/web/dist/assets/sequenceDiagram-FGHM5R23-DfCDpvrT.js +157 -0
  215. package/web/dist/assets/src-DdOdIreR.js +1 -0
  216. package/web/dist/assets/stateDiagram-FHFEXIEX-fuww6347.js +1 -0
  217. package/web/dist/assets/stateDiagram-v2-QKLJ7IA2-U6voafO3.js +1 -0
  218. package/web/dist/assets/timeline-definition-GMOUNBTQ-BWunHgBC.js +120 -0
  219. package/web/dist/assets/transform-messages-CqKEdRVp.js +1 -0
  220. package/web/dist/assets/transformers.web-DKUtmSAi.js +2818 -0
  221. package/web/dist/assets/treeView-SZITEDCU-BCx0xSAm.js +1 -0
  222. package/web/dist/assets/treemap-W4RFUUIX-2CvghWJK.js +1 -0
  223. package/web/dist/assets/vennDiagram-DHZGUBPP-CBXRutSP.js +34 -0
  224. package/web/dist/assets/wardley-RL74JXVD-BkPL_mhd.js +1 -0
  225. package/web/dist/assets/wardleyDiagram-NUSXRM2D-DTcVscPH.js +20 -0
  226. package/web/dist/assets/web-CMKYLKbT.js +10 -0
  227. package/web/dist/assets/xychartDiagram-5P7HB3ND-CZLgX9Fe.js +7 -0
  228. package/web/dist/favicon.svg +10 -0
  229. package/web/dist/index.html +104 -0
  230. package/web/dist/keating-metaharness.pdf +10557 -3
  231. package/web/dist/llms.txt +44 -0
  232. package/web/dist/logo.png +0 -0
  233. package/web/dist/manifest.webmanifest +1 -0
  234. package/web/dist/og-image.png +0 -0
  235. package/web/dist/pwa-192x192.svg +10 -0
  236. package/web/dist/pwa-512x512.svg +10 -0
  237. package/web/dist/registerSW.js +1 -0
  238. package/web/dist/robots.txt +8 -0
  239. package/web/dist/sitemap.xml +39 -0
  240. package/web/dist/sw.js +1 -0
  241. package/web/dist/tapes/doctor.mp4 +0 -0
  242. package/web/dist/tapes/feedback-flow.mp4 +0 -0
  243. package/web/dist/tapes/improve-flow.mp4 +0 -0
  244. package/web/dist/tapes/intro.mp4 +0 -0
  245. package/web/dist/tapes/learning-flow.mp4 +0 -0
  246. package/web/dist/tapes/session-flow.mp4 +0 -0
  247. package/web/dist/tapes/teacher-flow.mp4 +0 -0
  248. package/web/dist/tapes/tests.mp4 +0 -0
  249. package/web/dist/workbox-66610c77.js +1 -0
@@ -0,0 +1,2818 @@
1
+ import{a as e,r as t}from"./chunk-Bj-mKKzh.js";import{t as n}from"./preload-helper-DSXbuxSR.js";var r=new Map,i=[],a=(e,t,n)=>{if(t&&typeof t.init==`function`&&typeof t.createInferenceSessionHandler==`function`){let a=r.get(e);if(a===void 0)r.set(e,{backend:t,priority:n});else if(a.priority>n)return;else if(a.priority===n&&a.backend!==t)throw Error(`cannot register backend "${e}" using priority ${n}`);if(n>=0){let t=i.indexOf(e);t!==-1&&i.splice(t,1);for(let t=0;t<i.length;t++)if(r.get(i[t]).priority<=n){i.splice(t,0,e);return}i.push(e)}return}throw TypeError(`not a valid backend`)},o=async e=>{let t=r.get(e);if(!t)return`backend not found.`;if(t.initialized)return t.backend;if(t.aborted)return t.error;{let n=!!t.initPromise;try{return n||(t.initPromise=t.backend.init(e)),await t.initPromise,t.initialized=!0,t.backend}catch(e){return n||(t.error=`${e}`,t.aborted=!0),t.error}finally{delete t.initPromise}}},s=async e=>{let t=e.executionProviders||[],n=t.map(e=>typeof e==`string`?e:e.name),r=n.length===0?i:n,a,s=[],c=new Set;for(let e of r){let t=await o(e);typeof t==`string`?s.push({name:e,err:t}):(a||=t,a===t&&c.add(e))}if(!a)throw Error(`no available backend found. ERR: ${s.map(e=>`[${e.name}] ${e.err}`).join(`, `)}`);for(let{name:e,err:t}of s)n.includes(e)&&console.warn(`removing requested execution provider "${e}" from session options because it is not available: ${t}`);let l=t.filter(e=>c.has(typeof e==`string`?e:e.name));return[a,new Proxy(e,{get:(e,t)=>t===`executionProviders`?l:Reflect.get(e,t)})]},c=`1.21.0`,l=`warning`,u={wasm:{},webgl:{},webgpu:{},versions:{common:c},set logLevel(e){if(e!==void 0){if(typeof e!=`string`||[`verbose`,`info`,`warning`,`error`,`fatal`].indexOf(e)===-1)throw Error(`Unsupported logging level: ${e}`);l=e}},get logLevel(){return l}};Object.defineProperty(u,`logLevel`,{enumerable:!0});var d=u,f=(e,t)=>{let n=typeof document<`u`?document.createElement(`canvas`):new OffscreenCanvas(1,1);n.width=e.dims[3],n.height=e.dims[2];let r=n.getContext(`2d`);if(r!=null){let i,a;t?.tensorLayout!==void 0&&t.tensorLayout===`NHWC`?(i=e.dims[2],a=e.dims[3]):(i=e.dims[3],a=e.dims[2]);let o=t?.format===void 0?`RGB`:t.format,s=t?.norm,c,l;s===void 0||s.mean===void 0?c=[255,255,255,255]:typeof s.mean==`number`?c=[s.mean,s.mean,s.mean,s.mean]:(c=[s.mean[0],s.mean[1],s.mean[2],0],s.mean[3]!==void 0&&(c[3]=s.mean[3])),s===void 0||s.bias===void 0?l=[0,0,0,0]:typeof s.bias==`number`?l=[s.bias,s.bias,s.bias,s.bias]:(l=[s.bias[0],s.bias[1],s.bias[2],0],s.bias[3]!==void 0&&(l[3]=s.bias[3]));let u=a*i,d=0,f=u,p=u*2,m=-1;o===`RGBA`?(d=0,f=u,p=u*2,m=u*3):o===`RGB`?(d=0,f=u,p=u*2):o===`RBG`&&(d=0,p=u,f=u*2);for(let t=0;t<a;t++)for(let n=0;n<i;n++){let i=(e.data[d++]-l[0])*c[0],a=(e.data[f++]-l[1])*c[1],o=(e.data[p++]-l[2])*c[2],s=m===-1?255:(e.data[m++]-l[3])*c[3];r.fillStyle=`rgba(`+i+`,`+a+`,`+o+`,`+s+`)`,r.fillRect(n,t,1,1)}if(`toDataURL`in n)return n.toDataURL();throw Error(`toDataURL is not supported`)}else throw Error(`Can not access image data`)},p=(e,t)=>{let n=typeof document<`u`?document.createElement(`canvas`).getContext(`2d`):new OffscreenCanvas(1,1).getContext(`2d`),r;if(n!=null){let i,a,o;t?.tensorLayout!==void 0&&t.tensorLayout===`NHWC`?(i=e.dims[2],a=e.dims[1],o=e.dims[3]):(i=e.dims[3],a=e.dims[2],o=e.dims[1]);let s=t===void 0||t.format===void 0?`RGB`:t.format,c=t?.norm,l,u;c===void 0||c.mean===void 0?l=[255,255,255,255]:typeof c.mean==`number`?l=[c.mean,c.mean,c.mean,c.mean]:(l=[c.mean[0],c.mean[1],c.mean[2],255],c.mean[3]!==void 0&&(l[3]=c.mean[3])),c===void 0||c.bias===void 0?u=[0,0,0,0]:typeof c.bias==`number`?u=[c.bias,c.bias,c.bias,c.bias]:(u=[c.bias[0],c.bias[1],c.bias[2],0],c.bias[3]!==void 0&&(u[3]=c.bias[3]));let d=a*i;if(t!==void 0&&(t.format!==void 0&&o===4&&t.format!==`RGBA`||o===3&&t.format!==`RGB`&&t.format!==`BGR`))throw Error(`Tensor format doesn't match input tensor dims`);let f=0,p=1,m=2,h=3,g=0,_=d,v=d*2,y=-1;s===`RGBA`?(g=0,_=d,v=d*2,y=d*3):s===`RGB`?(g=0,_=d,v=d*2):s===`RBG`&&(g=0,v=d,_=d*2),r=n.createImageData(i,a);for(let t=0;t<a*i;f+=4,p+=4,m+=4,h+=4,t++)r.data[f]=(e.data[g++]-u[0])*l[0],r.data[p]=(e.data[_++]-u[1])*l[1],r.data[m]=(e.data[v++]-u[2])*l[2],r.data[h]=y===-1?255:(e.data[y++]-u[3])*l[3]}else throw Error(`Can not access image data`);return r},m=(e,t)=>{if(e===void 0)throw Error(`Image buffer must be defined`);if(t.height===void 0||t.width===void 0)throw Error(`Image height and width must be defined`);if(t.tensorLayout===`NHWC`)throw Error(`NHWC Tensor layout is not supported yet`);let{height:n,width:r}=t,i=t.norm??{mean:255,bias:0},a,o;a=typeof i.mean==`number`?[i.mean,i.mean,i.mean,i.mean]:[i.mean[0],i.mean[1],i.mean[2],i.mean[3]??255],o=typeof i.bias==`number`?[i.bias,i.bias,i.bias,i.bias]:[i.bias[0],i.bias[1],i.bias[2],i.bias[3]??0];let s=t.format===void 0?`RGBA`:t.format,c=t.tensorFormat===void 0||t.tensorFormat===void 0?`RGB`:t.tensorFormat,l=n*r,u=c===`RGBA`?new Float32Array(l*4):new Float32Array(l*3),d=4,f=0,p=1,m=2,h=3,g=0,_=l,v=l*2,y=-1;s===`RGB`&&(d=3,f=0,p=1,m=2,h=-1),c===`RGBA`?y=l*3:c===`RBG`?(g=0,v=l,_=l*2):c===`BGR`&&(v=0,_=l,g=l*2);for(let t=0;t<l;t++,f+=d,m+=d,p+=d,h+=d)u[g++]=(e[f]+o[0])/a[0],u[_++]=(e[p]+o[1])/a[1],u[v++]=(e[m]+o[2])/a[2],y!==-1&&h!==-1&&(u[y++]=(e[h]+o[3])/a[3]);return c===`RGBA`?new E(`float32`,u,[1,4,n,r]):new E(`float32`,u,[1,3,n,r])},h=async(e,t)=>{let n=typeof HTMLImageElement<`u`&&e instanceof HTMLImageElement,r=typeof ImageData<`u`&&e instanceof ImageData,i=typeof ImageBitmap<`u`&&e instanceof ImageBitmap,a=typeof e==`string`,o,s=t??{},c=()=>{if(typeof document<`u`)return document.createElement(`canvas`);if(typeof OffscreenCanvas<`u`)return new OffscreenCanvas(1,1);throw Error(`Canvas is not supported`)},l=e=>typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement||e instanceof OffscreenCanvas?e.getContext(`2d`):null;if(n){let n=c();n.width=e.width,n.height=e.height;let r=l(n);if(r!=null){let n=e.height,i=e.width;if(t!==void 0&&t.resizedHeight!==void 0&&t.resizedWidth!==void 0&&(n=t.resizedHeight,i=t.resizedWidth),t!==void 0){if(s=t,t.tensorFormat!==void 0)throw Error(`Image input config format must be RGBA for HTMLImageElement`);s.tensorFormat=`RGBA`,s.height=n,s.width=i}else s.tensorFormat=`RGBA`,s.height=n,s.width=i;r.drawImage(e,0,0),o=r.getImageData(0,0,i,n).data}else throw Error(`Can not access image data`)}else if(r){let n,r;if(t!==void 0&&t.resizedWidth!==void 0&&t.resizedHeight!==void 0?(n=t.resizedHeight,r=t.resizedWidth):(n=e.height,r=e.width),t!==void 0&&(s=t),s.format=`RGBA`,s.height=n,s.width=r,t!==void 0){let t=c();t.width=r,t.height=n;let i=l(t);if(i!=null)i.putImageData(e,0,0),o=i.getImageData(0,0,r,n).data;else throw Error(`Can not access image data`)}else o=e.data}else if(i){if(t===void 0)throw Error(`Please provide image config with format for Imagebitmap`);let n=c();n.width=e.width,n.height=e.height;let r=l(n);if(r!=null){let t=e.height,n=e.width;return r.drawImage(e,0,0,n,t),o=r.getImageData(0,0,n,t).data,s.height=t,s.width=n,m(o,s)}else throw Error(`Can not access image data`)}else if(a)return new Promise((t,n)=>{let r=c(),i=l(r);if(!e||!i)return n();let a=new Image;a.crossOrigin=`Anonymous`,a.src=e,a.onload=()=>{r.width=a.width,r.height=a.height,i.drawImage(a,0,0,r.width,r.height);let e=i.getImageData(0,0,r.width,r.height);s.height=r.height,s.width=r.width,t(m(e.data,s))}});else throw Error(`Input data provided is not supported - aborted tensor creation`);if(o!==void 0)return m(o,s);throw Error(`Input data provided is not supported - aborted tensor creation`)},g=(e,t)=>{let{width:n,height:r,download:i,dispose:a}=t;return new E({location:`texture`,type:`float32`,texture:e,dims:[1,r,n,4],download:i,dispose:a})},_=(e,t)=>{let{dataType:n,dims:r,download:i,dispose:a}=t;return new E({location:`gpu-buffer`,type:n??`float32`,gpuBuffer:e,dims:r,download:i,dispose:a})},v=(e,t)=>{let{dataType:n,dims:r,download:i,dispose:a}=t;return new E({location:`ml-tensor`,type:n??`float32`,mlTensor:e,dims:r,download:i,dispose:a})},y=(e,t,n)=>new E({location:`cpu-pinned`,type:e,data:t,dims:n??[t.length]}),b=new Map([[`float32`,Float32Array],[`uint8`,Uint8Array],[`int8`,Int8Array],[`uint16`,Uint16Array],[`int16`,Int16Array],[`int32`,Int32Array],[`bool`,Uint8Array],[`float64`,Float64Array],[`uint32`,Uint32Array],[`int4`,Uint8Array],[`uint4`,Uint8Array]]),x=new Map([[Float32Array,`float32`],[Uint8Array,`uint8`],[Int8Array,`int8`],[Uint16Array,`uint16`],[Int16Array,`int16`],[Int32Array,`int32`],[Float64Array,`float64`],[Uint32Array,`uint32`]]),S=!1,C=()=>{if(!S){S=!0;let e=typeof BigInt64Array<`u`&&BigInt64Array.from,t=typeof BigUint64Array<`u`&&BigUint64Array.from,n=globalThis.Float16Array,r=n!==void 0&&n.from;e&&(b.set(`int64`,BigInt64Array),x.set(BigInt64Array,`int64`)),t&&(b.set(`uint64`,BigUint64Array),x.set(BigUint64Array,`uint64`)),r?(b.set(`float16`,n),x.set(n,`float16`)):b.set(`float16`,Uint16Array)}},w=e=>{let t=1;for(let n=0;n<e.length;n++){let r=e[n];if(typeof r!=`number`||!Number.isSafeInteger(r))throw TypeError(`dims[${n}] must be an integer, got: ${r}`);if(r<0)throw RangeError(`dims[${n}] must be a non-negative integer, got: ${r}`);t*=r}return t},T=(e,t)=>{switch(e.location){case`cpu`:return new E(e.type,e.data,t);case`cpu-pinned`:return new E({location:`cpu-pinned`,data:e.data,type:e.type,dims:t});case`texture`:return new E({location:`texture`,texture:e.texture,type:e.type,dims:t});case`gpu-buffer`:return new E({location:`gpu-buffer`,gpuBuffer:e.gpuBuffer,type:e.type,dims:t});case`ml-tensor`:return new E({location:`ml-tensor`,mlTensor:e.mlTensor,type:e.type,dims:t});default:throw Error(`tensorReshape: tensor location ${e.location} is not supported`)}},E=class{constructor(e,t,n){C();let r,i;if(typeof e==`object`&&`location`in e)switch(this.dataLocation=e.location,r=e.type,i=e.dims,e.location){case`cpu-pinned`:{let t=b.get(r);if(!t)throw TypeError(`unsupported type "${r}" to create tensor from pinned buffer`);if(!(e.data instanceof t))throw TypeError(`buffer should be of type ${t.name}`);this.cpuData=e.data;break}case`texture`:if(r!==`float32`)throw TypeError(`unsupported type "${r}" to create tensor from texture`);this.gpuTextureData=e.texture,this.downloader=e.download,this.disposer=e.dispose;break;case`gpu-buffer`:if(r!==`float32`&&r!==`float16`&&r!==`int32`&&r!==`int64`&&r!==`uint32`&&r!==`uint8`&&r!==`bool`&&r!==`uint4`&&r!==`int4`)throw TypeError(`unsupported type "${r}" to create tensor from gpu buffer`);this.gpuBufferData=e.gpuBuffer,this.downloader=e.download,this.disposer=e.dispose;break;case`ml-tensor`:if(r!==`float32`&&r!==`float16`&&r!==`int32`&&r!==`int64`&&r!==`uint32`&&r!==`uint64`&&r!==`int8`&&r!==`uint8`&&r!==`bool`&&r!==`uint4`&&r!==`int4`)throw TypeError(`unsupported type "${r}" to create tensor from MLTensor`);this.mlTensorData=e.mlTensor,this.downloader=e.download,this.disposer=e.dispose;break;default:throw Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let a,o;if(typeof e==`string`)if(r=e,o=n,e===`string`){if(!Array.isArray(t))throw TypeError(`A string tensor's data must be a string array.`);a=t}else{let n=b.get(e);if(n===void 0)throw TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(t)){if(e===`float16`&&n===Uint16Array||e===`uint4`||e===`int4`)throw TypeError(`Creating a ${e} tensor from number array is not supported. Please use ${n.name} as data.`);a=e===`uint64`||e===`int64`?n.from(t,BigInt):n.from(t)}else if(t instanceof n)a=t;else if(t instanceof Uint8ClampedArray)if(e===`uint8`)a=Uint8Array.from(t);else throw TypeError(`A Uint8ClampedArray tensor's data must be type of uint8`);else if(e===`float16`&&t instanceof Uint16Array&&n!==Uint16Array)a=new globalThis.Float16Array(t.buffer,t.byteOffset,t.length);else throw TypeError(`A ${r} tensor's data must be type of ${n}`)}else if(o=t,Array.isArray(e)){if(e.length===0)throw TypeError(`Tensor type cannot be inferred from an empty array.`);let t=typeof e[0];if(t===`string`)r=`string`,a=e;else if(t===`boolean`)r=`bool`,a=Uint8Array.from(e);else throw TypeError(`Invalid element type of data array: ${t}.`)}else if(e instanceof Uint8ClampedArray)r=`uint8`,a=Uint8Array.from(e);else{let t=x.get(e.constructor);if(t===void 0)throw TypeError(`Unsupported type for tensor data: ${e.constructor}.`);r=t,a=e}if(o===void 0)o=[a.length];else if(!Array.isArray(o))throw TypeError(`A tensor's dims must be a number array`);i=o,this.cpuData=a,this.dataLocation=`cpu`}let a=w(i);if(this.cpuData&&a!==this.cpuData.length&&!((r===`uint4`||r===`int4`)&&Math.ceil(a/2)===this.cpuData.length))throw Error(`Tensor's size(${a}) does not match data length(${this.cpuData.length}).`);this.type=r,this.dims=i,this.size=a}static async fromImage(e,t){return h(e,t)}static fromTexture(e,t){return g(e,t)}static fromGpuBuffer(e,t){return _(e,t)}static fromMLTensor(e,t){return v(e,t)}static fromPinnedBuffer(e,t,n){return y(e,t,n)}toDataURL(e){return f(this,e)}toImageData(e){return p(this,e)}get data(){if(this.ensureValid(),!this.cpuData)throw Error("The data is not on CPU. Use `getData()` to download GPU data to CPU, or use `texture` or `gpuBuffer` property to access the GPU data directly.");return this.cpuData}get location(){return this.dataLocation}get texture(){if(this.ensureValid(),!this.gpuTextureData)throw Error(`The data is not stored as a WebGL texture.`);return this.gpuTextureData}get gpuBuffer(){if(this.ensureValid(),!this.gpuBufferData)throw Error(`The data is not stored as a WebGPU buffer.`);return this.gpuBufferData}get mlTensor(){if(this.ensureValid(),!this.mlTensorData)throw Error(`The data is not stored as a WebNN MLTensor.`);return this.mlTensorData}async getData(e){switch(this.ensureValid(),this.dataLocation){case`cpu`:case`cpu-pinned`:return this.data;case`texture`:case`gpu-buffer`:case`ml-tensor`:if(!this.downloader)throw Error(`The current tensor is not created with a specified data downloader.`);if(this.isDownloading)throw Error(`The current tensor is being downloaded.`);try{this.isDownloading=!0;let t=await this.downloader();return this.downloader=void 0,this.dataLocation=`cpu`,this.cpuData=t,e&&this.disposer&&(this.disposer(),this.disposer=void 0),t}finally{this.isDownloading=!1}default:throw Error(`cannot get data from location: ${this.dataLocation}`)}}dispose(){if(this.isDownloading)throw Error(`The current tensor is being downloaded.`);this.disposer&&=(this.disposer(),void 0),this.cpuData=void 0,this.gpuTextureData=void 0,this.gpuBufferData=void 0,this.mlTensorData=void 0,this.downloader=void 0,this.isDownloading=void 0,this.dataLocation=`none`}ensureValid(){if(this.dataLocation===`none`)throw Error(`The tensor is disposed.`)}reshape(e){if(this.ensureValid(),this.downloader||this.disposer)throw Error(`Cannot reshape a tensor that owns GPU resource.`);return T(this,e)}},D=E,O=(e,t)=>{(u.trace===void 0?!u.wasm.trace:!u.trace)||console.timeStamp(`${e}::ORT::${t}`)},k=(e,t)=>{let n=Error().stack?.split(/\r\n|\r|\n/g)||[],r=!1;for(let i=0;i<n.length;i++){if(r&&!n[i].includes(`TRACE_FUNC`)){let r=`FUNC_${e}::${n[i].trim().split(` `)[1]}`;t&&(r+=`::${t}`),O(`CPU`,r);return}n[i].includes(`TRACE_FUNC`)&&(r=!0)}},A=e=>{(u.trace===void 0?!u.wasm.trace:!u.trace)||k(`BEGIN`,e)},ee=e=>{(u.trace===void 0?!u.wasm.trace:!u.trace)||k(`END`,e)},te=class e{constructor(e){this.handler=e}async run(e,t,n){A();let r={},i={};if(typeof e!=`object`||!e||e instanceof D||Array.isArray(e))throw TypeError(`'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.`);let a=!0;if(typeof t==`object`){if(t===null)throw TypeError(`Unexpected argument[1]: cannot be null.`);if(t instanceof D)throw TypeError(`'fetches' cannot be a Tensor`);if(Array.isArray(t)){if(t.length===0)throw TypeError(`'fetches' cannot be an empty array.`);a=!1;for(let e of t){if(typeof e!=`string`)throw TypeError(`'fetches' must be a string array or an object.`);if(this.outputNames.indexOf(e)===-1)throw RangeError(`'fetches' contains invalid output name: ${e}.`);r[e]=null}if(typeof n==`object`&&n)i=n;else if(n!==void 0)throw TypeError(`'options' must be an object.`)}else{let e=!1,o=Object.getOwnPropertyNames(t);for(let n of this.outputNames)if(o.indexOf(n)!==-1){let i=t[n];(i===null||i instanceof D)&&(e=!0,a=!1,r[n]=i)}if(e){if(typeof n==`object`&&n)i=n;else if(n!==void 0)throw TypeError(`'options' must be an object.`)}else i=t}}else if(t!==void 0)throw TypeError(`Unexpected argument[1]: must be 'fetches' or 'options'.`);for(let t of this.inputNames)if(e[t]===void 0)throw Error(`input '${t}' is missing in 'feeds'.`);if(a)for(let e of this.outputNames)r[e]=null;let o=await this.handler.run(e,r,i),s={};for(let e in o)if(Object.hasOwnProperty.call(o,e)){let t=o[e];t instanceof D?s[e]=t:s[e]=new D(t.type,t.data,t.dims)}return ee(),s}async release(){return this.handler.dispose()}static async create(t,n,r,i){A();let a,o={};if(typeof t==`string`){if(a=t,typeof n==`object`&&n)o=n;else if(n!==void 0)throw TypeError(`'options' must be an object.`)}else if(t instanceof Uint8Array){if(a=t,typeof n==`object`&&n)o=n;else if(n!==void 0)throw TypeError(`'options' must be an object.`)}else if(t instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&t instanceof SharedArrayBuffer){let e=t,s=0,c=t.byteLength;if(typeof n==`object`&&n)o=n;else if(typeof n==`number`){if(s=n,!Number.isSafeInteger(s))throw RangeError(`'byteOffset' must be an integer.`);if(s<0||s>=e.byteLength)throw RangeError(`'byteOffset' is out of range [0, ${e.byteLength}).`);if(c=t.byteLength-s,typeof r==`number`){if(c=r,!Number.isSafeInteger(c))throw RangeError(`'byteLength' must be an integer.`);if(c<=0||s+c>e.byteLength)throw RangeError(`'byteLength' is out of range (0, ${e.byteLength-s}].`);if(typeof i==`object`&&i)o=i;else if(i!==void 0)throw TypeError(`'options' must be an object.`)}else if(r!==void 0)throw TypeError(`'byteLength' must be a number.`)}else if(n!==void 0)throw TypeError(`'options' must be an object.`);a=new Uint8Array(e,s,c)}else throw TypeError(`Unexpected argument[0]: must be 'path' or 'buffer'.`);let[c,l]=await s(o),u=await c.createInferenceSessionHandler(a,l);return ee(),new e(u)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}},ne=t({InferenceSession:()=>te,TRACE:()=>O,TRACE_FUNC_BEGIN:()=>A,TRACE_FUNC_END:()=>ee,Tensor:()=>D,env:()=>d,registerBackend:()=>a}),j=t({InferenceSession:()=>Ge,TRACE:()=>Be,TRACE_FUNC_BEGIN:()=>Ve,TRACE_FUNC_END:()=>He,Tensor:()=>Re,default:()=>tf,env:()=>I,registerBackend:()=>fe}),re=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,ae=Object.getOwnPropertyNames,oe=Object.prototype.hasOwnProperty,se=(t=>typeof e<`u`?e:typeof Proxy<`u`?new Proxy(t,{get:(t,n)=>(typeof e<`u`?e:t)[n]}):t)(function(t){if(typeof e<`u`)return e.apply(this,arguments);throw Error(`Dynamic require of "`+t+`" is not supported`)}),M=(e,t)=>()=>(e&&(t=e(e=0)),t),N=(e,t)=>{for(var n in t)re(e,n,{get:t[n],enumerable:!0})},ce=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let i of ae(t))!oe.call(e,i)&&i!==n&&re(e,i,{get:()=>t[i],enumerable:!(r=ie(t,i))||r.enumerable});return e},le=e=>ce(re({},`__esModule`,{value:!0}),e),ue,de,fe,pe,P,me=M(()=>{ue=new Map,de=[],fe=(e,t,n)=>{if(t&&typeof t.init==`function`&&typeof t.createInferenceSessionHandler==`function`){let r=ue.get(e);if(r===void 0)ue.set(e,{backend:t,priority:n});else{if(r.priority>n)return;if(r.priority===n&&r.backend!==t)throw Error(`cannot register backend "${e}" using priority ${n}`)}if(n>=0){let t=de.indexOf(e);t!==-1&&de.splice(t,1);for(let t=0;t<de.length;t++)if(ue.get(de[t]).priority<=n){de.splice(t,0,e);return}de.push(e)}return}throw TypeError(`not a valid backend`)},pe=async e=>{let t=ue.get(e);if(!t)return`backend not found.`;if(t.initialized)return t.backend;if(t.aborted)return t.error;{let n=!!t.initPromise;try{return n||(t.initPromise=t.backend.init(e)),await t.initPromise,t.initialized=!0,t.backend}catch(e){return n||(t.error=`${e}`,t.aborted=!0),t.error}finally{delete t.initPromise}}},P=async e=>{let t=e.executionProviders||[],n=t.map(e=>typeof e==`string`?e:e.name),r=n.length===0?de:n,i,a=[],o=new Set;for(let e of r){let t=await pe(e);typeof t==`string`?a.push({name:e,err:t}):(i||=t,i===t&&o.add(e))}if(!i)throw Error(`no available backend found. ERR: ${a.map(e=>`[${e.name}] ${e.err}`).join(`, `)}`);for(let{name:e,err:t}of a)n.includes(e)&&console.warn(`removing requested execution provider "${e}" from session options because it is not available: ${t}`);let s=t.filter(e=>o.has(typeof e==`string`?e:e.name));return[i,new Proxy(e,{get:(e,t)=>t===`executionProviders`?s:Reflect.get(e,t)})]}}),he=M(()=>{me()}),ge,_e=M(()=>{ge=`1.22.0-dev.20250409-89f8206ba4`}),ve,F,ye=M(()=>{_e(),ve=`warning`,F={wasm:{},webgl:{},webgpu:{},versions:{common:ge},set logLevel(e){if(e!==void 0){if(typeof e!=`string`||[`verbose`,`info`,`warning`,`error`,`fatal`].indexOf(e)===-1)throw Error(`Unsupported logging level: ${e}`);ve=e}},get logLevel(){return ve}},Object.defineProperty(F,`logLevel`,{enumerable:!0})}),I,L=M(()=>{ye(),I=F}),be,xe,Se=M(()=>{be=(e,t)=>{let n=typeof document<`u`?document.createElement(`canvas`):new OffscreenCanvas(1,1);n.width=e.dims[3],n.height=e.dims[2];let r=n.getContext(`2d`);if(r!=null){let i,a;t?.tensorLayout!==void 0&&t.tensorLayout===`NHWC`?(i=e.dims[2],a=e.dims[3]):(i=e.dims[3],a=e.dims[2]);let o=t?.format===void 0?`RGB`:t.format,s=t?.norm,c,l;s===void 0||s.mean===void 0?c=[255,255,255,255]:typeof s.mean==`number`?c=[s.mean,s.mean,s.mean,s.mean]:(c=[s.mean[0],s.mean[1],s.mean[2],0],s.mean[3]!==void 0&&(c[3]=s.mean[3])),s===void 0||s.bias===void 0?l=[0,0,0,0]:typeof s.bias==`number`?l=[s.bias,s.bias,s.bias,s.bias]:(l=[s.bias[0],s.bias[1],s.bias[2],0],s.bias[3]!==void 0&&(l[3]=s.bias[3]));let u=a*i,d=0,f=u,p=u*2,m=-1;o===`RGBA`?(d=0,f=u,p=u*2,m=u*3):o===`RGB`?(d=0,f=u,p=u*2):o===`RBG`&&(d=0,p=u,f=u*2);for(let t=0;t<a;t++)for(let n=0;n<i;n++){let i=(e.data[d++]-l[0])*c[0],a=(e.data[f++]-l[1])*c[1],o=(e.data[p++]-l[2])*c[2],s=m===-1?255:(e.data[m++]-l[3])*c[3];r.fillStyle=`rgba(`+i+`,`+a+`,`+o+`,`+s+`)`,r.fillRect(n,t,1,1)}if(`toDataURL`in n)return n.toDataURL();throw Error(`toDataURL is not supported`)}else throw Error(`Can not access image data`)},xe=(e,t)=>{let n=typeof document<`u`?document.createElement(`canvas`).getContext(`2d`):new OffscreenCanvas(1,1).getContext(`2d`),r;if(n!=null){let i,a,o;t?.tensorLayout!==void 0&&t.tensorLayout===`NHWC`?(i=e.dims[2],a=e.dims[1],o=e.dims[3]):(i=e.dims[3],a=e.dims[2],o=e.dims[1]);let s=t!==void 0&&t.format!==void 0?t.format:`RGB`,c=t?.norm,l,u;c===void 0||c.mean===void 0?l=[255,255,255,255]:typeof c.mean==`number`?l=[c.mean,c.mean,c.mean,c.mean]:(l=[c.mean[0],c.mean[1],c.mean[2],255],c.mean[3]!==void 0&&(l[3]=c.mean[3])),c===void 0||c.bias===void 0?u=[0,0,0,0]:typeof c.bias==`number`?u=[c.bias,c.bias,c.bias,c.bias]:(u=[c.bias[0],c.bias[1],c.bias[2],0],c.bias[3]!==void 0&&(u[3]=c.bias[3]));let d=a*i;if(t!==void 0&&(t.format!==void 0&&o===4&&t.format!==`RGBA`||o===3&&t.format!==`RGB`&&t.format!==`BGR`))throw Error(`Tensor format doesn't match input tensor dims`);let f=0,p=1,m=2,h=3,g=0,_=d,v=d*2,y=-1;s===`RGBA`?(g=0,_=d,v=d*2,y=d*3):s===`RGB`?(g=0,_=d,v=d*2):s===`RBG`&&(g=0,v=d,_=d*2),r=n.createImageData(i,a);for(let t=0;t<a*i;f+=4,p+=4,m+=4,h+=4,t++)r.data[f]=(e.data[g++]-u[0])*l[0],r.data[p]=(e.data[_++]-u[1])*l[1],r.data[m]=(e.data[v++]-u[2])*l[2],r.data[h]=y===-1?255:(e.data[y++]-u[3])*l[3]}else throw Error(`Can not access image data`);return r}}),R,Ce,z,we,Te,Ee,De=M(()=>{Le(),R=(e,t)=>{if(e===void 0)throw Error(`Image buffer must be defined`);if(t.height===void 0||t.width===void 0)throw Error(`Image height and width must be defined`);if(t.tensorLayout===`NHWC`)throw Error(`NHWC Tensor layout is not supported yet`);let{height:n,width:r}=t,i=t.norm??{mean:255,bias:0},a,o;a=typeof i.mean==`number`?[i.mean,i.mean,i.mean,i.mean]:[i.mean[0],i.mean[1],i.mean[2],i.mean[3]??255],o=typeof i.bias==`number`?[i.bias,i.bias,i.bias,i.bias]:[i.bias[0],i.bias[1],i.bias[2],i.bias[3]??0];let s=t.format===void 0?`RGBA`:t.format,c=t.tensorFormat!==void 0&&t.tensorFormat!==void 0?t.tensorFormat:`RGB`,l=n*r,u=c===`RGBA`?new Float32Array(l*4):new Float32Array(l*3),d=4,f=0,p=1,m=2,h=3,g=0,_=l,v=l*2,y=-1;s===`RGB`&&(d=3,f=0,p=1,m=2,h=-1),c===`RGBA`?y=l*3:c===`RBG`?(g=0,v=l,_=l*2):c===`BGR`&&(v=0,_=l,g=l*2);for(let t=0;t<l;t++,f+=d,m+=d,p+=d,h+=d)u[g++]=(e[f]+o[0])/a[0],u[_++]=(e[p]+o[1])/a[1],u[v++]=(e[m]+o[2])/a[2],y!==-1&&h!==-1&&(u[y++]=(e[h]+o[3])/a[3]);return c===`RGBA`?new Ie(`float32`,u,[1,4,n,r]):new Ie(`float32`,u,[1,3,n,r])},Ce=async(e,t)=>{let n=typeof HTMLImageElement<`u`&&e instanceof HTMLImageElement,r=typeof ImageData<`u`&&e instanceof ImageData,i=typeof ImageBitmap<`u`&&e instanceof ImageBitmap,a=typeof e==`string`,o,s=t??{},c=()=>{if(typeof document<`u`)return document.createElement(`canvas`);if(typeof OffscreenCanvas<`u`)return new OffscreenCanvas(1,1);throw Error(`Canvas is not supported`)},l=e=>typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement||e instanceof OffscreenCanvas?e.getContext(`2d`):null;if(n){let n=c();n.width=e.width,n.height=e.height;let r=l(n);if(r!=null){let n=e.height,i=e.width;if(t!==void 0&&t.resizedHeight!==void 0&&t.resizedWidth!==void 0&&(n=t.resizedHeight,i=t.resizedWidth),t!==void 0){if(s=t,t.tensorFormat!==void 0)throw Error(`Image input config format must be RGBA for HTMLImageElement`);s.tensorFormat=`RGBA`,s.height=n,s.width=i}else s.tensorFormat=`RGBA`,s.height=n,s.width=i;r.drawImage(e,0,0),o=r.getImageData(0,0,i,n).data}else throw Error(`Can not access image data`)}else if(r){let n,r;if(t!==void 0&&t.resizedWidth!==void 0&&t.resizedHeight!==void 0?(n=t.resizedHeight,r=t.resizedWidth):(n=e.height,r=e.width),t!==void 0&&(s=t),s.format=`RGBA`,s.height=n,s.width=r,t!==void 0){let t=c();t.width=r,t.height=n;let i=l(t);if(i!=null)i.putImageData(e,0,0),o=i.getImageData(0,0,r,n).data;else throw Error(`Can not access image data`)}else o=e.data}else if(i){if(t===void 0)throw Error(`Please provide image config with format for Imagebitmap`);let n=c();n.width=e.width,n.height=e.height;let r=l(n);if(r!=null){let t=e.height,n=e.width;return r.drawImage(e,0,0,n,t),o=r.getImageData(0,0,n,t).data,s.height=t,s.width=n,R(o,s)}else throw Error(`Can not access image data`)}else{if(a)return new Promise((t,n)=>{let r=c(),i=l(r);if(!e||!i)return n();let a=new Image;a.crossOrigin=`Anonymous`,a.src=e,a.onload=()=>{r.width=a.width,r.height=a.height,i.drawImage(a,0,0,r.width,r.height);let e=i.getImageData(0,0,r.width,r.height);s.height=r.height,s.width=r.width,t(R(e.data,s))}});throw Error(`Input data provided is not supported - aborted tensor creation`)}if(o!==void 0)return R(o,s);throw Error(`Input data provided is not supported - aborted tensor creation`)},z=(e,t)=>{let{width:n,height:r,download:i,dispose:a}=t;return new Ie({location:`texture`,type:`float32`,texture:e,dims:[1,r,n,4],download:i,dispose:a})},we=(e,t)=>{let{dataType:n,dims:r,download:i,dispose:a}=t;return new Ie({location:`gpu-buffer`,type:n??`float32`,gpuBuffer:e,dims:r,download:i,dispose:a})},Te=(e,t)=>{let{dataType:n,dims:r,download:i,dispose:a}=t;return new Ie({location:`ml-tensor`,type:n??`float32`,mlTensor:e,dims:r,download:i,dispose:a})},Ee=(e,t,n)=>new Ie({location:`cpu-pinned`,type:e,data:t,dims:n??[t.length]})}),Oe,ke,Ae,je,Me=M(()=>{Oe=new Map([[`float32`,Float32Array],[`uint8`,Uint8Array],[`int8`,Int8Array],[`uint16`,Uint16Array],[`int16`,Int16Array],[`int32`,Int32Array],[`bool`,Uint8Array],[`float64`,Float64Array],[`uint32`,Uint32Array],[`int4`,Uint8Array],[`uint4`,Uint8Array]]),ke=new Map([[Float32Array,`float32`],[Uint8Array,`uint8`],[Int8Array,`int8`],[Uint16Array,`uint16`],[Int16Array,`int16`],[Int32Array,`int32`],[Float64Array,`float64`],[Uint32Array,`uint32`]]),Ae=!1,je=()=>{if(!Ae){Ae=!0;let e=typeof BigInt64Array<`u`&&BigInt64Array.from,t=typeof BigUint64Array<`u`&&BigUint64Array.from,n=globalThis.Float16Array,r=typeof n<`u`&&n.from;e&&(Oe.set(`int64`,BigInt64Array),ke.set(BigInt64Array,`int64`)),t&&(Oe.set(`uint64`,BigUint64Array),ke.set(BigUint64Array,`uint64`)),r?(Oe.set(`float16`,n),ke.set(n,`float16`)):Oe.set(`float16`,Uint16Array)}}}),Ne,Pe,Fe=M(()=>{Le(),Ne=e=>{let t=1;for(let n=0;n<e.length;n++){let r=e[n];if(typeof r!=`number`||!Number.isSafeInteger(r))throw TypeError(`dims[${n}] must be an integer, got: ${r}`);if(r<0)throw RangeError(`dims[${n}] must be a non-negative integer, got: ${r}`);t*=r}return t},Pe=(e,t)=>{switch(e.location){case`cpu`:return new Ie(e.type,e.data,t);case`cpu-pinned`:return new Ie({location:`cpu-pinned`,data:e.data,type:e.type,dims:t});case`texture`:return new Ie({location:`texture`,texture:e.texture,type:e.type,dims:t});case`gpu-buffer`:return new Ie({location:`gpu-buffer`,gpuBuffer:e.gpuBuffer,type:e.type,dims:t});case`ml-tensor`:return new Ie({location:`ml-tensor`,mlTensor:e.mlTensor,type:e.type,dims:t});default:throw Error(`tensorReshape: tensor location ${e.location} is not supported`)}}}),Ie,Le=M(()=>{Se(),De(),Me(),Fe(),Ie=class{constructor(e,t,n){je();let r,i;if(typeof e==`object`&&`location`in e)switch(this.dataLocation=e.location,r=e.type,i=e.dims,e.location){case`cpu-pinned`:{let t=Oe.get(r);if(!t)throw TypeError(`unsupported type "${r}" to create tensor from pinned buffer`);if(!(e.data instanceof t))throw TypeError(`buffer should be of type ${t.name}`);this.cpuData=e.data;break}case`texture`:if(r!==`float32`)throw TypeError(`unsupported type "${r}" to create tensor from texture`);this.gpuTextureData=e.texture,this.downloader=e.download,this.disposer=e.dispose;break;case`gpu-buffer`:if(r!==`float32`&&r!==`float16`&&r!==`int32`&&r!==`int64`&&r!==`uint32`&&r!==`uint8`&&r!==`bool`&&r!==`uint4`&&r!==`int4`)throw TypeError(`unsupported type "${r}" to create tensor from gpu buffer`);this.gpuBufferData=e.gpuBuffer,this.downloader=e.download,this.disposer=e.dispose;break;case`ml-tensor`:if(r!==`float32`&&r!==`float16`&&r!==`int32`&&r!==`int64`&&r!==`uint32`&&r!==`uint64`&&r!==`int8`&&r!==`uint8`&&r!==`bool`&&r!==`uint4`&&r!==`int4`)throw TypeError(`unsupported type "${r}" to create tensor from MLTensor`);this.mlTensorData=e.mlTensor,this.downloader=e.download,this.disposer=e.dispose;break;default:throw Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let a,o;if(typeof e==`string`)if(r=e,o=n,e===`string`){if(!Array.isArray(t))throw TypeError(`A string tensor's data must be a string array.`);a=t}else{let n=Oe.get(e);if(n===void 0)throw TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(t)){if(e===`float16`&&n===Uint16Array||e===`uint4`||e===`int4`)throw TypeError(`Creating a ${e} tensor from number array is not supported. Please use ${n.name} as data.`);a=e===`uint64`||e===`int64`?n.from(t,BigInt):n.from(t)}else if(t instanceof n)a=t;else if(t instanceof Uint8ClampedArray)if(e===`uint8`)a=Uint8Array.from(t);else throw TypeError(`A Uint8ClampedArray tensor's data must be type of uint8`);else if(e===`float16`&&t instanceof Uint16Array&&n!==Uint16Array)a=new globalThis.Float16Array(t.buffer,t.byteOffset,t.length);else throw TypeError(`A ${r} tensor's data must be type of ${n}`)}else if(o=t,Array.isArray(e)){if(e.length===0)throw TypeError(`Tensor type cannot be inferred from an empty array.`);let t=typeof e[0];if(t===`string`)r=`string`,a=e;else if(t===`boolean`)r=`bool`,a=Uint8Array.from(e);else throw TypeError(`Invalid element type of data array: ${t}.`)}else if(e instanceof Uint8ClampedArray)r=`uint8`,a=Uint8Array.from(e);else{let t=ke.get(e.constructor);if(t===void 0)throw TypeError(`Unsupported type for tensor data: ${e.constructor}.`);r=t,a=e}if(o===void 0)o=[a.length];else if(!Array.isArray(o))throw TypeError(`A tensor's dims must be a number array`);i=o,this.cpuData=a,this.dataLocation=`cpu`}let a=Ne(i);if(this.cpuData&&a!==this.cpuData.length&&!((r===`uint4`||r===`int4`)&&Math.ceil(a/2)===this.cpuData.length))throw Error(`Tensor's size(${a}) does not match data length(${this.cpuData.length}).`);this.type=r,this.dims=i,this.size=a}static async fromImage(e,t){return Ce(e,t)}static fromTexture(e,t){return z(e,t)}static fromGpuBuffer(e,t){return we(e,t)}static fromMLTensor(e,t){return Te(e,t)}static fromPinnedBuffer(e,t,n){return Ee(e,t,n)}toDataURL(e){return be(this,e)}toImageData(e){return xe(this,e)}get data(){if(this.ensureValid(),!this.cpuData)throw Error("The data is not on CPU. Use `getData()` to download GPU data to CPU, or use `texture` or `gpuBuffer` property to access the GPU data directly.");return this.cpuData}get location(){return this.dataLocation}get texture(){if(this.ensureValid(),!this.gpuTextureData)throw Error(`The data is not stored as a WebGL texture.`);return this.gpuTextureData}get gpuBuffer(){if(this.ensureValid(),!this.gpuBufferData)throw Error(`The data is not stored as a WebGPU buffer.`);return this.gpuBufferData}get mlTensor(){if(this.ensureValid(),!this.mlTensorData)throw Error(`The data is not stored as a WebNN MLTensor.`);return this.mlTensorData}async getData(e){switch(this.ensureValid(),this.dataLocation){case`cpu`:case`cpu-pinned`:return this.data;case`texture`:case`gpu-buffer`:case`ml-tensor`:if(!this.downloader)throw Error(`The current tensor is not created with a specified data downloader.`);if(this.isDownloading)throw Error(`The current tensor is being downloaded.`);try{this.isDownloading=!0;let t=await this.downloader();return this.downloader=void 0,this.dataLocation=`cpu`,this.cpuData=t,e&&this.disposer&&(this.disposer(),this.disposer=void 0),t}finally{this.isDownloading=!1}default:throw Error(`cannot get data from location: ${this.dataLocation}`)}}dispose(){if(this.isDownloading)throw Error(`The current tensor is being downloaded.`);this.disposer&&=(this.disposer(),void 0),this.cpuData=void 0,this.gpuTextureData=void 0,this.gpuBufferData=void 0,this.mlTensorData=void 0,this.downloader=void 0,this.isDownloading=void 0,this.dataLocation=`none`}ensureValid(){if(this.dataLocation===`none`)throw Error(`The tensor is disposed.`)}reshape(e){if(this.ensureValid(),this.downloader||this.disposer)throw Error(`Cannot reshape a tensor that owns GPU resource.`);return Pe(this,e)}}}),Re,ze=M(()=>{Le(),Re=Ie}),Be,B,Ve,He,Ue=M(()=>{ye(),Be=(e,t)=>{(typeof F.trace>`u`?!F.wasm.trace:!F.trace)||console.timeStamp(`${e}::ORT::${t}`)},B=(e,t)=>{let n=Error().stack?.split(/\r\n|\r|\n/g)||[],r=!1;for(let i=0;i<n.length;i++){if(r&&!n[i].includes(`TRACE_FUNC`)){let r=`FUNC_${e}::${n[i].trim().split(` `)[1]}`;t&&(r+=`::${t}`),Be(`CPU`,r);return}n[i].includes(`TRACE_FUNC`)&&(r=!0)}},Ve=e=>{(typeof F.trace>`u`?!F.wasm.trace:!F.trace)||B(`BEGIN`,e)},He=e=>{(typeof F.trace>`u`?!F.wasm.trace:!F.trace)||B(`END`,e)}}),We,V=M(()=>{me(),ze(),Ue(),We=class e{constructor(e){this.handler=e}async run(e,t,n){Ve();let r={},i={};if(typeof e!=`object`||!e||e instanceof Re||Array.isArray(e))throw TypeError(`'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.`);let a=!0;if(typeof t==`object`){if(t===null)throw TypeError(`Unexpected argument[1]: cannot be null.`);if(t instanceof Re)throw TypeError(`'fetches' cannot be a Tensor`);if(Array.isArray(t)){if(t.length===0)throw TypeError(`'fetches' cannot be an empty array.`);a=!1;for(let e of t){if(typeof e!=`string`)throw TypeError(`'fetches' must be a string array or an object.`);if(this.outputNames.indexOf(e)===-1)throw RangeError(`'fetches' contains invalid output name: ${e}.`);r[e]=null}if(typeof n==`object`&&n)i=n;else if(typeof n<`u`)throw TypeError(`'options' must be an object.`)}else{let e=!1,o=Object.getOwnPropertyNames(t);for(let n of this.outputNames)if(o.indexOf(n)!==-1){let i=t[n];(i===null||i instanceof Re)&&(e=!0,a=!1,r[n]=i)}if(e){if(typeof n==`object`&&n)i=n;else if(typeof n<`u`)throw TypeError(`'options' must be an object.`)}else i=t}}else if(typeof t<`u`)throw TypeError(`Unexpected argument[1]: must be 'fetches' or 'options'.`);for(let t of this.inputNames)if(typeof e[t]>`u`)throw Error(`input '${t}' is missing in 'feeds'.`);if(a)for(let e of this.outputNames)r[e]=null;let o=await this.handler.run(e,r,i),s={};for(let e in o)if(Object.hasOwnProperty.call(o,e)){let t=o[e];t instanceof Re?s[e]=t:s[e]=new Re(t.type,t.data,t.dims)}return He(),s}async release(){return this.handler.dispose()}static async create(t,n,r,i){Ve();let a,o={};if(typeof t==`string`){if(a=t,typeof n==`object`&&n)o=n;else if(typeof n<`u`)throw TypeError(`'options' must be an object.`)}else if(t instanceof Uint8Array){if(a=t,typeof n==`object`&&n)o=n;else if(typeof n<`u`)throw TypeError(`'options' must be an object.`)}else if(t instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&t instanceof SharedArrayBuffer){let e=t,s=0,c=t.byteLength;if(typeof n==`object`&&n)o=n;else if(typeof n==`number`){if(s=n,!Number.isSafeInteger(s))throw RangeError(`'byteOffset' must be an integer.`);if(s<0||s>=e.byteLength)throw RangeError(`'byteOffset' is out of range [0, ${e.byteLength}).`);if(c=t.byteLength-s,typeof r==`number`){if(c=r,!Number.isSafeInteger(c))throw RangeError(`'byteLength' must be an integer.`);if(c<=0||s+c>e.byteLength)throw RangeError(`'byteLength' is out of range (0, ${e.byteLength-s}].`);if(typeof i==`object`&&i)o=i;else if(typeof i<`u`)throw TypeError(`'options' must be an object.`)}else if(typeof r<`u`)throw TypeError(`'byteLength' must be a number.`)}else if(typeof n<`u`)throw TypeError(`'options' must be an object.`);a=new Uint8Array(e,s,c)}else throw TypeError(`Unexpected argument[0]: must be 'path' or 'buffer'.`);let[s,c]=await P(o),l=await s.createInferenceSessionHandler(a,c);return He(),new e(l)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}get inputMetadata(){return this.handler.inputMetadata}get outputMetadata(){return this.handler.outputMetadata}}}),Ge,Ke=M(()=>{V(),Ge=We}),qe=M(()=>{}),Je=M(()=>{}),Ye=M(()=>{}),Xe=M(()=>{}),Ze={};N(Ze,{InferenceSession:()=>Ge,TRACE:()=>Be,TRACE_FUNC_BEGIN:()=>Ve,TRACE_FUNC_END:()=>He,Tensor:()=>Re,env:()=>I,registerBackend:()=>fe});var Qe=M(()=>{he(),L(),Ke(),ze(),qe(),Je(),Ue(),Ye(),Xe()}),$e=M(()=>{}),et={};N(et,{default:()=>rt});var tt,nt,rt,it=M(()=>{Ed(),Ft(),Tt(),tt=`ort-wasm-proxy-worker`,nt=globalThis.self?.name===tt,nt&&(self.onmessage=e=>{let{type:t,in:n}=e.data;try{switch(t){case`init-wasm`:Nt(n.wasm).then(()=>{md(n).then(()=>{postMessage({type:t})},e=>{postMessage({type:t,err:e})})},e=>{postMessage({type:t,err:e})});break;case`init-ep`:{let{epName:e,env:r}=n;hd(r,e).then(()=>{postMessage({type:t})},e=>{postMessage({type:t,err:e})});break}case`copy-from`:{let{buffer:e}=n,r=yd(e);postMessage({type:t,out:r});break}case`create`:{let{model:e,options:r}=n;bd(e,r).then(e=>{postMessage({type:t,out:e})},e=>{postMessage({type:t,err:e})});break}case`release`:xd(n),postMessage({type:t});break;case`run`:{let{sessionId:e,inputIndices:r,inputs:i,outputIndices:a,options:o}=n;Cd(e,r,i,a,Array(a.length).fill(null),o).then(e=>{e.some(e=>e[3]!==`cpu`)?postMessage({type:t,err:`Proxy does not support non-cpu tensor location.`}):postMessage({type:t,out:e},Td([...i,...e]))},e=>{postMessage({type:t,err:e})});break}case`end-profiling`:wd(n),postMessage({type:t});break;default:}}catch(e){postMessage({type:t,err:e})}}),rt=nt?null:e=>new Worker(e??mt,{type:`module`,name:tt})}),at={};N(at,{default:()=>ct});var ot,st,ct,lt,ut=M(()=>{st=(ot=import.meta.url,async function(e={}){var t,n,r=e,i=new Promise((e,r)=>{t=e,n=r}),a=typeof window==`object`,o=typeof WorkerGlobalScope<`u`,s=o&&self.name?.startsWith(`em-pthread`);r.mountExternalData=(e,t)=>{e.startsWith(`./`)&&(e=e.substring(2)),(r.Eb||=new Map).set(e,t)},r.unmountExternalData=()=>{delete r.Eb};var c=globalThis.SharedArrayBuffer??new WebAssembly.Memory({initial:0,maximum:0,pc:!0}).buffer.constructor;let l=e=>async(...t)=>{try{if(r.Fb)throw Error(`Session already started`);let n=r.Fb={dc:t[0],errors:[]},i=await e(...t);if(r.Fb!==n)throw Error(`Session mismatch`);r.Jb?.flush();let a=n.errors;if(0<a.length){let e=await Promise.all(a);if(e=e.filter(e=>e),0<e.length)throw Error(e.join(`
2
+ `))}return i}finally{r.Fb=null}};r.jsepInit=(e,t)=>{if(e===`webgpu`){[r.Jb,r.Ub,r.Yb,r.Kb,r.Xb,r.jb,r.Zb,r.ac,r.Vb,r.Wb,r.$b]=t;let e=r.Jb;r.jsepRegisterBuffer=(t,n,r,i)=>e.registerBuffer(t,n,r,i),r.jsepGetBuffer=t=>e.getBuffer(t),r.jsepCreateDownloader=(t,n,r)=>e.createDownloader(t,n,r),r.jsepOnCreateSession=t=>{e.onCreateSession(t)},r.jsepOnReleaseSession=t=>{e.onReleaseSession(t)},r.jsepOnRunStart=t=>e.onRunStart(t),r.bc=(t,n)=>{e.upload(t,n)}}else if(e===`webnn`){let e=t[0];[r.nc,r.Nb,r.webnnEnsureTensor,r.Ob,r.webnnDownloadTensor]=t.slice(1),r.webnnReleaseTensorId=r.Nb,r.webnnUploadTensor=r.Ob,r.webnnOnRunStart=t=>e.onRunStart(t),r.webnnOnRunEnd=e.onRunEnd.bind(e),r.webnnRegisterMLContext=(t,n)=>{e.registerMLContext(t,n)},r.webnnOnReleaseSession=t=>{e.onReleaseSession(t)},r.webnnCreateMLTensorDownloader=(t,n)=>e.createMLTensorDownloader(t,n),r.webnnRegisterMLTensor=(t,n,r,i)=>e.registerMLTensor(t,n,r,i),r.webnnCreateMLContext=t=>e.createMLContext(t),r.webnnRegisterMLConstant=(t,n,i,a,o,s)=>e.registerMLConstant(t,n,i,a,o,r.Eb,s),r.webnnRegisterGraphInput=e.registerGraphInput.bind(e),r.webnnIsGraphInput=e.isGraphInput.bind(e),r.webnnCreateTemporaryTensor=e.createTemporaryTensor.bind(e),r.webnnIsInt64Supported=e.isInt64Supported.bind(e)}};let u=()=>{let e=(e,t,n)=>(...r)=>{let i=$t,a=t?.();r=e(...r);let o=t?.();return a!==o&&(e=o,n(a),t=n=null),$t==i?r:new Promise((e,t)=>{an={resolve:e,reject:t}})};(()=>{for(let t of[`_OrtAppendExecutionProvider`,`_OrtCreateSession`,`_OrtRun`,`_OrtRunWithBinding`,`_OrtBindInput`])r[t]=e(r[t],()=>r[t],e=>r[t]=e)})(),l!==void 0&&(r._OrtRun=l(r._OrtRun),r._OrtRunWithBinding=l(r._OrtRunWithBinding)),u=void 0};r.asyncInit=()=>{u?.()};var d,f,p=Object.assign({},r),m=(e,t)=>{throw t},h=``;(a||o)&&(o?h=self.location.href:typeof document<`u`&&document.currentScript&&(h=document.currentScript.src),ot&&(h=ot),h=h.startsWith(`blob:`)?``:h.slice(0,h.replace(/[?#].*/,``).lastIndexOf(`/`)+1),o&&(f=e=>{var t=new XMLHttpRequest;return t.open(`GET`,e,!1),t.responseType=`arraybuffer`,t.send(null),new Uint8Array(t.response)}),d=async e=>{if(re(e))return new Promise((t,n)=>{var r=new XMLHttpRequest;r.open(`GET`,e,!0),r.responseType=`arraybuffer`,r.onload=()=>{r.status==200||r.status==0&&r.response?t(r.response):n(r.status)},r.onerror=n,r.send(null)});var t=await fetch(e,{credentials:`same-origin`});if(t.ok)return t.arrayBuffer();throw Error(t.status+` : `+t.url)});var g=console.log.bind(console),_=console.error.bind(console),v=g,y=_;Object.assign(r,p),p=null;var b,x,S,C,w,T,E,D,O,k,A,ee,te,ne=r.wasmBinary,j=!1,re=e=>e.startsWith(`file://`);function ie(){return b.buffer!=C.buffer&&fe(),C}function ae(){return b.buffer!=C.buffer&&fe(),w}function oe(){return b.buffer!=C.buffer&&fe(),T}function se(){return b.buffer!=C.buffer&&fe(),E}function M(){return b.buffer!=C.buffer&&fe(),D}function N(){return b.buffer!=C.buffer&&fe(),O}function ce(){return b.buffer!=C.buffer&&fe(),k}function le(){return b.buffer!=C.buffer&&fe(),te}if(s){let e=function(t){try{var n=t.data,i=n.Bb;if(i===`load`){let t=[];self.onmessage=e=>t.push(e),self.startWorker=()=>{postMessage({Bb:`loaded`});for(let n of t)e(n);self.onmessage=e};for(let e of n.Rb)r[e]&&!r[e].proxy||(r[e]=(...t)=>{postMessage({Bb:`callHandler`,Qb:e,args:t})},e==`print`&&(v=r[e]),e==`printErr`&&(y=r[e]));b=n.kc,fe(),ue(n.lc)}else if(i===`run`){Pe(n.Ab),_r(n.Ab,0,0,1,0,0),je(),zt(n.Ab),de||=(pr(),!0);try{Fe(n.fc,n.Hb)}catch(e){if(e!=`unwind`)throw e}}else n.target!==`setimmediate`&&(i===`checkMailbox`?de&&Bt():i&&(y(`worker: received unknown command ${i}`),y(n)))}catch(e){throw vr(),e}};var ue,de=!1;y=function(...e){e=e.join(` `),console.error(e)},self.alert=function(...e){postMessage({Bb:`alert`,text:e.join(` `),ic:mr()})},self.onunhandledrejection=e=>{throw e.reason||e},self.onmessage=e}function fe(){var e=b.buffer;r.HEAP8=C=new Int8Array(e),r.HEAP16=T=new Int16Array(e),r.HEAPU8=w=new Uint8Array(e),r.HEAPU16=E=new Uint16Array(e),r.HEAP32=D=new Int32Array(e),r.HEAPU32=O=new Uint32Array(e),r.HEAPF32=k=new Float32Array(e),r.HEAPF64=te=new Float64Array(e),r.HEAP64=A=new BigInt64Array(e),r.HEAPU64=ee=new BigUint64Array(e)}function pe(){s?startWorker(r):Z.Ca()}s||(b=new WebAssembly.Memory({initial:256,maximum:65536,shared:!0}),fe());var P,me=0,he=null;function ge(){if(--me==0&&he){var e=he;he=null,e()}}function _e(e){throw y(e=`Aborted(`+e+`)`),j=!0,e=new WebAssembly.RuntimeError(e+`. Build with -sASSERTIONS for more info.`),n(e),e}function ve(){return{a:{L:I,Aa:ye,b:Le,$:ze,A:He,pa:Ue,X:Ge,Z:Ke,qa:qe,na:Je,ga:Ye,ma:Xe,J:Ze,Y:Qe,V:$e,oa:et,W:tt,va:it,E:ft,Q:mt,O:St,D:wt,u:Tt,r:Et,P:Dt,z:Ft,R:It,ja:Lt,T:Vt,aa:Ut,M:Wt,F:Gt,ia:zt,sa:Kt,t:Yt,Ba:Xt,w:cn,o:un,l:fn,c:_t,n:mn,j:_n,v:vn,p:G,f:yn,s:bn,m:xn,e:Sn,k:Cn,i:wn,g:Tn,d:En,da:Dn,ea:jn,fa:Mn,ba:Nn,ca:Pn,N:Ln,xa:Rn,ua:Vn,h:Wn,C:Gn,G:Kn,ta:zn,x:qn,ra:Jn,U:Yn,q:In,y:Xn,K:Zn,S:Qn,za:tr,ya:nr,ka:J,la:Y,_:Te,B:ar,I:or,ha:sr,H:X,a:b,wa:z}}}var F={829644:(e,t,n,i,a)=>{if(r===void 0||!r.Eb)return 1;if((e=Ve(Number(e>>>0))).startsWith(`./`)&&(e=e.substring(2)),!(e=r.Eb.get(e)))return 2;if(t=Number(t>>>0),n=Number(n>>>0),i=Number(i>>>0),t+n>e.byteLength)return 3;try{let o=e.subarray(t,t+n);switch(a){case 0:ae().set(o,i>>>0);break;case 1:r.mc?r.mc(i,o):r.bc(i,o);break;default:return 4}return 0}catch{return 4}},830468:(e,t,n)=>{r.Ob(e,ae().subarray(t>>>0,t+n>>>0))},830532:()=>r.nc(),830574:e=>{r.Nb(e)},830611:()=>{r.Vb()},830642:()=>{r.Wb()},830671:()=>{r.$b()},830696:e=>r.Ub(e),830729:e=>r.Yb(e),830761:(e,t,n)=>{r.Kb(Number(e),Number(t),Number(n),!0)},830824:(e,t,n)=>{r.Kb(Number(e),Number(t),Number(n))},830881:()=>typeof wasmOffsetConverter<`u`,830938:e=>{r.jb(`Abs`,e,void 0)},830989:e=>{r.jb(`Neg`,e,void 0)},831040:e=>{r.jb(`Floor`,e,void 0)},831093:e=>{r.jb(`Ceil`,e,void 0)},831145:e=>{r.jb(`Reciprocal`,e,void 0)},831203:e=>{r.jb(`Sqrt`,e,void 0)},831255:e=>{r.jb(`Exp`,e,void 0)},831306:e=>{r.jb(`Erf`,e,void 0)},831357:e=>{r.jb(`Sigmoid`,e,void 0)},831412:(e,t,n)=>{r.jb(`HardSigmoid`,e,{alpha:t,beta:n})},831491:e=>{r.jb(`Log`,e,void 0)},831542:e=>{r.jb(`Sin`,e,void 0)},831593:e=>{r.jb(`Cos`,e,void 0)},831644:e=>{r.jb(`Tan`,e,void 0)},831695:e=>{r.jb(`Asin`,e,void 0)},831747:e=>{r.jb(`Acos`,e,void 0)},831799:e=>{r.jb(`Atan`,e,void 0)},831851:e=>{r.jb(`Sinh`,e,void 0)},831903:e=>{r.jb(`Cosh`,e,void 0)},831955:e=>{r.jb(`Asinh`,e,void 0)},832008:e=>{r.jb(`Acosh`,e,void 0)},832061:e=>{r.jb(`Atanh`,e,void 0)},832114:e=>{r.jb(`Tanh`,e,void 0)},832166:e=>{r.jb(`Not`,e,void 0)},832217:(e,t,n)=>{r.jb(`Clip`,e,{min:t,max:n})},832286:e=>{r.jb(`Clip`,e,void 0)},832338:(e,t)=>{r.jb(`Elu`,e,{alpha:t})},832396:e=>{r.jb(`Gelu`,e,void 0)},832448:e=>{r.jb(`Relu`,e,void 0)},832500:(e,t)=>{r.jb(`LeakyRelu`,e,{alpha:t})},832564:(e,t)=>{r.jb(`ThresholdedRelu`,e,{alpha:t})},832634:(e,t)=>{r.jb(`Cast`,e,{to:t})},832692:e=>{r.jb(`Add`,e,void 0)},832743:e=>{r.jb(`Sub`,e,void 0)},832794:e=>{r.jb(`Mul`,e,void 0)},832845:e=>{r.jb(`Div`,e,void 0)},832896:e=>{r.jb(`Pow`,e,void 0)},832947:e=>{r.jb(`Equal`,e,void 0)},833e3:e=>{r.jb(`Greater`,e,void 0)},833055:e=>{r.jb(`GreaterOrEqual`,e,void 0)},833117:e=>{r.jb(`Less`,e,void 0)},833169:e=>{r.jb(`LessOrEqual`,e,void 0)},833228:(e,t,n,i,a)=>{r.jb(`ReduceMean`,e,{keepDims:!!t,noopWithEmptyAxes:!!n,axes:i?Array.from(M().subarray(Number(i)>>>0,Number(a)>>>0)):[]})},833403:(e,t,n,i,a)=>{r.jb(`ReduceMax`,e,{keepDims:!!t,noopWithEmptyAxes:!!n,axes:i?Array.from(M().subarray(Number(i)>>>0,Number(a)>>>0)):[]})},833577:(e,t,n,i,a)=>{r.jb(`ReduceMin`,e,{keepDims:!!t,noopWithEmptyAxes:!!n,axes:i?Array.from(M().subarray(Number(i)>>>0,Number(a)>>>0)):[]})},833751:(e,t,n,i,a)=>{r.jb(`ReduceProd`,e,{keepDims:!!t,noopWithEmptyAxes:!!n,axes:i?Array.from(M().subarray(Number(i)>>>0,Number(a)>>>0)):[]})},833926:(e,t,n,i,a)=>{r.jb(`ReduceSum`,e,{keepDims:!!t,noopWithEmptyAxes:!!n,axes:i?Array.from(M().subarray(Number(i)>>>0,Number(a)>>>0)):[]})},834100:(e,t,n,i,a)=>{r.jb(`ReduceL1`,e,{keepDims:!!t,noopWithEmptyAxes:!!n,axes:i?Array.from(M().subarray(Number(i)>>>0,Number(a)>>>0)):[]})},834273:(e,t,n,i,a)=>{r.jb(`ReduceL2`,e,{keepDims:!!t,noopWithEmptyAxes:!!n,axes:i?Array.from(M().subarray(Number(i)>>>0,Number(a)>>>0)):[]})},834446:(e,t,n,i,a)=>{r.jb(`ReduceLogSum`,e,{keepDims:!!t,noopWithEmptyAxes:!!n,axes:i?Array.from(M().subarray(Number(i)>>>0,Number(a)>>>0)):[]})},834623:(e,t,n,i,a)=>{r.jb(`ReduceSumSquare`,e,{keepDims:!!t,noopWithEmptyAxes:!!n,axes:i?Array.from(M().subarray(Number(i)>>>0,Number(a)>>>0)):[]})},834803:(e,t,n,i,a)=>{r.jb(`ReduceLogSumExp`,e,{keepDims:!!t,noopWithEmptyAxes:!!n,axes:i?Array.from(M().subarray(Number(i)>>>0,Number(a)>>>0)):[]})},834983:e=>{r.jb(`Where`,e,void 0)},835036:(e,t,n)=>{r.jb(`Transpose`,e,{perm:t?Array.from(M().subarray(Number(t)>>>0,Number(n)>>>0)):[]})},835160:(e,t,n,i)=>{r.jb(`DepthToSpace`,e,{blocksize:t,mode:Ve(n),format:i?`NHWC`:`NCHW`})},835293:(e,t,n,i)=>{r.jb(`DepthToSpace`,e,{blocksize:t,mode:Ve(n),format:i?`NHWC`:`NCHW`})},835426:(e,t,n,i,a,o,s,c,l,u,d,f,p,m,h)=>{r.jb(`ConvTranspose`,e,{format:l?`NHWC`:`NCHW`,autoPad:t,dilations:[n],group:i,kernelShape:[a],pads:[o,s],strides:[c],wIsConst:()=>!!ie()[u>>>0],outputPadding:d?Array.from(M().subarray(Number(d)>>>0,Number(f)>>>0)):[],outputShape:p?Array.from(M().subarray(Number(p)>>>0,Number(m)>>>0)):[],activation:Ve(h)})},835859:(e,t,n,i,a,o,s,c,l,u,d,f,p,m)=>{r.jb(`ConvTranspose`,e,{format:c?`NHWC`:`NCHW`,autoPad:t,dilations:Array.from(M().subarray(Number(n)>>>0,2+(Number(n)>>>0)>>>0)),group:i,kernelShape:Array.from(M().subarray(Number(a)>>>0,2+(Number(a)>>>0)>>>0)),pads:Array.from(M().subarray(Number(o)>>>0,4+(Number(o)>>>0)>>>0)),strides:Array.from(M().subarray(Number(s)>>>0,2+(Number(s)>>>0)>>>0)),wIsConst:()=>!!ie()[l>>>0],outputPadding:u?Array.from(M().subarray(Number(u)>>>0,Number(d)>>>0)):[],outputShape:f?Array.from(M().subarray(Number(f)>>>0,Number(p)>>>0)):[],activation:Ve(m)})},836520:(e,t,n,i,a,o,s,c,l,u,d,f,p,m,h)=>{r.jb(`ConvTranspose`,e,{format:l?`NHWC`:`NCHW`,autoPad:t,dilations:[n],group:i,kernelShape:[a],pads:[o,s],strides:[c],wIsConst:()=>!!ie()[u>>>0],outputPadding:d?Array.from(M().subarray(Number(d)>>>0,Number(f)>>>0)):[],outputShape:p?Array.from(M().subarray(Number(p)>>>0,Number(m)>>>0)):[],activation:Ve(h)})},836953:(e,t,n,i,a,o,s,c,l,u,d,f,p,m)=>{r.jb(`ConvTranspose`,e,{format:c?`NHWC`:`NCHW`,autoPad:t,dilations:Array.from(M().subarray(Number(n)>>>0,2+(Number(n)>>>0)>>>0)),group:i,kernelShape:Array.from(M().subarray(Number(a)>>>0,2+(Number(a)>>>0)>>>0)),pads:Array.from(M().subarray(Number(o)>>>0,4+(Number(o)>>>0)>>>0)),strides:Array.from(M().subarray(Number(s)>>>0,2+(Number(s)>>>0)>>>0)),wIsConst:()=>!!ie()[l>>>0],outputPadding:u?Array.from(M().subarray(Number(u)>>>0,Number(d)>>>0)):[],outputShape:f?Array.from(M().subarray(Number(f)>>>0,Number(p)>>>0)):[],activation:Ve(m)})},837614:(e,t)=>{r.jb(`GlobalAveragePool`,e,{format:t?`NHWC`:`NCHW`})},837705:(e,t,n,i,a,o,s,c,l,u,d,f,p,m)=>{r.jb(`AveragePool`,e,{format:m?`NHWC`:`NCHW`,auto_pad:t,ceil_mode:n,count_include_pad:i,storage_order:a,dilations:o?Array.from(M().subarray(Number(o)>>>0,Number(s)>>>0)):[],kernel_shape:c?Array.from(M().subarray(Number(c)>>>0,Number(l)>>>0)):[],pads:u?Array.from(M().subarray(Number(u)>>>0,Number(d)>>>0)):[],strides:f?Array.from(M().subarray(Number(f)>>>0,Number(p)>>>0)):[]})},838184:(e,t)=>{r.jb(`GlobalAveragePool`,e,{format:t?`NHWC`:`NCHW`})},838275:(e,t,n,i,a,o,s,c,l,u,d,f,p,m)=>{r.jb(`AveragePool`,e,{format:m?`NHWC`:`NCHW`,auto_pad:t,ceil_mode:n,count_include_pad:i,storage_order:a,dilations:o?Array.from(M().subarray(Number(o)>>>0,Number(s)>>>0)):[],kernel_shape:c?Array.from(M().subarray(Number(c)>>>0,Number(l)>>>0)):[],pads:u?Array.from(M().subarray(Number(u)>>>0,Number(d)>>>0)):[],strides:f?Array.from(M().subarray(Number(f)>>>0,Number(p)>>>0)):[]})},838754:(e,t)=>{r.jb(`GlobalMaxPool`,e,{format:t?`NHWC`:`NCHW`})},838841:(e,t,n,i,a,o,s,c,l,u,d,f,p,m)=>{r.jb(`MaxPool`,e,{format:m?`NHWC`:`NCHW`,auto_pad:t,ceil_mode:n,count_include_pad:i,storage_order:a,dilations:o?Array.from(M().subarray(Number(o)>>>0,Number(s)>>>0)):[],kernel_shape:c?Array.from(M().subarray(Number(c)>>>0,Number(l)>>>0)):[],pads:u?Array.from(M().subarray(Number(u)>>>0,Number(d)>>>0)):[],strides:f?Array.from(M().subarray(Number(f)>>>0,Number(p)>>>0)):[]})},839316:(e,t)=>{r.jb(`GlobalMaxPool`,e,{format:t?`NHWC`:`NCHW`})},839403:(e,t,n,i,a,o,s,c,l,u,d,f,p,m)=>{r.jb(`MaxPool`,e,{format:m?`NHWC`:`NCHW`,auto_pad:t,ceil_mode:n,count_include_pad:i,storage_order:a,dilations:o?Array.from(M().subarray(Number(o)>>>0,Number(s)>>>0)):[],kernel_shape:c?Array.from(M().subarray(Number(c)>>>0,Number(l)>>>0)):[],pads:u?Array.from(M().subarray(Number(u)>>>0,Number(d)>>>0)):[],strides:f?Array.from(M().subarray(Number(f)>>>0,Number(p)>>>0)):[]})},839878:(e,t,n,i,a)=>{r.jb(`Gemm`,e,{alpha:t,beta:n,transA:i,transB:a})},839982:e=>{r.jb(`MatMul`,e,void 0)},840036:(e,t,n,i)=>{r.jb(`ArgMax`,e,{keepDims:!!t,selectLastIndex:!!n,axis:i})},840144:(e,t,n,i)=>{r.jb(`ArgMin`,e,{keepDims:!!t,selectLastIndex:!!n,axis:i})},840252:(e,t)=>{r.jb(`Softmax`,e,{axis:t})},840315:(e,t)=>{r.jb(`Concat`,e,{axis:t})},840375:(e,t,n,i,a)=>{r.jb(`Split`,e,{axis:t,numOutputs:n,splitSizes:i?Array.from(M().subarray(Number(i)>>>0,Number(a)>>>0)):[]})},840531:e=>{r.jb(`Expand`,e,void 0)},840585:(e,t)=>{r.jb(`Gather`,e,{axis:Number(t)})},840656:(e,t)=>{r.jb(`GatherElements`,e,{axis:Number(t)})},840735:(e,t)=>{r.jb(`GatherND`,e,{batch_dims:Number(t)})},840814:(e,t,n,i,a,o,s,c,l,u,d)=>{r.jb(`Resize`,e,{antialias:t,axes:n?Array.from(M().subarray(Number(n)>>>0,Number(i)>>>0)):[],coordinateTransformMode:Ve(a),cubicCoeffA:o,excludeOutside:s,extrapolationValue:c,keepAspectRatioPolicy:Ve(l),mode:Ve(u),nearestMode:Ve(d)})},841176:(e,t,n,i,a,o,s)=>{r.jb(`Slice`,e,{starts:t?Array.from(M().subarray(Number(t)>>>0,Number(n)>>>0)):[],ends:i?Array.from(M().subarray(Number(i)>>>0,Number(a)>>>0)):[],axes:o?Array.from(M().subarray(Number(o)>>>0,Number(s)>>>0)):[]})},841440:e=>{r.jb(`Tile`,e,void 0)},841492:(e,t,n)=>{r.jb(`InstanceNormalization`,e,{epsilon:t,format:n?`NHWC`:`NCHW`})},841606:(e,t,n)=>{r.jb(`InstanceNormalization`,e,{epsilon:t,format:n?`NHWC`:`NCHW`})},841720:e=>{r.jb(`Range`,e,void 0)},841773:(e,t)=>{r.jb(`Einsum`,e,{equation:Ve(t)})},841854:(e,t,n,i,a)=>{r.jb(`Pad`,e,{mode:t,value:n,pads:i?Array.from(M().subarray(Number(i)>>>0,Number(a)>>>0)):[]})},841997:(e,t,n,i,a,o)=>{r.jb(`BatchNormalization`,e,{epsilon:t,momentum:n,spatial:!!a,trainingMode:!!i,format:o?`NHWC`:`NCHW`})},842166:(e,t,n,i,a,o)=>{r.jb(`BatchNormalization`,e,{epsilon:t,momentum:n,spatial:!!a,trainingMode:!!i,format:o?`NHWC`:`NCHW`})},842335:(e,t,n)=>{r.jb(`CumSum`,e,{exclusive:Number(t),reverse:Number(n)})},842432:(e,t,n)=>{r.jb(`DequantizeLinear`,e,{axis:t,blockSize:n})},842522:(e,t,n,i,a)=>{r.jb(`GridSample`,e,{align_corners:t,mode:Ve(n),padding_mode:Ve(i),format:a?`NHWC`:`NCHW`})},842692:(e,t,n,i,a)=>{r.jb(`GridSample`,e,{align_corners:t,mode:Ve(n),padding_mode:Ve(i),format:a?`NHWC`:`NCHW`})},842862:(e,t)=>{r.jb(`ScatterND`,e,{reduction:Ve(t)})},842947:(e,t,n,i,a,o,s,c,l)=>{r.jb(`Attention`,e,{numHeads:t,isUnidirectional:n,maskFilterValue:i,scale:a,doRotary:o,qkvHiddenSizes:s?Array.from(M().subarray(Number(c)>>>0,Number(c)+s>>>0)):[],pastPresentShareBuffer:!!l})},843219:e=>{r.jb(`BiasAdd`,e,void 0)},843274:e=>{r.jb(`BiasSplitGelu`,e,void 0)},843335:e=>{r.jb(`FastGelu`,e,void 0)},843391:(e,t,n,i,a,o,s,c,l,u,d,f,p,m,h,g)=>{r.jb(`Conv`,e,{format:f?`NHWC`:`NCHW`,auto_pad:t,dilations:n?Array.from(M().subarray(Number(n)>>>0,Number(i)>>>0)):[],group:a,kernel_shape:o?Array.from(M().subarray(Number(o)>>>0,Number(s)>>>0)):[],pads:c?Array.from(M().subarray(Number(c)>>>0,Number(l)>>>0)):[],strides:u?Array.from(M().subarray(Number(u)>>>0,Number(d)>>>0)):[],w_is_const:()=>!!ie()[Number(p)>>>0],activation:Ve(m),activation_params:h?Array.from(ce().subarray(Number(h)>>>0,Number(g)>>>0)):[]})},843975:e=>{r.jb(`Gelu`,e,void 0)},844027:(e,t,n,i,a,o,s,c,l)=>{r.jb(`GroupQueryAttention`,e,{numHeads:t,kvNumHeads:n,scale:i,softcap:a,doRotary:o,rotaryInterleaved:s,smoothSoftmax:c,localWindowSize:l})},844244:(e,t,n,i)=>{r.jb(`LayerNormalization`,e,{axis:t,epsilon:n,simplified:!!i})},844355:(e,t,n,i)=>{r.jb(`LayerNormalization`,e,{axis:t,epsilon:n,simplified:!!i})},844466:(e,t,n,i,a,o)=>{r.jb(`MatMulNBits`,e,{k:t,n,accuracyLevel:i,bits:a,blockSize:o})},844593:(e,t,n,i,a,o)=>{r.jb(`MultiHeadAttention`,e,{numHeads:t,isUnidirectional:n,maskFilterValue:i,scale:a,doRotary:o})},844752:(e,t)=>{r.jb(`QuickGelu`,e,{alpha:t})},844816:(e,t,n,i,a)=>{r.jb(`RotaryEmbedding`,e,{interleaved:!!t,numHeads:n,rotaryEmbeddingDim:i,scale:a})},844955:(e,t,n)=>{r.jb(`SkipLayerNormalization`,e,{epsilon:t,simplified:!!n})},845057:(e,t,n)=>{r.jb(`SkipLayerNormalization`,e,{epsilon:t,simplified:!!n})},845159:(e,t,n,i)=>{r.jb(`GatherBlockQuantized`,e,{gatherAxis:t,quantizeAxis:n,blockSize:i})},845280:e=>{r.Zb(e)},845314:(e,t)=>r.ac(Number(e),Number(t),r.Fb.dc,r.Fb.errors)};function ye(e,t,n){return sn(async()=>{await r.Xb(Number(e),Number(t),Number(n))})}function I(){return typeof wasmOffsetConverter<`u`}class L{name=`ExitStatus`;constructor(e){this.message=`Program terminated with exit(${e})`,this.status=e}}var be=e=>{e.terminate(),e.onmessage=()=>{}},xe=[],Se=e=>{Ee.length==0&&(Ne(),Me(Ee[0]));var t=Ee.pop();if(!t)return 6;De.push(t),ke[e.Ab]=t,t.Ab=e.Ab;var n={Bb:`run`,fc:e.ec,Hb:e.Hb,Ab:e.Ab};return t.postMessage(n,e.Mb),0},R=0,Ce=(e,t,...n)=>{for(var r=2*n.length,i=Dr(),a=Er(8*r),o=a>>>3,s=0;s<n.length;s++){var c=n[s];typeof c==`bigint`?(A[o+2*s]=1n,A[o+2*s+1]=c):(A[o+2*s]=0n,le()[o+2*s+1>>>0]=c)}return e=yr(e,0,r,a,t),Tr(i),e};function z(e){if(s)return Ce(0,1,e);if(S=e,!(0<R)){for(var t of De)be(t);for(t of Ee)be(t);Ee=[],De=[],ke={},j=!0}m(0,new L(e))}function we(e){if(s)return Ce(1,0,e);Te(e)}var Te=e=>{if(S=e,s)throw we(e),`unwind`;z(e)},Ee=[],De=[],Oe=[],ke={},Ae=e=>{var t=e.Ab;delete ke[t],Ee.push(e),De.splice(De.indexOf(e),1),e.Ab=0,br(t)};function je(){Oe.forEach(e=>e())}var Me=e=>new Promise(t=>{e.onmessage=n=>{var i=(n=n.data).Bb;if(n.Gb&&n.Gb!=mr()){var a=ke[n.Gb];a?a.postMessage(n,n.Mb):y(`Internal error! Worker sent a message "${i}" to target pthread ${n.Gb}, but that thread no longer exists!`)}else i===`checkMailbox`?Bt():i===`spawnThread`?Se(n):i===`cleanupThread`?Ae(ke[n.hc]):i===`loaded`?(e.loaded=!0,t(e)):i===`alert`?alert(`Thread ${n.ic}: ${n.text}`):n.target===`setimmediate`?e.postMessage(n):i===`callHandler`?r[n.Qb](...n.args):i&&y(`worker sent an unknown command ${i}`)},e.onerror=e=>{throw y(`worker sent an error! ${e.filename}:${e.lineno}: ${e.message}`),e};var n,i=[];for(n of[])r.propertyIsEnumerable(n)&&i.push(n);e.postMessage({Bb:`load`,Rb:i,kc:b,lc:x})});function Ne(){var e=new Worker((()=>{let e=URL;return import.meta.url>`file:`&&import.meta.url<`file;`?new e(`ort.bundle.min.mjs`,import.meta.url):new URL(import.meta.url)})(),{type:`module`,workerData:`em-pthread`,name:`em-pthread`});Ee.push(e)}var Pe=e=>{fe();var t=N()[e+52>>>2>>>0];e=N()[e+56>>>2>>>0],wr(t,t-e),Tr(t)},Fe=(e,t)=>{R=0,e=Or(e,t),0<R?S=e:xr(e)};class Ie{constructor(e){this.Ib=e-24}}function Le(e,t,n){var r=new Ie(e>>>=0);throw t>>>=0,n>>>=0,N()[r.Ib+16>>>2>>>0]=0,N()[r.Ib+4>>>2>>>0]=t,N()[r.Ib+8>>>2>>>0]=n,e}function Re(e,t,n,r){return s?Ce(2,1,e,t,n,r):ze(e,t,n,r)}function ze(e,t,n,r){if(e>>>=0,n>>>=0,r>>>=0,c===void 0)return 6;var i=[];return s&&i.length===0?Re(e,t>>>=0,n,r):(e={ec:n,Ab:e,Hb:r,Mb:i},s?(e.Bb=`spawnThread`,postMessage(e,i),0):Se(e))}var Be=typeof TextDecoder<`u`?new TextDecoder:void 0,B=(e,t=0,n=NaN)=>{var r=(t>>>=0)+n;for(n=t;e[n]&&!(n>=r);)++n;if(16<n-t&&e.buffer&&Be)return Be.decode(e.buffer instanceof ArrayBuffer?e.subarray(t,n):e.slice(t,n));for(r=``;t<n;){var i=e[t++];if(128&i){var a=63&e[t++];if((224&i)==192)r+=String.fromCharCode((31&i)<<6|a);else{var o=63&e[t++];65536>(i=(240&i)==224?(15&i)<<12|a<<6|o:(7&i)<<18|a<<12|o<<6|63&e[t++])?r+=String.fromCharCode(i):(i-=65536,r+=String.fromCharCode(55296|i>>10,56320|1023&i))}}else r+=String.fromCharCode(i)}return r},Ve=(e,t)=>(e>>>=0)?B(ae(),e,t):``;function He(e,t,n){return s?Ce(3,1,e,t,n):0}function Ue(e,t){if(s)return Ce(4,1,e,t)}var We=e=>{for(var t=0,n=0;n<e.length;++n){var r=e.charCodeAt(n);127>=r?t++:2047>=r?t+=2:55296<=r&&57343>=r?(t+=4,++n):t+=3}return t},V=(e,t,n)=>{var r=ae();if(t>>>=0,0<n){var i=t;n=t+n-1;for(var a=0;a<e.length;++a){var o=e.charCodeAt(a);if(55296<=o&&57343>=o&&(o=65536+((1023&o)<<10)|1023&e.charCodeAt(++a)),127>=o){if(t>=n)break;r[t++>>>0]=o}else{if(2047>=o){if(t+1>=n)break;r[t++>>>0]=192|o>>6}else{if(65535>=o){if(t+2>=n)break;r[t++>>>0]=224|o>>12}else{if(t+3>=n)break;r[t++>>>0]=240|o>>18,r[t++>>>0]=128|o>>12&63}r[t++>>>0]=128|o>>6&63}r[t++>>>0]=128|63&o}}r[t>>>0]=0,e=t-i}else e=0;return e};function Ge(e,t){if(s)return Ce(5,1,e,t)}function Ke(e,t,n){if(s)return Ce(6,1,e,t,n)}function qe(e,t,n){return s?Ce(7,1,e,t,n):0}function Je(e,t){if(s)return Ce(8,1,e,t)}function Ye(e,t,n){if(s)return Ce(9,1,e,t,n)}function Xe(e,t,n,r){if(s)return Ce(10,1,e,t,n,r)}function Ze(e,t,n,r){if(s)return Ce(11,1,e,t,n,r)}function Qe(e,t,n,r){if(s)return Ce(12,1,e,t,n,r)}function $e(e){if(s)return Ce(13,1,e)}function et(e,t){if(s)return Ce(14,1,e,t)}function tt(e,t,n){if(s)return Ce(15,1,e,t,n)}var nt,rt,it=()=>_e(``),at=e=>{for(var t=``;ae()[e>>>0];)t+=nt[ae()[e++>>>0]];return t},st={},ct={},lt={};function ut(e,t,n={}){return function(e,t,n={}){var r=t.name;if(!e)throw new rt(`type "${r}" must have a positive integer typeid pointer`);if(ct.hasOwnProperty(e)){if(n.Sb)return;throw new rt(`Cannot register type '${r}' twice`)}ct[e]=t,delete lt[e],st.hasOwnProperty(e)&&(t=st[e],delete st[e],t.forEach(e=>e()))}(e,t,n)}var dt=(e,t,n)=>{switch(t){case 1:return n?e=>ie()[e>>>0]:e=>ae()[e>>>0];case 2:return n?e=>oe()[e>>>1>>>0]:e=>se()[e>>>1>>>0];case 4:return n?e=>M()[e>>>2>>>0]:e=>N()[e>>>2>>>0];case 8:return n?e=>A[e>>>3]:e=>ee[e>>>3];default:throw TypeError(`invalid integer width (${t}): ${e}`)}};function ft(e,t,n){n>>>=0,ut(e>>>=0,{name:t=at(t>>>0),fromWireType:e=>e,toWireType:function(e,t){if(typeof t!=`bigint`&&typeof t!=`number`)throw t=t===null?`null`:(e=typeof t)==`object`||e===`array`||e===`function`?t.toString():``+t,TypeError(`Cannot convert "${t}" to ${this.name}`);return typeof t==`number`&&(t=BigInt(t)),t},Cb:pt,readValueFromPointer:dt(t,n,t.indexOf(`u`)==-1),Db:null})}var pt=8;function mt(e,t,n,r){ut(e>>>=0,{name:t=at(t>>>0),fromWireType:function(e){return!!e},toWireType:function(e,t){return t?n:r},Cb:pt,readValueFromPointer:function(e){return this.fromWireType(ae()[e>>>0])},Db:null})}var ht=[],gt=[];function _t(e){9<(e>>>=0)&&--gt[e+1]==0&&(gt[e]=void 0,ht.push(e))}var vt=e=>{if(!e)throw new rt(`Cannot use deleted val. handle = `+e);return gt[e]},yt=e=>{switch(e){case void 0:return 2;case null:return 4;case!0:return 6;case!1:return 8;default:let t=ht.pop()||gt.length;return gt[t]=e,gt[t+1]=1,t}};function bt(e){return this.fromWireType(N()[e>>>2>>>0])}var xt={name:`emscripten::val`,fromWireType:e=>{var t=vt(e);return _t(e),t},toWireType:(e,t)=>yt(t),Cb:pt,readValueFromPointer:bt,Db:null};function St(e){return ut(e>>>0,xt)}var Ct=(e,t)=>{switch(t){case 4:return function(e){return this.fromWireType(ce()[e>>>2>>>0])};case 8:return function(e){return this.fromWireType(le()[e>>>3>>>0])};default:throw TypeError(`invalid float width (${t}): ${e}`)}};function wt(e,t,n){n>>>=0,ut(e>>>=0,{name:t=at(t>>>0),fromWireType:e=>e,toWireType:(e,t)=>t,Cb:pt,readValueFromPointer:Ct(t,n),Db:null})}function Tt(e,t,n,r,i){if(e>>>=0,n>>>=0,t=at(t>>>0),i===-1&&(i=4294967295),i=e=>e,r===0){var a=32-8*n;i=e=>e<<a>>>a}var o=t.includes(`unsigned`)?function(e,t){return t>>>0}:function(e,t){return t};ut(e,{name:t,fromWireType:i,toWireType:o,Cb:pt,readValueFromPointer:dt(t,n,r!==0),Db:null})}function Et(e,t,n){function r(e){var t=N()[e>>>2>>>0];return e=N()[e+4>>>2>>>0],new i(ie().buffer,e,t)}var i=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array][t];ut(e>>>=0,{name:n=at(n>>>0),fromWireType:r,Cb:pt,readValueFromPointer:r},{Sb:!0})}function Dt(e,t){ut(e>>>=0,{name:t=at(t>>>0),fromWireType:function(e){for(var t,n=N()[e>>>2>>>0],r=e+4,i=r,a=0;a<=n;++a){var o=r+a;a!=n&&ae()[o>>>0]!=0||(i=Ve(i,o-i),t===void 0?t=i:(t+=`\0`,t+=i),i=o+1)}return hr(e),t},toWireType:function(e,t){t instanceof ArrayBuffer&&(t=new Uint8Array(t));var n=typeof t==`string`;if(!(n||t instanceof Uint8Array||t instanceof Uint8ClampedArray||t instanceof Int8Array))throw new rt(`Cannot pass non-string to std::string`);var r=n?We(t):t.length,i=gr(4+r+1),a=i+4;if(N()[i>>>2>>>0]=r,n)V(t,a,r+1);else if(n)for(n=0;n<r;++n){var o=t.charCodeAt(n);if(255<o)throw hr(i),new rt(`String has UTF-16 code units that do not fit in 8 bits`);ae()[a+n>>>0]=o}else for(n=0;n<r;++n)ae()[a+n>>>0]=t[n];return e!==null&&e.push(hr,i),i},Cb:pt,readValueFromPointer:bt,Db(e){hr(e)}})}var Ot=typeof TextDecoder<`u`?new TextDecoder(`utf-16le`):void 0,kt=(e,t)=>{for(var n=e>>1,r=n+t/2;!(n>=r)&&se()[n>>>0];)++n;if(32<(n<<=1)-e&&Ot)return Ot.decode(ae().slice(e,n));for(n=``,r=0;!(r>=t/2);++r){var i=oe()[e+2*r>>>1>>>0];if(i==0)break;n+=String.fromCharCode(i)}return n},At=(e,t,n)=>{if(n??=2147483647,2>n)return 0;var r=t;n=(n-=2)<2*e.length?n/2:e.length;for(var i=0;i<n;++i){var a=e.charCodeAt(i);oe()[t>>>1>>>0]=a,t+=2}return oe()[t>>>1>>>0]=0,t-r},jt=e=>2*e.length,Mt=(e,t)=>{for(var n=0,r=``;!(n>=t/4);){var i=M()[e+4*n>>>2>>>0];if(i==0)break;++n,65536<=i?(i-=65536,r+=String.fromCharCode(55296|i>>10,56320|1023&i)):r+=String.fromCharCode(i)}return r},Nt=(e,t,n)=>{if(t>>>=0,n??=2147483647,4>n)return 0;var r=t;n=r+n-4;for(var i=0;i<e.length;++i){var a=e.charCodeAt(i);if(55296<=a&&57343>=a&&(a=65536+((1023&a)<<10)|1023&e.charCodeAt(++i)),M()[t>>>2>>>0]=a,(t+=4)+4>n)break}return M()[t>>>2>>>0]=0,t-r},Pt=e=>{for(var t=0,n=0;n<e.length;++n){var r=e.charCodeAt(n);55296<=r&&57343>=r&&++n,t+=4}return t};function Ft(e,t,n){if(e>>>=0,t>>>=0,n=at(n>>>=0),t===2)var r=kt,i=At,a=jt,o=e=>se()[e>>>1>>>0];else t===4&&(r=Mt,i=Nt,a=Pt,o=e=>N()[e>>>2>>>0]);ut(e,{name:n,fromWireType:e=>{for(var n,i=N()[e>>>2>>>0],a=e+4,s=0;s<=i;++s){var c=e+4+s*t;s!=i&&o(c)!=0||(a=r(a,c-a),n===void 0?n=a:(n+=`\0`,n+=a),a=c+t)}return hr(e),n},toWireType:(e,r)=>{if(typeof r!=`string`)throw new rt(`Cannot pass non-string to C++ string type ${n}`);var o=a(r),s=gr(4+o+t);return N()[s>>>2>>>0]=o/t,i(r,s+4,o+t),e!==null&&e.push(hr,s),s},Cb:pt,readValueFromPointer:bt,Db(e){hr(e)}})}function It(e,t){ut(e>>>=0,{Tb:!0,name:t=at(t>>>0),Cb:0,fromWireType:()=>{},toWireType:()=>{}})}function Lt(e){_r(e>>>0,!o,1,!a,131072,!1),je()}var Rt=e=>{if(!j)try{if(e(),!(0<R))try{s?xr(S):Te(S)}catch(e){e instanceof L||e==`unwind`||m(0,e)}}catch(e){e instanceof L||e==`unwind`||m(0,e)}};function zt(e){e>>>=0,typeof Atomics.jc==`function`&&(Atomics.jc(M(),e>>>2,e).value.then(Bt),e+=128,Atomics.store(M(),e>>>2,1))}var Bt=()=>{var e=mr();e&&(zt(e),Rt(Cr))};function Vt(e,t){(e>>>=0)==t>>>0?setTimeout(Bt):s?postMessage({Gb:e,Bb:`checkMailbox`}):(e=ke[e])&&e.postMessage({Bb:`checkMailbox`})}var Ht=[];function Ut(e,t,n,r,i){for(t>>>=0,r/=2,Ht.length=r,n=i>>>0>>>3,i=0;i<r;i++)Ht[i]=A[n+2*i]?A[n+2*i+1]:le()[n+2*i+1>>>0];return(t?F[t]:dr[e])(...Ht)}var Wt=()=>{R=0};function Gt(e){e>>>=0,s?postMessage({Bb:`cleanupThread`,hc:e}):Ae(ke[e])}function Kt(e){}var qt=(e,t)=>{var n=ct[e];if(n===void 0)throw e=fr(e),n=at(e),hr(e),new rt(`${t} has unknown type ${n}`);return n},Jt=(e,t,n)=>{var r=[];return e=e.toWireType(r,n),r.length&&(N()[t>>>2>>>0]=yt(r)),e};function Yt(e,t,n){return t>>>=0,n>>>=0,e=vt(e>>>0),t=qt(t,`emval::as`),Jt(t,n,e)}function Xt(e,t){return t>>>=0,e=vt(e>>>0),(t=qt(t,`emval::as`)).toWireType(null,e)}var Zt=e=>{try{e()}catch(e){_e(e)}},Qt=0,$t=null,en=0,tn=[],nn={},H={},rn=0,an=null,on=[];function sn(e){return function(e){if(!j){if(Qt===0){var t=!1,n=!1;e((e=0)=>{if(!j&&(en=e,t=!0,n)){Qt=2,Zt(()=>jr($t)),typeof MainLoop<`u`&&MainLoop.Pb&&MainLoop.resume(),e=!1;try{var r=function(){var e=M()[$t+8>>>2>>>0];return e=Z[H[e]],--R,e()}()}catch(t){r=t,e=!0}var i=!1;if(!$t){var a=an;a&&(an=null,(e?a.reject:a.resolve)(r),i=!0)}if(e&&!i)throw r}}),n=!0,t||(Qt=1,$t=function(){var e=gr(65548),t=e+12;N()[e>>>2>>>0]=t,N()[e+4>>>2>>>0]=t+65536,t=tn[0];var n=nn[t];return n===void 0&&(n=rn++,nn[t]=n,H[n]=t),t=n,M()[e+8>>>2>>>0]=t,e}(),typeof MainLoop<`u`&&MainLoop.Pb&&MainLoop.pause(),Zt(()=>kr($t)))}else Qt===2?(Qt=0,Zt(Mr),hr($t),$t=null,on.forEach(Rt)):_e(`invalid state: ${Qt}`);return en}}(t=>{e().then(t)})}function cn(e){return e>>>=0,sn(async()=>yt(await vt(e)))}var ln=[];function un(e,t,n,r){return n>>>=0,r>>>=0,(e=ln[e>>>0])(null,t=vt(t>>>0),n,r)}var dn={},U=e=>{var t=dn[e];return t===void 0?at(e):t};function fn(e,t,n,r,i){return n>>>=0,r>>>=0,i>>>=0,(e=ln[e>>>0])(t=vt(t>>>0),t[n=U(n)],r,i)}var pn=()=>typeof globalThis==`object`?globalThis:Function(`return this`)();function mn(e){return(e>>>=0)==0?yt(pn()):(e=U(e),yt(pn()[e]))}var W=e=>{var t=ln.length;return ln.push(e),t},hn=(e,t)=>{for(var n=Array(e),r=0;r<e;++r)n[r]=qt(N()[t+4*r>>>2>>>0],`parameter `+r);return n},gn=(e,t)=>Object.defineProperty(t,`name`,{value:e});function _n(e,t,n){var r=(t=hn(e,t>>>0)).shift();e--;var i=`return function (obj, func, destructorsRef, args) {
3
+ `,a=0,o=[];n===0&&o.push(`obj`);for(var s=[`retType`],c=[r],l=0;l<e;++l)o.push(`arg`+l),s.push(`argType`+l),c.push(t[l]),i+=` var arg${l} = argType${l}.readValueFromPointer(args${a?`+`+a:``});
4
+ `,a+=t[l].Cb;return i+=` var rv = ${n===1?`new func`:`func.call`}(${o.join(`, `)});
5
+ `,r.Tb||(s.push(`emval_returnValue`),c.push(Jt),i+=` return emval_returnValue(retType, destructorsRef, rv);
6
+ `),s.push(i+`};
7
+ `),e=function(e){var t=Function;if(!(t instanceof Function))throw TypeError(`new_ called with constructor type ${typeof t} which is not a function`);var n=gn(t.name||`unknownFunctionName`,function(){});return n.prototype=t.prototype,n=new n,(e=t.apply(n,e))instanceof Object?e:n}(s)(...c),n=`methodCaller<(${t.map(e=>e.name).join(`, `)}) => ${r.name}>`,W(gn(n,e))}function vn(e){return e=U(e>>>0),yt(r[e])}function G(e,t){return t>>>=0,e=vt(e>>>0),t=vt(t),yt(e[t])}function yn(e){9<(e>>>=0)&&(gt[e+1]+=1)}function bn(){return yt([])}function xn(e){e=vt(e>>>0);for(var t=Array(e.length),n=0;n<e.length;n++)t[n]=e[n];return yt(t)}function Sn(e){return yt(U(e>>>0))}function Cn(){return yt({})}function wn(e){for(var t=vt(e>>>=0);t.length;){var n=t.pop();t.pop()(n)}_t(e)}function Tn(e,t,n){t>>>=0,n>>>=0,e=vt(e>>>0),t=vt(t),n=vt(n),e[t]=n}function En(e,t){return t>>>=0,e=(e=qt(e>>>0,`_emval_take_value`)).readValueFromPointer(t),yt(e)}function Dn(e,t){e=-9007199254740992>e||9007199254740992<e?NaN:Number(e),t>>>=0,e=new Date(1e3*e),M()[t>>>2>>>0]=e.getUTCSeconds(),M()[t+4>>>2>>>0]=e.getUTCMinutes(),M()[t+8>>>2>>>0]=e.getUTCHours(),M()[t+12>>>2>>>0]=e.getUTCDate(),M()[t+16>>>2>>>0]=e.getUTCMonth(),M()[t+20>>>2>>>0]=e.getUTCFullYear()-1900,M()[t+24>>>2>>>0]=e.getUTCDay(),e=(e.getTime()-Date.UTC(e.getUTCFullYear(),0,1,0,0,0,0))/864e5|0,M()[t+28>>>2>>>0]=e}var On=e=>e%4==0&&(e%100!=0||e%400==0),kn=[0,31,60,91,121,152,182,213,244,274,305,335],An=[0,31,59,90,120,151,181,212,243,273,304,334];function jn(e,t){e=-9007199254740992>e||9007199254740992<e?NaN:Number(e),t>>>=0,e=new Date(1e3*e),M()[t>>>2>>>0]=e.getSeconds(),M()[t+4>>>2>>>0]=e.getMinutes(),M()[t+8>>>2>>>0]=e.getHours(),M()[t+12>>>2>>>0]=e.getDate(),M()[t+16>>>2>>>0]=e.getMonth(),M()[t+20>>>2>>>0]=e.getFullYear()-1900,M()[t+24>>>2>>>0]=e.getDay();var n=(On(e.getFullYear())?kn:An)[e.getMonth()]+e.getDate()-1|0;M()[t+28>>>2>>>0]=n,M()[t+36>>>2>>>0]=-60*e.getTimezoneOffset(),n=new Date(e.getFullYear(),6,1).getTimezoneOffset();var r=new Date(e.getFullYear(),0,1).getTimezoneOffset();e=0|(n!=r&&e.getTimezoneOffset()==Math.min(r,n)),M()[t+32>>>2>>>0]=e}function Mn(e){e>>>=0;var t=new Date(M()[e+20>>>2>>>0]+1900,M()[e+16>>>2>>>0],M()[e+12>>>2>>>0],M()[e+8>>>2>>>0],M()[e+4>>>2>>>0],M()[e>>>2>>>0],0),n=M()[e+32>>>2>>>0],r=t.getTimezoneOffset(),i=new Date(t.getFullYear(),6,1).getTimezoneOffset(),a=new Date(t.getFullYear(),0,1).getTimezoneOffset(),o=Math.min(a,i);return 0>n?M()[e+32>>>2>>>0]=+(i!=a&&o==r):0<n!=(o==r)&&(i=Math.max(a,i),t.setTime(t.getTime()+6e4*((0<n?o:i)-r))),M()[e+24>>>2>>>0]=t.getDay(),n=(On(t.getFullYear())?kn:An)[t.getMonth()]+t.getDate()-1|0,M()[e+28>>>2>>>0]=n,M()[e>>>2>>>0]=t.getSeconds(),M()[e+4>>>2>>>0]=t.getMinutes(),M()[e+8>>>2>>>0]=t.getHours(),M()[e+12>>>2>>>0]=t.getDate(),M()[e+16>>>2>>>0]=t.getMonth(),M()[e+20>>>2>>>0]=t.getYear(),e=t.getTime(),BigInt(isNaN(e)?-1:e/1e3)}function Nn(e,t,n,r,i,a,o){return s?Ce(16,1,e,t,n,r,i,a,o):-52}function Pn(e,t,n,r,i,a){if(s)return Ce(17,1,e,t,n,r,i,a)}var Fn={},In=()=>performance.timeOrigin+performance.now();function Ln(e,t){return s?Ce(18,1,e,t):(Fn[e]&&(clearTimeout(Fn[e].id),delete Fn[e]),t&&(Fn[e]={id:setTimeout(()=>{delete Fn[e],Rt(()=>Sr(e,performance.timeOrigin+performance.now()))},t),qc:t}),0)}function Rn(e,t,n,r){e>>>=0,t>>>=0,n>>>=0,r>>>=0;var i=new Date().getFullYear(),a=new Date(i,0,1).getTimezoneOffset();i=new Date(i,6,1).getTimezoneOffset();var o=Math.max(a,i);N()[e>>>2>>>0]=60*o,M()[t>>>2>>>0]=+(a!=i),e=(t=e=>{var t=Math.abs(e);return`UTC${0<=e?`-`:`+`}${String(Math.floor(t/60)).padStart(2,`0`)}${String(t%60).padStart(2,`0`)}`})(a),t=t(i),i<a?(V(e,n,17),V(t,r,17)):(V(e,r,17),V(t,n,17))}var zn=()=>Date.now(),Bn=1;function Vn(e,t,n){if(!(0<=e&&3>=e))return 28;if(e===0)e=Date.now();else{if(!Bn)return 52;e=performance.timeOrigin+performance.now()}return A[n>>>0>>>3]=BigInt(Math.round(1e6*e)),0}var Hn=[],Un=(e,t)=>{Hn.length=0;for(var n;n=ae()[e++>>>0];){var r=n!=105;t+=(r&=n!=112)&&t%8?4:0,Hn.push(n==112?N()[t>>>2>>>0]:n==106?A[t>>>3]:n==105?M()[t>>>2>>>0]:le()[t>>>3>>>0]),t+=r?8:4}return Hn};function Wn(e,t,n){return e>>>=0,t=Un(t>>>0,n>>>0),F[e](...t)}function Gn(e,t,n){return e>>>=0,t=Un(t>>>0,n>>>0),F[e](...t)}var Kn=()=>{};function qn(e,t){return y(Ve(e>>>0,t>>>0))}var Jn=()=>{throw R+=1,`unwind`};function Yn(){return 4294901760}var Xn=()=>navigator.hardwareConcurrency;function Zn(){return _e(`Cannot use emscripten_pc_get_function without -sUSE_OFFSET_CONVERTER`),0}function Qn(e){e>>>=0;var t=ae().length;if(e<=t||4294901760<e)return!1;for(var n=1;4>=n;n*=2){var r=t*(1+.2/n);r=Math.min(r,e+100663296);e:{r=(Math.min(4294901760,65536*Math.ceil(Math.max(e,r)/65536))-b.buffer.byteLength+65535)/65536|0;try{b.grow(r),fe();var i=1;break e}catch{}i=void 0}if(i)return!0}return!1}var $n=()=>(_e(`Cannot use convertFrameToPC (needed by __builtin_return_address) without -sUSE_OFFSET_CONVERTER`),0),K={},er=e=>{e.forEach(e=>{var t=$n();t&&(K[t]=e)})};function tr(){var e=Error().stack.toString().split(`
8
+ `);return e[0]==`Error`&&e.shift(),er(e),K.Lb=$n(),K.cc=e,K.Lb}function nr(e,t,n){if(e>>>=0,t>>>=0,K.Lb==e)var r=K.cc;else (r=Error().stack.toString().split(`
9
+ `))[0]==`Error`&&r.shift(),er(r);for(var i=3;r[i]&&$n()!=e;)++i;for(e=0;e<n&&r[e+i];++e)M()[t+4*e>>>2>>>0]=$n();return e}var rr,q={},ir=()=>{if(!rr){var e,t={USER:`web_user`,LOGNAME:`web_user`,PATH:`/`,PWD:`/`,HOME:`/home/web_user`,LANG:(typeof navigator==`object`&&navigator.languages&&navigator.languages[0]||`C`).replace(`-`,`_`)+`.UTF-8`,_:`./this.program`};for(e in q)q[e]===void 0?delete t[e]:t[e]=q[e];var n=[];for(e in t)n.push(`${e}=${t[e]}`);rr=n}return rr};function J(e,t){if(s)return Ce(19,1,e,t);e>>>=0,t>>>=0;var n=0;return ir().forEach((r,i)=>{var a=t+n;for(i=N()[e+4*i>>>2>>>0]=a,a=0;a<r.length;++a)ie()[i++>>>0]=r.charCodeAt(a);ie()[i>>>0]=0,n+=r.length+1}),0}function Y(e,t){if(s)return Ce(20,1,e,t);e>>>=0,t>>>=0;var n=ir();N()[e>>>2>>>0]=n.length;var r=0;return n.forEach(e=>r+=e.length+1),N()[t>>>2>>>0]=r,0}function ar(e){return s?Ce(21,1,e):52}function or(e,t,n,r){return s?Ce(22,1,e,t,n,r):52}function sr(e,t,n,r){return s?Ce(23,1,e,t,n,r):70}var cr=[null,[],[]];function X(e,t,n,r){if(s)return Ce(24,1,e,t,n,r);t>>>=0,n>>>=0,r>>>=0;for(var i=0,a=0;a<n;a++){var o=N()[t>>>2>>>0],c=N()[t+4>>>2>>>0];t+=8;for(var l=0;l<c;l++){var u=ae()[o+l>>>0],d=cr[e];u===0||u===10?((e===1?v:y)(B(d)),d.length=0):d.push(u)}i+=c}return N()[r>>>2>>>0]=i,0}s||function(){for(var e=r.numThreads-1;e--;)Ne();xe.unshift(()=>{me++,function(e){s?e():Promise.all(Ee.map(Me)).then(e)}(()=>ge())})}();for(var lr=Array(256),ur=0;256>ur;++ur)lr[ur]=String.fromCharCode(ur);nt=lr,rt=r.BindingError=class extends Error{constructor(e){super(e),this.name=`BindingError`}},r.InternalError=class extends Error{constructor(e){super(e),this.name=`InternalError`}},gt.push(0,1,void 0,1,null,1,!0,1,!1,1),r.count_emval_handles=()=>gt.length/2-5-ht.length;var Z,dr=[z,we,Re,He,Ue,Ge,Ke,qe,Je,Ye,Xe,Ze,Qe,$e,et,tt,Nn,Pn,Ln,J,Y,ar,or,sr,X];(async function(){function e(e,t){return Z=e.exports,Z=function(){var e=Z,t={};for(let[n,r]of Object.entries(e))t[n]=typeof r==`function`?(...e)=>{tn.push(n);try{return r(...e)}finally{j||(tn.pop(),$t&&Qt===1&&tn.length===0&&(Qt=0,R+=1,Zt(Ar),typeof Fibers<`u`&&Fibers.rc()))}}:r;return t}(),Z=function(){var e=Z,t=e=>t=>e(t)>>>0,n=e=>()=>e()>>>0;return(e=Object.assign({},e)).Da=t(e.Da),e.fb=n(e.fb),e.hb=t(e.hb),e.tb=t(e.tb),e.ub=n(e.ub),e.__cxa_get_exception_ptr=t(e.__cxa_get_exception_ptr),e}(),Oe.push(Z.ib),x=t,ge(),Z}me++;var t=ve();if(r.instantiateWasm)return new Promise(n=>{r.instantiateWasm(t,(t,r)=>{e(t,r),n(t.exports)})});if(s)return new Promise(t=>{ue=n=>{t(e(new WebAssembly.Instance(n,ve()),n))}});P??=r.locateFile?r.locateFile?r.locateFile(`ort-wasm-simd-threaded.jsep.wasm`,h):h+`ort-wasm-simd-threaded.jsep.wasm`:new URL(`/assets/ort-wasm-simd-threaded.jsep-B0T3yYHD.wasm`,``+import.meta.url).href;try{var i=await async function(e){var t=P;if(!ne&&typeof WebAssembly.instantiateStreaming==`function`&&!re(t))try{var n=fetch(t,{credentials:`same-origin`});return await WebAssembly.instantiateStreaming(n,e)}catch(e){y(`wasm streaming compile failed: ${e}`),y(`falling back to ArrayBuffer instantiation`)}return async function(e,t){try{var n=await async function(e){if(!ne)try{var t=await d(e);return new Uint8Array(t)}catch{}if(e==P&&ne)e=new Uint8Array(ne);else{if(!f)throw`both async and sync fetching of the wasm failed`;e=f(e)}return e}(e);return await WebAssembly.instantiate(n,t)}catch(e){y(`failed to asynchronously prepare wasm: ${e}`),_e(e)}}(t,e)}(t);return e(i.instance,i.module)}catch(e){return n(e),Promise.reject(e)}})();var fr=e=>(fr=Z.Da)(e),pr=()=>(pr=Z.Ea)();r._OrtInit=(e,t)=>(r._OrtInit=Z.Fa)(e,t),r._OrtGetLastError=(e,t)=>(r._OrtGetLastError=Z.Ga)(e,t),r._OrtCreateSessionOptions=(e,t,n,i,a,o,s,c,l,u)=>(r._OrtCreateSessionOptions=Z.Ha)(e,t,n,i,a,o,s,c,l,u),r._OrtAppendExecutionProvider=(e,t,n,i,a)=>(r._OrtAppendExecutionProvider=Z.Ia)(e,t,n,i,a),r._OrtAddFreeDimensionOverride=(e,t,n)=>(r._OrtAddFreeDimensionOverride=Z.Ja)(e,t,n),r._OrtAddSessionConfigEntry=(e,t,n)=>(r._OrtAddSessionConfigEntry=Z.Ka)(e,t,n),r._OrtReleaseSessionOptions=e=>(r._OrtReleaseSessionOptions=Z.La)(e),r._OrtCreateSession=(e,t,n)=>(r._OrtCreateSession=Z.Ma)(e,t,n),r._OrtReleaseSession=e=>(r._OrtReleaseSession=Z.Na)(e),r._OrtGetInputOutputCount=(e,t,n)=>(r._OrtGetInputOutputCount=Z.Oa)(e,t,n),r._OrtGetInputOutputMetadata=(e,t,n,i)=>(r._OrtGetInputOutputMetadata=Z.Pa)(e,t,n,i),r._OrtFree=e=>(r._OrtFree=Z.Qa)(e),r._OrtCreateTensor=(e,t,n,i,a,o)=>(r._OrtCreateTensor=Z.Ra)(e,t,n,i,a,o),r._OrtGetTensorData=(e,t,n,i,a)=>(r._OrtGetTensorData=Z.Sa)(e,t,n,i,a),r._OrtReleaseTensor=e=>(r._OrtReleaseTensor=Z.Ta)(e),r._OrtCreateRunOptions=(e,t,n,i)=>(r._OrtCreateRunOptions=Z.Ua)(e,t,n,i),r._OrtAddRunConfigEntry=(e,t,n)=>(r._OrtAddRunConfigEntry=Z.Va)(e,t,n),r._OrtReleaseRunOptions=e=>(r._OrtReleaseRunOptions=Z.Wa)(e),r._OrtCreateBinding=e=>(r._OrtCreateBinding=Z.Xa)(e),r._OrtBindInput=(e,t,n)=>(r._OrtBindInput=Z.Ya)(e,t,n),r._OrtBindOutput=(e,t,n,i)=>(r._OrtBindOutput=Z.Za)(e,t,n,i),r._OrtClearBoundOutputs=e=>(r._OrtClearBoundOutputs=Z._a)(e),r._OrtReleaseBinding=e=>(r._OrtReleaseBinding=Z.$a)(e),r._OrtRunWithBinding=(e,t,n,i,a)=>(r._OrtRunWithBinding=Z.ab)(e,t,n,i,a),r._OrtRun=(e,t,n,i,a,o,s,c)=>(r._OrtRun=Z.bb)(e,t,n,i,a,o,s,c),r._OrtEndProfiling=e=>(r._OrtEndProfiling=Z.cb)(e),r._JsepOutput=(e,t,n)=>(r._JsepOutput=Z.db)(e,t,n),r._JsepGetNodeName=e=>(r._JsepGetNodeName=Z.eb)(e);var mr=()=>(mr=Z.fb)(),hr=r._free=e=>(hr=r._free=Z.gb)(e),gr=r._malloc=e=>(gr=r._malloc=Z.hb)(e),_r=(e,t,n,r,i,a)=>(_r=Z.kb)(e,t,n,r,i,a),vr=()=>(vr=Z.lb)(),yr=(e,t,n,r,i)=>(yr=Z.mb)(e,t,n,r,i),br=e=>(br=Z.nb)(e),xr=e=>(xr=Z.ob)(e),Sr=(e,t)=>(Sr=Z.pb)(e,t),Cr=()=>(Cr=Z.qb)(),wr=(e,t)=>(wr=Z.rb)(e,t),Tr=e=>(Tr=Z.sb)(e),Er=e=>(Er=Z.tb)(e),Dr=()=>(Dr=Z.ub)(),Or=r.dynCall_ii=(e,t)=>(Or=r.dynCall_ii=Z.vb)(e,t),kr=e=>(kr=Z.wb)(e),Ar=()=>(Ar=Z.xb)(),jr=e=>(jr=Z.yb)(e),Mr=()=>(Mr=Z.zb)();return r.stackSave=()=>Dr(),r.stackRestore=e=>Tr(e),r.stackAlloc=e=>Er(e),r.setValue=function(e,t,n=`i8`){switch(n.endsWith(`*`)&&(n=`*`),n){case`i1`:case`i8`:ie()[e>>>0]=t;break;case`i16`:oe()[e>>>1>>>0]=t;break;case`i32`:M()[e>>>2>>>0]=t;break;case`i64`:A[e>>>3]=BigInt(t);break;case`float`:ce()[e>>>2>>>0]=t;break;case`double`:le()[e>>>3>>>0]=t;break;case`*`:N()[e>>>2>>>0]=t;break;default:_e(`invalid type for setValue: ${n}`)}},r.getValue=function(e,t=`i8`){switch(t.endsWith(`*`)&&(t=`*`),t){case`i1`:case`i8`:return ie()[e>>>0];case`i16`:return oe()[e>>>1>>>0];case`i32`:return M()[e>>>2>>>0];case`i64`:return A[e>>>3];case`float`:return ce()[e>>>2>>>0];case`double`:return le()[e>>>3>>>0];case`*`:return N()[e>>>2>>>0];default:_e(`invalid type for getValue: ${t}`)}},r.UTF8ToString=Ve,r.stringToUTF8=V,r.lengthBytesUTF8=We,function e(){if(0<me)he=e;else if(s)t(r),pe();else{for(;0<xe.length;)xe.shift()(r);0<me?he=e:(r.calledRun=!0,j||(pe(),t(r)))}}(),r.PTR_SIZE=4,i}),ct=st,lt=globalThis.self?.name?.startsWith(`em-pthread`),lt&&st()}),dt,ft,pt,mt,ht,gt,_t,vt,yt,bt,xt,St,Ct,wt,Tt=M(()=>{$e(),dt=typeof location>`u`?void 0:location.origin,ft=import.meta.url>`file:`&&import.meta.url<`file;`,pt=()=>ft?new URL(new URL(`ort.bundle.min.mjs`,import.meta.url).href,dt).href:import.meta.url,mt=pt(),ht=()=>{if(mt&&!mt.startsWith(`blob:`))return mt.substring(0,mt.lastIndexOf(`/`)+1)},gt=(e,t)=>{try{let n=t??mt;return(n?new URL(e,n):new URL(e)).origin===dt}catch{return!1}},_t=(e,t)=>{let n=t??mt;try{return(n?new URL(e,n):new URL(e)).href}catch{return}},vt=(e,t)=>`${t??`./`}${e}`,yt=async e=>{let t=await(await fetch(e,{credentials:`same-origin`})).blob();return URL.createObjectURL(t)},bt=async e=>(await n(async()=>{let{default:t}=await import(e);return{default:t}},[])).default,xt=(it(),le(et)).default,St=async()=>{if(!mt)throw Error(`Failed to load proxy worker: cannot determine the script source URL.`);if(gt(mt))return[void 0,xt()];let e=await yt(mt);return[e,xt(e)]},Ct=(ut(),le(at)).default,wt=async(e,t,n)=>{if(!e&&!t&&Ct&&mt&&gt(mt))return[void 0,Ct];{let r=`ort-wasm-simd-threaded.jsep.mjs`,i=e??_t(r,t),a=n&&i&&!gt(i,t),o=a?await yt(i):i??vt(r,t);return[a?o:void 0,await bt(o)]}}}),Et,Dt,Ot,kt,At,jt,Mt,Nt,Pt,Ft=M(()=>{Tt(),Dt=!1,Ot=!1,kt=!1,At=()=>{if(typeof SharedArrayBuffer>`u`)return!1;try{return typeof MessageChannel<`u`&&new MessageChannel().port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11]))}catch{return!1}},jt=()=>{try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,30,1,28,0,65,0,253,15,253,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,253,186,1,26,11]))}catch{return!1}},Mt=()=>{try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,19,1,17,0,65,1,253,15,65,2,253,15,65,3,253,15,253,147,2,11]))}catch{return!1}},Nt=async e=>{if(Dt)return Promise.resolve();if(Ot)throw Error(`multiple calls to 'initializeWebAssembly()' detected.`);if(kt)throw Error(`previous call to 'initializeWebAssembly()' failed.`);Ot=!0;let t=e.initTimeout,n=e.numThreads;if(e.simd!==!1){if(e.simd===`relaxed`){if(!Mt())throw Error(`Relaxed WebAssembly SIMD is not supported in the current environment.`)}else if(!jt())throw Error(`WebAssembly SIMD is not supported in the current environment.`)}let r=At();n>1&&!r&&(typeof self<`u`&&!self.crossOriginIsolated&&console.warn(`env.wasm.numThreads is set to `+n+`, but this will not work unless you enable crossOriginIsolated mode. See https://web.dev/cross-origin-isolation-guide/ for more info.`),console.warn(`WebAssembly multi-threading is not supported in the current environment. Falling back to single-threading.`),e.numThreads=n=1);let i=e.wasmPaths,a=typeof i==`string`?i:void 0,o=i?.mjs,s=o?.href??o,c=i?.wasm,l=c?.href??c,u=e.wasmBinary,[d,f]=await wt(s,a,n>1),p=!1,m=[];if(t>0&&m.push(new Promise(e=>{setTimeout(()=>{p=!0,e()},t)})),m.push(new Promise((e,t)=>{let r={numThreads:n};if(u)r.wasmBinary=u;else if(l||a)r.locateFile=e=>l??a+e;else if(s&&s.indexOf(`blob:`)!==0)r.locateFile=e=>new URL(e,s).href;else if(d){let e=ht();e&&(r.locateFile=t=>e+t)}f(r).then(t=>{Ot=!1,Dt=!0,Et=t,e(),d&&URL.revokeObjectURL(d)},e=>{Ot=!1,kt=!0,t(e)})})),await Promise.race(m),p)throw Error(`WebAssembly backend initializing failed due to timeout: ${t}ms`)},Pt=()=>{if(Dt&&Et)return Et;throw Error(`WebAssembly is not initialized yet.`)}}),It,Lt,Rt,zt=M(()=>{Ft(),It=(e,t)=>{let n=Pt(),r=n.lengthBytesUTF8(e)+1,i=n._malloc(r);return n.stringToUTF8(e,i,r),t.push(i),i},Lt=(e,t,n,r)=>{if(typeof e==`object`&&e){if(n.has(e))throw Error(`Circular reference in options`);n.add(e)}Object.entries(e).forEach(([e,i])=>{let a=t?t+e:e;if(typeof i==`object`)Lt(i,a+`.`,n,r);else if(typeof i==`string`||typeof i==`number`)r(a,i.toString());else if(typeof i==`boolean`)r(a,i?`1`:`0`);else throw Error(`Can't handle extra config type: ${typeof i}`)})},Rt=e=>{let t=Pt(),n=t.stackSave();try{let n=t.PTR_SIZE,r=t.stackAlloc(2*n);t._OrtGetLastError(r,r+n);let i=Number(t.getValue(r,n===4?`i32`:`i64`)),a=t.getValue(r+n,`*`),o=a?t.UTF8ToString(a):``;throw Error(`${e} ERROR_CODE: ${i}, ERROR_MESSAGE: ${o}`)}finally{t.stackRestore(n)}}}),Bt,Vt=M(()=>{Ft(),zt(),Bt=e=>{let t=Pt(),n=0,r=[],i=e||{};try{if(e?.logSeverityLevel===void 0)i.logSeverityLevel=2;else if(typeof e.logSeverityLevel!=`number`||!Number.isInteger(e.logSeverityLevel)||e.logSeverityLevel<0||e.logSeverityLevel>4)throw Error(`log serverity level is not valid: ${e.logSeverityLevel}`);if(e?.logVerbosityLevel===void 0)i.logVerbosityLevel=0;else if(typeof e.logVerbosityLevel!=`number`||!Number.isInteger(e.logVerbosityLevel))throw Error(`log verbosity level is not valid: ${e.logVerbosityLevel}`);e?.terminate===void 0&&(i.terminate=!1);let a=0;return e?.tag!==void 0&&(a=It(e.tag,r)),n=t._OrtCreateRunOptions(i.logSeverityLevel,i.logVerbosityLevel,!!i.terminate,a),n===0&&Rt(`Can't create run options.`),e?.extra!==void 0&&Lt(e.extra,``,new WeakSet,(e,i)=>{let a=It(e,r),o=It(i,r);t._OrtAddRunConfigEntry(n,a,o)!==0&&Rt(`Can't set a run config entry: ${e} - ${i}.`)}),[n,r]}catch(e){throw n!==0&&t._OrtReleaseRunOptions(n),r.forEach(e=>t._free(e)),e}}}),Ht,Ut,Wt,Gt,Kt,qt,Jt=M(()=>{Ft(),zt(),Ht=e=>{switch(e){case`disabled`:return 0;case`basic`:return 1;case`extended`:return 2;case`all`:return 99;default:throw Error(`unsupported graph optimization level: ${e}`)}},Ut=e=>{switch(e){case`sequential`:return 0;case`parallel`:return 1;default:throw Error(`unsupported execution mode: ${e}`)}},Wt=e=>{e.extra||={},e.extra.session||(e.extra.session={});let t=e.extra.session;t.use_ort_model_bytes_directly||=`1`,e.executionProviders&&e.executionProviders.some(e=>(typeof e==`string`?e:e.name)===`webgpu`)&&(e.enableMemPattern=!1)},Gt=(e,t,n,r)=>{let i=It(t,r),a=It(n,r);Pt()._OrtAddSessionConfigEntry(e,i,a)!==0&&Rt(`Can't set a session config entry: ${t} - ${n}.`)},Kt=async(e,t,n)=>{for(let r of t){let t=typeof r==`string`?r:r.name,i=[];switch(t){case`webnn`:if(t=`WEBNN`,typeof r!=`string`){let t=r?.deviceType;t&&Gt(e,`deviceType`,t,n)}break;case`webgpu`:if(t=`JS`,typeof r!=`string`){let t=r;if(t?.preferredLayout){if(t.preferredLayout!==`NCHW`&&t.preferredLayout!==`NHWC`)throw Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${t.preferredLayout}`);Gt(e,`preferredLayout`,t.preferredLayout,n)}}break;case`wasm`:case`cpu`:continue;default:throw Error(`not supported execution provider: ${t}`)}let a=It(t,n),o=i.length,s=0,c=0;if(o>0){s=Pt()._malloc(o*Pt().PTR_SIZE),n.push(s),c=Pt()._malloc(o*Pt().PTR_SIZE),n.push(c);for(let e=0;e<o;e++)Pt().setValue(s+e*Pt().PTR_SIZE,i[e][0],`*`),Pt().setValue(c+e*Pt().PTR_SIZE,i[e][1],`*`)}await Pt()._OrtAppendExecutionProvider(e,a,s,c,o)!==0&&Rt(`Can't append execution provider: ${t}.`)}},qt=async e=>{let t=Pt(),n=0,r=[],i=e||{};Wt(i);try{let e=Ht(i.graphOptimizationLevel??`all`),a=Ut(i.executionMode??`sequential`),o=typeof i.logId==`string`?It(i.logId,r):0,s=i.logSeverityLevel??2;if(!Number.isInteger(s)||s<0||s>4)throw Error(`log serverity level is not valid: ${s}`);let c=i.logVerbosityLevel??0;if(!Number.isInteger(c)||c<0||c>4)throw Error(`log verbosity level is not valid: ${c}`);let l=typeof i.optimizedModelFilePath==`string`?It(i.optimizedModelFilePath,r):0;if(n=t._OrtCreateSessionOptions(e,!!i.enableCpuMemArena,!!i.enableMemPattern,a,!!i.enableProfiling,0,o,s,c,l),n===0&&Rt(`Can't create session options.`),i.executionProviders&&await Kt(n,i.executionProviders,r),i.enableGraphCapture!==void 0){if(typeof i.enableGraphCapture!=`boolean`)throw Error(`enableGraphCapture must be a boolean value: ${i.enableGraphCapture}`);Gt(n,`enableGraphCapture`,i.enableGraphCapture.toString(),r)}if(i.freeDimensionOverrides)for(let[e,a]of Object.entries(i.freeDimensionOverrides)){if(typeof e!=`string`)throw Error(`free dimension override name must be a string: ${e}`);if(typeof a!=`number`||!Number.isInteger(a)||a<0)throw Error(`free dimension override value must be a non-negative integer: ${a}`);let i=It(e,r);t._OrtAddFreeDimensionOverride(n,i,a)!==0&&Rt(`Can't set a free dimension override: ${e} - ${a}.`)}return i.extra!==void 0&&Lt(i.extra,``,new WeakSet,(e,t)=>{Gt(n,e,t,r)}),[n,r]}catch(e){throw n!==0&&t._OrtReleaseSessionOptions(n)!==0&&Rt(`Can't release session options.`),r.forEach(e=>t._free(e)),e}}}),Yt,Xt,Zt,Qt,$t,en,tn,nn,H=M(()=>{Yt=e=>{switch(e){case`int8`:return 3;case`uint8`:return 2;case`bool`:return 9;case`int16`:return 5;case`uint16`:return 4;case`int32`:return 6;case`uint32`:return 12;case`float16`:return 10;case`float32`:return 1;case`float64`:return 11;case`string`:return 8;case`int64`:return 7;case`uint64`:return 13;case`int4`:return 22;case`uint4`:return 21;default:throw Error(`unsupported data type: ${e}`)}},Xt=e=>{switch(e){case 3:return`int8`;case 2:return`uint8`;case 9:return`bool`;case 5:return`int16`;case 4:return`uint16`;case 6:return`int32`;case 12:return`uint32`;case 10:return`float16`;case 1:return`float32`;case 11:return`float64`;case 8:return`string`;case 7:return`int64`;case 13:return`uint64`;case 22:return`int4`;case 21:return`uint4`;default:throw Error(`unsupported data type: ${e}`)}},Zt=(e,t)=>{let n=[-1,4,1,1,2,2,4,8,-1,1,2,8,4,8,-1,-1,-1,-1,-1,-1,-1,.5,.5][e],r=typeof t==`number`?t:t.reduce((e,t)=>e*t,1);return n>0?Math.ceil(r*n):void 0},Qt=e=>{switch(e){case`float16`:return typeof Float16Array<`u`&&Float16Array.from?Float16Array:Uint16Array;case`float32`:return Float32Array;case`uint8`:return Uint8Array;case`int8`:return Int8Array;case`uint16`:return Uint16Array;case`int16`:return Int16Array;case`int32`:return Int32Array;case`bool`:return Uint8Array;case`float64`:return Float64Array;case`uint32`:return Uint32Array;case`int64`:return BigInt64Array;case`uint64`:return BigUint64Array;default:throw Error(`unsupported type: ${e}`)}},$t=e=>{switch(e){case`verbose`:return 0;case`info`:return 1;case`warning`:return 2;case`error`:return 3;case`fatal`:return 4;default:throw Error(`unsupported logging level: ${e}`)}},en=e=>e===`float32`||e===`float16`||e===`int32`||e===`int64`||e===`uint32`||e===`uint8`||e===`bool`||e===`uint4`||e===`int4`,tn=e=>e===`float32`||e===`float16`||e===`int32`||e===`int64`||e===`uint32`||e===`uint64`||e===`int8`||e===`uint8`||e===`bool`||e===`uint4`||e===`int4`,nn=e=>{switch(e){case`none`:return 0;case`cpu`:return 1;case`cpu-pinned`:return 2;case`texture`:return 3;case`gpu-buffer`:return 4;case`ml-tensor`:return 5;default:throw Error(`unsupported data location: ${e}`)}}}),rn,an=M(()=>{$e(),rn=async e=>{if(typeof e==`string`){let t=await fetch(e);if(!t.ok)throw Error(`failed to load external data file: ${e}`);let n=t.headers.get(`Content-Length`),r=n?parseInt(n,10):0;if(r<1073741824)return new Uint8Array(await t.arrayBuffer());{if(!t.body)throw Error(`failed to load external data file: ${e}, no response body.`);let n=t.body.getReader(),i;try{i=new ArrayBuffer(r)}catch(e){if(e instanceof RangeError){let e=Math.ceil(r/65536);i=new WebAssembly.Memory({initial:e,maximum:e}).buffer}else throw e}let a=0;for(;;){let{done:e,value:t}=await n.read();if(e)break;let r=t.byteLength;new Uint8Array(i,a,r).set(t),a+=r}return new Uint8Array(i,0,r)}}else return e instanceof Blob?new Uint8Array(await e.arrayBuffer()):e instanceof Uint8Array?e:new Uint8Array(e)}}),on,sn,cn,ln,un,dn,U,fn=M(()=>{H(),on=[`V`,`I`,`W`,`E`,`F`],sn=(e,t)=>{console.log(`[${on[e]},${new Date().toISOString()}]${t}`)},un=(e,t)=>{cn=e,ln=t},dn=(e,t)=>{let n=$t(e);n>=$t(cn)&&sn(n,typeof t==`function`?t():t)},U=(...e)=>{ln&&dn(...e)}}),pn,mn,W,hn,gn,_n,vn,G=M(()=>{pn=class{static calcMatMulShape(e,t){return e[1]===t[0]?[e[0],t[1]]:void 0}},mn=class{static calcShape(e,t,n=!1){let r=e.length,i=t.length;if(r===0)return t;if(i===0)return e;let a=Math.max(e.length,t.length),o=Array(a);if(n){if(r<2||i<2)return;let n=pn.calcMatMulShape([e[r-2],e[r-1]],[t[i-2],t[i-1]]);if(n===void 0)return;[o[a-2],o[a-1]]=n}for(let s=n?3:1;s<=a;s++){let n=r-s<0?1:e[r-s],c=i-s<0?1:t[i-s];if(n!==c&&n>1&&c>1)return;let l=Math.max(n,c);if(n&&c)o[a-s]=Math.max(n,c);else{if(l>1)return;o[a-s]=0}}return o}static isValidBroadcast(e,t){let n=e.length,r=t.length;if(n>r)return!1;for(let i=1;i<=n;i++)if(e[n-i]!==1&&e[n-i]!==t[r-i])return!1;return!0}},W=class e{static size(t){return e.getSizeFromDimensionRange(t,0,t.length)}static convertShape(e,t=4){let n=e.length;if(n===0)return[];let r=Array(n),i=n-1;for(;i>=0;){if(e[i]%t===0){r[i]=e[i]/t;break}if(t%e[i]!==0)throw Error(`cannot convert shape`);r[i]=1,t/=e[i],i--}for(i--;i>=0;i--)r[i]=e[i];return r}static sizeFromDimension(t,n){if(n<0||n>t.length)throw Error(`invalid dimension of ${n} for sizeFromDimension as Tensor has ${t.length} dimensions.`);return e.getSizeFromDimensionRange(t,n,t.length)}static sizeToDimension(t,n){if(n<0||n>t.length)throw Error(`invalid dimension of ${n} for sizeToDimension as Tensor has ${t.length} dimensions.`);return e.getSizeFromDimensionRange(t,0,n)}static getSizeFromDimensionRange(e,t,n){let r=1;for(let i=t;i<n;i++){if(e[i]<0)throw Error(`cannot get valid size from specified dimension range. Most likely the range contains negative values in them.`);r*=Number(e[i])}return r}static computeStrides(e){let t=e.length;if(t===0)return[];if(t===1)return[1];let n=Array(t);n[t-1]=1,n[t-2]=e[t-1];for(let r=t-3;r>=0;--r)n[r]=n[r+1]*e[r+1];return n}static normalizeAxis(e,t){if(e<-t&&e>=t)throw Error(`unsupported axis for this operation.`);return e<0?e+t:e}static normalizeAxes(e,t){return e.map(n=>this.normalizeAxis(n,t??e.length))}static sortBasedOnPerm(e,t){return t?t.map(t=>e[t]):e.slice().reverse()}static padShape(e,t){let n=e.length;return e.map((e,r)=>e+t[r]+t[r+n])}static areEqual(e,t){return e.length===t.length?e.every((e,n)=>e===t[n]):!1}},hn=class e{static adjustPoolAttributes(e,t,n,r,i,a){if(!e&&n.length!==t.length-2)throw Error(`length of specified kernel shapes should be 2 less than length of input dimensions`);if(e)for(let e=0;e<t.length-2;e++)e>=n.length?n.push(t[e+2]):n[e]=t[e+2];for(let e=0;e<n.length;e++)if(e<r.length){if(r[e]<0)throw Error(`strides should be greater than or equal to 1`)}else r.push(1);for(let e=0;e<n.length;e++)if(e<i.length){if(i[e]<0)throw Error(`dilations should be greater than or equal to 1`)}else i.push(1);for(let e=0;e<n.length*2;e++)if(e<a.length){if(a[e]<0)throw Error(`pad should be greater than or equal to 1`)}else a.push(0);for(let e=0;e<n.length;e++){if(n[e]<=0)throw Error(`kernel shapes need to be greater than 0`);if(a[e]>=n[e]||a[e+n.length]>=n[e])throw Error(`pads should be smaller than kernel`)}}static adjustPadsBasedOnAutoPad(t,n,r,i,a,o,s){if(s){if(a.length!==2*(t.length-2))throw Error(`length of pads should be twice the length of data dimensions`);if(n.length!==t.length-2)throw Error(`length of strides should be the length of data dimensions`);if(i.length!==t.length-2)throw Error(`length of kernel shapes should be the length of data dimensions`);for(let c=0;c<t.length-2;c++)e.adjustPadAndReturnShape(t[c+(o?1:2)],n[c],r[c],i[c],a,c,c+t.length-2,s)}}static computePoolOutputShape(t,n,r,i,a,o,s){if(n.length<=0)throw Error(`input shape must be of size greater than 0`);let c=[n[0],n[1]];return e.computeShapeHelper(t,n,c,r,i,a,o,s),c}static computeConvOutputShape(t,n,r,i,a,o,s){if(t.length<=0||n.length<=0)throw Error(`invalid input tensor dims or invalid filter tensor dims`);let c=[t[0],n[0]];return e.computeShapeHelper(!1,t,c,r,i,a,o,s),c}static computeShapeHelper(t,n,r,i,a,o,s,c){if(t)for(let e=0;e<n.length-2;e++)r.push(1);else for(let t=0;t<n.length-2;t++)r.push(e.adjustPadAndReturnShape(n[t+2],i[t],a[t],o[t],s,t,t+n.length-2,c))}static adjustPadAndReturnShape(e,t,n,r,i,a,o,s){let c=n*(r-1)+1;if(s&&s!==`NOTSET`)switch(s){case`VALID`:return i[a]=0,i[o]=0,Math.floor((e-c)/t+1);case`SAME_LOWER`:case`SAME_UPPER`:if(n!==1)throw Error(`Dilation not supported for SAME_UPPER or SAME_LOWER`);{let n=((e+t-1)/t-1)*t+r-e;return i[a]=Math.floor(s===`SAME_LOWER`?(n+1)/2:n/2),i[o]=n-i[a],Math.floor((e+n-r)/t+1)}default:throw Error(`Unsupported AutoPad type`)}else return Math.floor((e+i[a]+i[o]-c)/t+1)}},gn=class{static getShapeOfGemmResult(e,t,n,r,i){if(e.length!==2||n.length!==2)throw Error(`shape need to be of size 2`);let a,o,s;t?(a=e[1],o=e[0]):(a=e[0],o=e[1]);let c=-1;if(r?(s=n[0],c=1):(s=n[1],c=0),n[c]!==o)throw Error(`dimension mismatch`);if(a<=0||s<=0||o<=0)throw Error(`invalid shape specified`);if(i&&!mn.isValidBroadcast(i,[a,s]))throw Error(`gemm: invalid bias shape for broadcast`);return[a,s,o]}},_n=-34028234663852886e22,vn=34028234663852886e22}),yn,bn=M(()=>{H(),yn=(e,t)=>new(Qt(t))(e)}),xn,Sn,Cn,wn,Tn,En,Dn,On,kn,An,jn=M(()=>{fn(),xn=(e,t=!0)=>{if(e.byteLength%8!=0)throw Error(`Invalid Uint8Array length - must be a multiple of 8 (BigInt).`);let n=e.byteLength/8,r=new BigInt64Array(e.buffer,e.byteOffset,n),i=new Int32Array(n);for(let e=0;e<n;e++){let t=r[e];if(t>2147483647n||t<-2147483648n)throw Error(`Overflow occurred when converting BigInt to Int32 at index ${e}: ${t}`);i[e]=Number(t)}return t?new Uint8Array(i.buffer):i},Sn=(e,t=!0)=>{if(e.byteLength%4!=0)throw Error(`Invalid Uint8Array length - must be a multiple of 4 (Int32).`);let n=e.byteLength/4,r=new Int32Array(e.buffer,e.byteOffset,n),i=BigInt64Array.from(r,BigInt);return t?new Uint8Array(i.buffer):i},Cn=1,wn=()=>Cn++,Tn=new Map([[`float32`,32],[`float16`,16],[`int32`,32],[`uint32`,32],[`int64`,64],[`uint64`,64],[`int8`,8],[`uint8`,8],[`int4`,4],[`uint4`,4]]),En=(e,t)=>{let n=Tn.get(e);if(!n)throw Error(`Unsupported data type.`);return t.length>0?Math.ceil(t.reduce((e,t)=>e*t)*n/8):0},Dn=class{constructor(e){this.shouldConvertInt64toInt32=!1,this.isInt64ToInt32Converted=!1;let{sessionId:t,context:n,tensor:r,dataType:i,shape:a,shouldConvertInt64toInt32:o=!1}=e;this.sessionId=t,this.mlContext=n,this.mlTensor=r,this.dataType=i,this.tensorShape=a,this.shouldConvertInt64toInt32=o}get tensor(){return this.mlTensor}get type(){return this.dataType}get shape(){return this.tensorShape}get byteLength(){return En(this.dataType,this.tensorShape)}destroy(){U(`verbose`,()=>`[WebNN] TensorWrapper.destroy`),this.mlTensor.destroy()}write(e){this.mlContext.writeTensor(this.mlTensor,e)}async read(e,t){if(e){let e=await this.mlContext.readTensor(this.mlTensor),n=Sn(new Uint8Array(e));if(t){(t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)).set(n);return}else return n.buffer}else return t?this.mlContext.readTensor(this.mlTensor,t):this.mlContext.readTensor(this.mlTensor)}canReuseTensor(e,t,n){return this.mlContext===e&&this.dataType===t&&this.tensorShape.length===n.length&&this.tensorShape.every((e,t)=>e===n[t])}setIsInt64ToInt32Converted(e){this.isInt64ToInt32Converted=e}},On=class{constructor(e,t){this.tensorManager=e,this.wrapper=t}get tensorWrapper(){return this.wrapper}releaseTensor(){this.tensorWrapper&&(this.tensorManager.releaseTensor(this.tensorWrapper),this.wrapper=void 0)}async ensureTensor(e,t,n,r){let i=t,a=this.tensorManager.getMLContext(e),o=i===`int64`&&!a.opSupportLimits().input.dataTypes.includes(`int64`);if(o&&(i=`int32`,U(`verbose`,()=>`[WebNN] TensorIdTracker.ensureTensor: convert dataType from int64 to int32`)),this.wrapper){if(this.wrapper.canReuseTensor(a,i,n))return this.wrapper.tensor;if(r){if(this.wrapper.byteLength!==En(i,n))throw Error(`Unable to copy data to tensor with different size.`);this.activeUpload=new Uint8Array(await this.wrapper.read())}this.tensorManager.releaseTensor(this.wrapper)}let s=typeof MLTensorUsage>`u`?void 0:MLTensorUsage.READ|MLTensorUsage.WRITE;return this.wrapper=await this.tensorManager.getCachedTensor(e,i,n,s,!0,!0,o),r&&this.activeUpload&&(this.wrapper.write(this.activeUpload),this.activeUpload=void 0),this.wrapper.tensor}upload(e){let t=e;if(this.wrapper)if(this.wrapper.shouldConvertInt64toInt32&&(t=xn(e,!0),this.wrapper.setIsInt64ToInt32Converted(!0)),t.byteLength===this.wrapper.byteLength){this.wrapper.write(t);return}else U(`verbose`,()=>`Data size does not match tensor size. Releasing tensor.`),this.releaseTensor();this.activeUpload?this.activeUpload.set(t):this.activeUpload=new Uint8Array(t)}async download(e){if(this.activeUpload){let t=this.wrapper?.isInt64ToInt32Converted?Sn(this.activeUpload):this.activeUpload;if(e){e instanceof ArrayBuffer?new Uint8Array(e).set(t):new Uint8Array(e.buffer,e.byteOffset,e.byteLength).set(t);return}else return t.buffer}if(!this.wrapper)throw Error(`Tensor has not been created.`);return e?this.wrapper.read(this.wrapper?.shouldConvertInt64toInt32,e):this.wrapper.read(this.wrapper?.shouldConvertInt64toInt32)}},kn=class{constructor(e){this.backend=e,this.tensorTrackersById=new Map,this.freeTensors=[],this.externalTensors=new Set}getMLContext(e){let t=this.backend.getMLContext(e);if(!t)throw Error(`MLContext not found for session.`);return t}reserveTensorId(){let e=wn();return this.tensorTrackersById.set(e,new On(this)),e}releaseTensorId(e){let t=this.tensorTrackersById.get(e);t&&(this.tensorTrackersById.delete(e),t.tensorWrapper&&this.releaseTensor(t.tensorWrapper))}async ensureTensor(e,t,n,r,i){U(`verbose`,()=>`[WebNN] TensorManager.ensureTensor {tensorId: ${t}, dataType: ${n}, shape: ${r}, copyOld: ${i}}`);let a=this.tensorTrackersById.get(t);if(!a)throw Error(`Tensor not found.`);return a.ensureTensor(e,n,r,i)}upload(e,t){let n=this.tensorTrackersById.get(e);if(!n)throw Error(`Tensor not found.`);n.upload(t)}async download(e,t){U(`verbose`,()=>`[WebNN] TensorManager.download {tensorId: ${e}, dstBuffer: ${t?.byteLength}}`);let n=this.tensorTrackersById.get(e);if(!n)throw Error(`Tensor not found.`);return n.download(t)}releaseTensorsForSession(e){for(let t of this.freeTensors)t.sessionId===e&&t.destroy();this.freeTensors=this.freeTensors.filter(t=>t.sessionId!==e)}registerTensor(e,t,n,r){let i=this.getMLContext(e),a=wn(),o=new Dn({sessionId:e,context:i,tensor:t,dataType:n,shape:r});return this.tensorTrackersById.set(a,new On(this,o)),this.externalTensors.add(o),a}async getCachedTensor(e,t,n,r,i,a,o=!1){let s=this.getMLContext(e);for(let[r,i]of this.freeTensors.entries())if(i.canReuseTensor(s,t,n)){U(`verbose`,()=>`[WebNN] Reusing tensor {dataType: ${t}, shape: ${n}}`);let i=this.freeTensors.splice(r,1)[0];return i.sessionId=e,i}U(`verbose`,()=>`[WebNN] MLContext.createTensor {dataType: ${t}, shape: ${n}}`);let c=await s.createTensor({dataType:t,shape:n,dimensions:n,usage:r,writable:i,readable:a});return new Dn({sessionId:e,context:s,tensor:c,dataType:t,shape:n,shouldConvertInt64toInt32:o})}releaseTensor(e){this.externalTensors.has(e)&&this.externalTensors.delete(e),this.freeTensors.push(e)}},An=(...e)=>new kn(...e)}),Mn,Nn,Pn,Fn=M(()=>{H(),Ft(),bn(),jn(),fn(),Mn=new Map([[1,`float32`],[10,`float16`],[6,`int32`],[12,`uint32`],[7,`int64`],[13,`uint64`],[22,`int4`],[21,`uint4`],[3,`int8`],[2,`uint8`],[9,`uint8`]]),Nn=(e,t)=>{if(e===t)return!0;if(e===void 0||t===void 0)return!1;let n=Object.keys(e).sort(),r=Object.keys(t).sort();return n.length===r.length&&n.every((n,i)=>n===r[i]&&e[n]===t[n])},Pn=class{constructor(e){this.tensorManager=An(this),this.mlContextBySessionId=new Map,this.sessionIdsByMLContext=new Map,this.mlContextCache=[],this.sessionGraphInputs=new Map,this.temporaryGraphInputs=[],this.temporarySessionTensorIds=new Map,un(e.logLevel,!!e.debug)}get currentSessionId(){if(this.activeSessionId===void 0)throw Error(`No active session`);return this.activeSessionId}onRunStart(e){U(`verbose`,()=>`[WebNN] onRunStart {sessionId: ${e}}`),this.activeSessionId=e}onRunEnd(e){U(`verbose`,()=>`[WebNN] onRunEnd {sessionId: ${e}}`);let t=this.temporarySessionTensorIds.get(e);if(t){for(let e of t)U(`verbose`,()=>`[WebNN] releasing temporary tensor {tensorId: ${e}}`),this.tensorManager.releaseTensorId(e);this.temporarySessionTensorIds.delete(e),this.activeSessionId=void 0}}async createMLContext(e){if(e instanceof GPUDevice){let t=this.mlContextCache.findIndex(t=>t.gpuDevice===e);if(t!==-1)return this.mlContextCache[t].mlContext;{let t=await navigator.ml.createContext(e);return this.mlContextCache.push({gpuDevice:e,mlContext:t}),t}}else if(e===void 0){let e=this.mlContextCache.findIndex(e=>e.options===void 0&&e.gpuDevice===void 0);if(e!==-1)return this.mlContextCache[e].mlContext;{let e=await navigator.ml.createContext();return this.mlContextCache.push({mlContext:e}),e}}let t=this.mlContextCache.findIndex(t=>Nn(t.options,e));if(t!==-1)return this.mlContextCache[t].mlContext;{let t=await navigator.ml.createContext(e);return this.mlContextCache.push({options:e,mlContext:t}),t}}registerMLContext(e,t){this.mlContextBySessionId.set(e,t);let n=this.sessionIdsByMLContext.get(t);n||(n=new Set,this.sessionIdsByMLContext.set(t,n)),n.add(e),this.temporaryGraphInputs.length>0&&(this.sessionGraphInputs.set(e,this.temporaryGraphInputs),this.temporaryGraphInputs=[])}onReleaseSession(e){this.sessionGraphInputs.delete(e);let t=this.mlContextBySessionId.get(e);if(!t)return;this.tensorManager.releaseTensorsForSession(e),this.mlContextBySessionId.delete(e);let n=this.sessionIdsByMLContext.get(t);if(n.delete(e),n.size===0){this.sessionIdsByMLContext.delete(t);let e=this.mlContextCache.findIndex(e=>e.mlContext===t);e!==-1&&this.mlContextCache.splice(e,1)}}getMLContext(e){return this.mlContextBySessionId.get(e)}reserveTensorId(){return this.tensorManager.reserveTensorId()}releaseTensorId(e){U(`verbose`,()=>`[WebNN] releaseTensorId {tensorId: ${e}}`),this.tensorManager.releaseTensorId(e)}async ensureTensor(e,t,n,r,i){let a=Mn.get(n);if(!a)throw Error(`Unsupported ONNX data type: ${n}`);return this.tensorManager.ensureTensor(e??this.currentSessionId,t,a,r,i)}async createTemporaryTensor(e,t,n){U(`verbose`,()=>`[WebNN] createTemporaryTensor {onnxDataType: ${t}, shape: ${n}}`);let r=Mn.get(t);if(!r)throw Error(`Unsupported ONNX data type: ${t}`);let i=this.tensorManager.reserveTensorId();await this.tensorManager.ensureTensor(e,i,r,n,!1);let a=this.temporarySessionTensorIds.get(e);return a?a.push(i):this.temporarySessionTensorIds.set(e,[i]),i}uploadTensor(e,t){if(!Pt().shouldTransferToMLTensor)throw Error(`Trying to upload to a MLTensor while shouldTransferToMLTensor is false`);U(`verbose`,()=>`[WebNN] uploadTensor {tensorId: ${e}, data: ${t.byteLength}}`),this.tensorManager.upload(e,t)}async downloadTensor(e,t){return this.tensorManager.download(e,t)}createMLTensorDownloader(e,t){return async()=>{let n=await this.tensorManager.download(e);return yn(n,t)}}registerMLTensor(e,t,n,r){let i=Mn.get(n);if(!i)throw Error(`Unsupported ONNX data type: ${n}`);let a=this.tensorManager.registerTensor(e,t,i,r);return U(`verbose`,()=>`[WebNN] registerMLTensor {tensor: ${t}, dataType: ${i}, dimensions: ${r}} -> {tensorId: ${a}}`),a}registerMLConstant(e,t,n,r,i,a,o=!1){if(!a)throw Error(`External mounted files are not available.`);let s=e;e.startsWith(`./`)&&(s=e.substring(2));let c=a.get(s);if(!c)throw Error(`File with name ${s} not found in preloaded files.`);if(t+n>c.byteLength)throw Error(`Out of bounds: data offset and length exceed the external file data size.`);let l=c.slice(t,t+n).buffer,u;switch(i.dataType){case`float32`:u=new Float32Array(l);break;case`float16`:u=typeof Float16Array<`u`&&Float16Array.from?new Float16Array(l):new Uint16Array(l);break;case`int32`:u=new Int32Array(l);break;case`uint32`:u=new Uint32Array(l);break;case`int64`:o?(u=xn(new Uint8Array(l),!1),i.dataType=`int32`):u=new BigInt64Array(l);break;case`uint64`:u=new BigUint64Array(l);break;case`int8`:u=new Int8Array(l);break;case`int4`:case`uint4`:case`uint8`:u=new Uint8Array(l);break;default:throw Error(`Unsupported data type: ${i.dataType} in creating WebNN Constant from external data.`)}return U(`verbose`,()=>`[WebNN] registerMLConstant {dataType: ${i.dataType}, shape: ${i.shape}}} ${o?`(Note: it was int64 data type and registered to int32 as workaround)`:``}`),r.constant(i,u)}registerGraphInput(e){this.temporaryGraphInputs.push(e)}isGraphInput(e,t){let n=this.sessionGraphInputs.get(e);return n?n.includes(t):!1}isInt64Supported(e){return!!this.mlContextBySessionId.get(e)?.opSupportLimits().input.dataTypes.includes(`int64`)}flush(){}}}),In=M(()=>{}),Ln,Rn,zn,Bn,Vn,Hn,Un,Wn,Gn,Kn=M(()=>{fn(),In(),Ln=new Map([[64,250],[128,200],[256,200],[512,200],[2048,230],[4096,200],[8192,50],[16384,50],[32768,50],[65536,50],[131072,50],[262144,50],[524288,50],[1048576,50],[2097152,30],[4194304,20],[8388608,10],[12582912,10],[16777216,10],[26214400,15],[33554432,22],[44236800,2],[58982400,6],[67108864,6],[134217728,6],[167772160,6]]),Rn=[],zn=e=>Math.ceil(Number(e)/16)*16,Bn=e=>{for(let t=0;t<Rn.length;t++){let n=Rn[t];if(e<=n)return n}return Math.ceil(e/16)*16},Vn=1,Hn=()=>Vn++,Un=async(e,t,n,r)=>{let i=zn(n),a=e.device.createBuffer({size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});try{let o=e.getCommandEncoder();e.endComputePass(),o.copyBufferToBuffer(t,0,a,0,i),e.flush(),await a.mapAsync(GPUMapMode.READ);let s=a.getMappedRange();if(r){let e=r();return e.set(new Uint8Array(s,0,n)),e}else return new Uint8Array(s.slice(0,n))}finally{a.destroy()}},Wn=class{constructor(e){this.backend=e,this.storageCache=new Map,this.freeBuffers=new Map,this.freeUniformBuffers=new Map,this.buffersPending=[],this.capturedPendingBuffers=new Map;for(let[e]of Ln)Rn.push(e),this.freeBuffers.set(e,[]),this.freeUniformBuffers.set(e,[]);this.sessionCount=0}upload(e,t){let n=t.buffer,r=t.byteOffset,i=t.byteLength,a=zn(i),o=this.storageCache.get(e);if(!o)throw Error(`gpu data for uploading does not exist`);if(Number(o.originalSize)!==i)throw Error(`inconsistent data size. gpu data size=${o.originalSize}, data size=${i}`);let s=this.backend.device.createBuffer({mappedAtCreation:!0,size:a,usage:GPUBufferUsage.MAP_WRITE|GPUBufferUsage.COPY_SRC}),c=s.getMappedRange();new Uint8Array(c).set(new Uint8Array(n,r,i)),s.unmap();let l=this.backend.device.createCommandEncoder();l.copyBufferToBuffer(s,0,o.gpuData.buffer,0,a),this.backend.device.queue.submit([l.finish()]),s.destroy(),U(`verbose`,()=>`[WebGPU] GpuDataManager.upload(id=${e})`)}memcpy(e,t){let n=this.storageCache.get(e);if(!n)throw Error(`source gpu data for memcpy does not exist`);let r=this.storageCache.get(t);if(!r)throw Error(`destination gpu data for memcpy does not exist`);if(n.originalSize!==r.originalSize)throw Error(`inconsistent source and destination gpu data size`);let i=zn(n.originalSize),a=this.backend.getCommandEncoder();this.backend.endComputePass(),a.copyBufferToBuffer(n.gpuData.buffer,0,r.gpuData.buffer,0,i)}registerExternalBuffer(e,t,n){let r;if(n){if(r=n[0],e===n[1])return U(`verbose`,()=>`[WebGPU] GpuDataManager.registerExternalBuffer(size=${t}) => id=${r}, buffer is the same, skip.`),r;if(this.backend.capturedCommandList.has(this.backend.currentSessionId))throw Error(`Registering a different external buffer under graph capture mode is not supported yet.
10
+ Please use the previous external buffer!`)}else r=Hn();return this.storageCache.set(r,{gpuData:{id:r,type:0,buffer:e},originalSize:t}),U(`verbose`,()=>`[WebGPU] GpuDataManager.registerExternalBuffer(size=${t}) => id=${r}, registered.`),r}unregisterExternalBuffer(e){e!==void 0&&(this.storageCache.delete(e),U(`verbose`,()=>`[WebGPU] GpuDataManager.unregisterExternalBuffer() => id=${e}`))}create(e,t=GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST){let n=Bn(e),r,i=(t&GPUBufferUsage.STORAGE)===GPUBufferUsage.STORAGE,a=(t&GPUBufferUsage.UNIFORM)===GPUBufferUsage.UNIFORM;if(i||a){let e=(i?this.freeBuffers:this.freeUniformBuffers).get(n);r=e&&e.length>0?e.pop():this.backend.device.createBuffer({size:n,usage:t})}else r=this.backend.device.createBuffer({size:n,usage:t});let o={id:Hn(),type:0,buffer:r};return this.storageCache.set(o.id,{gpuData:o,originalSize:Number(e)}),U(`verbose`,()=>`[WebGPU] GpuDataManager.create(size=${e}) => id=${o.id}`),o}get(e){return this.storageCache.get(e)?.gpuData}release(e){let t=typeof e==`bigint`?Number(e):e,n=this.storageCache.get(t);if(!n){if(this.storageCache.size===0)return 0;throw Error(`releasing data does not exist`)}return U(`verbose`,()=>`[WebGPU] GpuDataManager.release(id=${t}), gpuDataId=${n.gpuData.id}`),this.storageCache.delete(t),this.buffersPending.push(n.gpuData.buffer),n.originalSize}async download(e,t){let n=this.storageCache.get(Number(e));if(!n)throw Error(`data does not exist`);await Un(this.backend,n.gpuData.buffer,n.originalSize,t)}refreshPendingBuffers(){if(this.buffersPending.length!==0)if(this.backend.sessionStatus===`default`){for(let e of this.buffersPending){let t=Ln.get(e.size);if((e.usage&GPUBufferUsage.STORAGE)===GPUBufferUsage.STORAGE){let n=this.freeBuffers.get(e.size)||[];t===void 0||n.length>=t?e.destroy():n.push(e)}else if((e.usage&GPUBufferUsage.UNIFORM)===GPUBufferUsage.UNIFORM){let n=this.freeUniformBuffers.get(e.size)||[];t===void 0||n.length>=t?e.destroy():n.push(e)}else e.destroy()}this.buffersPending=[]}else{let e=this.capturedPendingBuffers.get(this.backend.currentSessionId);e||(e=[],this.capturedPendingBuffers.set(this.backend.currentSessionId,e));for(let t of this.buffersPending)e.push(t);this.buffersPending=[]}}dispose(){this.freeBuffers.forEach(e=>{e.forEach(e=>{e.destroy()})}),this.freeUniformBuffers.forEach(e=>{e.forEach(e=>{e.destroy()})}),this.storageCache.forEach(e=>{e.gpuData.buffer.destroy()}),this.capturedPendingBuffers.forEach(e=>{e.forEach(e=>{e.destroy()})}),this.storageCache=new Map,this.freeBuffers=new Map,this.freeUniformBuffers=new Map,this.capturedPendingBuffers=new Map}onCreateSession(){this.sessionCount+=1}onReleaseSession(e){let t=this.capturedPendingBuffers.get(e);t&&(t.forEach(e=>{e.destroy()}),this.capturedPendingBuffers.delete(e)),--this.sessionCount,this.sessionCount===0&&(U(`warning`,()=>`[WebGPU] Clearing webgpu buffer cache`),this.storageCache.forEach(e=>{e.gpuData.buffer.destroy()}),this.storageCache=new Map)}},Gn=(...e)=>new Wn(...e)}),qn,Jn,Yn=M(()=>{qn=class{constructor(e){Object.assign(this,e)}get cacheKey(){return this.key||=Object.getOwnPropertyNames(this).sort().map(e=>`${this[e]}`).join(`;`),this.key}},Jn=e=>new qn(e)}),Xn,Zn,Qn,$n,K,er,tr,nr,rr,q,ir,J,Y,ar,or,sr,cr,X=M(()=>{H(),G(),Xn=64,Zn=(e,t)=>{if(t===3)throw Error(`vec3 has same alignment as vec4, use vec4 instead`);switch(Number(e)){case 10:return t>1?`vec${t}<f16>`:`f16`;case 1:return t>1?`vec${t}<f32>`:`f32`;case 6:return t>1?`vec${t}<i32>`:`i32`;case 12:return t>1?`vec${t}<u32>`:`u32`;case 7:if(t>1)throw Error(`currently not supported vecX of uint64 yet`);return[`vec2<u32>`,`i32`];case 13:if(t>1)throw Error(`currently not supported vecX of uint64 yet`);return[`vec2<u32>`,`u32`];case 9:if(t!==4)throw Error(`bool must be vec4`);return[`u32`,`vec4<bool>`];case 22:return`i32`;case 21:return`u32`;default:throw Error(`Unknown data type: ${e}`)}},Qn=(e,t=1)=>{let n=Zn(e,t);return typeof n==`string`?n:n[0]},$n=(e,t=1)=>{let n=Zn(e,t);return typeof n==`string`?n:n[1]},K=(...e)=>{let t=[];return e.forEach(e=>{e.length!==0&&t.push({type:12,data:e},{type:12,data:W.computeStrides(e)})}),t},er=e=>e%4==0?4:e%2==0?2:1,tr=(e=`f32`,t,n=`0`)=>!t||t===1?`${e}(${n})`:`vec${t}<${e}>(${n})`,nr=(e,t,n)=>e===`f32`?n:t===1?`f32(${n})`:`vec${t}<f32>(${n})`,rr=(e,t)=>t===4?`(${e}.x + ${e}.y + ${e}.z + ${e}.w)`:t===2?`(${e}.x + ${e}.y)`:t===3?`(${e}.x + ${e}.y + ${e}.z)`:e,q=(e,t,n,r)=>e.startsWith(`uniforms.`)&&n>4?typeof t==`string`?r===`f16`?`${e}[(${t}) / 8][(${t}) % 8 / 4][(${t}) % 8 % 4]`:`${e}[(${t}) / 4][(${t}) % 4]`:r===`f16`?`${e}[${Math.floor(t/8)}][${Math.floor(t%8/4)}][${t%8%4}]`:`${e}[${Math.floor(t/4)}][${t%4}]`:n>1?`${e}[${t}]`:e,ir=(e,t,n,r,i)=>{let a=typeof n==`number`,o=a?n:n.length,s=[...Array(o).keys()],c=o<2?`u32`:o<=4?`vec${o}<u32>`:`array<u32, ${o}>`,l=Zn(t,i),u=typeof l==`string`?l:l[1],d={indices:c,value:u,storage:typeof l==`string`?l:l[0],tensor:t},f=e=>typeof e==`string`?e:`${e}u`,p={offsetToIndices:!1,indicesToOffset:!1,broadcastedIndicesToOffset:!1,set:!1,setByIndices:!1,get:!1,getByIndices:!1},m=a?`uniforms.`:``,h=`${m}${e}_shape`,g=`${m}${e}_strides`,_=``;for(let e=0;e<o-1;e++)_+=`
11
+ let dim${e} = current / ${q(g,e,o)};
12
+ let rest${e} = current % ${q(g,e,o)};
13
+ indices[${e}] = dim${e};
14
+ current = rest${e};
15
+ `;_+=`indices[${o-1}] = current;`;let v=o<2?``:`
16
+ fn o2i_${e}(offset: u32) -> ${d.indices} {
17
+ var indices: ${d.indices};
18
+ var current = offset;
19
+ ${_}
20
+ return indices;
21
+ }`,y=t=>(p.offsetToIndices=!0,o<2?t:`o2i_${e}(${t})`),b=[];if(o>=2)for(let e=o-1;e>=0;e--)b.push(`${q(g,e,o)} * (indices[${e}])`);let x=o<2?``:`
22
+ fn i2o_${e}(indices: ${d.indices}) -> u32 {
23
+ return ${b.join(`+`)};
24
+ }`,S=t=>(p.indicesToOffset=!0,o<2?t:`i2o_${e}(${t})`),C=(...e)=>o===0?`0u`:`${d.indices}(${e.map(f).join(`,`)})`,w=(e,t)=>o<2?`${e}`:`${q(e,t,o)}`,T=(e,t,n)=>o<2?`${e}=${n};`:`${q(e,t,o)}=${n};`,E={},D=(t,n)=>{p.broadcastedIndicesToOffset=!0;let r=`${n.name}broadcastedIndicesTo${e}Offset`;if(r in E)return`${r}(${t})`;let i=[];for(let e=o-1;e>=0;e--){let t=n.indicesGet(`outputIndices`,e+n.rank-o);i.push(`${w(g,e)} * (${t} % ${w(h,e)})`)}return E[r]=`fn ${r}(outputIndices: ${n.type.indices}) -> u32 {
25
+ return ${i.length>0?i.join(`+`):`0u`};
26
+ }`,`${r}(${t})`},O=(t,n)=>(()=>{if(d.storage===d.value)return`${e}[${t}]=${n};`;if(d.storage===`vec2<u32>`&&d.value===`i32`)return`${e}[${t}]=vec2<u32>(u32(${n}), select(0u, 0xFFFFFFFFu, ${n} < 0));`;if(d.storage===`vec2<u32>`&&d.value===`u32`)return`${e}[${t}]=vec2<u32>(u32(${n}), 0u);`;if(d.storage===`u32`&&d.value===`vec4<bool>`)return`${e}[${t}]=dot(vec4<u32>(0x1, 0x100, 0x10000, 0x1000000), vec4<u32>(${n}));`;throw Error(`not supported combination of storage type ${d.storage} and value type ${d.value} yet`)})(),k=t=>(()=>{if(d.storage===d.value)return`${e}[${t}]`;if(d.storage===`vec2<u32>`&&d.value===`i32`)return`i32(${e}[${t}].x)`;if(d.storage===`vec2<u32>`&&d.value===`u32`)return`u32(${e}[${t}].x)`;if(d.storage===`u32`&&d.value===`vec4<bool>`)return`vec4<bool>(bool(${e}[${t}] & 0xFFu), bool(${e}[${t}] & 0xFF00u), bool(${e}[${t}] & 0xFF0000u), bool(${e}[${t}] & 0xFF000000u))`;throw Error(`not supported combination of storage type ${d.storage} and value type ${d.value} yet`)})(),A=o<2?``:`
27
+ fn get_${e}ByIndices(indices: ${d.indices}) -> ${u} {
28
+ return ${k(`i2o_${e}(indices)`)};
29
+ }`,ee=o<2?``:`
30
+ fn get_${e}(${s.map(e=>`d${e}: u32`).join(`, `)}) -> ${u} {
31
+ return get_${e}ByIndices(${C(s.map(e=>`d${e}`).join(`, `))});
32
+ }`,te=(...t)=>{if(t.length!==o)throw Error(`indices length must be ${o}`);let n=t.map(f).join(`,`);return o===0?k(`0u`):o===1?k(n[0]):(p.get=!0,p.getByIndices=!0,p.indicesToOffset=!0,`get_${e}(${n})`)},ne=t=>o<2?k(t):(p.getByIndices=!0,p.indicesToOffset=!0,`get_${e}ByIndices(${t})`),j=o<2?``:`
33
+ fn set_${e}ByIndices(indices: ${d.indices}, value: ${u}) {
34
+ ${O(`i2o_${e}(indices)`,`value`)}
35
+ }`,re=o<2?``:`
36
+ fn set_${e}(${s.map(e=>`d${e}: u32`).join(`, `)}, value: ${u}) {
37
+ set_${e}ByIndices(${C(s.map(e=>`d${e}`).join(`, `))}, value);
38
+ }`;return{impl:()=>{let e=[],t=!1;return p.offsetToIndices&&(e.push(v),t=!0),p.indicesToOffset&&(e.push(x),t=!0),p.broadcastedIndicesToOffset&&(Object.values(E).forEach(t=>e.push(t)),t=!0),p.set&&(e.push(re),t=!0),p.setByIndices&&(e.push(j),t=!0),p.get&&(e.push(ee),t=!0),p.getByIndices&&(e.push(A),t=!0),!a&&t&&e.unshift(`const ${h} = ${d.indices}(${n.join(`,`)});`,`const ${g} = ${d.indices}(${W.computeStrides(n).join(`,`)});`),e.join(`
39
+ `)},type:d,offsetToIndices:y,indicesToOffset:S,broadcastedIndicesToOffset:D,indices:C,indicesGet:w,indicesSet:T,set:(...t)=>{if(t.length!==o+1)throw Error(`indices length must be ${o}`);let n=t[o];if(typeof n!=`string`)throw Error(`value must be string`);let r=t.slice(0,o).map(f).join(`,`);return o===0?O(`0u`,n):o===1?O(r[0],n):(p.set=!0,p.setByIndices=!0,p.indicesToOffset=!0,`set_${e}(${r}, ${n})`)},setByOffset:O,setByIndices:(t,n)=>o<2?O(t,n):(p.setByIndices=!0,p.indicesToOffset=!0,`set_${e}ByIndices(${t}, ${n});`),get:te,getByOffset:k,getByIndices:ne,usage:r,name:e,strides:g,shape:h,rank:o}},J=(e,t,n,r=1)=>ir(e,t,n,`input`,r),Y=(e,t,n,r=1)=>ir(e,t,n,`output`,r),ar=(e,t,n)=>ir(e,t,n,`atomicOutput`,1),or=(e,t,n,r=1)=>ir(e,t,n,`internal`,r),sr=class{constructor(e,t){this.normalizedDispatchGroup=e,this.limits=t,this.internalVariables=[],this.variables=[],this.uniforms=[],this.variableIndex=0}guardAgainstOutOfBoundsWorkgroupSizes(e){return`if (global_idx >= ${typeof e==`number`?`${e}u`:e}) { return; }`}mainStart(e=Xn){let t=typeof e==`number`?e:e[0],n=typeof e==`number`?1:e[1],r=typeof e==`number`?1:e[2];if(t>this.limits.maxComputeWorkgroupSizeX||n>this.limits.maxComputeWorkgroupSizeY||r>this.limits.maxComputeWorkgroupSizeZ)throw Error(`workgroup size [${t}, ${n}, ${r}] exceeds the maximum workgroup size [${this.limits.maxComputeWorkgroupSizeX}, ${this.limits.maxComputeWorkgroupSizeY}, ${this.limits.maxComputeWorkgroupSizeZ}].`);if(t*n*r>this.limits.maxComputeInvocationsPerWorkgroup)throw Error(`workgroup size [${t}, ${n}, ${r}] exceeds the maximum workgroup invocations ${this.limits.maxComputeInvocationsPerWorkgroup}.`);let i=this.normalizedDispatchGroup[1]===1&&this.normalizedDispatchGroup[2]===1;return`@compute @workgroup_size(${t}, ${n}, ${r})
40
+ fn main(${i?`@builtin(global_invocation_id) global_id : vec3<u32>,
41
+ @builtin(workgroup_id) workgroup_id : vec3<u32>,
42
+ @builtin(local_invocation_index) local_idx : u32,
43
+ @builtin(local_invocation_id) local_id : vec3<u32>`:`@builtin(global_invocation_id) global_id : vec3<u32>,
44
+ @builtin(local_invocation_id) local_id : vec3<u32>,
45
+ @builtin(local_invocation_index) local_idx : u32,
46
+ @builtin(workgroup_id) workgroup_id : vec3<u32>,
47
+ @builtin(num_workgroups) num_workgroups : vec3<u32>`}) {
48
+ ${i?`let global_idx = global_id.x;
49
+ let workgroup_index = workgroup_id.x;`:`let workgroup_index = workgroup_id.z * num_workgroups[0] * num_workgroups[1] +
50
+ workgroup_id.y * num_workgroups[0] + workgroup_id.x;
51
+ let global_idx = workgroup_index * ${t*n*r}u + local_idx;`}
52
+ `}appendVariableUniforms(e){e.rank!==0&&(e.shape.startsWith(`uniforms.`)&&this.uniforms.push({name:e.shape.replace(`uniforms.`,``),type:`u32`,length:e.rank}),e.strides.startsWith(`uniforms.`)&&this.uniforms.push({name:e.strides.replace(`uniforms.`,``),type:`u32`,length:e.rank}))}declareVariable(e,t){if(e.usage===`internal`)throw Error(`cannot use internal variable with declareVariable(). use registerInternalVariables() instead.`);this.variables.push(e),this.appendVariableUniforms(e);let n=e.usage===`input`?`read`:`read_write`,r=e.usage===`atomicOutput`?`atomic<i32>`:e.type.storage;return`@group(0) @binding(${t}) var<storage, ${n}> ${e.name}: array<${r}>;`}declareVariables(...e){return e.map(e=>this.declareVariable(e,this.variableIndex++)).join(`
53
+ `)}registerInternalVariable(e){if(e.usage!==`internal`)throw Error(`cannot use input or output variable with registerInternalVariable(). use declareVariables() instead.`);this.internalVariables.push(e),this.appendVariableUniforms(e)}registerInternalVariables(...e){return e.forEach(e=>this.registerInternalVariable(e)),this}registerUniform(e,t,n=1){return this.uniforms.push({name:e,type:t,length:n}),this}registerUniforms(e){return this.uniforms=this.uniforms.concat(e),this}uniformDeclaration(){if(this.uniforms.length===0)return``;let e=[];for(let{name:t,type:n,length:r}of this.uniforms)if(r&&r>4)n===`f16`?e.push(`@align(16) ${t}:array<mat2x4<${n}>, ${Math.ceil(r/8)}>`):e.push(`${t}:array<vec4<${n}>, ${Math.ceil(r/4)}>`);else{let i=r==null||r===1?n:`vec${r}<${n}>`;e.push(`${t}:${i}`)}return`
54
+ struct Uniforms { ${e.join(`, `)} };
55
+ @group(0) @binding(${this.variableIndex}) var<uniform> uniforms: Uniforms;`}get additionalImplementations(){return this.uniformDeclaration()+this.variables.map(e=>e.impl()).join(`
56
+ `)+this.internalVariables.map(e=>e.impl()).join(`
57
+ `)}get variablesInfo(){if(this.uniforms.length===0)return;let e=e=>[12,10,1,6][[`u32`,`f16`,`f32`,`i32`].indexOf(e)];return this.uniforms.map(t=>[e(t.type),t.length??1])}},cr=(e,t)=>new sr(e,t)}),lr,ur,Z,dr,fr,pr,mr,hr,gr,_r=M(()=>{H(),G(),Yn(),X(),lr=(e,t)=>{if(!e||e.length!==1)throw Error(`Transpose requires 1 input.`);if(t.length!==0&&t.length!==e[0].dims.length)throw Error(`perm size ${t.length} does not match input rank ${e[0].dims.length}`)},ur=(e,t)=>t.length===0?[...Array(e).keys()].reverse():t,Z=(e,t)=>W.sortBasedOnPerm(e,ur(e.length,t)),dr=(e,t,n,r)=>{let i=`fn perm(i: ${r.type.indices}) -> ${n.type.indices} {
58
+ var a: ${n.type.indices};`;for(let n=0;n<t;++n)i+=`a[${e[n]}]=i[${n}];`;return i+=`return a;}`},fr=(e,t)=>{let n=[],r=[];for(let i=0;i<e.length;++i)e[i]!==1&&n.push(e[i]),e[t[i]]!==1&&r.push(t[i]);return{newShape:n,newPerm:r}},pr=(e,t)=>{let n=0;for(let r=0;r<e.length;++r)if(t[e[r]]!==1){if(e[r]<n)return!1;n=e[r]}return!0},mr=(e,t)=>{let n=e.dataType,r=e.dims.length,i=ur(r,t),a=Z(e.dims,i),o=e.dims,s=a,c=r<2||pr(i,e.dims),l;if(c)return l=e=>{let t=J(`input`,n,o,4),r=Y(`output`,n,s,4);return`
59
+ ${e.registerUniform(`output_size`,`u32`).declareVariables(t,r)}
60
+ ${e.mainStart()}
61
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)}
62
+ output[global_idx] = input[global_idx];
63
+ }`},{name:`TransposeCopy`,shaderCache:{inputDependencies:[`type`]},getRunData:()=>{let t=W.size(a);return{outputs:[{dims:a,dataType:e.dataType}],dispatchGroup:{x:Math.ceil(t/64/4)},programUniforms:[{type:12,data:Math.ceil(t/4)}]}},getShaderSource:l};let{newShape:u,newPerm:d}=fr(e.dims,i),f=W.areEqual(d,[2,3,1]),p=W.areEqual(d,[3,1,2]);return u.length===2||f||p?(o=f?[u[0],u[1]*u[2]]:p?[u[0]*u[1],u[2]]:u,s=[o[1],o[0]],l=e=>{let t=J(`a`,n,o.length),r=Y(`output`,n,s.length);return`
64
+ ${e.registerUniform(`output_size`,`u32`).declareVariables(t,r)}
65
+ var<workgroup> tile : array<array<${r.type.value}, 17>, 16>;
66
+ ${e.mainStart([16,16,1])}
67
+ let stride = (uniforms.output_shape[1] - 1) / 16 + 1;
68
+ let workgroup_id_x = workgroup_index % stride;
69
+ let workgroup_id_y = workgroup_index / stride;
70
+ let input_col = workgroup_id_y * 16u + local_id.x;
71
+ let input_row = workgroup_id_x * 16u + local_id.y;
72
+ if (input_row < uniforms.a_shape[0] && input_col < uniforms.a_shape[1]) {
73
+ tile[local_id.y][local_id.x] = ${t.getByIndices(`${t.type.indices}(input_row, input_col)`)};
74
+ }
75
+ workgroupBarrier();
76
+
77
+ let output_col = workgroup_id_x * 16u + local_id.x;
78
+ let output_row = workgroup_id_y * 16u + local_id.y;
79
+ if (output_row < uniforms.output_shape[0] && output_col < uniforms.output_shape[1]) {
80
+ ${r.setByIndices(`${r.type.indices}(output_row, output_col)`,`tile[local_id.x][local_id.y]`)}
81
+ }
82
+ }`},{name:`TransposeShared`,shaderCache:{inputDependencies:[`type`]},getRunData:()=>{let t=W.size(a);return{outputs:[{dims:a,dataType:e.dataType}],dispatchGroup:{x:Math.ceil(s[1]/16),y:Math.ceil(s[0]/16)},programUniforms:[{type:12,data:t},...K(o,s)]}},getShaderSource:l}):(l=e=>{let t=J(`a`,n,o.length),a=Y(`output`,n,s.length);return`
83
+ ${e.registerUniform(`output_size`,`u32`).declareVariables(t,a)}
84
+
85
+ ${dr(i,r,t,a)}
86
+
87
+ ${e.mainStart()}
88
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)}
89
+
90
+ let indices = ${a.offsetToIndices(`global_idx`)};
91
+ let aIndices = perm(indices);
92
+
93
+ ${a.setByOffset(`global_idx`,t.getByIndices(`aIndices`))}
94
+ }`},{name:`Transpose`,shaderCache:{hint:`${t}`,inputDependencies:[`rank`]},getRunData:()=>{let t=W.size(a);return{outputs:[{dims:a,dataType:e.dataType}],dispatchGroup:{x:Math.ceil(t/64)},programUniforms:[{type:12,data:t},...K(o,s)]}},getShaderSource:l})},hr=(e,t)=>{lr(e.inputs,t.perm),e.compute(mr(e.inputs[0],t.perm))},gr=e=>Jn({perm:e.perm})}),vr,yr,br,xr,Sr,Cr,wr,Tr,Er,Dr,Or,kr,Ar,jr,Mr,Nr,Pr,Fr,Ir,Lr,Rr,zr=M(()=>{H(),G(),X(),fi(),_r(),vr={max:`select(bestValue, candidate, candidate > bestValue)`,min:`select(bestValue, candidate, candidate < bestValue)`,mean:`bestValue + candidate`,sum:`bestValue + candidate`,prod:`bestValue * candidate`,sumSquare:`bestValue + candidate * candidate`,logSumExp:`bestValue + exp(candidate)`,l1:`bestValue + abs(candidate)`,l2:`bestValue + candidate * candidate`,logSum:`bestValue + candidate`},yr={max:`select(bestValue, candidate, candidate > bestValue)`,min:`select(bestValue, candidate, candidate < bestValue)`,mean:`bestValue + candidate`,sum:`bestValue + candidate`,prod:`bestValue * candidate`,sumSquare:`bestValue + candidate`,logSumExp:`bestValue + candidate`,l1:`bestValue + candidate`,l2:`bestValue + candidate`,logSum:`bestValue + candidate`},br={max:`_A[offset]`,min:`_A[offset]`,mean:`0`,sum:`0`,prod:`1`,sumSquare:`0`,logSumExp:`0`,l1:`0`,l2:`0`,logSum:`0`},xr={max:`bestValue`,min:`bestValue`,sum:`bestValue`,prod:`bestValue`,sumSquare:`bestValue`,logSumExp:`log(bestValue)`,l1:`bestValue`,l2:`sqrt(bestValue)`,logSum:`log(bestValue)`},Sr=(e,t)=>{let n=[];for(let r=t-e;r<t;++r)n.push(r);return n},Cr=(e,t)=>{let n=[],r=e.length;for(let i=0;i<r;i++)t.indexOf(i)===-1&&n.push(e[i]);return[n,t.map(t=>e[t])]},wr=(e,t)=>{let n=e.length+t.length,r=[],i=0;for(let a=0;a<n;a++)t.indexOf(a)===-1?r.push(e[i++]):r.push(1);return r},Tr=(e,t)=>{for(let n=0;n<e.length;++n)if(e[e.length-n-1]!==t-1-n)return!1;return!0},Er=(e,t)=>{let n=[];if(!Tr(e,t)){for(let r=0;r<t;++r)e.indexOf(r)===-1&&n.push(r);e.forEach(e=>n.push(e))}return n},Dr=(e,t,n,r,i,a,o)=>{let s=n[0].dims,c=W.size(a),l=W.size(o),u=J(`_A`,n[0].dataType,s),d=Y(`output`,i,a),f=64;c===1&&(f=256);let p=`
95
+ var<workgroup> aBestValues : array<f32, ${f}>;
96
+ `;return{name:e,shaderCache:{hint:`${t};${f}`,inputDependencies:[`type`]},getShaderSource:e=>`
97
+ ${e.registerUniform(`reduceSize`,`u32`).declareVariables(u,d)}
98
+ ${p}
99
+ fn DIV_CEIL(a : u32, b : u32) -> u32 {
100
+ return ((a - 1u) / b + 1u);
101
+ }
102
+ ${e.mainStart(f)}
103
+
104
+ let outputIndex = global_idx / ${f};
105
+ let offset = outputIndex * uniforms.reduceSize;
106
+
107
+ var bestValue = f32(${br[r]});
108
+ let Length = uniforms.reduceSize;
109
+ for (var k = local_idx; k < Length; k = k + ${f}) {
110
+ let candidate = f32(${u.getByOffset(`offset + k`)});
111
+ bestValue = ${vr[r]};
112
+ }
113
+ aBestValues[local_idx] = bestValue;
114
+ workgroupBarrier();
115
+
116
+ var reduceSize = min(Length, ${f}u);
117
+ for (var currentSize = reduceSize / 2u; reduceSize > 1u;
118
+ currentSize = reduceSize / 2u) {
119
+ let interval = DIV_CEIL(reduceSize, 2u);
120
+ if (local_idx < currentSize) {
121
+ let candidate = aBestValues[local_idx + interval];
122
+ bestValue = ${yr[r]};
123
+ aBestValues[local_idx] = bestValue;
124
+ }
125
+ reduceSize = interval;
126
+ workgroupBarrier();
127
+ }
128
+
129
+ if (local_idx == 0u) {
130
+ ${d.setByOffset(`outputIndex`,`${r===`mean`?`${d.type.storage}(bestValue / f32(uniforms.reduceSize))`:`${d.type.storage}(${xr[r]})`}`)};
131
+ }
132
+ }`,getRunData:()=>({outputs:[{dims:a,dataType:i}],dispatchGroup:{x:c},programUniforms:[{type:12,data:l}]})}},Or=(e,t,n,r)=>{let i=e.inputs.length===1?n:Ur(e.inputs,n),a=i.axes;a.length===0&&!i.noopWithEmptyAxes&&(a=e.inputs[0].dims.map((e,t)=>t));let o=W.normalizeAxes(a,e.inputs[0].dims.length),s=o,c=e.inputs[0],l=Er(s,e.inputs[0].dims.length);l.length>0&&(c=e.compute(mr(e.inputs[0],l),{inputs:[0],outputs:[-1]})[0],s=Sr(s.length,c.dims.length));let[u,d]=Cr(c.dims,s),f=u;i.keepDims&&(f=wr(u,o)),e.compute(Dr(t,i.cacheKey,[c],r,e.inputs[0].dataType,f,d),{inputs:[c]})},kr=(e,t)=>{Or(e,`ReduceMeanShared`,t,`mean`)},Ar=(e,t)=>{Or(e,`ReduceL1Shared`,t,`l1`)},jr=(e,t)=>{Or(e,`ReduceL2Shared`,t,`l2`)},Mr=(e,t)=>{Or(e,`ReduceLogSumExpShared`,t,`logSumExp`)},Nr=(e,t)=>{Or(e,`ReduceMaxShared`,t,`max`)},Pr=(e,t)=>{Or(e,`ReduceMinShared`,t,`min`)},Fr=(e,t)=>{Or(e,`ReduceProdShared`,t,`prod`)},Ir=(e,t)=>{Or(e,`ReduceSumShared`,t,`sum`)},Lr=(e,t)=>{Or(e,`ReduceSumSquareShared`,t,`sumSquare`)},Rr=(e,t)=>{Or(e,`ReduceLogSumShared`,t,`logSum`)}}),Br,Vr,Hr,Ur,Wr,Gr,Kr,qr,Jr,Yr,Xr,Zr,Qr,$r,ei,ti,ni,ri,ii,ai,oi,si,ci,li,ui,di,fi=M(()=>{H(),G(),Yn(),X(),zr(),Br=e=>{if(!e||e.length===0||e.length>2)throw Error(`Reduce op requires 1 or 2 inputs.`);if(e.length===2&&e[1].dims.length!==1)throw Error(`Invalid axes input dims.`)},Vr=e=>[``,``,`var value = ${e.getByIndices(`input_indices`)};`,``],Hr=(e,t,n,r,i,a,o=!1,s=!1)=>{let c=[],l=n[0].dims,u=l.length,d=W.normalizeAxes(i,u),f=!s&&d.length===0;l.forEach((e,t)=>{f||d.indexOf(t)>=0?o&&c.push(1):c.push(e)});let p=c.length,m=W.size(c);return{name:e,shaderCache:t,getShaderSource:e=>{let t=[],i=J(`_A`,n[0].dataType,u),s=Y(`output`,a,p),c=r(i,s,d),m=c[2];for(let e=0,n=0;e<u;e++)f||d.indexOf(e)>=0?(o&&n++,m=`for(var j${e}: u32 = 0; j${e} < ${l[e]}; j${e}++) {
133
+ ${c[2].includes(`last_index`)?`let last_index = j${e};`:``}
134
+ ${i.indicesSet(`input_indices`,e,`j${e}`)}
135
+ ${m}
136
+ }`):(t.push(`${i.indicesSet(`input_indices`,e,s.indicesGet(`output_indices`,n))};`),n++);return`
137
+
138
+ ${e.registerUniform(`output_size`,`u32`).declareVariables(i,s)}
139
+
140
+ ${e.mainStart()}
141
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)}
142
+ var input_indices: ${i.type.indices};
143
+ let output_indices = ${s.offsetToIndices(`global_idx`)};
144
+
145
+ ${t.join(`
146
+ `)}
147
+ ${c[0]} // init ops for reduce max/min
148
+ ${c[1]}
149
+ ${m}
150
+ ${c[3]}
151
+ ${c.length===4?s.setByOffset(`global_idx`,`value`):c.slice(4).join(`
152
+ `)}
153
+ }`},getRunData:()=>({outputs:[{dims:c,dataType:a}],dispatchGroup:{x:Math.ceil(m/64)},programUniforms:[{type:12,data:m},...K(l,c)]})}},Ur=(e,t)=>{let n=[];return e[1].dims[0]>0&&e[1].getBigInt64Array().forEach(e=>n.push(Number(e))),Jn({axes:n,keepDims:t.keepDims,noopWithEmptyAxes:t.noopWithEmptyAxes})},Wr=(e,t,n,r)=>{let i=e.inputs,a=i.length===1?n:Ur(i,n);e.compute(Hr(t,{hint:a.cacheKey,inputDependencies:[`rank`]},[i[0]],a.noopWithEmptyAxes&&a.axes.length===0?Vr:r,a.axes,i[0].dataType,a.keepDims,a.noopWithEmptyAxes),{inputs:[0]})},Gr=(e,t)=>{Br(e.inputs),Wr(e,`ReduceLogSum`,t,(e,t)=>[`var value = ${t.type.storage}(0);`,``,`value += ${e.getByIndices(`input_indices`)};`,`value = log(value);`])},Kr=(e,t)=>{Br(e.inputs),Wr(e,`ReduceL1`,t,(e,t)=>[`var value = ${t.type.storage}(0);`,``,`value += abs(${e.getByIndices(`input_indices`)});`,``])},qr=(e,t)=>{Br(e.inputs),Wr(e,`ReduceL2`,t,(e,t)=>[`var t = ${t.type.value}(0); var value = ${t.type.value}(0);`,``,`t = ${e.getByIndices(`input_indices`)}; value += (t * t);`,`value = sqrt(value);`])},Jr=(e,t)=>{Br(e.inputs),Wr(e,`ReduceLogSumExp`,t,(e,t)=>[`var value = ${t.type.storage}(0);`,``,`value += exp(${e.getByIndices(`input_indices`)});`,`value = log(value);`])},Yr=(e,t)=>{Br(e.inputs),Wr(e,`ReduceMax`,t,(e,t,n)=>{let r=[];for(let t=0;t<e.rank;t++)(n.indexOf(t)>=0||n.length===0)&&r.push(e.indicesSet(`input_indices`,t,0));return[`${r.join(`
154
+ `)}`,`var value = ${e.getByIndices(`input_indices`)};`,`value = max(value, ${e.getByIndices(`input_indices`)});`,``]})},Xr=(e,t)=>{Br(e.inputs),Wr(e,`ReduceMean`,t,(t,n,r)=>{let i=1;for(let n=0;n<t.rank;n++)(r.indexOf(n)>=0||r.length===0)&&(i*=e.inputs[0].dims[n]);return[`var sum = f32(0);`,``,`sum += f32(${t.getByIndices(`input_indices`)});`,`let value = ${n.type.value}(sum / ${i});`]})},Zr=(e,t)=>{Br(e.inputs),Wr(e,`ReduceMin`,t,(e,t,n)=>{let r=[];for(let t=0;t<e.rank;t++)(n.indexOf(t)>=0||n.length===0)&&r.push(`input_indices[${t}] = 0;`);return[`${r.join(`
155
+ `)}`,`var value = ${e.getByIndices(`input_indices`)};`,`value = min(value, ${e.getByIndices(`input_indices`)});`,``]})},Qr=(e,t)=>{Br(e.inputs),Wr(e,`ReduceProd`,t,(e,t)=>[`var value = ${t.type.storage}(1);`,``,`value *= ${e.getByIndices(`input_indices`)};`,``])},$r=(e,t)=>{Br(e.inputs),Wr(e,`ReduceSum`,t,(e,t)=>[`var value = ${t.type.storage}(0);`,``,`value += ${e.getByIndices(`input_indices`)};`,``])},ei=(e,t)=>{Br(e.inputs),Wr(e,`ReduceSumSquare`,t,(e,t)=>[`var t = ${t.type.value}(0); var value = ${t.type.value}(0);`,``,`t = ${e.getByIndices(`input_indices`)}; value += t * t;`,``])},ti=(e,t,n)=>{if(t.length===0)return n;let r=1,i=1;for(let n=0;n<t.length;n++)t.indexOf(n)===-1?r*=e[n]:i*=e[n];return i<32&&r>1024},ni=(e,t)=>{ti(e.inputs[0].dims,t.axes,t.noopWithEmptyAxes)?Xr(e,t):kr(e,t)},ri=(e,t)=>{ti(e.inputs[0].dims,t.axes,t.noopWithEmptyAxes)?Kr(e,t):Ar(e,t)},ii=(e,t)=>{ti(e.inputs[0].dims,t.axes,t.noopWithEmptyAxes)?qr(e,t):jr(e,t)},ai=(e,t)=>{ti(e.inputs[0].dims,t.axes,t.noopWithEmptyAxes)?Jr(e,t):Mr(e,t)},oi=(e,t)=>{ti(e.inputs[0].dims,t.axes,t.noopWithEmptyAxes)?Yr(e,t):Nr(e,t)},si=(e,t)=>{ti(e.inputs[0].dims,t.axes,t.noopWithEmptyAxes)?Zr(e,t):Pr(e,t)},ci=(e,t)=>{ti(e.inputs[0].dims,t.axes,t.noopWithEmptyAxes)?Qr(e,t):Fr(e,t)},li=(e,t)=>{ti(e.inputs[0].dims,t.axes,t.noopWithEmptyAxes)?$r(e,t):Ir(e,t)},ui=(e,t)=>{ti(e.inputs[0].dims,t.axes,t.noopWithEmptyAxes)?ei(e,t):Lr(e,t)},di=(e,t)=>{ti(e.inputs[0].dims,t.axes,t.noopWithEmptyAxes)?Gr(e,t):Rr(e,t)}}),pi,mi,hi,gi,_i=M(()=>{H(),Yn(),fi(),pi=e=>{if(!e||e.length===0||e.length>2)throw Error(`ArgMinMaxOp op requires 1 or 2 inputs.`);if(e[0].dataType!==1)throw Error(`Invalid input type.`)},mi=(e,t)=>{pi(e.inputs),e.compute(Hr(`ArgMin`,{hint:t.cacheKey,inputDependencies:[`rank`]},[e.inputs[0]],(e,n,r)=>{let i=[];for(let t=0;t<e.rank;t++)(r.indexOf(t)>=0||r.length===0)&&i.push(`input_indices[${t}] = 0;`);return[`${i.join(`
156
+ `)}`,`var value = ${e.getByIndices(`input_indices`)};
157
+ var best_index : i32 = 0;`,`if (${e.getByIndices(`input_indices`)} ${t.selectLastIndex>0?`<=`:`<`} value) {
158
+ value = ${e.getByIndices(`input_indices`)};
159
+ best_index = i32(last_index);
160
+ }`,``,n.setByOffset(`global_idx`,`best_index`)]},[t.axis],7,t.keepDims),{inputs:[0]})},hi=(e,t)=>{pi(e.inputs),e.compute(Hr(`argMax`,{hint:t.cacheKey,inputDependencies:[`rank`]},[e.inputs[0]],(e,n,r)=>{let i=[];for(let t=0;t<e.rank;t++)(r.indexOf(t)>=0||r.length===0)&&i.push(`input_indices[${t}] = 0;`);return[`${i.join(`
161
+ `)}`,`var value = ${e.getByIndices(`input_indices`)};
162
+ var best_index : i32 = 0;`,`if (${e.getByIndices(`input_indices`)} ${t.selectLastIndex>0?`>=`:`>`} value) {
163
+ value = ${e.getByIndices(`input_indices`)};
164
+ best_index = i32(last_index);
165
+ }`,``,n.setByOffset(`global_idx`,`best_index`)]},[t.axis],7,t.keepDims),{inputs:[0]})},gi=e=>Jn(e)}),vi,yi,bi,xi,Si,Ci,wi,Ti,Ei=M(()=>{H(),G(),In(),X(),vi=(e,t)=>{let n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],s=e[5];if(o&&s)throw Error(`Attention cannot have both past and attention_bias`);if(n.dims.length!==3)throw Error(`Input "input" must have 3 dimensions`);let c=n.dims[0],l=n.dims[1],u=n.dims[2];if(i.dims.length!==1)throw Error(`Input "bias" is expected to have 1 dimensions`);if(r.dims.length!==2)throw Error(`Input "weights" is expected to have 2 dimensions`);if(r.dims[0]!==u)throw Error(`Input 1 dimension 0 should have same length as dimension 2 of input 0`);if(i.dims[0]!==r.dims[1])throw Error(`Input "bias" dimension 0 should have same length as dimension 1 of input "weights"`);let d=i.dims[0]/3,f=d,p=f;if(t.qkvHiddenSizes.length>0){if(t.qkvHiddenSizes.length!==3)throw Error(`qkv_hidden_sizes attribute should have 3 elements`);for(let e of t.qkvHiddenSizes)if(e%t.numHeads!==0)throw Error(`qkv_hidden_sizes should be divisible by num_heads`);d=t.qkvHiddenSizes[0],f=t.qkvHiddenSizes[1],p=t.qkvHiddenSizes[2]}let m=l;if(d!==f)throw Error(`qkv_hidden_sizes first element should be same as the second`);if(i.dims[0]!==d+f+p)throw Error(`Input "bias" dimension 0 should have same length as sum of Q/K/V hidden sizes`);let h=0;if(o){if(f!==p)throw Error(`Input "past" expect k_hidden_size == v_hidden_size`);if(o.dims.length!==5)throw Error(`Input "past" must have 5 dimensions`);if(o.dims[0]!==2)throw Error(`Input "past" first dimension must be 2`);if(o.dims[1]!==c)throw Error(`Input "past" second dimension must be batch_size`);if(o.dims[2]!==t.numHeads)throw Error(`Input "past" third dimension must be num_heads`);if(o.dims[4]!==f/t.numHeads)throw Error(`Input "past" fifth dimension must be k_hidden_size / num_heads`);t.pastPresentShareBuffer||(h=o.dims[3])}let g=m+h;if(a)throw Error(`Mask not supported`);if(o)throw Error(`past is not supported`);if(s){if(s.dims.length!==4)throw Error(`Input "attention_bias" must have 4 dimensions`);if(s.dims[0]!==c||s.dims[1]!==t.numHeads||s.dims[2]!==l||s.dims[3]!==g)throw Error(`Expect "attention_bias" shape (batch_size, num_heads, sequence_length, total_sequence_length)`)}return{batchSize:c,sequenceLength:l,pastSequenceLength:h,kvSequenceLength:m,totalSequenceLength:g,maxSequenceLength:-1,inputHiddenSize:u,hiddenSize:d,vHiddenSize:p,headSize:Math.floor(d/t.numHeads),vHeadSize:Math.floor(p/t.numHeads),numHeads:t.numHeads,isUnidirectional:!1,pastPresentShareBuffer:!1,maskFilterValue:t.maskFilterValue,maskType:0,scale:t.scale,broadcastResPosBias:!1,passPastInKv:!1,qkvFormat:1}},yi=(e,t,n)=>t&&e?`
166
+ let total_sequence_length_input = u32(${t.getByOffset(`0`)});
167
+ let present_sequence_length = max(total_sequence_length_input, uniforms.past_sequence_length);
168
+ let is_subsequent_prompt: bool = sequence_length > 1 && sequence_length != total_sequence_length_input;
169
+ let is_first_prompt: bool = is_subsequent_prompt == false && sequence_length == total_sequence_length_input;
170
+ total_sequence_length = u32(${e?.getByOffset(`batchIdx`)}) + 1;
171
+ var past_sequence_length: u32 = 0;
172
+ if (is_first_prompt == false) {
173
+ past_sequence_length = total_sequence_length - sequence_length;
174
+ }
175
+ `:`
176
+ ${n?`let past_sequence_length = uniforms.past_sequence_length`:``};
177
+ let present_sequence_length = total_sequence_length;
178
+ `,bi=(e,t,n,r,i,a,o,s)=>{let c=er(o?1:a),l=64,u=a/c;u<l&&(l=32);let d=Math.ceil(a/c/l),f=[{type:12,data:t},{type:12,data:n},{type:12,data:r},{type:12,data:i},{type:12,data:u},{type:12,data:d}],p=Qn(e.dataType,c),m=$n(1,c),h=[`type`];return o&&h.push(`type`),s&&h.push(`type`),{name:`AttentionProbsSoftmax`,shaderCache:{hint:`${l};${p};${c}`,inputDependencies:h},getShaderSource:t=>{let n=Y(`x`,e.dataType,e.dims,c),r=[n],i=o?J(`seq_lens`,o.dataType,o.dims):void 0;i&&r.push(i);let a=s?J(`total_sequence_length_input`,s.dataType,s.dims):void 0;a&&r.push(a);let u=$n(e.dataType);return`
179
+ var<workgroup> thread_max: array<f32, ${l}>;
180
+ var<workgroup> thread_sum: array<f32, ${l}>;
181
+ ${t.registerUniforms([{name:`batch_size`,type:`u32`},{name:`num_heads`,type:`u32`},{name:`past_sequence_length`,type:`u32`},{name:`sequence_length`,type:`u32`},{name:`total_sequence_length`,type:`u32`},{name:`elements_per_thread`,type:`u32`}]).declareVariables(...r)}
182
+ ${t.mainStart([l,1,1])}
183
+ let batchIdx = workgroup_id.z / uniforms.num_heads;
184
+ let headIdx = workgroup_id.z % uniforms.num_heads;
185
+ let sequence_length = uniforms.sequence_length;
186
+ var total_sequence_length = uniforms.total_sequence_length;
187
+ ${yi(i,a,!1)}
188
+ let local_offset = local_idx * uniforms.elements_per_thread;
189
+ let offset = (global_idx / ${l}) * uniforms.total_sequence_length + local_offset;
190
+ let seq_causal_length = ${o?`u32(past_sequence_length + workgroup_id.y + 1)`:`total_sequence_length`};
191
+ var thread_max_vector = ${m}(-3.402823e+38f);
192
+ for (var i: u32 = 0; i < uniforms.elements_per_thread && i + local_offset < seq_causal_length; i++) {
193
+ thread_max_vector = max(${m}(x[offset + i]), thread_max_vector);
194
+ }
195
+ thread_max[local_idx] = ${(()=>{switch(c){case 1:return`thread_max_vector`;case 2:return`max(thread_max_vector.x, thread_max_vector.y)`;case 4:return`max(max(thread_max_vector.x, thread_max_vector.y), max(thread_max_vector.z, thread_max_vector.w))`;default:throw Error(`Unsupported components: ${c}`)}})()};
196
+ workgroupBarrier();
197
+
198
+ var max_value = f32(-3.402823e+38f);
199
+ for (var i = 0u; i < ${l}; i++) {
200
+ max_value = max(thread_max[i], max_value);
201
+ }
202
+
203
+ var sum_vector = ${m}(0);
204
+ for (var i: u32 = 0; i < uniforms.elements_per_thread && i + local_offset < seq_causal_length; i++) {
205
+ sum_vector += exp(${m}(x[offset + i]) - max_value);
206
+ }
207
+ thread_sum[local_idx] = ${(()=>{switch(c){case 1:return`sum_vector`;case 2:return`sum_vector.x + sum_vector.y`;case 4:return`sum_vector.x + sum_vector.y + sum_vector.z + sum_vector.w`;default:throw Error(`Unsupported components: ${c}`)}})()};
208
+ workgroupBarrier();
209
+
210
+ var sum: f32 = 0;
211
+ for (var i = 0u; i < ${l}; i++) {
212
+ sum += thread_sum[i];
213
+ }
214
+
215
+ if (sum == 0) {
216
+ for (var i: u32 = 0; i < uniforms.elements_per_thread && i + local_offset < seq_causal_length; i++) {
217
+ x[offset + i] = ${n.type.value}(${u}(1.0) / ${u}(seq_causal_length));
218
+ }
219
+ } else {
220
+ for (var i: u32 = 0; i < uniforms.elements_per_thread && i + local_offset < seq_causal_length; i++) {
221
+ var f32input = ${m}(x[offset + i]);
222
+ x[offset + i] = ${n.type.value}(exp(f32input - max_value) / sum);
223
+ }
224
+ }
225
+ ${o?`
226
+ for (var total_seq_id: u32 = seq_causal_length; total_seq_id + local_offset < uniforms.total_sequence_length; total_seq_id++) {
227
+ x[offset + total_seq_id] = ${n.type.value}(${u}(0));
228
+ }`:``};
229
+ }`},getRunData:()=>({outputs:[],dispatchGroup:{x:1,y:i,z:t*n},programUniforms:f})}},xi=(e,t,n,r,i,a,o,s,c)=>{let l=o+a.kvSequenceLength,u=[a.batchSize,a.numHeads,a.sequenceLength,l],d=e>1&&r,f=a.kvNumHeads?a.kvNumHeads:a.numHeads,p=d?[a.batchSize,f,l,a.headSize]:void 0,m=a.nReps?a.nReps:1,h=a.scale===0?1/Math.sqrt(a.headSize):a.scale,g=er(a.headSize),_=a.headSize/g,v={x:Math.ceil(l/12),y:Math.ceil(a.sequenceLength/12),z:a.batchSize*a.numHeads},y=[{type:12,data:a.sequenceLength},{type:12,data:_},{type:12,data:l},{type:12,data:a.numHeads},{type:12,data:a.headSize},{type:1,data:h},{type:12,data:o},{type:12,data:a.kvSequenceLength},{type:12,data:m}],b=d&&r&&W.size(r.dims)>0,x=[`type`,`type`];b&&x.push(`type`),i&&x.push(`type`),s&&x.push(`type`),c&&x.push(`type`);let S=[{dims:u,dataType:t.dataType,gpuDataType:0}];return d&&S.push({dims:p,dataType:t.dataType,gpuDataType:0}),{name:`AttentionProbs`,shaderCache:{hint:`${g};${i!==void 0};${r!==void 0};${e}`,inputDependencies:x},getRunData:()=>({outputs:S,dispatchGroup:v,programUniforms:y}),getShaderSource:e=>{let a=J(`q`,t.dataType,t.dims,g),o=[a,J(`key`,n.dataType,n.dims,g)];if(b){let e=J(`past_key`,r.dataType,r.dims,g);o.push(e)}i&&o.push(J(`attention_bias`,i.dataType,i.dims));let l=s?J(`seq_lens`,s.dataType,s.dims):void 0;l&&o.push(l);let f=c?J(`total_sequence_length_input`,c.dataType,c.dims):void 0;f&&o.push(f);let h=Y(`output`,t.dataType,u),_=[h];d&&_.push(Y(`present_key`,t.dataType,p,g));let v=$n(1,g);return`
230
+ const TILE_SIZE = 12u;
231
+
232
+ var<workgroup> tileQ: array<${a.type.storage}, 144>;
233
+ var<workgroup> tileK: array<${a.type.storage}, 144>;
234
+ ${e.registerUniforms([{name:`M`,type:`u32`},{name:`K`,type:`u32`},{name:`N`,type:`u32`},{name:`num_heads`,type:`u32`},{name:`head_size`,type:`u32`},{name:`alpha`,type:`f32`},{name:`past_sequence_length`,type:`u32`},{name:`kv_sequence_length`,type:`u32`},{name:`n_reps`,type:`u32`}]).declareVariables(...o,..._)}
235
+ ${e.mainStart([12,12,1])}
236
+ // x holds the N and y holds the M
237
+ let headIdx = workgroup_id.z % uniforms.num_heads;
238
+ let kvHeadIdx = ${m===1?`headIdx`:`headIdx / uniforms.n_reps`};
239
+ let kv_num_heads = ${m===1?`uniforms.num_heads`:`uniforms.num_heads / uniforms.n_reps`};
240
+ let batchIdx = workgroup_id.z / uniforms.num_heads;
241
+ let m = workgroup_id.y * TILE_SIZE;
242
+ let n = workgroup_id.x * TILE_SIZE;
243
+ let sequence_length = uniforms.M;
244
+ var total_sequence_length = uniforms.N;
245
+ ${yi(l,f,!0)}
246
+ let absKvHeadIdx = batchIdx * kv_num_heads + kvHeadIdx;
247
+ let qOffset = workgroup_id.z * uniforms.M * uniforms.K + m * uniforms.K;
248
+ ${b&&d?`let pastKeyOffset = absKvHeadIdx * uniforms.past_sequence_length * uniforms.K;`:``};
249
+ let kOffset = absKvHeadIdx * uniforms.kv_sequence_length * uniforms.K;
250
+ ${d?`let presentKeyOffset = absKvHeadIdx * uniforms.N * uniforms.K;`:``}
251
+ var value = ${v}(0);
252
+ for (var w: u32 = 0u; w < uniforms.K; w += TILE_SIZE) {
253
+ if (global_id.y < uniforms.M && w + local_id.x < uniforms.K) {
254
+ tileQ[TILE_SIZE * local_id.y + local_id.x] = q[qOffset + local_id.y * uniforms.K + w + local_id.x];
255
+ }
256
+ if (n + local_id.y < uniforms.N && w + local_id.x < uniforms.K) {
257
+ var idx = TILE_SIZE * local_id.y + local_id.x;
258
+ ${b&&d?`
259
+ if (n + local_id.y < past_sequence_length) {
260
+ tileK[idx] = past_key[pastKeyOffset + (n + local_id.y) * uniforms.K + w + local_id.x];
261
+ } else if (n + local_id.y - past_sequence_length < uniforms.kv_sequence_length) {
262
+ tileK[idx] = key[kOffset + (n + local_id.y - past_sequence_length) * uniforms.K + w + local_id.x];
263
+ }`:`
264
+ if (n + local_id.y < uniforms.kv_sequence_length) {
265
+ tileK[idx] = key[kOffset + (n + local_id.y) * uniforms.K + w + local_id.x];
266
+ }`}
267
+ ${d?`if (n + local_id.y < present_sequence_length) {
268
+ present_key[presentKeyOffset + (n + local_id.y) * uniforms.K + w + local_id.x] = tileK[idx];
269
+ }`:``}
270
+ }
271
+ workgroupBarrier();
272
+
273
+ for (var k: u32 = 0u; k < TILE_SIZE && w+k < uniforms.K; k++) {
274
+ value += ${v}(tileQ[TILE_SIZE * local_id.y + k] * tileK[TILE_SIZE * local_id.x + k]);
275
+ }
276
+
277
+ workgroupBarrier();
278
+ }
279
+
280
+ if (global_id.y < uniforms.M && global_id.x < total_sequence_length) {
281
+ let headOffset = workgroup_id.z * uniforms.M * uniforms.N;
282
+ let outputIdx = headOffset + global_id.y * uniforms.N + global_id.x;
283
+ var sum: f32 = ${(()=>{switch(g){case 1:return`value`;case 2:return`value.x + value.y`;case 4:return`value.x + value.y + value.z + value.w`;default:throw Error(`Unsupported components: ${g}`)}})()};
284
+ output[outputIdx] = ${h.type.value} (sum * uniforms.alpha) + ${i?`attention_bias[outputIdx]`:`0.0`};
285
+ }
286
+ }`}}},Si=(e,t,n,r,i,a,o=void 0,s=void 0)=>{let c=a+i.kvSequenceLength,l=i.nReps?i.nReps:1,u=i.vHiddenSize*l,d=e>1&&r,f=i.kvNumHeads?i.kvNumHeads:i.numHeads,p=d?[i.batchSize,f,c,i.headSize]:void 0,m=[i.batchSize,i.sequenceLength,u],h={x:Math.ceil(i.vHeadSize/12),y:Math.ceil(i.sequenceLength/12),z:i.batchSize*i.numHeads},g=[{type:12,data:i.sequenceLength},{type:12,data:c},{type:12,data:i.vHeadSize},{type:12,data:i.numHeads},{type:12,data:i.headSize},{type:12,data:u},{type:12,data:a},{type:12,data:i.kvSequenceLength},{type:12,data:l}],_=d&&r&&W.size(r.dims)>0,v=[`type`,`type`];_&&v.push(`type`),o&&v.push(`type`),s&&v.push(`type`);let y=[{dims:m,dataType:t.dataType,gpuDataType:0}];return d&&y.push({dims:p,dataType:t.dataType,gpuDataType:0}),{name:`AttentionScore`,shaderCache:{hint:`${r!==void 0};${e}`,inputDependencies:v},getRunData:()=>({outputs:y,dispatchGroup:h,programUniforms:g}),getShaderSource:e=>{let i=J(`probs`,t.dataType,t.dims),a=[i,J(`v`,n.dataType,n.dims)];_&&a.push(J(`past_value`,r.dataType,r.dims));let c=o?J(`seq_lens`,o.dataType,o.dims):void 0;o&&a.push(c);let u=s?J(`total_sequence_length_input`,s.dataType,s.dims):void 0;s&&a.push(u);let f=[Y(`output`,t.dataType,m)];return d&&f.push(Y(`present_value`,t.dataType,p)),`
287
+ const TILE_SIZE = 12u;
288
+ var<workgroup> tileQ: array<${i.type.value}, 144>;
289
+ var<workgroup> tileV: array<${i.type.value}, 144>;
290
+ ${e.registerUniforms([{name:`M`,type:`u32`},{name:`K`,type:`u32`},{name:`N`,type:`u32`},{name:`num_heads`,type:`u32`},{name:`head_size`,type:`u32`},{name:`v_hidden_size`,type:`u32`},{name:`past_sequence_length`,type:`u32`},{name:`kv_sequence_length`,type:`u32`},{name:`n_reps`,type:`u32`}]).declareVariables(...a,...f)}
291
+ ${e.mainStart([12,12,1])}
292
+ let headIdx = workgroup_id.z % uniforms.num_heads;
293
+ let batchIdx = workgroup_id.z / uniforms.num_heads;
294
+ let kvHeadIdx = ${l===1?`headIdx`:`headIdx / uniforms.n_reps`};
295
+ let kv_num_heads = ${l===1?`uniforms.num_heads`:`uniforms.num_heads / uniforms.n_reps`};
296
+ let m = global_id.y;
297
+ let n = global_id.x;
298
+ let sequence_length = uniforms.M;
299
+ var total_sequence_length = uniforms.K;
300
+ ${yi(c,u,!0)}
301
+ let offsetA = workgroup_id.z * uniforms.M * uniforms.K + m * uniforms.K;
302
+ let absKvHeadIdx = batchIdx * kv_num_heads + kvHeadIdx; // kvHeadIdx is relative to the batch
303
+ ${_&&d?`let pastValueOffset = absKvHeadIdx * uniforms.N * uniforms.past_sequence_length + n;`:``};
304
+ let vOffset = absKvHeadIdx * uniforms.N * uniforms.kv_sequence_length + n;
305
+ ${d?`let presentValueOffset = absKvHeadIdx * uniforms.N * uniforms.K + n;`:``}
306
+ var value = ${i.type.storage}(0);
307
+ for (var w: u32 = 0u; w < uniforms.K; w += TILE_SIZE) {
308
+ if (m < uniforms.M && w + local_id.x < uniforms.K) {
309
+ tileQ[TILE_SIZE * local_id.y + local_id.x] = probs[offsetA + w + local_id.x];
310
+ }
311
+ if (n < uniforms.N && w + local_id.y < uniforms.K) {
312
+ var idx = TILE_SIZE * local_id.y + local_id.x;
313
+ ${_&&d?`
314
+ if (w + local_id.y < past_sequence_length) {
315
+ tileV[idx] = past_value[pastValueOffset + (w + local_id.y) * uniforms.N];
316
+ } else if (w + local_id.y - past_sequence_length < uniforms.kv_sequence_length) {
317
+ tileV[idx] = v[vOffset + (w + local_id.y - past_sequence_length) * uniforms.N];
318
+ }
319
+ `:`
320
+ if (w + local_id.y < uniforms.kv_sequence_length) {
321
+ tileV[idx] = v[vOffset + (w + local_id.y) * uniforms.N];
322
+ }`}
323
+ ${d?`
324
+ if (w + local_id.y < present_sequence_length) {
325
+ present_value[presentValueOffset + (w + local_id.y) * uniforms.N] = tileV[idx];
326
+ }`:``}
327
+ }
328
+ workgroupBarrier();
329
+ for (var k: u32 = 0u; k < TILE_SIZE && w+k < total_sequence_length; k++) {
330
+ value += tileQ[TILE_SIZE * local_id.y + k] * tileV[TILE_SIZE * k + local_id.x];
331
+ }
332
+ workgroupBarrier();
333
+ }
334
+
335
+ // we need to transpose output from BNSH_v to BSND_v
336
+ if (m < uniforms.M && n < uniforms.N) {
337
+ let outputIdx = batchIdx * uniforms.M * uniforms.v_hidden_size + m * uniforms.v_hidden_size
338
+ + headIdx * uniforms.N + n;
339
+ output[outputIdx] = value;
340
+ }
341
+ }`}}},Ci=(e,t,n,r,i,a,o,s,c,l,u=void 0,d=void 0)=>{let f=Math.min(e.outputCount,1+ +!!o+ +!!s),p=f>1?l.pastSequenceLength:0,m=p+l.kvSequenceLength,h=c&&W.size(c.dims)>0?c:void 0,g=[t,n];f>1&&o&&W.size(o.dims)>0&&g.push(o),h&&g.push(h),u&&g.push(u),d&&g.push(d);let _=e.compute(xi(f,t,n,o,h,l,p,u,d),{inputs:g,outputs:f>1?[-1,1]:[-1]})[0];e.compute(bi(_,l.batchSize,l.numHeads,p,l.sequenceLength,m,u,d),{inputs:u&&d?[_,u,d]:[_],outputs:[]});let v=[_,r];f>1&&s&&W.size(s.dims)>0&&v.push(s),u&&v.push(u),d&&v.push(d),e.compute(Si(f,_,r,s,l,p,u,d),{inputs:v,outputs:f>1?[0,2]:[0]})},wi=(e,t)=>{let n=[t.batchSize,t.numHeads,t.sequenceLength,t.headSize],r=t.sequenceLength,i=t.inputHiddenSize,a=t.headSize,o={x:Math.ceil(t.headSize/12),y:Math.ceil(t.sequenceLength/12),z:t.batchSize*t.numHeads},s=[e.inputs[0],e.inputs[1],e.inputs[2]],c=[{type:12,data:r},{type:12,data:i},{type:12,data:a},{type:12,data:t.numHeads},{type:12,data:t.headSize},{type:12,data:t.hiddenSize},{type:12,data:t.hiddenSize+t.hiddenSize+t.vHiddenSize}];return e.compute({name:`AttentionPrepare`,shaderCache:{inputDependencies:[`type`,`type`,`type`]},getRunData:()=>({outputs:[{dims:n,dataType:e.inputs[0].dataType,gpuDataType:0},{dims:n,dataType:e.inputs[0].dataType,gpuDataType:0},{dims:n,dataType:e.inputs[0].dataType,gpuDataType:0}],dispatchGroup:o,programUniforms:c}),getShaderSource:e=>{let t=Y(`output_q`,s[0].dataType,n),r=Y(`output_k`,s[0].dataType,n),i=Y(`output_v`,s[0].dataType,n),a=J(`input`,s[0].dataType,s[0].dims),o=J(`weight`,s[1].dataType,s[1].dims),c=J(`bias`,s[2].dataType,s[2].dims),l=a.type.storage;return`
342
+ const TILE_SIZE = 12u;
343
+ var<workgroup> tileInput: array<${l}, 144>;
344
+ var<workgroup> tileWeightQ: array<${l}, 144>;
345
+ var<workgroup> tileWeightK: array<${l}, 144>;
346
+ var<workgroup> tileWeightV: array<${l}, 144>;
347
+ ${e.registerUniforms([{name:`M`,type:`u32`},{name:`K`,type:`u32`},{name:`N`,type:`u32`},{name:`num_heads`,type:`u32`},{name:`head_size`,type:`u32`},{name:`hidden_size`,type:`u32`},{name:`ldb`,type:`u32`}]).declareVariables(a,o,c,t,r,i)}
348
+ ${e.mainStart([12,12,1])}
349
+ let batchIndex = workgroup_id.z / uniforms.num_heads;
350
+ let headNumber = workgroup_id.z % uniforms.num_heads;
351
+ let m = global_id.y;
352
+ let n = global_id.x;
353
+
354
+ let inputOffset = batchIndex * (uniforms.M * uniforms.K) + m * uniforms.K;
355
+ let biasOffsetQ = headNumber * uniforms.head_size;
356
+ let biasOffsetK = uniforms.hidden_size + biasOffsetQ;
357
+ let biasOffsetV = uniforms.hidden_size + biasOffsetK;
358
+
359
+ var valueQ = ${l}(0);
360
+ var valueK = ${l}(0);
361
+ var valueV = ${l}(0);
362
+ for (var w: u32 = 0u; w < uniforms.K; w += TILE_SIZE) {
363
+ if (m < uniforms.M && w + local_id.x < uniforms.K) {
364
+ tileInput[TILE_SIZE * local_id.y + local_id.x] = input[inputOffset + w + local_id.x];
365
+ }
366
+ if (n < uniforms.N && w + local_id.y < uniforms.K) {
367
+ let offset = n + (w + local_id.y) * uniforms.ldb;
368
+ tileWeightQ[TILE_SIZE * local_id.y + local_id.x] = weight[biasOffsetQ + offset];
369
+ tileWeightK[TILE_SIZE * local_id.y + local_id.x] = weight[biasOffsetK + offset];
370
+ tileWeightV[TILE_SIZE * local_id.y + local_id.x] = weight[biasOffsetV + offset];
371
+ }
372
+ workgroupBarrier();
373
+ for (var k: u32 = 0u; k<TILE_SIZE && w+k < uniforms.K; k++) {
374
+ let inputTileOffset = TILE_SIZE * local_id.y + k;
375
+ let weightTileOffset = TILE_SIZE * k + local_id.x;
376
+ valueQ += tileInput[inputTileOffset] * tileWeightQ[weightTileOffset];
377
+ valueK += tileInput[inputTileOffset] * tileWeightK[weightTileOffset];
378
+ valueV += tileInput[inputTileOffset] * tileWeightV[weightTileOffset];
379
+ }
380
+
381
+ workgroupBarrier();
382
+ }
383
+
384
+ let headOffset = (m * uniforms.N + n) % uniforms.head_size;
385
+ valueQ += bias[headOffset + biasOffsetQ];
386
+ valueK += bias[headOffset + biasOffsetK];
387
+ valueV += bias[headOffset + biasOffsetV];
388
+
389
+ let offset = workgroup_id.z * uniforms.M * uniforms.N;
390
+ if (m < uniforms.M && n < uniforms.N) {
391
+ let outputIdx = offset + m * uniforms.N + n;
392
+ output_q[outputIdx] = valueQ;
393
+ output_k[outputIdx] = valueK;
394
+ output_v[outputIdx] = valueV;
395
+ }
396
+ }`}},{inputs:s,outputs:[-1,-1,-1]})},Ti=(e,t)=>{let n=vi(e.inputs,t),[r,i,a]=wi(e,n);return Ci(e,r,i,a,e.inputs[4],void 0,void 0,void 0,e.inputs[5],n)}}),Di,Oi,ki,Ai,ji=M(()=>{Qe(),H(),G(),Yn(),X(),Di=(e,t)=>{if(!e||e.length!==5)throw Error(`BatchNormalization requires 5 inputs`);let n=(e,t,n)=>{let r=t.length;if(r!==e.length)throw Error(`${n}: num dimensions != ${r}`);t.forEach((t,r)=>{if(t!==e[r])throw Error(`${n}: dim[${r}] do not match`)})};if(e[0].dims.length>1){let r=t.format===`NHWC`?t.spatial?e[0].dims.slice(-1):e[0].dims.slice(-1).concat(e[0].dims.slice(1,e[0].dims.length-1)):e[0].dims.slice(1,t.spatial?2:void 0);n(e[1].dims,r,`Invalid input scale`),n(e[2].dims,r,`Invalid input B`),n(e[3].dims,r,`Invalid input mean`),n(e[4].dims,r,`Invalid input var`)}else n(e[1].dims,[1],`Invalid input scale`),n(e[2].dims,[1],`Invalid input B`),n(e[3].dims,[1],`Invalid input mean`),n(e[4].dims,[1],`Invalid input var`)},Oi=(e,t)=>{let{epsilon:n,spatial:r,format:i}=t,a=e[0].dims,o=r?er(a[a.length-1]):1,s=i===`NHWC`&&a.length>1?o:1,c=W.size(a)/o,l=r,u=l?a.length:a,d=J(`x`,e[0].dataType,e[0].dims,o),f=J(`scale`,e[1].dataType,e[1].dims,s),p=J(`bias`,e[2].dataType,e[2].dims,s),m=J(`inputMean`,e[3].dataType,e[3].dims,s),h=J(`inputVar`,e[4].dataType,e[4].dims,s),g=Y(`y`,e[0].dataType,u,o),_=()=>{let e=``;if(r)e=`let cOffset = ${a.length===1?`0u`:i===`NHWC`?`outputIndices[${a.length-1}] / ${o}`:`outputIndices[1]`};`;else if(i===`NCHW`)e=`
397
+ ${g.indicesSet(`outputIndices`,`0`,`0`)}
398
+ let cOffset = ${g.indicesToOffset(`outputIndices`)};`;else{e=`var cIndices = ${f.type.indices}(0);
399
+ cIndices[0] = outputIndices[${a.length-1}];`;for(let t=1;t<f.rank;t++)e+=`cIndices[${t}] = outputIndices[${t}];`;e+=`let cOffset = ${f.indicesToOffset(`cIndices`)};`}return e};return{name:`BatchNormalization`,shaderCache:{hint:`${t.epsilon}_${t.format}_${r}_${o}`,inputDependencies:l?[`rank`,`type`,`type`,`type`,`type`]:void 0},getShaderSource:e=>`
400
+ const epsilon = ${n};
401
+ ${e.registerUniform(`outputSize`,`u32`).declareVariables(d,f,p,m,h,g)}
402
+ ${e.mainStart()}
403
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.outputSize`)}
404
+ var outputIndices = ${g.offsetToIndices(`global_idx * ${o}`)};
405
+ ${_()}
406
+ let scale = ${f.getByOffset(`cOffset`)};
407
+ let bias = ${p.getByOffset(`cOffset`)};
408
+ let inputMean = ${m.getByOffset(`cOffset`)};
409
+ let inputVar = ${h.getByOffset(`cOffset`)};
410
+ let x = ${d.getByOffset(`global_idx`)};
411
+ let value = (x - inputMean) * inverseSqrt(inputVar + epsilon) * scale + bias;
412
+ ${g.setByOffset(`global_idx`,`value`)}
413
+ }`,getRunData:()=>({outputs:[{dims:e[0].dims,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(c/64)},programUniforms:l?[{type:12,data:c},...K(a)]:[{type:12,data:c}]})}},ki=e=>Jn(e),Ai=(e,t)=>{let{inputs:n,outputCount:r}=e,i=ki({...t,outputCount:r});if(I.webgpu.validateInputContent&&Di(n,i),t.trainingMode)throw Error(`BatchNormalization trainingMode is not supported yet.`);e.compute(Oi(n,i))}}),Mi,Ni,Pi,Fi=M(()=>{G(),X(),Mi=e=>{if(e[0].dims.length!==3)throw Error(`input should have 3 dimensions`);if(![320,640,1280].includes(e[0].dims[2]))throw Error(`number of channels should be 320, 640 or 1280`);if(e[1].dims.length!==1)throw Error(`bias is expected to have 1 dimensions`);if(e[0].dims[2]!==e[1].dims[0])throw Error(`last dimension of input and bias are not the same`)},Ni=e=>{let t=e[0].dims,n=e[0].dims[2],r=W.size(t)/4,i=e[0].dataType,a=J(`input`,i,t,4),o=J(`bias`,i,[n],4),s=J(`residual`,i,t,4),c=Y(`output`,i,t,4);return{name:`BiasAdd`,getRunData:()=>({outputs:[{dims:t,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(r/64)}}),getShaderSource:e=>`
414
+ const channels = ${n}u / 4;
415
+ ${e.declareVariables(a,o,s,c)}
416
+
417
+ ${e.mainStart()}
418
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(r)}
419
+ let value = ${a.getByOffset(`global_idx`)}
420
+ + ${o.getByOffset(`global_idx % channels`)} + ${s.getByOffset(`global_idx`)};
421
+ ${c.setByOffset(`global_idx`,`value`)}
422
+ }`}},Pi=e=>{Mi(e.inputs),e.compute(Ni(e.inputs))}}),Ii,Li,Ri,zi,Bi,Vi,Hi,Ui,Wi,Gi,Ki,qi,Ji,Yi,Xi,Zi,Qi,$i,ea,ta,na,ra,ia,aa,oa,sa,ca,la,ua,da,fa,pa,ma,ha,ga,_a,va,ya,ba,xa,Sa,Ca,wa,Ta,Ea,Da=M(()=>{H(),G(),Yn(),X(),Ii=(e,t,n,r,i,a,o)=>{let s=Math.ceil(t/4),c=``;c=typeof i==`string`?`${i}(a)`:i(`a`);let l=J(`inputData`,n,[s],4),u=Y(`outputData`,r,[s],4),d=[{name:`vec_size`,type:`u32`}];return o&&d.push(...o),`
423
+ ${e.registerUniforms(d).declareVariables(l,u)}
424
+
425
+ ${a??``}
426
+
427
+ ${e.mainStart()}
428
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.vec_size`)}
429
+
430
+ let a = ${l.getByOffset(`global_idx`)};
431
+ ${u.setByOffset(`global_idx`,c)}
432
+ }`},Li=(e,t,n,r,i,a=e.dataType,o,s)=>{let c=[{type:12,data:Math.ceil(W.size(e.dims)/4)}];return o&&c.push(...o),{name:t,shaderCache:{hint:i,inputDependencies:[`type`]},getShaderSource:t=>Ii(t,W.size(e.dims),e.dataType,a,n,r,s),getRunData:t=>({outputs:[{dims:e.dims,dataType:a}],dispatchGroup:{x:Math.ceil(W.size(t[0].dims)/64/4)},programUniforms:c})}},Ri=e=>{e.compute(Li(e.inputs[0],`Abs`,`abs`))},zi=e=>{e.compute(Li(e.inputs[0],`Acos`,`acos`))},Bi=e=>{e.compute(Li(e.inputs[0],`Acosh`,`acosh`))},Vi=e=>{e.compute(Li(e.inputs[0],`Asin`,`asin`))},Hi=e=>{e.compute(Li(e.inputs[0],`Asinh`,`asinh`))},Ui=e=>{e.compute(Li(e.inputs[0],`Atan`,`atan`))},Wi=e=>{e.compute(Li(e.inputs[0],`Atanh`,`atanh`))},Gi=e=>Jn(e),Ki=(e,t)=>{let n;switch(t.to){case 10:n=`vec4<f16>`;break;case 1:n=`vec4<f32>`;break;case 12:n=`vec4<u32>`;break;case 6:n=`vec4<i32>`;break;case 9:n=`vec4<bool>`;break;default:throw RangeError(`not supported type (specified in attribute 'to' from 'Cast' operator): ${t.to}`)}e.compute(Li(e.inputs[0],`Cast`,n,void 0,t.cacheKey,t.to))},qi=e=>{let t,n,r=e.length>=2&&e[1].data!==0,i=e.length>=3&&e[2].data!==0;switch(e[0].dataType){case 1:t=r?e[1].getFloat32Array()[0]:-34028234663852886e22,n=i?e[2].getFloat32Array()[0]:34028234663852886e22;break;case 10:t=r?e[1].getUint16Array()[0]:64511,n=i?e[2].getUint16Array()[0]:31743;break;default:throw Error(`Unsupport data type`)}return Jn({min:t,max:n})},Ji=(e,t)=>{let n=t||qi(e.inputs),r=$n(e.inputs[0].dataType);e.compute(Li(e.inputs[0],`Clip`,e=>`clamp(${e}, vec4<${r}>(uniforms.min), vec4<${r}>(uniforms.max))`,void 0,n.cacheKey,void 0,[{type:e.inputs[0].dataType,data:n.min},{type:e.inputs[0].dataType,data:n.max}],[{name:`min`,type:r},{name:`max`,type:r}]),{inputs:[0]})},Yi=e=>{e.compute(Li(e.inputs[0],`Ceil`,`ceil`))},Xi=e=>{e.compute(Li(e.inputs[0],`Cos`,`cos`))},Zi=e=>{e.compute(Li(e.inputs[0],`Cosh`,`cosh`))},Qi=e=>Jn(e),$i=(e,t)=>{let n=$n(e.inputs[0].dataType);e.compute(Li(e.inputs[0],`Elu`,e=>`elu_vf32(${e})`,`
433
+ const elu_alpha_ = ${n}(${t.alpha});
434
+
435
+ fn elu_f32(a: ${n}) -> ${n} {
436
+ return select((exp(a) - 1.0) * elu_alpha_, a, a >= 0.0);
437
+ }
438
+
439
+ fn elu_vf32(v: vec4<${n}>) -> vec4<${n}> {
440
+ return vec4(elu_f32(v.x), elu_f32(v.y), elu_f32(v.z), elu_f32(v.w));
441
+ }`,t.cacheKey))},ea=(e=`f32`)=>`
442
+ const r0: ${e} = 0.3275911;
443
+ const r1: ${e} = 0.254829592;
444
+ const r2: ${e} = -0.284496736;
445
+ const r3: ${e} = 1.421413741;
446
+ const r4: ${e} = -1.453152027;
447
+ const r5: ${e} = 1.061405429;
448
+
449
+ fn erf_vf32(v: vec4<${e}>) -> vec4<${e}> {
450
+ let absv = abs(v);
451
+ let x = 1.0 / (1.0 + r0 * absv);
452
+ return sign(v) * (1.0 - ((((r5 * x + r4) * x + r3) * x + r2) * x + r1) * x * exp(-absv * absv));
453
+ }`,ta=e=>{let t=$n(e.inputs[0].dataType);e.compute(Li(e.inputs[0],`Erf`,e=>`erf_vf32(${e})`,ea(t)))},na=e=>{e.compute(Li(e.inputs[0],`Exp`,`exp`))},ra=e=>{e.compute(Li(e.inputs[0],`Floor`,`floor`))},ia=e=>{let t=$n(e.inputs[0].dataType);e.compute(Li(e.inputs[0],`Gelu`,e=>`0.5 * ${e} * (1.0 + erf_vf32(${e} * 0.7071067811865475))`,ea(t)))},aa=(e,t)=>{let n=$n(e.inputs[0].dataType);e.compute(Li(e.inputs[0],`LeakyRelu`,e=>`select(leaky_relu_alpha_ * ${e}, ${e}, ${e} >= vec4<${n}>(0.0))`,`const leaky_relu_alpha_ = ${n}(${t.alpha});`,t.cacheKey))},oa=e=>{e.compute(Li(e.inputs[0],`Not`,e=>`!${e}`))},sa=e=>{e.compute(Li(e.inputs[0],`Neg`,e=>`-${e}`))},ca=e=>{e.compute(Li(e.inputs[0],`Reciprocal`,e=>`1.0/${e}`))},la=e=>{let t=$n(e.inputs[0].dataType);e.compute(Li(e.inputs[0],`Relu`,e=>`select(vec4<${t}>(0.0), ${e}, ${e} > vec4<${t}>(0.0))`))},ua=e=>{e.compute(Li(e.inputs[0],`Sigmoid`,e=>`(1.0 / (1.0 + exp(-${e})))`))},da=e=>Jn(e),fa=(e,t)=>{let n=$n(e.inputs[0].dataType);e.compute(Li(e.inputs[0],`HardSigmoid`,e=>`max(vec4<${n}>(0.0), min(vec4<${n}>(1.0), ${t.alpha} * ${e} + vec4<${n}>(${t.beta})))`,void 0,t.cacheKey))},pa=e=>{e.compute(Li(e.inputs[0],`Sin`,`sin`))},ma=e=>{e.compute(Li(e.inputs[0],`Sinh`,`sinh`))},ha=e=>{e.compute(Li(e.inputs[0],`Sqrt`,`sqrt`))},ga=e=>{e.compute(Li(e.inputs[0],`Tan`,`tan`))},_a=e=>`sign(${e}) * (1 - exp(-2 * abs(${e}))) / (1 + exp(-2 * abs(${e})))`,va=e=>{e.compute(Li(e.inputs[0],`Tanh`,_a))},ya=(e=`f32`)=>`
454
+ const fast_gelu_a: ${e} = 0.5;
455
+ const fast_gelu_b: ${e} = 0.7978845608028654;
456
+ const fast_gelu_c: ${e} = 0.035677408136300125;
457
+
458
+ fn tanh_v(v: vec4<${e}>) -> vec4<${e}> {
459
+ return ${_a(`v`)};
460
+ }
461
+ `,ba=e=>`(fast_gelu_a + fast_gelu_a * tanh_v(${e} * (fast_gelu_c * ${e} * ${e} + fast_gelu_b))) * ${e}`,xa=e=>{let t=$n(e.inputs[0].dataType);e.compute(Li(e.inputs[0],`FastGelu`,ba,ya(t),void 0,e.inputs[0].dataType))},Sa=(e,t)=>{let n=$n(e.inputs[0].dataType);return e.compute(Li(e.inputs[0],`ThresholdedRelu`,e=>`select(vec4<${n}>(0.0), ${e}, ${e} > thresholded_relu_alpha_)`,`const thresholded_relu_alpha_ = vec4<${n}>(${t.alpha});`,t.cacheKey)),0},Ca=e=>{e.compute(Li(e.inputs[0],`Log`,`log`))},wa=(e,t)=>`
462
+ const alpha = vec4<${e}>(${t});
463
+ const one = ${e}(1.0);
464
+ const zero = ${e}(0.0);
465
+
466
+ fn quick_gelu_impl(x: vec4<${e}>) -> vec4<${e}> {
467
+ let v = x *alpha;
468
+ var x1 : vec4<${e}>;
469
+ for (var i = 0; i < 4; i = i + 1) {
470
+ if (v[i] >= zero) {
471
+ x1[i] = one / (one + exp(-v[i]));
472
+ } else {
473
+ x1[i] = one - one / (one + exp(v[i]));
474
+ }
475
+ }
476
+ return x * x1;
477
+ }
478
+ `,Ta=e=>`quick_gelu_impl(${e})`,Ea=(e,t)=>{let n=$n(e.inputs[0].dataType);e.compute(Li(e.inputs[0],`QuickGelu`,Ta,wa(n,t.alpha),t.cacheKey,e.inputs[0].dataType))}}),Oa,ka,Aa,ja=M(()=>{G(),X(),Da(),Oa=e=>{if(e[0].dims.length!==3)throw Error(`input should have 3 dimensions`);if(![2560,5120,10240].includes(e[0].dims[2]))throw Error(`hidden state should be 2560, 5120 or 10240`);if(e[1].dims.length!==1)throw Error(`bias is expected to have 1 dimensions`);if(e[0].dims[2]!==e[1].dims[0])throw Error(`last dimension of input and bias are not the same`)},ka=e=>{let t=e[0].dims.slice();t[2]/=2;let n=J(`input`,e[0].dataType,e[0].dims,4),r=J(`bias`,e[0].dataType,[e[0].dims[2]],4),i=Y(`output`,e[0].dataType,t,4),a=W.size(t)/4,o=Qn(e[0].dataType);return{name:`BiasSplitGelu`,getRunData:()=>({outputs:[{dims:t,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(a/64)}}),getShaderSource:t=>`
479
+ const M_SQRT2 = sqrt(2.0);
480
+ const halfChannels = ${e[0].dims[2]/4/2}u;
481
+
482
+ ${t.declareVariables(n,r,i)}
483
+
484
+ ${ea(o)}
485
+
486
+ ${t.mainStart()}
487
+ ${t.guardAgainstOutOfBoundsWorkgroupSizes(a)}
488
+ let biasIdx = global_idx % halfChannels;
489
+ let batchIndex = global_idx / halfChannels;
490
+ let inputOffset = biasIdx + batchIndex * halfChannels * 2;
491
+ let valueLeft = input[inputOffset] + bias[biasIdx];
492
+ let valueRight = input[inputOffset + halfChannels] + bias[biasIdx + halfChannels];
493
+ let geluRight = valueRight * 0.5 * (erf_vf32(valueRight / M_SQRT2) + 1);
494
+
495
+ ${i.setByOffset(`global_idx`,`valueLeft * geluRight`)}
496
+ }`}},Aa=e=>{Oa(e.inputs),e.compute(ka(e.inputs))}}),Ma,Na,Pa,Fa,Ia,La,Ra,za,Ba,Va,Ha,Ua,Wa,Ga=M(()=>{H(),G(),X(),Ma=(e,t,n,r,i,a,o,s,c,l,u,d)=>{let f,p;typeof s==`string`?f=p=(e,t)=>`${s}((${e}),(${t}))`:typeof s==`function`?f=p=s:(f=s.scalar,p=s.vector);let m=Y(`outputData`,u,r.length,4),h=J(`aData`,c,t.length,4),g=J(`bData`,l,n.length,4),_;if(i)if(a){let e=W.size(t)===1,r=W.size(n)===1,i=t.length>0&&t[t.length-1]%4==0,a=n.length>0&&n[n.length-1]%4==0;_=e||r?m.setByOffset(`global_idx`,p(e?`${h.type.value}(${h.getByOffset(`0`)}.x)`:h.getByOffset(`global_idx`),r?`${g.type.value}(${g.getByOffset(`0`)}.x)`:g.getByOffset(`global_idx`))):`
497
+ let outputIndices = ${m.offsetToIndices(`global_idx * 4u`)};
498
+ let offsetA = ${h.broadcastedIndicesToOffset(`outputIndices`,m)};
499
+ let offsetB = ${g.broadcastedIndicesToOffset(`outputIndices`,m)};
500
+ ${m.setByOffset(`global_idx`,p(o||i?h.getByOffset(`offsetA / 4u`):`${h.type.value}(${h.getByOffset(`offsetA / 4u`)}[offsetA % 4u])`,o||a?g.getByOffset(`offsetB / 4u`):`${g.type.value}(${g.getByOffset(`offsetB / 4u`)}[offsetB % 4u])`))}
501
+ `}else _=m.setByOffset(`global_idx`,p(h.getByOffset(`global_idx`),g.getByOffset(`global_idx`)));else{if(!a)throw Error(`no necessary to use scalar implementation for element-wise binary op implementation.`);let e=(e,t,n=``)=>{let r=`aData[indexA${t}][componentA${t}]`,i=`bData[indexB${t}][componentB${t}]`;return`
502
+ let outputIndices${t} = ${m.offsetToIndices(`global_idx * 4u + ${t}u`)};
503
+ let offsetA${t} = ${h.broadcastedIndicesToOffset(`outputIndices${t}`,m)};
504
+ let offsetB${t} = ${g.broadcastedIndicesToOffset(`outputIndices${t}`,m)};
505
+ let indexA${t} = offsetA${t} / 4u;
506
+ let indexB${t} = offsetB${t} / 4u;
507
+ let componentA${t} = offsetA${t} % 4u;
508
+ let componentB${t} = offsetB${t} % 4u;
509
+ ${e}[${t}] = ${n}(${f(r,i)});
510
+ `};_=u===9?`
511
+ var data = vec4<u32>(0);
512
+ ${e(`data`,0,`u32`)}
513
+ ${e(`data`,1,`u32`)}
514
+ ${e(`data`,2,`u32`)}
515
+ ${e(`data`,3,`u32`)}
516
+ outputData[global_idx] = dot(vec4<u32>(0x1, 0x100, 0x10000, 0x1000000), vec4<u32>(data));`:`
517
+ ${e(`outputData[global_idx]`,0)}
518
+ ${e(`outputData[global_idx]`,1)}
519
+ ${e(`outputData[global_idx]`,2)}
520
+ ${e(`outputData[global_idx]`,3)}
521
+ `}return`
522
+ ${e.registerUniform(`vec_size`,`u32`).declareVariables(h,g,m)}
523
+
524
+ ${d??``}
525
+
526
+ ${e.mainStart()}
527
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.vec_size`)}
528
+ ${_}
529
+ }`},Na=(e,t,n,r,i,a,o=n.dataType)=>{let s=n.dims.map(e=>Number(e)??1),c=r.dims.map(e=>Number(e)??1),l=!W.areEqual(s,c),u=s,d=W.size(s),f=!1,p=!1,m=[l];if(l){let e=mn.calcShape(s,c,!1);if(!e)throw Error(`Can't perform binary op on the given tensors`);u=e.slice(),d=W.size(u);let t=W.size(s)===1,n=W.size(c)===1,r=s.length>0&&s[s.length-1]%4==0,i=c.length>0&&c[c.length-1]%4==0;m.push(t),m.push(n),m.push(r),m.push(i);let a=1;for(let e=1;e<u.length;e++){let t=s[s.length-e];if(t===c[c.length-e])a*=t;else break}a%4==0?(p=!0,f=!0):(t||n||r||i)&&(f=!0)}else f=!0;return m.push(f),{name:e,shaderCache:{hint:t+m.map(e=>e.toString()).join(`_`),inputDependencies:[`rank`,`rank`]},getShaderSource:e=>Ma(e,s,c,u,f,l,p,i,n.dataType,r.dataType,o,a),getRunData:()=>({outputs:[{dims:u,dataType:o}],dispatchGroup:{x:Math.ceil(d/64/4)},programUniforms:[{type:12,data:Math.ceil(W.size(u)/4)},...K(s,c,u)]})}},Pa=(e,t,n,r,i,a)=>{e.compute(Na(t,i??``,e.inputs[0],e.inputs[1],n,r,a))},Fa=e=>{Pa(e,`Add`,(e,t)=>`${e}+${t}`)},Ia=e=>{Pa(e,`Div`,(e,t)=>`${e}/${t}`)},La=e=>{Pa(e,`Equal`,{scalar:(e,t)=>`u32(${e}==${t})`,vector:(e,t)=>`vec4<u32>(${e}==${t})`},void 0,void 0,9)},Ra=e=>{Pa(e,`Mul`,(e,t)=>`${e}*${t}`)},za=e=>{let t=J(`input`,e.inputs[0].dataType,e.inputs[0].dims).type.value;Pa(e,`Pow`,{scalar:(e,t)=>`pow_custom(${e},${t})`,vector:(e,t)=>`pow_vector_custom(${e},${t})`},`
530
+ fn pow_custom(a : ${t}, b : ${t}) -> ${t} {
531
+ if (b == ${t}(0.0)) {
532
+ return ${t}(1.0);
533
+ } else if (a < ${t}(0.0) && f32(b) != floor(f32(b))) {
534
+ return ${t}(pow(f32(a), f32(b))); // NaN
535
+ }
536
+ return select(sign(a), ${t}(1.0), round(f32(abs(b) % ${t}(2.0))) != 1.0) * ${t}(${t===`i32`?`round`:``}(pow(f32(abs(a)), f32(b))));
537
+ }
538
+ fn pow_vector_custom(a : vec4<${t}>, b : vec4<${t}>) -> vec4<${t}> {
539
+ // TODO: implement vectorized pow
540
+ return vec4<${t}>(pow_custom(a.x, b.x), pow_custom(a.y, b.y), pow_custom(a.z, b.z), pow_custom(a.w, b.w));
541
+ }
542
+ `)},Ba=e=>{Pa(e,`Sub`,(e,t)=>`${e}-${t}`)},Va=e=>{Pa(e,`Greater`,{scalar:(e,t)=>`u32(${e}>${t})`,vector:(e,t)=>`vec4<u32>(${e}>${t})`},void 0,void 0,9)},Ha=e=>{Pa(e,`Less`,{scalar:(e,t)=>`u32(${e}<${t})`,vector:(e,t)=>`vec4<u32>(${e}<${t})`},void 0,void 0,9)},Ua=e=>{Pa(e,`GreaterOrEqual`,{scalar:(e,t)=>`u32(${e}>=${t})`,vector:(e,t)=>`vec4<u32>(${e}>=${t})`},void 0,void 0,9)},Wa=e=>{Pa(e,`LessOrEqual`,{scalar:(e,t)=>`u32(${e}<=${t})`,vector:(e,t)=>`vec4<u32>(${e}<=${t})`},void 0,void 0,9)}}),Ka,qa,Ja,Ya,Xa,Za,Qa=M(()=>{H(),G(),Yn(),X(),Ka=(e,t)=>{if(!e||e.length<1)throw Error(`too few inputs`);let n=e[0],r=n.dataType,i=n.dims.length;e.forEach((e,a)=>{if(a!==0){if(e.dataType!==r)throw Error(`input tensors should be one type`);if(e.dims.length!==i)throw Error(`input tensors should have the same shape`);e.dims.forEach((e,r)=>{if(r!==t&&e!==n.dims[r])throw Error(`non concat dimensions must match`)})}})},qa=(e,t)=>`
543
+ fn calculateInputIndex(index: u32) -> u32 {
544
+ let sizeInConcatAxis = array<u32, ${e}u>(${t});
545
+ for (var i: u32 = 0u; i < ${e}; i += 1u ) {
546
+ if (index < sizeInConcatAxis[i]) {
547
+ return i;
548
+ }
549
+ }
550
+ return ${e}u;
551
+ }`,Ja=(e,t)=>{let n=e.length,r=[];for(let i=0;i<n;++i){let a=t.setByOffset(`global_idx`,e[i].getByIndices(`indices`));n===1?r.push(a):i===0?r.push(`if (inputIndex == ${i}u) { ${a} }`):i===n-1?r.push(`else { ${a} }`):r.push(`else if (inputIndex == ${i}) { ${a} }`)}return r.join(`
552
+ `)},Ya=(e,t,n,r)=>{let i=W.size(n),a=Array(e.length),o=Array(e.length),s=0,c=[],l=[],u=[{type:12,data:i}];for(let n=0;n<e.length;++n)s+=e[n].dims[t],a[n]=s,l.push(e[n].dims.length),o[n]=J(`input${n}`,r,l[n]),c.push(`rank`),u.push({type:12,data:a[n]});for(let t=0;t<e.length;++t)u.push(...K(e[t].dims));u.push(...K(n));let d=Y(`output`,r,n.length),f=d.indicesGet(`indices`,t),p=Array.from(Array(a.length).keys()).map(e=>`uniforms.sizeInConcatAxis${e}`).join(`,`);return{name:`Concat`,shaderCache:{hint:`${t}`,inputDependencies:c},getRunData:()=>({outputs:[{dims:n,dataType:r}],dispatchGroup:{x:Math.ceil(i/64)},programUniforms:u}),getShaderSource:t=>`
553
+
554
+ ${(()=>{t.registerUniform(`outputSize`,`u32`);for(let n=0;n<e.length;n++)t.registerUniform(`sizeInConcatAxis${n}`,`u32`);return t.declareVariables(...o,d)})()}
555
+
556
+ ${qa(a.length,p)}
557
+
558
+ ${t.mainStart()}
559
+ ${t.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.outputSize`)}
560
+
561
+ var indices = ${d.offsetToIndices(`global_idx`)};
562
+
563
+ let inputIndex = calculateInputIndex(${f});
564
+ if (inputIndex != 0u) {
565
+ let sizeInConcatAxis = array<u32, ${a.length}u>(${p});
566
+ ${f} -= sizeInConcatAxis[inputIndex - 1u];
567
+ }
568
+
569
+ ${Ja(o,d)}
570
+ }`}},Xa=(e,t)=>{let n=e.inputs,r=n[0].dims,i=W.normalizeAxis(t.axis,r.length);Ka(n,i);let a=r.slice();a[i]=n.reduce((e,t)=>e+(t.dims.length>i?t.dims[i]:0),0);let o=n.filter(e=>W.size(e.dims)>0);e.compute(Ya(o,i,a,n[0].dataType),{inputs:o})},Za=e=>Jn({axis:e.axis})}),$a,eo,to,no,ro=M(()=>{H(),G(),$a=(e,t,n=`f32`)=>{switch(e.activation){case`Relu`:return`value = max(value, ${t}(0.0));`;case`Sigmoid`:return`value = (${t}(1.0) / (${t}(1.0) + exp(-value)));`;case`Clip`:return`value = clamp(value, ${t}(${n}(uniforms.clip_min)), ${t}(${n}(uniforms.clip_max)));`;case`HardSigmoid`:return`value = max(${t}(0.0), min(${t}(1.0), ${n}(uniforms.alpha) * value + ${n}(uniforms.beta)));`;case`LeakyRelu`:return`value = select(${n}(uniforms.alpha) * value, value, value >= ${t}(0.0));`;case`Tanh`:return`let e2x = exp(-2.0 * abs(value));
571
+ value = sign(value) * (1.0 - e2x) / (1.0 + e2x);
572
+ `;case``:return``;default:throw Error(`Unsupported activation ${e.activation}`)}},eo=(e,t)=>{e.activation===`Clip`?t.push({type:1,data:e.clipMax},{type:1,data:e.clipMin}):e.activation===`HardSigmoid`?t.push({type:1,data:e.alpha},{type:1,data:e.beta}):e.activation===`LeakyRelu`&&t.push({type:1,data:e.alpha})},to=(e,t)=>{e.activation===`Clip`?t.push({name:`clip_max`,type:`f32`},{name:`clip_min`,type:`f32`}):e.activation===`HardSigmoid`?t.push({name:`alpha`,type:`f32`},{name:`beta`,type:`f32`}):e.activation===`LeakyRelu`&&t.push({name:`alpha`,type:`f32`})},no=e=>{let t=e?.activation||``;if(t===`HardSigmoid`){let[n,r]=e?.activation_params||[.2,.5];return{activation:t,alpha:n,beta:r}}else if(t===`Clip`){let[n,r]=e?.activation_params||[_n,vn];return{activation:t,clipMax:r,clipMin:n}}else if(t===`LeakyRelu`){let[n]=e?.activation_params||[.01];return{activation:t,alpha:n}}return{activation:t}}}),io,ao,oo=M(()=>{io=(e,t)=>{switch(e){case 1:return t;case 2:return`vec2<${t}>`;case 3:return`vec3<${t}>`;case 4:return`vec4<${t}>`;default:throw Error(`${e}-component is not supported.`)}},ao=e=>`
573
+ ${e?`value = value + getBiasByOutputCoords(coords);`:``}
574
+ `}),so,co=M(()=>{so=e=>`
575
+ fn getIndexFromCoords4D(coords : vec4<i32>, shape : vec4<i32>) -> i32 {
576
+ return dot(coords, vec4<i32>(
577
+ shape.y * shape.z * shape.w, shape.z * shape.w, shape.w, 1));
578
+ }
579
+ fn getOutputIndexFromCoords(coords : vec4<i32>) -> i32 {
580
+ return dot(coords, vec4<i32>(
581
+ i32(${e}.x), i32(${e}.y), i32(${e}.z), 1));
582
+ }
583
+ `}),lo,uo,fo=M(()=>{H(),G(),X(),ro(),lo=(e,t,n,r,i)=>{let a=r-n;return`
584
+ ${Array.from({length:n}).map((n,o)=>`
585
+ if (${q(t.shape,o,t.rank)} != 1) {
586
+ ${t.indicesSet(e,o,q(i,o+a,r))}
587
+ } else {
588
+ ${t.indicesSet(e,o,0)}
589
+ }`).join(``)}
590
+ `},uo=(e,t,n,r,i=!1,a)=>{let o=e[0].dims,s=e[1].dims,c=o[o.length-2],l=s[s.length-1],u=o[o.length-1],d=er(l),f=er(u),p=er(c),m=W.size(n)/d/p,h=e.length>2,g=r?r.slice(0,-2):n.slice(0,-2),_=[W.size(g),c,l],v=[{type:12,data:m},{type:12,data:c},{type:12,data:l},{type:12,data:u}];return eo(t,v),v.push(...K(g,o,s)),h&&v.push(...K(e[2].dims)),v.push(...K(_)),{name:`MatMulNaive`,shaderCache:{hint:`${t.activation};${d};${f};${p};${i}`,inputDependencies:h?[`rank`,`rank`,`rank`]:[`rank`,`rank`]},getRunData:()=>({outputs:[{dims:a?a(n):n,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(m/64)},programUniforms:v}),getShaderSource:r=>{let a=or(`batch_dims`,e[0].dataType,g.length),c=J(`a`,e[0].dataType,o.length,f),l=J(`b`,e[1].dataType,s.length,d),u=Y(`output`,e[0].dataType,_.length,d),m=Qn(u.type.tensor),v=$a(t,u.type.value,m),y=[c,l],b=``;if(h){let t=i?d:1;y.push(J(`bias`,e[2].dataType,e[2].dims.length,t)),b=`${i?`value += bias[col / ${t}];`:`value += ${u.type.value}(bias[row + i]);`}`}let x=[{name:`output_size`,type:`u32`},{name:`M`,type:`u32`},{name:`N`,type:`u32`},{name:`K`,type:`u32`}];to(t,x);let S=()=>{let e=`var a_data: ${c.type.value};`;for(let t=0;t<f;t++)e+=`
591
+ let b_data${t} = b[(b_offset + (k + ${t}) * uniforms.N + col) / ${d}];`;for(let t=0;t<p;t++){e+=`a_data = a[(a_offset + (row + ${t}) * uniforms.K + k) / ${f}];`;for(let n=0;n<f;n++)e+=`
592
+ values[${t}] = fma(${l.type.value}(a_data${f===1?``:`[${n}]`}), b_data${n}, values[${t}]);
593
+ `}return e};return`
594
+ ${r.registerUniforms(x).registerInternalVariables(a).declareVariables(...y,u)}
595
+ ${r.mainStart()}
596
+ ${r.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)}
597
+ let col = (global_idx % (uniforms.N / ${d})) * ${d};
598
+ var index1 = global_idx / (uniforms.N / ${d});
599
+ let stride1 = uniforms.M / ${p};
600
+ let row = (index1 % stride1) * ${p};
601
+ let batch = index1 / stride1;
602
+
603
+ ${n.length===2?``:`let batch_indices = ${a.offsetToIndices(`batch`)};`}
604
+
605
+ var a_indices: ${c.type.indices};
606
+ ${lo(`a_indices`,c,c.rank-2,a.rank,`batch_indices`)}
607
+ ${c.indicesSet(`a_indices`,c.rank-2,0)}
608
+ ${c.indicesSet(`a_indices`,c.rank-1,0)}
609
+ let a_offset = ${c.indicesToOffset(`a_indices`)};
610
+
611
+ var b_indices: ${l.type.indices};
612
+ ${lo(`b_indices`,l,l.rank-2,a.rank,`batch_indices`)}
613
+ ${l.indicesSet(`b_indices`,l.rank-2,0)}
614
+ ${l.indicesSet(`b_indices`,l.rank-1,0)}
615
+ let b_offset = ${l.indicesToOffset(`b_indices`)};
616
+ var values: array<${u.type.value}, ${p}>;
617
+ for (var k: u32 = 0u; k < uniforms.K; k = k + ${f}) {
618
+ ${S()}
619
+ }
620
+ for (var i = 0u; i < ${p}u; i++) {
621
+ var value = values[i];
622
+ ${b}
623
+ ${v}
624
+ let cur_indices = ${u.type.indices}(batch, row + i, col);
625
+ let offset = ${u.indicesToOffset(`cur_indices`)};
626
+ ${u.setByOffset(`offset / ${d}`,`value`)};
627
+ }
628
+ }
629
+ `}}}}),po,mo,ho,go,_o,vo,yo,bo,xo=M(()=>{H(),G(),X(),ro(),fo(),oo(),po=(e,t)=>e?`
630
+ mm_Asub[inputRow][inputCol] = mm_readA(batch,
631
+ kStart + inputRow,
632
+ globalRowStart / innerElementSize + inputCol${t?`, batchIndices`:``});
633
+ `:`
634
+ mm_Asub[inputRow][inputCol] = mm_readA(batch,
635
+ globalRow + innerRow,
636
+ kStart / innerElementSize + inputCol${t?`, batchIndices`:``});
637
+ `,mo=(e,t)=>e?`
638
+ let ACached0 = mm_Asub[k * innerElementSize][localRow];
639
+ let ACached1 = mm_Asub[k * innerElementSize + 1][localRow];
640
+ let ACached2 = mm_Asub[k * innerElementSize + 2][localRow];
641
+ ${t===3?``:`let ACached3 = mm_Asub[k * innerElementSize + 3][localRow];`}
642
+ for (var i = 0; i < rowPerThread; i = i + 1) {
643
+ acc[i] = BCached0 * ACached0[i] + acc[i];
644
+ acc[i] = BCached1 * ACached1[i] + acc[i];
645
+ acc[i] = BCached2 * ACached2[i] + acc[i];
646
+ ${t===3?``:`acc[i] = BCached3 * ACached3[i] + acc[i];`}
647
+ }`:`
648
+ for (var i = 0; i < rowPerThread; i = i + 1) {
649
+ let ACached = mm_Asub[tileRow + i][k];
650
+ acc[i] = BCached0 * ACached.x + acc[i];
651
+ acc[i] = BCached1 * ACached.y + acc[i];
652
+ acc[i] = BCached2 * ACached.z + acc[i];
653
+ ${t===3?``:`acc[i] = BCached3 * ACached.w + acc[i];`}
654
+ }`,ho=(e,t,n=`f32`,r,i=!1,a=32,o=!1,s=32)=>{let c=t[1]*e[1],l=t[0]*e[0],u=i?c:a,d=i?a:c,f=u/t[0],p=a/t[1];if(!((i&&f===4&&e[1]===4||!i&&(f===3||f===4))&&u%t[0]===0&&a%t[1]===0&&e[0]===4))throw Error(`If transposeA ${i} is true, innerElementSize ${f} and workPerThread[1] ${e[1]} must be 4.
655
+ Otherwise, innerElementSize ${f} must be 3 or 4.
656
+ tileAWidth ${u} must be divisible by workgroupSize[0]${t[0]}. tileInner ${a} must be divisible by workgroupSize[1] ${t[1]}. colPerThread ${e[0]} must be 4.`);return`
657
+ var<workgroup> mm_Asub: array<array<vec${f}<${n}>, ${u/f}>, ${d}>;
658
+ var<workgroup> mm_Bsub: array<array<vec4<${n}>, ${l/e[0]}>, ${a}>;
659
+
660
+ const rowPerThread = ${e[1]};
661
+ const colPerThread = ${e[0]};
662
+ const innerElementSize = ${f};
663
+ const tileInner = ${a};
664
+
665
+ @compute @workgroup_size(${t[0]}, ${t[1]}, ${t[2]})
666
+ fn main(@builtin(local_invocation_id) localId : vec3<u32>,
667
+ @builtin(global_invocation_id) globalId : vec3<u32>,
668
+ @builtin(workgroup_id) workgroupId : vec3<u32>) {
669
+ let localRow = i32(localId.y);
670
+ let tileRow = localRow * rowPerThread;
671
+ let tileCol = i32(localId.x);
672
+
673
+ let globalRow =i32(globalId.y) * rowPerThread;
674
+ let globalCol = i32(globalId.x);
675
+ let batch = ${o?`0`:`i32(globalId.z)`};
676
+ ${r?`let batchIndices = ${r.offsetToIndices(`u32(batch)`)};`:``}
677
+ let globalRowStart = i32(workgroupId.y) * ${c};
678
+
679
+ let num_tiles = ${o?`${Math.ceil(s/a)}`:`(uniforms.dim_inner - 1) / tileInner + 1`};
680
+ var kStart = ${o?`i32(globalId.z) * ${s}`:`0`};
681
+
682
+ var acc: array<vec4<${n}>, rowPerThread>;
683
+
684
+ // Loop over shared dimension.
685
+ let tileRowB = localRow * ${p};
686
+ for (var t = 0; t < num_tiles; t = t + 1) {
687
+ // Load one tile of A into local memory.
688
+ for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) {
689
+ let inputRow = tileRow + innerRow;
690
+ let inputCol = tileCol;
691
+ ${po(i,r)}
692
+ }
693
+
694
+ // Load one tile of B into local memory.
695
+ for (var innerRow = 0; innerRow < ${p}; innerRow = innerRow + 1) {
696
+ let inputRow = tileRowB + innerRow;
697
+ let inputCol = tileCol;
698
+ mm_Bsub[inputRow][inputCol] = mm_readB(batch, kStart + inputRow, globalCol${r?`, batchIndices`:``});
699
+ }
700
+ kStart = kStart + tileInner;
701
+ workgroupBarrier();
702
+
703
+ // Compute acc values for a single thread.
704
+ for (var k = 0; k < tileInner / innerElementSize; k = k + 1) {
705
+ let BCached0 = mm_Bsub[k * innerElementSize][tileCol];
706
+ let BCached1 = mm_Bsub[k * innerElementSize + 1][tileCol];
707
+ let BCached2 = mm_Bsub[k * innerElementSize + 2][tileCol];
708
+ ${f===3?``:`let BCached3 = mm_Bsub[k * innerElementSize + 3][tileCol];`}
709
+
710
+ ${mo(i,f)}
711
+ }
712
+
713
+ workgroupBarrier();
714
+ }
715
+
716
+ for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) {
717
+ mm_write(batch, globalRow + innerRow, globalCol, acc[innerRow]);
718
+ }
719
+ }`},go=(e,t)=>e?`
720
+ mm_Asub[inputRow][inputCol] = mm_readA(batch,
721
+ kStart + inputRow,
722
+ globalRowStart + inputCol${t?`, batchIndices`:``});
723
+ `:`
724
+ mm_Asub[inputRow][inputCol] = mm_readA(batch,
725
+ globalRowStart + inputRow,
726
+ kStart + inputCol${t?`, batchIndices`:``});
727
+ `,_o=e=>e?`let ACached = mm_Asub[k][tileRow + innerRow];`:`let ACached = mm_Asub[tileRow + innerRow][k];`,vo=(e,t,n=`f32`,r,i=!1,a=32,o=!1,s=32,c=!1)=>{let l=e[1]*t[1],u=e[0]*t[0],d=i?l:a,f=i?a:l;if(!(f%t[1]===0&&d%t[0]===0&&a%t[1]===0))throw Error(`tileAHight ${f} must be divisible by workgroupSize[1]${t[1]}, tileAWidth ${d} must be divisible by workgroupSize[0]${t[0]}, tileInner ${a} must be divisible by workgroupSize[1]${t[1]}`);let p=f/t[1],m=d/t[0],h=a/t[1],g=c?`
728
+ let localRow = i32(localId.y);
729
+ let localCol = i32(localId.x);
730
+ let globalRowStart = i32(workgroupId.y) * ${l};
731
+ let globalColStart = i32(workgroupId.x) * ${u};
732
+
733
+ // Loop over shared dimension.
734
+ for (var t = 0; t < num_tiles; t = t + 1) {
735
+ // Load one tile of A into local memory.
736
+ for (var inputRow = localRow; inputRow < ${f}; inputRow = inputRow + ${t[1]}) {
737
+ for (var inputCol = localCol; inputCol < ${d}; inputCol = inputCol + ${t[0]}) {
738
+ ${go(i,r)}
739
+ }
740
+ }
741
+ // Load one tile of B into local memory.
742
+ for (var inputRow = localRow; inputRow < ${a}; inputRow = inputRow + ${t[1]}) {
743
+ for (var inputCol = localCol; inputCol < ${u}; inputCol = inputCol + ${t[0]}) {
744
+ mm_Bsub[inputRow][inputCol] = mm_readB(batch,
745
+ kStart + inputRow,
746
+ globalColStart + inputCol${r?`, batchIndices`:``});
747
+ }
748
+ }
749
+ kStart = kStart + tileInner;
750
+ workgroupBarrier();
751
+
752
+ // Compute acc values for a single thread.
753
+ var BCached : array<${n}, colPerThread>;
754
+ for (var k = 0; k < tileInner; k = k + 1) {
755
+ for (var inner = 0; inner < colPerThread; inner = inner + 1) {
756
+ BCached[inner] = mm_Bsub[k][localCol + inner * ${t[0]}];
757
+ }
758
+ for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) {
759
+ let ACached = ${i?`mm_Asub[k][localRow + innerRow * ${t[1]}];`:`mm_Asub[localRow + innerRow * ${t[1]}][k];`}
760
+ for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) {
761
+ acc[innerRow][innerCol] = acc[innerRow][innerCol] +
762
+ ACached * BCached[innerCol];
763
+ }
764
+ }
765
+ }
766
+ workgroupBarrier();
767
+ }
768
+ for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) {
769
+ let gRow = globalRowStart + localRow + innerRow * ${t[1]};
770
+ for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) {
771
+ let gCol = globalColStart + localCol + innerCol * ${t[0]};
772
+ mm_write(batch, gRow, gCol, acc[innerRow][innerCol]);
773
+ }
774
+ }
775
+ `:`
776
+ let tileRow = i32(localId.y) * rowPerThread;
777
+ let tileCol = i32(localId.x) * colPerThread;
778
+
779
+ let globalRow = i32(globalId.y) * rowPerThread;
780
+ let globalCol = i32(globalId.x) * colPerThread;
781
+ let globalRowStart = i32(workgroupId.y) * ${l};
782
+
783
+ let tileRowA = i32(localId.y) * ${p};
784
+ let tileColA = i32(localId.x) * ${m};
785
+ let tileRowB = i32(localId.y) * ${h};
786
+ // Loop over shared dimension.
787
+ for (var t = 0; t < num_tiles; t = t + 1) {
788
+ // Load one tile of A into local memory.
789
+ for (var innerRow = 0; innerRow < ${p}; innerRow = innerRow + 1) {
790
+ for (var innerCol = 0; innerCol < ${m}; innerCol = innerCol + 1) {
791
+ let inputRow = tileRowA + innerRow;
792
+ let inputCol = tileColA + innerCol;
793
+ ${go(i,r)}
794
+ }
795
+ }
796
+
797
+ // Load one tile of B into local memory.
798
+ for (var innerRow = 0; innerRow < ${h}; innerRow = innerRow + 1) {
799
+ for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) {
800
+ let inputRow = tileRowB + innerRow;
801
+ let inputCol = tileCol + innerCol;
802
+ mm_Bsub[inputRow][inputCol] = mm_readB(batch,
803
+ kStart + inputRow,
804
+ globalCol + innerCol${r?`, batchIndices`:``});
805
+ }
806
+ }
807
+ kStart = kStart + tileInner;
808
+ workgroupBarrier();
809
+
810
+ // Compute acc values for a single thread.
811
+ var BCached : array<${n}, colPerThread>;
812
+ for (var k = 0; k < tileInner; k = k + 1) {
813
+ for (var inner = 0; inner < colPerThread; inner = inner + 1) {
814
+ BCached[inner] = mm_Bsub[k][tileCol + inner];
815
+ }
816
+
817
+ for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) {
818
+ ${_o(i)}
819
+ for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) {
820
+ acc[innerRow][innerCol] = acc[innerRow][innerCol] + ACached * BCached[innerCol];
821
+ }
822
+ }
823
+ }
824
+
825
+ workgroupBarrier();
826
+ }
827
+
828
+ for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) {
829
+ for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) {
830
+ mm_write(batch, globalRow + innerRow, globalCol + innerCol,
831
+ acc[innerRow][innerCol]);
832
+ }
833
+ }
834
+ `;return`
835
+ var<workgroup> mm_Asub : array<array<${n}, ${d}>, ${f}>;
836
+ var<workgroup> mm_Bsub : array<array<${n}, ${u}>, ${a}>;
837
+ const rowPerThread = ${e[1]};
838
+ const colPerThread = ${e[0]};
839
+ const tileInner = ${a};
840
+
841
+ @compute @workgroup_size(${t[0]}, ${t[1]}, ${t[2]})
842
+ fn main(@builtin(local_invocation_id) localId : vec3<u32>,
843
+ @builtin(global_invocation_id) globalId : vec3<u32>,
844
+ @builtin(workgroup_id) workgroupId : vec3<u32>) {
845
+ let batch = ${o?`0`:`i32(globalId.z)`};
846
+ ${r?`let batchIndices = ${r.offsetToIndices(`u32(batch)`)};`:``}
847
+ let num_tiles = ${o?`${Math.ceil(s/a)}`:`(uniforms.dim_inner - 1) / tileInner + 1`};
848
+ var kStart = ${o?`i32(globalId.z) * ${s}`:`0`};
849
+
850
+ var acc : array<array<${n}, colPerThread>, rowPerThread>;
851
+ ${g}
852
+ }
853
+ `},yo=(e,t,n,r,i=!1)=>{let[a,o,s,c]=r,l=Qn(r[0].type.tensor);return`
854
+ fn mm_readA(batch: i32, row: i32, colIn: i32, batchIndices: ${a.type.indices}) -> ${io(e,l)} {
855
+ var value = ${io(e,l)}(0.0);
856
+ let col = colIn * ${e};
857
+ if(row < uniforms.dim_a_outer && col < uniforms.dim_inner)
858
+ {
859
+ var aIndices: ${o.type.indices};
860
+ ${lo(`aIndices`,o,o.rank-2,a.rank,`batchIndices`)}
861
+ ${o.indicesSet(`aIndices`,o.rank-2,`u32(row)`)}
862
+ ${o.indicesSet(`aIndices`,o.rank-1,`u32(colIn)`)}
863
+ value = ${o.getByIndices(`aIndices`)};
864
+ }
865
+ return value;
866
+ }
867
+
868
+ fn mm_readB(batch: i32, row: i32, colIn: i32, batchIndices: ${a.type.indices}) -> ${io(e,l)} {
869
+ var value = ${io(e,l)}(0.0);
870
+ let col = colIn * ${e};
871
+ if(row < uniforms.dim_inner && col < uniforms.dim_b_outer)
872
+ {
873
+ var bIndices: ${s.type.indices};
874
+ ${lo(`bIndices`,s,s.rank-2,a.rank,`batchIndices`)}
875
+ ${s.indicesSet(`bIndices`,s.rank-2,`u32(row)`)}
876
+ ${s.indicesSet(`bIndices`,s.rank-1,`u32(colIn)`)}
877
+ value = ${s.getByIndices(`bIndices`)};
878
+ }
879
+ return value;
880
+ }
881
+
882
+ fn mm_write(batch: i32, row: i32, colIn: i32, valueIn: ${io(e,l)}) {
883
+ let col = colIn * ${e};
884
+ if (row < uniforms.dim_a_outer && col < uniforms.dim_b_outer) {
885
+ var value = valueIn;
886
+ let coords = vec3<i32>(batch, row, colIn);
887
+ ${t?`value = value + ${i?`bias[colIn]`:`${io(e,l)}(bias[row])`};`:``}
888
+ ${n}
889
+ ${c.setByIndices(`vec3<u32>(coords)`,`value`)}
890
+ }
891
+ }
892
+ `},bo=(e,t,n,r,i=!1,a)=>{let o=e[0].dims,s=e[1].dims,c=o.slice(0,-2),l=s.slice(0,-2),u=r?r.slice(0,-2):n.slice(0,-2),d=W.size(u),f=o[o.length-2],p=o[o.length-1],m=s[s.length-1],h=p%4==0&&m%4==0,g=f<=8?[4,1,1]:[4,4,1],_=[8,8,1],v=[Math.ceil(m/_[0]/g[0]),Math.ceil(f/_[1]/g[1]),Math.ceil(d/_[2]/g[2])],y=h?4:1,b=[...c,f,p/y],x=b.length,S=[...l,p,m/y],C=S.length,w=[d,f,m/y],T=[{type:6,data:f},{type:6,data:m},{type:6,data:p}];eo(t,T),T.push(...K(u,b,S));let E=[`rank`,`rank`],D=e.length>2;return D&&(T.push(...K(e[2].dims)),E.push(`rank`)),T.push(...K(w)),{name:`MatMul`,shaderCache:{hint:`${g};${t.activation};${h};${i}`,inputDependencies:E},getRunData:()=>({outputs:[{dims:a?a(n):n,dataType:e[0].dataType}],dispatchGroup:{x:v[0],y:v[1],z:v[2]},programUniforms:T}),getShaderSource:n=>{let r=u.length,a=or(`batchDims`,e[0].dataType,r,1),o=Qn(e[0].dataType),s=J(`a`,e[0].dataType,x,y),c=J(`b`,e[1].dataType,C,y),l=Y(`result`,e[0].dataType,w.length,y),d=[s,c];if(D){let t=i?y:1;d.push(J(`bias`,e[2].dataType,e[2].dims.length,t))}let f=[{name:`dim_a_outer`,type:`i32`},{name:`dim_b_outer`,type:`i32`},{name:`dim_inner`,type:`i32`}];to(t,f);let p=Qn(l.type.tensor),m=$a(t,l.type.value,p),v=yo(y,D,m,[a,s,c,l],i);return`
893
+ ${n.registerUniforms(f).registerInternalVariables(a).declareVariables(...d,l)}
894
+ ${v}
895
+ ${h?ho(g,_,o,a):vo(g,_,o,a)}
896
+ `}}}}),So,Co,wo=M(()=>{H(),fn(),X(),ro(),oo(),co(),xo(),So=(e,t,n,r,i=!1,a,o=4,s=4,c=4,l=`f32`)=>{let u=e=>{switch(e){case 1:return`resData = x[xIndex];`;case 3:return`resData = vec3<${l}>(x[xIndex], x[xIndex + 1], x[xIndex + 2]);`;case 4:return`resData = x[xIndex / 4];`;default:throw Error(`innerElementSize ${e} is not supported.`)}},d=e=>{switch(e){case 1:return`return w[row * i32(uniforms.w_shape[3]) + colIn];`;case 4:return`return w[row * i32(uniforms.w_shape[3]) / 4 + colIn];`;default:throw Error(`innerElementSize ${e} is not supported.`)}},f=e?`
897
+ let coord = vec4<i32>(batch, xRow, xCol, xCh);
898
+ `:`
899
+ let coord = vec4<i32>(batch, xCh, xRow, xCol);
900
+ `,p=e?`
901
+ let coords = vec4<i32>(
902
+ batch,
903
+ row / outWidth,
904
+ row % outWidth,
905
+ col);
906
+ `:`
907
+ let coords = vec4<i32>(
908
+ batch,
909
+ row,
910
+ col / outWidth,
911
+ col % outWidth);
912
+ `,m=e?`i32(uniforms.x_shape[1])`:`i32(uniforms.x_shape[2])`,h=e?`i32(uniforms.x_shape[2])`:`i32(uniforms.x_shape[3])`,g=e?`row`:`col`,_=e?`col`:`row`,v=`
913
+ let inChannels = i32(uniforms.w_shape[2]);
914
+ let outWidth = ${e?`i32(uniforms.result_shape[2])`:`i32(uniforms.result_shape[3])`};
915
+ let outRow = ${g} / outWidth;
916
+ let outCol = ${g} % outWidth;
917
+
918
+ let WRow = ${_} / (i32(uniforms.w_shape[1]) * inChannels);
919
+ let WCol = ${_} / inChannels % i32(uniforms.w_shape[1]);
920
+ let xRow = outRow * uniforms.stride[0] + uniforms.dilation[0] * WRow - uniforms.pad[0];
921
+ let xCol = outCol * uniforms.stride[1] + uniforms.dilation[1] * WCol - uniforms.pad[1];
922
+ let xCh = ${_} % inChannels;
923
+ var resData = ${io(o,l)}(0.0);
924
+ // The bounds checking is always needed since we use it to pad zero for
925
+ // the 'same' padding type.
926
+ if (xRow >= 0 && xRow < ${m} && xCol >= 0 && xCol < ${h}) {
927
+ ${f}
928
+ let xIndex = getIndexFromCoords4D(coord, vec4<i32>(uniforms.x_shape));
929
+ ${u(o)}
930
+ }
931
+ return resData;`,y=e?t&&r?`
932
+ let col = colIn * ${o};
933
+ ${v}`:`
934
+ let col = colIn * ${o};
935
+ if (row < uniforms.dim_a_outer && col < uniforms.dim_inner) {
936
+ ${v}
937
+ }
938
+ return ${io(o,l)}(0.0);`:r&&n?`
939
+ let col = colIn * ${o};
940
+ ${v}`:`
941
+ let col = colIn * ${o};
942
+ if (row < uniforms.dim_inner && col < uniforms.dim_b_outer) {
943
+ ${v}
944
+ }
945
+ return ${io(o,l)}(0.0);`,b=e?r&&n?d(s):`
946
+ let col = colIn * ${s};
947
+ if (row < uniforms.dim_inner && col < uniforms.dim_b_outer) {
948
+ ${d(s)}
949
+ }
950
+ return ${io(s,l)}(0.0);`:`
951
+ let col = colIn * ${s};
952
+ if (row < uniforms.dim_inner && col < uniforms.dim_a_outer) {
953
+ ${d(s)}
954
+ }
955
+ return ${io(s,l)}(0.0);`,x=io(c,l),S=io(e?o:s,l),C=io(e?s:o,l),w=$a(a,x,l);return`
956
+ fn mm_readA(batch: i32, row : i32, colIn : i32) -> ${S} {
957
+ ${e?y:b}
958
+ }
959
+
960
+ fn mm_readB(batch: i32, row : i32, colIn : i32) -> ${C} {
961
+ ${e?b:y}
962
+ }
963
+
964
+ fn mm_write(batch: i32, row : i32, colIn : i32, valueIn : ${x}) {
965
+ let col = colIn * ${c};
966
+ if (row < uniforms.dim_a_outer && col < uniforms.dim_b_outer)
967
+ {
968
+ var value = valueIn;
969
+ let outWidth = ${e?`i32(uniforms.result_shape[2])`:`i32(uniforms.result_shape[3])`};
970
+ ${p}
971
+ ${ao(i)}
972
+ ${w}
973
+ setOutputAtCoords(coords[0], coords[1], coords[2], coords[3], value);
974
+ }
975
+ }`},Co=(e,t,n,r,i,a,o,s,c)=>{let l=t.format===`NHWC`,u=l?e[0].dims[3]:e[0].dims[1],d=n[0],f=l?n[2]:n[3],p=l?n[1]:n[2],m=l?n[3]:n[1],h=l&&(u%4==0||u%3==0)&&m%4==0,g=l?m:f*p,_=l?f*p:m,v=[8,8,1],y=r<=8?[4,1,1]:[4,4,1],b=[Math.ceil(g/v[0]/y[0]),Math.ceil(_/v[1]/y[1]),Math.ceil(d/v[2]/y[2])];U(`verbose`,()=>`[conv2d_mm_webgpu] dispatch = ${b}`);let x=h?l&&u%4!=0?3:4:1,S=v[1]*y[1],C=v[0]*y[0],w=Math.max(v[0]*x,v[1]),T=r%S===0,E=i%C===0,D=a%w===0,O=h?[x,4,4]:[1,1,1],k=[{type:6,data:r},{type:6,data:i},{type:6,data:a},{type:6,data:[t.pads[0],t.pads[1]]},{type:6,data:t.strides},{type:6,data:t.dilations}];eo(t,k),k.push(...K(e[0].dims,e[1].dims));let A=[`rank`,`rank`];return o&&(k.push(...K(e[2].dims)),A.push(`rank`)),k.push(...K(n)),{name:`Conv2DMatMul`,shaderCache:{hint:`${t.cacheKey};${x};${h};${T};${E};${D};${S};${C};${w}`,inputDependencies:A},getRunData:()=>({outputs:[{dims:c?c(n):n,dataType:e[0].dataType}],dispatchGroup:{x:b[0],y:b[1],z:b[2]},programUniforms:k}),getShaderSource:r=>{let i=[{name:`dim_a_outer`,type:`i32`},{name:`dim_b_outer`,type:`i32`},{name:`dim_inner`,type:`i32`},{name:`pad`,type:`i32`,length:2},{name:`stride`,type:`i32`,length:2},{name:`dilation`,type:`i32`,length:2}];to(t,i);let a=h?4:1,c=Qn(e[0].dataType),u=`
976
+ fn setOutputAtIndex(flatIndex : i32, value : ${h?`vec4<${c}>`:c}) {
977
+ result[flatIndex] = ${h?`vec4<${c}>`:c}(value);
978
+ }
979
+ fn setOutputAtCoords(d0 : i32, d1 : i32, d2 : i32, d3 : i32, value : ${h?`vec4<${c}>`:c}) {
980
+ let flatIndex = getOutputIndexFromCoords(vec4<i32>(d0, d1, d2, d3));
981
+ setOutputAtIndex(flatIndex ${h?`/ 4`:``}, value);
982
+ }`,d=[J(`x`,e[0].dataType,e[0].dims.length,x===3?1:x),J(`w`,e[1].dataType,e[1].dims.length,a)],f=Y(`result`,e[0].dataType,n.length,a);if(o){let t=J(`bias`,e[2].dataType,e[2].dims.length,a);d.push(t),u+=`
983
+ fn getBiasByOutputCoords(coords : vec4<i32>) -> ${h?`vec4<${c}>`:c} {
984
+ return bias[coords.${l?`w`:`y`}${h?`/ 4`:``}];
985
+ }`}return`
986
+ ${so(`uniforms.result_strides`)}
987
+ //struct Uniforms { xShape : vec4<i32>, wShape : vec4<i32>, outShape : vec4<i32>,
988
+ // outShapeStrides: vec3<i32>, filterDims : vec2<i32>, pad : vec2<i32>, stride : vec2<i32>,
989
+ // dilation : vec2<i32>, dimAOuter : i32, dimBOuter : i32, dimInner : i32 };
990
+ ${r.registerUniforms(i).declareVariables(...d,f)}
991
+ ${u}
992
+ ${So(l,T,E,D,o,t,O[0],O[1],O[2],c)}
993
+ ${h?ho(y,v,c,void 0,!l,w):vo(y,v,c,void 0,!l,w,!1,void 0,s)}`}}}}),To,Eo,Do,Oo,ko,Ao,jo,Mo,No=M(()=>{H(),fn(),G(),X(),ro(),oo(),To=e=>{let t=1;for(let n=0;n<e.length;n++)t*=e[n];return t},Eo=e=>typeof e==`number`?[e,e,e]:e,Do=(e,t)=>t<=1?e:e+(e-1)*(t-1),Oo=(e,t,n,r=1)=>{let i=Do(t,r);return Math.floor((e[0]*(n-1)-n+i)/2)},ko=(e,t,n,r,i)=>{i??=Oo(e,t[0],r[0]);let a=[0,0,0,n];for(let n=0;n<3;n++)e[n]+2*i>=t[n]&&(a[n]=Math.trunc((e[n]-t[n]+2*i)/r[n]+1));return a},Ao=(e,t,n,r,i,a,o,s,c,l)=>{let u,d,f,p;if(e===`VALID`&&(e=0),typeof e==`number`){u={top:e,bottom:e,left:e,right:e,front:e,back:e};let m=ko([t,n,r,1],[s,c,l],1,[i,a,o],e);d=m[0],f=m[1],p=m[2]}else if(Array.isArray(e)){if(!e.every((e,t,n)=>e===n[0]))throw Error(`Unsupported padding parameter: ${e}`);u={top:e[0],bottom:e[1],left:e[2],right:e[3],front:e[4],back:e[5]};let m=ko([t,n,r,1],[s,c,l],1,[i,a,o],e[0]);d=m[0],f=m[1],p=m[2]}else if(e===`SAME_UPPER`){d=Math.ceil(t/i),f=Math.ceil(n/a),p=Math.ceil(r/o);let e=(d-1)*i+s-t,m=(f-1)*a+c-n,h=(p-1)*o+l-r,g=Math.floor(e/2),_=e-g,v=Math.floor(m/2),y=m-v,b=Math.floor(h/2);u={top:v,bottom:y,left:b,right:h-b,front:g,back:_}}else throw Error(`Unknown padding parameter: ${e}`);return{padInfo:u,outDepth:d,outHeight:f,outWidth:p}},jo=(e,t,n,r,i,a=!1,o=`channelsLast`)=>{let s,c,l,u,d;if(o===`channelsLast`)[s,c,l,u,d]=e;else if(o===`channelsFirst`)[s,d,c,l,u]=e;else throw Error(`Unknown dataFormat ${o}`);let[f,,p,m,h]=t,[g,_,v]=Eo(n),[y,b,x]=Eo(r),S=Do(p,y),C=Do(m,b),w=Do(h,x),{padInfo:T,outDepth:E,outHeight:D,outWidth:O}=Ao(i,c,l,u,g,_,v,S,C,w),k=a?f*d:f,A=[0,0,0,0,0];return o===`channelsFirst`?A=[s,k,E,D,O]:o===`channelsLast`&&(A=[s,E,D,O,k]),{batchSize:s,dataFormat:o,inDepth:c,inHeight:l,inWidth:u,inChannels:d,outDepth:E,outHeight:D,outWidth:O,outChannels:k,padInfo:T,strideDepth:g,strideHeight:_,strideWidth:v,filterDepth:p,filterHeight:m,filterWidth:h,effectiveFilterDepth:S,effectiveFilterHeight:C,effectiveFilterWidth:w,dilationDepth:y,dilationHeight:b,dilationWidth:x,inShape:e,outShape:A,filterShape:t}},Mo=(e,t,n,r,i,a)=>{let o=a===`channelsLast`;o?e[0].dims[3]:e[0].dims[1];let s=[64,1,1],c={x:n.map((e,t)=>t)},l=[Math.ceil(To(c.x.map(e=>n[e]))/s[0]),1,1];U(`verbose`,()=>`[conv3d_naive_webgpu] dispatch = ${l}`);let u=[{type:12,data:W.size(n)},{type:12,data:r},{type:12,data:i},{type:12,data:t.strides},{type:12,data:t.dilations}];eo(t,u),u.push(...K(e[0].dims,e[1].dims));let d=[`rank`,`rank`],f=e.length===3;return f&&(u.push(...K(e[2].dims)),d.push(`rank`)),u.push(...K(n)),{name:`Conv3DNaive`,shaderCache:{hint:`${t.cacheKey};${o};1;${f}`,inputDependencies:d},getRunData:()=>({outputs:[{dims:n,dataType:e[0].dataType}],dispatchGroup:{x:l[0],y:l[1],z:l[2]},programUniforms:u}),getShaderSource:a=>{let s=[{name:`output_size`,type:`u32`},{name:`filter_dims`,type:`u32`,length:r.length},{name:`pads`,type:`u32`,length:i.length},{name:`strides`,type:`u32`,length:t.strides.length},{name:`dilations`,type:`u32`,length:t.dilations.length}];to(t,s);let c=Qn(e[0].dataType),l=J(`x`,e[0].dataType,e[0].dims.length,1),u=J(`W`,e[1].dataType,e[1].dims.length,1),d=[l,u],p=Y(`result`,e[0].dataType,n.length,1),m=``;if(f){let t=J(`bias`,e[2].dataType,e[2].dims.length,1);d.push(t),m+=`
994
+ fn getBiasByOutputCoords(coords : array<u32, 5>) -> ${c} {
995
+ return bias[${o?q(`coords`,4,5):q(`coords`,1,5)}];
996
+ }`}let h=io(1,c),g=$a(t,h,c);return`
997
+ ${m}
998
+ fn getX(d0 : u32, d1 : u32, d2 : u32, d3 : u32, d4 : u32) -> f32 {
999
+ let aIndices = array<u32, 5>(d0, d1, d2, d3, d4);
1000
+ return ${l.getByIndices(`aIndices`)};
1001
+ }
1002
+ fn getW(d0 : u32, d1 : u32, d2 : u32, d3 : u32, d4 : u32) -> f32 {
1003
+ let aIndices = array<u32, 5>(d0, d1, d2, d3, d4);
1004
+ return ${u.getByIndices(`aIndices`)};
1005
+ }
1006
+ ${a.registerUniforms(s).declareVariables(...d,p)}
1007
+ ${a.mainStart()}
1008
+ ${a.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)}
1009
+ let coords = ${p.offsetToIndices(`global_idx`)};
1010
+ let batch = ${q(`coords`,0,l.rank)};
1011
+ let d2 = ${o?q(`coords`,l.rank-1,l.rank):q(`coords`,1,l.rank)};
1012
+ let xFRCCorner = vec3<u32>(${o?q(`coords`,1,l.rank):q(`coords`,2,l.rank)},
1013
+ ${o?q(`coords`,2,l.rank):q(`coords`,3,l.rank)},
1014
+ ${o?q(`coords`,3,l.rank):q(`coords`,4,l.rank)}) * uniforms.strides - uniforms.pads;
1015
+ let xFCorner = xFRCCorner.x;
1016
+ let xRCorner = xFRCCorner.y;
1017
+ let xCCorner = xFRCCorner.z;
1018
+ let xShapeY = ${o?q(`uniforms.x_shape`,1,l.rank):q(`uniforms.x_shape`,2,l.rank)};
1019
+ let xShapeZ = ${o?q(`uniforms.x_shape`,2,l.rank):q(`uniforms.x_shape`,3,l.rank)};
1020
+ let xShapeW = ${o?q(`uniforms.x_shape`,3,l.rank):q(`uniforms.x_shape`,4,l.rank)};
1021
+ let xShapeU = ${o?q(`uniforms.x_shape`,4,l.rank):q(`uniforms.x_shape`,1,l.rank)};
1022
+ let inputDepthNearestVec4 = (xShapeU / 4) * 4;
1023
+ let inputDepthVec4Remainder = xShapeU % 4;
1024
+
1025
+ var value = 0.0;
1026
+ for (var wF = 0u; wF < uniforms.filter_dims[0]; wF++) {
1027
+ let xF = xFCorner + wF * uniforms.dilations[0];
1028
+ if (xF < 0 || xF >= xShapeY) {
1029
+ continue;
1030
+ }
1031
+
1032
+ for (var wR = 0u; wR < uniforms.filter_dims[1]; wR++) {
1033
+ let xR = xRCorner + wR * uniforms.dilations[1];
1034
+ if (xR < 0 || xR >= xShapeZ) {
1035
+ continue;
1036
+ }
1037
+
1038
+ for (var wC = 0u; wC < uniforms.filter_dims[2]; wC++) {
1039
+ let xC = xCCorner + wC * uniforms.dilations[2];
1040
+ if (xC < 0 || xC >= xShapeW) {
1041
+ continue;
1042
+ }
1043
+
1044
+ for (var d1 = 0u; d1 < inputDepthNearestVec4; d1 += 4) {
1045
+ ${o?`let xValues = vec4<f32>(
1046
+ getX(batch, xF, xR, xC, d1),
1047
+ getX(batch, xF, xR, xC, d1 + 1),
1048
+ getX(batch, xF, xR, xC, d1 + 2),
1049
+ getX(batch, xF, xR, xC, d1 + 3));
1050
+ `:`let xValues = vec4<f32>(
1051
+ getX(batch, d1, xF, xR, xC),
1052
+ getX(batch, d1 + 1, xF, xR, xC),
1053
+ getX(batch, d1 + 2, xF, xR, xC),
1054
+ getX(batch, d1 + 3, xF, xR, xC));
1055
+ `}
1056
+ let wValues = vec4<f32>(
1057
+ getW(d2, d1, wF, wR, wC),
1058
+ getW(d2, d1 + 1, wF, wR, wC),
1059
+ getW(d2, d1 + 2, wF, wR, wC),
1060
+ getW(d2, d1 + 3, wF, wR, wC));
1061
+ value += dot(xValues, wValues);
1062
+ }
1063
+ if (inputDepthVec4Remainder == 1) {
1064
+ ${o?`value += getX(batch, xF, xR, xC, inputDepthNearestVec4)
1065
+ * getW(d2, inputDepthNearestVec4, wF, wR, wC);`:`value += getX(batch, inputDepthNearestVec4, xF, xR, xC)
1066
+ * getW(d2, inputDepthNearestVec4, wF, wR, wC);`}
1067
+ } else if (inputDepthVec4Remainder == 2) {
1068
+ ${o?`let xValues = vec2<f32>(
1069
+ getX(batch, xF, xR, xC, inputDepthNearestVec4),
1070
+ getX(batch, xF, xR, xC, inputDepthNearestVec4 + 1));
1071
+ `:`let xValues = vec2<f32>(
1072
+ getX(batch, inputDepthNearestVec4, xF, xR, xC),
1073
+ getX(batch, inputDepthNearestVec4 + 1, xF, xR, xC));
1074
+ `}
1075
+ let wValues = vec2<f32>(
1076
+ getW(d2, inputDepthNearestVec4, wF, wR, wC),
1077
+ getW(d2, inputDepthNearestVec4 + 1, wF, wR, wC));
1078
+ value += dot(xValues, wValues);
1079
+ } else if (inputDepthVec4Remainder == 3) {
1080
+ ${o?`let xValues = vec3<f32>(
1081
+ getX(batch, xF, xR, xC, inputDepthNearestVec4),
1082
+ getX(batch, xF, xR, xC, inputDepthNearestVec4 + 1),
1083
+ getX(batch, xF, xR, xC, inputDepthNearestVec4 + 2));
1084
+ `:`let xValues = vec3<f32>(
1085
+ getX(batch, inputDepthNearestVec4, xF, xR, xC),
1086
+ getX(batch, inputDepthNearestVec4 + 1, xF, xR, xC),
1087
+ getX(batch, inputDepthNearestVec4 + 2, xF, xR, xC));
1088
+ `}
1089
+ let wValues = vec3<f32>(
1090
+ getW(d2, inputDepthNearestVec4, wF, wR, wC),
1091
+ getW(d2, inputDepthNearestVec4 + 1, wF, wR, wC),
1092
+ getW(d2, inputDepthNearestVec4 + 2, wF, wR, wC));
1093
+ value += dot(xValues, wValues);
1094
+ }
1095
+ }
1096
+ }
1097
+ }
1098
+ ${f?`value = value + getBiasByOutputCoords(coords)`:``};
1099
+ ${g}
1100
+ result[global_idx] = f32(value);
1101
+ }`}}}}),Po,Fo,Io=M(()=>{H(),G(),X(),ro(),Po=(e,t,n,r)=>{let i=e.length>2,a=i?`value += b[output_channel];`:``,o=e[0].dims,s=e[1].dims,c=t.format===`NHWC`,l=c?n[3]:n[1],u=l/t.group,d=c&&u>=4?er(l):1,f=W.size(n)/d,p=[{type:12,data:f},{type:12,data:t.dilations},{type:12,data:[t.strides[0],t.strides[1]]},{type:12,data:[t.pads[0],t.pads[1]]},{type:12,data:u}];eo(t,p),p.push(...K(o,[s[0],s[1],s[2],s[3]/d]));let m=i?[`rank`,`rank`,`rank`]:[`rank`,`rank`];return p.push(...K([n[0],n[1],n[2],n[3]/d])),{name:`GroupedConv`,shaderCache:{hint:`${t.cacheKey}_${d}`,inputDependencies:m},getRunData:()=>({outputs:[{dims:r?r(n):n,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(f/64)},programUniforms:p}),getShaderSource:r=>{let l=Y(`output`,e[0].dataType,n.length,d),u=Qn(l.type.tensor),f=$a(t,l.type.value,u),p=J(`x`,e[0].dataType,o.length),m=J(`w`,e[1].dataType,s.length,d),h=[p,m];i&&h.push(J(`b`,e[2].dataType,e[2].dims,d));let g=[{name:`output_size`,type:`u32`},{name:`dilations`,type:`u32`,length:t.dilations.length},{name:`strides`,type:`u32`,length:2},{name:`pads`,type:`u32`,length:2},{name:`output_channels_per_group`,type:`u32`}];to(t,g);let _=c?`
1102
+ for (var wHeight: u32 = 0u; wHeight < uniforms.w_shape[0]; wHeight++) {
1103
+ let xHeight = xRCCorner.x + wHeight * uniforms.dilations[0];
1104
+
1105
+ if (xHeight < 0u || xHeight >= uniforms.x_shape[1]) {
1106
+ continue;
1107
+ }
1108
+
1109
+ for (var wWidth: u32 = 0u; wWidth < uniforms.w_shape[1]; wWidth++) {
1110
+ let xWidth = xRCCorner.y + wWidth * uniforms.dilations[1];
1111
+ if (xWidth < 0u || xWidth >= uniforms.x_shape[2]) {
1112
+ continue;
1113
+ }
1114
+
1115
+ for (var wInChannel: u32 = 0u; wInChannel < uniforms.w_shape[2]; wInChannel++) {
1116
+ let input_channel = in_channel_offset + wInChannel;
1117
+ let xVal = ${p.get(`batch`,`xHeight`,`xWidth`,`input_channel`)};
1118
+ let wVal = ${m.get(`wHeight`,`wWidth`,`wInChannel`,`output_channel`)};
1119
+ value += xVal * wVal;
1120
+ }
1121
+ }
1122
+ }
1123
+ `:`
1124
+ for (var wInChannel: u32 = 0u; wInChannel < uniforms.w_shape[1]; wInChannel++) {
1125
+ let input_channel = in_channel_offset + wInChannel;
1126
+ for (var wHeight: u32 = 0u; wHeight < uniforms.w_shape[2]; wHeight++) {
1127
+ let xHeight = xRCCorner.x + wHeight * uniforms.dilations[0];
1128
+
1129
+ if (xHeight < 0u || xHeight >= uniforms.x_shape[2]) {
1130
+ continue;
1131
+ }
1132
+
1133
+ for (var wWidth: u32 = 0u; wWidth < uniforms.w_shape[3]; wWidth++) {
1134
+ let xWidth = xRCCorner.y + wWidth * uniforms.dilations[1];
1135
+ if (xWidth < 0u || xWidth >= uniforms.x_shape[3]) {
1136
+ continue;
1137
+ }
1138
+
1139
+ let xVal = ${p.get(`batch`,`input_channel`,`xHeight`,`xWidth`)};
1140
+ let wVal = ${m.get(`output_channel`,`wInChannel`,`wHeight`,`wWidth`)};
1141
+ value += xVal * wVal;
1142
+ }
1143
+ }
1144
+ }
1145
+ `;return`
1146
+ ${r.registerUniforms(g).declareVariables(...h,l)}
1147
+
1148
+ ${r.mainStart()}
1149
+ ${r.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)}
1150
+
1151
+ let outputIndices = ${l.offsetToIndices(`global_idx`)};
1152
+ let batch: u32 = outputIndices[0];
1153
+ let output_channel: u32 = outputIndices[${c?3:1}];
1154
+ let xRCCorner: vec2<u32> = vec2<u32>(outputIndices[${c?1:2}], outputIndices[${c?2:3}]) * uniforms.strides - uniforms.pads;
1155
+ let group_id: u32 = output_channel * ${d} / uniforms.output_channels_per_group;
1156
+ var in_channel_offset = group_id * uniforms.w_shape[${c?2:1}];
1157
+
1158
+ var value: ${l.type.value} = ${l.type.value}(0);
1159
+ ${_}
1160
+ ${a}
1161
+ ${f}
1162
+ ${l.setByOffset(`global_idx`,`value`)}
1163
+ }`}}},Fo=(e,t,n,r)=>{let i=e.length>2,a=er(n[3]),o=er(n[2]),s=W.size(n)/a/o,c=[e[0].dims[0],e[0].dims[1],e[0].dims[2],e[0].dims[3]/a],l=[e[1].dims[0],e[1].dims[1],e[1].dims[2],e[1].dims[3]/a],u=[n[0],n[1],n[2],n[3]/a],d=[{type:12,data:s},{type:6,data:[t.strides[0],t.strides[1]]},{type:6,data:[t.pads[0],t.pads[1]]}];eo(t,d),d.push(...K(c,l,u));let f=(o-1)*t.strides[1]+l[1];return{name:`GroupedConv-Vectorize`,shaderCache:{hint:`${t.cacheKey};${a};${o};${f};${l[0]};${l[1]}`,inputDependencies:i?[`rank`,`rank`,`type`]:[`rank`,`rank`]},getRunData:()=>({outputs:[{dims:r?r(n):n,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(s/64)},programUniforms:d}),getShaderSource:n=>{let r=Y(`output`,e[0].dataType,u.length,a),s=Qn(r.type.tensor),d=$a(t,r.type.value,s),p=J(`x`,e[0].dataType,c.length,a),m=J(`w`,e[1].dataType,l.length,a),h=[p,m];i&&h.push(J(`b`,e[2].dataType,e[2].dims,a));let g=i?`value += b[output_channel];`:``,_=[{name:`output_size`,type:`u32`},{name:`strides`,type:`i32`,length:2},{name:`pads`,type:`i32`,length:2}];return to(t,_),`
1164
+ ${n.registerUniforms(_).declareVariables(...h,r)}
1165
+ ${n.mainStart()}
1166
+ ${n.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)}
1167
+ let width0 = uniforms.output_shape[3];
1168
+ let output_channel = global_idx % width0;
1169
+ var index1 = global_idx / width0;
1170
+ let width1 = uniforms.output_shape[2] / ${o}u;
1171
+ let col = (index1 % width1) * ${o}u;
1172
+ index1 = index1 / width1;
1173
+ let row = index1 % uniforms.output_shape[1];
1174
+ let batch = index1 / uniforms.output_shape[1];
1175
+
1176
+ let x_corner = vec2<i32>(i32(row), i32(col)) * uniforms.strides - uniforms.pads;
1177
+
1178
+ var x_vals: array<${p.type.value}, ${f}>;
1179
+ var values: array<${r.type.value}, ${o}>;
1180
+ let input_channel = output_channel;
1181
+ // Use constant instead of uniform can give better performance for w's height/width.
1182
+ for (var w_height: u32 = 0u; w_height < ${l[0]}; w_height++) {
1183
+ let x_height = x_corner.x + i32(w_height);
1184
+ if (x_height >= 0 && u32(x_height) < uniforms.x_shape[1]) {
1185
+ for (var i = 0; i < ${f}; i++) {
1186
+ let x_width = x_corner.y + i;
1187
+ if (x_width >= 0 && u32(x_width) < uniforms.x_shape[2]) {
1188
+ x_vals[i] = ${p.get(`batch`,`u32(x_height)`,`u32(x_width)`,`input_channel`)};
1189
+ } else {
1190
+ x_vals[i] = ${p.type.value}(0);
1191
+ }
1192
+ }
1193
+ for (var w_width: u32 = 0u; w_width < ${l[1]}; w_width++) {
1194
+ let w_val = ${m.get(`w_height`,`w_width`,`0`,`output_channel`)};
1195
+ for (var i = 0u; i < ${o}u; i++) {
1196
+ values[i] = fma(x_vals[i * u32(uniforms.strides[1]) + w_width], w_val, values[i]);
1197
+ }
1198
+ }
1199
+ }
1200
+ }
1201
+
1202
+ for (var i = 0u; i < ${o}u; i++) {
1203
+ var value = values[i];
1204
+ ${g}
1205
+ ${d}
1206
+ ${r.set(`batch`,`row`,`col + i`,`output_channel`,`value`)};
1207
+ }
1208
+ }`}}}}),Lo,Ro,zo,Bo,Vo,Ho,Uo,Wo,Go,Ko=M(()=>{G(),wo(),No(),xo(),Io(),ro(),fo(),_r(),Lo=(e,t,n,r,i,a)=>{let o=e[0],s=e.slice(a?1:2,a?3:4),c=s.length,l=t[0],u=t.slice(2).map((e,t)=>e+(e-1)*(n[t]-1)),d=s.map((e,t)=>e+r[t]+r[t+c]).map((e,t)=>Math.floor((e-u[t]+i[t])/i[t]));return d.splice(0,0,o),d.splice(a?3:1,0,l),d},Ro=[2,3,1,0],zo=(e,t)=>{if(!e||e.length!==2&&e.length!==3)throw Error(`Conv requires 2 or 3 inputs`);if(e[0].dims.length>5)throw Error(`greater than 5D is not supported`);if(e[0].dims.length!==e[1].dims.length)throw Error(`filter does not have same dimension as input`);if(e[0].dims[t.format===`NHWC`?e[0].dims.length-1:1]!==e[1].dims[1]*t.group)throw Error(`FILTER_IN_CHANNEL should be equal to DATA_CHANNEL`);if(e.length===3&&(e[2].dims.length!==1||e[1].dims[0]!==e[2].dims[0]))throw Error(`invalid bias`);let n=e[0].dims.length-2;if(t.dilations.length!==n)throw Error(`dilations should be ${n}D`);if(t.strides.length!==n)throw Error(`strides should be ${n}D`);if(t.pads.length!==n*2)throw Error(`pads should be ${n*2}D`);if(t.kernelShape.length!==0&&t.kernelShape.length!==e[1].dims.length-2)throw Error(`invalid kernel shape`)},Bo=(e,t)=>{let n=e.kernelShape.slice();n.length<t[1].dims.length-2&&n.push(...Array(t[1].dims.length-2-n.length).fill(0));for(let e=2;e<t[1].dims.length;++e)n[e-2]===0&&(n[e-2]=t[1].dims[e]);let r=e.pads.slice();hn.adjustPadsBasedOnAutoPad(t[0].dims,e.strides,e.dilations,n,r,e.format===`NHWC`,e.autoPad);let i=Object.assign({},e);return Object.assign(i,{kernelShape:n,pads:r}),i},Vo=e=>{let t=no(e),n=e.format;return{autoPad:[`NOTSET`,`VALID`,`SAME_UPPER`,`SAME_LOWER`][e.auto_pad],format:n,dilations:e.dilations,group:e.group,kernelShape:e.kernel_shape,pads:e.pads,strides:e.strides,wIsConst:e.w_is_const(),...t,cacheKey:`${e.format};${t.activation};`}},Ho=(e,t,n,r)=>{let i=n.format===`NHWC`,a=Lo(t[0].dims,t[1].dims,n.dilations,n.pads,n.strides,i);if(n.group!==1){let o=[t[0]];if(i){let r=e.kernelCustomData.wT??e.compute(mr(t[1],Ro),{inputs:[1],outputs:[n.wIsConst?-2:-1]})[0];n.wIsConst&&!e.kernelCustomData.wT&&(e.kernelCustomData.wT=r),o.push(r)}else o.push(t[1]);t.length===3&&o.push(t[2]),!e.adapterInfo.isArchitecture(`ampere`)&&i&&t[1].dims[0]===n.group&&t[1].dims[1]===1&&n.dilations[0]===1&&n.dilations[1]===1?e.compute(Fo(o,n,a,r),{inputs:o}):e.compute(Po(o,n,a,r),{inputs:o});return}let o=t.length===3,s=t[0].dims[i?1:2],c=t[0].dims[i?2:3],l=t[0].dims[i?3:1],u=t[1].dims[2],d=t[1].dims[3],f=a[i?1:2],p=a[i?2:3],m=a[i?3:1],h=i&&u===s&&d===c&&n.pads[0]===0&&n.pads[1]===0;if(h||u===1&&d===1&&n.dilations[0]===1&&n.dilations[1]===1&&n.strides[0]===1&&n.strides[1]===1&&n.pads[0]===0&&n.pads[1]===0){let u=a[0],d,g,_,v=[];if(i){let r=e.kernelCustomData.wT??e.compute(mr(t[1],Ro),{inputs:[1],outputs:[n.wIsConst?-2:-1]})[0];if(n.wIsConst&&!e.kernelCustomData.wT&&(e.kernelCustomData.wT=r),h){let e=s*c*l;d=t[0].reshape([1,u,e]),g=r.reshape([1,e,m]),_=[1,u,m]}else d=t[0].reshape([u,s*c,l]),g=r.reshape([1,l,m]),_=[u,f*p,m];v.push(d),v.push(g)}else d=t[0].reshape([u,l,s*c]),g=t[1].reshape([1,m,l]),_=[u,m,f*p],v.push(g),v.push(d);o&&v.push(t[2]);let y=_[2],b=v[0].dims[v[0].dims.length-1];y<8&&b<8?e.compute(uo(v,n,a,_,i,r),{inputs:v}):e.compute(bo(v,n,a,_,i,r),{inputs:v});return}let g=e.kernelCustomData.wT??e.compute(mr(t[1],Ro),{inputs:[1],outputs:[n.wIsConst?-2:-1]})[0];n.wIsConst&&!e.kernelCustomData.wT&&(e.kernelCustomData.wT=g);let _=[t[0],g];o&&_.push(t[2]);let v=i?f*p:m,y=i?m:f*p,b=u*d*l;e.compute(Co(_,n,a,v,y,b,o,!0,r),{inputs:_})},Uo=(e,t)=>{let n=t.format===`NHWC`,r=[e.inputs[0].reshape(n?[e.inputs[0].dims[0],1,e.inputs[0].dims[1],e.inputs[0].dims[2]]:[e.inputs[0].dims[0],e.inputs[0].dims[1],1,e.inputs[0].dims[2]]),e.inputs[1].reshape([e.inputs[1].dims[0],e.inputs[1].dims[1],1,e.inputs[1].dims[2]])];e.inputs.length===3&&r.push(e.inputs[2]);let i=[0,t.pads[0],0,t.pads[1]],a=[1].concat(t.strides),o=[1].concat(t.dilations),s=[1].concat(t.kernelShape),c=Bo({...t,pads:i,strides:a,dilations:o,kernelShape:s},r);Ho(e,r,c,e=>n?[e[0],e[2],e[3]]:[e[0],e[1],e[3]])},Wo=(e,t,n)=>{let r=n.format===`NHWC`?`channelsLast`:`channelsFirst`,i=Bo(n,t),a=n.autoPad===`NOTSET`?n.pads:n.autoPad,o=jo(t[0].dims,t[1].dims,n.strides,n.dilations,a,!1,r);e.compute(Mo(t,i,o.outShape,[o.filterDepth,o.filterHeight,o.filterWidth],[o.padInfo.front,o.padInfo.top,o.padInfo.left],r))},Go=(e,t)=>{if(zo(e.inputs,t),e.inputs[0].dims.length===3)Uo(e,t);else if(e.inputs[0].dims.length===5)Wo(e,e.inputs,t);else{let n=Bo(t,e.inputs);Ho(e,e.inputs,n)}}}),qo,Jo=M(()=>{H(),fn(),G(),X(),qo=(e,t,n)=>{let r=e.length>2,i=t.outputShape,a=t.format===`NHWC`,o=t.group,s=e[1].dims,c=s[2]/o,l=s[3],u=a?er(c):1,d=a&&l===1&&c>=4,f=d?Math.floor(c/4)*4:Math.floor(c/u)*u,p=c-f,m=a?er(l):1,h=a?l===1?u:m:1,g=W.size(i)/m,_=[Math.ceil(g/64),1,1];U(`verbose`,()=>`[conv2d_backprop_webgpu] dispatch = ${_}`);let v=[`rank`,`rank`],y=[t.strides[0],t.strides[1]],b=[t.kernelShape[a?1:2],t.kernelShape[a?2:3]],x=[t.dilations[0],t.dilations[1]],S=[b[0]+(t.dilations[0]<=1?0:(t.kernelShape[a?1:2]-1)*(t.dilations[0]-1)),b[1]+(t.dilations[1]<=1?0:(t.kernelShape[a?2:3]-1)*(t.dilations[1]-1))],C=[S[0]-1-Math.floor((t.pads[0]+t.pads[2])/2),S[1]-1-Math.floor((t.pads[1]+t.pads[3])/2)],w=[{type:12,data:g},{type:12,data:y},{type:12,data:b},{type:12,data:x},{type:12,data:S},{type:6,data:C},{type:12,data:f},{type:12,data:c},{type:12,data:l},...K(e[0].dims,e[1].dims)];return r&&(w.push(...K(e[2].dims)),v.push(`rank`)),w.push(...K(i)),{name:`ConvTranspose2D`,shaderCache:{hint:`${t.cacheKey};${u}${h}${m}${d}${p}`,inputDependencies:v},getRunData:()=>({dispatchGroup:{x:_[0],y:_[1],z:_[2]},outputs:[{dims:n?n(i):i,dataType:e[0].dataType}],programUniforms:w}),getShaderSource:t=>{let n=[{name:`output_size`,type:`u32`},{name:`strides`,type:`u32`,length:y.length},{name:`filter_dims`,type:`u32`,length:b.length},{name:`dilations`,type:`u32`,length:b.length},{name:`effective_filter_dims`,type:`u32`,length:S.length},{name:`pads`,type:`i32`,length:C.length},{name:`input_channels_per_group_int`,type:`u32`},{name:`input_channels_per_group`,type:`u32`},{name:`output_channels_per_group`,type:`u32`}],o=Qn(e[0].dataType),s=a?1:2,c=a?2:3,l=a?3:1,f=J(`W`,e[1].dataType,e[1].dims.length,h),g=J(`Dy`,e[0].dataType,e[0].dims.length,u),_=[g,f];r&&_.push(J(`bias`,e[2].dataType,[i[l]].length,m));let v=Y(`result`,e[0].dataType,i.length,m),x=`
1209
+ let outputIndices = ${v.offsetToIndices(`global_idx * ${m}`)};
1210
+ let batch = ${v.indicesGet(`outputIndices`,0)};
1211
+ let d1 = ${v.indicesGet(`outputIndices`,l)};
1212
+ let r = ${v.indicesGet(`outputIndices`,s)};
1213
+ let c = ${v.indicesGet(`outputIndices`,c)};
1214
+ let dyCorner = vec2<i32>(i32(r), i32(c)) - uniforms.pads;
1215
+ let dyRCorner = dyCorner.x;
1216
+ let dyCCorner = dyCorner.y;
1217
+ let groupId = d1 / uniforms.output_channels_per_group;
1218
+ let wOutChannel = d1 - groupId * uniforms.output_channels_per_group;
1219
+ // Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).
1220
+ // ? = to be determined. : = across all values in that axis.
1221
+ var dotProd = ${v.type.value}(0.0);
1222
+ var wR: u32 = 0;
1223
+ if (uniforms.dilations.x == 1) {
1224
+ // Minimum wR >= 0 that satisfies (dyRCorner + wR) % (uniforms.strides.x) == 0
1225
+ wR = u32(((dyRCorner + i32(uniforms.strides.x) - 1) / i32(uniforms.strides.x)) * i32(uniforms.strides.x) - dyRCorner);
1226
+ }
1227
+ for (; wR < uniforms.effective_filter_dims.x; wR = wR + 1) {
1228
+ if (wR % uniforms.dilations.x != 0) {
1229
+ continue;
1230
+ }
1231
+ let dyR = (${o}(dyRCorner) + ${o}(wR)) / ${o}(uniforms.strides[0]);
1232
+ let wRPerm = uniforms.filter_dims.x - 1 - wR / uniforms.dilations.x;
1233
+ if (dyR < 0.0 || dyR >= ${o}(uniforms.Dy_shape[${s}]) || fract(dyR) > 0.0 ||
1234
+ wRPerm < 0) {
1235
+ continue;
1236
+ }
1237
+ let idyR: u32 = u32(dyR);
1238
+ var wC: u32 = 0;
1239
+ if (uniforms.dilations.y == 1) {
1240
+ // Minimum wC >= 0 that satisfies (dyCCorner + wC) % (uniforms.strides.y) == 0
1241
+ wC = u32(((dyCCorner + i32(uniforms.strides.y) - 1) / i32(uniforms.strides.y)) * i32(uniforms.strides.y) - dyCCorner);
1242
+ }
1243
+ for (; wC < uniforms.effective_filter_dims.y; wC = wC + 1) {
1244
+ if (wC % uniforms.dilations.y != 0) {
1245
+ continue;
1246
+ }
1247
+ let dyC = (${o}(dyCCorner) + ${o}(wC)) / ${o}(uniforms.strides.y);
1248
+ let wCPerm = uniforms.filter_dims.y - 1 - wC / uniforms.dilations.y;
1249
+ if (dyC < 0.0 || dyC >= ${o}(uniforms.Dy_shape[${c}]) ||
1250
+ fract(dyC) > 0.0 || wCPerm < 0) {
1251
+ continue;
1252
+ }
1253
+ let idyC: u32 = u32(dyC);
1254
+ var inputChannel = groupId * uniforms.input_channels_per_group;
1255
+ ${d?`
1256
+ var x_offset = ${g.indicesToOffset(`${g.type.indices}(batch, idyR, idyC, inputChannel)`)} / ${u};
1257
+ var w_offset = ${f.indicesToOffset(`${f.type.indices}(wRPerm, wCPerm, inputChannel, wOutChannel)`)} / ${h};
1258
+ `:``}
1259
+ for (var d2: u32 = 0; d2 < uniforms.input_channels_per_group_int; d2 = d2 + ${d?4:u}) {
1260
+ ${(()=>{let e=``;if(d)u===4?e+=`
1261
+ let xValue = ${g.getByOffset(`x_offset`)};
1262
+ let wValue = ${f.getByOffset(`w_offset`)};
1263
+ dotProd = dotProd + dot(xValue, wValue);
1264
+ x_offset += 1u;
1265
+ w_offset += 1u;`:u===2?e+=`
1266
+ dotProd = dotProd + dot(vec4<${o}>(${g.getByOffset(`x_offset`)}, ${g.getByOffset(`x_offset + 1u`)}), vec4<${o}>(${f.getByOffset(`w_offset`)}, ${f.getByOffset(`w_offset + 1u`)}));
1267
+ x_offset += 2u;
1268
+ w_offset += 2u;`:u===1&&(e+=`
1269
+ dotProd = dotProd + dot(vec4<${o}>(${g.getByOffset(`x_offset`)}, ${g.getByOffset(`x_offset + 1u`)}, ${g.getByOffset(`x_offset + 2u`)}, ${g.getByOffset(`x_offset + 3u`)}), vec4<${o}>(${f.getByOffset(`w_offset`)}, ${f.getByOffset(`w_offset + 1u`)}, ${f.getByOffset(`w_offset + 2u`)}, ${f.getByOffset(`w_offset + 3u`)}));
1270
+ x_offset += 4u;
1271
+ w_offset += 4u;`);else if(e+=`
1272
+ let xValue = ${a?g.getByOffset(`${g.indicesToOffset(`${g.type.indices}(batch, idyR, idyC, inputChannel)`)} / ${u}`):g.get(`batch`,`inputChannel`,`idyR`,`idyC`)};
1273
+ `,u===1)e+=`
1274
+ let w_offset = ${f.indicesToOffset(`${f.type.indices}(u32(wRPerm), u32(wCPerm), inputChannel, wOutChannel)`)};
1275
+ let wValue = ${f.getByOffset(`w_offset / ${h}`)};
1276
+ dotProd = dotProd + xValue * wValue;`;else for(let t=0;t<u;t++)e+=`
1277
+ let wValue${t} = ${f.getByOffset(`${f.indicesToOffset(`${f.type.indices}(u32(wRPerm), u32(wCPerm), inputChannel + ${t}, wOutChannel)`)} / ${h}`)};
1278
+ dotProd = dotProd + xValue[${t}] * wValue${t};`;return e})()}
1279
+ inputChannel = inputChannel + ${d?4:u};
1280
+ }
1281
+ ${(()=>{if(p===0)return``;if(!d)throw Error(`packInputAs4 ${d} is not true.`);let e=``;if(u===1){e+=`dotProd = dotProd`;for(let t=0;t<p;t++)e+=`
1282
+ + ${g.getByOffset(`x_offset + ${t}`)} * ${f.getByOffset(`w_offset + ${t}`)}`;e+=`;`}else if(u===2){if(p!==2)throw Error(`Invalid inputChannelsRemainder ${p}.`);e+=`
1283
+ let xValue = ${g.getByOffset(`x_offset`)};
1284
+ let wValue = ${f.getByOffset(`w_offset`)};
1285
+ dotProd = dotProd + dot(xValue, wValue);`}return e})()}
1286
+ wC = wC + uniforms.strides.y - 1;
1287
+ }
1288
+ wR = wR + uniforms.strides[0] - 1;
1289
+ }
1290
+ let value = dotProd${r?` + bias[d1 / ${m}]`:``};
1291
+ ${v.setByOffset(`global_idx`,`value`)};
1292
+ `;return`
1293
+ ${t.registerUniforms(n).declareVariables(..._,v)}
1294
+ ${t.mainStart()}
1295
+ ${t.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)};
1296
+ ${x}}`}}}}),Yo,Xo,Zo,Qo,$o,es,ts,ns,rs,is=M(()=>{Jo(),ro(),_r(),Yo=(e,t,n,r,i,a)=>(e-1)*t+n+(r-1)*i+1-a,Xo=(e,t,n,r,i)=>{let a=Math.floor(e/2);t===`SAME_UPPER`?(n[r]=a,n[i]=e-a):t===`SAME_LOWER`&&(n[r]=e-a,n[i]=a)},Zo=(e,t,n,r,i,a,o,s,c,l)=>{let u=e.length-2,d=l.length===0;c.length<u&&c.push(...Array(u-c.length).fill(0));let f=e[0],p=t[s?3:1]*i;for(let i=0,f=e.length-u-+!!s;i<u;++i,++f){let s=e[f],p=d?s*o[i]:l[i],m=Yo(s,o[i],a[i],t[f],n[i],p);Xo(m,r,a,i,i+u),d&&l.push(o[i]*(s-1)+c[i]+(t[f]-1)*n[i]+1-a[i]-a[i+u])}l.splice(0,0,f),l.splice(s?3:1,0,p)},Qo=(e,t)=>{let n=e.kernelShape.slice();if(e.kernelShape.length===0||e.kernelShape.reduce((e,t)=>e*t,1)===0){n.length=0;for(let e=2;e<t[1].dims.length;++e)n.push(t[1].dims[e])}let r=e.format===`NHWC`;n.splice(0,0,t[1].dims[0]),n.splice(r?3:1,0,t[1].dims[1]);let i=e.pads.slice(),a=e.outputShape.slice(),o=e.outputPadding.slice(),s=t[0].dims,c=e.dilations.slice();if(c.reduce((e,t)=>e+t,0)===0){let e=t[0].dims.length-2;c=Array(e).fill(1)}let l=e.strides.slice();if(l.reduce((e,t)=>e+t,0)===0){let e=t[0].dims.length-2;l=Array(e).fill(1)}Zo(s,n,c,e.autoPad,e.group,i,l,r,o,a);let u=Object.assign({},e);return Object.assign(u,{kernelShape:n,pads:i,outputPadding:o,outputShape:a,dilations:c,strides:l}),u},$o=e=>{let t=no(e),n=e.format,r=[`NOTSET`,`VALID`,`SAME_UPPER`,`SAME_LOWER`][typeof e.autoPad>`u`?0:e.autoPad],i=e.dilations,a=e.group,o=e.kernelShape,s=e.pads,c=e.strides,l=e.wIsConst();return{autoPad:r,format:n,dilations:i,group:a,kernelShape:o,outputPadding:e.outputPadding,outputShape:e.outputShape,pads:s,strides:c,wIsConst:l,...t,cacheKey:`${e.format};${t.activation};`}},es=(e,t)=>{if(!e||e.length!==2&&e.length!==3)throw Error(`Conv requires 2 or 3 inputs`);if(e[0].dims.length!==4&&e[0].dims.length!==3)throw Error(`currently only support 2-dimensional conv`);if(e[0].dims.length!==e[1].dims.length)throw Error(`filter does not have same dimension as input`);if(e[0].dims[t.format===`NHWC`?e[0].dims.length-1:1]!==e[1].dims[0])throw Error(`FILTER_IN_CHANNEL should be equal to DATA_CHANNEL`);let n=e[1].dims[1]*t.group;if(e.length===3&&(e[2].dims.length!==1||e[2].dims[0]!==n))throw Error(`invalid bias`);let r=e[0].dims.length-2;if(t.dilations.reduce((e,t)=>e+t,0)>0&&t.dilations.length!==r)throw Error(`dilations should be ${r}D`);if(t.strides.reduce((e,t)=>e+t,0)>0&&t.strides.length!==r)throw Error(`strides should be ${r}D`);if(t.pads.reduce((e,t)=>e+t,0)>0&&t.pads.length!==r*2)throw Error(`pads should be ${r*2}D`);if(t.outputPadding.length!==r&&t.outputPadding.length!==0)throw Error(`output_padding should be ${r}D`);if(t.kernelShape.reduce((e,t)=>e+t,0)>0&&t.kernelShape.length!==0&&t.kernelShape.length!==e[1].dims.length-2)throw Error(`invalid kernel shape`);if(t.outputShape.length!==0&&t.outputShape.length!==e[0].dims.length-2)throw Error(`invalid output shape`)},ts=(e,t,n,r)=>{let i=e.kernelCustomData.wT??e.compute(mr(t[1],[2,3,0,1]),{inputs:[1],outputs:[n.wIsConst?-2:-1]})[0];n.wIsConst&&!e.kernelCustomData.wT&&(e.kernelCustomData.wT=i);let a=[t[0],i];t.length===3&&a.push(t[2]),e.compute(qo(a,n,r),{inputs:a})},ns=(e,t)=>{let n=t.format===`NHWC`,r=[e.inputs[0].reshape(n?[e.inputs[0].dims[0],1,e.inputs[0].dims[1],e.inputs[0].dims[2]]:[e.inputs[0].dims[0],e.inputs[0].dims[1],1,e.inputs[0].dims[2]]),e.inputs[1].reshape([e.inputs[1].dims[0],e.inputs[1].dims[1],1,e.inputs[1].dims[2]])];e.inputs.length===3&&r.push(e.inputs[2]);let i=t.kernelShape;(i.length===0||i[0]===0)&&(i=[e.inputs[1].dims[2]]);let a=t.dilations;(a.length===0||a[0]===0)&&(a=[1]);let o=t.strides;(o.length===0||o[0]===0)&&(o=[1]);let s=t.pads;s.length===0&&(s=[0,0]),s=[0,s[0],0,s[1]],o=[1].concat(o),a=[1].concat(a),i=[1].concat(i);let c=t.outputPadding;c=[0].concat(c);let l=Qo({...t,pads:s,strides:o,dilations:a,kernelShape:i,outputPadding:c},r);ts(e,r,l,e=>n?[e[0],e[2],e[3]]:[e[0],e[1],e[3]])},rs=(e,t)=>{if(es(e.inputs,t),e.inputs[0].dims.length===3)ns(e,t);else{let n=Qo(t,e.inputs);ts(e,e.inputs,n)}}}),as,os,ss,cs=M(()=>{H(),G(),Yn(),X(),as=(e,t,n,r)=>{let i=W.size(t),a=t.length,o=J(`input`,e,a),s=Y(`output`,e,a),c=n.dataType===6?n.getInt32Array()[0]:Number(n.getBigInt64Array()[0]),l=W.normalizeAxis(c,a);return{name:`CumSum`,shaderCache:{hint:r.cacheKey,inputDependencies:[`rank`]},getRunData:()=>({outputs:[{dims:t,dataType:e}],dispatchGroup:{x:Math.ceil(i/64)},programUniforms:[{type:12,data:i},{type:12,data:l},...K(t,t)]}),getShaderSource:e=>{let t=` i32(${o.indicesGet(`inputIndices`,`uniforms.axis`)}) `,n=q(`uniforms.input_shape`,`uniforms.axis`,a),i=r.reverse?t+(r.exclusive?` + 1`:``):`0`,c=r.reverse?n:t+(r.exclusive?``:` + 1`);return`
1297
+ ${e.registerUniform(`outputSize`,`u32`).registerUniform(`axis`,`u32`).declareVariables(o,s)}
1298
+ ${e.mainStart()}
1299
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.outputSize`)}
1300
+ var inputIndices = ${s.offsetToIndices(`global_idx`)};
1301
+ var sum = ${s.type.value}(0);
1302
+ let first : i32 = ${i};
1303
+ let last : i32 = ${c};
1304
+ for (var i : i32 = first; i < last; i++) {
1305
+ ${o.indicesSet(`inputIndices`,`uniforms.axis`,`u32(i)`)};
1306
+ sum = sum + ${o.getByIndices(`inputIndices`)};
1307
+ }
1308
+ ${s.setByOffset(`global_idx`,`sum`)};
1309
+ }`}}},os=(e,t)=>{let n=e.inputs[0].dims,r=e.inputs[0].dataType,i=e.inputs[1];e.compute(as(r,n,i,t),{inputs:[0]})},ss=e=>{let t=e.exclusive===1,n=e.reverse===1;return Jn({exclusive:t,reverse:n})}}),ls,us,ds,fs,ps,ms=M(()=>{H(),G(),Yn(),X(),ls=e=>{if(!e||e.length!==1)throw Error(`DepthToSpace requires 1 input.`);if(e[0].dims.length!==4)throw Error(`DepthToSpace requires 4D input.`)},us=(e,t,n,r)=>{let i=[];i.push(`fn perm(i: ${r.type.indices}) -> ${n.type.indices} {
1310
+ var a: ${n.type.indices};`);for(let r=0;r<t;++r)i.push(n.indicesSet(`a`,e[r],`i[${r}]`));return i.push(`return a;}`),i.join(`
1311
+ `)},ds=(e,t)=>{let n,r,i,a,o,s,c=t.format===`NHWC`,l=t.blocksize,u=t.mode===`DCR`;c?([n,r,i,a]=e.dims,o=u?[n,r,i,l,l,a/l**2]:[n,r,i,a/l**2,l,l],s=u?[0,1,3,2,4,5]:[0,1,4,2,5,3]):([n,r,i,a]=[e.dims[0],e.dims[2],e.dims[3],e.dims[1]],o=u?[n,l,l,a/l**2,r,i]:[n,a/l**2,l,l,r,i],s=u?[0,3,4,1,5,2]:[0,1,4,2,5,3]);let d=e.reshape(o),f=d.dims.length,p=e.dataType,m=J(`a`,p,f),h=Y(`output`,p,f);return{name:`DepthToSpace`,shaderCache:{hint:`${e.dims};${t.blocksize};${t.mode}`,inputDependencies:[`rank`]},getRunData:e=>{let t=c?[n,r*l,i*l,a/l**2]:[n,a/l**2,r*l,i*l],o=W.size(t),u=d.dims,f=W.sortBasedOnPerm(u,s);return{outputs:[{dims:t,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(o/64)},programUniforms:[{type:12,data:o},...K(u,f)]}},getShaderSource:e=>`
1312
+ ${e.registerUniform(`output_size`,`u32`).declareVariables(m,h)}
1313
+
1314
+ ${us(s,f,m,h)}
1315
+
1316
+ ${e.mainStart()}
1317
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)}
1318
+
1319
+ let indices = ${h.offsetToIndices(`global_idx`)};
1320
+ let aIndices = perm(indices);
1321
+
1322
+ ${h.setByOffset(`global_idx`,m.getByIndices(`aIndices`))}
1323
+ }`}},fs=(e,t)=>{ls(e.inputs),e.compute(ds(e.inputs[0],t))},ps=e=>Jn({blocksize:e.blocksize,mode:e.mode,format:e.format})}),hs,gs,_s,vs,ys,bs,xs,Ss,Cs,ws,Ts,Es=M(()=>{H(),G(),Yn(),X(),hs=`[a-zA-Z]|\\.\\.\\.`,gs=`(`+hs+`)+`,_s=`^`+gs+`$`,vs=`(`+gs+`,)*`+gs,ys=`^`+vs+`$`,bs=class{constructor(e=-1){this.symbolToIndices=new Map,this.inputIndex=e}addSymbol(e,t){let n=this.symbolToIndices.get(e);n===void 0?n=[t]:n.push(t),this.symbolToIndices.set(e,n)}},xs=class{constructor(e,t){this.equation=t,this.hasEllipsis=!1,this.symbolToInfo=new Map,this.lhs=[],this.outputDims=[];let[n,r]=t.includes(`->`)?t.split(`->`,2):[t,``];if(!n.match(RegExp(ys)))throw Error(`Invalid LHS term`);if(n.split(`,`).forEach((t,n)=>{let r=e[n].dims.slice();if(!t.match(RegExp(_s)))throw Error(`Invalid LHS term`);let i=this.processTerm(t,!0,r,n);this.lhs.push(i)}),r===``)r+=[...this.symbolToInfo.entries()].filter(([e,t])=>t.count===1||e===`...`).map(([e])=>e).join(``);else if(!r.match(RegExp(gs)))throw Error(`Invalid RHS`);r.match(RegExp(hs,`g`))?.forEach(e=>{if(e===`...`)this.outputDims=this.outputDims.concat(this.ellipsisDims);else{let t=this.symbolToInfo.get(e);if(t===void 0)throw Error(`Invalid RHS symbol`);this.outputDims.push(t.dimValue)}}),this.rhs=this.processTerm(r,!1,this.outputDims)}addSymbol(e,t,n){let r=this.symbolToInfo.get(e);if(r!==void 0){if(r.dimValue!==t&&r.count!==1)throw Error(`Dimension mismatch`);r.count++,r.inputIndices.push(n)}else r={count:1,dimValue:t,inputIndices:[n]};this.symbolToInfo.set(e,r)}processTerm(e,t,n,r=-1){let i=n.length,a=!1,o=[],s=0;if(!e.match(RegExp(_s))&&!t&&e!==``)throw Error(`Invalid LHS term`);let c=e.match(RegExp(hs,`g`)),l=new bs(r);return c?.forEach((e,u)=>{if(e===`...`){if(a)throw Error(`Only one ellipsis is allowed per input term`);a=!0;let e=i-c.length+1;if(e<0)throw Error(`Ellipsis out of bounds`);if(o=n.slice(s,s+e),this.hasEllipsis){if(this.ellipsisDims.length!==o.length||this.ellipsisDims.toString()!==o.toString())throw Error(`Ellipsis dimensions mismatch`)}else if(t)this.hasEllipsis=!0,this.ellipsisDims=o;else throw Error(`Ellipsis must be specified in the LHS`);for(let e=0;e<o.length;e++){let t=String.fromCharCode(48+e);l.addSymbol(t,u+e),this.addSymbol(t,n[s++],r)}}else l.addSymbol(e,u+(this.hasEllipsis?this.ellipsisDims.length-1:0)),this.addSymbol(e,n[s++],r)}),l}},Ss=e=>e+`_max`,Cs=(e,t,n,r)=>{let i=e.map(e=>e.length).map((e,n)=>J(`input${n}`,t,e)),a=W.size(r),o=Y(`output`,t,r.length),s=[...n.symbolToInfo.keys()].filter(e=>!n.rhs.symbolToIndices.has(e));return{name:`Einsum`,shaderCache:{hint:n.equation,inputDependencies:e.map(()=>`rank`)},getRunData:()=>{let i=s.filter(e=>n.symbolToInfo.has(e)).map(e=>({type:12,data:n.symbolToInfo.get(e)?.dimValue||0}));i.push({type:12,data:a});let o=e.map((e,t)=>[...K(e)]).reduce((e,t)=>e.concat(t),i);return o.push(...K(r)),{outputs:[{dims:r,dataType:t}],dispatchGroup:{x:Math.ceil(a/64)},programUniforms:o}},getShaderSource:e=>{let t=[],r=[],a=[],c=[],l=[],u=n.symbolToInfo.size===n.rhs.symbolToIndices.size;n.symbolToInfo.forEach((e,s)=>{if(n.rhs.symbolToIndices.has(s)){let r=n.rhs.symbolToIndices.get(s)?.[0];r!==void 0&&n.lhs.forEach((n,a)=>{if(e.inputIndices.includes(a)){let e=n.symbolToIndices.get(s);if(e===void 0)throw Error(`Invalid symbol error`);e.forEach(e=>{t.push(`${i[a].indicesSet(`input${a}Indices`,e,o.indicesGet(`outputIndices`,r))}`)})}})}else n.lhs.forEach((t,n)=>{if(e.inputIndices.includes(n)){let e=t.symbolToIndices.get(s);if(e===void 0)throw Error(`Invalid symbol error`);e.forEach(e=>{r.push(`${i[n].indicesSet(`input${n}Indices`,e,`${s}`)}`)}),l.push(`prod *= ${i[n].getByIndices(`input${n}Indices`)};`)}}),a.push(`for(var ${s}: u32 = 0; ${s} < uniforms.${Ss(s)}; ${s}++) {`),c.push(`}`)});let d=u?[...t,`let sum = ${i.map((e,t)=>e.getByIndices(`input${t}Indices`)).join(` * `)};`]:[...t,`var sum = 0.0;`,...a,...r,`var prod = 1.0;`,...l,`sum += prod;`,...c];return`
1324
+ ${e.registerUniforms(s.map(e=>({name:`${Ss(e)}`,type:`u32`}))).registerUniform(`outputSize`,`u32`).declareVariables(...i,o)}
1325
+
1326
+ ${e.mainStart()}
1327
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.outputSize`)}
1328
+ var outputIndices = ${o.offsetToIndices(`global_idx`)};
1329
+ ${i.map((e,t)=>`var input${t}Indices: ${i[t].type.indices};`).join(`
1330
+ `)}
1331
+ ${d.join(`
1332
+ `)};
1333
+ ${o.setByOffset(`global_idx`,`sum`)};
1334
+ }`}}},ws=(e,t)=>{let n=new xs(e.inputs,t.equation),r=n.outputDims,i=e.inputs.map((e,t)=>e.dims);e.compute(Cs(i,e.inputs[0].dataType,n,r))},Ts=e=>{let t=e.equation.replace(/\s+/g,``);return Jn({equation:t})}}),Ds,Os,ks,As,js,Ms=M(()=>{H(),G(),X(),Ds=e=>{if(!e||e.length!==2)throw Error(`Expand requires 2 input.`);let t=e[0].dims,n=Array.from(e[1].getBigInt64Array(),Number),r=n.length<t.length?0:n.length-t.length,i=t.length<n.length?0:t.length-n.length;for(;r<n.length&&i<t.length;++r,++i)if(n[r]!==t[i]&&n[r]!==1&&t[i]!==1)throw Error(`Expand requires shape to be broadcastable to input`)},Os=(e,t)=>{let n=e.length-t.length,r=[];for(let t=0;t<n;++t)r.push(e[t]);for(let i=0;i<t.length;++i)r.push(t[i]===1?e[i+n]:t[i]);return r},ks=(e,t)=>e.length>t.length?Os(e,t):Os(t,e),As=e=>{let t=e[0].dims,n=Array.from(e[1].getBigInt64Array(),Number),r=ks(t,n),i=e[0].dataType,a=i===9||W.size(t)===1,o=i===9||t.length>0&&t[t.length-1]%4==0?4:1,s=a||r.length>0&&r[r.length-1]%4==0?4:1,c=Math.ceil(W.size(r)/s),l=e=>{let n=J(`input`,i,t.length,o),a=Y(`output`,i,r.length,s),c;if(i===9){let e=(e,t,r=``)=>`
1335
+ let outputIndices${t} = ${a.offsetToIndices(`outputOffset + ${t}u`)};
1336
+ let offset${t} = ${n.broadcastedIndicesToOffset(`outputIndices${t}`,a)};
1337
+ let index${t} = offset${t} / 4u;
1338
+ let component${t} = offset${t} % 4u;
1339
+ ${e}[${t}] = ${r}(${n.getByOffset(`index${t}`)}[component${t}]);
1340
+ `;c=`
1341
+ let outputOffset = global_idx * ${s};
1342
+ var data = vec4<u32>(0);
1343
+ ${e(`data`,0,`u32`)}
1344
+ ${e(`data`,1,`u32`)}
1345
+ ${e(`data`,2,`u32`)}
1346
+ ${e(`data`,3,`u32`)}
1347
+ ${a.setByOffset(`global_idx`,`data`)}
1348
+ }`}else c=`
1349
+ let outputIndices = ${a.offsetToIndices(`global_idx * ${s}`)};
1350
+ let inputOffset = ${n.broadcastedIndicesToOffset(`outputIndices`,a)};
1351
+ let data = ${a.type.value}(${n.getByOffset(`inputOffset / ${o}`)});
1352
+ ${a.setByOffset(`global_idx`,`data`)}
1353
+ }`;return`
1354
+ ${e.registerUniform(`vec_size`,`u32`).declareVariables(n,a)}
1355
+ ${e.mainStart()}
1356
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.vec_size`)}
1357
+ ${c}`},u=[{type:12,data:c},...K(t,r)];return{name:`Expand`,shaderCache:{hint:`${r.length};${o}${s}`,inputDependencies:[`rank`]},getShaderSource:l,getRunData:()=>({outputs:[{dims:r,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(c/64)},programUniforms:u})}},js=e=>{Ds(e.inputs),e.compute(As(e.inputs),{inputs:[0]})}}),Ns,Ps,Fs=M(()=>{H(),G(),X(),Da(),Ns=e=>{let t=e[0].dataType,n=W.size(e[0].dims),r=W.size(e[1].dims),i=r%4==0;return{name:`FastGeluWithBias`,shaderCache:{hint:`${i}`,inputDependencies:[`type`,`type`]},getShaderSource:e=>{let n=J(`x`,t,[1],4),r=J(`bias`,t,[1],4),a=Y(`y`,t,[1],4),o=[{name:`output_vec_size`,type:`u32`},{name:`bias_size`,type:`u32`}],s=e=>`
1358
+ let bias${e}_offset: u32 = (global_idx * 4 + ${e}) % uniforms.bias_size;
1359
+ let bias${e} = ${r.getByOffset(`bias${e}_offset / 4`)}[bias${e}_offset % 4];`,c=i?`
1360
+ let bias = ${r.getByOffset(`global_idx % (uniforms.bias_size / 4)`)};`:`${s(0)}${s(1)}${s(2)}${s(3)}
1361
+ let bias = ${n.type.value}(bias0, bias1, bias2, bias3);`;return`${e.registerUniforms(o).declareVariables(n,r,a)}
1362
+
1363
+ ${ya($n(t))}
1364
+
1365
+ ${e.mainStart(Xn)}
1366
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_vec_size`)}
1367
+
1368
+ let x = ${n.getByOffset(`global_idx`)};
1369
+ ${c}
1370
+ let x_in = x + bias;
1371
+ ${a.setByOffset(`global_idx`,ba(`x_in`))}
1372
+ }`},getRunData:e=>({outputs:[{dims:e[0].dims,dataType:e[0].dataType}],programUniforms:[{type:12,data:Math.ceil(n/4)},{type:12,data:r}],dispatchGroup:{x:Math.ceil(n/Xn/4)}})}},Ps=e=>{e.inputs.length<2||W.size(e.inputs[1].dims)===0?xa(e):e.compute(Ns(e.inputs))}}),Is,Ls,Rs,zs,Bs=M(()=>{H(),G(),Yn(),X(),Is=e=>{if(!e||e.length!==2)throw Error(`Gather requires 2 inputs.`)},Ls=(e,t)=>{let n=e[0].dims,r=e[1].dims,i=n.length,a=W.normalizeAxis(t.axis,i),o=n.slice(0);o.splice(a,1,...r);let s=n[a],c=e[0].dataType===9?4:1,l=Math.ceil(W.size(o)/c),u=[{type:12,data:l},{type:6,data:s},{type:12,data:a},...K(e[0].dims,e[1].dims,o)];return{name:`Gather`,shaderCache:{hint:t.cacheKey,inputDependencies:[`rank`,`rank`]},getRunData:()=>({outputs:[{dims:o,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(l/64)},programUniforms:u}),getShaderSource:t=>{let n=J(`data`,e[0].dataType,e[0].dims.length,c),s=J(`inputIndices`,e[1].dataType,e[1].dims.length),l=Y(`output`,e[0].dataType,o.length,c),u=e=>{let t=r.length,c=`var indicesIndices${e} = ${s.type.indices}(0);`;for(let n=0;n<t;n++)c+=`${t>1?`indicesIndices${e}[${n}]`:`indicesIndices${e}`} = ${o.length>1?`outputIndices${e}[uniforms.axis + ${n}]`:`outputIndices${e}`};`;c+=`
1373
+ var idx${e} = ${s.getByIndices(`indicesIndices${e}`)};
1374
+ if (idx${e} < 0) {
1375
+ idx${e} = idx${e} + uniforms.axisDimLimit;
1376
+ }
1377
+ var dataIndices${e} : ${n.type.indices};
1378
+ `;for(let n=0,r=0;n<i;n++)n===a?(c+=`${i>1?`dataIndices${e}[${n}]`:`dataIndices${e}`} = u32(idx${e});`,r+=t):(c+=`${i>1?`dataIndices${e}[${n}]`:`dataIndices${e}`} = ${o.length>1?`outputIndices${e}[${r}]`:`outputIndices${e}`};`,r++);return c},d;if(e[0].dataType===9){let e=(e,t,r=``)=>`
1379
+ let outputIndices${t} = ${l.offsetToIndices(`outputOffset + ${t}u`)};
1380
+ ${u(t)};
1381
+ let offset${t} = ${n.indicesToOffset(`dataIndices${t}`)};
1382
+ let index${t} = offset${t} / 4u;
1383
+ let component${t} = offset${t} % 4u;
1384
+ ${e}[${t}] = ${r}(${n.getByOffset(`index${t}`)}[component${t}]);
1385
+ `;d=`
1386
+ let outputOffset = global_idx * ${c};
1387
+ var value = vec4<u32>(0);
1388
+ ${e(`value`,0,`u32`)}
1389
+ ${e(`value`,1,`u32`)}
1390
+ ${e(`value`,2,`u32`)}
1391
+ ${e(`value`,3,`u32`)}
1392
+ ${l.setByOffset(`global_idx`,`value`)}
1393
+ `}else d=`
1394
+ let outputIndices = ${l.offsetToIndices(`global_idx`)};
1395
+ ${u(``)};
1396
+ let value = ${n.getByIndices(`dataIndices`)};
1397
+ ${l.setByOffset(`global_idx`,`value`)};
1398
+ `;return`
1399
+ ${t.registerUniform(`outputSize`,`u32`).registerUniform(`axisDimLimit`,`i32`).registerUniform(`axis`,`u32`).declareVariables(n,s,l)}
1400
+ ${t.mainStart()}
1401
+ ${t.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.outputSize`)}
1402
+ ${d}
1403
+ }`}}},Rs=e=>Jn({axis:e.axis}),zs=(e,t)=>{let n=e.inputs;Is(n),e.compute(Ls(e.inputs,t))}}),Vs,Hs,Us,Ws=M(()=>{H(),G(),X(),Vs=(e,t,n,r,i,a,o,s,c)=>{let l=[{type:12,data:a},{type:12,data:r},{type:12,data:i},{type:12,data:n},{type:12,data:o},{type:12,data:s},{type:12,data:c}],u=[a];return l.push(...K(t.dims,u)),e.compute({name:`computeSliceOffsets`,shaderCache:{hint:`${i.length}_${n.length}`,inputDependencies:[`rank`]},getRunData:()=>({outputs:[{dims:u,dataType:e.inputs[1].dataType}],dispatchGroup:{x:Math.ceil(a/64)},programUniforms:l}),getShaderSource:e=>{let r=[J(`indices_data`,t.dataType,t.dims.length),Y(`input_slice_offsets_data`,12,1,1)],a=[{name:`output_size`,type:`u32`},{name:`batch_dims`,type:`u32`},{name:`input_dims`,type:`u32`,length:i.length},{name:`sizes_from_slice_dims_data`,type:`u32`,length:n.length},{name:`num_slices_per_batch`,type:`u32`},{name:`input_batch_stride`,type:`u32`},{name:`num_slice_dims`,type:`u32`}];return`
1404
+ ${e.registerUniforms(a).declareVariables(...r)}
1405
+ ${e.mainStart()}
1406
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)}
1407
+ let batch_idx = global_idx / uniforms.num_slices_per_batch;
1408
+ let base_offset = batch_idx * uniforms.input_batch_stride;
1409
+
1410
+ let slice_indices_base_offset = global_idx * uniforms.num_slice_dims;
1411
+ var relative_slice_offset = 0;
1412
+ for (var dim_idx = 0u; dim_idx < uniforms.num_slice_dims; dim_idx ++) {
1413
+ var index = i32(indices_data[dim_idx + slice_indices_base_offset].x);
1414
+ let input_dim_idx = uniforms.batch_dims + dim_idx;
1415
+ if (index < 0) {
1416
+ ${i.length===1?`index += i32(uniforms.input_dims);`:`index += i32(uniforms.input_dims[input_dim_idx]);`}
1417
+ }
1418
+ ${n.length===1?`relative_slice_offset += index * i32(uniforms.sizes_from_slice_dims_data);`:`relative_slice_offset += index * i32(uniforms.sizes_from_slice_dims_data[dim_idx]);`}
1419
+ }
1420
+
1421
+ input_slice_offsets_data[global_idx] = base_offset + u32(relative_slice_offset);
1422
+ }`}},{inputs:[t],outputs:[-1]})[0]},Hs=(e,t)=>{let n=e.inputs,r=n[0].dims,i=n[0].dataType,a=n[1].dims,o=a[a.length-1],s=W.sizeToDimension(a,a.length-1),c=W.sizeFromDimension(r,t.batchDims+o),l=W.sizeToDimension(r,t.batchDims),u=W.sizeFromDimension(r,t.batchDims),d=s/l,f=Array(o),p=c;for(let e=0;e<o;++e)f[o-1-e]=p,p*=r[t.batchDims+o-1-e];let m=Vs(e,n[1],f,t.batchDims,r,s,d,u,o),h=t.batchDims+o;if(h>r.length)throw Error(`last dimension of indices must not be larger than rank of input tensor`);let g=a.slice(0,-1).concat(r.slice(h)),_=W.size(g),v=[{type:12,data:_},{type:12,data:c},...K(n[0].dims,m.dims,g)];e.compute({name:`GatherND`,shaderCache:{hint:t.cacheKey,inputDependencies:[`rank`,`rank`]},getRunData:()=>({outputs:[{dims:g,dataType:i}],dispatchGroup:{x:Math.ceil(_/64)},programUniforms:v}),getShaderSource:e=>{let t=J(`data`,n[0].dataType,n[0].dims.length),r=J(`slice_offsets`,12,m.dims.length),i=Y(`output`,n[0].dataType,g.length);return`
1423
+ ${e.registerUniform(`output_size`,`u32`).registerUniform(`slice_size`,`u32`).declareVariables(t,r,i)}
1424
+ ${e.mainStart()}
1425
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)}
1426
+ let slice_offset = slice_offsets[global_idx / uniforms.slice_size];
1427
+ output[global_idx] = data[u32(slice_offset) + global_idx % uniforms.slice_size];
1428
+ }`}},{inputs:[n[0],m]})},Us=e=>({batchDims:e.batch_dims,cacheKey:``})}),Gs,Ks,qs,Js,Ys=M(()=>{H(),G(),Yn(),X(),Gs=(e,t)=>{if(e.length<3||e.length>4)throw Error(`GatherBlockQuantized requires 3 or 4 inputs.`);let n=W.normalizeAxis(t.quantizeAxis,e[0].dims.length),r=t.blockSize,i=e[0],a=e[2],o=e.length===4?e[3]:void 0;if(a.dims.length!==i.dims.length||!i.dims.map((e,t)=>t===n?Math.ceil(e/r)===a.dims[t]:e===a.dims[t]).reduce((e,t)=>e&&t,!0))throw Error(`Scales must have the same rank as the input tensor and the dims should match except on gatherAxis.`);if(o){if(o.dataType!==i.dataType)throw Error(`Zero point must have the same data type as the input tensor.`);if(o.dims.length!==a.dims.length||!o.dims.map((e,t)=>e===a.dims[t]).reduce((e,t)=>e&&t,!0))throw Error(`Zero point must have the same rank as the input tensor and the dims should match except on quantizeAxis.`)}},Ks=(e,t)=>{let n=e[0].dims,r=e[1].dims,i=n.length,a=W.normalizeAxis(t.gatherAxis,i),o=W.normalizeAxis(t.quantizeAxis,i),s=n.slice(0);s.splice(a,1,...r);let c=W.size(s),l=e[2].dataType,u=e[0].dataType===22,d=[{type:12,data:c},{type:12,data:o},{type:12,data:a},{type:12,data:t.blockSize},...K(...e.map((e,t)=>e.dims),s)];return{name:`GatherBlockQuantized`,shaderCache:{hint:`${t.cacheKey};${e.filter((e,t)=>t!==1).map(e=>e.dims.join(`_`)).join(`;`)}`,inputDependencies:Array.from({length:e.length},(e,t)=>`rank`)},getRunData:()=>({outputs:[{dims:s,dataType:l}],dispatchGroup:{x:Math.ceil(c/64)},programUniforms:d}),getShaderSource:t=>{let i=J(`data`,e[0].dataType,e[0].dims.length),o=J(`inputIndices`,e[1].dataType,e[1].dims.length),c=J(`scales`,e[2].dataType,e[2].dims.length),d=e.length>3?J(`zeroPoint`,e[3].dataType,e[3].dims.length):void 0,f=Y(`output`,l,s.length),p=[i,o,c];return d&&p.push(d),`
1429
+ ${t.registerUniforms([{name:`output_size`,type:`u32`},{name:`quantize_axis`,type:`u32`},{name:`gather_axis`,type:`u32`},{name:`block_size`,type:`u32`}]).declareVariables(...p,f)}
1430
+ ${t.mainStart()}
1431
+ let output_indices = ${f.offsetToIndices(`global_idx`)};
1432
+ var indices_indices = ${o.type.indices}(0);
1433
+ ${r.length>1?`
1434
+ for (var i: u32 = 0; i < ${r.length}; i++) {
1435
+ let index = ${f.indicesGet(`output_indices`,`uniforms.gather_axis + i`)};
1436
+ ${o.indicesSet(`indices_indices`,`i`,`index`)};
1437
+ }`:`indices_indices = ${f.indicesGet(`output_indices`,`uniforms.gather_axis`)};`};
1438
+ var data_indices = ${i.type.indices}(0);
1439
+ for (var i: u32 = 0; i < uniforms.gather_axis; i++) {
1440
+ let index = ${f.indicesGet(`output_indices`,`i`)};
1441
+ ${i.indicesSet(`data_indices`,`i`,`index`)};
1442
+ }
1443
+ var index_from_indices = ${o.getByIndices(`indices_indices`)};
1444
+ if (index_from_indices < 0) {
1445
+ index_from_indices += ${n[a]};
1446
+ }
1447
+ ${i.indicesSet(`data_indices`,`uniforms.gather_axis`,`u32(index_from_indices)`)};
1448
+ for (var i = uniforms.gather_axis + 1; i < ${s.length}; i++) {
1449
+ let index = ${f.indicesGet(`output_indices`,`i + ${r.length} - 1`)};
1450
+ ${i.indicesSet(`data_indices`,`i`,`index`)};
1451
+ }
1452
+ let data_offset = ${i.indicesToOffset(`data_indices`)};
1453
+ let data_index = data_offset % 8;
1454
+ // Convert 4-bit packed data to 8-bit packed data.
1455
+ let packed_4bit_quantized_data = ${i.getByOffset(`data_offset / 8`)};
1456
+ let packed_8bit_quantized_data = (packed_4bit_quantized_data >> (4 * (data_index % 2))) & 0x0f0f0f0f;
1457
+ let quantized_data_vec = ${u?`unpack4xI8`:`unpack4xU8`}(u32(packed_8bit_quantized_data));
1458
+ let quantized_data = quantized_data_vec[data_index / 2];
1459
+ var scale_indices = data_indices;
1460
+ let quantize_axis_index = ${c.indicesGet(`data_indices`,`uniforms.quantize_axis`)} / uniforms.block_size;
1461
+ ${c.indicesSet(`scale_indices`,`uniforms.quantize_axis`,`quantize_axis_index`)};
1462
+ var scale = ${c.getByIndices(`scale_indices`)};
1463
+ ${d?`
1464
+ let zero_point_indices = scale_indices;
1465
+ let zero_point_offset = ${d.indicesToOffset(`zero_point_indices`)};
1466
+ let zero_point_index = zero_point_offset % 8;
1467
+ let packed_4bit_zero_points = ${d.getByOffset(`zero_point_offset / 8`)};
1468
+ let packed_8bit_zero_points = (packed_4bit_zero_points >> (4 * (zero_point_index % 2))) & 0x0f0f0f0f;
1469
+ let zero_point_vec = ${u?`unpack4xI8`:`unpack4xU8`}(u32(packed_8bit_zero_points));
1470
+ let zero_point = zero_point_vec[zero_point_index / 2];`:`var zero_point = 0`};
1471
+ let dequantized_data = ${$n(l)}(quantized_data - zero_point) * scale;
1472
+ ${f.setByOffset(`global_idx`,`dequantized_data`)};
1473
+ }`}}},qs=(e,t)=>{let n=e.inputs;Gs(n,t),e.compute(Ks(e.inputs,t))},Js=e=>Jn({blockSize:e.blockSize,gatherAxis:e.gatherAxis,quantizeAxis:e.quantizeAxis})}),Xs,Zs,Qs,$s,ec=M(()=>{H(),G(),Yn(),X(),Xs=e=>{if(!e||e.length!==2)throw Error(`GatherElements requires 2 inputs.`);if(e[0].dims.length<1)throw Error(`GatherElements requires that the data input be rank >= 1.`);if(e[0].dims.length!==e[1].dims.length)throw Error(`GatherElements requires that the data input and
1474
+ indices input tensors be of same rank.`)},Zs=(e,t)=>{let n=e[0].dims,r=e[0].dataType,i=n.length,a=e[1].dims,o=e[1].dataType,s=W.normalizeAxis(t.axis,i),c=n[s],l=a.slice(0),u=W.size(l),d=J(`input`,r,i),f=J(`indicesInput`,o,a.length),p=Y(`output`,r,l.length),m=[{type:12,data:u},{type:6,data:c},{type:12,data:s}];return m.push(...K(n,a,l)),{name:`GatherElements`,shaderCache:{inputDependencies:[`rank`,`rank`]},getRunData:()=>({outputs:[{dims:l,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(u/64)},programUniforms:m}),getShaderSource:e=>`
1475
+ ${e.registerUniform(`outputSize`,`u32`).registerUniform(`axisDimLimit`,`i32`).registerUniform(`axis`,`u32`).declareVariables(d,f,p)}
1476
+ ${e.mainStart()}
1477
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.outputSize`)}
1478
+
1479
+ let outputIndices = ${p.offsetToIndices(`global_idx`)};
1480
+
1481
+ var idx = ${f.getByOffset(`global_idx`)};
1482
+ if (idx < 0) {
1483
+ idx = idx + uniforms.axisDimLimit;
1484
+ }
1485
+ var inputIndices = ${d.type.indices}(outputIndices);
1486
+ ${d.indicesSet(`inputIndices`,`uniforms.axis`,`u32(idx)`)};
1487
+ let value = ${d.getByIndices(`inputIndices`)};
1488
+
1489
+ ${p.setByOffset(`global_idx`,`value`)};
1490
+ }`}},Qs=e=>Jn({axis:e.axis}),$s=(e,t)=>{let n=e.inputs;Xs(n),e.compute(Zs(e.inputs,t))}}),tc,nc,rc,ic,ac=M(()=>{H(),G(),X(),tc=e=>{if(!e)throw Error(`Input is missing`);if(e.length<2||e.length>3)throw Error(`Invaid input number.`);if(e.length===3&&e[2].dims.length>2)throw Error(`Invalid input shape of C`);if(e[0].dataType!==e[1].dataType||e.length===3&&e[0].dataType!==e[2].dataType)throw Error(`Input types are mismatched`)},nc=(e,t)=>{let n=e[0].dims.slice(),r=e[1].dims.slice(),[i,a,o]=gn.getShapeOfGemmResult(n,t.transA,r,t.transB,e.length===3?e[2].dims:void 0),s=[i,a];if(!s)throw Error(`Can't use gemm on the given tensors`);let c=Math.ceil(a/16),l=Math.ceil(i/16);W.size(s);let u=[{type:12,data:c},{type:12,data:i},{type:12,data:a},{type:12,data:o},{type:1,data:t.alpha},{type:1,data:t.beta}],d=[`type`,`type`];return e.length===3&&(u.push(...K(e[2].dims)),d.push(`rank`)),u.push(...K(s)),{name:`GemmShared`,shaderCache:{hint:`${t.cacheKey}`,inputDependencies:d},getRunData:()=>({outputs:[{dims:s,dataType:e[0].dataType}],dispatchGroup:{x:c*l},programUniforms:u}),getShaderSource:n=>{let r=J(`a`,e[0].dataType,e[0].dims),i=J(`b`,e[1].dataType,e[1].dims),a=null,o=[r,i];e.length===3&&(a=J(`c`,e[2].dataType,e[2].dims.length),o.push(a));let c=Y(`output`,e[0].dataType,s.length);o.push(c);let l=[{name:`num_tile_n`,type:`u32`},{name:`M`,type:`u32`},{name:`N`,type:`u32`},{name:`K`,type:`u32`},{name:`alpha`,type:`f32`},{name:`beta`,type:`f32`}],u=``,d=``;t.transA&&t.transB?(d=`
1491
+ var col = tile_row_start + local_id.x;
1492
+ var row = k_start + local_id.y;
1493
+ if (col < uniforms.M && row < uniforms.K) {
1494
+ tile_a[local_id.y][local_id.x] = a[row * uniforms.M + col];
1495
+ } else {
1496
+ tile_a[local_id.y][local_id.x] = ${r.type.value}(0);
1497
+ }
1498
+
1499
+ col = k_start + local_id.x;
1500
+ row = tile_col_start + local_id.y;
1501
+ if (col < uniforms.K && row < uniforms.N) {
1502
+ tile_b[local_id.y][local_id.x] = b[row * uniforms.K + col];
1503
+ } else {
1504
+ tile_b[local_id.y][local_id.x] = ${i.type.value}(0);
1505
+ }
1506
+ `,u=`value += tile_a[k][local_id.y] * tile_b[local_id.x][k];`):t.transA&&!t.transB?(d=`
1507
+ var col = tile_row_start + local_id.x;
1508
+ var row = k_start + local_id.y;
1509
+ if (col < uniforms.M && row < uniforms.K) {
1510
+ tile_a[local_id.y][local_id.x] = a[row * uniforms.M + col];
1511
+ } else {
1512
+ tile_a[local_id.y][local_id.x] = ${r.type.value}(0);
1513
+ }
1514
+
1515
+ col = tile_col_start + local_id.x;
1516
+ row = k_start + local_id.y;
1517
+ if (col < uniforms.N && row < uniforms.K) {
1518
+ tile_b[local_id.y][local_id.x] = b[row * uniforms.N + col];
1519
+ } else {
1520
+ tile_b[local_id.y][local_id.x] = ${i.type.value}(0);
1521
+ }
1522
+ `,u=`value += tile_a[k][local_id.y] * tile_b[k][local_id.x];`):!t.transA&&t.transB?(d=`
1523
+ var col = k_start + local_id.x;
1524
+ var row = tile_row_start + local_id.y;
1525
+ if (col < uniforms.K && row < uniforms.M) {
1526
+ tile_a[local_id.y][local_id.x] = a[row * uniforms.K + col];
1527
+ } else {
1528
+ tile_a[local_id.y][local_id.x] = ${r.type.value}(0);
1529
+ }
1530
+
1531
+ col = k_start + local_id.x;
1532
+ row = tile_col_start + local_id.y;
1533
+ if (col < uniforms.K && row < uniforms.N) {
1534
+ tile_b[local_id.y][local_id.x] = b[row * uniforms.K + col];
1535
+ } else {
1536
+ tile_b[local_id.y][local_id.x] = ${i.type.value}(0);
1537
+ }
1538
+ `,u=`value += tile_a[local_id.y][k] * tile_b[local_id.x][k];`):!t.transA&&!t.transB&&(d=`
1539
+ var col = k_start + local_id.x;
1540
+ var row = tile_row_start + local_id.y;
1541
+ if (col < uniforms.K && row < uniforms.M) {
1542
+ tile_a[local_id.y][local_id.x] = a[row * uniforms.K + col];
1543
+ } else {
1544
+ tile_a[local_id.y][local_id.x] = ${r.type.value}(0);
1545
+ }
1546
+
1547
+ col = tile_col_start + local_id.x;
1548
+ row = k_start + local_id.y;
1549
+ if (col < uniforms.N && row < uniforms.K) {
1550
+ tile_b[local_id.y][local_id.x] = b[row * uniforms.N + col];
1551
+ } else {
1552
+ tile_b[local_id.y][local_id.x] = ${i.type.value}(0);
1553
+ }
1554
+ `,u=`value += tile_a[local_id.y][k] * tile_b[k][local_id.x];`);let f=t.alpha===1?``:`value *= uniforms.alpha;`;return`
1555
+ ${n.registerUniforms(l).declareVariables(...o)}
1556
+ var<workgroup> tile_a: array<array<${r.type.storage}, 16>, 16>;
1557
+ var<workgroup> tile_b: array<array<${i.type.storage}, 16>, 16>;
1558
+ ${n.mainStart([16,16,1])}
1559
+ let tile_col_start = (workgroup_index % uniforms.num_tile_n) * 16;
1560
+ let tile_row_start = (workgroup_index / uniforms.num_tile_n) * 16;
1561
+ let num_tiles = (uniforms.K - 1) / 16 + 1;
1562
+ var k_start = 0u;
1563
+ var value = ${c.type.value}(0);
1564
+ for (var t: u32 = 0u; t < num_tiles; t++) {
1565
+ ${d}
1566
+ k_start = k_start + 16;
1567
+ workgroupBarrier();
1568
+
1569
+ for (var k: u32 = 0u; k < 16; k++) {
1570
+ ${u}
1571
+ }
1572
+ workgroupBarrier();
1573
+ }
1574
+
1575
+ ${f}
1576
+ let m = tile_row_start + local_id.y;
1577
+ let n = tile_col_start + local_id.x;
1578
+ ${a==null?``:`let cOffset = ${a.broadcastedIndicesToOffset(`vec2(m, n)`,c)}; value += ${c.type.value}(uniforms.beta) * ${a.getByOffset(`cOffset`)};`}
1579
+ if (m < uniforms.M && n < uniforms.N) {
1580
+ output[m * uniforms.N + n] = value;
1581
+ }
1582
+ }`}}},rc=e=>({transA:e.transA,transB:e.transB,alpha:e.alpha,beta:e.beta,cacheKey:`${e.transA};${e.transB};${e.alpha===1}`}),ic=(e,t)=>{tc(e.inputs),e.compute(nc(e.inputs,t))}}),oc,sc,cc,lc,uc,dc,fc,pc,mc,hc,gc,_c,vc,yc,bc=M(()=>{H(),G(),Yn(),X(),[oc,sc,cc,lc]=[0,1,2,3],uc=e=>{if(e[0].dims.length!==4)throw Error(`only 4-D tensor is supported.`);if(e[0].dims.length!==e[1].dims.length)throw Error(`input dimensions must be equal to grid dimensions`);if(e[0].dims.length-2!==e[1].dims[e[1].dims.length-1])throw Error(`last dimension of grid must be equal to ${e[0].dims.length-2}`);if(e[0].dims[0]!==e[1].dims[0])throw Error(`grid batch size must match input batch size`)},dc=`
1583
+ fn gs_get_cubic_coeffs(x: f32) -> vec4<f32> {
1584
+ let cubic_alpha = -0.75f;
1585
+ let x_abs = abs(x);
1586
+ var coeffs: vec4<f32>;
1587
+ coeffs[0] = (((cubic_alpha * (x_abs + 1) - 5 * cubic_alpha) * (x_abs + 1) + 8 * cubic_alpha) * (x_abs + 1) - 4 * cubic_alpha);
1588
+ coeffs[1] = (((cubic_alpha + 2) * x_abs - (cubic_alpha + 3)) * x_abs * x_abs + 1);
1589
+ coeffs[2] = (((cubic_alpha + 2) * (1 - x_abs) - (cubic_alpha + 3)) * (1 - x_abs) * (1 - x_abs) + 1);
1590
+ coeffs[3] = (((cubic_alpha * (2 - x_abs) - 5 * cubic_alpha) * (2 - x_abs) + 8 * cubic_alpha) * (2 - x_abs) - 4 * cubic_alpha);
1591
+ return coeffs;
1592
+ }
1593
+ `,fc=e=>`
1594
+ fn gs_bicubic_interpolate(p: mat4x4<${e}>, x: f32, y: f32) -> ${e} {
1595
+ var v: vec4<f32>;
1596
+ var coeffs = gs_get_cubic_coeffs(x);
1597
+ for (var i = 0; i < 4; i++) {
1598
+ v[i] = coeffs[0] * p[i][0] + coeffs[1] * p[i][1] + coeffs[2] * p[i][2] + coeffs[3] * p[i][3];
1599
+ }
1600
+ coeffs = gs_get_cubic_coeffs(y);
1601
+ let pixel = ${e}(coeffs[0] * v[0] + coeffs[1] * v[1] + coeffs[2] * v[2] + coeffs[3] * v[3]);
1602
+ return pixel;
1603
+ }
1604
+ `,pc=e=>`
1605
+ fn gs_denormalize(n: f32, length: i32) -> f32 {
1606
+ ${e.alignCorners===0?`
1607
+ // alignCorners: false => [-1, 1] to [-0.5, length - 0.5]
1608
+ return ((n + 1.0) * f32(length) - 1.0) / 2.0;
1609
+ `:`
1610
+ // alignCorners: true => [-1, 1] to [0, length - 1]
1611
+ return (n + 1.0) / 2.0 * (f32(length - 1));
1612
+ `}
1613
+ }
1614
+ `,mc=e=>`
1615
+ ${e.paddingMode===`reflection`?`
1616
+ fn gs_reflect(x: i32, x_min: f32, x_max: f32) -> u32 {
1617
+ var dx = 0.0;
1618
+ var fx = f32(x);
1619
+ let range = x_max - x_min;
1620
+ if (fx < x_min) {
1621
+ dx = x_min - fx;
1622
+ let n = u32(dx / range);
1623
+ let r = dx - f32(n) * range;
1624
+ if (n % 2 == 0) {
1625
+ fx = x_min + r;
1626
+ } else {
1627
+ fx = x_max - r;
1628
+ }
1629
+ } else if (fx > x_max) {
1630
+ dx = fx - x_max;
1631
+ let n = u32(dx / range);
1632
+ let r = dx - f32(n) * range;
1633
+ if (n % 2 == 0) {
1634
+ fx = x_max - r;
1635
+ } else {
1636
+ fx = x_min + r;
1637
+ }
1638
+ }
1639
+ return u32(fx);
1640
+ }`:``}
1641
+ `,hc=(e,t,n)=>`
1642
+ fn pixel_at_grid(r: i32, c: i32, H: i32, W: i32, batch: u32, channel: u32, border: vec4<f32>) -> ${t} {
1643
+ var pixel = ${t}(0);
1644
+ var indices = vec4<u32>(0);
1645
+ indices[${oc}] = batch;
1646
+ indices[${sc}] = channel;`+(()=>{switch(n.paddingMode){case`zeros`:return`
1647
+ if (r >= 0 && r < H && c >=0 && c < W) {
1648
+ indices[${cc}] = u32(r);
1649
+ indices[${lc}] = u32(c);
1650
+ } else {
1651
+ return ${t}(0);
1652
+ }
1653
+ `;case`border`:return`
1654
+ indices[${cc}] = u32(clamp(r, 0, H - 1));
1655
+ indices[${lc}] = u32(clamp(c, 0, W - 1));
1656
+ `;case`reflection`:return`
1657
+ indices[${cc}] = gs_reflect(r, border[1], border[3]);
1658
+ indices[${lc}] = gs_reflect(c, border[0], border[2]);
1659
+ `;default:throw Error(`padding mode ${n.paddingMode} is not supported`)}})()+`
1660
+ return ${e.getByIndices(`indices`)};
1661
+ }
1662
+ `,gc=(e,t,n)=>(()=>{switch(n.mode){case`nearest`:return`
1663
+ let result = pixel_at_grid(i32(round(y)), i32(round(x)), H_in, W_in, indices[${oc}], indices[${sc}], border);
1664
+ `;case`bilinear`:return`
1665
+ let x1 = i32(floor(x));
1666
+ let y1 = i32(floor(y));
1667
+ let x2 = x1 + 1;
1668
+ let y2 = y1 + 1;
1669
+
1670
+ let p11 = pixel_at_grid(y1, x1, H_in, W_in, indices[${oc}], indices[${sc}], border);
1671
+ let p12 = pixel_at_grid(y1, x2, H_in, W_in, indices[${oc}], indices[${sc}], border);
1672
+ let p21 = pixel_at_grid(y2, x1, H_in, W_in, indices[${oc}], indices[${sc}], border);
1673
+ let p22 = pixel_at_grid(y2, x2, H_in, W_in, indices[${oc}], indices[${sc}], border);
1674
+
1675
+ let dx2 = ${t}(f32(x2) - x);
1676
+ let dx1 = ${t}(x - f32(x1));
1677
+ let dy2 = ${t}(f32(y2) - y);
1678
+ let dy1 = ${t}(y - f32(y1));
1679
+ let result = dy2 * (dx2 * p11 + dx1 * p12) + dy1 * (dx2 * p21 + dx1 * p22);
1680
+ `;case`bicubic`:return`
1681
+ let x0 = i32(floor(x)) - 1;
1682
+ let y0 = i32(floor(y)) - 1;
1683
+ var p: mat4x4<${t}>;
1684
+ for (var h = 0; h < 4; h++) {
1685
+ for (var w = 0; w < 4; w++) {
1686
+ p[h][w] = pixel_at_grid(h + y0, w + x0, H_in, W_in, indices[${oc}], indices[${sc}], border);
1687
+ }
1688
+ }
1689
+
1690
+ let dx = x - f32(x0 + 1);
1691
+ let dy = y - f32(y0 + 1);
1692
+ let result = gs_bicubic_interpolate(p, dx, dy);
1693
+ `;default:throw Error(`mode ${n.mode} is not supported`)}})()+`${e.setByOffset(`global_idx`,`result`)}`,_c=(e,t)=>{let n=J(`x`,e[0].dataType,e[0].dims.length),r=[e[1].dims[0],e[1].dims[1],e[1].dims[2]],i=J(`grid`,e[1].dataType,r.length,2),a=[e[0].dims[0],e[0].dims[1],e[1].dims[1],e[1].dims[2]];t.format===`NHWC`&&(a=[e[0].dims[0],e[1].dims[1],e[1].dims[2],e[0].dims[3]],[oc,sc,cc,lc]=[0,3,1,2]);let o=Y(`output`,e[0].dataType,a.length),s=n.type.value,c=[{type:12,data:W.size(a)},...K(e[0].dims,r,a)];return{name:`GridSample`,shaderCache:{hint:`${t.cacheKey}`,inputDependencies:[`type`,`type`]},getRunData:e=>{let t=W.size(a);return{outputs:[{dims:a,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(t/64)},programUniforms:c}},getShaderSource:e=>`
1694
+ ${e.registerUniform(`output_size`,`u32`).declareVariables(n,i,o)}
1695
+ ${dc}
1696
+ ${fc(s)}
1697
+ ${pc(t)}
1698
+ ${mc(t)}
1699
+ ${hc(n,s,t)}
1700
+
1701
+ ${e.mainStart()}
1702
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)}
1703
+ let H_in = i32(uniforms.x_shape[${cc}]);
1704
+ let W_in = i32(uniforms.x_shape[${lc}]);
1705
+
1706
+ ${t.alignCorners===0?`
1707
+ let x_min = -0.5;
1708
+ let x_max = f32(W_in) - 0.5;
1709
+ let y_min = -0.5;
1710
+ let y_max = f32(H_in) - 0.5;
1711
+ `:`
1712
+ let x_min = 0.0;
1713
+ let x_max = f32(W_in) - 1.0;
1714
+ let y_min = 0.0;
1715
+ let y_max = f32(H_in) - 1.0;
1716
+ `};
1717
+ let border = vec4<f32>(x_min, y_min, x_max, y_max);
1718
+
1719
+ let indices = ${o.offsetToIndices(`global_idx`)};
1720
+ var grid_indices = vec3<u32>(indices[${oc}], indices[${cc}], indices[${lc}]);
1721
+ let nxy = ${i.getByIndices(`grid_indices`)};
1722
+ var x = gs_denormalize(f32(nxy[0]), W_in);
1723
+ var y = gs_denormalize(f32(nxy[1]), H_in);
1724
+
1725
+ ${gc(o,s,t)}
1726
+ }`}},vc=(e,t)=>{uc(e.inputs),e.compute(_c(e.inputs,t))},yc=e=>Jn({alignCorners:e.align_corners,mode:e.mode,paddingMode:e.padding_mode,format:e.format})}),xc,Sc,Cc,wc,Tc,Ec,Dc,Oc=M(()=>{H(),G(),Yn(),In(),Ei(),X(),_r(),xc=(e,t)=>e.length>t&&e[t].dims.length>0?e[t]:void 0,Sc=(e,t)=>{let n=e[0],r=xc(e,1),i=xc(e,2),a=xc(e,3),o=xc(e,4),s=xc(e,5),c=xc(e,6),l=xc(e,7);if(n.dims.length!==3&&n.dims.length!==5)throw Error(`Input query is expected to have 3 or 5 dimensions`);let u=n.dims[0],d=n.dims[1],f=n.dims.length===3?n.dims[2]:t.numHeads*n.dims[4],p=d,m=0,h=0,g=Math.floor(f/t.numHeads);if(c&&l&&W.size(c.dims)&&W.size(l.dims)){if(c.dims.length!==4)throw Error(`Input "past_key" is expected to have 4 dimensions`);if(c.dims[0]!==u||c.dims[1]!==t.numHeads||c.dims[3]!==g)throw Error(`Input "past_key" shape (batch_size, num_heads, past_sequence_length, head_size)`);if(l.dims[0]!==u||l.dims[1]!==t.numHeads||l.dims[3]!==g)throw Error(`Input "past_value" shape (batch_size, num_heads, past_sequence_length, head_size)`);if(c.dims[2]!==l.dims[2])throw Error(`Input "past_key" and "past_value" shall have same dim 2 (past_sequence_length)`);if(l.dims.length!==4)throw Error(`Input "past_value" is expected to have 4 dimensions`);m=c.dims[2],h=c.dims[2]}else if(c&&W.size(c.dims)||l&&W.size(l.dims))throw Error(`Input "past_key" and "past_value" shall be both present or both absent`);let _;if(r&&W.size(r.dims)>0){if(n.dims.length!==3)throw Error(`Input "query" is expected to have 3 dimensions when key is given`);if(r.dims.length<3||r.dims.length>5)throw Error(`Input "key" is expected to have 3, 4, or 5 dimensions`);if(n.dims[0]!==r.dims[0])throw Error(`Input "query" and "key" shall have same dim 0 (batch size)`);if(r.dims.length===3){if(r.dims[2]!==n.dims[2])throw Error(`Input "query" and "key" shall have same dim 2 (hidden_size)`);_=2,p=r.dims[1]}else if(r.dims.length===5){if(r.dims[2]!==t.numHeads||r.dims[3]!==2||r.dims[4]!==g)throw Error(`Expect "key" shape (batch_size, kv_sequence_length, num_heads, 2, head_size) for packed kv`);if(i)throw Error(`Expect "value" be none when "key" has packed kv format.`);_=5,p=r.dims[1]}else{if(r.dims[1]!==t.numHeads||r.dims[3]!==g)throw Error(`Expect "key" shape (batch_size, num_heads, kv_sequence_length, head_size) for past_key`);_=0,p=r.dims[2]}}else{if(n.dims.length!==5)throw Error(`Input "query" is expected to have 5 dimensions when key is empty`);if(n.dims[2]!==t.numHeads||n.dims[3]!==3)throw Error(`Expect "query" shape (batch_size, kv_sequence_length, num_heads, 3, head_size) for packed kv`);_=3}if(a&&W.size(a.dims)>0){if(a.dims.length!==1)throw Error(`Input "bias" is expected to have 1 dimension`);if(r&&r.dims.length===5&&r.dims[3]===2)throw Error(`bias is not allowed for packed kv.`)}let v=m+p,y=0;if(o&&W.size(o.dims)>0){y=8;let e=o.dims;throw e.length===1?e[0]===u?y=1:e[0]===3*u+2&&(y=3):e.length===2&&e[0]===u&&e[1]===v&&(y=5),Error(y===8?`Input "key_padding_mask" shape shall be (batch_size) or (batch_size, total_sequence_length)`:`Mask not supported`)}let b=!1,x=f;if(i&&W.size(i.dims)>0){if(i.dims.length!==3&&i.dims.length!==4)throw Error(`Input "value" is expected to have 3 or 4 dimensions`);if(n.dims[0]!==i.dims[0])throw Error(`Input "query" and "value" shall have same dim 0 (batch_size)`);if(i.dims.length===3){if(p!==i.dims[1])throw Error(`Input "key" and "value" shall have the same dim 1 (kv_sequence_length)`);x=i.dims[2]}else{if(p!==i.dims[2])throw Error(`Input "key" and "value" shall have the same dim 2 (kv_sequence_length)`);x=i.dims[1]*i.dims[3],b=!0}}if(o&&W.size(o.dims)>0)throw Error(`Key padding mask is not supported`);if(s&&W.size(s.dims)>0){if(s.dims.length!==4)throw Error(`Input "attention_bias" is expected to have 4 dimensions`);if(s.dims[0]!==u||s.dims[1]!==t.numHeads||s.dims[2]!==d||s.dims[3]!==v)throw Error(`Expect "attention_bias" shape (batch_size, num_heads, sequence_length, total_sequence_length)`)}return{batchSize:u,sequenceLength:d,pastSequenceLength:m,kvSequenceLength:p,totalSequenceLength:v,maxSequenceLength:h,inputHiddenSize:0,hiddenSize:f,vHiddenSize:x,headSize:g,vHeadSize:Math.floor(x/t.numHeads),numHeads:t.numHeads,isUnidirectional:!1,pastPresentShareBuffer:!1,maskFilterValue:t.maskFilterValue,maskType:y,scale:t.scale,broadcastResPosBias:!1,passPastInKv:b,qkvFormat:_}},Cc=e=>Jn({...e}),wc=Jn({perm:[0,2,1,3]}),Tc=(e,t,n,r,i,a,o)=>{let s=[r,i,a],c=W.size(s),l=[{type:12,data:c},{type:12,data:o},{type:12,data:a}];return e.compute({name:`MultiHeadAttentionAddBias`,shaderCache:{inputDependencies:[`type`,`type`]},getRunData:()=>({outputs:[{dims:s,dataType:t.dataType,gpuDataType:0}],dispatchGroup:{x:Math.ceil(c/64)},programUniforms:l}),getShaderSource:e=>{let r=Y(`qkv_with_bias`,t.dataType,s),i=J(`qkv`,t.dataType,s),a=J(`bias`,n.dataType,s);return`
1727
+ ${e.registerUniforms([{name:`output_size`,type:`u32`},{name:`bias_offset`,type:`u32`},{name:`hidden_size`,type:`u32`}]).declareVariables(i,a,r)}
1728
+ ${e.mainStart()}
1729
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)}
1730
+ let bias_offset_idx = (global_idx % uniforms.hidden_size) + uniforms.bias_offset;
1731
+
1732
+ qkv_with_bias[global_idx] = qkv[global_idx] + bias[bias_offset_idx];
1733
+ }`}},{inputs:[t,n],outputs:[-1]})[0]},Ec=(e,t,n,r,i,a,o,s)=>{let c=a;if(o&&W.size(o.dims)>0){if(r===1)throw Error(`AddBiasReshape is not implemented. Please export your model with packed QKV or KV`);return c=Tc(e,a,o,t,r,n*i,s),c=c.reshape([t,r,n,i]),n===1||r===1?c:e.compute(mr(c,wc.perm),{inputs:[c],outputs:[-1]})[0]}else return a.dims.length===3&&(c=a.reshape([t,r,n,i])),n===1||r===1?c:e.compute(mr(c,wc.perm),{inputs:[c],outputs:[-1]})[0]},Dc=(e,t)=>{let n=Sc(e.inputs,t),r=e.inputs[0],i=xc(e.inputs,1),a=xc(e.inputs,2),o=xc(e.inputs,3),s=xc(e.inputs,4),c=xc(e.inputs,5),l=xc(e.inputs,6),u=xc(e.inputs,7);if(r.dims.length===5)throw Error(`Packed QKV is not implemented`);if(i?.dims.length===5)throw Error(`Packed KV is not implemented`);let d=i&&a&&i.dims.length===4&&a.dims.length===4,f=Ec(e,n.batchSize,n.numHeads,n.sequenceLength,n.headSize,r,o,0);if(d)return Ci(e,f,i,a,s,void 0,l,u,c,n);if(!i||!a)throw Error(`key and value must be provided`);let p=Ec(e,n.batchSize,n.numHeads,n.kvSequenceLength,n.headSize,i,o,n.hiddenSize),m=Ec(e,n.batchSize,n.numHeads,n.kvSequenceLength,n.vHeadSize,a,o,2*n.hiddenSize);Ci(e,f,p,m,s,void 0,l,u,c,n)}}),kc,Ac,jc,Mc,Nc,Pc,Fc,Ic=M(()=>{H(),G(),Yn(),X(),kc=e=>{if(!e||e.length<1)throw Error(`too few inputs`)},Ac=(e,t)=>{let n=[],r=t.numOutputs;return e[1].dims[0]>0&&(e[1].getBigInt64Array().forEach(e=>n.push(Number(e))),r=n.length),Jn({numOutputs:r,axis:t.axis,splitSizes:n})},jc=e=>`
1734
+ fn calculateOutputIndex(index: u32) -> u32 {
1735
+ for (var i: u32 = 0u; i < ${e}u; i += 1u ) {
1736
+ if (index < ${q(`uniforms.size_in_split_axis`,`i`,e)}) {
1737
+ return i;
1738
+ }
1739
+ }
1740
+ return ${e}u;
1741
+ }`,Mc=e=>{let t=e.length,n=[];for(let r=0;r<t;++r){let i=e[r].setByIndices(`indices`,`input[global_idx]`);t===1?n.push(i):r===0?n.push(`if (output_number == ${r}u) { ${i} }`):r===t-1?n.push(`else { ${i} }`):n.push(`else if (output_number == ${r}) { ${i} }`)}return`
1742
+ fn writeBufferData(output_number: u32, indices: ${e[0].type.indices}, global_idx: u32) {
1743
+ ${n.join(`
1744
+ `)}
1745
+ }`},Nc=(e,t)=>{let n=e[0].dims,r=W.size(n),i=e[0].dataType,a=W.normalizeAxis(t.axis,n.length),o=Array(t.numOutputs),s=J(`input`,i,n.length),c=Array(t.numOutputs),l=[],u=[],d=0,f=[{type:12,data:r}];for(let r=0;r<t.numOutputs;r++){d+=t.splitSizes[r],c[r]=d;let s=n.slice();s[a]=t.splitSizes[r],u.push(s),o[r]=Y(`output${r}`,i,s.length),l.push({dims:u[r],dataType:e[0].dataType})}return f.push({type:12,data:c},...K(n,...u)),{name:`Split`,shaderCache:{hint:t.cacheKey,inputDependencies:[`rank`]},getShaderSource:e=>`
1746
+ ${e.registerUniform(`input_size`,`u32`).registerUniform(`size_in_split_axis`,`u32`,c.length).declareVariables(s,...o)}
1747
+ ${jc(c.length)}
1748
+ ${Mc(o)}
1749
+
1750
+ ${e.mainStart()}
1751
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.input_size`)}
1752
+
1753
+ var indices = ${s.offsetToIndices(`global_idx`)};
1754
+ var index = ${s.indicesGet(`indices`,a)};
1755
+ let output_number = calculateOutputIndex(index);
1756
+ if (output_number != 0) {
1757
+ index -= ${q(`uniforms.size_in_split_axis`,`output_number - 1u`,c.length)};
1758
+ ${s.indicesSet(`indices`,a,`index`)};
1759
+ }
1760
+ writeBufferData(output_number, indices, global_idx);
1761
+ }`,getRunData:()=>({outputs:l,dispatchGroup:{x:Math.ceil(r/64)},programUniforms:f})}},Pc=(e,t)=>{kc(e.inputs);let n=e.inputs.length===1?t:Ac(e.inputs,t);e.compute(Nc(e.inputs,n),{inputs:[0]})},Fc=e=>{let t=e.axis,n=e.splitSizes,r=e.numOutputs<0?n.length:e.numOutputs;if(r!==n.length)throw Error(`numOutputs and splitSizes lengh must be equal`);return Jn({axis:t,numOutputs:r,splitSizes:n})}}),Lc,Rc,zc,Bc=M(()=>{H(),G(),Yn(),X(),Lc=(e,t)=>{let[n,r,i,a]=e,{numHeads:o,rotaryEmbeddingDim:s}=t;if(n.dims.length!==3&&n.dims.length!==4)throw Error(`Input 'x' is expected to have 3 or 4 dimensions, got ${n.dims.length}`);if(!W.areEqual(r.dims,[])&&!W.areEqual(r.dims,[1])&&r.dims.length!==2)throw Error(`Input 'position_ids' is expected to have 0, 1, or 2 dimensions, got ${r.dims.length}`);if(i.dims.length!==2)throw Error(`Input 'cos_cache' is expected to have 2 dimensions, got ${i.dims.length}`);if(a.dims.length!==2)throw Error(`Input 'sin_cache' is expected to have 2 dimensions, got ${a.dims.length}`);if(!W.areEqual(i.dims,a.dims))throw Error(`Inputs 'cos_cache' and 'sin_cache' are expected to have the same shape`);if(s>0&&o===0)throw Error(`num_heads must be provided if rotary_embedding_dim is specified`);let c=n.dims[0],l=n.dims[n.dims.length-2],u=i.dims[0],d=W.sizeFromDimension(n.dims,1)/l,f=s===0?i.dims[1]*2:d/o;if(s>f)throw Error(`rotary_embedding_dim must be less than or equal to head_size`);if(r.dims.length===2){if(c!==r.dims[0])throw Error(`Input 'position_ids' dimension 0 should be of size batch_size, got ${r.dims[0]}`);if(l!==r.dims[1])throw Error(`Input 'position_ids' dimension 1 should be of size sequence_length, got ${r.dims[1]}`)}if(f/2!==i.dims[1]&&s/2!==i.dims[1])throw Error(`Input 'cos_cache' dimension 1 should be same as head_size / 2 or rotary_embedding_dim / 2, got ${i.dims[1]}`);if(l>u)throw Error(`Updating cos_cache and sin_cache in RotaryEmbedding is not currently supported`)},Rc=(e,t)=>{let{interleaved:n,numHeads:r,rotaryEmbeddingDim:i,scale:a}=t,o=e[0].dims[0],s=W.sizeFromDimension(e[0].dims,1),c=e[0].dims[e[0].dims.length-2],l=s/c,u=e[2].dims[1],d=i===0?u*2:l/r,f=[o,c,l/d,d-u],p=W.computeStrides(f),m=[{type:1,data:a},{type:12,data:f},{type:12,data:p},...e[0].dims.length===3?Array({type:12,data:[s,l,d,1]}):[],...e[0].dims.length===4?Array({type:12,data:[s,d,c*d,1]}):[],...K(e[0].dims,e[1].dims,e[2].dims,e[3].dims,e[0].dims)];return{name:`RotaryEmbedding`,shaderCache:{hint:Jn({interleaved:n}).cacheKey,inputDependencies:[`rank`,`rank`,`rank`,`rank`]},getShaderSource:t=>{let r=J(`input`,e[0].dataType,e[0].dims.length),i=J(`position_ids`,e[1].dataType,e[1].dims.length),a=J(`cos_cache`,e[2].dataType,e[2].dims.length),o=J(`sin_cache`,e[3].dataType,e[3].dims.length),s=Y(`output`,e[0].dataType,e[0].dims.length);return t.registerUniforms([{name:`scale`,type:`f32`},{name:`global_shape`,type:`u32`,length:f.length},{name:`global_strides`,type:`u32`,length:p.length},{name:`input_output_strides`,type:`u32`,length:p.length}]),`
1762
+ ${t.declareVariables(r,i,a,o,s)}
1763
+
1764
+ ${t.mainStart(Xn)}
1765
+ let half_rotary_emb_dim = uniforms.${a.name}_shape[1];
1766
+ let bsnh = global_idx / uniforms.global_strides % uniforms.global_shape;
1767
+ let size = uniforms.global_shape[0] * uniforms.global_strides[0];
1768
+ ${t.guardAgainstOutOfBoundsWorkgroupSizes(`size`)}
1769
+
1770
+ if (bsnh[3] < half_rotary_emb_dim) {
1771
+ let position_ids_idx =
1772
+ ${i.broadcastedIndicesToOffset(`bsnh.xy`,Y(``,i.type.tensor,2))};
1773
+ let position_id =
1774
+ u32(${i.getByOffset(`position_ids_idx`)}) + select(0, bsnh[1], position_ids_idx == 0);
1775
+ let i = dot(bsnh, uniforms.input_output_strides) + select(0, bsnh[3], ${n});
1776
+ let j = i + select(half_rotary_emb_dim, 1, ${n});
1777
+ let re = ${r.getByOffset(`i`)} * ${a.get(`position_id`,`bsnh[3]`)} -
1778
+ ${r.getByOffset(`j`)} * ${o.get(`position_id`,`bsnh[3]`)};
1779
+ ${s.setByOffset(`i`,`re`)}
1780
+ let im = ${r.getByOffset(`i`)} * ${o.get(`position_id`,`bsnh[3]`)} +
1781
+ ${r.getByOffset(`j`)} * ${a.get(`position_id`,`bsnh[3]`)};
1782
+ ${s.setByOffset(`j`,`im`)}
1783
+ } else {
1784
+ let k = dot(bsnh, uniforms.input_output_strides) + half_rotary_emb_dim;
1785
+ ${s.setByOffset(`k`,r.getByOffset(`k`))}
1786
+ }
1787
+ }`},getRunData:()=>({outputs:[{dims:e[0].dims,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(W.size(f)/Xn)},programUniforms:m})}},zc=(e,t)=>{Lc(e.inputs,t),e.compute(Rc(e.inputs,t))}}),Vc,Hc,Uc,Wc,Gc,Kc=M(()=>{Yn(),H(),Ei(),Oc(),Ic(),_r(),Bc(),X(),Vc=(e,t)=>{if(t.doRotary&&e.length<=7)throw Error(`cos_cache and sin_cache inputs are required if do_rotary is specified`);let n=e[0],r=e[1],i=e[2],a=e[3],o=e[4];if(t.doRotary!==0&&e.length<=7)throw Error(`cos_cast and sin_cache are expected if do_rotary attribute is non-zero`);if(t.localWindowSize!==-1)throw Error(`Local attention is not supported`);if(t.softcap!==0)throw Error(`Softcap is not supported`);if(t.rotaryInterleaved!==0)throw Error(`Rotary interleaved is not supported`);if(t.smoothSoftmax)throw Error(`Smooth softmax is not supported`);if(n.dims.length!==3&&n.dims.length!==5)throw Error(`Input query is expected to have 3 or 5 dimensions`);let s=n.dims[0],c=n.dims[1],l=n.dims.length===3?n.dims[2]:t.numHeads*n.dims[4],u=c,d=0,f=!r||r.dims.length===0,p=Math.floor(f?l/(t.numHeads+2*t.kvNumHeads):l/t.numHeads);f&&(l=p*t.numHeads);let m=a&&a.dims.length!==0,h=o&&o.dims.length!==0;if(m&&a.dims.length===4&&a.dims[0]===s&&a.dims[1]!==t.kvNumHeads&&a.dims[2]===t.kvNumHeads&&a.dims[3]===p)throw Error(`BSNH pastKey/pastValue is not supported`);if(m&&h){if(a.dims.length!==4)throw Error(`Input "past_key" is expected to have 4 dimensions`);if(o.dims.length!==4)throw Error(`Input "past_value" is expected to have 4 dimensions`);d=a.dims[2]}else if(m||h)throw Error(`Input "past_key" and "past_value" shall be both present or both absent`);let g=1;if(r&&r.dims.length>0){if(n.dims.length!==3)throw Error(`Input "query" is expected to have 3 dimensions when key is given`);if(r.dims.length<3||r.dims.length>5)throw Error(`Input "key" is expected to have 3, 4, or 5 dimensions`);if(n.dims[0]!==r.dims[0])throw Error(`Input "query" and "key" shall have same dim 0 (batch size)`);if(r.dims.length===3){if(n.dims[2]%r.dims[2]!==0)throw Error(`Dimension 2 of "query" should be a multiple of "key"`);u=r.dims[1]}else if(r.dims.length===5){if(r.dims[2]!==t.numHeads||r.dims[3]!==2||r.dims[4]!==p)throw Error(`Expect "key" shape (batch_size, kv_sequence_length, num_heads, 2, head_size) for packed kv`);if(i)throw Error(`Expect "value" be none when "key" has packed kv format.`);u=r.dims[1]}else{if(r.dims[1]!==t.numHeads||r.dims[3]!==p)throw Error(`Expect "key" shape (batch_size, num_heads, kv_sequence_length, head_size) for past_key`);u=r.dims[2]}}else{if(n.dims.length!==3&&n.dims.length!==5)throw Error(`Input "query" is expected to have 3 or 5 dimensions when key is empty`);if(n.dims.length===5&&(n.dims[2]!==t.numHeads||n.dims[3]!==3))throw Error(`Expect "query" shape (batch_size, kv_sequence_length, num_heads, 3, head_size) for packed kv`);g=3}let _=!1,v=t.kvNumHeads?p*t.kvNumHeads:l;if(i&&i.dims.length>0){if(i.dims.length!==3&&i.dims.length!==4)throw Error(`Input "value" is expected to have 3 or 4 dimensions`);if(n.dims[0]!==i.dims[0])throw Error(`Input "query" and "value" shall have same dim 0 (batch_size)`);if(i.dims.length===3){if(u!==i.dims[1])throw Error(`Input "key" and "value" shall have the same dim 1 (kv_sequence_length)`);v=i.dims[2]}else{if(u!==i.dims[2])throw Error(`Input "past_key" and "past_value" shall have the same dim 2 (kv_sequence_length)`);v=i.dims[1]*i.dims[3],_=!0}}let y=e.length>4?e[5]:void 0;if(y&&y.dims.length!==1&&y.dims[0]!==s)throw Error(`Input "seqlens" is expected to have 1 dimension and the same dim 0 as batch_size`);return{batchSize:s,sequenceLength:c,pastSequenceLength:d,kvSequenceLength:u,totalSequenceLength:-1,maxSequenceLength:-1,inputHiddenSize:0,hiddenSize:l,vHiddenSize:v,headSize:p,vHeadSize:Math.floor(v/t.kvNumHeads),numHeads:t.numHeads,kvNumHeads:t.kvNumHeads,nReps:t.numHeads/t.kvNumHeads,pastPresentShareBuffer:!1,maskType:0,scale:t.scale,broadcastResPosBias:!1,passPastInKv:_,qkvFormat:g}},Hc=Jn({perm:[0,2,1,3]}),Uc=(e,t,n)=>{let r=t,i=n.kvNumHeads;return t.dims.length===3&&n.kvSequenceLength!==0&&(r=t.reshape([n.batchSize,n.kvSequenceLength,i,n.headSize]),r=e.compute(mr(r,Hc.perm),{inputs:[r],outputs:[-1]})[0]),r},Wc=(e,t,n,r)=>{let i=[`type`,`type`],a=[e*t],o=e*t,s=[{type:12,data:o},{type:12,data:t},{type:12,data:e}];return{name:`GeneratePositionIds`,shaderCache:{hint:`${e};${t}`,inputDependencies:i},getRunData:()=>({outputs:[{dims:a,dataType:7}],dispatchGroup:{x:Math.ceil(o/64)},programUniforms:s}),getShaderSource:e=>{let t=J(`seq_lens`,n.dataType,n.dims),i=J(`total_seq_lens`,r.dataType,r.dims),o=Y(`pos_ids`,7,a);return`
1788
+ ${e.registerUniforms([{name:`output_size`,type:`u32`},{name:`sequence_length`,type:`u32`},{name:`batch_size`,type:`u32`}]).declareVariables(t,i,o)}
1789
+ ${e.mainStart()}
1790
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)}
1791
+ let total_sequence_length = u32(${i.getByOffset(`0`)});
1792
+ let is_subsequent_prompt = uniforms.sequence_length > 1 && uniforms.sequence_length != total_sequence_length;
1793
+ let is_first_prompt = !is_subsequent_prompt && uniforms.sequence_length == total_sequence_length;
1794
+ let batch_idx = global_idx / uniforms.sequence_length;
1795
+ let sequence_idx = i32(global_idx % uniforms.sequence_length);
1796
+ var pos_id: i32 = 0;
1797
+ let seqlen = ${t.getByOffset(`batch_idx`)};
1798
+ let total_seqlen = seqlen + 1;
1799
+ if (is_first_prompt) {
1800
+ if (sequence_idx < total_seqlen) {
1801
+ pos_id = sequence_idx;
1802
+ } else {
1803
+ pos_id = 1;
1804
+ }
1805
+ ${o.setByOffset(`global_idx`,`pos_id`)}
1806
+ } else if (is_subsequent_prompt) {
1807
+ let past_seqlen = total_seqlen - i32(uniforms.sequence_length);
1808
+ if (past_seqlen + sequence_idx < total_seqlen) {
1809
+ pos_id = past_seqlen + sequence_idx;
1810
+ } else {
1811
+ pos_id = 1;
1812
+ }
1813
+ ${o.setByOffset(`global_idx`,`pos_id`)}
1814
+ } else if (global_idx < uniforms.batch_size) {
1815
+ ${o.setByOffset(`global_idx`,`seqlen`)}
1816
+ };
1817
+ }
1818
+ `}}},Gc=(e,t)=>{let n=Vc(e.inputs,t);if(e.inputs[0].dims.length===5)throw Error(`Packed QKV is not implemented`);if(e.inputs[1]?.dims.length===5)throw Error(`Packed KV is not implemented`);let r=e.inputs[0],i=e.inputs[1]&&e.inputs[1].dims.length>0?e.inputs[1]:void 0,a=e.inputs[2]&&e.inputs[2].dims.length>0?e.inputs[2]:void 0,o=e.inputs[3]&&e.inputs[3].dims.length!==0?e.inputs[3]:void 0,s=e.inputs[4]&&e.inputs[4].dims.length!==0?e.inputs[4]:void 0,c=e.inputs.length>4?e.inputs[5]:void 0,l=e.inputs.length>5?e.inputs[6]:void 0,u=n.kvNumHeads?n.kvNumHeads:n.numHeads,d=Jn({axis:2,numOutputs:3,splitSizes:[n.numHeads*n.headSize,u*n.headSize,u*n.headSize]}),[f,p,m]=!i&&!a?e.compute(Nc([r],d),{inputs:[r],outputs:[-1,-1,-1]}):[r,i,a],h,g;if(t.doRotary){let r=e.compute(Wc(n.batchSize,n.sequenceLength,c,l),{inputs:[c,l],outputs:[-1]})[0],i=e.inputs[7],a=e.inputs[8],o=Jn({interleaved:t.rotaryInterleaved!==0,numHeads:n.numHeads,rotaryEmbeddingDim:0,scale:t.scale}),s=[f,r,i,a],u=[-1];h=e.compute(Rc(s,o),{inputs:s,outputs:u})[0],s.splice(0,1,p);let d=Jn({interleaved:t.rotaryInterleaved!==0,numHeads:n.kvNumHeads,rotaryEmbeddingDim:0,scale:t.scale});g=e.compute(Rc(s,d),{inputs:s,outputs:u})[0]}let _=Ec(e,n.batchSize,n.numHeads,n.sequenceLength,n.headSize,t.doRotary?h:f,void 0,0),v=Uc(e,t.doRotary?g:p,n),y=Uc(e,m,n);Ci(e,_,v,y,void 0,void 0,o,s,void 0,n,c,l)}}),qc,Jc,Yc,Xc,Zc=M(()=>{H(),G(),_r(),X(),qc=(e,t,n,r,i,a,o,s)=>{let c=er(a),l=c===1?`f32`:`vec${c}f`,u=c===1?`vec2f`:`mat2x${c}f`,d=i*o,f=64;d===1&&(f=256);let p=[i,o,a/c],m=[i,o,2],h=[`rank`,`type`,`type`],g=[];return g.push(...K(p,m)),e.compute({name:`InstanceNormComputeChannelScaleShift`,shaderCache:{hint:`${c};${s};${f}`,inputDependencies:h},getRunData:()=>({outputs:[{dims:m,dataType:1}],dispatchGroup:{x:d},programUniforms:g}),getShaderSource:e=>{let i=J(`x`,t.dataType,3,c),a=[i,J(`scale`,n.dataType,n.dims),J(`bias`,r.dataType,r.dims),Y(`output`,1,3,2)];return`
1819
+ var<workgroup> workgroup_shared : array<${u}, ${f}>;
1820
+ const workgroup_size = ${f}u;
1821
+ ${e.declareVariables(...a)}
1822
+ ${e.mainStart(f)}
1823
+ let batch = workgroup_index / uniforms.x_shape[1];
1824
+ let channel = workgroup_index % uniforms.x_shape[1];
1825
+ let hight = uniforms.x_shape[2];
1826
+ // initialize workgroup memory
1827
+ var sum = ${l}(0);
1828
+ var squared_sum = ${l}(0);
1829
+ for (var h = local_idx; h < hight; h += workgroup_size) {
1830
+ let value = ${l}(${i.get(`batch`,`channel`,`h`)});
1831
+ sum += value;
1832
+ squared_sum += value * value;
1833
+ }
1834
+ workgroup_shared[local_idx] = ${u}(sum, squared_sum);
1835
+ workgroupBarrier();
1836
+
1837
+ for (var currSize = workgroup_size >> 1; currSize > 0; currSize = currSize >> 1) {
1838
+ if (local_idx < currSize) {
1839
+ workgroup_shared[local_idx] = workgroup_shared[local_idx] + workgroup_shared[local_idx + currSize];
1840
+ }
1841
+ workgroupBarrier();
1842
+ }
1843
+ if (local_idx == 0) {
1844
+ let sum_final = ${rr(`workgroup_shared[0][0]`,c)} / f32(hight * ${c});
1845
+ let squared_sum_final = ${rr(`workgroup_shared[0][1]`,c)} / f32(hight * ${c});
1846
+
1847
+ let inv_std_dev = inverseSqrt(squared_sum_final - sum_final * sum_final + f32(${s}));
1848
+ let channel_scale = inv_std_dev * f32(scale[channel]);
1849
+ let channel_shift = f32(bias[channel]) - sum_final * channel_scale;
1850
+ output[workgroup_index] = vec2f(channel_scale, channel_shift);
1851
+ }
1852
+ }`}},{inputs:[t,n,r],outputs:[-1]})[0]},Jc=(e,t,n)=>{let r=t[0].dims,i=r,a=r[0],o=r[1],s=W.sizeFromDimension(r,2),c=er(s),l=W.size(i)/c,u=qc(e,t[0],t[1],t[2],a,s,o,n.epsilon),d=[a,o,s/c],f=[a,o];e.compute({name:`InstanceNormalization`,shaderCache:{hint:`${c}`,inputDependencies:[`type`,`none`]},getRunData:()=>({outputs:[{dims:i,dataType:t[0].dataType}],dispatchGroup:{x:Math.ceil(l/64)},programUniforms:[{type:12,data:l},...K(d,f,d)]}),getShaderSource:e=>{let n=J(`x`,t[0].dataType,d.length,c),r=J(`scale_shift`,1,f.length,2),i=Y(`output`,t[0].dataType,d.length,c),a=[n,r,i];return`
1853
+ ${e.registerUniform(`output_size`,`u32`).declareVariables(...a)}
1854
+ ${e.mainStart()}
1855
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)}
1856
+ let outputIndices = ${i.offsetToIndices(`global_idx`)};
1857
+ let batch = outputIndices[0];
1858
+ let channel = outputIndices[1];
1859
+ let scale_shift = ${r.getByIndices(`vec2<u32>(batch, channel)`)};
1860
+ let value = ${n.getByOffset(`global_idx`)} * ${i.type.value}(scale_shift.x) + ${i.type.value}(scale_shift.y);
1861
+ ${i.setByOffset(`global_idx`,`value`)};
1862
+ }`}},{inputs:[t[0],u]})},Yc=(e,t,n)=>{let r=t[0].dims,i=r,a=r[0],o=r[r.length-1],s=W.sizeFromDimension(r,1)/o,c=er(o),l=W.size(i)/c,u=[{type:12,data:s},{type:12,data:Math.floor(o/c)}],d=[`type`,`type`],f=!1,p=[0,r.length-1];for(let e=0;e<r.length-2;e++)f||=r[e+1]!==1,p.push(e+1);f&&=r[r.length-1]!==1;let m=f?e.compute(mr(e.inputs[0],p),{inputs:[e.inputs[0]],outputs:[-1]})[0]:e.inputs[0].reshape(Array.from({length:r.length},(e,t)=>r[p[t]])),h=qc(e,m,t[1],t[2],a,s,o,n.epsilon);e.compute({name:`InstanceNormalizationNHWC`,shaderCache:{hint:`${c}`,inputDependencies:d},getRunData:()=>({outputs:[{dims:i,dataType:t[0].dataType}],dispatchGroup:{x:Math.ceil(l/64)},programUniforms:u}),getShaderSource:e=>{let n=Qn(t[0].dataType),r=c===1?`vec2f`:`mat${c}x2f`,a=e=>{let t=e===0?`x`:`y`,r=c===1?`f32`:`vec${c}f`;switch(c){case 1:return`${n}(${r}(scale.${t}))`;case 2:return`vec2<${n}>(${r}(scale[0].${t}, scale[1].${t}))`;case 4:return`vec4<${n}>(${r}(scale[0].${t}, scale[1].${t}, scale[2].${t}, scale[3].${t}))`;default:throw Error(`Not supported compoents ${c}`)}},o=J(`input`,t[0].dataType,t[0].dims,c),s=Y(`output`,t[0].dataType,i,c);return`
1863
+ @group(0) @binding(0) var<storage, read> input : array<${o.type.storage}>;
1864
+ @group(0) @binding(1) var<storage, read> scale_input : array<${r}>;
1865
+ @group(0) @binding(2) var<storage, read_write> output : array<${s.type.storage}>;
1866
+ struct Uniforms {H: u32, C : u32};
1867
+ @group(0) @binding(3) var<uniform> uniforms: Uniforms;
1868
+
1869
+ ${e.mainStart()}
1870
+ let current_image_number = global_idx / (uniforms.C * uniforms.H);
1871
+ let current_channel_number = global_idx % uniforms.C;
1872
+
1873
+ let scale_offset = current_image_number * uniforms.C + current_channel_number;
1874
+ let scale = scale_input[scale_offset];
1875
+ output[global_idx] = fma(input[global_idx], ${a(0)}, ${a(1)});
1876
+ }`}},{inputs:[t[0],h]})},Xc=(e,t)=>{t.format===`NHWC`?Yc(e,e.inputs,t):Jc(e,e.inputs,t)}}),Qc,$c,el,tl=M(()=>{H(),G(),X(),Qc=e=>{if(!e||e.length<2)throw Error(`layerNorm requires at least 2 inputs.`)},$c=(e,t,n)=>{let r=t.simplified,i=e[0].dims,a=e[1],o=!r&&e[2],s=i,c=W.normalizeAxis(t.axis,i.length),l=W.sizeToDimension(i,c),u=W.sizeFromDimension(i,c),d=W.size(a.dims),f=o?W.size(o.dims):0;if(d!==u||o&&f!==u)throw Error(`Size of X.shape()[axis:] == ${u}.
1877
+ Size of scale and bias (if provided) must match this.
1878
+ Got scale size of ${d} and bias size of ${f}`);let p=[];for(let e=0;e<i.length;++e)e<c?p.push(i[e]):p.push(1);let m=er(u),h=[`type`,`type`],g=[{type:12,data:l},{type:1,data:u},{type:12,data:Math.floor(u/m)},{type:1,data:t.epsilon}];o&&h.push(`type`);let _=n>1,v=n>2,y=t=>{let n=Qn(e[0].dataType),i=[J(`x`,e[0].dataType,e[0].dims,m),J(`scale`,a.dataType,a.dims,m)];return o&&i.push(J(`bias`,o.dataType,o.dims,m)),i.push(Y(`output`,e[0].dataType,s,m)),_&&i.push(Y(`mean_data_output`,1,p)),v&&i.push(Y(`inv_std_output`,1,p)),`
1879
+ ${t.registerUniforms([{name:`norm_count`,type:`u32`},{name:`norm_size`,type:`f32`},{name:`norm_size_vectorized`,type:`u32`},{name:`epsilon`,type:`f32`}]).declareVariables(...i)}
1880
+ ${t.mainStart()}
1881
+ ${t.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.norm_count`)}
1882
+ let offset = global_idx * uniforms.norm_size_vectorized;
1883
+ var mean_vector = ${tr(`f32`,m)};
1884
+ var mean_square_vector = ${tr(`f32`,m)};
1885
+
1886
+ for (var h: u32 = 0u; h < uniforms.norm_size_vectorized; h++) {
1887
+ let value = ${nr(n,m,`x[h + offset]`)};
1888
+ mean_vector += value;
1889
+ mean_square_vector += value * value;
1890
+ }
1891
+ let mean = ${rr(`mean_vector`,m)} / uniforms.norm_size;
1892
+ let inv_std_dev = inverseSqrt(${rr(`mean_square_vector`,m)} / uniforms.norm_size ${r?``:`- mean * mean`} + uniforms.epsilon);
1893
+
1894
+ for (var j: u32 = 0; j < uniforms.norm_size_vectorized; j++) {
1895
+ let f32input = ${nr(n,m,`x[j + offset]`)};
1896
+ let f32scale = ${nr(n,m,`scale[j]`)};
1897
+ output[j + offset] = ${i[0].type.value}((f32input ${r?``:`- mean`}) * inv_std_dev * f32scale
1898
+ ${o?`+ ${nr(n,m,`bias[j]`)}`:``}
1899
+ );
1900
+ }
1901
+
1902
+ ${_?`mean_data_output[global_idx] = mean`:``};
1903
+ ${v?`inv_std_output[global_idx] = inv_std_dev`:``};
1904
+ }`},b=[{dims:s,dataType:e[0].dataType}];return _&&b.push({dims:p,dataType:1}),v&&b.push({dims:p,dataType:1}),{name:`LayerNormalization`,shaderCache:{hint:`${m};${n};${r}`,inputDependencies:h},getRunData:()=>({outputs:b,dispatchGroup:{x:Math.ceil(l/64)},programUniforms:g}),getShaderSource:y}},el=(e,t)=>{Qc(e.inputs),e.compute($c(e.inputs,t,e.outputCount))}}),nl,rl,il=M(()=>{G(),fo(),xo(),nl=e=>{if(!e||e.length!==2)throw Error(`MatMul requires 2 inputs.`);if(e[0].dims[e[0].dims.length-1]!==e[1].dims[e[1].dims.length-2])throw Error(`shared dimension does not match.`)},rl=e=>{nl(e.inputs);let t=mn.calcShape(e.inputs[0].dims,e.inputs[1].dims,!0);if(!t)throw Error(`Can't use matmul on the given tensors`);let n=t[t.length-1],r=e.inputs[0].dims[e.inputs[0].dims.length-1];if(n<8&&r<8)e.compute(uo(e.inputs,{activation:``},t));else{let i=t[t.length-2],a=W.size(e.inputs[0].dims.slice(0,-2)),o=W.size(e.inputs[1].dims.slice(0,-2));if(a!==1&&i===1&&o===1){let i=e.inputs[0].reshape([1,a,r]),o=e.inputs[1].reshape([1,r,n]),s=[1,a,n],c=[i,o];e.compute(bo(c,{activation:``},t,s),{inputs:c})}else e.compute(bo(e.inputs,{activation:``},t))}}}),al,ol,sl,cl,ll,ul=M(()=>{H(),G(),Yn(),X(),al=(e,t)=>{if(e.length<3||e.length>4)throw Error(`MatMulNBits requires 3 or 4 inputs`);let n=e[0],r=n.dims.length;if(n.dims[r-1]!==t.k)throw Error(`The last dim of input shape does not match the k value`);let i=Math.floor((t.k+t.blockSize-1)/t.blockSize),a=t.blockSize/8*t.bits,o=e[1];if(!W.areEqual(o.dims,[t.n,i,a]))throw Error(`The second inputs must be 3D tensor with shape N X nBlocksPerCol X blobSize`);let s=e[2].dims;if(W.size(s)!==t.n*i)throw Error(`scales input size error.`);if(e.length===4){let n=e[3].dims,r=t.bits>4?t.n*i:t.n*Math.floor((i+1)/2);if(W.size(n)!==r)throw Error(`zeroPoints input size error.`)}},ol=(e,t)=>{let n=e[0].dims,r=n.length,i=n[r-2],a=t.k,o=t.n,s=n.slice(0,r-2),c=W.size(s),l=e[1].dims[2]/4,u=e[0].dataType,d=er(t.k),f=er(l),p=er(o),m=s.concat([i,o]),h=i>1&&o/p%2==0?2:1,g=W.size(m)/p/h,_=[],v=[c,i,a/d],y=W.convertShape(e[1].dims).slice();y.splice(-1,1,l/f),_.push(...K(v)),_.push(...K(y)),_.push(...K(e[2].dims)),e.length===4&&_.push(...K(W.convertShape(e[3].dims)));let b=[c,i,o/p];return _.push(...K(b)),{name:`MatMulNBits`,shaderCache:{hint:`${t.blockSize};${t.bits};${d};${f};${p};${h};64`,inputDependencies:Array(e.length).fill(`rank`)},getRunData:()=>({outputs:[{dims:m,dataType:u}],dispatchGroup:{x:g},programUniforms:_}),getShaderSource:n=>{let r=v.length,i=J(`a`,e[0].dataType,r,d),a=J(`b`,12,y.length,f),o=J(`scales`,e[2].dataType,e[2].dims.length),s=[i,a,o],c=e.length===4?J(`zero_points`,12,e[3].dims.length):void 0;c&&s.push(c);let u=b.length,m=Y(`output`,e[0].dataType,u,p),g=Qn(e[0].dataType),_=(()=>{switch(d){case 1:return`array<${g}, 8>`;case 2:return`mat4x2<${g}>`;case 4:return`mat2x4<${g}>`;default:throw Error(`${d}-component is not supported.`)}})(),x=()=>{let e=`
1905
+ // reuse a data
1906
+ var input_offset = ${i.indicesToOffset(`${i.type.indices}(batch, row, word_offset)`)};
1907
+ var a_data: ${_};
1908
+ for (var j: u32 = 0; j < ${8/d}; j++) {
1909
+ a_data[j] = ${i.getByOffset(`input_offset`)};
1910
+ input_offset++;
1911
+ }
1912
+ `;for(let t=0;t<p*h;t++)e+=`
1913
+ b_value = ${f===1?`b${t}_data`:`b${t}_data[i]`};
1914
+ b_value_lower = unpack4xU8(b_value & b_mask);
1915
+ b_value_upper = unpack4xU8((b_value >> 4) & b_mask);
1916
+ b_quantized_values = ${_}(${Array.from({length:4},(e,t)=>`${g}(b_value_lower[${t}]), ${g}(b_value_upper[${t}])`).join(`, `)});
1917
+ b_dequantized_values = ${d===1?`${_}(${Array.from({length:8},(e,n)=>`(b_quantized_values[${n}] - ${c?`zero_point${t}`:`zero_point`}) * scale${t}`).join(`, `)});`:`(b_quantized_values - ${_}(${Array(8).fill(`${c?`zero_point${t}`:`zero_point`}`).join(`,`)})) * scale${t};`};
1918
+ workgroup_shared[local_id.x * ${h} + ${Math.floor(t/p)}]${p>1?`[${t%p}]`:``} += ${Array.from({length:8/d},(e,t)=>`${d===1?`a_data[${t}] * b_dequantized_values[${t}]`:`dot(a_data[${t}], b_dequantized_values[${t}])`}`).join(` + `)};
1919
+ `;return e},S=()=>{let e=`
1920
+ var col_index = col * ${p};
1921
+ ${c?`
1922
+ let zero_point_bytes_per_col = (nBlocksPerCol + 1) / 2;
1923
+ var zero_point_byte_count: u32;
1924
+ var zero_point_word_index: u32;
1925
+ var zero_point_byte_offset: u32;
1926
+ let zero_point_nibble_offset: u32 = block & 0x1u;
1927
+ var zero_point_bits_offset: u32;
1928
+ var zero_point_word: u32;`:`
1929
+ // The default zero point is 8 for unsigned 4-bit quantization.
1930
+ let zero_point = ${g}(8);`}
1931
+ `;for(let t=0;t<p*h;t++)e+=`
1932
+ let scale${t} = ${o.getByOffset(`col_index * nBlocksPerCol + block`)};
1933
+ ${c?`
1934
+ zero_point_byte_count = col_index * zero_point_bytes_per_col + (block >> 0x1u);
1935
+ zero_point_word_index = zero_point_byte_count >> 0x2u;
1936
+ zero_point_byte_offset = zero_point_byte_count & 0x3u;
1937
+ zero_point_bits_offset = (zero_point_byte_offset << 3) + (zero_point_nibble_offset << 2);
1938
+ zero_point_word = ${c.getByOffset(`zero_point_word_index`)} >> zero_point_bits_offset;
1939
+ let zero_point${t} = ${g}((zero_point_word) & 0xFu);`:``}
1940
+ col_index += 1;`;return e},C=()=>{let e=`col_index = col * ${p};`;for(let t=0;t<p*h;t++)e+=`
1941
+ let b${t}_data = ${a.getByIndices(`${a.type.indices}(col_index, block, word)`)};
1942
+ col_index += 1;`;return e+=`
1943
+ var b_value: u32;
1944
+ let b_mask: u32 = 0x0F0F0F0Fu;
1945
+ var b_value_lower: vec4<u32>;
1946
+ var b_value_upper: vec4<u32>;
1947
+ var b_quantized_values: ${_};
1948
+ var b_dequantized_values: ${_};`,e};return`
1949
+ var<workgroup> workgroup_shared: array<${m.type.value}, ${h*64}>;
1950
+ ${n.declareVariables(...s,m)}
1951
+ ${n.mainStart([64,1,1])}
1952
+ let output_indices = ${m.offsetToIndices(`(global_idx / 64) * ${h}`)};
1953
+ let col = output_indices[2];
1954
+ let row = output_indices[1];
1955
+ let batch = output_indices[0];
1956
+ let nBlocksPerCol = uniforms.b_shape[1];
1957
+
1958
+ for (var block = local_id.x; block < nBlocksPerCol; block += 64) {
1959
+ //process one block
1960
+ var word_offset: u32 = block * ${t.blockSize/d};
1961
+ ${S()}
1962
+ for (var word: u32 = 0; word < ${l}; word += ${f}) {
1963
+ ${C()}
1964
+ for (var i: u32 = 0; i < ${f}; i++) {
1965
+ ${x()}
1966
+ word_offset += ${8/d};
1967
+ }
1968
+ }
1969
+ }
1970
+ workgroupBarrier();
1971
+
1972
+ if (local_id.x < ${h}) {
1973
+ var output_value: ${m.type.value} = ${m.type.value}(0);
1974
+ var workgroup_shared_offset: u32 = local_id.x;
1975
+ for (var b: u32 = 0u; b < 64u; b++) {
1976
+ output_value += workgroup_shared[workgroup_shared_offset];
1977
+ workgroup_shared_offset += ${h};
1978
+ }
1979
+ ${m.setByIndices(`${m.type.indices}(batch, row, col + local_id.x)`,`output_value`)};
1980
+ }
1981
+ }`}}},sl=(e,t)=>{let n=e[0].dims,r=n.length,i=n[r-2],a=t.k,o=t.n,s=n.slice(0,r-2),c=W.size(s),l=e[1].dims[2]/4,u=e[0].dataType,d=er(t.k),f=er(l),p=s.concat([i,o]),m=o%8==0?8:o%4==0?4:1,h=128/m,g=h*f*8,_=g/d,v=g/t.blockSize,y=W.size(p)/m,b=[],x=[c,i,a/d],S=W.convertShape(e[1].dims).slice();S.splice(-1,1,l/f),b.push(...K(x)),b.push(...K(S)),b.push(...K(e[2].dims)),e.length===4&&b.push(...K(W.convertShape(e[3].dims)));let C=[c,i,o];return b.push(...K(C)),{name:`BlockwiseMatMulNBits32`,shaderCache:{hint:`${t.blockSize};${d};${f};${h};${m}`,inputDependencies:Array(e.length).fill(`rank`)},getRunData:()=>({outputs:[{dims:p,dataType:u}],dispatchGroup:{x:y},programUniforms:b}),getShaderSource:n=>{let r=x.length,i=J(`a`,e[0].dataType,r,d),a=J(`b`,12,S.length,f),o=J(`scales`,e[2].dataType,e[2].dims.length),s=[i,a,o],c=e.length===4?J(`zero_points`,12,e[3].dims.length):void 0;c&&s.push(c);let l=C.length,u=Y(`output`,e[0].dataType,l),p=Qn(e[0].dataType),g=()=>{switch(d){case 1:return`
1982
+ let a_data0 = vec4<${p}>(sub_a[word_offset], sub_a[word_offset + 1], sub_a[word_offset + 2], sub_a[word_offset + 3]);
1983
+ let a_data1 = vec4<${p}>(sub_a[word_offset + 4], sub_a[word_offset + 5], sub_a[word_offset + 6], sub_a[word_offset + 7]);`;case 2:return`
1984
+ let a_data0 = vec4<${p}>(sub_a[word_offset], sub_a[word_offset + 1]);
1985
+ let a_data1 = vec4<${p}>(sub_a[word_offset + 2], sub_a[word_offset + 3]);`;case 4:return`
1986
+ let a_data0 = sub_a[word_offset];
1987
+ let a_data1 = sub_a[word_offset + 1];`;default:throw Error(`${d}-component is not supported.`)}};return`
1988
+ var<workgroup> sub_a: array<${i.type.value}, ${_}>;
1989
+ var<workgroup> inter_results: array<array<${u.type.value}, ${h}>, ${m}>;
1990
+ ${n.declareVariables(...s,u)}
1991
+ ${n.mainStart([h,m,1])}
1992
+ let output_indices = ${u.offsetToIndices(`workgroup_index * ${m}`)};
1993
+ let col = output_indices[2];
1994
+ let row = output_indices[1];
1995
+ let batch = output_indices[0];
1996
+ let n_blocks_per_col = uniforms.b_shape[1];
1997
+ let num_tiles = (n_blocks_per_col - 1) / ${v} + 1;
1998
+
1999
+ // Loop over shared dimension.
2000
+ for (var tile: u32 = 0; tile < num_tiles; tile += 1) {
2001
+ let a_col_start = tile * ${_};
2002
+ // load one tile A data into shared memory.
2003
+ for (var a_offset = local_idx; a_offset < ${_}; a_offset += 128)
2004
+ {
2005
+ let a_col = a_col_start + a_offset;
2006
+ if (a_col < uniforms.a_shape[2])
2007
+ {
2008
+ sub_a[a_offset] = ${i.getByIndices(`${i.type.indices}(batch, row, a_col)`)};
2009
+ } else {
2010
+ sub_a[a_offset] = ${i.type.value}(0);
2011
+ }
2012
+ }
2013
+ workgroupBarrier();
2014
+
2015
+ // each thread process one block
2016
+ let b_row = col + local_id.y;
2017
+ let block = tile * ${v} + local_id.x;
2018
+ ${c?`
2019
+ let zero_point_bytes_per_col = (n_blocks_per_col + 1) / 2;
2020
+ let zero_point_byte_count = b_row * zero_point_bytes_per_col + (block >> 0x1u);
2021
+ let zero_point_word_index = zero_point_byte_count >> 0x2u;
2022
+ let zero_point_byte_offset = zero_point_byte_count & 0x3u;
2023
+ let zero_point_nibble_offset: u32 = block & 0x1u;
2024
+ let zero_point_bits_offset = (zero_point_byte_offset << 3) + (zero_point_nibble_offset << 2);
2025
+ let zero_point_word = ${c.getByOffset(`zero_point_word_index`)} >> zero_point_bits_offset;
2026
+ let zero_point = ${p}((zero_point_word) & 0xFu);`:`
2027
+ // The default zero point is 8 for unsigned 4-bit quantization.
2028
+ let zero_point = ${p}(8);`}
2029
+ let scale = ${o.getByOffset(`b_row * n_blocks_per_col + block`)};
2030
+ let b_data = ${a.getByIndices(`${a.type.indices}(b_row, block, 0)`)};
2031
+ var word_offset = local_id.x * ${t.blockSize/d};
2032
+ for (var i: u32 = 0; i < ${f}; i++) {
2033
+ ${g()}
2034
+ let b_value = ${f===1?`b_data`:`b_data[i]`};
2035
+ let b_value_lower = unpack4xU8(b_value & 0x0F0F0F0Fu);
2036
+ let b_value_upper = unpack4xU8((b_value >> 4) & 0x0F0F0F0Fu);
2037
+ let b_quantized_values = mat2x4<${p}>(${Array.from({length:4},(e,t)=>`${p}(b_value_lower[${t}]), ${p}(b_value_upper[${t}])`).join(`, `)});
2038
+ let b_dequantized_values = (b_quantized_values - mat2x4<${p}>(${Array(8).fill(`zero_point`).join(`,`)})) * scale;
2039
+ inter_results[local_id.y][local_id.x] += ${Array.from({length:2},(e,t)=>`${`dot(a_data${t}, b_dequantized_values[${t}])`}`).join(` + `)};
2040
+ word_offset += ${8/d};
2041
+ }
2042
+ workgroupBarrier();
2043
+ }
2044
+
2045
+ if (local_idx < ${m}) {
2046
+ var output_value: ${u.type.value} = ${u.type.value}(0);
2047
+ for (var b = 0u; b < ${h}; b++) {
2048
+ output_value += inter_results[local_idx][b];
2049
+ }
2050
+ if (col + local_idx < uniforms.output_shape[2])
2051
+ {
2052
+ ${u.setByIndices(`${u.type.indices}(batch, row, col + local_idx)`,`output_value`)}
2053
+ }
2054
+ }
2055
+ }`}}},cl=(e,t)=>{al(e.inputs,t),t.blockSize===32&&e.adapterInfo.isVendor(`intel`)&&e.adapterInfo.isArchitecture(`gen-12lp`)?e.compute(sl(e.inputs,t)):e.compute(ol(e.inputs,t))},ll=e=>Jn(e)}),dl,fl,pl,ml,hl,gl,_l,vl,yl,bl=M(()=>{H(),G(),X(),dl=e=>{if(!e||e.length<1)throw Error(`Too few inputs`);if(e[0].dataType!==1&&e[0].dataType!==10)throw Error(`Input type must be float or float16.`);if(e.length>=2){let t=e[0].dims.length*2===e[1].dims[0];if(e.length===4&&(t=e[3].dims[0]*2===e[1].dims[0]),!t)throw Error(`The pads should be a 1D tensor of shape [2 * input_rank] or [2 * num_axes].`)}},fl=(e,t,n)=>{let r=``;for(let i=t-1;i>=0;--i)r+=`
2056
+ k = i32(${e.indicesGet(`indices`,i)}) - ${q(`uniforms.pads`,i,n)};
2057
+ if (k < 0) {
2058
+ break;
2059
+ }
2060
+ if (k >= i32(${q(`uniforms.x_shape`,i,t)})) {
2061
+ break;
2062
+ }
2063
+ offset += k * i32(${q(`uniforms.x_strides`,i,t)});
2064
+ `;return`
2065
+ value = ${e.type.value}(uniforms.constant_value);
2066
+ for (var i = 0; i < 1; i++) {
2067
+ var offset = 0;
2068
+ var k = 0;
2069
+ ${r}
2070
+ value = x[offset];
2071
+ }
2072
+ `},pl=(e,t,n)=>{let r=``;for(let i=t-1;i>=0;--i)r+=`
2073
+ k = i32(${e.indicesGet(`indices`,i)}) - ${q(`uniforms.pads`,i,n)};
2074
+ if (k < 0) {
2075
+ k = -k;
2076
+ }
2077
+ {
2078
+ let _2n_1 = 2 * (i32(${q(`uniforms.x_shape`,i,t)}) - 1);
2079
+ k = k % _2n_1;
2080
+ if(k >= i32(${q(`uniforms.x_shape`,i,t)})) {
2081
+ k = _2n_1 - k;
2082
+ }
2083
+ }
2084
+ offset += k * i32(${q(`uniforms.x_strides`,i,t)});
2085
+ `;return`
2086
+ var offset = 0;
2087
+ var k = 0;
2088
+ ${r}
2089
+ value = x[offset];
2090
+ `},ml=(e,t,n)=>{let r=``;for(let i=t-1;i>=0;--i)r+=`
2091
+ k = i32(${e.indicesGet(`indices`,i)}) - ${q(`uniforms.pads`,i,n)};
2092
+ if (k < 0) {
2093
+ k = 0;
2094
+ }
2095
+ if (k >= i32(${q(`uniforms.x_shape`,i,t)})) {
2096
+ k = i32(${q(`uniforms.x_shape`,i,t)}) - 1;
2097
+ }
2098
+ offset += k * i32(${q(`uniforms.x_strides`,i,t)});
2099
+ `;return`
2100
+ var offset = 0;
2101
+ var k = 0;
2102
+ ${r}
2103
+ value = x[offset];
2104
+ `},hl=(e,t,n)=>{let r=``;for(let i=t-1;i>=0;--i)r+=`
2105
+ k = i32(${e.indicesGet(`indices`,i)}) - ${q(`uniforms.pads`,i,n)};
2106
+ if (k < 0) {
2107
+ k += i32(${q(`uniforms.x_shape`,i,t)}]);
2108
+ }
2109
+ if (k >= i32(${q(`uniforms.x_shape`,i,t)})) {
2110
+ k -= i32(${q(`uniforms.x_shape`,i,t)});
2111
+ }
2112
+ offset += k * i32(${q(`uniforms.x_strides`,i,t)});
2113
+ `;return`
2114
+ var offset = 0;
2115
+ var k = 0;
2116
+ ${r}
2117
+ value = x[offset];
2118
+ `},gl=(e,t,n)=>{switch(n.mode){case 0:return fl(e,t,n.pads.length);case 1:return pl(e,t,n.pads.length);case 2:return ml(e,t,n.pads.length);case 3:return hl(e,t,n.pads.length);default:throw Error(`Invalid mode`)}},_l=(e,t)=>{let n=W.padShape(e[0].dims.slice(),t.pads),r=e[0].dims,i=[{type:12,data:W.size(n)},{type:6,data:t.pads}],a=e.length>=3&&e[2].data;return t.mode===0&&i.push({type:a?e[2].dataType:1,data:t.value}),i.push(...K(e[0].dims,n)),{name:`Pad`,shaderCache:{hint:`${t.mode}${a}`,inputDependencies:[`rank`]},getRunData:()=>({outputs:[{dims:n,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(W.size(n)/64)},programUniforms:i}),getShaderSource:i=>{let o=Y(`output`,e[0].dataType,n.length),s=J(`x`,e[0].dataType,r.length),c=s.type.value,l=gl(o,r.length,t),u=[{name:`output_size`,type:`u32`},{name:`pads`,type:`i32`,length:t.pads.length}];return t.mode===0&&u.push({name:`constant_value`,type:a?c:`f32`}),`
2119
+ ${i.registerUniforms(u).declareVariables(s,o)}
2120
+ ${i.mainStart()}
2121
+ ${i.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)}
2122
+
2123
+ let indices = ${o.offsetToIndices(`global_idx`)};
2124
+
2125
+ var value = ${c}(0);
2126
+ ${l}
2127
+ output[global_idx] = value;
2128
+ }`}}},vl=(e,t)=>{if(e.length>1){let n=e[1].getBigInt64Array(),r=e.length>=3&&e[2].data?e[2].dataType===10?e[2].getUint16Array()[0]:e[2].getFloat32Array()[0]:0,i=e[0].dims.length,a=new Int32Array(2*i).fill(0);if(e.length>=4){let t=e[3].getBigInt64Array();for(let e=0;e<t.length;e++)a[Number(t[e])]=Number(n[e]),a[Number(t[e])+i]=Number(n[e+t.length])}else n.forEach((e,t)=>a[Number(t)]=Number(e));let o=[];return a.forEach(e=>o.push(e)),{mode:t.mode,value:r,pads:o}}else return t},yl=(e,t)=>{dl(e.inputs);let n=vl(e.inputs,t);e.compute(_l(e.inputs,n),{inputs:[0]})}}),xl,Sl,Cl,wl,Tl,El,Dl,Ol,kl,Al,jl,Ml,Nl,Pl,Fl,Il,Ll,Rl,zl,Bl=M(()=>{Qe(),H(),G(),X(),xl=e=>{if(I.webgpu.validateInputContent&&(!e||e.length!==1))throw Error(`Pool ops requires 1 input.`)},Sl=(e,t,n)=>{let r=t.format===`NHWC`,i=e.dims.slice();r&&i.splice(1,0,i.pop());let a=Object.hasOwnProperty.call(t,`dilations`),o=t.kernelShape.slice(),s=t.strides.slice(),c=a?t.dilations.slice():[],l=t.pads.slice();hn.adjustPoolAttributes(n,i,o,s,c,l);let u=hn.computePoolOutputShape(n,i,s,c,o,l,t.autoPad),d=Object.assign({},t);a?Object.assign(d,{kernelShape:o,strides:s,pads:l,dilations:c,cacheKey:t.cacheKey}):Object.assign(d,{kernelShape:o,strides:s,pads:l,cacheKey:t.cacheKey});let f=u.slice();return f.push(f.splice(1,1)[0]),[d,r?f:u]},Cl=(e,t)=>{let n=t.format===`NHWC`,r=W.size(e),i=W.size(t.kernelShape),a=[{type:12,data:r},{type:12,data:i}],o=[{name:`outputSize`,type:`u32`},{name:`kernelSize`,type:`u32`}];if(t.kernelShape.length<=2){let e=t.kernelShape[t.kernelShape.length-1],n=t.strides[t.strides.length-1],r=t.pads[t.pads.length/2-1],i=t.pads[t.pads.length-1],s=!!(r+i);a.push({type:12,data:e},{type:12,data:n},{type:12,data:r},{type:12,data:i}),o.push({name:`kw`,type:`u32`},{name:`sw`,type:`u32`},{name:`pwStart`,type:`u32`},{name:`pwEnd`,type:`u32`});let c=!1;if(t.kernelShape.length===2){let e=t.kernelShape[t.kernelShape.length-2],n=t.strides[t.strides.length-2],r=t.pads[t.pads.length/2-2],i=t.pads[t.pads.length-2];c=!!(r+i),a.push({type:12,data:e},{type:12,data:n},{type:12,data:r},{type:12,data:i}),o.push({name:`kh`,type:`u32`},{name:`sh`,type:`u32`},{name:`phStart`,type:`u32`},{name:`phEnd`,type:`u32`})}return[a,o,!0,s,c]}else{if(n)throw Error(`Pooling with kernelShape.length > 2 is not supported for NHWC format.`);let e=W.computeStrides(t.kernelShape);return a.push({type:12,data:e},{type:12,data:t.pads},{type:12,data:t.strides}),o.push({name:`kernelStrides`,type:`u32`,length:e.length},{name:`pads`,type:`u32`,length:t.pads.length},{name:`strides`,type:`u32`,length:t.strides.length}),[a,o,!!t.pads.reduce((e,t)=>e+t),!1,!1]}},wl=(e,t,n,r,i,a,o,s,c,l,u,d)=>{let f=i.format===`NHWC`,p=t.type.value,m=Y(`output`,t.type.tensor,r);if(i.kernelShape.length<=2){let r=``,l=``,h=``,g=n-(f?2:1);if(r=u?`
2129
+ for (var i: u32 = 0u; i < uniforms.kw; i++) {
2130
+ xIndices[${g}] = indices[${g}] * uniforms.sw - uniforms.pwStart + i;
2131
+ if (xIndices[${g}] < 0 || xIndices[${g}]
2132
+ >= uniforms.x_shape[${g}]) {
2133
+ pad++;
2134
+ continue;
2135
+ }
2136
+ let x_val = x[${t.indicesToOffset(`xIndices`)}];
2137
+ ${a}
2138
+ }`:`
2139
+ for (var i: u32 = 0u; i < uniforms.kw; i++) {
2140
+ xIndices[${g}] = indices[${g}] * uniforms.sw - uniforms.pwStart + i;
2141
+ let x_val = x[${t.indicesToOffset(`xIndices`)}];
2142
+ ${a}
2143
+ }`,i.kernelShape.length===2){let e=n-(f?3:2);l=d?`
2144
+ for (var j: u32 = 0u; j < uniforms.kh; j++) {
2145
+ xIndices[${e}] = indices[${e}] * uniforms.sh - uniforms.phStart + j;
2146
+ if (xIndices[${e}] < 0 || xIndices[${e}] >= uniforms.x_shape[${e}]) {
2147
+ pad += i32(uniforms.kw);
2148
+ continue;
2149
+ }
2150
+ `:`
2151
+ for (var j: u32 = 0u; j < uniforms.kh; j++) {
2152
+ xIndices[${e}] = indices[${e}] * uniforms.sh - uniforms.phStart + j;
2153
+ `,h=`
2154
+ }
2155
+ `}return`
2156
+ ${e.registerUniforms(c).declareVariables(t,m)}
2157
+
2158
+ ${e.mainStart()}
2159
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.outputSize`)}
2160
+
2161
+ let indices = ${m.offsetToIndices(`global_idx`)};
2162
+ var xIndices = ${m.offsetToIndices(`global_idx`)};
2163
+
2164
+ var value = ${p}(${s});
2165
+ var pad = 0;
2166
+ ${l}
2167
+ ${r}
2168
+ ${h}
2169
+ ${o}
2170
+
2171
+ output[global_idx] = value;
2172
+ }`}else{if(f)throw Error(`Pooling with kernelShape.length > 2 is not supported for NHWC format.`);let r=i.kernelShape.length,u=i.pads.length,d=``;return d=l?`
2173
+ if (xIndices[j] >= uniforms.x_shape[j]) {
2174
+ pad++;
2175
+ isPad = true;
2176
+ break;
2177
+ }
2178
+ }
2179
+ if (!isPad) {
2180
+ let x_val = x[${t.indicesToOffset(`xIndices`)}];
2181
+ ${a}
2182
+ }`:`
2183
+ }
2184
+ let x_val = x[${t.indicesToOffset(`xIndices`)}];
2185
+ ${a}
2186
+ `,`
2187
+ ${e.registerUniforms(c).declareVariables(t,m)}
2188
+
2189
+ ${e.mainStart()}
2190
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.outputSize`)}
2191
+ let indices = ${m.offsetToIndices(`global_idx`)};
2192
+ var xIndices = ${m.offsetToIndices(`global_idx`)};
2193
+
2194
+ var offsets: array<u32, ${r}>;
2195
+
2196
+ var value = ${p}(${s});
2197
+ var pad = 0;
2198
+ var isPad = false;
2199
+
2200
+ for (var i: u32 = 0u; i < uniforms.kernelSize; i++) {
2201
+ var offset = i;
2202
+ for (var j = 0u; j < ${r-1}u; j++) {
2203
+ offsets[j] = offset / ${q(`uniforms.kernelStrides`,`j`,r)};
2204
+ offset -= offsets[j] * ${q(`uniforms.kernelStrides`,`j`,r)};
2205
+ }
2206
+ offsets[${r-1}] = offset;
2207
+
2208
+ isPad = false;
2209
+ for (var j = ${n-r}u; j < ${n}u; j++) {
2210
+ xIndices[j] = indices[j] * ${q(`uniforms.strides`,`j - ${n-r}u`,r)}
2211
+ + offsets[j - ${n-r}u] - ${q(`uniforms.pads`,`j - 2u`,u)};
2212
+ ${d}
2213
+ }
2214
+ ${o}
2215
+
2216
+ output[global_idx] = value;
2217
+ }`}},Tl=e=>`${e.format};${e.ceilMode};${e.autoPad};${e.kernelShape.length}`,El=e=>`${Tl(e)};${e.countIncludePad}`,Dl=e=>`${Tl(e)};${e.storageOrder};${e.dilations}`,Ol=e=>({format:e.format,autoPad:[`NOTSET`,`VALID`,`SAME_UPPER`,`SAME_LOWER`][e.auto_pad],ceilMode:e.ceil_mode,kernelShape:e.kernel_shape,strides:e.strides,pads:e.pads}),kl=(e,t,n,r)=>{let[i,a]=Sl(t,r,n),o=J(`x`,t.dataType,t.dims.length),s=o.type.value,c=``;i.countIncludePad?c+=`value /= ${s}(uniforms.kernelSize);`:c+=`value /= ${s}(i32(uniforms.kernelSize) - pad);`;let[l,u,d,f,p]=Cl(a,i);return l.push(...K(t.dims,a)),{name:e,shaderCache:{hint:`${r.cacheKey};${d};${f};${p}`,inputDependencies:[`rank`]},getRunData:()=>({outputs:[{dims:a,dataType:t.dataType}],dispatchGroup:{x:Math.ceil(W.size(a)/64)},programUniforms:l}),getShaderSource:e=>wl(e,o,t.dims.length,a.length,i,`value += x_val;`,c,0,u,d,f,p)}},Al=e=>{let t=e.count_include_pad!==0,n=Ol(e);if(n.ceilMode!==0)throw Error(`using ceil() in shape computation is not yet supported for AveragePool`);let r={countIncludePad:t,...n,cacheKey:``};return{...r,cacheKey:El(r)}},jl=(e,t)=>{xl(e.inputs),e.compute(kl(`AveragePool`,e.inputs[0],!1,t))},Ml={autoPad:``,ceilMode:0,countIncludePad:!1,kernelShape:[],strides:[],pads:[],storageOrder:0,dilations:[]},Nl=e=>{let t=e.format;return{format:t,...Ml,cacheKey:t}},Pl=(e,t)=>{xl(e.inputs),e.compute(kl(`GlobalAveragePool`,e.inputs[0],!0,t))},Fl=(e,t,n,r)=>{let[i,a]=Sl(t,r,n),o=J(`x`,t.dataType,t.dims.length),s=[`rank`],[c,l,u,d,f]=Cl(a,i);return c.push(...K(t.dims,a)),{name:e,shaderCache:{hint:`${r.cacheKey};${u};${d};${f}`,inputDependencies:s},getRunData:()=>({outputs:[{dims:a,dataType:t.dataType}],dispatchGroup:{x:Math.ceil(W.size(a)/64)},programUniforms:c}),getShaderSource:e=>wl(e,o,t.dims.length,a.length,i,`
2218
+ value = max(x_val, value);
2219
+ `,``,t.dataType===10?-65504:-1e5,l,u,d,f)}},Il=(e,t)=>{xl(e.inputs),e.compute(Fl(`MaxPool`,e.inputs[0],!1,t))},Ll=e=>{let t=e.storage_order,n=e.dilations,r=Ol(e);if(t!==0)throw Error(`column major storage order is not yet supported for MaxPool`);if(r.ceilMode!==0)throw Error(`using ceil() in shape computation is not yet supported for MaxPool`);let i={storageOrder:t,dilations:n,...r,cacheKey:``};return{...i,cacheKey:Dl(i)}},Rl=e=>{let t=e.format;return{format:t,...Ml,cacheKey:t}},zl=(e,t)=>{xl(e.inputs),e.compute(Fl(`GlobalMaxPool`,e.inputs[0],!0,t))}}),Vl,Hl,Ul,Wl,Gl=M(()=>{H(),G(),Yn(),X(),Vl=(e,t)=>{if(e.length<2||e.length>3)throw Error(`DequantizeLinear requires 2 or 3 inputs.`);if(e.length===3&&e[1].dims===e[2].dims)throw Error(`x-scale and x-zero-point must have the same shape.`);if(e.length===3&&e[0].dataType!==e[2].dataType)throw Error(`x and x-zero-point must have the same data type.`);if(e[0].dataType===6&&e.length>2)throw Error(`In the case of dequantizing int32 there is no zero point.`);if(e[1].dims.length!==0&&e[1].dims.length!==1&&e[1].dims.length!==e[0].dims.length)throw Error(`scale input must be a scalar, a 1D tensor, or have the same rank as the input tensor.`);if(e.length>2){if(e[0].dataType!==e[2].dataType)throw Error(`x and x-zero-point must have the same data type.`);if(e[1].dims.length!==e[2].dims.length)throw Error(`scale and zero-point inputs must have the same rank.`);if(!e[1].dims.map((t,n)=>t===e[2].dims[n]).reduce((e,t)=>e&&t,!0))throw Error(`scale and zero-point inputs must have the same shape.`)}if(t.blockSize>0){if(e[1].dims.length===0||e[1].dims.length===1&&e[1].dims[0]===1)throw Error(`blockSize must be set only for block quantization.`);if(!e[1].dims.map((n,r)=>r===t.axis||n===e[0].dims[r]).reduce((e,t)=>e&&t,!0))throw Error(`For block qunatization, scale input shape to match the input shape except for the axis`);if(e[1].dims.length!==e[0].dims.length)throw Error(`For block qunatization the scale input rank must be the same as the x rank.`);let n=e[0].dims[t.axis],r=e[1].dims[t.axis];if(t.blockSize<Math.ceil(n/r)||t.blockSize>Math.ceil(n/(r-1)-1))throw Error(`blockSize must be with in the range [ceil(dI / Si), ceil(dI / (Si - 1) - 1)].`)}},Hl=(e,t)=>{let n=W.normalizeAxis(t.axis,e[0].dims.length),r=e[0].dataType,i=r===3,a=e[0].dims,o=e[1].dataType,s=W.size(a),c=r===3||r===2,l=c?[Math.ceil(W.size(e[0].dims)/4)]:e[0].dims,u=e[1].dims,d=e.length>2?e[2]:void 0,f=d?c?[Math.ceil(W.size(d.dims)/4)]:d.dims:void 0,p=u.length===0||u.length===1&&u[0]===1,m=p===!1&&u.length===1,h=er(s),g=p&&(!c||h===4),_=g?h:1,v=g&&!c?h:1,y=J(`input`,c?12:r,l.length,v),b=J(`scale`,o,u.length),x=d?J(`zero_point`,c?12:r,f.length):void 0,S=Y(`output`,o,a.length,_),C=[y,b];x&&C.push(x);let w=[l,u];d&&w.push(f);let T=[{type:12,data:s/_},{type:12,data:n},{type:12,data:t.blockSize},...K(...w,a)];return{name:`DequantizeLinear`,shaderCache:{hint:t.cacheKey,inputDependencies:x?[`rank`,`rank`,`rank`]:[`rank`,`rank`]},getShaderSource:e=>`
2220
+ ${e.registerUniforms([{name:`output_size`,type:`u32`},{name:`axis`,type:`u32`},{name:`block_size`,type:`u32`}]).declareVariables(...C,S)}
2221
+ ${e.mainStart()}
2222
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)}
2223
+ let output_indices = ${S.offsetToIndices(`global_idx`)};
2224
+
2225
+ // Set input x
2226
+ ${c?`
2227
+ let input = ${y.getByOffset(`global_idx / 4`)};
2228
+ let x_vec = ${i?`unpack4xI8(input)`:`unpack4xU8(input)`};
2229
+ let x_value = ${_===1?`x_vec[global_idx % 4]`:`x_vec`};`:`let x_value = ${y.getByOffset(`global_idx`)};`};
2230
+
2231
+ // Set scale input
2232
+ ${p?`let scale_value= ${b.getByOffset(`0`)}`:m?`
2233
+ let scale_index = ${S.indicesGet(`output_indices`,`uniforms.axis`)};
2234
+ let scale_value= ${b.getByOffset(`scale_index`)};`:`
2235
+ var scale_indices: ${b.type.indices} = output_indices;
2236
+ let index = ${b.indicesGet(`scale_indices`,`uniforms.axis`)} / uniforms.block_size;
2237
+ ${b.indicesSet(`scale_indices`,`uniforms.axis`,`index`)};
2238
+ let scale_value= ${b.getByIndices(`scale_indices`)};`};
2239
+
2240
+ // Set zero-point input
2241
+ ${x?p?c?`
2242
+ let zero_point_input = ${x.getByOffset(`0`)};
2243
+ let zero_point_vec = ${i?`unpack4xI8(zero_point_input)`:`unpack4xU8(zero_point_input)`};
2244
+ let zero_point_value= zero_point_vec[0]`:`let zero_point_value = ${x.getByOffset(`0`)}`:m?c?`
2245
+ let zero_point_index = ${S.indicesGet(`output_indices`,`uniforms.axis`)};
2246
+ let zero_point_input = ${x.getByOffset(`zero_point_index / 4`)};
2247
+ let zero_point_vec = ${i?`unpack4xI8(zero_point_input)`:`unpack4xU8(zero_point_input)`};
2248
+ let zero_point_value = zero_point_vec[zero_point_index % 4]`:`
2249
+ let zero_point_index = ${S.indicesGet(`output_indices`,`uniforms.axis`)};
2250
+ let zero_point_value = ${x.getByOffset(`zero_point_index`)};`:c?`
2251
+ let zero_point_offset = ${b.indicesToOffset(`scale_indices`)};
2252
+ let zero_point_input = ${x.getByOffset(`zero_point_offset / 4`)};
2253
+ let zero_point_vec = ${i?`unpack4xI8(zero_point_input)`:`unpack4xU8(zero_point_input)`};
2254
+ let zero_point_value = zero_point_vec[zero_point_offset % 4];`:`let zero_point_value = ${x.getByIndices(`scale_indices`)};`:`let zero_point_value = ${c?i?`i32`:`u32`:y.type.value}(0);`};
2255
+ // Compute and write output
2256
+ ${S.setByOffset(`global_idx`,`${S.type.value}(x_value - zero_point_value) * scale_value`)};
2257
+ }`,getRunData:()=>({outputs:[{dims:a,dataType:o}],dispatchGroup:{x:Math.ceil(s/_/64),y:1,z:1},programUniforms:T})}},Ul=(e,t)=>{Vl(e.inputs,t),e.compute(Hl(e.inputs,t))},Wl=e=>Jn({axis:e.axis,blockSize:e.blockSize})}),Kl,ql,Jl,Yl=M(()=>{Qe(),H(),X(),Kl=(e,t,n)=>{if(e===t||e<t&&n<0||e>t&&n>0)throw Error(`Range these inputs' contents are invalid.`)},ql=(e,t,n,r)=>{let i=Math.abs(Math.ceil((t-e)/n)),a=[i],o=i,s=[{type:12,data:o},{type:r,data:e},{type:r,data:n},...K(a)];return{name:`Range`,shaderCache:{hint:`${r}`},getShaderSource:e=>{let t=Y(`output`,r,a.length),n=t.type.value,i=[{name:`outputSize`,type:`u32`},{name:`start`,type:n},{name:`delta`,type:n}];return`
2258
+ ${e.registerUniforms(i).declareVariables(t)}
2259
+ ${e.mainStart()}
2260
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.outputSize`)}
2261
+ output[global_idx] = uniforms.start + ${n}(global_idx) * uniforms.delta;
2262
+ }`},getRunData:()=>({outputs:[{dims:a,dataType:r}],dispatchGroup:{x:Math.ceil(o/64)},programUniforms:s})}},Jl=e=>{let t=0,n=0,r=0;e.inputs[0].dataType===6?(t=e.inputs[0].getInt32Array()[0],n=e.inputs[1].getInt32Array()[0],r=e.inputs[2].getInt32Array()[0]):e.inputs[0].dataType===1&&(t=e.inputs[0].getFloat32Array()[0],n=e.inputs[1].getFloat32Array()[0],r=e.inputs[2].getFloat32Array()[0]),I.webgpu.validateInputContent&&Kl(t,n,r),e.compute(ql(t,n,r,e.inputs[0].dataType),{inputs:[]})}}),Xl,Zl,Ql,$l,eu,tu,nu=M(()=>{H(),G(),Yn(),X(),Xl=(e,t,n,r)=>{if(e!==`none`&&r!==`i32`&&r!==`u32`&&r!==`f32`)throw Error(`Input ${r} is not supported with reduction ${e}.`);let i=`{
2263
+ var oldValue = 0;
2264
+ loop {
2265
+ let newValueF32 =`,a=`;
2266
+ let newValue = bitcast<i32>(newValueF32);
2267
+ let res = atomicCompareExchangeWeak(&${t}, oldValue, newValue);
2268
+ if res.exchanged {
2269
+ break;
2270
+ }
2271
+ oldValue = res.old_value;
2272
+ }
2273
+ }`;switch(e){case`none`:return`${t}=${n};`;case`add`:return r===`i32`||r===`u32`?`atomicAdd(&${t}, bitcast<${r}>(${n}));`:`
2274
+ ${i}bitcast<${r}>(oldValue) + (${n})${a}`;case`max`:return r===`i32`||r===`u32`?`atomicMax(&${t}, bitcast<${r}>(${n}));`:`
2275
+ ${i}max(bitcast<f32>(oldValue), (${n}))${a}`;case`min`:return r===`i32`||r===`u32`?`atomicMin(&${t}, bitcast<${r}>(${n}));`:`${i}min(bitcast<${r}>(oldValue), (${n}))${a}`;case`mul`:return`${i}(bitcast<${r}>(oldValue) * (${n}))${a}`;default:throw Error(`Reduction ${e} is not supported.`)}},Zl=(e,t)=>`${e===1?`
2276
+ let element_count_dim = uniforms.output_strides;
2277
+ let dim_value = uniforms.output_shape;`:`
2278
+ let element_count_dim = uniforms.output_strides[${t?`i - indices_start`:`i`}];
2279
+ let dim_value = uniforms.output_shape[${t?`i - indices_start`:`i`} + uniforms.last_index_dimension];`}
2280
+
2281
+ if (index >= 0) {
2282
+ if (index >= i32(dim_value)) {
2283
+ index = i32(dim_value - 1);
2284
+ }
2285
+ } else {
2286
+ if (index < -i32(dim_value)) {
2287
+ index = 0;
2288
+ } else {
2289
+ index += i32(dim_value);
2290
+ }
2291
+ }
2292
+ data_offset += u32((u32(index) * element_count_dim));`,Ql=(e,t,n)=>`for (var i = 0u; i < uniforms.num_updates_elements; i++) {
2293
+ let value = updates[uniforms.num_updates_elements * ${n?`global_idx`:`idx`} + i];
2294
+ ${Xl(e.reduction,`output[data_offset + i]`,`value`,t)}
2295
+ }`,$l=(e,t)=>{let n=e[0].dims,r=e[1].dims,i=n,a=Math.ceil(W.size(r)/1),o=r[r.length-1],s=W.sizeFromDimension(n,o),c=W.sizeFromDimension(r,0)/o,l=[{type:12,data:a},{type:12,data:o},{type:12,data:s},...K(e[1].dims,e[2].dims,i)];return{name:`ScatterND`,shaderCache:{hint:`${t.cacheKey}_${t.reduction}`,inputDependencies:[`rank`,`rank`]},getRunData:()=>({outputs:[{dims:i,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(a/64)},programUniforms:l}),getShaderSource:r=>{let a=J(`indices`,e[1].dataType,e[1].dims.length),o=J(`updates`,e[2].dataType,e[2].dims.length,1),s=t.reduction!==`none`&&t.reduction!==``?ar(`output`,e[0].dataType,i.length):Y(`output`,e[0].dataType,i.length,1);return`
2296
+ ${r.registerUniform(`output_size`,`u32`).registerUniform(`last_index_dimension`,`u32`).registerUniform(`num_updates_elements`,`u32`).declareVariables(a,o,s)}
2297
+ ${r.mainStart()}
2298
+ ${r.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)}
2299
+ var hasDuplicates = false;
2300
+ if (${t.reduction===`none`}) {
2301
+ for (var i = 0; i < ${c}; i = i + 1) {
2302
+ for (var j = i + 1; j < ${c}; j = j + 1) {
2303
+ var index_i = i32(indices[i].x);
2304
+ var index_j = i32(indices[j].x);
2305
+ if (index_i == index_j) {
2306
+ hasDuplicates = true;
2307
+ break;
2308
+ }
2309
+ }
2310
+ if (hasDuplicates) {
2311
+ break;
2312
+ }
2313
+ }
2314
+ }
2315
+
2316
+ if (${t.reduction===`none`} && hasDuplicates) {
2317
+ if (global_idx != 0u) {
2318
+ return;
2319
+ }
2320
+ // Process each index-update pair individually when duplicates exist
2321
+ for (var idx = 0u; idx < ${c}u; idx++) {
2322
+ var data_offset = 0u;
2323
+ for (var i = 0u; i < uniforms.last_index_dimension; i++) {
2324
+ var index = i32(indices[idx * uniforms.last_index_dimension + i].x);
2325
+ ${Zl(n.length,!1)}
2326
+ }
2327
+ ${Ql(t,s.type.value,!1)}
2328
+ }
2329
+ return;
2330
+ }
2331
+
2332
+ var data_offset = 0u;
2333
+ var indices_start = uniforms.last_index_dimension * global_idx;
2334
+ var indices_end = indices_start + uniforms.last_index_dimension;
2335
+ for (var i = indices_start; i < indices_end; i++) {
2336
+ var index = i32(indices[i].x);
2337
+ ${Zl(n.length,!0)}
2338
+ }
2339
+ ${Ql(t,s.type.value,!0)}
2340
+ }`}}},eu=e=>Jn({reduction:e.reduction}),tu=(e,t)=>{e.compute($l(e.inputs,t),{inputs:[e.inputs[1],e.inputs[2]],outputs:[]})}}),ru,iu,au,ou,su,cu,lu,uu,du,fu,pu,mu,hu,gu,_u,vu,yu,bu,xu,Su,Cu=M(()=>{H(),G(),Yn(),X(),ru=(e,t)=>{if(e.every(e=>e>0||(()=>{throw Error(`Resize requires scales input values to be positive`)})),e.length>0){if(t.mode===`linear`){if(!(e.length===2||e.length===3||e.length===4&&e[0]===1&&e[1]===1||e.length===4&&e[0]===1&&e[3]===1||e.length===5&&e[0]===1&&e[1]===1))throw Error(`For linear mode, Resize requires scales to be 2D, 3D, 4D with either two outermost or one innermost and
2341
+ one outermost scale values equal to 1, or 5D with two outermost scale values equal to 1`)}else if(t.mode===`cubic`&&!(e.length===2||e.length===4&&e[0]===1&&e[1]===1||e.length===4&&e[0]===1&&e[3]===1))throw Error(`Resize requires scales input size to be 2 or 4 for cubic mode`)}},iu=(e,t,n)=>{t.every(e=>e>=0&&e<n||(()=>{throw Error(`Resize requires axes input values to be positive and less than rank`)}));let r=Array(n).fill(1);return t.forEach((t,n)=>r[t]=e[n]),r},au=(e,t,n,r,i,a)=>{let[o,s,c]=n>10?[1,2,3]:[-1,e.length>1?1:-1,-1],l=e[0].dims.length;if(o>0&&e.length>o&&e[o].dims.length>0)e[o].getFloat32Array().forEach(e=>a.push(e));else if(t.coordinateTransformMode===`tf_crop_and_resize`)throw Error(`Resize requires RoI input to be specified when coordinateTransformMode is tfCropAndResize`);if(s>0&&e.length>s&&e[s].dims.length===1&&e[s].dims[0]>0){if(e[s].getFloat32Array().forEach(e=>r.push(e)),r.length!==0&&r.length!==l&&n>=18&&r.length!==t.axes.length)throw Error(`Resize requires scales input size to be same as input rank or axes size for opset 18 and up`);ru(r,t),t.axes.length>0&&iu(r,t.axes,l).forEach((e,t)=>r[t]=e)}if(c>0&&e.length>c&&e[c].dims.length===1&&e[c].dims[0]>0&&(e[c].getBigInt64Array().forEach(e=>i.push(Number(e))),i.length!==0&&i.length!==l&&n>=18&&i.length!==t.axes.length))throw Error(`Resize requires sizes input size to be same as input rank or axes size for opset 18 and up`);if(t.axes.length>0){if(r.length!==0&&r.length!==t.axes.length)throw Error(`Resize requires "scales" input size to be of axes rank when axes attributes is specified`);if(i.length!==0&&i.length!==t.axes.length)throw Error(`Resize requires "sizes" input size to be of rank axes rank when axes attributes is specified`)}if(typeof r<`u`&&typeof i<`u`&&r.length>0&&i.length>l)throw Error(`Resize requires only of scales or sizes to be specified`)},ou=(e,t,n,r)=>`
2342
+ // The whole part and the fractional part are calculated separately due to inaccuracy of floating
2343
+ // point division. As an example, f32(21) / f32(7) may evaluate to 2.99... instead of 3, causing an
2344
+ // offset-by-one error later in floor().
2345
+ let big = (${e}) * (${t});
2346
+ let whole = ${r}(big / (${n}));
2347
+ let fract = ${r}(big % (${n})) / ${r}(${n});
2348
+ return whole + fract;
2349
+ `,su=(e,t)=>`fn getOriginalCoordinateFromResizedCoordinate(xResized: u32, xScale: f32, lengthResized: u32,
2350
+ lengthOriginal: u32, roiStart: f32, roiEnd: f32) -> ${t} { `+(()=>{switch(e){case`asymmetric`:return`
2351
+ if (xScale < 1.0 || floor(xScale) != xScale) {
2352
+ return ${t}(xResized) / ${t}(xScale);
2353
+ } else {
2354
+ ${ou(`xResized`,`lengthOriginal`,`lengthResized`,t)}
2355
+ }
2356
+ `;case`pytorch_half_pixel`:return`if (lengthResized > 1) {
2357
+ return (${t}(xResized) + 0.5) / ${t}(xScale) - 0.5;
2358
+ } else {
2359
+ return 0.0;
2360
+ }`;case`tf_half_pixel_for_nn`:return`return (${t}(xResized) + 0.5) / ${t}(xScale);`;case`align_corners`:return`if (lengthResized == 1) {
2361
+ return 0.0;
2362
+ } else {
2363
+ ${ou(`xResized`,`lengthOriginal - 1`,`lengthResized - 1`,t)}
2364
+ }`;case`tf_crop_and_resize`:return`if (lengthResized > 1) {
2365
+ return ${t}(roiStart) * ${t}(lengthOriginal - 1) +
2366
+ (${t}(xResized) * ${t}(roiEnd - roiStart) * ${t}(lengthOriginal - 1)) /
2367
+ ${t}(lengthResized - 1);
2368
+ } else {
2369
+ return 0.5 * ${t}(roiStart + roiEnd) * ${t}(lengthOriginal - 1);
2370
+ }`;case`half_pixel_symmetric`:return`const outputWidth = ${t}xScale * ${t}(lengthResized);
2371
+ const adjustment = ${t}(lengthResized) / outputWidth;
2372
+ const center = ${t}(lengthOriginal) / 2;
2373
+ const offset = center * (1 - adjustment);
2374
+ return offset + ((${t}(xResized) + 0.5) / ${t}(xScale)) - 0.5;`;case`half_pixel`:return`return ((${t}(xResized) + 0.5) / ${t}(xScale)) - 0.5;`;default:throw Error(`Coordinate transform mode ${e} is not supported`)}})()+`}`,cu=(e,t,n)=>`fn getNearestPixelFromOriginal(xOriginal: ${n}, isDownSample: bool) -> ${n} {`+(()=>{switch(e){case`round_prefer_ceil`:return`if (fract(xOriginal) == 0.5) { return ceil(xOriginal); } else { return round(xOriginal); }`;case`floor`:return`return floor(xOriginal);`;case`ceil`:return`return ceil(xOriginal);`;case`round_prefer_floor`:return`if (fract(xOriginal) == 0.5) { return floor(xOriginal); } else { return round(xOriginal); }`;default:if(t<11)return`if (isDownSample) { return ceil(xOriginal); } else { return xOriginal; }`;throw Error(`Nearest mode ${e} is not supported`)}})()+`}`,lu=(e,t,n)=>{let r=Array(n).fill(0).concat(Array(n).fill(1)),i=e.length===0?r:e.slice();return t.length>0?(t.forEach((e,a)=>{r[e]=i[a],r[a+n]=i[t.length+a]}),r):i},uu=(e,t,n,r)=>{let i=[];if(n.length>0)if(r.length>0){if(e.forEach(e=>i.push(e)),Math.max(...r)>e.length)throw Error(`axes is out of bound`);r.forEach((e,t)=>i[e]=n[t])}else n.forEach(e=>i.push(e));else{if(t.length===0)throw Error(`Resize requires either scales or sizes.`);i=e.map((e,n)=>Math.round(e*t[n]))}return i},du=(e,t,n)=>{let r=(()=>{switch(n.keepAspectRatioPolicy){case`not_larger`:return n.axes.length>0?Math.min(...n.axes.map(e=>t[e]),Number.MAX_VALUE):Math.min(...t,Number.MAX_VALUE);case`not_smaller`:return n.axes.length>0?Math.max(...n.axes.map(e=>t[e]),Number.MIN_VALUE):Math.max(...t,Number.MIN_VALUE);default:throw Error(`Keep aspect ratio policy ${n.keepAspectRatioPolicy} is not supported`)}})();t.fill(1,0,t.length);let i=e.slice();return n.axes.length>0?(n.axes.forEach(e=>t[e]=r),n.axes.forEach(n=>i[n]=Math.round(e[n]*t[n]))):(t.fill(r,0,t.length),i.forEach((e,n)=>i[n]=Math.round(e*t[n]))),i},fu=(e,t,n,r,i)=>`
2375
+ fn calculateOriginalIndicesFromOutputIndices(output_indices: ${e.type.indices}) -> array<${e.type.value}, ${n.length}> {
2376
+ var original_indices: array<${e.type.value}, ${n.length}>;
2377
+ for (var i:u32 = 0; i < ${n.length}; i++) {
2378
+ var output_index = ${e.indicesGet(`output_indices`,`i`)};
2379
+ var scale = ${q(`uniforms.scales`,`i`,r)};
2380
+ var roi_low = ${q(`uniforms.roi`,`i`,i)};
2381
+ var roi_hi = ${q(`uniforms.roi`,`i + ${t.length}`,i)};
2382
+ if (scale == 1.0) {
2383
+ original_indices[i] = ${e.type.value}(output_index);
2384
+ } else {
2385
+ var input_shape_i = ${q(`uniforms.input_shape`,`i`,t.length)};
2386
+ var output_shape_i = ${q(`uniforms.output_shape`,`i`,n.length)};
2387
+ original_indices[i] = getOriginalCoordinateFromResizedCoordinate(output_index, scale, output_shape_i,
2388
+ input_shape_i, roi_low, roi_hi);
2389
+ }
2390
+ }
2391
+ return original_indices;
2392
+ }`,pu=(e,t,n,r,i,a,o)=>`
2393
+ fn calculateInputIndicesFromOutputIndices(output_indices: ${t.type.indices}) -> ${e.type.indices} {
2394
+ var input_indices: ${e.type.indices};
2395
+ for (var i:u32 = 0; i < ${r.length}; i++) {
2396
+ var output_index = ${t.indicesGet(`output_indices`,`i`)};
2397
+ var input_index: u32;
2398
+ var scale = ${q(`uniforms.scales`,`i`,i)};
2399
+ if (scale == 1.0) {
2400
+ input_index = output_index;
2401
+ } else {
2402
+ var roi_low = ${q(`uniforms.roi`,`i`,a)};
2403
+ var roi_hi = ${q(`uniforms.roi`,`i + ${n.length}`,a)};
2404
+ var input_shape_i = ${q(`uniforms.input_shape`,`i`,n.length)};
2405
+ var output_shape_i = ${q(`uniforms.output_shape`,`i`,r.length)};
2406
+ var original_idx = getOriginalCoordinateFromResizedCoordinate(output_index, scale, output_shape_i,
2407
+ input_shape_i, roi_low, roi_hi);
2408
+ if (!${o} || (original_idx >= 0 && original_idx < ${t.type.value}(input_shape_i))) {
2409
+ if (original_idx < 0) {
2410
+ input_index = 0;
2411
+ } else if (original_idx > ${t.type.value}(input_shape_i - 1)) {
2412
+ input_index = input_shape_i - 1;
2413
+ } else {
2414
+ input_index = u32(getNearestPixelFromOriginal(original_idx, scale < 1));
2415
+ }
2416
+ } else {
2417
+ input_index = u32(original_idx);
2418
+ }
2419
+ }
2420
+ ${e.indicesSet(`input_indices`,`i`,`input_index`)}
2421
+ }
2422
+ return input_indices;
2423
+ }`,mu=(e,t)=>`
2424
+ fn checkInputIndices(input_indices: ${e.type.indices}) -> bool {
2425
+ for (var i:u32 = 0; i < ${t.length}; i++) {
2426
+ var input_index = ${e.indicesGet(`input_indices`,`i`)};
2427
+ if (input_index < 0 || input_index >= ${q(`uniforms.input_shape`,`i`,t.length)}) {
2428
+ return false;
2429
+ }
2430
+ }
2431
+ return true;
2432
+ }`,hu=(e,t,n,r)=>e.rank>r?`
2433
+ ${e.indicesSet(`input_indices`,t,`channel`)};
2434
+ ${e.indicesSet(`input_indices`,n,`batch`)};
2435
+ `:``,gu=(e,t,n,r,i)=>{let[a,o,s,c]=n.length===2?[-1,0,1,-1]:[0,2,3,1],l=e.type.value;return`
2436
+ fn getInputValue(batch: u32, channel: u32, row: u32, col: u32) -> ${l} {
2437
+ var input_indices: ${e.type.indices};
2438
+ ${e.indicesSet(`input_indices`,o,`max(0, min(row, ${n[o]} - 1))`)};
2439
+ ${e.indicesSet(`input_indices`,s,`max(0, min(col, ${n[s]} - 1))`)};
2440
+ ${hu(e,c,a,2)}
2441
+ return ${e.getByIndices(`input_indices`)};
2442
+ }
2443
+
2444
+ fn bilinearInterpolation(output_indices: ${t.type.indices}) -> ${l} {
2445
+ var originalIndices = calculateOriginalIndicesFromOutputIndices(output_indices);
2446
+ var row:${l} = originalIndices[${o}];
2447
+ var col:${l} = originalIndices[${s}];
2448
+ ${r?`if (row < 0 || row > (${n[o]} - 1) || col < 0 || col > (${n[s]} - 1)) {
2449
+ return ${i};
2450
+ }`:``};
2451
+ row = max(0, min(row, ${n[o]} - 1));
2452
+ col = max(0, min(col, ${n[s]} - 1));
2453
+ var row1: u32 = u32(row);
2454
+ var col1: u32 = u32(col);
2455
+ var row2: u32 = u32(row + 1);
2456
+ var col2: u32 = u32(col + 1);
2457
+ var channel: u32 = ${n.length>2?`u32(originalIndices[${c}])`:`0`};
2458
+ var batch: u32 = ${n.length>2?`u32(originalIndices[${a}])`:`0`};
2459
+ var x11: ${l} = getInputValue(batch, channel, row1, col1);
2460
+ var x12: ${l} = getInputValue(batch, channel, row1, col2);
2461
+ var x21: ${l} = getInputValue(batch, channel, row2, col1);
2462
+ var x22: ${l} = getInputValue(batch, channel, row2, col2);
2463
+ var dx1: ${l} = abs(row - ${l}(row1));
2464
+ var dx2: ${l} = abs(${l}(row2) - row);
2465
+ var dy1: ${l} = abs(col - ${l}(col1));
2466
+ var dy2: ${l} = abs(${l}(col2) - col);
2467
+ if (row1 == row2) {
2468
+ dx1 = 0.5;
2469
+ dx2 = 0.5;
2470
+ }
2471
+ if (col1 == col2) {
2472
+ dy1 = 0.5;
2473
+ dy2 = 0.5;
2474
+ }
2475
+ return (x11 * dx2 * dy2 + x12 * dx2 * dy1 + x21 * dx1 * dy2 + x22 * dx1 * dy1);
2476
+ }`},_u=(e,t,n,r,i,a,o,s,c,l)=>{let[u,d]=n.length===2?[0,1]:[2,3],f=e.type.value,p=o=>{let d=o===u?`row`:`col`;return`
2477
+ fn ${d}CubicInterpolation(input_indices: ${e.type.indices}, output_indices: ${t.type.indices}) -> ${f} {
2478
+ var output_index = ${t.indicesGet(`output_indices`,o)};
2479
+ var originalIdx: ${f} = getOriginalCoordinateFromResizedCoordinate(output_index, ${i[o]},
2480
+ ${r[o]}, ${n[o]}, ${a[o]}, ${a[o]} + ${n.length});
2481
+ var fractOriginalIdx: ${f} = originalIdx - floor(originalIdx);
2482
+ var coefs = getCubicInterpolationCoefs(fractOriginalIdx);
2483
+
2484
+ if (${s} && (originalIdx < 0 || originalIdx > (${n[o]} - 1))) {
2485
+ return ${c};
2486
+ }
2487
+ var data: array<${f}, 4> = array<${f}, 4>(0.0, 0.0, 0.0, 0.0);
2488
+ for (var i: i32 = -1; i < 3; i++) {
2489
+ var ${d}: ${f} = originalIdx + ${f}(i);
2490
+ if (${d} < 0 || ${d} >= ${n[o]}) {
2491
+ ${l?`coefs[i + 1] = 0.0;
2492
+ continue;`:s?`return ${c};`:`${d} = max(0, min(${d}, ${n[o]} - 1));`};
2493
+ }
2494
+ var input_indices_copy: ${e.type.indices} = input_indices;
2495
+ ${e.indicesSet(`input_indices_copy`,o,`u32(${d})`)};
2496
+ data[i + 1] = ${o===u?e.getByIndices(`input_indices_copy`):`rowCubicInterpolation(input_indices_copy, output_indices)`};
2497
+ }
2498
+ return cubicInterpolation1D(data, coefs);
2499
+ }`};return`
2500
+ ${p(u)};
2501
+ ${p(d)};
2502
+ fn getCubicInterpolationCoefs(s: ${f}) -> array<${f}, 4> {
2503
+ var absS = abs(s);
2504
+ var coeffs: array<${f}, 4> = array<${f}, 4>(0.0, 0.0, 0.0, 0.0);
2505
+ var oneMinusAbsS: ${f} = 1.0 - absS;
2506
+ var twoMinusAbsS: ${f} = 2.0 - absS;
2507
+ var onePlusAbsS: ${f} = 1.0 + absS;
2508
+ coeffs[0] = ((${o} * onePlusAbsS - 5 * ${o}) * onePlusAbsS + 8 * ${o}) * onePlusAbsS - 4 * ${o};
2509
+ coeffs[1] = ((${o} + 2) * absS - (${o} + 3)) * absS * absS + 1;
2510
+ coeffs[2] = ((${o} + 2) * oneMinusAbsS - (${o} + 3)) * oneMinusAbsS * oneMinusAbsS + 1;
2511
+ coeffs[3] = ((${o} * twoMinusAbsS - 5 * ${o}) * twoMinusAbsS + 8 * ${o}) * twoMinusAbsS - 4 * ${o};
2512
+ return coeffs;
2513
+ }
2514
+
2515
+ fn cubicInterpolation1D(x: array<${f}, 4>, coefs: array<${f}, 4>) -> ${f} {
2516
+ var coefsSum: ${f} = coefs[0] + coefs[1] + coefs[2] + coefs[3];
2517
+ return (x[0] * coefs[0] + x[1] * coefs[1]+ x[2] * coefs[2]+ x[3] * coefs[3]) / coefsSum;
2518
+ }
2519
+
2520
+ fn bicubicInterpolation(output_indices: ${t.type.indices}) -> ${f} {
2521
+ var input_indices: ${e.type.indices} = output_indices;
2522
+ return colCubicInterpolation(input_indices, output_indices);
2523
+ }
2524
+ `},vu=(e,t,n,r,i)=>{let[a,o,s,c,l]=n.length===3?[-1,0,1,2,-1]:[0,2,3,4,1],u=e.type.value;return`
2525
+ fn getInputValue(batch: u32, channel: u32, depth:u32, height: u32, width: u32) -> ${u} {
2526
+ var input_indices: ${e.type.indices};
2527
+ ${e.indicesSet(`input_indices`,o,`max(0, min(depth, ${n[o]} - 1))`)};
2528
+ ${e.indicesSet(`input_indices`,s,`max(0, min(height, ${n[s]} - 1))`)};
2529
+ ${e.indicesSet(`input_indices`,c,`max(0, min(width, ${n[c]} - 1))`)};
2530
+ ${hu(e,l,a,3)}
2531
+ return ${e.getByIndices(`input_indices`)};
2532
+ }
2533
+
2534
+ fn trilinearInterpolation(output_indices: ${t.type.indices}) -> ${u} {
2535
+ var originalIndices = calculateOriginalIndicesFromOutputIndices(output_indices);
2536
+ var depth:${u} = originalIndices[${o}];
2537
+ var height:${u} = originalIndices[${s}];
2538
+ var width:${u} = originalIndices[${c}];
2539
+ ${r?`if (depth < 0 || depth > (${n[o]} - 1) || height < 0 || height > (${n[s]} - 1) || width < 0 || (width > ${n[c]} - 1)) {
2540
+ return ${i};
2541
+ }`:``};
2542
+
2543
+ depth = max(0, min(depth, ${n[o]} - 1));
2544
+ height = max(0, min(height, ${n[s]} - 1));
2545
+ width = max(0, min(width, ${n[c]} - 1));
2546
+ var depth1: u32 = u32(depth);
2547
+ var height1: u32 = u32(height);
2548
+ var width1: u32 = u32(width);
2549
+ var depth2: u32 = u32(depth + 1);
2550
+ var height2: u32 = u32(height + 1);
2551
+ var width2: u32 = u32(width + 1);
2552
+ var channel: u32 = ${n.length>3?`u32(originalIndices[${l}])`:`0`};
2553
+ var batch: u32 = ${n.length>3?`u32(originalIndices[${a}])`:`0`};
2554
+
2555
+ var x111: ${u} = getInputValue(batch, channel, depth1, height1, width1);
2556
+ var x112: ${u} = getInputValue(batch, channel, depth1, height1, width2);
2557
+ var x121: ${u} = getInputValue(batch, channel, depth1, height2, width1);
2558
+ var x122: ${u} = getInputValue(batch, channel, depth1, height2, width2);
2559
+ var x211: ${u} = getInputValue(batch, channel, depth2, height1, width1);
2560
+ var x212: ${u} = getInputValue(batch, channel, depth2, height1, width2);
2561
+ var x221: ${u} = getInputValue(batch, channel, depth2, height2, width1);
2562
+ var x222: ${u} = getInputValue(batch, channel, depth2, height2, width2);
2563
+ var dx1: ${u} = abs(depth - ${u}(depth1));
2564
+ var dx2: ${u} = abs(${u}(depth2) - depth);
2565
+ var dy1: ${u} = abs(height - ${u}(height1));
2566
+ var dy2: ${u} = abs(${u}(height2) - height);
2567
+ var dz1: ${u} = abs(width - ${u}(width1));
2568
+ var dz2: ${u} = abs(${u}(width2) - width);
2569
+ if (depth1 == depth2) {
2570
+ dx1 = 0.5;
2571
+ dx2 = 0.5;
2572
+ }
2573
+ if (height1 == height2) {
2574
+ dy1 = 0.5;
2575
+ dy2 = 0.5;
2576
+ }
2577
+ if (width1 == width2) {
2578
+ dz1 = 0.5;
2579
+ dz2 = 0.5;
2580
+ }
2581
+ return (x111 * dx2 * dy2 * dz2 + x112 * dx2 * dy2 * dz1 + x121 * dx2 * dy1 *dz2 + x122 * dx2 * dy1 * dz1 +
2582
+ x211 * dx1 * dy2 * dz2 + x212 * dx1 * dy2 * dz1 + x221 * dx1 * dy1 *dz2 + x222 * dx1 * dy1 * dz1);
2583
+ }`},yu=(e,t,n,r,i,a)=>{let o=e.dims,s=lu(a,t.axes,o.length),c=uu(o,r,i,t.axes),l=r.slice();r.length===0&&(l=o.map((e,t)=>e===0?1:c[t]/e),t.keepAspectRatioPolicy!==`stretch`&&(c=du(o,l,t)));let u=Y(`output`,e.dataType,c.length),d=J(`input`,e.dataType,o.length),f=W.size(c),p=o.length===c.length&&o.every((e,t)=>e===c[t]),m=t.coordinateTransformMode===`tf_crop_and_resize`,h=t.extrapolationValue,g=d.type.value;return{name:`Resize`,shaderCache:{hint:`${t.cacheKey}|${n}|${l.length>0?t.mode===`cubic`?l:l.length:``}|${i.length>0?i:``}|${s.length>0?s:``}|${p}|${t.mode===`nearest`?o.length:o}`,inputDependencies:[`rank`]},getShaderSource:e=>`
2584
+ ${p?``:`
2585
+ ${su(t.coordinateTransformMode,g)};
2586
+ ${(()=>{switch(t.mode){case`nearest`:return`
2587
+ ${mu(d,o)};
2588
+ ${cu(t.nearestMode,n,g)};
2589
+ ${pu(d,u,o,c,l.length,s.length,m)};
2590
+ `;case`linear`:return`
2591
+ ${fu(u,o,c,l.length,s.length)};
2592
+ ${(()=>{if(o.length===2||o.length===4)return`${gu(d,u,o,m,h)}`;if(o.length===3||o.length===5)return`${vu(d,u,o,m,h)}`;throw Error(`Linear mode only supports input dims 2, 3, 4 and 5 are supported in linear mode.`)})()};
2593
+ `;case`cubic`:return`
2594
+ ${(()=>{if(o.length===2||o.length===4)return`${_u(d,u,o,c,l,s,t.cubicCoeffA,m,t.extrapolationValue,t.excludeOutside)}`;throw Error(`Cubic mode only supports input dims 2 and 4 are supported in linear mode.`)})()};
2595
+ `;default:throw Error(`Invalid resize mode`)}})()};
2596
+ `}
2597
+ ${e.registerUniform(`output_size`,`u32`).registerUniform(`scales`,`f32`,l.length).registerUniform(`roi`,`f32`,s.length).declareVariables(d,u)}
2598
+ ${e.mainStart()}
2599
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)}
2600
+ ${p?`output[global_idx] = input[global_idx];`:`
2601
+ let output_indices = ${u.offsetToIndices(`global_idx`)};
2602
+ var input_indices: ${d.type.indices};
2603
+ ${(()=>{switch(t.mode){case`nearest`:return`input_indices = calculateInputIndicesFromOutputIndices(output_indices);
2604
+ if (checkInputIndices(input_indices)) {
2605
+ output[global_idx] = ${d.getByIndices(`input_indices`)};
2606
+ } else {
2607
+ output[global_idx] = ${t.extrapolationValue};
2608
+ }`;case`linear`:return`output[global_idx] = ${o.length===2||o.length===4?`bilinearInterpolation`:`trilinearInterpolation`}(output_indices);`;case`cubic`:return`output[global_idx] = bicubicInterpolation(output_indices);`;default:throw Error(`Unsupported resize mode: ${t.mode}`)}})()};
2609
+ `}
2610
+ }`,getRunData:()=>({outputs:[{dims:c,dataType:e.dataType}],dispatchGroup:{x:Math.ceil(f/64)},programUniforms:[{type:12,data:f},{type:1,data:l},{type:1,data:s},...K(o,c)]})}},bu=e=>{let t=e.customDataBuffer;return new Uint32Array(t,t.byteOffset,1)[0]},xu=(e,t)=>{let n=[],r=[],i=[],a=bu(e);if(t.antialias!==0)throw Error(`Only default value (0) for Antialias attribute is supported`);au(e.inputs,t,a,n,r,i),e.compute(yu(e.inputs[0],t,a,n,r,i),{inputs:[0]})},Su=e=>{let t=e.antialias,n=e.axes,r=e.coordinateTransformMode,i=e.cubicCoeffA,a=e.excludeOutside!==0,o=e.extrapolationValue,s=e.keepAspectRatioPolicy,c=e.mode,l=e.nearestMode===``?`simple`:e.nearestMode;return Jn({antialias:t,axes:n,coordinateTransformMode:r,cubicCoeffA:i,excludeOutside:a,extrapolationValue:o,keepAspectRatioPolicy:s,mode:c,nearestMode:l})}}),wu,Tu,Eu,Du=M(()=>{H(),G(),X(),wu=e=>{if(!e||e.length<3)throw Error(`layerNorm requires at least 3 inputs.`);let t=e[0],n=e[1],r=e[2];if(t.dataType!==n.dataType||t.dataType!==r.dataType)throw Error(`All inputs must have the same data type`);if(t.dims.length!==3&&t.dims.length!==2)throw Error(`Input must be 2D or 3D`);if(n.dims.length!==3&&n.dims.length!==2)throw Error(`Skip must be 2D or 3D`);let i=t.dims[t.dims.length-1],a=t.dims[t.dims.length-2];if(n.dims[n.dims.length-1]!==i)throw Error(`Skip must have the same hidden size as input`);if(n.dims[n.dims.length-2]!==a)throw Error(`Skip must have the same sequence length as input`);if(r.dims.length!==1)throw Error(`Gamma must be 1D`);if(r.dims[r.dims.length-1]!==i)throw Error(`Gamma must have the same hidden size as input`);if(e.length>3){let t=e[3];if(t.dims.length!==1)throw Error(`Beta must be 1D`);if(t.dims[t.dims.length-1]!==i)throw Error(`Beta must have the same hidden size as input`)}if(e.length>4){let t=e[4];if(t.dims.length!==1)throw Error(`Bias must be 1D`);if(t.dims[t.dims.length-1]!==i)throw Error(`Bias must have the same hidden size as input`)}},Tu=(e,t,n,r)=>{let i=t.simplified,a=e[0].dims,o=W.size(a),s=a,c=o,l=a.slice(-1)[0],u=r?a.slice(0,-1).concat(1):[],d=!i&&e.length>3,f=e.length>4,p=r&&n>1,m=r&&n>2,h=n>3,g=er(l),_=[{type:12,data:c},{type:12,data:g},{type:12,data:l},{type:1,data:t.epsilon}],v=t=>{let n=[{name:`output_size`,type:`u32`},{name:`components`,type:`u32`},{name:`hidden_size`,type:`u32`},{name:`epsilon`,type:`f32`}],r=[J(`x`,e[0].dataType,e[0].dims,g),J(`skip`,e[1].dataType,e[1].dims,g),J(`gamma`,e[2].dataType,e[2].dims,g)];d&&r.push(J(`beta`,e[3].dataType,e[3].dims,g)),f&&r.push(J(`bias`,e[4].dataType,e[4].dims,g)),r.push(Y(`output`,e[0].dataType,s,g)),p&&r.push(Y(`mean_output`,1,u)),m&&r.push(Y(`inv_std_output`,1,u)),h&&r.push(Y(`input_skip_bias_sum`,e[0].dataType,s,g));let a=Qn(e[0].dataType),o=Qn(1,g);return`
2611
+
2612
+ ${t.registerUniforms(n).declareVariables(...r)}
2613
+ var<workgroup> sum_shared : array<${o}, 64>;
2614
+ var<workgroup> sum_squared_shared : array<${o}, 64>;
2615
+
2616
+ ${t.mainStart([64,1,1])}
2617
+ let ix = local_id.x;
2618
+ let iy = global_id.x / 64;
2619
+
2620
+ let hidden_size_vectorized: u32 = uniforms.hidden_size / uniforms.components;
2621
+ var stride = hidden_size_vectorized / 64;
2622
+ let offset = ix * stride + iy * hidden_size_vectorized;
2623
+ let offset1d = stride * ix;
2624
+ if (ix == 63) {
2625
+ stride = hidden_size_vectorized - stride * ix;
2626
+ }
2627
+ for (var i: u32 = 0; i < stride; i++) {
2628
+ let skip_value = skip[offset + i];
2629
+ let bias_value = ${f?`bias[offset1d + i]`:a+`(0.0)`};
2630
+ let input_value = x[offset + i];
2631
+ let value = input_value + skip_value + bias_value;
2632
+ ${h?`input_skip_bias_sum[offset + i] = value;`:``}
2633
+ output[offset + i] = value;
2634
+ let f32_value = ${nr(a,g,`value`)};
2635
+ sum_shared[ix] += f32_value;
2636
+ sum_squared_shared[ix] += f32_value * f32_value;
2637
+ }
2638
+ workgroupBarrier();
2639
+
2640
+ var reduce_size : u32 = 64;
2641
+ for (var curr_size = reduce_size >> 1; curr_size > 0; curr_size = reduce_size >> 1) {
2642
+ reduce_size = curr_size + (reduce_size & 1);
2643
+ if (ix < curr_size) {
2644
+ sum_shared[ix] += sum_shared[ix + reduce_size];
2645
+ sum_squared_shared[ix] += sum_squared_shared[ix + reduce_size];
2646
+ }
2647
+ workgroupBarrier();
2648
+ }
2649
+
2650
+ let sum = sum_shared[0];
2651
+ let square_sum = sum_squared_shared[0];
2652
+ let mean = ${rr(`sum`,g)} / f32(uniforms.hidden_size);
2653
+ let inv_std_dev = inverseSqrt(${rr(`square_sum`,g)} / f32(uniforms.hidden_size) ${i?``:`- mean * mean`} + uniforms.epsilon);
2654
+ ${p?`mean_output[global_idx] = mean;`:``}
2655
+ ${m?`inv_std_output[global_idx] = inv_std_dev;`:``}
2656
+
2657
+ for (var i: u32 = 0; i < stride; i++) {
2658
+ output[offset + i] = (output[offset + i] ${i?``:`- ${a}(mean)`}) *
2659
+ ${a}(inv_std_dev) * gamma[offset1d + i]
2660
+ ${d?`+ beta[offset1d + i]`:``};
2661
+ }
2662
+ }`},y=[{dims:s,dataType:e[0].dataType}];return n>1&&y.push({dims:u,dataType:1}),n>2&&y.push({dims:u,dataType:1}),n>3&&y.push({dims:a,dataType:e[0].dataType}),{name:`SkipLayerNormalization`,shaderCache:{hint:`${g};${p};${m};${h}`,inputDependencies:e.map((e,t)=>`type`)},getShaderSource:v,getRunData:()=>({outputs:y,dispatchGroup:{x:Math.ceil(c/l)},programUniforms:_})}},Eu=(e,t)=>{wu(e.inputs);let n=[0];e.outputCount>1&&n.push(-3),e.outputCount>2&&n.push(-3),e.outputCount>3&&n.push(3),e.compute(Tu(e.inputs,t,e.outputCount,!1),{outputs:n})}}),Ou,ku,Au,ju,Mu,Nu,Pu,Fu,Iu=M(()=>{H(),G(),Yn(),X(),Ou=(e,t)=>{if(!e||e.length<1)throw Error(`too few inputs`);if(t.axes.length!==0){if(t.axes.length!==t.starts.length||t.axes.length!==t.ends.length)throw Error(`axes, starts and ends must have the same length`)}else if(t.starts.length!==t.ends.length)throw Error(`starts and ends must have the same length`);e.slice(1).forEach((t,n)=>{if(e[n+1].dataType!==6&&e[n+1].dataType!==7)throw Error(`Input ${n} must be an array of int32 or int64`)})},ku=(e,t)=>{let n=[];if(e.length>t)if(e[t].dataType===7)e[t].getBigInt64Array().forEach(e=>n.push(Number(e)));else if(e[t].dataType===6)e[t].getInt32Array().forEach(e=>n.push(Number(e)));else throw Error(`Input ${t} must be an array of int32 or int64`);return n},Au=(e,t)=>{if(e.length>1){let t=ku(e,1),n=ku(e,2),r=ku(e,3);return r.length===0&&(r=[...Array(e[0].dims.length).keys()]),Jn({starts:t,ends:n,axes:r})}else return t},ju=(e,t,n,r,i)=>{let a=e;return e<0&&(a+=n[r[t]]),i[t]<0?Math.max(0,Math.min(a,n[r[t]]-1)):Math.max(0,Math.min(a,n[r[t]]))},Mu=(e,t,n)=>`fn calculateInputIndices(output_indices: ${t.type.indices}) -> ${e.type.indices} {
2663
+ var input_indices: ${e.type.indices};
2664
+ var carry = 0u;
2665
+ for (var i = ${n.length}; i >= 0; i--) {
2666
+ let input_shape_i = ${q(`uniforms.input_shape`,`i`,n.length)};
2667
+ let steps_i = ${q(`uniforms.steps`,`i`,n.length)};
2668
+ let signs_i = ${q(`uniforms.signs`,`i`,n.length)};
2669
+ let starts_i = ${q(`uniforms.starts`,`i`,n.length)};
2670
+ var output_index = ${t.indicesGet(`output_indices`,`i`)};
2671
+ var input_index = output_index * steps_i + starts_i + carry;
2672
+ carry = input_index / input_shape_i;
2673
+ input_index = input_index % input_shape_i;
2674
+ if (signs_i < 0) {
2675
+ input_index = input_shape_i - input_index - 1u + starts_i;
2676
+ }
2677
+ ${e.indicesSet(`input_indices`,`i`,`input_index`)};
2678
+ }
2679
+ return input_indices;
2680
+ }`,Nu=(e,t)=>{let n=e[0].dims,r=W.size(n),i=t.axes.length>0?W.normalizeAxes(t.axes,n.length):[...Array(n.length).keys()],a=ku(e,4);a.forEach(e=>e!==0||(()=>{throw Error(`step cannot be 0`)})),a.length===0&&(a=Array(i.length).fill(1));let o=t.starts.map((e,t)=>ju(e,t,n,i,a)),s=t.ends.map((e,t)=>ju(e,t,n,i,a));if(i.length!==o.length||i.length!==s.length)throw Error(`start, ends and axes should have the same number of elements`);if(i.length!==n.length)for(let e=0;e<n.length;++e)i.includes(e)||(o.splice(e,0,0),s.splice(e,0,n[e]),a.splice(e,0,1));let c=a.map(e=>Math.sign(e));a.forEach((e,t,n)=>{if(e<0){let r=(s[t]-o[t])/e,i=o[t];o[t]=i+r*a[t],s[t]=i,n[t]=-e}});let l=n.slice(0);i.forEach((e,t)=>{l[e]=Math.ceil((s[e]-o[e])/a[e])});let u={dims:l,dataType:e[0].dataType},d=Y(`output`,e[0].dataType,l.length),f=J(`input`,e[0].dataType,e[0].dims.length),p=W.size(l),m=[{name:`outputSize`,type:`u32`},{name:`starts`,type:`u32`,length:o.length},{name:`signs`,type:`i32`,length:c.length},{name:`steps`,type:`u32`,length:a.length}],h=[{type:12,data:p},{type:12,data:o},{type:6,data:c},{type:12,data:a},...K(e[0].dims,l)];return{name:`Slice`,shaderCache:{hint:`${c.length}_${o.length}_${a.length}`,inputDependencies:[`rank`]},getShaderSource:e=>`
2681
+ ${e.registerUniforms(m).declareVariables(f,d)}
2682
+ ${Mu(f,d,n)}
2683
+ ${e.mainStart()}
2684
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.outputSize`)}
2685
+ let output_indices = ${d.offsetToIndices(`global_idx`)};
2686
+ let input_indices = calculateInputIndices(output_indices);
2687
+ ${d.setByOffset(`global_idx`,f.getByIndices(`input_indices`))}
2688
+ }`,getRunData:()=>({outputs:[u],dispatchGroup:{x:Math.ceil(r/64)},programUniforms:h})}},Pu=(e,t)=>{Ou(e.inputs,t);let n=Au(e.inputs,t);e.compute(Nu(e.inputs,n),{inputs:[0]})},Fu=e=>{let t=e.starts,n=e.ends,r=e.axes;return Jn({starts:t,ends:n,axes:r})}}),Lu,Ru,zu,Bu,Vu=M(()=>{H(),G(),Yn(),_r(),X(),Lu=e=>{if(!e||e.length!==1)throw Error(`Softmax op requires 1 input.`)},Ru=(e,t)=>{let n=e.inputs[0],r=n.dims,i=W.size(r),a=r.length,o=W.normalizeAxis(t.axis,a),s=o<r.length-1,c,l=[];s?(l=Array.from({length:a},(e,t)=>t),l[o]=a-1,l[a-1]=o,c=e.compute(mr(n,l),{inputs:[n],outputs:[-1]})[0]):c=n;let u=c.dims,d=u[a-1],f=i/d,p=er(d),m=d/p,h=64;f===1&&(h=256);let g=(e,t)=>t===4?`max(max(${e}.x, ${e}.y), max(${e}.z, ${e}.w))`:t===2?`max(${e}.x, ${e}.y)`:t===3?`max(max(${e}.x, ${e}.y), ${e}.z)`:e,_=J(`x`,c.dataType,c.dims,p),v=Y(`result`,c.dataType,c.dims,p),y=_.type.value,b=Qn(c.dataType)===`f32`?`var threadMax = ${y}(-3.402823e+38f);`:`var threadMax = ${y}(-65504.0h);`,x=e.compute({name:`Softmax`,shaderCache:{hint:`${p};${h}`,inputDependencies:[`type`]},getRunData:()=>({outputs:[{dims:u,dataType:c.dataType}],dispatchGroup:{x:f},programUniforms:[{type:6,data:m}]}),getShaderSource:e=>`
2689
+ var<workgroup> rowMaxShared : ${y};
2690
+ var<workgroup> rowSumShared : ${y};
2691
+ var<workgroup> threadShared : array<${y}, ${h}>;
2692
+
2693
+ fn getValue(row: i32, col: i32, row_stride: i32) -> ${y} {
2694
+ let index = row * row_stride + col;
2695
+ return x[index];
2696
+ }
2697
+
2698
+ fn setValue(row: i32, col: i32, row_stride: i32, value: ${y}) {
2699
+ let index = row * row_stride + col;
2700
+ result[index] = value;
2701
+ }
2702
+ ${e.registerUniform(`packedCols`,`i32`).declareVariables(_,v)}
2703
+ ${e.mainStart(h)}
2704
+ let gindex = i32(global_idx);
2705
+ let lindex = i32(local_idx);
2706
+ const wg = ${h};
2707
+ let row = gindex / wg;
2708
+ let cols = uniforms.packedCols;
2709
+ let row_stride : i32 = uniforms.packedCols;
2710
+
2711
+ // find the rows max
2712
+ ${b}
2713
+ for (var col = lindex; col < cols; col += wg) {
2714
+ let value = getValue(row, col, row_stride);
2715
+ threadMax = max(threadMax, value);
2716
+ }
2717
+ if (lindex < cols) {
2718
+ threadShared[lindex] = threadMax;
2719
+ }
2720
+ workgroupBarrier();
2721
+
2722
+ var reduceSize = min(cols, wg);
2723
+ for (var currSize = reduceSize >> 1; currSize > 0; currSize = reduceSize >> 1) {
2724
+ reduceSize = currSize + (reduceSize & 1);
2725
+ if (lindex < currSize) {
2726
+ threadShared[lindex] = max(threadShared[lindex], threadShared[lindex + reduceSize]);
2727
+ }
2728
+ workgroupBarrier();
2729
+ }
2730
+ if (lindex == 0) {
2731
+ rowMaxShared = ${y}(${g(`threadShared[0]`,p)});
2732
+ }
2733
+ workgroupBarrier();
2734
+
2735
+ // find the rows sum
2736
+ var threadSum = ${y}(0.0);
2737
+ for (var col = lindex; col < cols; col += wg) {
2738
+ let subExp = exp(getValue(row, col, row_stride) - rowMaxShared);
2739
+ threadSum += subExp;
2740
+ }
2741
+ threadShared[lindex] = threadSum;
2742
+ workgroupBarrier();
2743
+
2744
+ for (var currSize = wg >> 1; currSize > 0; currSize = currSize >> 1) {
2745
+ if (lindex < currSize) {
2746
+ threadShared[lindex] = threadShared[lindex] + threadShared[lindex + currSize];
2747
+ }
2748
+ workgroupBarrier();
2749
+ }
2750
+ if (lindex == 0) {
2751
+ rowSumShared = ${y}(${rr(`threadShared[0]`,p)});
2752
+ }
2753
+ workgroupBarrier();
2754
+
2755
+ // calculate final value for each element in the row
2756
+ for (var col = lindex; col < cols; col += wg) {
2757
+ let value = exp(getValue(row, col, row_stride) - rowMaxShared) / rowSumShared;
2758
+ setValue(row, col, row_stride, value);
2759
+ }
2760
+ }`},{inputs:[c],outputs:[s?-1:0]})[0];s&&e.compute(mr(x,l),{inputs:[x]})},zu=(e,t)=>{Lu(e.inputs),Ru(e,t)},Bu=e=>Jn({axis:e.axis})}),Hu,Uu,Wu,Gu,Ku,qu=M(()=>{H(),G(),X(),Hu=e=>Array.from(e.getBigInt64Array(),Number),Uu=e=>{if(!e||e.length!==2)throw Error(`Tile requires 2 inputs.`);if(e[0].dataType!==1&&e[0].dataType!==10&&e[0].dataType!==6&&e[0].dataType!==12)throw Error(`Tile only support float, float16, int32, and uint32 data types`);if(e[1].dataType!==7)throw Error("Tile `repeats` input should be of int64 data type");if(e[1].dims.length!==1)throw Error("Tile `repeats` input should be 1-D");if(Hu(e[1]).length!==e[0].dims.length)throw Error("Tile `repeats` input should have same number of elements as rank of input data tensor")},Wu=(e,t)=>{let n=[];for(let r=0;r<e.length;++r)n.push(e[r]*t[r]);return n},Gu=(e,t)=>{let n=e[0].dims,r=t??Hu(e[1]),i=Wu(n,r),a=W.size(i),o=e[0].dataType,s=J(`input`,o,n.length),c=Y(`output`,o,i.length);return{name:`Tile`,shaderCache:{hint:`${r}`,inputDependencies:[`rank`]},getRunData:()=>({outputs:[{dims:i,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(a/64)},programUniforms:[{type:12,data:a},...K(e[0].dims,i)]}),getShaderSource:e=>`
2761
+ const inputShape = ${s.indices(...n)};
2762
+ ${e.registerUniform(`output_size`,`u32`).declareVariables(s,c)}
2763
+ ${e.mainStart()}
2764
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.output_size`)}
2765
+ let output_indices = ${c.offsetToIndices(`global_idx`)};
2766
+ var input_indices: ${s.type.indices};
2767
+ for (var i = 0; i < ${n.length}; i++) {
2768
+ let input_dim_i = ${s.indicesGet(`uniforms.input_shape`,`i`)};
2769
+ let input_dim_value = ${c.indicesGet(`output_indices`,`i`)} % input_dim_i;
2770
+
2771
+ ${s.indicesSet(`input_indices`,`i`,`input_dim_value`)}
2772
+ }
2773
+ ${c.setByOffset(`global_idx`,s.getByIndices(`input_indices`))}
2774
+ }`}},Ku=e=>{Uu(e.inputs),e.compute(Gu(e.inputs),{inputs:[0]})}}),Ju,Yu,Xu,Zu=M(()=>{H(),G(),X(),Ju=(e,t,n,r,i)=>{let a=Y(`output_data`,i,n.length,4),o=J(`a_data`,t[1].dataType,t[1].dims.length,4),s=J(`b_data`,t[2].dataType,t[2].dims.length,4),c=J(`c_data`,t[0].dataType,t[0].dims.length,4),l,u=(e,t,n)=>`select(${t}, ${e}, ${n})`;if(!r)l=a.setByOffset(`global_idx`,u(o.getByOffset(`global_idx`),s.getByOffset(`global_idx`),c.getByOffset(`global_idx`)));else{let e=(e,t,n=``)=>{let r=`a_data[index_a${t}][component_a${t}]`,i=`b_data[index_b${t}][component_b${t}]`,l=`bool(c_data[index_c${t}] & (0xffu << (component_c${t} * 8)))`;return`
2775
+ let output_indices${t} = ${a.offsetToIndices(`global_idx * 4u + ${t}u`)};
2776
+ let offset_a${t} = ${o.broadcastedIndicesToOffset(`output_indices${t}`,a)};
2777
+ let offset_b${t} = ${s.broadcastedIndicesToOffset(`output_indices${t}`,a)};
2778
+ let offset_c${t} = ${c.broadcastedIndicesToOffset(`output_indices${t}`,a)};
2779
+ let index_a${t} = offset_a${t} / 4u;
2780
+ let index_b${t} = offset_b${t} / 4u;
2781
+ let index_c${t} = offset_c${t} / 4u;
2782
+ let component_a${t} = offset_a${t} % 4u;
2783
+ let component_b${t} = offset_b${t} % 4u;
2784
+ let component_c${t} = offset_c${t} % 4u;
2785
+ ${e}[${t}] = ${n}(${u(r,i,l)});
2786
+ `};l=i===9?`
2787
+ var data = vec4<u32>(0);
2788
+ ${e(`data`,0,`u32`)}
2789
+ ${e(`data`,1,`u32`)}
2790
+ ${e(`data`,2,`u32`)}
2791
+ ${e(`data`,3,`u32`)}
2792
+ output_data[global_idx] = dot(vec4<u32>(0x1, 0x100, 0x10000, 0x1000000), vec4<u32>(data));`:`
2793
+ ${e(`output_data[global_idx]`,0)}
2794
+ ${e(`output_data[global_idx]`,1)}
2795
+ ${e(`output_data[global_idx]`,2)}
2796
+ ${e(`output_data[global_idx]`,3)}
2797
+ `}return`
2798
+ ${e.registerUniform(`vec_size`,`u32`).declareVariables(c,o,s,a)}
2799
+ ${e.mainStart()}
2800
+ ${e.guardAgainstOutOfBoundsWorkgroupSizes(`uniforms.vec_size`)}
2801
+ ${l}
2802
+ }`},Yu=e=>{let t=e[1].dims,n=e[2].dims,r=e[0].dims,i=e[1].dataType,a=!(W.areEqual(t,n)&&W.areEqual(n,r)),o=t,s=W.size(t);if(a){let e=mn.calcShape(mn.calcShape(t,n,!1),r,!1);if(!e)throw Error(`Can't perform where op on the given tensors`);o=e,s=W.size(o)}let c=Math.ceil(s/4);return{name:`Where`,shaderCache:{inputDependencies:[`rank`,`rank`,`rank`]},getShaderSource:t=>Ju(t,e,o,a,i),getRunData:()=>({outputs:[{dims:o,dataType:i}],dispatchGroup:{x:Math.ceil(s/64/4)},programUniforms:[{type:12,data:c},...K(r,t,n,o)]})}},Xu=e=>{e.compute(Yu(e.inputs))}}),Qu,$u=M(()=>{_i(),Ei(),ji(),Fi(),ja(),Ga(),Qa(),Ko(),is(),cs(),ms(),Es(),Ms(),Fs(),Bs(),Ws(),Ys(),ec(),ac(),bc(),Kc(),Zc(),tl(),il(),ul(),Oc(),bl(),Bl(),Gl(),Yl(),nu(),fi(),Cu(),Bc(),Du(),Iu(),Vu(),Ic(),qu(),_r(),Da(),Zu(),Qu=new Map([[`Abs`,[Ri]],[`Acos`,[zi]],[`Acosh`,[Bi]],[`Add`,[Fa]],[`ArgMax`,[hi,gi]],[`ArgMin`,[mi,gi]],[`Asin`,[Vi]],[`Asinh`,[Hi]],[`Atan`,[Ui]],[`Atanh`,[Wi]],[`Attention`,[Ti]],[`AveragePool`,[jl,Al]],[`BatchNormalization`,[Ai]],[`BiasAdd`,[Pi]],[`BiasSplitGelu`,[Aa]],[`Cast`,[Ki,Gi]],[`Ceil`,[Yi]],[`Clip`,[Ji]],[`Concat`,[Xa,Za]],[`Conv`,[Go,Vo]],[`ConvTranspose`,[rs,$o]],[`Cos`,[Xi]],[`Cosh`,[Zi]],[`CumSum`,[os,ss]],[`DepthToSpace`,[fs,ps]],[`DequantizeLinear`,[Ul,Wl]],[`Div`,[Ia]],[`Einsum`,[ws,Ts]],[`Elu`,[$i,Qi]],[`Equal`,[La]],[`Erf`,[ta]],[`Exp`,[na]],[`Expand`,[js]],[`FastGelu`,[Ps]],[`Floor`,[ra]],[`FusedConv`,[Go,Vo]],[`Gather`,[zs,Rs]],[`GatherElements`,[$s,Qs]],[`GatherBlockQuantized`,[qs,Js]],[`GatherND`,[Hs,Us]],[`Gelu`,[ia]],[`Gemm`,[ic,rc]],[`GlobalAveragePool`,[Pl,Nl]],[`GlobalMaxPool`,[zl,Rl]],[`Greater`,[Va]],[`GreaterOrEqual`,[Ua]],[`GridSample`,[vc,yc]],[`GroupQueryAttention`,[Gc]],[`HardSigmoid`,[fa,da]],[`InstanceNormalization`,[Xc]],[`LayerNormalization`,[el]],[`LeakyRelu`,[aa,Qi]],[`Less`,[Ha]],[`LessOrEqual`,[Wa]],[`Log`,[Ca]],[`MatMul`,[rl]],[`MatMulNBits`,[cl,ll]],[`MaxPool`,[Il,Ll]],[`Mul`,[Ra]],[`MultiHeadAttention`,[Dc,Cc]],[`Neg`,[sa]],[`Not`,[oa]],[`Pad`,[yl]],[`Pow`,[za]],[`QuickGelu`,[Ea,Qi]],[`Range`,[Jl]],[`Reciprocal`,[ca]],[`ReduceMin`,[si]],[`ReduceMean`,[ni]],[`ReduceMax`,[oi]],[`ReduceSum`,[li]],[`ReduceProd`,[ci]],[`ReduceL1`,[ri]],[`ReduceL2`,[ii]],[`ReduceLogSum`,[di]],[`ReduceLogSumExp`,[ai]],[`ReduceSumSquare`,[ui]],[`Relu`,[la]],[`Resize`,[xu,Su]],[`RotaryEmbedding`,[zc]],[`ScatterND`,[tu,eu]],[`Sigmoid`,[ua]],[`Sin`,[pa]],[`Sinh`,[ma]],[`Slice`,[Pu,Fu]],[`SkipLayerNormalization`,[Eu]],[`Split`,[Pc,Fc]],[`Sqrt`,[ha]],[`Softmax`,[zu,Bu]],[`Sub`,[Ba]],[`Tan`,[ga]],[`Tanh`,[va]],[`ThresholdedRelu`,[Sa,Qi]],[`Tile`,[Ku]],[`Transpose`,[hr,gr]],[`Where`,[Xu]]])}),ed,td=M(()=>{Qe(),fn(),X(),ed=class{constructor(e){this.backend=e,this.repo=new Map,this.attributesBound=!1}getArtifact(e){return this.repo.get(e)}setArtifact(e,t){this.repo.set(e,t)}run(e,t,n,r,i){Ve(e.programInfo.name);let a=this.backend.device,o=this.backend.getComputePassEncoder();this.backend.writeTimestamp(this.backend.pendingDispatchNumber*2);let s=[];for(let e of t)s.push({binding:s.length,resource:{buffer:e.buffer}});for(let e of n)s.push({binding:s.length,resource:{buffer:e.buffer}});i&&s.push({binding:s.length,resource:i});let c=a.createBindGroup({layout:e.computePipeline.getBindGroupLayout(0),entries:s,label:e.programInfo.name});if(this.backend.sessionStatus===`capturing`){let t={kernelId:this.backend.currentKernelId,computePipeline:e.computePipeline,bindGroup:c,dispatchGroup:r};this.backend.capturedCommandList.get(this.backend.currentSessionId).push(t)}o.setPipeline(e.computePipeline),o.setBindGroup(0,c),o.dispatchWorkgroups(...r),this.backend.writeTimestamp(this.backend.pendingDispatchNumber*2+1),this.backend.pendingDispatchNumber++,(this.backend.pendingDispatchNumber>=this.backend.maxDispatchNumber||this.backend.queryType===`at-passes`)&&this.backend.endComputePass(),this.backend.pendingDispatchNumber>=this.backend.maxDispatchNumber&&this.backend.flush(),He(e.programInfo.name)}dispose(){}build(e,t){Ve(e.name);let n=this.backend.device,r=[];[{feature:`shader-f16`,extension:`f16`},{feature:`subgroups`,extension:`subgroups`}].forEach(e=>{n.features.has(e.feature)&&r.push(`enable ${e.extension};`)});let i=cr(t,this.backend.device.limits),a=e.getShaderSource(i),o=`${r.join(`
2803
+ `)}
2804
+ ${i.additionalImplementations}
2805
+ ${a}`,s=n.createShaderModule({code:o,label:e.name});U(`verbose`,()=>`[WebGPU] ${e.name} shader code: ${o}`);let c=n.createComputePipeline({compute:{module:s,entryPoint:`main`},layout:`auto`,label:e.name});return He(e.name),{programInfo:e,computePipeline:c,uniformVariablesInfo:i.variablesInfo}}normalizeDispatchGroupSize(e){let t=typeof e==`number`?e:e.x,n=typeof e==`number`?1:e.y||1,r=typeof e==`number`?1:e.z||1,i=this.backend.device.limits.maxComputeWorkgroupsPerDimension;if(t<=i&&n<=i&&r<=i)return[t,n,r];let a=t*n*r,o=Math.ceil(Math.sqrt(a));if(o>i){if(o=Math.ceil(Math.cbrt(a)),o>i)throw Error(`Total dispatch size exceeds WebGPU maximum.`);return[o,o,o]}else return[o,o,1]}}}),nd={};N(nd,{WebGpuBackend:()=>od});var rd,id,ad,od,sd=M(()=>{Qe(),H(),fn(),bn(),Kn(),$u(),td(),rd=(e,t)=>{if(t.length!==e.length)throw Error(`inputDependencies length ${t.length} is not equal to inputTensors length ${e.length}.`);let n=[];for(let r=0;r<e.length;++r){let i=e[r].dataType;switch(t[r]){case`none`:n.push(``);break;case`type`:n.push(`${i}`);break;case`rank`:{let t=e[r].dims.length;n.push(`${i};${t}`);break}case`dims`:{let t=e[r].dims.join(`,`);n.push(`${i};${t}`);break}default:throw Error(`unsupported input dependency: ${t[r]}`)}}return n.join(`|`)},id=(e,t,n)=>{let r=e.name;return e.shaderCache?.hint&&(r+=`[`+e.shaderCache.hint+`]`),r+=`:`+n+`:${rd(t,e.shaderCache?.inputDependencies??Array(t.length).fill(`dims`))}`,r},ad=class{constructor(e){e&&(this.architecture=e.architecture,this.vendor=e.vendor)}isArchitecture(e){return this.architecture===e}isVendor(e){return this.vendor===e}},od=class{constructor(){this.currentSessionId=null,this.currentKernelId=null,this.commandEncoder=null,this.computePassEncoder=null,this.maxDispatchNumber=16,this.pendingDispatchNumber=0,this.pendingKernels=[],this.pendingQueries=new Map,this.sessionStatus=`default`,this.capturedCommandList=new Map,this.capturedPendingKernels=new Map,this.sessionExternalDataMapping=new Map}get currentKernelCustomData(){if(this.currentKernelId===null)throw Error(`currentKernelCustomData(): currentKernelId is null. (should not happen)`);let e=this.kernelCustomData.get(this.currentKernelId);return e||(e={},this.kernelCustomData.set(this.currentKernelId,e)),e}async initialize(e,t){this.env=e;let n=[],r={requiredLimits:{maxComputeWorkgroupStorageSize:t.limits.maxComputeWorkgroupStorageSize,maxComputeWorkgroupsPerDimension:t.limits.maxComputeWorkgroupsPerDimension,maxStorageBufferBindingSize:t.limits.maxStorageBufferBindingSize,maxBufferSize:t.limits.maxBufferSize,maxComputeInvocationsPerWorkgroup:t.limits.maxComputeInvocationsPerWorkgroup,maxComputeWorkgroupSizeX:t.limits.maxComputeWorkgroupSizeX,maxComputeWorkgroupSizeY:t.limits.maxComputeWorkgroupSizeY,maxComputeWorkgroupSizeZ:t.limits.maxComputeWorkgroupSizeZ},requiredFeatures:n},i=e=>t.features.has(e)&&n.push(e)&&!0;i(`chromium-experimental-timestamp-query-inside-passes`)||i(`timestamp-query`),i(`shader-f16`),i(`subgroups`),this.device=await t.requestDevice(r),this.adapterInfo=new ad(t.info||await t.requestAdapterInfo()),this.gpuDataManager=Gn(this),this.programManager=new ed(this),this.kernels=new Map,this.kernelPersistentData=new Map,this.kernelCustomData=new Map,un(e.logLevel,!!e.debug),this.device.onuncapturederror=e=>{e.error instanceof GPUValidationError&&console.error(`An uncaught WebGPU validation error was raised: ${e.error.message}`)},Object.defineProperty(this.env.webgpu,`device`,{value:this.device,writable:!1,enumerable:!0,configurable:!1}),Object.defineProperty(this.env.webgpu,`adapter`,{value:t,writable:!1,enumerable:!0,configurable:!1}),this.setQueryType()}dispose(){typeof this.querySet<`u`&&this.querySet.destroy(),this.gpuDataManager.dispose()}getCommandEncoder(){return this.commandEncoder||=this.device.createCommandEncoder(),this.commandEncoder}getComputePassEncoder(){if(!this.computePassEncoder){let e=this.getCommandEncoder(),t={};this.queryType===`at-passes`&&(t.timestampWrites={querySet:this.querySet,beginningOfPassWriteIndex:this.pendingDispatchNumber*2,endOfPassWriteIndex:this.pendingDispatchNumber*2+1}),this.computePassEncoder=e.beginComputePass(t)}return this.computePassEncoder}endComputePass(){this.computePassEncoder&&=(this.computePassEncoder.end(),null)}flush(){if(!this.commandEncoder)return;Ve(),this.endComputePass();let e;this.queryType!==`none`&&(this.commandEncoder.resolveQuerySet(this.querySet,0,this.pendingDispatchNumber*2,this.queryResolveBuffer,0),e=this.device.createBuffer({size:this.pendingDispatchNumber*2*8,usage:GPUBufferUsage.MAP_READ|GPUBufferUsage.COPY_DST}),this.pendingQueries.set(e,this.pendingKernels),this.pendingKernels=[],this.commandEncoder.copyBufferToBuffer(this.queryResolveBuffer,0,e,0,this.pendingDispatchNumber*2*8)),this.device.queue.submit([this.commandEncoder.finish()]),this.gpuDataManager.refreshPendingBuffers(),this.commandEncoder=null,this.pendingDispatchNumber=0,this.queryType!==`none`&&e.mapAsync(GPUMapMode.READ).then(()=>{let t=new BigUint64Array(e.getMappedRange()),n=this.pendingQueries.get(e);for(let e=0;e<t.length/2;e++){let r=n[e],i=r.kernelId,a=this.kernels.get(i),o=a.kernelType,s=a.kernelName,c=r.programName,l=r.inputTensorViews,u=r.outputTensorViews,d=t[e*2],f=t[e*2+1];typeof this.queryTimeBase>`u`&&(this.queryTimeBase=d);let p=Number(d-this.queryTimeBase),m=Number(f-this.queryTimeBase);if(!Number.isSafeInteger(p)||!Number.isSafeInteger(m))throw RangeError(`incorrect timestamp range`);if(this.env.webgpu.profiling?.ondata)this.env.webgpu.profiling.ondata({version:1,inputsMetadata:l.map(e=>({dims:e.dims,dataType:Xt(e.dataType)})),outputsMetadata:u.map(e=>({dims:e.dims,dataType:Xt(e.dataType)})),kernelId:i,kernelType:o,kernelName:s,programName:c,startTime:p,endTime:m});else{let e=``;l.forEach((t,n)=>{e+=`input[${n}]: [${t.dims}] | ${Xt(t.dataType)}, `});let t=``;u.forEach((e,n)=>{t+=`output[${n}]: [${e.dims}] | ${Xt(e.dataType)}, `}),console.log(`[profiling] kernel "${i}|${o}|${s}|${c}" ${e}${t}execution time: ${m-p} ns`)}Be(`GPU`,`${c}::${d}::${f}`)}e.unmap(),this.pendingQueries.delete(e)}),He()}run(e,t,n,r,i,a){Ve(e.name);let o=[];for(let e=0;e<t.length;++e){let n=t[e].data;if(n===0)continue;let r=this.gpuDataManager.get(n);if(!r)throw Error(`no GPU data for input: ${n}`);o.push(r)}let{outputs:s,dispatchGroup:c,programUniforms:l}=e.getRunData(t),u=n.length===0?s.map((e,t)=>t):n;if(u.length!==s.length)throw Error(`Output size ${u.length} must be equal to ${s.length}.`);let d=[],f=[];for(let e=0;e<s.length;++e){if(!Number.isInteger(u[e])||u[e]<-3||u[e]>=a)throw Error(`Invalid output index: ${u[e]}`);if(u[e]===-3)continue;let t=u[e]===-1,n=u[e]===-2,o=t||n?i(s[e].dataType,s[e].dims):r(u[e],s[e].dataType,s[e].dims);if(d.push(o),o.data===0)continue;let c=this.gpuDataManager.get(o.data);if(!c)throw Error(`no GPU data for output: ${o.data}`);if(t&&this.temporaryData.push(c),n){let e=this.kernelPersistentData.get(this.currentKernelId);e||(e=[],this.kernelPersistentData.set(this.currentKernelId,e)),e.push(c)}f.push(c)}if(o.length!==t.length||f.length!==d.length){if(f.length===0)return He(e.name),d;throw Error(`Program ${e.name} has zero-sized tensor(s) in inputs or outputs. This is not supported now.`)}let p;if(l){let e=0,t=[];l.forEach(n=>{let r=typeof n.data==`number`?[n.data]:n.data;if(r.length===0)return;let i=n.type===10?2:4,a,o;n.type===10?(o=r.length>4?16:r.length>2?8:r.length*i,a=r.length>4?16:i*r.length):(o=r.length<=2?r.length*i:16,a=16),e=Math.ceil(e/o)*o,t.push(e);let s=n.type===10?8:4;e+=r.length>4?Math.ceil(r.length/s)*a:r.length*i}),e=Math.ceil(e/16)*16;let n=new ArrayBuffer(e);l.forEach((e,r)=>{let i=t[r],a=typeof e.data==`number`?[e.data]:e.data;if(e.type===6)new Int32Array(n,i,a.length).set(a);else if(e.type===12)new Uint32Array(n,i,a.length).set(a);else if(e.type===10)new Uint16Array(n,i,a.length).set(a);else if(e.type===1)new Float32Array(n,i,a.length).set(a);else throw Error(`Unsupported uniform type: ${Xt(e.type)}`)});let r=this.gpuDataManager.create(e,GPUBufferUsage.COPY_DST|GPUBufferUsage.UNIFORM);this.device.queue.writeBuffer(r.buffer,0,n,0,e),this.gpuDataManager.release(r.id),p={offset:0,size:e,buffer:r.buffer}}let m=this.programManager.normalizeDispatchGroupSize(c),h=m[1]===1&&m[2]===1,g=id(e,t,h),_=this.programManager.getArtifact(g);if(_||(_=this.programManager.build(e,m),this.programManager.setArtifact(g,_),U(`info`,()=>`[artifact] key: ${g}, programName: ${e.name}`)),l&&_.uniformVariablesInfo){if(l.length!==_.uniformVariablesInfo.length)throw Error(`Uniform variables count mismatch: expect ${_.uniformVariablesInfo.length}, got ${l.length} in program "${_.programInfo.name}".`);for(let e=0;e<l.length;e++){let t=l[e],n=t.type,r=typeof t.data==`number`?1:t.data.length,[i,a]=_.uniformVariablesInfo[e];if(n!==i||r!==a)throw Error(`Uniform variable ${e} mismatch: expect type ${i} with size ${a}, got type ${n} with size ${r} in program "${_.programInfo.name}".`)}}if(U(`info`,()=>`[ProgramManager] run "${e.name}" (key=${g}) with ${m[0]}x${m[1]}x${m[2]}`),this.queryType!==`none`||this.sessionStatus===`capturing`){let e={kernelId:this.currentKernelId,programName:_.programInfo.name,inputTensorViews:t,outputTensorViews:d};this.pendingKernels.push(e),this.sessionStatus===`capturing`&&this.capturedPendingKernels.get(this.currentSessionId).push(e)}return this.programManager.run(_,o,f,m,p),He(e.name),d}upload(e,t){this.gpuDataManager.upload(e,t)}memcpy(e,t){this.gpuDataManager.memcpy(e,t)}async download(e,t){await this.gpuDataManager.download(e,t)}alloc(e){return this.gpuDataManager.create(e).id}free(e){return this.gpuDataManager.release(e)}createKernel(e,t,n,r){let i=Qu.get(e);if(!i)throw Error(`kernel not implemented: ${e}`);let a={kernelType:e,kernelName:r,kernelEntry:i[0],attributes:[i[1],n]};this.kernels.set(t,a)}releaseKernel(e){let t=this.kernelPersistentData.get(e);if(t){for(let e of t)this.gpuDataManager.release(e.id);this.kernelPersistentData.delete(e)}this.kernelCustomData.delete(e),this.kernels.delete(e)}computeKernel(e,t,n){let r=this.kernels.get(e);if(!r)throw Error(`kernel not created: ${e}`);let i=r.kernelType,a=r.kernelName,o=r.kernelEntry,s=r.attributes;if(this.currentKernelId!==null)throw Error(`kernel "[${i}] ${a}" is not allowed to be called recursively`);this.currentKernelId=e,s[0]&&=(s[1]=s[0](s[1]),void 0),U(`info`,()=>`[WebGPU] Start to run kernel "[${i}] ${a}"...`);let c=this.env.debug;this.temporaryData=[];try{return c&&this.device.pushErrorScope(`validation`),o(t,s[1]),0}catch(e){return n.push(Promise.resolve(`[WebGPU] Kernel "[${i}] ${a}" failed. ${e}`)),1}finally{c&&n.push(this.device.popErrorScope().then(e=>e?`GPU validation error for kernel "[${i}] ${a}": ${e.message}`:null));for(let e of this.temporaryData)this.gpuDataManager.release(e.id);this.temporaryData=[],this.currentKernelId=null}}registerBuffer(e,t,n,r){let i=this.sessionExternalDataMapping.get(e);i||(i=new Map,this.sessionExternalDataMapping.set(e,i));let a=i.get(t),o=this.gpuDataManager.registerExternalBuffer(n,r,a);return i.set(t,[o,n]),o}unregisterBuffers(e){let t=this.sessionExternalDataMapping.get(e);t&&(t.forEach(e=>this.gpuDataManager.unregisterExternalBuffer(e[0])),this.sessionExternalDataMapping.delete(e))}getBuffer(e){let t=this.gpuDataManager.get(e);if(!t)throw Error(`no GPU data for buffer: ${e}`);return t.buffer}createDownloader(e,t,n){return async()=>{let r=await Un(this,e,t);return yn(r.buffer,n)}}writeTimestamp(e){this.queryType===`inside-passes`&&this.computePassEncoder.writeTimestamp(this.querySet,e)}setQueryType(){this.queryType=`none`,(this.env.webgpu.profiling?.mode===`default`||(typeof this.env.trace>`u`?this.env.wasm.trace:this.env.trace))&&(this.device.features.has(`chromium-experimental-timestamp-query-inside-passes`)?this.queryType=`inside-passes`:this.device.features.has(`timestamp-query`)&&(this.queryType=`at-passes`),this.queryType!==`none`&&typeof this.querySet>`u`&&(this.querySet=this.device.createQuerySet({type:`timestamp`,count:this.maxDispatchNumber*2}),this.queryResolveBuffer=this.device.createBuffer({size:this.maxDispatchNumber*2*8,usage:GPUBufferUsage.COPY_SRC|GPUBufferUsage.QUERY_RESOLVE})))}captureBegin(){U(`info`,`captureBegin`),this.capturedCommandList.get(this.currentSessionId)||this.capturedCommandList.set(this.currentSessionId,[]),this.capturedPendingKernels.get(this.currentSessionId)||this.capturedPendingKernels.set(this.currentSessionId,[]),this.flush(),this.sessionStatus=`capturing`}captureEnd(){U(`info`,`captureEnd`),this.flush(),this.sessionStatus=`default`}replay(){U(`info`,`replay`),this.sessionStatus=`replaying`;let e=this.capturedCommandList.get(this.currentSessionId),t=this.capturedPendingKernels.get(this.currentSessionId),n=e.length;this.pendingKernels=[];for(let r=0;r<n;r++){let n=this.getComputePassEncoder(),i=e[r];this.writeTimestamp(this.pendingDispatchNumber*2),n.setPipeline(i.computePipeline),n.setBindGroup(0,i.bindGroup),n.dispatchWorkgroups(...i.dispatchGroup),this.writeTimestamp(this.pendingDispatchNumber*2+1),this.pendingDispatchNumber++,this.queryType!==`none`&&this.pendingKernels.push(t[r]),(this.pendingDispatchNumber>=this.maxDispatchNumber||this.queryType===`at-passes`)&&this.endComputePass(),this.pendingDispatchNumber>=this.maxDispatchNumber&&this.flush()}this.flush(),this.sessionStatus=`default`}onCreateSession(){this.gpuDataManager.onCreateSession()}onReleaseSession(e){this.unregisterBuffers(e),this.capturedCommandList.has(e)&&this.capturedCommandList.delete(e),this.capturedPendingKernels.has(e)&&this.capturedPendingKernels.delete(e),this.gpuDataManager.onReleaseSession(e)}onRunStart(e){this.currentSessionId=e,this.setQueryType()}}}),cd={};N(cd,{init:()=>dd});var ld,ud,dd,fd=M(()=>{H(),fn(),G(),Fn(),ld=class e{constructor(e,t,n,r){this.module=e,this.dataType=t,this.data=n,this.dims=r}getFloat32Array(){if(this.dataType!==1)throw Error(`Invalid data type`);let e=W.size(this.dims);return e===0?new Float32Array:new Float32Array(this.module.HEAP8.buffer,this.data,e)}getBigInt64Array(){if(this.dataType!==7)throw Error(`Invalid data type`);let e=W.size(this.dims);return e===0?new BigInt64Array:new BigInt64Array(this.module.HEAP8.buffer,this.data,e)}getInt32Array(){if(this.dataType!==6)throw Error(`Invalid data type`);let e=W.size(this.dims);return e===0?new Int32Array:new Int32Array(this.module.HEAP8.buffer,this.data,e)}getUint16Array(){if(this.dataType!==10&&this.dataType!==4)throw Error(`Invalid data type`);let e=W.size(this.dims);return e===0?new Uint16Array:new Uint16Array(this.module.HEAP8.buffer,this.data,e)}reshape(t){if(W.size(t)!==W.size(this.dims))throw Error(`Invalid new shape`);return new e(this.module,this.dataType,this.data,t)}},ud=class{constructor(e,t,n){this.module=e,this.backend=t,this.customDataOffset=0,this.customDataSize=0,this.adapterInfo=t.adapterInfo;let r=e.PTR_SIZE,i=n/e.PTR_SIZE,a=r===4?`i32`:`i64`;this.opKernelContext=Number(e.getValue(r*i++,a));let o=Number(e.getValue(r*i++,a));this.outputCount=Number(e.getValue(r*i++,a)),this.customDataOffset=Number(e.getValue(r*i++,`*`)),this.customDataSize=Number(e.getValue(r*i++,a));let s=[];for(let t=0;t<o;t++){let t=Number(e.getValue(r*i++,a)),n=Number(e.getValue(r*i++,`*`)),o=Number(e.getValue(r*i++,a)),c=[];for(let t=0;t<o;t++)c.push(Number(e.getValue(r*i++,a)));s.push(new ld(e,t,n,c))}this.inputs=s}get kernelCustomData(){return this.backend.currentKernelCustomData}get customDataBuffer(){return this.module.HEAPU8.subarray(this.customDataOffset,this.customDataOffset+this.customDataSize)}compute(e,t){let n=t?.inputs?.map(e=>typeof e==`number`?this.inputs[e]:e)??this.inputs,r=t?.outputs??[];return this.backend.run(e,n,r,(e,t,n)=>new ld(this.module,t,this.output(e,n),n),(e,t)=>{let n=Zt(e,t);if(!n)throw Error(`Unsupported data type: ${e}`);let r=n>0?this.backend.gpuDataManager.create(n).id:0;return new ld(this.module,e,r,t)},this.outputCount)}output(e,t){let n=this.module.stackSave();try{let n=this.module.PTR_SIZE,r=n===4?`i32`:`i64`,i=this.module.stackAlloc((1+t.length)*n);this.module.setValue(i,t.length,r);for(let e=0;e<t.length;e++)this.module.setValue(i+n*(e+1),t[e],r);return this.module._JsepOutput(this.opKernelContext,e,i)}catch(n){throw Error(`Failed to generate kernel's output[${e}] with dims [${t}]. If you are running with pre-allocated output, please make sure the output type/dims are correct. Error: ${n}`)}finally{this.module.stackRestore(n)}}},dd=async(e,t,n,r)=>{let i=t.jsepInit;if(!i)throw Error(`Failed to initialize JSEP. The WebAssembly module is not built with JSEP support.`);if(e===`webgpu`){let e=(sd(),le(nd)).WebGpuBackend,a=new e;await a.initialize(n,r),i(`webgpu`,[a,e=>a.alloc(Number(e)),e=>a.free(e),(e,n,r,i=!1)=>{if(i)U(`verbose`,()=>`[WebGPU] jsepCopyGpuToGpu: src=${Number(e)}, dst=${Number(n)}, size=${Number(r)}`),a.memcpy(Number(e),Number(n));else{U(`verbose`,()=>`[WebGPU] jsepCopyCpuToGpu: dataOffset=${Number(e)}, gpuDataId=${Number(n)}, size=${Number(r)}`);let i=t.HEAPU8.subarray(Number(e>>>0),Number(e>>>0)+Number(r));a.upload(Number(n),i)}},async(e,n,r)=>{U(`verbose`,()=>`[WebGPU] jsepCopyGpuToCpu: gpuDataId=${e}, dataOffset=${n}, size=${r}`),await a.download(Number(e),()=>t.HEAPU8.subarray(Number(n)>>>0,Number(n+r)>>>0))},(e,n,r)=>a.createKernel(e,Number(n),r,t.UTF8ToString(t._JsepGetNodeName(Number(n)))),e=>a.releaseKernel(e),(e,n,r,i)=>{U(`verbose`,()=>`[WebGPU] jsepRun: sessionHandle=${r}, kernel=${e}, contextDataOffset=${n}`);let o=new ud(t,a,Number(n));return a.computeKernel(Number(e),o,i)},()=>a.captureBegin(),()=>a.captureEnd(),()=>a.replay()])}else{let e=new Pn(n);i(`webnn`,[e,()=>e.reserveTensorId(),t=>e.releaseTensorId(t),async(t,n,r,i,a)=>e.ensureTensor(t,n,r,i,a),(t,n)=>{e.uploadTensor(t,n)},async(t,n)=>e.downloadTensor(t,n)])}}}),pd,md,hd,gd,_d,vd,yd,bd,xd,Sd,Cd,wd,Td,Ed=M(()=>{Vt(),Jt(),H(),Ft(),zt(),an(),pd=(e,t)=>{Pt()._OrtInit(e,t)!==0&&Rt(`Can't initialize onnxruntime.`)},md=async e=>{pd(e.wasm.numThreads,$t(e.logLevel))},hd=async(e,t)=>{Pt().asyncInit?.();{let n=(fd(),le(cd)).init;if(t===`webgpu`){if(typeof navigator>`u`||!navigator.gpu)throw Error(`WebGPU is not supported in current environment`);let t=e.webgpu.adapter;if(t){if(typeof t.limits!=`object`||typeof t.features!=`object`||typeof t.requestDevice!=`function`)throw Error("Invalid GPU adapter set in `env.webgpu.adapter`. It must be a GPUAdapter object.")}else{let n=e.webgpu.powerPreference;if(n!==void 0&&n!==`low-power`&&n!==`high-performance`)throw Error(`Invalid powerPreference setting: "${n}"`);let r=e.webgpu.forceFallbackAdapter;if(r!==void 0&&typeof r!=`boolean`)throw Error(`Invalid forceFallbackAdapter setting: "${r}"`);if(t=await navigator.gpu.requestAdapter({powerPreference:n,forceFallbackAdapter:r}),!t)throw Error(`Failed to get GPU adapter. You may need to enable flag "--enable-unsafe-webgpu" if you are using Chrome.`)}await n(`webgpu`,Pt(),e,t)}if(t===`webnn`){if(typeof navigator>`u`||!navigator.ml)throw Error(`WebNN is not supported in current environment`);await n(`webnn`,Pt(),e)}}},gd=new Map,_d=e=>{let t=Pt(),n=t.stackSave();try{let n=t.PTR_SIZE,r=t.stackAlloc(2*n);t._OrtGetInputOutputCount(e,r,r+n)!==0&&Rt(`Can't get session input/output count.`);let i=n===4?`i32`:`i64`;return[Number(t.getValue(r,i)),Number(t.getValue(r+n,i))]}finally{t.stackRestore(n)}},vd=(e,t)=>{let n=Pt(),r=n.stackSave(),i=0;try{let r=n.PTR_SIZE,a=n.stackAlloc(2*r);n._OrtGetInputOutputMetadata(e,t,a,a+r)!==0&&Rt(`Can't get session input/output metadata.`);let o=Number(n.getValue(a,`*`));i=Number(n.getValue(a+r,`*`));let s=n.HEAP32[i/4];if(s===0)return[o,0];let c=n.HEAPU32[i/4+1],l=[];for(let e=0;e<c;e++){let t=Number(n.getValue(i+8+e*r,`*`));l.push(t===0?Number(n.getValue(i+8+(e+c)*r,`*`)):n.UTF8ToString(t))}return[o,s,l]}finally{n.stackRestore(r),i!==0&&n._OrtFree(i)}},yd=e=>{let t=Pt(),n=t._malloc(e.byteLength);if(n===0)throw Error(`Can't create a session. failed to allocate a buffer of size ${e.byteLength}.`);return t.HEAPU8.set(e,n),[n,e.byteLength]},bd=async(e,t)=>{let n,r,i=Pt();Array.isArray(e)?[n,r]=e:e.buffer===i.HEAPU8.buffer?[n,r]=[e.byteOffset,e.byteLength]:[n,r]=yd(e);let a=0,o=0,s=0,c=[],l=[],u=[];try{if([o,c]=await qt(t),t?.externalData&&i.mountExternalData){let e=[];for(let n of t.externalData){let t=typeof n==`string`?n:n.path;e.push(rn(typeof n==`string`?n:n.data).then(e=>{i.mountExternalData(t,e)}))}await Promise.all(e)}for(let e of t?.executionProviders??[])if((typeof e==`string`?e:e.name)===`webnn`){if(i.shouldTransferToMLTensor=!1,typeof e!=`string`){let t=e,n=t?.context,r=t?.gpuDevice,a=t?.deviceType,o=t?.powerPreference;n?i.currentContext=n:r?i.currentContext=await i.webnnCreateMLContext(r):i.currentContext=await i.webnnCreateMLContext({deviceType:a,powerPreference:o})}else i.currentContext=await i.webnnCreateMLContext();break}a=await i._OrtCreateSession(n,r,o),i.webgpuOnCreateSession?.(a),a===0&&Rt(`Can't create a session.`),i.jsepOnCreateSession?.(),i.currentContext&&(i.webnnRegisterMLContext(a,i.currentContext),i.currentContext=void 0,i.shouldTransferToMLTensor=!0);let[e,d]=_d(a),f=!!t?.enableGraphCapture,p=[],m=[],h=[],g=[],_=[];for(let t=0;t<e;t++){let[e,n,r]=vd(a,t);e===0&&Rt(`Can't get an input name.`),l.push(e);let o=i.UTF8ToString(e);p.push(o),h.push(n===0?{name:o,isTensor:!1}:{name:o,isTensor:!0,type:Xt(n),shape:r})}for(let n=0;n<d;n++){let[r,o,s]=vd(a,n+e);r===0&&Rt(`Can't get an output name.`),u.push(r);let c=i.UTF8ToString(r);m.push(c),g.push(o===0?{name:c,isTensor:!1}:{name:c,isTensor:!0,type:Xt(o),shape:s});{if(f&&t?.preferredOutputLocation===void 0){_.push(`gpu-buffer`);continue}let e=typeof t?.preferredOutputLocation==`string`?t.preferredOutputLocation:t?.preferredOutputLocation?.[c]??`cpu`;if(e!==`cpu`&&e!==`cpu-pinned`&&e!==`gpu-buffer`&&e!==`ml-tensor`)throw Error(`Not supported preferred output location: ${e}.`);if(f&&e!==`gpu-buffer`)throw Error(`Not supported preferred output location: ${e}. Only 'gpu-buffer' location is supported when enableGraphCapture is true.`);_.push(e)}}let v=null;return _.some(e=>e===`gpu-buffer`||e===`ml-tensor`)&&(s=i._OrtCreateBinding(a),s===0&&Rt(`Can't create IO binding.`),v={handle:s,outputPreferredLocations:_,outputPreferredLocationsEncoded:_.map(e=>nn(e))}),gd.set(a,[a,l,u,v,f,!1]),[a,p,m,h,g]}catch(e){throw l.forEach(e=>i._OrtFree(e)),u.forEach(e=>i._OrtFree(e)),s!==0&&i._OrtReleaseBinding(s)!==0&&Rt(`Can't release IO binding.`),a!==0&&i._OrtReleaseSession(a)!==0&&Rt(`Can't release session.`),e}finally{i._free(n),o!==0&&i._OrtReleaseSessionOptions(o)!==0&&Rt(`Can't release session options.`),c.forEach(e=>i._free(e)),i.unmountExternalData?.()}},xd=e=>{let t=Pt(),n=gd.get(e);if(!n)throw Error(`cannot release session. invalid session id: ${e}`);let[r,i,a,o,s]=n;o&&(s&&t._OrtClearBoundOutputs(o.handle)!==0&&Rt(`Can't clear bound outputs.`),t._OrtReleaseBinding(o.handle)!==0&&Rt(`Can't release IO binding.`)),t.jsepOnReleaseSession?.(e),t.webnnOnReleaseSession?.(e),t.webgpuOnReleaseSession?.(e),i.forEach(e=>t._OrtFree(e)),a.forEach(e=>t._OrtFree(e)),t._OrtReleaseSession(r)!==0&&Rt(`Can't release session.`),gd.delete(e)},Sd=async(e,t,n,r,i,a,o=!1)=>{if(!e){t.push(0);return}let s=Pt(),c=s.PTR_SIZE,l=e[0],u=e[1],d=e[3],f=d,p,m;if(l===`string`&&(d===`gpu-buffer`||d===`ml-tensor`))throw Error(`String tensor is not supported on GPU.`);if(o&&d!==`gpu-buffer`)throw Error(`External buffer must be provided for input/output index ${a} when enableGraphCapture is true.`);if(d===`gpu-buffer`){let t=e[2].gpuBuffer;m=Zt(Yt(l),u);{let e=s.jsepRegisterBuffer;if(!e)throw Error(`Tensor location "gpu-buffer" is not supported without using WebGPU.`);p=e(r,a,t,m)}}else if(d===`ml-tensor`){let t=e[2].mlTensor;m=Zt(Yt(l),u);let n=s.webnnRegisterMLTensor;if(!n)throw Error(`Tensor location "ml-tensor" is not supported without using WebNN.`);p=n(r,t,Yt(l),u)}else{let t=e[2];if(Array.isArray(t)){m=c*t.length,p=s._malloc(m),n.push(p);for(let e=0;e<t.length;e++){if(typeof t[e]!=`string`)throw TypeError(`tensor data at index ${e} is not a string`);s.setValue(p+e*c,It(t[e],n),`*`)}}else{let e=s.webnnIsGraphInput;if(l!==`string`&&e)if(e(r,s.UTF8ToString(i))){let e=Yt(l);m=Zt(e,u),f=`ml-tensor`;let n=s.webnnCreateTemporaryTensor,i=s.webnnUploadTensor;if(!n||!i)throw Error(`Tensor location "ml-tensor" is not supported without using WebNN.`);let a=await n(r,e,u);i(a,new Uint8Array(t.buffer,t.byteOffset,t.byteLength)),p=a}else m=t.byteLength,p=s._malloc(m),n.push(p),s.HEAPU8.set(new Uint8Array(t.buffer,t.byteOffset,m),p);else m=t.byteLength,p=s._malloc(m),n.push(p),s.HEAPU8.set(new Uint8Array(t.buffer,t.byteOffset,m),p)}}let h=s.stackSave(),g=s.stackAlloc(4*u.length);try{u.forEach((e,t)=>s.setValue(g+t*c,e,c===4?`i32`:`i64`));let e=s._OrtCreateTensor(Yt(l),p,m,g,u.length,nn(f));e===0&&Rt(`Can't create tensor for input/output. session=${r}, index=${a}.`),t.push(e)}finally{s.stackRestore(h)}},Cd=async(e,t,n,r,i,a)=>{let o=Pt(),s=o.PTR_SIZE,c=gd.get(e);if(!c)throw Error(`cannot run inference. invalid session id: ${e}`);let l=c[0],u=c[1],d=c[2],f=c[3],p=c[4],m=c[5],h=t.length,g=r.length,_=0,v=[],y=[],b=[],x=[],S=o.stackSave(),C=o.stackAlloc(h*s),w=o.stackAlloc(h*s),T=o.stackAlloc(g*s),E=o.stackAlloc(g*s);try{[_,v]=Bt(a);for(let r=0;r<h;r++)await Sd(n[r],y,x,e,u[t[r]],t[r],p);for(let t=0;t<g;t++)await Sd(i[t],b,x,e,d[r[t]],h+r[t],p);for(let e=0;e<h;e++)o.setValue(C+e*s,y[e],`*`),o.setValue(w+e*s,u[t[e]],`*`);for(let e=0;e<g;e++)o.setValue(T+e*s,b[e],`*`),o.setValue(E+e*s,d[r[e]],`*`);if(f&&!m){let{handle:n,outputPreferredLocations:a,outputPreferredLocationsEncoded:s}=f;if(u.length!==h)throw Error(`input count from feeds (${h}) is expected to be always equal to model's input count (${u.length}).`);for(let r=0;r<h;r++){let i=t[r];await o._OrtBindInput(n,u[i],y[r])!==0&&Rt(`Can't bind input[${r}] for session=${e}.`)}for(let t=0;t<g;t++){let c=r[t];i[t]?.[3]?o._OrtBindOutput(n,d[c],b[t],0)!==0&&Rt(`Can't bind pre-allocated output[${t}] for session=${e}.`):o._OrtBindOutput(n,d[c],0,s[c])!==0&&Rt(`Can't bind output[${t}] to ${a[t]} for session=${e}.`)}gd.set(e,[l,u,d,f,p,!0])}o.jsepOnRunStart?.(l),o.webnnOnRunStart?.(l);let c;c=f?await o._OrtRunWithBinding(l,f.handle,g,T,_):await o._OrtRun(l,w,C,h,E,g,T,_),c!==0&&Rt(`failed to call OrtRun().`);let S=[];for(let t=0;t<g;t++){let n=Number(o.getValue(T+t*s,`*`));if(n===b[t]){S.push(i[t]);continue}let a=o.stackSave(),c=o.stackAlloc(4*s),u=!1,d,p=0;try{o._OrtGetTensorData(n,c,c+s,c+2*s,c+3*s)!==0&&Rt(`Can't access output tensor data on index ${t}.`);let i=s===4?`i32`:`i64`,a=Number(o.getValue(c,i));p=o.getValue(c+s,`*`);let l=o.getValue(c+s*2,`*`),m=Number(o.getValue(c+s*3,i)),h=[];for(let e=0;e<m;e++)h.push(Number(o.getValue(l+e*s,i)));o._OrtFree(l)!==0&&Rt(`Can't free memory for tensor dims.`);let g=h.reduce((e,t)=>e*t,1);d=Xt(a);let _=f?.outputPreferredLocations[r[t]];if(d===`string`){if(_===`gpu-buffer`||_===`ml-tensor`)throw Error(`String tensor is not supported on GPU.`);let e=[];for(let t=0;t<g;t++){let n=o.getValue(p+t*s,`*`),r=o.getValue(p+(t+1)*s,`*`),i=t===g-1?void 0:r-n;e.push(o.UTF8ToString(n,i))}S.push([d,h,e,`cpu`])}else if(_===`gpu-buffer`&&g>0){let e=o.jsepGetBuffer;if(!e)throw Error(`preferredLocation "gpu-buffer" is not supported without using WebGPU.`);let t=e(p),r=Zt(a,g);if(r===void 0||!en(d))throw Error(`Unsupported data type: ${d}`);u=!0,S.push([d,h,{gpuBuffer:t,download:o.jsepCreateDownloader(t,r,d),dispose:()=>{o._OrtReleaseTensor(n)!==0&&Rt(`Can't release tensor.`)}},`gpu-buffer`])}else if(_===`ml-tensor`&&g>0){let t=o.webnnEnsureTensor,r=o.webnnIsInt64Supported;if(!t||!r)throw Error(`preferredLocation "ml-tensor" is not supported without using WebNN.`);if(Zt(a,g)===void 0||!tn(d))throw Error(`Unsupported data type: ${d}`);if(d===`int64`&&!r(e))throw Error(`preferredLocation "ml-tensor" for int64 output is not supported by current WebNN Context.`);let i=await t(e,p,a,h,!1);u=!0,S.push([d,h,{mlTensor:i,download:o.webnnCreateMLTensorDownloader(p,d),dispose:()=>{o.webnnReleaseTensorId(p),o._OrtReleaseTensor(n)}},`ml-tensor`])}else{let e=new(Qt(d))(g);new Uint8Array(e.buffer,e.byteOffset,e.byteLength).set(o.HEAPU8.subarray(p,p+e.byteLength)),S.push([d,h,e,`cpu`])}}finally{o.stackRestore(a),d===`string`&&p&&o._free(p),u||o._OrtReleaseTensor(n),o.webnnOnRunEnd?.(l)}}return f&&!p&&(o._OrtClearBoundOutputs(f.handle)!==0&&Rt(`Can't clear bound outputs.`),gd.set(e,[l,u,d,f,p,!1])),S}finally{o.stackRestore(S),y.forEach(e=>o._OrtReleaseTensor(e)),b.forEach(e=>o._OrtReleaseTensor(e)),x.forEach(e=>o._free(e)),_!==0&&o._OrtReleaseRunOptions(_),v.forEach(e=>o._free(e))}},wd=e=>{let t=Pt(),n=gd.get(e);if(!n)throw Error(`invalid session id`);let r=n[0],i=t._OrtEndProfiling(r);i===0&&Rt(`Can't get an profile file name.`),t._OrtFree(i)},Td=e=>{let t=[];for(let n of e){let e=n[2];!Array.isArray(e)&&`buffer`in e&&t.push(e.buffer)}return t}}),Dd,Od,kd,Ad,Q,jd,Md,Nd,Pd,Fd,Id,Ld,Rd,zd,Bd,Vd,Hd,Ud,Wd=M(()=>{Qe(),Ed(),Ft(),Tt(),Dd=()=>!!I.wasm.proxy&&typeof document<`u`,kd=!1,Ad=!1,Q=!1,Nd=new Map,Pd=(e,t)=>{let n=Nd.get(e);n?n.push(t):Nd.set(e,[t])},Fd=()=>{if(kd||!Ad||Q||!Od)throw Error(`worker not ready`)},Id=e=>{switch(e.data.type){case`init-wasm`:kd=!1,e.data.err?(Q=!0,Md[1](e.data.err)):(Ad=!0,Md[0]()),jd&&=(URL.revokeObjectURL(jd),void 0);break;case`init-ep`:case`copy-from`:case`create`:case`release`:case`run`:case`end-profiling`:{let t=Nd.get(e.data.type);e.data.err?t.shift()[1](e.data.err):t.shift()[0](e.data.out);break}default:}},Ld=async()=>{if(!Ad){if(kd)throw Error(`multiple calls to 'initWasm()' detected.`);if(Q)throw Error(`previous call to 'initWasm()' failed.`);if(kd=!0,Dd())return new Promise((e,t)=>{Od?.terminate(),St().then(([n,r])=>{try{Od=r,Od.onerror=e=>t(e),Od.onmessage=Id,Md=[e,t];let i={type:`init-wasm`,in:I};!i.in.wasm.wasmPaths&&(n||ft)&&(i.in.wasm.wasmPaths={wasm:new URL(`/assets/ort-wasm-simd-threaded.jsep-B0T3yYHD.wasm`,``+import.meta.url).href}),Od.postMessage(i),jd=n}catch(e){t(e)}},t)});try{await Nt(I.wasm),await md(I),Ad=!0}catch(e){throw Q=!0,e}finally{kd=!1}}},Rd=async e=>{if(Dd())return Fd(),new Promise((t,n)=>{Pd(`init-ep`,[t,n]);let r={type:`init-ep`,in:{epName:e,env:I}};Od.postMessage(r)});await hd(I,e)},zd=async e=>Dd()?(Fd(),new Promise((t,n)=>{Pd(`copy-from`,[t,n]);let r={type:`copy-from`,in:{buffer:e}};Od.postMessage(r,[e.buffer])})):yd(e),Bd=async(e,t)=>{if(Dd()){if(t?.preferredOutputLocation)throw Error(`session option "preferredOutputLocation" is not supported for proxy.`);return Fd(),new Promise((n,r)=>{Pd(`create`,[n,r]);let i={type:`create`,in:{model:e,options:{...t}}},a=[];e instanceof Uint8Array&&a.push(e.buffer),Od.postMessage(i,a)})}else return bd(e,t)},Vd=async e=>{if(Dd())return Fd(),new Promise((t,n)=>{Pd(`release`,[t,n]);let r={type:`release`,in:e};Od.postMessage(r)});xd(e)},Hd=async(e,t,n,r,i,a)=>{if(Dd()){if(n.some(e=>e[3]!==`cpu`))throw Error(`input tensor on GPU is not supported for proxy.`);if(i.some(e=>e))throw Error(`pre-allocated output tensor is not supported for proxy.`);return Fd(),new Promise((i,o)=>{Pd(`run`,[i,o]);let s=n,c={type:`run`,in:{sessionId:e,inputIndices:t,inputs:s,outputIndices:r,options:a}};Od.postMessage(c,Td(s))})}else return Cd(e,t,n,r,i,a)},Ud=async e=>{if(Dd())return Fd(),new Promise((t,n)=>{Pd(`end-profiling`,[t,n]);let r={type:`end-profiling`,in:e};Od.postMessage(r)});wd(e)}}),Gd,Kd,qd,Jd=M(()=>{Qe(),Wd(),H(),$e(),an(),Gd=(e,t)=>{switch(e.location){case`cpu`:return[e.type,e.dims,e.data,`cpu`];case`gpu-buffer`:return[e.type,e.dims,{gpuBuffer:e.gpuBuffer},`gpu-buffer`];case`ml-tensor`:return[e.type,e.dims,{mlTensor:e.mlTensor},`ml-tensor`];default:throw Error(`invalid data location: ${e.location} for ${t()}`)}},Kd=e=>{switch(e[3]){case`cpu`:return new Re(e[0],e[2],e[1]);case`gpu-buffer`:{let t=e[0];if(!en(t))throw Error(`not supported data type: ${t} for deserializing GPU tensor`);let{gpuBuffer:n,download:r,dispose:i}=e[2];return Re.fromGpuBuffer(n,{dataType:t,dims:e[1],download:r,dispose:i})}case`ml-tensor`:{let t=e[0];if(!tn(t))throw Error(`not supported data type: ${t} for deserializing MLTensor tensor`);let{mlTensor:n,download:r,dispose:i}=e[2];return Re.fromMLTensor(n,{dataType:t,dims:e[1],download:r,dispose:i})}default:throw Error(`invalid data location: ${e[3]}`)}},qd=class{async fetchModelAndCopyToWasmMemory(e){return zd(await rn(e))}async loadModel(e,t){Ve();let n;n=typeof e==`string`?await this.fetchModelAndCopyToWasmMemory(e):e,[this.sessionId,this.inputNames,this.outputNames,this.inputMetadata,this.outputMetadata]=await Bd(n,t),He()}async dispose(){return Vd(this.sessionId)}async run(e,t,n){Ve();let r=[],i=[];Object.entries(e).forEach(e=>{let t=e[0],n=e[1],a=this.inputNames.indexOf(t);if(a===-1)throw Error(`invalid input '${t}'`);r.push(n),i.push(a)});let a=[],o=[];Object.entries(t).forEach(e=>{let t=e[0],n=e[1],r=this.outputNames.indexOf(t);if(r===-1)throw Error(`invalid output '${t}'`);a.push(n),o.push(r)});let s=r.map((e,t)=>Gd(e,()=>`input "${this.inputNames[i[t]]}"`)),c=a.map((e,t)=>e?Gd(e,()=>`output "${this.outputNames[o[t]]}"`):null),l=await Hd(this.sessionId,i,s,o,c,n),u={};for(let e=0;e<l.length;e++)u[this.outputNames[o[e]]]=a[e]??Kd(l[e]);return He(),u}startProfiling(){}endProfiling(){Ud(this.sessionId)}}}),Yd={};N(Yd,{OnnxruntimeWebAssemblyBackend:()=>Zd,initializeFlags:()=>Xd,wasmBackend:()=>Qd});var Xd,Zd,Qd,$d=M(()=>{Qe(),Wd(),Jd(),Xd=()=>{(typeof I.wasm.initTimeout!=`number`||I.wasm.initTimeout<0)&&(I.wasm.initTimeout=0);let e=I.wasm.simd;if(typeof e!=`boolean`&&e!==void 0&&e!==`fixed`&&e!==`relaxed`&&(console.warn(`Property "env.wasm.simd" is set to unknown value "${e}". Reset it to \`false\` and ignore SIMD feature checking.`),I.wasm.simd=!1),typeof I.wasm.proxy!=`boolean`&&(I.wasm.proxy=!1),typeof I.wasm.trace!=`boolean`&&(I.wasm.trace=!1),typeof I.wasm.numThreads!=`number`||!Number.isInteger(I.wasm.numThreads)||I.wasm.numThreads<=0)if(typeof self<`u`&&!self.crossOriginIsolated)I.wasm.numThreads=1;else{let e=typeof navigator>`u`?se(`node:os`).cpus().length:navigator.hardwareConcurrency;I.wasm.numThreads=Math.min(4,Math.ceil((e||1)/2))}},Zd=class{async init(e){Xd(),await Ld(),await Rd(e)}async createInferenceSessionHandler(e,t){let n=new qd;return await n.loadModel(e,t),n}},Qd=new Zd});Qe(),Qe(),Qe();var ef=`1.22.0-dev.20250409-89f8206ba4`,tf=Ze;{let e=($d(),le(Yd)).wasmBackend;fe(`webgpu`,e,5),fe(`webnn`,e,5),fe(`cpu`,e,10),fe(`wasm`,e,10)}Object.defineProperty(I.versions,`web`,{value:ef,enumerable:!0});var nf={"onnxruntime-common":(e=>{e.exports=ne}),"onnxruntime-web":(e=>{e.exports=j}),"?2ce3":(()=>{}),"?7992":(()=>{}),"?5af5":(()=>{}),"?2b25":(()=>{}),"?db59":(()=>{}),"?383f":(()=>{}),"?fa4b":(()=>{}),"./node_modules/@huggingface/jinja/dist/index.js":((e,t,n)=>{n.r(t),n.d(t,{Environment:()=>Ee,Interpreter:()=>Ae,Template:()=>Ge,parse:()=>le,tokenize:()=>d});var r=Object.freeze({Text:`Text`,NumericLiteral:`NumericLiteral`,StringLiteral:`StringLiteral`,Identifier:`Identifier`,Equals:`Equals`,OpenParen:`OpenParen`,CloseParen:`CloseParen`,OpenStatement:`OpenStatement`,CloseStatement:`CloseStatement`,OpenExpression:`OpenExpression`,CloseExpression:`CloseExpression`,OpenSquareBracket:`OpenSquareBracket`,CloseSquareBracket:`CloseSquareBracket`,OpenCurlyBracket:`OpenCurlyBracket`,CloseCurlyBracket:`CloseCurlyBracket`,Comma:`Comma`,Dot:`Dot`,Colon:`Colon`,Pipe:`Pipe`,CallOperator:`CallOperator`,AdditiveBinaryOperator:`AdditiveBinaryOperator`,MultiplicativeBinaryOperator:`MultiplicativeBinaryOperator`,ComparisonBinaryOperator:`ComparisonBinaryOperator`,UnaryOperator:`UnaryOperator`,Comment:`Comment`}),i=class{constructor(e,t){this.value=e,this.type=t}};function a(e){return/\w/.test(e)}function o(e){return/[0-9]/.test(e)}function s(e){return/\s/.test(e)}var c=[[`{%`,r.OpenStatement],[`%}`,r.CloseStatement],[`{{`,r.OpenExpression],[`}}`,r.CloseExpression],[`(`,r.OpenParen],[`)`,r.CloseParen],[`{`,r.OpenCurlyBracket],[`}`,r.CloseCurlyBracket],[`[`,r.OpenSquareBracket],[`]`,r.CloseSquareBracket],[`,`,r.Comma],[`.`,r.Dot],[`:`,r.Colon],[`|`,r.Pipe],[`<=`,r.ComparisonBinaryOperator],[`>=`,r.ComparisonBinaryOperator],[`==`,r.ComparisonBinaryOperator],[`!=`,r.ComparisonBinaryOperator],[`<`,r.ComparisonBinaryOperator],[`>`,r.ComparisonBinaryOperator],[`+`,r.AdditiveBinaryOperator],[`-`,r.AdditiveBinaryOperator],[`~`,r.AdditiveBinaryOperator],[`*`,r.MultiplicativeBinaryOperator],[`/`,r.MultiplicativeBinaryOperator],[`%`,r.MultiplicativeBinaryOperator],[`=`,r.Equals]],l=new Map([[`n`,`
2806
+ `],[`t`,` `],[`r`,`\r`],[`b`,`\b`],[`f`,`\f`],[`v`,`\v`],[`'`,`'`],[`"`,`"`],[`\\`,`\\`]]);function u(e,t={}){return e.endsWith(`
2807
+ `)&&(e=e.slice(0,-1)),t.lstrip_blocks&&(e=e.replace(/^[ \t]*({[#%-])/gm,`$1`)),t.trim_blocks&&(e=e.replace(/([#%-]})\n/g,`$1`)),e.replace(/{%\s*(end)?generation\s*%}/gs,``)}function d(e,t={}){let n=[],d=u(e,t),f=0,p=0,m=e=>{let t=``;for(;e(d[f]);){if(d[f]===`\\`){if(++f,f>=d.length)throw SyntaxError(`Unexpected end of input`);let e=d[f++],n=l.get(e);if(n===void 0)throw SyntaxError(`Unexpected escaped character: ${e}`);t+=n;continue}if(t+=d[f++],f>=d.length)throw SyntaxError(`Unexpected end of input`)}return t},h=()=>{let e=n.at(-1);e&&e.type===r.Text&&(e.value=e.value.trimEnd(),e.value===``&&n.pop())},g=()=>{for(;f<d.length&&s(d[f]);)++f};main:for(;f<d.length;){let e=n.at(-1)?.type;if(e===void 0||e===r.CloseStatement||e===r.CloseExpression||e===r.Comment){let e=``;for(;f<d.length&&!(d[f]===`{`&&(d[f+1]===`%`||d[f+1]===`{`||d[f+1]===`#`));)e+=d[f++];if(e.length>0){n.push(new i(e,r.Text));continue}}if(d[f]===`{`&&d[f+1]===`#`){f+=2;let e=d[f]===`-`;e&&++f;let t=``;for(;d[f]!==`#`||d[f+1]!==`}`;){if(f+2>=d.length)throw SyntaxError(`Missing end of comment tag`);t+=d[f++]}let a=t.endsWith(`-`);a&&(t=t.slice(0,-1)),e&&h(),n.push(new i(t,r.Comment)),f+=2,a&&g();continue}if(d.slice(f,f+3)===`{%-`){h(),n.push(new i(`{%`,r.OpenStatement)),f+=3;continue}if(d.slice(f,f+3)===`{{-`){h(),n.push(new i(`{{`,r.OpenExpression)),p=0,f+=3;continue}if(m(s),d.slice(f,f+3)===`-%}`){n.push(new i(`%}`,r.CloseStatement)),f+=3,g();continue}if(d.slice(f,f+3)===`-}}`){n.push(new i(`}}`,r.CloseExpression)),f+=3,g();continue}let t=d[f];if(t===`-`||t===`+`){let e=n.at(-1)?.type;if(e===r.Text||e===void 0)throw SyntaxError(`Unexpected character: ${t}`);switch(e){case r.Identifier:case r.NumericLiteral:case r.StringLiteral:case r.CloseParen:case r.CloseSquareBracket:break;default:{++f;let e=m(o);n.push(new i(`${t}${e}`,e.length>0?r.NumericLiteral:r.UnaryOperator));continue}}}for(let[e,t]of c)if(!(e===`}}`&&p>0)&&d.slice(f,f+e.length)===e){n.push(new i(e,t)),t===r.OpenExpression?p=0:t===r.OpenCurlyBracket?++p:t===r.CloseCurlyBracket&&--p,f+=e.length;continue main}if(t===`'`||t===`"`){++f;let e=m(e=>e!==t);n.push(new i(e,r.StringLiteral)),++f;continue}if(o(t)){let e=m(o);if(d[f]===`.`&&o(d[f+1])){++f;let t=m(o);e=`${e}.${t}`}n.push(new i(e,r.NumericLiteral));continue}if(a(t)){let e=m(a);n.push(new i(e,r.Identifier));continue}throw SyntaxError(`Unexpected character: ${t}`)}return n}var f=class{type=`Statement`},p=class extends f{constructor(e){super(),this.body=e}type=`Program`},m=class extends f{constructor(e,t,n){super(),this.test=e,this.body=t,this.alternate=n}type=`If`},h=class extends f{constructor(e,t,n,r){super(),this.loopvar=e,this.iterable=t,this.body=n,this.defaultBlock=r}type=`For`},g=class extends f{type=`Break`},_=class extends f{type=`Continue`},v=class extends f{constructor(e,t,n){super(),this.assignee=e,this.value=t,this.body=n}type=`Set`},y=class extends f{constructor(e,t,n){super(),this.name=e,this.args=t,this.body=n}type=`Macro`},b=class extends f{constructor(e){super(),this.value=e}type=`Comment`},x=class extends f{type=`Expression`},S=class extends x{constructor(e,t,n){super(),this.object=e,this.property=t,this.computed=n}type=`MemberExpression`},C=class extends x{constructor(e,t){super(),this.callee=e,this.args=t}type=`CallExpression`},w=class extends x{constructor(e){super(),this.value=e}type=`Identifier`},T=class extends x{constructor(e){super(),this.value=e}type=`Literal`},E=class extends T{type=`IntegerLiteral`},D=class extends T{type=`FloatLiteral`},O=class extends T{type=`StringLiteral`},k=class extends T{type=`ArrayLiteral`},A=class extends T{type=`TupleLiteral`},ee=class extends T{type=`ObjectLiteral`},te=class extends x{constructor(e,t,n){super(),this.operator=e,this.left=t,this.right=n}type=`BinaryExpression`},ne=class extends x{constructor(e,t){super(),this.operand=e,this.filter=t}type=`FilterExpression`},j=class extends f{constructor(e,t){super(),this.filter=e,this.body=t}type=`FilterStatement`},re=class extends x{constructor(e,t){super(),this.lhs=e,this.test=t}type=`SelectExpression`},ie=class extends x{constructor(e,t,n){super(),this.operand=e,this.negate=t,this.test=n}type=`TestExpression`},ae=class extends x{constructor(e,t){super(),this.operator=e,this.argument=t}type=`UnaryExpression`},oe=class extends x{constructor(e=void 0,t=void 0,n=void 0){super(),this.start=e,this.stop=t,this.step=n}type=`SliceExpression`},se=class extends x{constructor(e,t){super(),this.key=e,this.value=t}type=`KeywordArgumentExpression`},M=class extends x{constructor(e){super(),this.argument=e}type=`SpreadExpression`},N=class extends f{constructor(e,t,n){super(),this.call=e,this.callerArgs=t,this.body=n}type=`CallStatement`},ce=class extends x{constructor(e,t,n){super(),this.condition=e,this.trueExpr=t,this.falseExpr=n}type=`Ternary`};function le(e){let t=new p([]),n=0;function a(t,r){let i=e[n++];if(!i||i.type!==t)throw Error(`Parser Error: ${r}. ${i.type} !== ${t}.`);return i}function o(e){if(!u(e))throw SyntaxError(`Expected ${e}`);++n}function s(){switch(e[n].type){case r.Comment:return new b(e[n++].value);case r.Text:return d();case r.OpenStatement:return f();case r.OpenExpression:return x();default:throw SyntaxError(`Unexpected token type: ${e[n].type}`)}}function c(...t){return n+t.length<=e.length&&t.every((t,r)=>t===e[n+r].type)}function l(...t){return e[n]?.type===r.OpenStatement&&e[n+1]?.type===r.Identifier&&t.includes(e[n+1]?.value)}function u(...t){return n+t.length<=e.length&&t.every((t,r)=>e[n+r].type===`Identifier`&&t===e[n+r].value)}function d(){return new O(a(r.Text,`Expected text token`).value)}function f(){if(a(r.OpenStatement,`Expected opening statement token`),e[n].type!==r.Identifier)throw SyntaxError(`Unknown statement, got ${e[n].type}`);let t=e[n].value,i;switch(t){case`set`:++n,i=T();break;case`if`:++n,i=le(),a(r.OpenStatement,`Expected {% token`),o(`endif`),a(r.CloseStatement,`Expected %} token`);break;case`macro`:++n,i=ue(),a(r.OpenStatement,`Expected {% token`),o(`endmacro`),a(r.CloseStatement,`Expected %} token`);break;case`for`:++n,i=fe(),a(r.OpenStatement,`Expected {% token`),o(`endfor`),a(r.CloseStatement,`Expected %} token`);break;case`call`:{++n;let e=null;c(r.OpenParen)&&(e=I());let t=z();if(t.type!==`Identifier`)throw SyntaxError(`Expected identifier following call statement`);let u=I();a(r.CloseStatement,`Expected closing statement token`);let d=[];for(;!l(`endcall`);)d.push(s());a(r.OpenStatement,`Expected '{%'`),o(`endcall`),a(r.CloseStatement,`Expected closing statement token`),i=new N(new C(t,u),e,d);break}case`break`:++n,a(r.CloseStatement,`Expected closing statement token`),i=new g;break;case`continue`:++n,a(r.CloseStatement,`Expected closing statement token`),i=new _;break;case`filter`:{++n;let e=z();e instanceof w&&c(r.OpenParen)&&(e=ye(e)),a(r.CloseStatement,`Expected closing statement token`);let t=[];for(;!l(`endfilter`);)t.push(s());a(r.OpenStatement,`Expected '{%'`),o(`endfilter`),a(r.CloseStatement,`Expected '%}'`),i=new j(e,t);break}default:throw SyntaxError(`Unknown statement type: ${t}`)}return i}function x(){a(r.OpenExpression,`Expected opening expression token`);let e=pe();return a(r.CloseExpression,`Expected closing expression token`),e}function T(){let e=de(),t=null,i=[];if(c(r.Equals))++n,t=de();else{for(a(r.CloseStatement,`Expected %} token`);!l(`endset`);)i.push(s());a(r.OpenStatement,`Expected {% token`),o(`endset`)}return a(r.CloseStatement,`Expected closing statement token`),new v(e,t,i)}function le(){let e=pe();a(r.CloseStatement,`Expected closing statement token`);let t=[],i=[];for(;!l(`elif`,`else`,`endif`);)t.push(s());if(l(`elif`)){++n,++n;let e=le();i.push(e)}else if(l(`else`))for(++n,++n,a(r.CloseStatement,`Expected closing statement token`);!l(`endif`);)i.push(s());return new m(e,t,i)}function ue(){let e=z();if(e.type!==`Identifier`)throw SyntaxError(`Expected identifier following macro statement`);let t=I();a(r.CloseStatement,`Expected closing statement token`);let n=[];for(;!l(`endmacro`);)n.push(s());return new y(e,t,n)}function de(e=!1){let t=e?z:pe,i=[t()],a=c(r.Comma);for(;a&&(++n,i.push(t()),c(r.Comma)););return a?new A(i):i[0]}function fe(){let e=de(!0);if(!(e instanceof w||e instanceof A))throw SyntaxError(`Expected identifier/tuple for the loop variable, got ${e.type} instead`);if(!u(`in`))throw SyntaxError("Expected `in` keyword following loop variable");++n;let t=pe();a(r.CloseStatement,`Expected closing statement token`);let i=[];for(;!l(`endfor`,`else`);)i.push(s());let o=[];if(l(`else`))for(++n,++n,a(r.CloseStatement,`Expected closing statement token`);!l(`endfor`);)o.push(s());return new h(e,t,i,o)}function pe(){return P()}function P(){let e=me();if(u(`if`)){++n;let t=me();return u(`else`)?(++n,new ce(t,e,P())):new re(e,t)}return e}function me(){let t=he();for(;u(`or`);){let r=e[n];++n;let i=he();t=new te(r,t,i)}return t}function he(){let t=ge();for(;u(`and`);){let r=e[n];++n;let i=ge();t=new te(r,t,i)}return t}function ge(){let t;for(;u(`not`);){let r=e[n];++n,t=new ae(r,ge())}return t??_e()}function _e(){let t=ve();for(;;){let a;if(u(`not`,`in`))a=new i(`not in`,r.Identifier),n+=2;else if(u(`in`))a=e[n++];else if(c(r.ComparisonBinaryOperator))a=e[n++];else break;let o=ve();t=new te(a,t,o)}return t}function ve(){let t=Se();for(;c(r.AdditiveBinaryOperator);){let r=e[n];++n;let i=Se();t=new te(r,t,i)}return t}function F(){let e=xe(z());return c(r.OpenParen)?ye(e):e}function ye(e){let t=new C(e,I());return t=xe(t),c(r.OpenParen)&&(t=ye(t)),t}function I(){a(r.OpenParen,`Expected opening parenthesis for arguments list`);let e=L();return a(r.CloseParen,`Expected closing parenthesis for arguments list`),e}function L(){let t=[];for(;!c(r.CloseParen);){let i;if(e[n].type===r.MultiplicativeBinaryOperator&&e[n].value===`*`)++n,i=new M(pe());else if(i=pe(),c(r.Equals)){if(++n,!(i instanceof w))throw SyntaxError(`Expected identifier for keyword argument`);let e=pe();i=new se(i,e)}t.push(i),c(r.Comma)&&++n}return t}function be(){let e=[],t=!1;for(;!c(r.CloseSquareBracket);)c(r.Colon)?(e.push(void 0),++n,t=!0):(e.push(pe()),c(r.Colon)&&(++n,t=!0));if(e.length===0)throw SyntaxError(`Expected at least one argument for member/slice expression`);if(t){if(e.length>3)throw SyntaxError(`Expected 0-3 arguments for slice expression`);return new oe(...e)}return e[0]}function xe(t){for(;c(r.Dot)||c(r.OpenSquareBracket);){let i=e[n];++n;let o,s=i.type===r.OpenSquareBracket;if(s)o=be(),a(r.CloseSquareBracket,`Expected closing square bracket`);else if(o=z(),o.type!==`Identifier`)throw SyntaxError(`Expected identifier following dot operator`);t=new S(t,o,s)}return t}function Se(){let t=R();for(;c(r.MultiplicativeBinaryOperator);){let r=e[n++],i=R();t=new te(r,t,i)}return t}function R(){let e=Ce();for(;u(`is`);){++n;let t=u(`not`);t&&++n;let r=z();if(!(r instanceof w))throw SyntaxError(`Expected identifier for the test`);e=new ie(e,t,r)}return e}function Ce(){let e=F();for(;c(r.Pipe);){++n;let t=z();if(!(t instanceof w))throw SyntaxError(`Expected identifier for the filter`);c(r.OpenParen)&&(t=ye(t)),e=new ne(e,t)}return e}function z(){let t=e[n++];switch(t.type){case r.NumericLiteral:{let e=t.value;return e.includes(`.`)?new D(Number(e)):new E(Number(e))}case r.StringLiteral:{let i=t.value;for(;c(r.StringLiteral);)i+=e[n++].value;return new O(i)}case r.Identifier:return new w(t.value);case r.OpenParen:{let e=de();return a(r.CloseParen,"Expected closing parenthesis, got ${tokens[current].type} instead."),e}case r.OpenSquareBracket:{let e=[];for(;!c(r.CloseSquareBracket);)e.push(pe()),c(r.Comma)&&++n;return++n,new k(e)}case r.OpenCurlyBracket:{let e=new Map;for(;!c(r.CloseCurlyBracket);){let t=pe();a(r.Colon,`Expected colon between key and value in object literal`);let i=pe();e.set(t,i),c(r.Comma)&&++n}return++n,new ee(e)}default:throw SyntaxError(`Unexpected token: ${t.type}`)}}for(;n<e.length;)t.body.push(s());return t}function ue(e,t,n=1){t===void 0&&(t=e,e=0);let r=[];for(let i=e;i<t;i+=n)r.push(i);return r}function de(e,t,n,r=1){let i=Math.sign(r);i>=0?(t=(t??=0)<0?Math.max(e.length+t,0):Math.min(t,e.length),n=(n??=e.length)<0?Math.max(e.length+n,0):Math.min(n,e.length)):(t=(t??=e.length-1)<0?Math.max(e.length+t,-1):Math.min(t,e.length-1),n=(n??=-1)<-1?Math.max(e.length+n,-1):Math.min(n,e.length-1));let a=[];for(let o=t;i*o<i*n;o+=r)a.push(e[o]);return a}function fe(e){return e.replace(/\b\w/g,e=>e.toUpperCase())}function pe(e){return P(new Date,e)}function P(e,t){let n=new Intl.DateTimeFormat(void 0,{month:`long`}),r=new Intl.DateTimeFormat(void 0,{month:`short`}),i=e=>e<10?`0`+e:e.toString();return t.replace(/%[YmdbBHM%]/g,t=>{switch(t){case`%Y`:return e.getFullYear().toString();case`%m`:return i(e.getMonth()+1);case`%d`:return i(e.getDate());case`%b`:return r.format(e);case`%B`:return n.format(e);case`%H`:return i(e.getHours());case`%M`:return i(e.getMinutes());case`%%`:return`%`;default:return t}})}function me(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function he(e,t,n,r){if(r===0)return e;let i=r==null||r<0?1/0:r,a=t.length===0?RegExp(`(?=)`,`gu`):new RegExp(me(t),`gu`);return e.replaceAll(a,e=>i>0?(--i,n):e)}var ge=class extends Error{},_e=class extends Error{},ve=class{type=`RuntimeValue`;value;builtins=new Map;constructor(e=void 0){this.value=e}__bool__(){return new L(!!this.value)}toString(){return String(this.value)}},F=class extends ve{type=`IntegerValue`},ye=class extends ve{type=`FloatValue`;toString(){return this.value%1==0?this.value.toFixed(1):this.value.toString()}},I=class extends ve{type=`StringValue`;builtins=new Map([[`upper`,new z(()=>new I(this.value.toUpperCase()))],[`lower`,new z(()=>new I(this.value.toLowerCase()))],[`strip`,new z(()=>new I(this.value.trim()))],[`title`,new z(()=>new I(fe(this.value)))],[`capitalize`,new z(()=>new I(this.value.charAt(0).toUpperCase()+this.value.slice(1)))],[`length`,new F(this.value.length)],[`rstrip`,new z(()=>new I(this.value.trimEnd()))],[`lstrip`,new z(()=>new I(this.value.trimStart()))],[`startswith`,new z(e=>{if(e.length===0)throw Error(`startswith() requires at least one argument`);let t=e[0];if(t instanceof I)return new L(this.value.startsWith(t.value));if(t instanceof R){for(let e of t.value){if(!(e instanceof I))throw Error(`startswith() tuple elements must be strings`);if(this.value.startsWith(e.value))return new L(!0)}return new L(!1)}throw Error(`startswith() argument must be a string or tuple of strings`)})],[`endswith`,new z(e=>{if(e.length===0)throw Error(`endswith() requires at least one argument`);let t=e[0];if(t instanceof I)return new L(this.value.endsWith(t.value));if(t instanceof R){for(let e of t.value){if(!(e instanceof I))throw Error(`endswith() tuple elements must be strings`);if(this.value.endsWith(e.value))return new L(!0)}return new L(!1)}throw Error(`endswith() argument must be a string or tuple of strings`)})],[`split`,new z(e=>{let t=e[0]??new we;if(!(t instanceof I||t instanceof we))throw Error(`sep argument must be a string or null`);let n=e[1]??new F(-1);if(!(n instanceof F))throw Error(`maxsplit argument must be a number`);let r=[];if(t instanceof we){let e=this.value.trimStart();for(let{0:t,index:i}of e.matchAll(/\S+/g)){if(n.value!==-1&&r.length>=n.value&&i!==void 0){r.push(t+e.slice(i+t.length));break}r.push(t)}}else{if(t.value===``)throw Error(`empty separator`);r=this.value.split(t.value),n.value!==-1&&r.length>n.value&&r.push(r.splice(n.value).join(t.value))}return new R(r.map(e=>new I(e)))})],[`replace`,new z(e=>{if(e.length<2)throw Error(`replace() requires at least two arguments`);let t=e[0],n=e[1];if(!(t instanceof I&&n instanceof I))throw Error(`replace() arguments must be strings`);let r;if(r=e.length>2?e[2].type===`KeywordArgumentsValue`?e[2].value.get(`count`)??new we:e[2]:new we,!(r instanceof F||r instanceof we))throw Error(`replace() count argument must be a number or null`);return new I(he(this.value,t.value,n.value,r.value))})]])},L=class extends ve{type=`BooleanValue`};function be(e,t,n,r=!0){let i=n??0;switch(e.type){case`NullValue`:return`null`;case`UndefinedValue`:return r?`null`:`undefined`;case`IntegerValue`:case`FloatValue`:case`StringValue`:case`BooleanValue`:return JSON.stringify(e.value);case`ArrayValue`:case`ObjectValue`:{let n=t?` `.repeat(t):``,a=`
2808
+ `+n.repeat(i),o=a+n;if(e.type===`ArrayValue`){let n=e.value.map(e=>be(e,t,i+1,r));return t?`[${o}${n.join(`,${o}`)}${a}]`:`[${n.join(`, `)}]`}else{let n=Array.from(e.value.entries()).map(([e,n])=>{let a=`"${e}": ${be(n,t,i+1,r)}`;return t?`${o}${a}`:a});return t?`{${n.join(`,`)}${a}}`:`{${n.join(`, `)}}`}}default:throw Error(`Cannot convert to JSON: ${e.type}`)}}var xe=class extends ve{type=`ObjectValue`;__bool__(){return new L(this.value.size>0)}builtins=new Map([[`get`,new z(([e,t])=>{if(!(e instanceof I))throw Error(`Object key must be a string: got ${e.type}`);return this.value.get(e.value)??t??new we})],[`items`,new z(()=>this.items())],[`keys`,new z(()=>this.keys())],[`values`,new z(()=>this.values())],[`dictsort`,new z(e=>{let t=new Map,n=e.filter(e=>e instanceof Se?(t=e.value,!1):!0),r=n.at(0)??t.get(`case_sensitive`)??new L(!1);if(!(r instanceof L))throw Error(`case_sensitive must be a boolean`);let i=n.at(1)??t.get(`by`)??new I(`key`);if(!(i instanceof I))throw Error(`by must be a string`);if(![`key`,`value`].includes(i.value))throw Error(`by must be either 'key' or 'value'`);let a=n.at(2)??t.get(`reverse`)??new L(!1);if(!(a instanceof L))throw Error(`reverse must be a boolean`);return new R(Array.from(this.value.entries()).map(([e,t])=>new R([new I(e),t])).sort((e,t)=>{let n=i.value===`key`?0:1,o=e.value[n],s=t.value[n],c=ke(o,s,r.value);return a.value?-c:c}))})]]);items(){return new R(Array.from(this.value.entries()).map(([e,t])=>new R([new I(e),t])))}keys(){return new R(Array.from(this.value.keys()).map(e=>new I(e)))}values(){return new R(Array.from(this.value.values()))}toString(){return be(this,null,0,!1)}},Se=class extends xe{type=`KeywordArgumentsValue`},R=class extends ve{type=`ArrayValue`;builtins=new Map([[`length`,new F(this.value.length)]]);__bool__(){return new L(this.value.length>0)}toString(){return be(this,null,0,!1)}},Ce=class extends R{type=`TupleValue`},z=class extends ve{type=`FunctionValue`},we=class extends ve{type=`NullValue`},Te=class extends ve{type=`UndefinedValue`},Ee=class{constructor(e){this.parent=e}variables=new Map([[`namespace`,new z(e=>{if(e.length===0)return new xe(new Map);if(e.length!==1||!(e[0]instanceof xe))throw Error("`namespace` expects either zero arguments or a single object argument");return e[0]})]]);tests=new Map([[`boolean`,e=>e.type===`BooleanValue`],[`callable`,e=>e instanceof z],[`odd`,e=>{if(!(e instanceof F))throw Error(`cannot odd on ${e.type}`);return e.value%2!=0}],[`even`,e=>{if(!(e instanceof F))throw Error(`cannot even on ${e.type}`);return e.value%2==0}],[`false`,e=>e.type===`BooleanValue`&&!e.value],[`true`,e=>e.type===`BooleanValue`&&e.value],[`none`,e=>e.type===`NullValue`],[`string`,e=>e.type===`StringValue`],[`number`,e=>e instanceof F||e instanceof ye],[`integer`,e=>e instanceof F],[`iterable`,e=>e.type===`ArrayValue`||e.type===`StringValue`],[`mapping`,e=>e.type===`ObjectValue`],[`lower`,e=>{let t=e.value;return e.type===`StringValue`&&t===t.toLowerCase()}],[`upper`,e=>{let t=e.value;return e.type===`StringValue`&&t===t.toUpperCase()}],[`none`,e=>e.type===`NullValue`],[`defined`,e=>e.type!==`UndefinedValue`],[`undefined`,e=>e.type===`UndefinedValue`],[`equalto`,(e,t)=>e.value===t.value],[`eq`,(e,t)=>e.value===t.value]]);set(e,t){return this.declareVariable(e,je(t))}declareVariable(e,t){if(this.variables.has(e))throw SyntaxError(`Variable already declared: ${e}`);return this.variables.set(e,t),t}setVariable(e,t){return this.variables.set(e,t),t}resolve(e){if(this.variables.has(e))return this;if(this.parent)return this.parent.resolve(e);throw Error(`Unknown variable: ${e}`)}lookupVariable(e){try{return this.resolve(e).variables.get(e)??new Te}catch{return new Te}}};function De(e){e.set(`false`,!1),e.set(`true`,!0),e.set(`none`,null),e.set(`raise_exception`,e=>{throw Error(e)}),e.set(`range`,ue),e.set(`strftime_now`,pe),e.set(`True`,!0),e.set(`False`,!1),e.set(`None`,null)}function Oe(e,t){let n=t.split(`.`),r=e;for(let e of n)if(r instanceof xe)r=r.value.get(e)??new Te;else if(r instanceof R){let t=parseInt(e,10);if(!isNaN(t)&&t>=0&&t<r.value.length)r=r.value[t];else return new Te}else return new Te;return r}function ke(e,t,n=!1){if(e instanceof we&&t instanceof we)return 0;if(e instanceof we||t instanceof we)throw Error(`Cannot compare ${e.type} with ${t.type}`);if(e instanceof Te&&t instanceof Te)return 0;if(e instanceof Te||t instanceof Te)throw Error(`Cannot compare ${e.type} with ${t.type}`);let r=e=>e instanceof F||e instanceof ye||e instanceof L,i=e=>e instanceof L?+!!e.value:e.value;if(r(e)&&r(t)){let n=i(e),r=i(t);return n<r?-1:+(n>r)}if(e.type!==t.type)throw Error(`Cannot compare different types: ${e.type} and ${t.type}`);switch(e.type){case`StringValue`:{let r=e.value,i=t.value;return n||(r=r.toLowerCase(),i=i.toLowerCase()),r<i?-1:+(r>i)}default:throw Error(`Cannot compare type: ${e.type}`)}}var Ae=class{global;constructor(e){this.global=e??new Ee}run(e){return this.evaluate(e,this.global)}evaluateBinaryExpression(e,t){let n=this.evaluate(e.left,t);switch(e.operator.value){case`and`:return n.__bool__().value?this.evaluate(e.right,t):n;case`or`:return n.__bool__().value?n:this.evaluate(e.right,t)}let r=this.evaluate(e.right,t);switch(e.operator.value){case`==`:return new L(n.value==r.value);case`!=`:return new L(n.value!=r.value)}if(n instanceof Te||r instanceof Te){if(r instanceof Te&&[`in`,`not in`].includes(e.operator.value))return new L(e.operator.value===`not in`);throw Error(`Cannot perform operation ${e.operator.value} on undefined values`)}else if(n instanceof we||r instanceof we)throw Error(`Cannot perform operation on null values`);else if(e.operator.value===`~`)return new I(n.value.toString()+r.value.toString());else if((n instanceof F||n instanceof ye)&&(r instanceof F||r instanceof ye)){let t=n.value,i=r.value;switch(e.operator.value){case`+`:case`-`:case`*`:{let a=e.operator.value===`+`?t+i:e.operator.value===`-`?t-i:t*i;return n instanceof ye||r instanceof ye?new ye(a):new F(a)}case`/`:return new ye(t/i);case`%`:{let e=t%i;return n instanceof ye||r instanceof ye?new ye(e):new F(e)}case`<`:return new L(t<i);case`>`:return new L(t>i);case`>=`:return new L(t>=i);case`<=`:return new L(t<=i)}}else if(n instanceof R&&r instanceof R)switch(e.operator.value){case`+`:return new R(n.value.concat(r.value))}else if(r instanceof R){let t=r.value.find(e=>e.value===n.value)!==void 0;switch(e.operator.value){case`in`:return new L(t);case`not in`:return new L(!t)}}if(n instanceof I||r instanceof I)switch(e.operator.value){case`+`:return new I(n.value.toString()+r.value.toString())}if(n instanceof I&&r instanceof I)switch(e.operator.value){case`in`:return new L(r.value.includes(n.value));case`not in`:return new L(!r.value.includes(n.value))}if(n instanceof I&&r instanceof xe)switch(e.operator.value){case`in`:return new L(r.value.has(n.value));case`not in`:return new L(!r.value.has(n.value))}throw SyntaxError(`Unknown operator "${e.operator.value}" between ${n.type} and ${r.type}`)}evaluateArguments(e,t){let n=[],r=new Map;for(let i of e)if(i.type===`SpreadExpression`){let e=i,r=this.evaluate(e.argument,t);if(!(r instanceof R))throw Error(`Cannot unpack non-iterable type: ${r.type}`);for(let e of r.value)n.push(e)}else if(i.type===`KeywordArgumentExpression`){let e=i;r.set(e.key.value,this.evaluate(e.value,t))}else{if(r.size>0)throw Error(`Positional arguments must come before keyword arguments`);n.push(this.evaluate(i,t))}return[n,r]}applyFilter(e,t,n){if(t.type===`Identifier`){let r=t;if(r.value===`tojson`)return new I(be(e));if(e instanceof R)switch(r.value){case`list`:return e;case`first`:return e.value[0];case`last`:return e.value[e.value.length-1];case`length`:return new F(e.value.length);case`reverse`:return new R(e.value.slice().reverse());case`sort`:return new R(e.value.slice().sort((e,t)=>ke(e,t,!1)));case`join`:return new I(e.value.map(e=>e.value).join(``));case`string`:return new I(be(e,null,0,!1));case`unique`:{let t=new Set,n=[];for(let r of e.value)t.has(r.value)||(t.add(r.value),n.push(r));return new R(n)}default:throw Error(`Unknown ArrayValue filter: ${r.value}`)}else if(e instanceof I)switch(r.value){case`length`:case`upper`:case`lower`:case`title`:case`capitalize`:{let t=e.builtins.get(r.value);if(t instanceof z)return t.value([],n);if(t instanceof F)return t;throw Error(`Unknown StringValue filter: ${r.value}`)}case`trim`:return new I(e.value.trim());case`indent`:return new I(e.value.split(`
2809
+ `).map((e,t)=>t===0||e.length===0?e:` `+e).join(`
2810
+ `));case`join`:case`string`:return e;case`int`:{let t=parseInt(e.value,10);return new F(isNaN(t)?0:t)}case`float`:{let t=parseFloat(e.value);return new ye(isNaN(t)?0:t)}default:throw Error(`Unknown StringValue filter: ${r.value}`)}else if(e instanceof F||e instanceof ye)switch(r.value){case`abs`:return e instanceof F?new F(Math.abs(e.value)):new ye(Math.abs(e.value));case`int`:return new F(Math.floor(e.value));case`float`:return new ye(e.value);default:throw Error(`Unknown NumericValue filter: ${r.value}`)}else if(e instanceof xe)switch(r.value){case`items`:return new R(Array.from(e.value.entries()).map(([e,t])=>new R([new I(e),t])));case`length`:return new F(e.value.size);default:{let t=e.builtins.get(r.value);if(t)return t instanceof z?t.value([],n):t;throw Error(`Unknown ObjectValue filter: ${r.value}`)}}else if(e instanceof L)switch(r.value){case`bool`:return new L(e.value);case`int`:return new F(+!!e.value);case`float`:return new ye(+!!e.value);case`string`:return new I(e.value?`true`:`false`);default:throw Error(`Unknown BooleanValue filter: ${r.value}`)}throw Error(`Cannot apply filter "${r.value}" to type: ${e.type}`)}else if(t.type===`CallExpression`){let r=t;if(r.callee.type!==`Identifier`)throw Error(`Unknown filter: ${r.callee.type}`);let i=r.callee.value;if(i===`tojson`){let[,t]=this.evaluateArguments(r.args,n),i=t.get(`indent`)??new we;if(!(i instanceof F||i instanceof we))throw Error(`If set, indent must be a number`);return new I(be(e,i.value))}else if(i===`join`){let t;if(e instanceof I)t=Array.from(e.value);else if(e instanceof R)t=e.value.map(e=>e.value);else throw Error(`Cannot apply filter "${i}" to type: ${e.type}`);let[a,o]=this.evaluateArguments(r.args,n),s=a.at(0)??o.get(`separator`)??new I(``);if(!(s instanceof I))throw Error(`separator must be a string`);return new I(t.join(s.value))}else if(i===`int`||i===`float`){let[t,a]=this.evaluateArguments(r.args,n),o=t.at(0)??a.get(`default`)??(i===`int`?new F(0):new ye(0));if(e instanceof I){let t=i===`int`?parseInt(e.value,10):parseFloat(e.value);return isNaN(t)?o:i===`int`?new F(t):new ye(t)}else if(e instanceof F||e instanceof ye)return e;else if(e instanceof L)return i===`int`?new F(+!!e.value):new ye(+!!e.value);else throw Error(`Cannot apply filter "${i}" to type: ${e.type}`)}else if(i===`default`){let[t,i]=this.evaluateArguments(r.args,n),a=t[0]??new I(``),o=t[1]??i.get(`boolean`)??new L(!1);if(!(o instanceof L))throw Error("`default` filter flag must be a boolean");return e instanceof Te||o.value&&!e.__bool__().value?a:e}if(e instanceof R){switch(i){case`sort`:{let[t,i]=this.evaluateArguments(r.args,n),a=t.at(0)??i.get(`reverse`)??new L(!1);if(!(a instanceof L))throw Error(`reverse must be a boolean`);let o=t.at(1)??i.get(`case_sensitive`)??new L(!1);if(!(o instanceof L))throw Error(`case_sensitive must be a boolean`);let s=t.at(2)??i.get(`attribute`)??new we;if(!(s instanceof I||s instanceof F||s instanceof we))throw Error(`attribute must be a string, integer, or null`);let c=e=>s instanceof we?e:Oe(e,s instanceof F?String(s.value):s.value);return new R(e.value.slice().sort((e,t)=>{let n=ke(c(e),c(t),o.value);return a.value?-n:n}))}case`selectattr`:case`rejectattr`:{let t=i===`selectattr`;if(e.value.some(e=>!(e instanceof xe)))throw Error(`\`${i}\` can only be applied to array of objects`);if(r.args.some(e=>e.type!==`StringLiteral`))throw Error(`arguments of \`${i}\` must be strings`);let[a,o,s]=r.args.map(e=>this.evaluate(e,n)),c;if(o){let e=n.tests.get(o.value);if(!e)throw Error(`Unknown test: ${o.value}`);c=e}else c=(...e)=>e[0].__bool__().value;return new R(e.value.filter(e=>{let n=e.value.get(a.value),r=n?c(n,s):!1;return t?r:!r}))}case`map`:{let[,t]=this.evaluateArguments(r.args,n);if(t.has(`attribute`)){let n=t.get(`attribute`);if(!(n instanceof I))throw Error(`attribute must be a string`);let r=t.get(`default`);return new R(e.value.map(e=>{if(!(e instanceof xe))throw Error(`items in map must be an object`);let t=Oe(e,n.value);return t instanceof Te?r??new Te:t}))}else throw Error("`map` expressions without `attribute` set are not currently supported.")}}throw Error(`Unknown ArrayValue filter: ${i}`)}else if(e instanceof I){switch(i){case`indent`:{let[t,i]=this.evaluateArguments(r.args,n),a=t.at(0)??i.get(`width`)??new F(4);if(!(a instanceof F))throw Error(`width must be a number`);let o=t.at(1)??i.get(`first`)??new L(!1),s=t.at(2)??i.get(`blank`)??new L(!1),c=e.value.split(`
2811
+ `),l=` `.repeat(a.value);return new I(c.map((e,t)=>!o.value&&t===0||!s.value&&e.length===0?e:l+e).join(`
2812
+ `))}case`replace`:{let t=e.builtins.get(`replace`);if(!(t instanceof z))throw Error(`replace filter not available`);let[i,a]=this.evaluateArguments(r.args,n);return t.value([...i,new Se(a)],n)}}throw Error(`Unknown StringValue filter: ${i}`)}else if(e instanceof xe){let t=e.builtins.get(i);if(t&&t instanceof z){let[e,i]=this.evaluateArguments(r.args,n);return i.size>0&&e.push(new Se(i)),t.value(e,n)}throw Error(`Unknown ObjectValue filter: ${i}`)}else throw Error(`Cannot apply filter "${i}" to type: ${e.type}`)}throw Error(`Unknown filter: ${t.type}`)}evaluateFilterExpression(e,t){let n=this.evaluate(e.operand,t);return this.applyFilter(n,e.filter,t)}evaluateTestExpression(e,t){let n=this.evaluate(e.operand,t),r=t.tests.get(e.test.value);if(!r)throw Error(`Unknown test: ${e.test.value}`);let i=r(n);return new L(e.negate?!i:i)}evaluateSelectExpression(e,t){return this.evaluate(e.test,t).__bool__().value?this.evaluate(e.lhs,t):new Te}evaluateUnaryExpression(e,t){let n=this.evaluate(e.argument,t);switch(e.operator.value){case`not`:return new L(!n.value);default:throw SyntaxError(`Unknown operator: ${e.operator.value}`)}}evaluateTernaryExpression(e,t){return this.evaluate(e.condition,t).__bool__().value?this.evaluate(e.trueExpr,t):this.evaluate(e.falseExpr,t)}evalProgram(e,t){return this.evaluateBlock(e.body,t)}evaluateBlock(e,t){let n=``;for(let r of e){let e=this.evaluate(r,t);e.type!==`NullValue`&&e.type!==`UndefinedValue`&&(n+=e.toString())}return new I(n)}evaluateIdentifier(e,t){return t.lookupVariable(e.value)}evaluateCallExpression(e,t){let[n,r]=this.evaluateArguments(e.args,t);r.size>0&&n.push(new Se(r));let i=this.evaluate(e.callee,t);if(i.type!==`FunctionValue`)throw Error(`Cannot call something that is not a function: got ${i.type}`);return i.value(n,t)}evaluateSliceExpression(e,t,n){if(!(e instanceof R||e instanceof I))throw Error(`Slice object must be an array or string`);let r=this.evaluate(t.start,n),i=this.evaluate(t.stop,n),a=this.evaluate(t.step,n);if(!(r instanceof F||r instanceof Te))throw Error(`Slice start must be numeric or undefined`);if(!(i instanceof F||i instanceof Te))throw Error(`Slice stop must be numeric or undefined`);if(!(a instanceof F||a instanceof Te))throw Error(`Slice step must be numeric or undefined`);return e instanceof R?new R(de(e.value,r.value,i.value,a.value)):new I(de(Array.from(e.value),r.value,i.value,a.value).join(``))}evaluateMemberExpression(e,t){let n=this.evaluate(e.object,t),r;if(e.computed){if(e.property.type===`SliceExpression`)return this.evaluateSliceExpression(n,e.property,t);r=this.evaluate(e.property,t)}else r=new I(e.property.value);let i;if(n instanceof xe){if(!(r instanceof I))throw Error(`Cannot access property with non-string: got ${r.type}`);i=n.value.get(r.value)??n.builtins.get(r.value)}else if(n instanceof R||n instanceof I)if(r instanceof F)i=n.value.at(r.value),n instanceof I&&(i=new I(n.value.at(r.value)));else if(r instanceof I)i=n.builtins.get(r.value);else throw Error(`Cannot access property with non-string/non-number: got ${r.type}`);else{if(!(r instanceof I))throw Error(`Cannot access property with non-string: got ${r.type}`);i=n.builtins.get(r.value)}return i instanceof ve?i:new Te}evaluateSet(e,t){let n=e.value?this.evaluate(e.value,t):this.evaluateBlock(e.body,t);if(e.assignee.type===`Identifier`){let r=e.assignee.value;t.setVariable(r,n)}else if(e.assignee.type===`TupleLiteral`){let r=e.assignee;if(!(n instanceof R))throw Error(`Cannot unpack non-iterable type in set: ${n.type}`);let i=n.value;if(i.length!==r.value.length)throw Error(`Too ${r.value.length>i.length?`few`:`many`} items to unpack in set`);for(let e=0;e<r.value.length;++e){let n=r.value[e];if(n.type!==`Identifier`)throw Error(`Cannot unpack to non-identifier in set: ${n.type}`);t.setVariable(n.value,i[e])}}else if(e.assignee.type===`MemberExpression`){let r=e.assignee,i=this.evaluate(r.object,t);if(!(i instanceof xe))throw Error(`Cannot assign to member of non-object`);if(r.property.type!==`Identifier`)throw Error(`Cannot assign to member with non-identifier property`);i.value.set(r.property.value,n)}else throw Error(`Invalid LHS inside assignment expression: ${JSON.stringify(e.assignee)}`);return new we}evaluateIf(e,t){let n=this.evaluate(e.test,t);return this.evaluateBlock(n.__bool__().value?e.body:e.alternate,t)}evaluateFor(e,t){let n=new Ee(t),r,i;if(e.iterable.type===`SelectExpression`){let t=e.iterable;i=this.evaluate(t.lhs,n),r=t.test}else i=this.evaluate(e.iterable,n);if(!(i instanceof R||i instanceof xe))throw Error(`Expected iterable or object type in for loop: got ${i.type}`);i instanceof xe&&(i=i.keys());let a=[],o=[];for(let t=0;t<i.value.length;++t){let s=new Ee(n),c=i.value[t],l;if(e.loopvar.type===`Identifier`)l=t=>t.setVariable(e.loopvar.value,c);else if(e.loopvar.type===`TupleLiteral`){let t=e.loopvar;if(c.type!==`ArrayValue`)throw Error(`Cannot unpack non-iterable type: ${c.type}`);let n=c;if(t.value.length!==n.value.length)throw Error(`Too ${t.value.length>n.value.length?`few`:`many`} items to unpack`);l=e=>{for(let r=0;r<t.value.length;++r){if(t.value[r].type!==`Identifier`)throw Error(`Cannot unpack non-identifier type: ${t.value[r].type}`);e.setVariable(t.value[r].value,n.value[r])}}}else throw Error(`Invalid loop variable(s): ${e.loopvar.type}`);r&&(l(s),!this.evaluate(r,s).__bool__().value)||(a.push(c),o.push(l))}let s=``,c=!0;for(let t=0;t<a.length;++t){let r=new Map([[`index`,new F(t+1)],[`index0`,new F(t)],[`revindex`,new F(a.length-t)],[`revindex0`,new F(a.length-t-1)],[`first`,new L(t===0)],[`last`,new L(t===a.length-1)],[`length`,new F(a.length)],[`previtem`,t>0?a[t-1]:new Te],[`nextitem`,t<a.length-1?a[t+1]:new Te]]);n.setVariable(`loop`,new xe(r)),o[t](n);try{let t=this.evaluateBlock(e.body,n);s+=t.value}catch(e){if(e instanceof _e)continue;if(e instanceof ge)break;throw e}c=!1}if(c){let t=this.evaluateBlock(e.defaultBlock,n);s+=t.value}return new I(s)}evaluateMacro(e,t){return t.setVariable(e.name.value,new z((t,n)=>{let r=new Ee(n);t=t.slice();let i;t.at(-1)?.type===`KeywordArgumentsValue`&&(i=t.pop());for(let n=0;n<e.args.length;++n){let a=e.args[n],o=t[n];if(a.type===`Identifier`){let e=a;if(!o)throw Error(`Missing positional argument: ${e.value}`);r.setVariable(e.value,o)}else if(a.type===`KeywordArgumentExpression`){let e=a,t=o??i?.value.get(e.key.value)??this.evaluate(e.value,r);r.setVariable(e.key.value,t)}else throw Error(`Unknown argument type: ${a.type}`)}return this.evaluateBlock(e.body,r)})),new we}evaluateCallStatement(e,t){let n=new z((t,n)=>{let r=new Ee(n);if(e.callerArgs)for(let n=0;n<e.callerArgs.length;++n){let i=e.callerArgs[n];if(i.type!==`Identifier`)throw Error(`Caller parameter must be an identifier, got ${i.type}`);r.setVariable(i.value,t[n]??new Te)}return this.evaluateBlock(e.body,r)}),[r,i]=this.evaluateArguments(e.call.args,t);r.push(new Se(i));let a=this.evaluate(e.call.callee,t);if(a.type!==`FunctionValue`)throw Error(`Cannot call something that is not a function: got ${a.type}`);let o=new Ee(t);return o.setVariable(`caller`,n),a.value(r,o)}evaluateFilterStatement(e,t){let n=this.evaluateBlock(e.body,t);return this.applyFilter(n,e.filter,t)}evaluate(e,t){if(!e)return new Te;switch(e.type){case`Program`:return this.evalProgram(e,t);case`Set`:return this.evaluateSet(e,t);case`If`:return this.evaluateIf(e,t);case`For`:return this.evaluateFor(e,t);case`Macro`:return this.evaluateMacro(e,t);case`CallStatement`:return this.evaluateCallStatement(e,t);case`Break`:throw new ge;case`Continue`:throw new _e;case`IntegerLiteral`:return new F(e.value);case`FloatLiteral`:return new ye(e.value);case`StringLiteral`:return new I(e.value);case`ArrayLiteral`:return new R(e.value.map(e=>this.evaluate(e,t)));case`TupleLiteral`:return new Ce(e.value.map(e=>this.evaluate(e,t)));case`ObjectLiteral`:{let n=new Map;for(let[r,i]of e.value){let e=this.evaluate(r,t);if(!(e instanceof I))throw Error(`Object keys must be strings: got ${e.type}`);n.set(e.value,this.evaluate(i,t))}return new xe(n)}case`Identifier`:return this.evaluateIdentifier(e,t);case`CallExpression`:return this.evaluateCallExpression(e,t);case`MemberExpression`:return this.evaluateMemberExpression(e,t);case`UnaryExpression`:return this.evaluateUnaryExpression(e,t);case`BinaryExpression`:return this.evaluateBinaryExpression(e,t);case`FilterExpression`:return this.evaluateFilterExpression(e,t);case`FilterStatement`:return this.evaluateFilterStatement(e,t);case`TestExpression`:return this.evaluateTestExpression(e,t);case`SelectExpression`:return this.evaluateSelectExpression(e,t);case`Ternary`:return this.evaluateTernaryExpression(e,t);case`Comment`:return new we;default:throw SyntaxError(`Unknown node type: ${e.type}`)}}};function je(e){switch(typeof e){case`number`:return Number.isInteger(e)?new F(e):new ye(e);case`string`:return new I(e);case`boolean`:return new L(e);case`undefined`:return new Te;case`object`:return e===null?new we:Array.isArray(e)?new R(e.map(je)):new xe(new Map(Object.entries(e).map(([e,t])=>[e,je(t)])));case`function`:return new z((t,n)=>je(e(...t.map(e=>e.value))??null));default:throw Error(`Cannot convert to runtime value: ${e}`)}}var Me=`
2813
+ `,Ne=`{%- `,Pe=` -%}`;function Fe(e){switch(e.operator.type){case`MultiplicativeBinaryOperator`:return 4;case`AdditiveBinaryOperator`:return 3;case`ComparisonBinaryOperator`:return 2;case`Identifier`:return e.operator.value===`and`?1:e.operator.value===`in`||e.operator.value===`not in`?2:0}return 0}function Ie(e,t=` `){let n=typeof t==`number`?` `.repeat(t):t;return Re(e.body,0,n).replace(/\n$/,``)}function Le(...e){return Ne+e.join(` `)+Pe}function Re(e,t,n){return e.map(e=>ze(e,t,n)).join(Me)}function ze(e,t,n){let r=n.repeat(t);switch(e.type){case`Program`:return Re(e.body,t,n);case`If`:return Be(e,t,n);case`For`:return B(e,t,n);case`Set`:return Ve(e,t,n);case`Macro`:return He(e,t,n);case`Break`:return r+Le(`break`);case`Continue`:return r+Le(`continue`);case`CallStatement`:return Ue(e,t,n);case`FilterStatement`:return We(e,t,n);case`Comment`:return r+`{# `+e.value+` #}`;default:return r+`{{- `+V(e)+` -}}`}}function Be(e,t,n){let r=n.repeat(t),i=[],a=e;for(;a&&(i.push({test:a.test,body:a.body}),a.alternate.length===1&&a.alternate[0].type===`If`);)a=a.alternate[0];let o=r+Le(`if`,V(i[0].test))+Me+Re(i[0].body,t+1,n);for(let e=1;e<i.length;++e)o+=Me+r+Le(`elif`,V(i[e].test))+Me+Re(i[e].body,t+1,n);return a&&a.alternate.length>0&&(o+=Me+r+Le(`else`)+Me+Re(a.alternate,t+1,n)),o+=Me+r+Le(`endif`),o}function B(e,t,n){let r=n.repeat(t),i=``;if(e.iterable.type===`SelectExpression`){let t=e.iterable;i=`${V(t.lhs)} if ${V(t.test)}`}else i=V(e.iterable);let a=r+Le(`for`,V(e.loopvar),`in`,i)+Me+Re(e.body,t+1,n);return e.defaultBlock.length>0&&(a+=Me+r+Le(`else`)+Me+Re(e.defaultBlock,t+1,n)),a+=Me+r+Le(`endfor`),a}function Ve(e,t,n){let r=n.repeat(t),i=V(e.assignee),a=e.value?V(e.value):``,o=r+Le(`set`,`${i}${e.value?` = `+a:``}`);return e.body.length===0?o:o+Me+Re(e.body,t+1,n)+Me+r+Le(`endset`)}function He(e,t,n){let r=n.repeat(t),i=e.args.map(V).join(`, `);return r+Le(`macro`,`${e.name.value}(${i})`)+Me+Re(e.body,t+1,n)+Me+r+Le(`endmacro`)}function Ue(e,t,n){let r=n.repeat(t),i=e.callerArgs&&e.callerArgs.length>0?`(${e.callerArgs.map(V).join(`, `)})`:``,a=V(e.call),o=r+Le(`call${i}`,a)+Me;return o+=Re(e.body,t+1,n)+Me,o+=r+Le(`endcall`),o}function We(e,t,n){let r=n.repeat(t),i=r+Le(`filter`,e.filter.type===`Identifier`?e.filter.value:V(e.filter))+Me;return i+=Re(e.body,t+1,n)+Me,i+=r+Le(`endfilter`),i}function V(e,t=-1){switch(e.type){case`SpreadExpression`:return`*${V(e.argument)}`;case`Identifier`:return e.value;case`IntegerLiteral`:return`${e.value}`;case`FloatLiteral`:return`${e.value}`;case`StringLiteral`:return JSON.stringify(e.value);case`BinaryExpression`:{let n=e,r=Fe(n),i=V(n.left,r),a=V(n.right,r+1),o=`${i} ${n.operator.value} ${a}`;return r<t?`(${o})`:o}case`UnaryExpression`:{let t=e;return t.operator.value+(t.operator.value===`not`?` `:``)+V(t.argument,1/0)}case`CallExpression`:{let t=e,n=t.args.map(V).join(`, `);return`${V(t.callee)}(${n})`}case`MemberExpression`:{let t=e,n=V(t.object);[`Identifier`,`MemberExpression`,`CallExpression`,`StringLiteral`,`IntegerLiteral`,`FloatLiteral`,`ArrayLiteral`,`TupleLiteral`,`ObjectLiteral`].includes(t.object.type)||(n=`(${n})`);let r=V(t.property);return!t.computed&&t.property.type!==`Identifier`&&(r=`(${r})`),t.computed?`${n}[${r}]`:`${n}.${r}`}case`FilterExpression`:{let t=e,n=V(t.operand,1/0);return t.filter.type===`CallExpression`?`${n} | ${V(t.filter)}`:`${n} | ${t.filter.value}`}case`SelectExpression`:{let t=e;return`${V(t.lhs)} if ${V(t.test)}`}case`TestExpression`:{let t=e;return`${V(t.operand)} is${t.negate?` not`:``} ${t.test.value}`}case`ArrayLiteral`:case`TupleLiteral`:{let t=e.value.map(V),n=e.type===`ArrayLiteral`?`[]`:`()`;return`${n[0]}${t.join(`, `)}${n[1]}`}case`ObjectLiteral`:return`{${Array.from(e.value.entries()).map(([e,t])=>`${V(e)}: ${V(t)}`).join(`, `)}}`;case`SliceExpression`:{let t=e;return`${t.start?V(t.start):``}:${t.stop?V(t.stop):``}${t.step?`:${V(t.step)}`:``}`}case`KeywordArgumentExpression`:{let t=e;return`${t.key.value}=${V(t.value)}`}case`Ternary`:{let n=e,r=`${V(n.trueExpr)} if ${V(n.condition,0)} else ${V(n.falseExpr)}`;return t>-1?`(${r})`:r}default:throw Error(`Unknown expression type: ${e.type}`)}}var Ge=class{parsed;constructor(e){this.parsed=le(d(e,{lstrip_blocks:!0,trim_blocks:!0}))}render(e){let t=new Ee;if(De(t),e)for(let[n,r]of Object.entries(e))t.set(n,r);return new Ae(t).run(this.parsed).value}format(e){return Ie(this.parsed,e?.indent||` `)}}}),"./src/backends/onnx.js":((e,t,n)=>{var r;n.r(t),n.d(t,{Tensor:()=>s.Tensor,createInferenceSession:()=>g,deviceToExecutionProviders:()=>m,isONNXProxy:()=>S,isONNXTensor:()=>b,runInferenceSession:()=>y});var i=n(`./src/env.js`),a=n(`?2ce3`),o=n(`onnxruntime-web`),s=n(`onnxruntime-common`);let c=Object.freeze({auto:null,gpu:null,cpu:`cpu`,wasm:`wasm`,webgpu:`webgpu`,cuda:`cuda`,dml:`dml`,webnn:{name:`webnn`,deviceType:`cpu`},"webnn-npu":{name:`webnn`,deviceType:`npu`},"webnn-gpu":{name:`webnn`,deviceType:`gpu`},"webnn-cpu":{name:`webnn`,deviceType:`cpu`}}),l=[],u,d,f=Symbol.for(`onnxruntime`);if(f in globalThis)d=globalThis[f];else if(i.apis.IS_NODE_ENV){switch(d=a??(r||=n.t(a,2)),process.platform){case`win32`:l.push(`dml`);break;case`linux`:process.arch===`x64`&&l.push(`cuda`);break;case`darwin`:break}l.push(`cpu`),u=[`cpu`]}else d=o,i.apis.IS_WEBNN_AVAILABLE&&l.push(`webnn-npu`,`webnn-gpu`,`webnn-cpu`,`webnn`),i.apis.IS_WEBGPU_AVAILABLE&&l.push(`webgpu`),l.push(`wasm`),u=[`wasm`];let p=d.InferenceSession;function m(e=null){if(!e)return u;switch(e){case`auto`:return l;case`gpu`:return l.filter(e=>[`webgpu`,`cuda`,`dml`,`webnn-gpu`].includes(e))}if(l.includes(e))return[c[e]??e];throw Error(`Unsupported device: "${e}". Should be one of: ${l.join(`, `)}.`)}let h=null;async function g(e,t,n){h&&await h;let r=p.create(e,t);h??=r;let i=await r;return i.config=n,i}let _=Promise.resolve(),v=i.apis.IS_BROWSER_ENV||i.apis.IS_WEBWORKER_ENV;async function y(e,t){let n=()=>e.run(t);return await(v?_=_.then(n):n())}function b(e){return e instanceof d.Tensor}let x=d?.env;x?.wasm&&(!(typeof ServiceWorkerGlobalScope<`u`&&self instanceof ServiceWorkerGlobalScope)&&!x.wasm.wasmPaths&&(x.wasm.wasmPaths=`https://cdn.jsdelivr.net/npm/@huggingface/transformers@${i.env.version}/dist/`),x.wasm.proxy=!1),x?.webgpu&&(x.webgpu.powerPreference=`high-performance`);function S(){return x?.wasm?.proxy}i.env.backends.onnx=x}),"./src/base/feature_extraction_utils.js":((e,t,n)=>{n.r(t),n.d(t,{FeatureExtractor:()=>o,validate_audio_inputs:()=>s});var r=n(`./src/utils/constants.js`),i=n(`./src/utils/generic.js`),a=n(`./src/utils/hub.js`);class o extends i.Callable{constructor(e){super(),this.config=e}static async from_pretrained(e,t={}){let n=await(0,a.getModelJSON)(e,r.FEATURE_EXTRACTOR_NAME,!0,t);return new this(n)}}function s(e,t){if(!(e instanceof Float32Array||e instanceof Float64Array))throw Error(`${t} expects input to be a Float32Array or a Float64Array, but got ${e?.constructor?.name??typeof e} instead. If using the feature extractor directly, remember to use \`read_audio(url, sampling_rate)\` to obtain the raw audio data of the file/url.`)}}),"./src/base/image_processors_utils.js":((e,t,n)=>{n.r(t),n.d(t,{ImageProcessor:()=>b,center_to_corners_format:()=>d,post_process_instance_segmentation:()=>y,post_process_object_detection:()=>f,post_process_panoptic_segmentation:()=>v,post_process_semantic_segmentation:()=>p});var r=n(`./src/utils/generic.js`),i=n(`./src/utils/tensor.js`),a=n(`./src/utils/maths.js`);n(`./src/utils/image.js`);var o=n(`./src/utils/core.js`),s=n(`./src/utils/hub.js`),c=n(`./src/utils/constants.js`);function l(e,t,n=0,r=null){let i=e/t,o=(0,a.bankers_round)(i)*t;return r!==null&&o>r&&(o=Math.floor(i)*t),o<n&&(o=Math.ceil(i)*t),o}function u([e,t],n){return[Math.max(Math.floor(e/n),1)*n,Math.max(Math.floor(t/n),1)*n]}function d([e,t,n,r]){return[e-n/2,t-r/2,e+n/2,t+r/2]}function f(e,t=.5,n=null,r=!1){let i=e.logits,o=e.pred_boxes,[s,c,l]=i.dims;if(n!==null&&n.length!==s)throw Error(`Make sure that you pass in as many target sizes as the batch dimension of the logits`);let u=[];for(let e=0;e<s;++e){let s=n===null?null:n[e],f={boxes:[],classes:[],scores:[]},p=i[e],m=o[e];for(let e=0;e<c;++e){let n=p[e],i=[],o;if(r){o=n.sigmoid().data;for(let e=0;e<o.length;++e)o[e]>t&&i.push(e)}else{let e=(0,a.max)(n.data)[1];if(e===l-1||(o=(0,a.softmax)(n.data),o[e]<t))continue;i.push(e)}for(let t of i){let n=m[e].data;n=d(n),s!==null&&(n=n.map((e,t)=>e*s[(t+1)%2])),f.boxes.push(n),f.classes.push(t),f.scores.push(o[t])}}u.push(f)}return u}function p(e,t=null){let n=e.logits,r=n.dims[0];if(t!==null&&t.length!==r)throw Error(`Make sure that you pass in as many target sizes as the batch dimension of the logits`);let a=[];for(let e=0;e<r;++e){let r=t===null?null:t[e],o=n[e];r!==null&&(o=(0,i.interpolate)(o,r,`bilinear`,!1));let[s,c]=r??o.dims.slice(-2),l=new i.Tensor(`int32`,new Int32Array(s*c),[s,c]),u=o[0].data,d=l.data;for(let e=1;e<o.dims[0];++e){let t=o[e].data;for(let n=0;n<t.length;++n)t[n]>u[n]&&(u[n]=t[n],d[n]=e)}let f=Array(o.dims[0]);for(let e=0;e<d.length;++e){let t=d[e];f[t]=t}let p=f.filter(e=>e!==void 0);a.push({segmentation:l,labels:p})}return a}function m(e,t,n,r){let i=[],o=[],s=[];for(let c=0;c<e.dims[0];++c){let l=e[c],u=t[c],d=(0,a.max)(l.data)[1];if(d===r)continue;let f=(0,a.softmax)(l.data)[d];f>n&&(i.push(u),o.push(f),s.push(d))}return[i,o,s]}function h(e,t,n,r=.5,i=.8){let a=[],o=0,s=0,c=t[n].data;for(let t=0;t<e.length;++t)e[t]===n&&(a.push(t),++o),c[t]>=r&&++s;let l=o>0&&s>0;return l&&=o/s>i,[l,a]}function g(e,t,n,r,a,o=null,s=null){let[c,l]=s??e[0].dims,u=new i.Tensor(`int32`,new Int32Array(c*l),[c,l]),d=[];if(s!==null)for(let t=0;t<e.length;++t)e[t]=(0,i.interpolate)(e[t],s,`bilinear`,!1);let f=new Int32Array(e[0].data.length),p=new Float32Array(e[0].data.length);for(let n=0;n<e.length;++n){let r=t[n],i=e[n].data;for(let e=0;e<i.length;++e)i[e]*=r,i[e]>p[e]&&(f[e]=n,p[e]=i[e])}let m=0,g=u.data;for(let i=0;i<n.length;++i){let o=n[i],[s,c]=h(f,e,i,r,a);if(s){++m;for(let e of c)g[e]=m;d.push({id:m,label_id:o,score:t[i]})}}return[u,d]}function _(e,t,n=28,r=3136,i=784*1280){if(e<n||t<n)throw Error(`height:${e} or width:${t} must be larger than factor:${n}`);if(Math.max(e,t)/Math.min(e,t)>200)throw Error(`absolute aspect ratio must be smaller than 200, got ${Math.max(e,t)/Math.min(e,t)}`);let a=Math.round(e/n)*n,o=Math.round(t/n)*n;if(a*o>i){let r=Math.sqrt(e*t/i);a=Math.floor(e/r/n)*n,o=Math.floor(t/r/n)*n}else if(a*o<r){let i=Math.sqrt(r/(e*t));a=Math.ceil(e*i/n)*n,o=Math.ceil(t*i/n)*n}return[a,o]}function v(e,t=.5,n=.5,r=.8,a=null,o=null){a===null&&(console.warn("`label_ids_to_fuse` unset. No instance will be fused."),a=new Set);let s=e.class_queries_logits??e.logits,c=(e.masks_queries_logits??e.pred_masks).sigmoid(),[l,u,d]=s.dims;if(--d,o!==null&&o.length!==l)throw Error(`Make sure that you pass in as many target sizes as the batch dimension of the logits`);let f=[];for(let e=0;e<l;++e){let l=o===null?null:o[e],u=s[e],p=c[e],[h,_,v]=m(u,p,t,d);if(v.length===0){let[e,t]=l??p.dims.slice(-2),n=new i.Tensor(`int32`,new Int32Array(e*t).fill(-1),[e,t]);f.push({segmentation:n,segments_info:[]});continue}let[y,b]=g(h,_,v,n,r,a,l);f.push({segmentation:y,segments_info:b})}return f}function y(e,t=.5,n=null){throw Error("`post_process_instance_segmentation` is not yet implemented.")}class b extends r.Callable{constructor(e){super(),this.image_mean=e.image_mean??e.mean,this.image_std=e.image_std??e.std,this.resample=e.resample??2,this.do_rescale=e.do_rescale??!0,this.rescale_factor=e.rescale_factor??1/255,this.do_normalize=e.do_normalize,this.do_thumbnail=e.do_thumbnail,this.size=e.size??e.image_size,this.do_resize=e.do_resize??this.size!==void 0,this.size_divisibility=e.size_divisibility??e.size_divisor,this.do_center_crop=e.do_center_crop,this.crop_size=e.crop_size,this.do_convert_rgb=e.do_convert_rgb??!0,this.do_crop_margin=e.do_crop_margin,this.pad_size=e.pad_size,this.do_pad=e.do_pad,this.min_pixels=e.min_pixels,this.max_pixels=e.max_pixels,this.do_pad&&!this.pad_size&&this.size&&this.size.width!==void 0&&this.size.height!==void 0&&(this.pad_size=this.size),this.do_flip_channel_order=e.do_flip_channel_order??!1,this.config=e}async thumbnail(e,t,n=2){let r=e.height,i=e.width,a=t.height,o=t.width,s=Math.min(r,a),c=Math.min(i,o);return s===r&&c===i?e:(r>i?c=Math.floor(i*s/r):i>r&&(s=Math.floor(r*c/i)),await e.resize(c,s,{resample:n}))}async crop_margin(e,t=200){let n=e.clone().grayscale(),r=(0,a.min)(n.data)[0],i=(0,a.max)(n.data)[0]-r;if(i===0)return e;let o=t/255,s=n.width,c=n.height,l=0,u=0,d=n.data;for(let e=0;e<n.height;++e){let t=e*n.width;for(let a=0;a<n.width;++a)(d[t+a]-r)/i<o&&(s=Math.min(s,a),c=Math.min(c,e),l=Math.max(l,a),u=Math.max(u,e))}return e=await e.crop([s,c,l,u]),e}pad_image(e,t,n,{mode:r=`constant`,center:i=!1,constant_values:a=0}={}){let[s,c,l]=t,u,d;if(typeof n==`number`?(u=n,d=n):n===`square`?u=d=Math.max(s,c):(u=n.width,d=n.height),u!==c||d!==s){let n=new Float32Array(u*d*l);if(Array.isArray(a))for(let e=0;e<n.length;++e)n[e]=a[e%l];else a!==0&&n.fill(a);let[f,p]=i?[Math.floor((u-c)/2),Math.floor((d-s)/2)]:[0,0];for(let t=0;t<s;++t){let r=(t+p)*u,i=t*c;for(let t=0;t<c;++t){let a=(r+t+f)*l,o=(i+t)*l;for(let t=0;t<l;++t)n[a+t]=e[o+t]}}if(r===`symmetric`){if(i)throw Error("`center` padding is not supported when `mode` is set to `symmetric`.");let t=s-1,r=c-1;for(let i=0;i<d;++i){let a=i*u,d=(0,o.calculateReflectOffset)(i,t)*c;for(let t=0;t<u;++t){if(i<s&&t<c)continue;let u=(a+t)*l,f=(d+(0,o.calculateReflectOffset)(t,r))*l;for(let t=0;t<l;++t)n[u+t]=e[f+t]}}}e=n,t=[d,u,l]}return[e,t]}rescale(e){for(let t=0;t<e.length;++t)e[t]=this.rescale_factor*e[t]}get_resize_output_image_size(e,t){let[n,r]=e.size,i,a;if(this.do_thumbnail){let{height:e,width:n}=t;i=Math.min(e,n)}else Number.isInteger(t)?(i=t,a=this.config.max_size??i):t!==void 0&&(i=t.shortest_edge,a=t.longest_edge);if(i!==void 0||a!==void 0){let e=i===void 0?1:Math.max(i/n,i/r),t=n*e,o=r*e,s=a===void 0?1:Math.min(a/t,a/o),c=Math.floor(Number((t*s).toFixed(2))),l=Math.floor(Number((o*s).toFixed(2)));return this.size_divisibility!==void 0&&([c,l]=u([c,l],this.size_divisibility)),[c,l]}else if(t!==void 0&&t.width!==void 0&&t.height!==void 0){let e=t.width,i=t.height;if(this.config.keep_aspect_ratio&&this.config.ensure_multiple_of){let t=i/r,a=e/n;Math.abs(1-a)<Math.abs(1-t)?t=a:a=t,i=l(t*r,this.config.ensure_multiple_of),e=l(a*n,this.config.ensure_multiple_of)}return[e,i]}else if(this.size_divisibility!==void 0)return u([n,r],this.size_divisibility);else if(this.min_pixels!==void 0&&this.max_pixels!==void 0)return _(r,n,this.config.patch_size*this.config.merge_size,this.min_pixels,this.max_pixels);else throw Error(`Could not resize image due to unsupported \`this.size\` option in config: ${JSON.stringify(t)}`)}async resize(e){let[t,n]=this.get_resize_output_image_size(e,this.size);return await e.resize(t,n,{resample:this.resample})}async preprocess(e,{do_normalize:t=null,do_pad:n=null,do_convert_rgb:r=null,do_convert_grayscale:a=null,do_flip_channel_order:o=null}={}){this.do_crop_margin&&(e=await this.crop_margin(e));let[s,c]=e.size;if(r??this.do_convert_rgb?e=e.rgb():a&&(e=e.grayscale()),this.do_resize&&(e=await this.resize(e)),this.do_thumbnail&&(e=await this.thumbnail(e,this.size,this.resample)),this.do_center_crop){let t,n;Number.isInteger(this.crop_size)?(t=this.crop_size,n=this.crop_size):(t=this.crop_size.width,n=this.crop_size.height),e=await e.center_crop(t,n)}let l=[e.height,e.width],d=Float32Array.from(e.data),f=[e.height,e.width,e.channels];if(this.do_rescale&&this.rescale(d),t??this.do_normalize){let t=this.image_mean;Array.isArray(this.image_mean)||(t=Array(e.channels).fill(t));let n=this.image_std;if(Array.isArray(this.image_std)||(n=Array(e.channels).fill(n)),t.length!==e.channels||n.length!==e.channels)throw Error(`When set to arrays, the length of \`image_mean\` (${t.length}) and \`image_std\` (${n.length}) must match the number of channels in the image (${e.channels}).`);for(let r=0;r<d.length;r+=e.channels)for(let i=0;i<e.channels;++i)d[r+i]=(d[r+i]-t[i])/n[i]}if(n??this.do_pad){if(this.pad_size){let t=this.pad_image(d,[e.height,e.width,e.channels],this.pad_size);[d,f]=t}else if(this.size_divisibility){let[e,t]=u([f[1],f[0]],this.size_divisibility);[d,f]=this.pad_image(d,f,{width:e,height:t})}}if(o??this.do_flip_channel_order){if(f[2]!==3)throw Error(`Flipping channel order is only supported for RGB images.`);for(let e=0;e<d.length;e+=3){let t=d[e];d[e]=d[e+2],d[e+2]=t}}let p=new i.Tensor(`float32`,d,f).permute(2,0,1);return{original_size:[c,s],reshaped_input_size:l,pixel_values:p}}async _call(e,...t){Array.isArray(e)||(e=[e]);let n=await Promise.all(e.map(e=>this.preprocess(e)));return{pixel_values:(0,i.stack)(n.map(e=>e.pixel_values),0),original_sizes:n.map(e=>e.original_size),reshaped_input_sizes:n.map(e=>e.reshaped_input_size)}}static async from_pretrained(e,t={}){let n=await(0,s.getModelJSON)(e,c.IMAGE_PROCESSOR_NAME,!0,t);return new this(n)}}}),"./src/base/processing_utils.js":((e,t,n)=>{n.r(t),n.d(t,{Processor:()=>o});var r=n(`./src/utils/constants.js`),i=n(`./src/utils/generic.js`),a=n(`./src/utils/hub.js`);class o extends i.Callable{static classes=[`image_processor_class`,`tokenizer_class`,`feature_extractor_class`];static uses_processor_config=!1;static uses_chat_template_file=!1;constructor(e,t,n){super(),this.config=e,this.components=t,this.chat_template=n}get image_processor(){return this.components.image_processor}get tokenizer(){return this.components.tokenizer}get feature_extractor(){return this.components.feature_extractor}apply_chat_template(e,t={}){if(!this.tokenizer)throw Error(`Unable to apply chat template without a tokenizer.`);return this.tokenizer.apply_chat_template(e,{tokenize:!1,chat_template:this.chat_template??void 0,...t})}batch_decode(...e){if(!this.tokenizer)throw Error(`Unable to decode without a tokenizer.`);return this.tokenizer.batch_decode(...e)}decode(...e){if(!this.tokenizer)throw Error(`Unable to decode without a tokenizer.`);return this.tokenizer.decode(...e)}async _call(e,...t){for(let n of[this.image_processor,this.feature_extractor,this.tokenizer])if(n)return n(e,...t);throw Error(`No image processor, feature extractor, or tokenizer found.`)}static async from_pretrained(e,t={}){let[n,i,o]=await Promise.all([this.uses_processor_config?(0,a.getModelJSON)(e,r.PROCESSOR_NAME,!0,t):{},Promise.all(this.classes.filter(e=>e in this).map(async n=>{let r=await this[n].from_pretrained(e,t);return[n.replace(/_class$/,``),r]})).then(Object.fromEntries),this.uses_chat_template_file?(0,a.getModelText)(e,r.CHAT_TEMPLATE_NAME,!0,t):null]);return new this(n,i,o)}}}),"./src/configs.js":((e,t,n)=>{n.r(t),n.d(t,{AutoConfig:()=>u,PretrainedConfig:()=>l,getCacheShapes:()=>s});var r=n(`./src/utils/core.js`),i=n(`./src/utils/hub.js`);async function a(e,t){return await(0,i.getModelJSON)(e,`config.json`,!0,t)}function o(e){let t={},n={};switch(e.model_type){case`llava`:case`paligemma`:case`gemma3`:case`florence2`:case`llava_onevision`:case`idefics3`:case`ultravox`:case`voxtral`:case`smolvlm`:case`gemma3n`:case`mistral3`:n=o(e.text_config);break;case`moondream1`:n=o(e.phi_config);break;case`musicgen`:n=o(e.decoder);break;case`multi_modality`:n=o(e.language_config);break;case`gpt2`:case`gptj`:case`jais`:case`codegen`:case`gpt_bigcode`:t.num_heads=`n_head`,t.num_layers=`n_layer`,t.hidden_size=`n_embd`;break;case`gpt_neox`:case`stablelm`:case`opt`:case`falcon`:case`modernbert-decoder`:t.num_heads=`num_attention_heads`,t.num_layers=`num_hidden_layers`,t.hidden_size=`hidden_size`;break;case`llama`:case`llama4_text`:case`nanochat`:case`arcee`:case`lfm2`:case`smollm3`:case`olmo`:case`olmo2`:case`mobilellm`:case`granite`:case`granitemoehybrid`:case`cohere`:case`mistral`:case`starcoder2`:case`qwen2`:case`qwen2_vl`:case`phi`:case`phi3`:case`phi3_v`:case`llava_qwen2`:t.num_heads=`num_key_value_heads`,t.num_layers=`num_hidden_layers`,t.hidden_size=`hidden_size`,t.num_attention_heads=`num_attention_heads`,t.dim_kv=`head_dim`;break;case`qwen3`:case`gemma`:case`gemma2`:case`vaultgemma`:case`gemma3_text`:case`gemma3n_text`:case`glm`:case`helium`:case`ernie4_5`:case`ministral`:case`ministral3`:t.num_heads=`num_key_value_heads`,t.num_layers=`num_hidden_layers`,t.dim_kv=`head_dim`;break;case`openelm`:t.num_heads=`num_kv_heads`,t.num_layers=`num_transformer_layers`,t.dim_kv=`head_dim`;break;case`gpt_neo`:case`donut-swin`:t.num_heads=`num_heads`,t.num_layers=`num_layers`,t.hidden_size=`hidden_size`;break;case`bloom`:t.num_heads=`n_head`,t.num_layers=`n_layer`,t.hidden_size=`hidden_size`;break;case`mpt`:t.num_heads=`n_heads`,t.num_layers=`n_layers`,t.hidden_size=`d_model`;break;case`exaone`:t.num_heads=`num_key_value_heads`,t.num_layers=`num_layers`,t.dim_kv=`head_dim`,t.num_attention_heads=`num_attention_heads`;break;case`t5`:case`mt5`:case`longt5`:t.num_decoder_layers=`num_decoder_layers`,t.num_decoder_heads=`num_heads`,t.decoder_dim_kv=`d_kv`,t.num_encoder_layers=`num_layers`,t.num_encoder_heads=`num_heads`,t.encoder_dim_kv=`d_kv`;break;case`bart`:case`mbart`:case`marian`:case`whisper`:case`lite-whisper`:case`m2m_100`:case`blenderbot`:case`blenderbot-small`:case`florence2_language`:t.num_decoder_layers=`decoder_layers`,t.num_decoder_heads=`decoder_attention_heads`,t.decoder_hidden_size=`d_model`,t.num_encoder_layers=`encoder_layers`,t.num_encoder_heads=`encoder_attention_heads`,t.encoder_hidden_size=`d_model`;break;case`speecht5`:t.num_decoder_layers=`decoder_layers`,t.num_decoder_heads=`decoder_attention_heads`,t.decoder_hidden_size=`hidden_size`,t.num_encoder_layers=`encoder_layers`,t.num_encoder_heads=`encoder_attention_heads`,t.encoder_hidden_size=`hidden_size`;break;case`trocr`:t.num_encoder_layers=t.num_decoder_layers=`decoder_layers`,t.num_encoder_heads=t.num_decoder_heads=`decoder_attention_heads`,t.encoder_hidden_size=t.decoder_hidden_size=`d_model`;break;case`musicgen_decoder`:t.num_encoder_layers=t.num_decoder_layers=`num_hidden_layers`,t.num_encoder_heads=t.num_decoder_heads=`num_attention_heads`,t.encoder_hidden_size=t.decoder_hidden_size=`hidden_size`;break;case`moonshine`:t.num_decoder_layers=`decoder_num_hidden_layers`,t.num_decoder_heads=`decoder_num_key_value_heads`,t.num_encoder_layers=`encoder_num_hidden_layers`,t.num_encoder_heads=`encoder_num_key_value_heads`,t.encoder_hidden_size=t.decoder_hidden_size=`hidden_size`;break;case`vision-encoder-decoder`:let i=o(e.decoder),a=`num_decoder_layers`in i,s=(0,r.pick)(e,[`model_type`,`is_encoder_decoder`]);return a?(s.num_decoder_layers=i.num_decoder_layers,s.num_decoder_heads=i.num_decoder_heads,s.decoder_hidden_size=i.decoder_hidden_size,s.num_encoder_layers=i.num_encoder_layers,s.num_encoder_heads=i.num_encoder_heads,s.encoder_hidden_size=i.encoder_hidden_size):(s.num_layers=i.num_layers,s.num_heads=i.num_heads,s.hidden_size=i.hidden_size),s}let i={...n,...(0,r.pick)(e,[`model_type`,`multi_query`,`is_encoder_decoder`])};for(let n in t)i[n]=e[t[n]];return i}function s(e,t){if(e.model_type===`lfm2`){let n=t?.prefix??`past_key_values`,r=n===`present`?`present`:`past`,i={},{layer_types:a,num_attention_heads:o,num_key_value_heads:s,hidden_size:c,conv_L_cache:l}=e,u=c/o,d=t?.batch_size??1;for(let e=0;e<a.length;++e)if(a[e]===`full_attention`)for(let t of[`key`,`value`])i[`${n}.${e}.${t}`]=[d,s,0,u];else if(a[e]===`conv`)i[`${r}_conv.${e}`]=[d,c,l];else throw Error(`Unsupported layer type: ${a[e]}`);return i}return c(e,t)}function c(e,{prefix:t=`past_key_values`,batch_size:n=1}={}){let r={},i=e.normalized_config;if(i.is_encoder_decoder&&`num_encoder_heads`in i&&`num_decoder_heads`in i){let e=i.encoder_dim_kv??i.encoder_hidden_size/i.num_encoder_heads,a=i.decoder_dim_kv??i.decoder_hidden_size/i.num_decoder_heads,o=[n,i.num_encoder_heads,0,e],s=[n,i.num_decoder_heads,0,a];for(let e=0;e<i.num_decoder_layers;++e)r[`${t}.${e}.encoder.key`]=o,r[`${t}.${e}.encoder.value`]=o,r[`${t}.${e}.decoder.key`]=s,r[`${t}.${e}.decoder.value`]=s}else{let e=i.num_heads,a=i.num_layers,o=i.dim_kv??i.hidden_size/(i.num_attention_heads??e);if(i.model_type===`falcon`){let i=[n*e,0,o];for(let e=0;e<a;++e)r[`${t}.${e}.key`]=i,r[`${t}.${e}.value`]=i}else if(i.multi_query){let i=[n*e,0,2*o];for(let e=0;e<a;++e)r[`${t}.${e}.key_value`]=i}else if(i.model_type===`bloom`){let i=[n*e,o,0],s=[n*e,0,o];for(let e=0;e<a;++e)r[`${t}.${e}.key`]=i,r[`${t}.${e}.value`]=s}else if(i.model_type===`openelm`)for(let i=0;i<a;++i){let a=[n,e[i],0,o];r[`${t}.${i}.key`]=a,r[`${t}.${i}.value`]=a}else{let i=[n,e,0,o];for(let e=0;e<a;++e)r[`${t}.${e}.key`]=i,r[`${t}.${e}.value`]=i}}return r}class l{model_type=null;is_encoder_decoder=!1;max_position_embeddings;"transformers.js_config";constructor(e){Object.assign(this,e),this.normalized_config=o(this)}static async from_pretrained(e,{progress_callback:t=null,config:n=null,cache_dir:r=null,local_files_only:i=!1,revision:o=`main`}={}){n&&!(n instanceof l)&&(n=new l(n));let s=n??await a(e,{progress_callback:t,config:n,cache_dir:r,local_files_only:i,revision:o});return new this(s)}}class u{static async from_pretrained(...e){return l.from_pretrained(...e)}}}),"./src/env.js":((e,t,n)=>{n.r(t),n.d(t,{apis:()=>g,env:()=>S});var r=n(`?db59`),i=n(`?383f`),a=n(`?fa4b`);let o=typeof window<`u`&&window.document!==void 0,s=typeof self<`u`&&[`DedicatedWorkerGlobalScope`,`ServiceWorkerGlobalScope`,`SharedWorkerGlobalScope`].includes(self.constructor?.name),c=typeof self<`u`&&`caches`in self,l=typeof navigator<`u`&&`gpu`in navigator,u=typeof navigator<`u`&&`ml`in navigator,d=typeof process<`u`,f=d&&process?.release?.name===`node`,p=!C(r),m=!C(i),h=globalThis.Deno!==void 0;globalThis.Bun;let g=Object.freeze({IS_BROWSER_ENV:o,IS_WEBWORKER_ENV:s,IS_WEB_CACHE_AVAILABLE:c,IS_WEBGPU_AVAILABLE:l,IS_WEBNN_AVAILABLE:u,IS_PROCESS_AVAILABLE:d,IS_NODE_ENV:f,IS_FS_AVAILABLE:p,IS_PATH_AVAILABLE:m}),_=p&&m,v=`./`;if(_){let e=Object(import.meta).url;e?v=i.dirname(i.dirname(a.fileURLToPath(e))):typeof __dirname<`u`&&(v=i.dirname(__dirname))}let y=_?i.join(v,`/.cache/`):null,b=`/models/`,x=_?i.join(v,b):b,S={version:`3.8.1`,backends:{onnx:{}},allowRemoteModels:!0,remoteHost:`https://huggingface.co/`,remotePathTemplate:`{model}/resolve/{revision}/`,allowLocalModels:!(o||s),localModelPath:x,useFS:p,useBrowserCache:c&&!h,useFSCache:p,cacheDir:y,useCustomCache:!1,customCache:null};function C(e){return Object.keys(e).length===0}}),"./src/generation/configuration_utils.js":((e,t,n)=>{n.r(t),n.d(t,{GenerationConfig:()=>i});var r=n(`./src/utils/core.js`);class i{max_length=20;max_new_tokens=null;min_length=0;min_new_tokens=null;early_stopping=!1;max_time=null;do_sample=!1;num_beams=1;num_beam_groups=1;penalty_alpha=null;use_cache=!0;temperature=1;top_k=50;top_p=1;typical_p=1;epsilon_cutoff=0;eta_cutoff=0;diversity_penalty=0;repetition_penalty=1;encoder_repetition_penalty=1;length_penalty=1;no_repeat_ngram_size=0;bad_words_ids=null;force_words_ids=null;renormalize_logits=!1;constraints=null;forced_bos_token_id=null;forced_eos_token_id=null;remove_invalid_values=!1;exponential_decay_length_penalty=null;suppress_tokens=null;streamer=null;begin_suppress_tokens=null;forced_decoder_ids=null;guidance_scale=null;num_return_sequences=1;output_attentions=!1;output_hidden_states=!1;output_scores=!1;return_dict_in_generate=!1;pad_token_id=null;bos_token_id=null;eos_token_id=null;encoder_no_repeat_ngram_size=0;decoder_start_token_id=null;generation_kwargs={};constructor(e){Object.assign(this,(0,r.pick)(e,Object.getOwnPropertyNames(this)))}}}),"./src/generation/logits_process.js":((e,t,n)=>{n.r(t),n.d(t,{ClassifierFreeGuidanceLogitsProcessor:()=>_,ForcedBOSTokenLogitsProcessor:()=>c,ForcedEOSTokenLogitsProcessor:()=>l,LogitsProcessor:()=>a,LogitsProcessorList:()=>s,LogitsWarper:()=>o,MinLengthLogitsProcessor:()=>m,MinNewTokensLengthLogitsProcessor:()=>h,NoBadWordsLogitsProcessor:()=>g,NoRepeatNGramLogitsProcessor:()=>f,RepetitionPenaltyLogitsProcessor:()=>p,SuppressTokensAtBeginLogitsProcessor:()=>u,TemperatureLogitsWarper:()=>v,TopKLogitsWarper:()=>b,TopPLogitsWarper:()=>y,WhisperTimeStampLogitsProcessor:()=>d});var r=n(`./src/utils/generic.js`);n(`./src/utils/tensor.js`);var i=n(`./src/utils/maths.js`);class a extends r.Callable{_call(e,t){throw Error("`_call` should be implemented in a subclass")}}class o extends r.Callable{_call(e,t){throw Error("`_call` should be implemented in a subclass")}}class s extends r.Callable{constructor(){super(),this.processors=[]}push(e){this.processors.push(e)}extend(e){this.processors.push(...e)}_call(e,t){let n=t;for(let t of this.processors)n=t(e,n);return n}[Symbol.iterator](){return this.processors.values()}}class c extends a{constructor(e){super(),this.bos_token_id=e}_call(e,t){for(let n=0;n<e.length;++n)if(e[n].length===1){let e=t[n].data;e.fill(-1/0),e[this.bos_token_id]=0}return t}}class l extends a{constructor(e,t){super(),this.max_length=e,this.eos_token_id=Array.isArray(t)?t:[t]}_call(e,t){for(let n=0;n<e.length;++n)if(e[n].length===this.max_length-1){let e=t[n].data;e.fill(-1/0);for(let t of this.eos_token_id)e[t]=0}return t}}class u extends a{constructor(e,t){super(),this.begin_suppress_tokens=e,this.begin_index=t}_call(e,t){for(let n=0;n<e.length;++n)if(e[n].length===this.begin_index){let e=t[n].data;for(let t of this.begin_suppress_tokens)e[t]=-1/0}return t}}class d extends a{constructor(e,t){super(),this.eos_token_id=Array.isArray(e.eos_token_id)?e.eos_token_id[0]:e.eos_token_id,this.no_timestamps_token_id=e.no_timestamps_token_id,this.timestamp_begin=this.no_timestamps_token_id+1,this.begin_index=t.length,t.at(-1)===this.no_timestamps_token_id&&--this.begin_index,this.max_initial_timestamp_index=e.max_initial_timestamp_index}_call(e,t){for(let n=0;n<e.length;++n){let r=t[n].data;if(r[this.no_timestamps_token_id]=-1/0,e[n].length===this.begin_index-1){r.fill(-1/0),r[this.timestamp_begin]=0;continue}let a=e[n].slice(this.begin_index),o=a.length>=1&&a[a.length-1]>=this.timestamp_begin,s=a.length<2||a[a.length-2]>=this.timestamp_begin;if(o&&(s?r.subarray(this.timestamp_begin).fill(-1/0):r.subarray(0,this.eos_token_id).fill(-1/0)),e[n].length===this.begin_index&&this.max_initial_timestamp_index!==null){let e=this.timestamp_begin+this.max_initial_timestamp_index;r.subarray(e+1).fill(-1/0)}let c=(0,i.log_softmax)(r);Math.log(c.subarray(this.timestamp_begin).map(Math.exp).reduce((e,t)=>e+t))>(0,i.max)(c.subarray(0,this.timestamp_begin))[0]&&r.subarray(0,this.timestamp_begin).fill(-1/0)}return t}}class f extends a{constructor(e){super(),this.no_repeat_ngram_size=e}getNgrams(e){let t=e.length,n=[];for(let r=0;r<t+1-this.no_repeat_ngram_size;++r){let t=[];for(let n=0;n<this.no_repeat_ngram_size;++n)t.push(e[r+n]);n.push(t.map(Number))}let r=new Map;for(let e of n){let t=e.slice(0,e.length-1),n=JSON.stringify(t),i=r.get(n)??[];i.push(e[e.length-1]),r.set(n,i)}return r}getGeneratedNgrams(e,t){let n=t.slice(t.length+1-this.no_repeat_ngram_size,t.length);return e.get(JSON.stringify(n.map(Number)))??[]}calcBannedNgramTokens(e){let t=[];if(e.length+1<this.no_repeat_ngram_size)return t;{let t=this.getNgrams(e);return this.getGeneratedNgrams(t,e)}}_call(e,t){for(let n=0;n<e.length;++n){let r=t[n].data,i=this.calcBannedNgramTokens(e[n]);for(let e of i)r[e]=-1/0}return t}}class p extends a{constructor(e){super(),this.penalty=e}_call(e,t){for(let n=0;n<e.length;++n){let r=t[n].data;for(let t of new Set(e[n])){let e=Number(t);r[e]<0?r[e]*=this.penalty:r[e]/=this.penalty}}return t}}class m extends a{constructor(e,t){super(),this.min_length=e,this.eos_token_id=Array.isArray(t)?t:[t]}_call(e,t){for(let n=0;n<e.length;++n)if(e[n].length<this.min_length){let e=t[n].data;for(let t of this.eos_token_id)e[t]=-1/0}return t}}class h extends a{constructor(e,t,n){super(),this.prompt_length_to_skip=e,this.min_new_tokens=t,this.eos_token_id=Array.isArray(n)?n:[n]}_call(e,t){for(let n=0;n<e.length;++n)if(e[n].length-this.prompt_length_to_skip<this.min_new_tokens){let e=t[n].data;for(let t of this.eos_token_id)e[t]=-1/0}return t}}class g extends a{constructor(e,t){super(),this.bad_words_ids=e,this.eos_token_id=Array.isArray(t)?t:[t]}_call(e,t){for(let n=0;n<e.length;++n){let r=t[n].data,i=e[n];for(let e of this.bad_words_ids){if(i.length<e.length-1)continue;let t=!0;for(let n=1;n<=e.length-1;++n)if(e.at(-n-1)!=i.at(-n)){t=!1;break}t&&(r[e.at(-1)]=-1/0)}}return t}}class _ extends a{constructor(e){if(super(),e<=1)throw Error(`Require guidance scale >1 to use the classifier free guidance processor, got guidance scale ${e}.`);this.guidance_scale=e}_call(e,t){if(t.dims[0]!==2*e.length)throw Error(`Logits should have twice the batch size of the input ids, the first half of batches corresponding to the conditional inputs, and the second half of batches corresponding to the unconditional inputs. Got batch size ${t.dims[0]} for the logits and ${e.length} for the input ids.`);let n=e.length,r=t.slice([0,n],null),i=t.slice([n,t.dims[0]],null);for(let e=0;e<i.data.length;++e)i.data[e]+=(r.data[e]-i.data[e])*this.guidance_scale;return i}}class v extends o{constructor(e){if(super(),typeof e!=`number`||e<=0){let t=`\`temperature\` (=${e}) must be a strictly positive float, otherwise your next token scores will be invalid.`;e===0&&(t+=" If you're looking for greedy decoding strategies, set `do_sample=false`.")}this.temperature=e}_call(e,t){let n=t.data;for(let e=0;e<n.length;++e)n[e]/=this.temperature;return t}}class y extends o{constructor(e,{filter_value:t=-1/0,min_tokens_to_keep:n=1}={}){if(super(),e<0||e>1)throw Error(`\`top_p\` must be a float > 0 and < 1, but is ${e}`);if(!Number.isInteger(n)||n<1)throw Error(`\`min_tokens_to_keep\` must be a positive integer, but is ${n}`);this.top_p=e,this.filter_value=t,this.min_tokens_to_keep=n}}class b extends o{constructor(e,{filter_value:t=-1/0,min_tokens_to_keep:n=1}={}){if(super(),!Number.isInteger(e)||e<0)throw Error(`\`top_k\` must be a positive integer, but is ${e}`);this.top_k=Math.max(e,n),this.filter_value=t}}}),"./src/generation/logits_sampler.js":((e,t,n)=>{n.r(t),n.d(t,{LogitsSampler:()=>o});var r=n(`./src/utils/generic.js`),i=n(`./src/utils/tensor.js`),a=n(`./src/utils/maths.js`);n(`./src/generation/configuration_utils.js`);class o extends r.Callable{constructor(e){super(),this.generation_config=e}async _call(e){return this.sample(e)}async sample(e){throw Error(`sample should be implemented in subclasses.`)}getLogits(e,t){let n=e.dims.at(-1),r=e.data;if(t===-1)r=r.slice(-n);else{let e=t*n;r=r.slice(e,e+n)}return r}randomSelect(e){let t=0;for(let n=0;n<e.length;++n)t+=e[n];let n=Math.random()*t;for(let t=0;t<e.length;++t)if(n-=e[t],n<=0)return t;return 0}static getSampler(e){if(e.do_sample)return new c(e);if(e.num_beams>1)return new l(e);if(e.num_return_sequences>1)throw Error(`num_return_sequences has to be 1 when doing greedy search, but is ${e.num_return_sequences}.`);return new s(e)}}class s extends o{async sample(e){let t=(0,a.max)(e.data)[1];return[[BigInt(t),0]]}}class c extends o{async sample(e){let t=e.dims.at(-1);this.generation_config.top_k>0&&(t=Math.min(this.generation_config.top_k,t));let[n,r]=await(0,i.topk)(e,t),o=(0,a.softmax)(n.data);return Array.from({length:this.generation_config.num_beams},()=>{let e=this.randomSelect(o);return[r.data[e],Math.log(o[e])]})}}class l extends o{async sample(e){let t=e.dims.at(-1);this.generation_config.top_k>0&&(t=Math.min(this.generation_config.top_k,t));let[n,r]=await(0,i.topk)(e,t),o=(0,a.softmax)(n.data);return Array.from({length:this.generation_config.num_beams},(e,t)=>[r.data[t],Math.log(o[t])])}}}),"./src/generation/stopping_criteria.js":((e,t,n)=>{n.r(t),n.d(t,{EosTokenCriteria:()=>s,InterruptableStoppingCriteria:()=>c,MaxLengthCriteria:()=>o,StoppingCriteria:()=>i,StoppingCriteriaList:()=>a});var r=n(`./src/utils/generic.js`);class i extends r.Callable{_call(e,t){throw Error(`StoppingCriteria needs to be subclassed`)}}class a extends r.Callable{constructor(){super(),this.criteria=[]}push(e){this.criteria.push(e)}extend(e){e instanceof a?e=e.criteria:e instanceof i&&(e=[e]),this.criteria.push(...e)}_call(e,t){let n=Array(e.length).fill(!1);for(let r of this.criteria){let i=r(e,t);for(let e=0;e<n.length;++e)n[e]||=i[e]}return n}[Symbol.iterator](){return this.criteria.values()}}class o extends i{constructor(e,t=null){super(),this.max_length=e,this.max_position_embeddings=t}_call(e){return e.map(e=>e.length>=this.max_length)}}class s extends i{constructor(e){super(),Array.isArray(e)||(e=[e]),this.eos_token_id=e}_call(e,t){return e.map(e=>{let t=e.at(-1);return this.eos_token_id.some(e=>t==e)})}}class c extends i{constructor(){super(),this.interrupted=!1}interrupt(){this.interrupted=!0}reset(){this.interrupted=!1}_call(e,t){return Array(e.length).fill(this.interrupted)}}}),"./src/generation/streamers.js":((e,t,n)=>{n.r(t),n.d(t,{BaseStreamer:()=>o,TextStreamer:()=>c,WhisperTextStreamer:()=>l});var r=n(`./src/utils/core.js`),i=n(`./src/tokenizers.js`),a=n(`./src/env.js`);class o{put(e){throw Error(`Not implemented`)}end(){throw Error(`Not implemented`)}}let s=a.apis.IS_PROCESS_AVAILABLE?e=>process.stdout.write(e):e=>console.log(e);class c extends o{constructor(e,{skip_prompt:t=!1,callback_function:n=null,token_callback_function:r=null,skip_special_tokens:i=!0,decode_kwargs:a={},...o}={}){super(),this.tokenizer=e,this.skip_prompt=t,this.callback_function=n??s,this.token_callback_function=r,this.decode_kwargs={skip_special_tokens:i,...a,...o},this.token_cache=[],this.print_len=0,this.next_tokens_are_prompt=!0}put(e){if(e.length>1)throw Error(`TextStreamer only supports batch size of 1`);let t=this.next_tokens_are_prompt;if(t&&(this.next_tokens_are_prompt=!1,this.skip_prompt))return;let n=e[0];this.token_callback_function?.(n),this.token_cache=(0,r.mergeArrays)(this.token_cache,n);let a=this.tokenizer.decode(this.token_cache,this.decode_kwargs),o;t||a.endsWith(`
2814
+ `)?(o=a.slice(this.print_len),this.token_cache=[],this.print_len=0):a.length>0&&(0,i.is_chinese_char)(a.charCodeAt(a.length-1))?(o=a.slice(this.print_len),this.print_len+=o.length):(o=a.slice(this.print_len,a.lastIndexOf(` `)+1),this.print_len+=o.length),this.on_finalized_text(o,!1)}end(){let e;this.token_cache.length>0?(e=this.tokenizer.decode(this.token_cache,this.decode_kwargs).slice(this.print_len),this.token_cache=[],this.print_len=0):e=``,this.next_tokens_are_prompt=!0,this.on_finalized_text(e,!0)}on_finalized_text(e,t){e.length>0&&this.callback_function?.(e),t&&this.callback_function===s&&a.apis.IS_PROCESS_AVAILABLE&&this.callback_function?.(`
2815
+ `)}}class l extends c{constructor(e,{skip_prompt:t=!1,callback_function:n=null,token_callback_function:r=null,on_chunk_start:i=null,on_chunk_end:a=null,on_finalize:o=null,time_precision:s=.02,skip_special_tokens:c=!0,decode_kwargs:l={}}={}){super(e,{skip_prompt:t,skip_special_tokens:c,callback_function:n,token_callback_function:r,decode_kwargs:l}),this.timestamp_begin=e.timestamp_begin,this.on_chunk_start=i,this.on_chunk_end=a,this.on_finalize=o,this.time_precision=s,this.waiting_for_timestamp=!1}put(e){if(e.length>1)throw Error(`WhisperTextStreamer only supports batch size of 1`);let t=e[0];if(t.length===1){let e=Number(t[0])-this.timestamp_begin;if(e>=0){let n=e*this.time_precision;this.waiting_for_timestamp?this.on_chunk_end?.(n):this.on_chunk_start?.(n),this.waiting_for_timestamp=!this.waiting_for_timestamp,this.token_callback_function?.(t);return}}return super.put(e)}end(){super.end(),this.on_finalize?.()}}}),"./src/models.js":((e,t,n)=>{n.r(t),n.d(t,{ASTForAudioClassification:()=>Mn,ASTModel:()=>jn,ASTPreTrainedModel:()=>An,AlbertForMaskedLM:()=>Wt,AlbertForQuestionAnswering:()=>Ut,AlbertForSequenceClassification:()=>Ht,AlbertModel:()=>Vt,AlbertPreTrainedModel:()=>Bt,ArceeForCausalLM:()=>Jr,ArceeModel:()=>qr,ArceePreTrainedModel:()=>Kr,AutoModel:()=>$u,AutoModelForAudioClassification:()=>vd,AutoModelForAudioFrameClassification:()=>bd,AutoModelForAudioTextToText:()=>kd,AutoModelForCTC:()=>_d,AutoModelForCausalLM:()=>od,AutoModelForDepthEstimation:()=>wd,AutoModelForDocumentQuestionAnswering:()=>xd,AutoModelForImageClassification:()=>ud,AutoModelForImageFeatureExtraction:()=>Dd,AutoModelForImageMatting:()=>Sd,AutoModelForImageSegmentation:()=>dd,AutoModelForImageTextToText:()=>Od,AutoModelForImageToImage:()=>Cd,AutoModelForMaskGeneration:()=>gd,AutoModelForMaskedLM:()=>sd,AutoModelForNormalEstimation:()=>Td,AutoModelForObjectDetection:()=>md,AutoModelForPoseEstimation:()=>Ed,AutoModelForQuestionAnswering:()=>cd,AutoModelForSemanticSegmentation:()=>fd,AutoModelForSeq2SeqLM:()=>nd,AutoModelForSequenceClassification:()=>ed,AutoModelForSpeechSeq2Seq:()=>rd,AutoModelForTextToSpectrogram:()=>id,AutoModelForTextToWaveform:()=>ad,AutoModelForTokenClassification:()=>td,AutoModelForUniversalSegmentation:()=>pd,AutoModelForVision2Seq:()=>ld,AutoModelForXVector:()=>yd,AutoModelForZeroShotObjectDetection:()=>hd,BartForConditionalGeneration:()=>nn,BartForSequenceClassification:()=>H,BartModel:()=>tn,BartPretrainedModel:()=>en,BaseModelOutput:()=>he,BeitForImageClassification:()=>Ya,BeitModel:()=>Ja,BeitPreTrainedModel:()=>qa,BertForMaskedLM:()=>ve,BertForQuestionAnswering:()=>I,BertForSequenceClassification:()=>F,BertForTokenClassification:()=>ye,BertModel:()=>_e,BertPreTrainedModel:()=>ge,BlenderbotForConditionalGeneration:()=>dn,BlenderbotModel:()=>un,BlenderbotPreTrainedModel:()=>ln,BlenderbotSmallForConditionalGeneration:()=>pn,BlenderbotSmallModel:()=>fn,BlenderbotSmallPreTrainedModel:()=>U,BloomForCausalLM:()=>aa,BloomModel:()=>ia,BloomPreTrainedModel:()=>ra,CLIPModel:()=>q,CLIPPreTrainedModel:()=>rr,CLIPSegForImageSegmentation:()=>gr,CLIPSegModel:()=>hr,CLIPSegPreTrainedModel:()=>mr,CLIPTextModel:()=>ir,CLIPTextModelWithProjection:()=>J,CLIPVisionModel:()=>Y,CLIPVisionModelWithProjection:()=>ar,CamembertForMaskedLM:()=>Ze,CamembertForQuestionAnswering:()=>et,CamembertForSequenceClassification:()=>Qe,CamembertForTokenClassification:()=>$e,CamembertModel:()=>Xe,CamembertPreTrainedModel:()=>Ye,CausalLMOutput:()=>Fd,CausalLMOutputWithPast:()=>Id,ChineseCLIPModel:()=>ur,ChineseCLIPPreTrainedModel:()=>lr,ClapAudioModelWithProjection:()=>nl,ClapModel:()=>el,ClapPreTrainedModel:()=>$c,ClapTextModelWithProjection:()=>tl,CodeGenForCausalLM:()=>Lr,CodeGenModel:()=>Ir,CodeGenPreTrainedModel:()=>Fr,CohereForCausalLM:()=>Di,CohereModel:()=>Ei,CoherePreTrainedModel:()=>Ti,ConvBertForMaskedLM:()=>B,ConvBertForQuestionAnswering:()=>Ue,ConvBertForSequenceClassification:()=>Ve,ConvBertForTokenClassification:()=>He,ConvBertModel:()=>Be,ConvBertPreTrainedModel:()=>ze,ConvNextForImageClassification:()=>ls,ConvNextModel:()=>cs,ConvNextPreTrainedModel:()=>ss,ConvNextV2ForImageClassification:()=>fs,ConvNextV2Model:()=>ds,ConvNextV2PreTrainedModel:()=>us,DFineForObjectDetection:()=>_o,DFineModel:()=>go,DFinePreTrainedModel:()=>ho,DINOv3ConvNextModel:()=>Ss,DINOv3ConvNextPreTrainedModel:()=>xs,DINOv3ViTModel:()=>bs,DINOv3ViTPreTrainedModel:()=>ys,DPTForDepthEstimation:()=>Bo,DPTModel:()=>zo,DPTPreTrainedModel:()=>Ro,DacDecoderModel:()=>cu,DacDecoderOutput:()=>au,DacEncoderModel:()=>su,DacEncoderOutput:()=>iu,DacModel:()=>ou,DacPreTrainedModel:()=>ru,DebertaForMaskedLM:()=>rt,DebertaForQuestionAnswering:()=>ot,DebertaForSequenceClassification:()=>it,DebertaForTokenClassification:()=>at,DebertaModel:()=>nt,DebertaPreTrainedModel:()=>tt,DebertaV2ForMaskedLM:()=>lt,DebertaV2ForQuestionAnswering:()=>ft,DebertaV2ForSequenceClassification:()=>ut,DebertaV2ForTokenClassification:()=>dt,DebertaV2Model:()=>ct,DebertaV2PreTrainedModel:()=>st,DecisionTransformerModel:()=>Il,DecisionTransformerPreTrainedModel:()=>Fl,DeiTForImageClassification:()=>wo,DeiTModel:()=>Co,DeiTPreTrainedModel:()=>So,DepthAnythingForDepthEstimation:()=>Ho,DepthAnythingPreTrainedModel:()=>Vo,DepthProForDepthEstimation:()=>Jo,DepthProPreTrainedModel:()=>qo,DetrForObjectDetection:()=>Qa,DetrForSegmentation:()=>$a,DetrModel:()=>Za,DetrObjectDetectionOutput:()=>eo,DetrPreTrainedModel:()=>Xa,DetrSegmentationOutput:()=>to,Dinov2ForImageClassification:()=>hs,Dinov2Model:()=>ms,Dinov2PreTrainedModel:()=>ps,Dinov2WithRegistersForImageClassification:()=>vs,Dinov2WithRegistersModel:()=>_s,Dinov2WithRegistersPreTrainedModel:()=>gs,DistilBertForMaskedLM:()=>vt,DistilBertForQuestionAnswering:()=>_t,DistilBertForSequenceClassification:()=>ht,DistilBertForTokenClassification:()=>gt,DistilBertModel:()=>mt,DistilBertPreTrainedModel:()=>pt,DonutSwinModel:()=>os,DonutSwinPreTrainedModel:()=>as,EdgeTamModel:()=>Fs,EfficientNetForImageClassification:()=>ml,EfficientNetModel:()=>pl,EfficientNetPreTrainedModel:()=>fl,ElectraForMaskedLM:()=>Ge,ElectraForQuestionAnswering:()=>Je,ElectraForSequenceClassification:()=>Ke,ElectraForTokenClassification:()=>qe,ElectraModel:()=>V,ElectraPreTrainedModel:()=>We,Ernie4_5ForCausalLM:()=>Kc,Ernie4_5Model:()=>Gc,Ernie4_5PreTrainedModel:()=>Wc,EsmForMaskedLM:()=>xt,EsmForSequenceClassification:()=>St,EsmForTokenClassification:()=>Ct,EsmModel:()=>bt,EsmPreTrainedModel:()=>yt,ExaoneForCausalLM:()=>li,ExaoneModel:()=>ci,ExaonePreTrainedModel:()=>si,FalconForCausalLM:()=>Qc,FalconModel:()=>Zc,FalconPreTrainedModel:()=>Xc,FastViTForImageClassification:()=>Ma,FastViTModel:()=>ja,FastViTPreTrainedModel:()=>Aa,Florence2ForConditionalGeneration:()=>Kn,Florence2PreTrainedModel:()=>Gn,GLPNForDepthEstimation:()=>is,GLPNModel:()=>rs,GLPNPreTrainedModel:()=>ns,GPT2LMHeadModel:()=>yr,GPT2Model:()=>vr,GPT2PreTrainedModel:()=>_r,GPTBigCodeForCausalLM:()=>Pr,GPTBigCodeModel:()=>Nr,GPTBigCodePreTrainedModel:()=>Mr,GPTJForCausalLM:()=>jr,GPTJModel:()=>Ar,GPTJPreTrainedModel:()=>kr,GPTNeoForCausalLM:()=>Tr,GPTNeoModel:()=>wr,GPTNeoPreTrainedModel:()=>Cr,GPTNeoXForCausalLM:()=>Or,GPTNeoXModel:()=>Dr,GPTNeoXPreTrainedModel:()=>Er,Gemma2ForCausalLM:()=>Ni,Gemma2Model:()=>Mi,Gemma2PreTrainedModel:()=>ji,Gemma3ForCausalLM:()=>zi,Gemma3Model:()=>Ri,Gemma3PreTrainedModel:()=>Li,Gemma3nForConditionalGeneration:()=>Qn,Gemma3nPreTrainedModel:()=>Zn,GemmaForCausalLM:()=>Ai,GemmaModel:()=>ki,GemmaPreTrainedModel:()=>Oi,GlmForCausalLM:()=>oi,GlmModel:()=>ai,GlmPreTrainedModel:()=>ii,GraniteForCausalLM:()=>xi,GraniteModel:()=>bi,GraniteMoeHybridForCausalLM:()=>wi,GraniteMoeHybridModel:()=>Ci,GraniteMoeHybridPreTrainedModel:()=>Si,GranitePreTrainedModel:()=>yi,GroundingDinoForObjectDetection:()=>ws,GroundingDinoPreTrainedModel:()=>Cs,GroupViTModel:()=>ka,GroupViTPreTrainedModel:()=>Oa,HeliumForCausalLM:()=>ri,HeliumModel:()=>ni,HeliumPreTrainedModel:()=>ti,HieraForImageClassification:()=>Do,HieraModel:()=>Eo,HieraPreTrainedModel:()=>To,HubertForCTC:()=>gc,HubertForSequenceClassification:()=>_c,HubertModel:()=>hc,HubertPreTrainedModel:()=>mc,IJepaForImageClassification:()=>_a,IJepaModel:()=>ga,IJepaPreTrainedModel:()=>ha,Idefics3ForConditionalGeneration:()=>K,Idefics3PreTrainedModel:()=>$n,ImageMattingOutput:()=>Ld,JAISLMHeadModel:()=>Sr,JAISModel:()=>xr,JAISPreTrainedModel:()=>br,JinaCLIPModel:()=>dr,JinaCLIPPreTrainedModel:()=>Z,JinaCLIPTextModel:()=>fr,JinaCLIPVisionModel:()=>pr,Lfm2ForCausalLM:()=>Zr,Lfm2Model:()=>Xr,Lfm2PreTrainedModel:()=>Yr,LiteWhisperForConditionalGeneration:()=>In,Llama4ForCausalLM:()=>Hr,Llama4PreTrainedModel:()=>Vr,LlamaForCausalLM:()=>Br,LlamaModel:()=>zr,LlamaPreTrainedModel:()=>Rr,LlavaForConditionalGeneration:()=>Hn,LlavaOnevisionForConditionalGeneration:()=>Un,LlavaPreTrainedModel:()=>Vn,LlavaQwen2ForCausalLM:()=>Yn,LongT5ForConditionalGeneration:()=>Xt,LongT5Model:()=>Yt,LongT5PreTrainedModel:()=>Jt,M2M100ForConditionalGeneration:()=>Hs,M2M100Model:()=>Vs,M2M100PreTrainedModel:()=>Bs,MBartForCausalLM:()=>cn,MBartForConditionalGeneration:()=>on,MBartForSequenceClassification:()=>sn,MBartModel:()=>an,MBartPreTrainedModel:()=>rn,MPNetForMaskedLM:()=>jt,MPNetForQuestionAnswering:()=>Pt,MPNetForSequenceClassification:()=>Mt,MPNetForTokenClassification:()=>Nt,MPNetModel:()=>At,MPNetPreTrainedModel:()=>kt,MT5ForConditionalGeneration:()=>$t,MT5Model:()=>Qt,MT5PreTrainedModel:()=>Zt,MarianMTModel:()=>zs,MarianModel:()=>Rs,MarianPreTrainedModel:()=>Ls,MaskFormerForInstanceSegmentation:()=>ts,MaskFormerModel:()=>es,MaskFormerPreTrainedModel:()=>$o,MaskedLMOutput:()=>Nd,Metric3DForDepthEstimation:()=>Xo,Metric3DPreTrainedModel:()=>Yo,Metric3Dv2ForDepthEstimation:()=>Qo,Metric3Dv2PreTrainedModel:()=>Zo,MgpstrForSceneTextRecognition:()=>Vl,MgpstrModelOutput:()=>zl,MgpstrPreTrainedModel:()=>Bl,MimiDecoderModel:()=>nu,MimiDecoderOutput:()=>$l,MimiEncoderModel:()=>tu,MimiEncoderOutput:()=>Ql,MimiModel:()=>eu,MimiPreTrainedModel:()=>Zl,Ministral3ForCausalLM:()=>Uc,Ministral3Model:()=>Hc,Ministral3PreTrainedModel:()=>Vc,MinistralForCausalLM:()=>Bc,MinistralModel:()=>zc,MinistralPreTrainedModel:()=>Rc,Mistral3ForConditionalGeneration:()=>Xn,MistralForCausalLM:()=>Lc,MistralModel:()=>Ic,MistralPreTrainedModel:()=>Fc,MobileBertForMaskedLM:()=>Et,MobileBertForQuestionAnswering:()=>Ot,MobileBertForSequenceClassification:()=>Dt,MobileBertModel:()=>Tt,MobileBertPreTrainedModel:()=>wt,MobileLLMForCausalLM:()=>fi,MobileLLMModel:()=>di,MobileLLMPreTrainedModel:()=>ui,MobileNetV1ForImageClassification:()=>xl,MobileNetV1ForSemanticSegmentation:()=>Sl,MobileNetV1Model:()=>bl,MobileNetV1PreTrainedModel:()=>yl,MobileNetV2ForImageClassification:()=>Tl,MobileNetV2ForSemanticSegmentation:()=>El,MobileNetV2Model:()=>wl,MobileNetV2PreTrainedModel:()=>Cl,MobileNetV3ForImageClassification:()=>kl,MobileNetV3ForSemanticSegmentation:()=>Al,MobileNetV3Model:()=>Ol,MobileNetV3PreTrainedModel:()=>Dl,MobileNetV4ForImageClassification:()=>Nl,MobileNetV4ForSemanticSegmentation:()=>Pl,MobileNetV4Model:()=>Ml,MobileNetV4PreTrainedModel:()=>jl,MobileViTForImageClassification:()=>La,MobileViTModel:()=>Ia,MobileViTPreTrainedModel:()=>Fa,MobileViTV2ForImageClassification:()=>Ba,MobileViTV2Model:()=>za,MobileViTV2PreTrainedModel:()=>Ra,ModelOutput:()=>me,ModernBertDecoderForCausalLM:()=>Ae,ModernBertDecoderModel:()=>ke,ModernBertDecoderPreTrainedModel:()=>Oe,ModernBertForMaskedLM:()=>Te,ModernBertForSequenceClassification:()=>Ee,ModernBertForTokenClassification:()=>De,ModernBertModel:()=>we,ModernBertPreTrainedModel:()=>z,Moondream1ForConditionalGeneration:()=>Wn,MoonshineForConditionalGeneration:()=>zn,MoonshineModel:()=>Rn,MoonshinePreTrainedModel:()=>Ln,MptForCausalLM:()=>ca,MptModel:()=>sa,MptPreTrainedModel:()=>oa,MultiModalityCausalLM:()=>Rl,MultiModalityPreTrainedModel:()=>Ll,MusicgenForCausalLM:()=>_l,MusicgenForConditionalGeneration:()=>vl,MusicgenModel:()=>gl,MusicgenPreTrainedModel:()=>hl,NanoChatForCausalLM:()=>Gr,NanoChatModel:()=>Wr,NanoChatPreTrainedModel:()=>Ur,NeoBertForMaskedLM:()=>xe,NeoBertForQuestionAnswering:()=>Ce,NeoBertForSequenceClassification:()=>Se,NeoBertForTokenClassification:()=>R,NeoBertModel:()=>be,NeoBertPreTrainedModel:()=>L,NomicBertModel:()=>Me,NomicBertPreTrainedModel:()=>je,OPTForCausalLM:()=>da,OPTModel:()=>ua,OPTPreTrainedModel:()=>la,Olmo2ForCausalLM:()=>vi,Olmo2Model:()=>_i,Olmo2PreTrainedModel:()=>gi,OlmoForCausalLM:()=>hi,OlmoModel:()=>mi,OlmoPreTrainedModel:()=>pi,OpenELMForCausalLM:()=>Hi,OpenELMModel:()=>Vi,OpenELMPreTrainedModel:()=>Bi,OwlViTForObjectDetection:()=>Ua,OwlViTModel:()=>Ha,OwlViTPreTrainedModel:()=>Va,Owlv2ForObjectDetection:()=>Ka,Owlv2Model:()=>Ga,Owlv2PreTrainedModel:()=>Wa,PaliGemmaForConditionalGeneration:()=>Jn,PaliGemmaPreTrainedModel:()=>qn,ParakeetForCTC:()=>Ys,ParakeetPreTrainedModel:()=>Js,PatchTSMixerForPrediction:()=>ql,PatchTSMixerModel:()=>Kl,PatchTSMixerPreTrainedModel:()=>Gl,PatchTSTForPrediction:()=>Wl,PatchTSTModel:()=>Ul,PatchTSTPreTrainedModel:()=>Hl,Phi3ForCausalLM:()=>na,Phi3Model:()=>ta,Phi3PreTrainedModel:()=>ea,Phi3VForCausalLM:()=>nr,Phi3VPreTrainedModel:()=>tr,PhiForCausalLM:()=>$i,PhiModel:()=>Qi,PhiPreTrainedModel:()=>Zi,PreTrainedModel:()=>P,PretrainedMixin:()=>pu,PvtForImageClassification:()=>Sa,PvtModel:()=>xa,PvtPreTrainedModel:()=>ba,PyAnnoteForAudioFrameClassification:()=>Qs,PyAnnoteModel:()=>Zs,PyAnnotePreTrainedModel:()=>Xs,QuestionAnsweringModelOutput:()=>Pd,Qwen2ForCausalLM:()=>Gi,Qwen2Model:()=>Wi,Qwen2PreTrainedModel:()=>Ui,Qwen2VLForConditionalGeneration:()=>Xi,Qwen2VLPreTrainedModel:()=>Yi,Qwen3ForCausalLM:()=>Ji,Qwen3Model:()=>qi,Qwen3PreTrainedModel:()=>Ki,RFDetrForObjectDetection:()=>po,RFDetrModel:()=>fo,RFDetrObjectDetectionOutput:()=>mo,RFDetrPreTrainedModel:()=>uo,RTDetrForObjectDetection:()=>io,RTDetrModel:()=>ro,RTDetrObjectDetectionOutput:()=>ao,RTDetrPreTrainedModel:()=>no,RTDetrV2ForObjectDetection:()=>co,RTDetrV2Model:()=>so,RTDetrV2ObjectDetectionOutput:()=>lo,RTDetrV2PreTrainedModel:()=>oo,ResNetForImageClassification:()=>Ao,ResNetModel:()=>ko,ResNetPreTrainedModel:()=>Oo,RoFormerForMaskedLM:()=>Fe,RoFormerForQuestionAnswering:()=>Re,RoFormerForSequenceClassification:()=>Ie,RoFormerForTokenClassification:()=>Le,RoFormerModel:()=>Pe,RoFormerPreTrainedModel:()=>Ne,RobertaForMaskedLM:()=>hn,RobertaForQuestionAnswering:()=>vn,RobertaForSequenceClassification:()=>gn,RobertaForTokenClassification:()=>_n,RobertaModel:()=>W,RobertaPreTrainedModel:()=>mn,Sam2ImageSegmentationOutput:()=>Ms,Sam2Model:()=>Ps,Sam2PreTrainedModel:()=>Ns,Sam3TrackerModel:()=>Is,SamImageSegmentationOutput:()=>js,SamModel:()=>As,SamPreTrainedModel:()=>ks,SapiensForDepthEstimation:()=>Go,SapiensForNormalEstimation:()=>Ko,SapiensForSemanticSegmentation:()=>Wo,SapiensPreTrainedModel:()=>Uo,SegformerForImageClassification:()=>sl,SegformerForSemanticSegmentation:()=>cl,SegformerModel:()=>ol,SegformerPreTrainedModel:()=>al,Seq2SeqLMOutput:()=>Ad,SequenceClassifierOutput:()=>Q,SiglipModel:()=>sr,SiglipPreTrainedModel:()=>or,SiglipTextModel:()=>cr,SiglipVisionModel:()=>X,SmolLM3ForCausalLM:()=>ei,SmolLM3Model:()=>$r,SmolLM3PreTrainedModel:()=>Qr,SmolVLMForConditionalGeneration:()=>er,SnacDecoderModel:()=>fu,SnacEncoderModel:()=>du,SnacModel:()=>uu,SnacPreTrainedModel:()=>lu,SpeechT5ForSpeechToText:()=>Oc,SpeechT5ForTextToSpeech:()=>kc,SpeechT5HifiGan:()=>Ac,SpeechT5Model:()=>Dc,SpeechT5PreTrainedModel:()=>Ec,SqueezeBertForMaskedLM:()=>Lt,SqueezeBertForQuestionAnswering:()=>zt,SqueezeBertForSequenceClassification:()=>Rt,SqueezeBertModel:()=>It,SqueezeBertPreTrainedModel:()=>Ft,StableLmForCausalLM:()=>dl,StableLmModel:()=>ul,StableLmPreTrainedModel:()=>ll,Starcoder2ForCausalLM:()=>Yc,Starcoder2Model:()=>Jc,Starcoder2PreTrainedModel:()=>qc,StyleTextToSpeech2Model:()=>Tc,StyleTextToSpeech2PreTrainedModel:()=>wc,SupertonicForConditionalGeneration:()=>Mc,SupertonicPreTrainedModel:()=>jc,Swin2SRForImageSuperResolution:()=>Lo,Swin2SRModel:()=>Io,Swin2SRPreTrainedModel:()=>Fo,SwinForImageClassification:()=>No,SwinForSemanticSegmentation:()=>Po,SwinModel:()=>Mo,SwinPreTrainedModel:()=>jo,T5ForConditionalGeneration:()=>qt,T5Model:()=>Kt,T5PreTrainedModel:()=>Gt,TableTransformerForObjectDetection:()=>bo,TableTransformerModel:()=>yo,TableTransformerObjectDetectionOutput:()=>xo,TableTransformerPreTrainedModel:()=>vo,TokenClassifierOutput:()=>Md,TrOCRForCausalLM:()=>Pc,TrOCRPreTrainedModel:()=>Nc,UltravoxModel:()=>Yl,UltravoxPreTrainedModel:()=>Jl,UniSpeechForCTC:()=>rc,UniSpeechForSequenceClassification:()=>ic,UniSpeechModel:()=>nc,UniSpeechPreTrainedModel:()=>tc,UniSpeechSatForAudioFrameClassification:()=>lc,UniSpeechSatForCTC:()=>sc,UniSpeechSatForSequenceClassification:()=>cc,UniSpeechSatModel:()=>oc,UniSpeechSatPreTrainedModel:()=>ac,VaultGemmaForCausalLM:()=>Ii,VaultGemmaModel:()=>Fi,VaultGemmaPreTrainedModel:()=>Pi,ViTForImageClassification:()=>ma,ViTMAEModel:()=>wa,ViTMAEPreTrainedModel:()=>Ca,ViTMSNForImageClassification:()=>Da,ViTMSNModel:()=>Ea,ViTMSNPreTrainedModel:()=>Ta,ViTModel:()=>pa,ViTPreTrainedModel:()=>fa,VisionEncoderDecoderModel:()=>Bn,VitMatteForImageMatting:()=>Pa,VitMattePreTrainedModel:()=>Na,VitPoseForPoseEstimation:()=>ya,VitPosePreTrainedModel:()=>va,VitsModel:()=>il,VitsModelOutput:()=>Rd,VitsPreTrainedModel:()=>rl,VoxtralForConditionalGeneration:()=>Xl,Wav2Vec2BertForCTC:()=>fc,Wav2Vec2BertForSequenceClassification:()=>pc,Wav2Vec2BertModel:()=>dc,Wav2Vec2BertPreTrainedModel:()=>uc,Wav2Vec2ForAudioFrameClassification:()=>qs,Wav2Vec2ForCTC:()=>Gs,Wav2Vec2ForSequenceClassification:()=>Ks,Wav2Vec2Model:()=>Ws,Wav2Vec2PreTrainedModel:()=>Us,WavLMForAudioFrameClassification:()=>Cc,WavLMForCTC:()=>bc,WavLMForSequenceClassification:()=>xc,WavLMForXVector:()=>Sc,WavLMModel:()=>yc,WavLMPreTrainedModel:()=>vc,WeSpeakerResNetModel:()=>ec,WeSpeakerResNetPreTrainedModel:()=>$s,WhisperForConditionalGeneration:()=>Fn,WhisperModel:()=>Pn,WhisperPreTrainedModel:()=>Nn,XLMForQuestionAnswering:()=>Cn,XLMForSequenceClassification:()=>xn,XLMForTokenClassification:()=>Sn,XLMModel:()=>yn,XLMPreTrainedModel:()=>G,XLMRobertaForMaskedLM:()=>En,XLMRobertaForQuestionAnswering:()=>kn,XLMRobertaForSequenceClassification:()=>Dn,XLMRobertaForTokenClassification:()=>On,XLMRobertaModel:()=>Tn,XLMRobertaPreTrainedModel:()=>wn,XLMWithLMHeadModel:()=>bn,XVectorOutput:()=>jd,YolosForObjectDetection:()=>Ds,YolosModel:()=>Es,YolosObjectDetectionOutput:()=>Os,YolosPreTrainedModel:()=>Ts});var r=n(`./src/configs.js`),i=n(`./src/backends/onnx.js`),a=n(`./src/utils/dtypes.js`),o=n(`./src/utils/generic.js`),s=n(`./src/utils/core.js`),c=n(`./src/utils/hub.js`),l=n(`./src/utils/constants.js`),u=n(`./src/generation/logits_process.js`),d=n(`./src/generation/configuration_utils.js`),f=n(`./src/utils/tensor.js`),p=n(`./src/utils/image.js`),m=n(`./src/utils/maths.js`),h=n(`./src/generation/stopping_criteria.js`),g=n(`./src/generation/logits_sampler.js`),_=n(`./src/env.js`),v=n(`./src/models/whisper/generation_whisper.js`),y=n(`./src/models/whisper/common_whisper.js`);let b={EncoderOnly:0,EncoderDecoder:1,Seq2Seq:2,Vision2Seq:3,DecoderOnly:4,MaskGeneration:5,ImageTextToText:6,Musicgen:7,MultiModality:8,Phi3V:9,AudioTextToText:10,AutoEncoder:11,ImageAudioTextToText:12,Supertonic:13},x=new Map,S=new Map,C=new Map;async function w(e,t,n){let o=n.config?.[`transformers.js_config`]??{},s=n.device??o.device;s&&typeof s!=`string`&&(s.hasOwnProperty(t)?s=s[t]:(console.warn(`device not specified for "${t}". Using the default device.`),s=null));let l=s??(_.apis.IS_NODE_ENV?`cpu`:`wasm`),u=(0,i.deviceToExecutionProviders)(l),d=o.device_config??{};d.hasOwnProperty(l)&&(o={...o,...d[l]});let f=n.dtype??o.dtype;if(typeof f!=`string`&&(f&&f.hasOwnProperty(t)?f=f[t]:(f=a.DEFAULT_DEVICE_DTYPE_MAPPING[l]??a.DATA_TYPES.fp32,console.warn(`dtype not specified for "${t}". Using the default dtype (${f}) for this device (${l}).`))),f===a.DATA_TYPES.auto){let e=o.dtype;typeof e!=`string`&&(e=e?.[t]),f=e&&e!==a.DATA_TYPES.auto&&a.DATA_TYPES.hasOwnProperty(e)?e:a.DEFAULT_DEVICE_DTYPE_MAPPING[l]??a.DATA_TYPES.fp32}let p=f;if(!a.DEFAULT_DTYPE_SUFFIX_MAPPING.hasOwnProperty(p))throw Error(`Invalid dtype: ${p}. Should be one of: ${Object.keys(a.DATA_TYPES).join(`, `)}`);if(p===a.DATA_TYPES.fp16&&l===`webgpu`&&!await(0,a.isWebGpuFp16Supported)())throw Error(`The device (${l}) does not support fp16.`);let m=o.kv_cache_dtype,h=m?typeof m==`string`?m:m[p]??`float32`:void 0;if(h&&![`float32`,`float16`].includes(h))throw Error(`Invalid kv_cache_dtype: ${h}. Should be one of: float32, float16`);let g={dtype:p,kv_cache_dtype:h,device:l},v=`${t}${a.DEFAULT_DTYPE_SUFFIX_MAPPING[p]}.onnx`,y=`${n.subfolder??``}/${v}`,b={...n.session_options};b.executionProviders??=u;let x=o.free_dimension_overrides;x?b.freeDimensionOverrides??=x:l.startsWith(`webnn`)&&!b.freeDimensionOverrides&&console.warn(`WebNN does not currently support dynamic shapes and requires 'free_dimension_overrides' to be set in config.json, preferably as a field within config["transformers.js_config"]["device_config"]["${l}"]. When 'free_dimension_overrides' is not set, you may experience significant performance degradation.`);let S=_.apis.IS_NODE_ENV&&_.env.useFSCache,C=(0,c.getModelFile)(e,y,!0,n,S),w=n.use_external_data_format??o.use_external_data_format,T=[];if(w){let r;r=typeof w==`object`?w.hasOwnProperty(v)?w[v]:w.hasOwnProperty(t)?w[t]:!1:w;let i=+r;if(i>c.MAX_EXTERNAL_DATA_CHUNKS)throw Error(`The number of external data chunks (${i}) exceeds the maximum allowed value (${c.MAX_EXTERNAL_DATA_CHUNKS}).`);for(let t=0;t<i;++t){let r=`${v}_data${t===0?``:`_`+t}`,i=`${n.subfolder??``}/${r}`;T.push(new Promise(async(t,a)=>{let o=await(0,c.getModelFile)(e,i,!0,n,S);t(o instanceof Uint8Array?{path:r,data:o}:r)}))}}else b.externalData!==void 0&&(T=b.externalData.map(async t=>{if(typeof t.data==`string`){let r=await(0,c.getModelFile)(e,t.data,!0,n);return{...t,data:r}}return t}));if(T.length>0){let e=await Promise.all(T);_.apis.IS_NODE_ENV||(b.externalData=e)}if(l===`webgpu`){let e=(0,r.getCacheShapes)(n.config,{prefix:`present`});if(Object.keys(e).length>0&&!(0,i.isONNXProxy)()){let t={};for(let n in e)t[n]=`gpu-buffer`;b.preferredOutputLocation=t}}return{buffer_or_path:await C,session_options:b,session_config:g}}async function T(e,t,n){return Object.fromEntries(await Promise.all(Object.keys(t).map(async r=>{let{buffer_or_path:a,session_options:o,session_config:s}=await w(e,t[r],n);return[r,await(0,i.createInferenceSession)(a,o,s)]})))}async function E(e,t,n){return Object.fromEntries(await Promise.all(Object.keys(t).map(async r=>[r,await(0,c.getModelJSON)(e,t[r],!1,n)])))}function D(e,t){let n=Object.create(null),r=[];for(let a of e.inputNames){let e=t[a];if(!(e instanceof f.Tensor)){r.push(a);continue}n[a]=(0,i.isONNXProxy)()?e.clone():e}if(r.length>0)throw Error(`An error occurred during model execution: "Missing the following inputs: ${r.join(`, `)}.`);let a=Object.keys(t).length,o=e.inputNames.length;if(a>o){let n=Object.keys(t).filter(t=>!e.inputNames.includes(t));console.warn(`WARNING: Too many inputs were provided (${a} > ${o}). The following inputs will be ignored: "${n.join(`, `)}".`)}return n}async function O(e,t){let n=D(e,t);try{let t=Object.fromEntries(Object.entries(n).map(([e,t])=>[e,t.ort_tensor]));return k(await(0,i.runInferenceSession)(e,t))}catch(e){let t=Object.fromEntries(Object.entries(n).map(([e,t])=>{let n={type:t.type,dims:t.dims,location:t.location};return n.location!==`gpu-buffer`&&(n.data=t.data),[e,n]}));throw console.error(`An error occurred during model execution: "${e}".`),console.error(`Inputs given to model:`,t),e}}function k(e){for(let t in e)(0,i.isONNXTensor)(e[t])?e[t]=new f.Tensor(e[t]):typeof e[t]==`object`&&k(e[t]);return e}function A(e){if(e instanceof f.Tensor)return e;if(e.length===0)throw Error(`items must be non-empty`);if(Array.isArray(e[0])){if(e.some(t=>t.length!==e[0].length))throw Error(`Unable to create tensor, you should probably activate truncation and/or padding with 'padding=True' and/or 'truncation=True' to have batched tensors with the same length.`);return new f.Tensor(`int64`,BigInt64Array.from(e.flat().map(e=>BigInt(e))),[e.length,e[0].length])}else return new f.Tensor(`int64`,BigInt64Array.from(e.map(e=>BigInt(e))),[1,e.length])}function ee(e){return new f.Tensor(`bool`,[e],[1])}async function te(e,t){let{encoder_outputs:n,input_ids:r,decoder_input_ids:i,...a}=t;return n||=(await ne(e,(0,s.pick)(t,e.sessions.model.inputNames))).last_hidden_state,a.input_ids=i,a.encoder_hidden_states=n,e.sessions.decoder_model_merged.inputNames.includes(`encoder_attention_mask`)&&(a.encoder_attention_mask=t.attention_mask),await re(e,a,!0)}async function ne(e,t){let n=e.sessions.model,r=(0,s.pick)(t,n.inputNames);if(n.inputNames.includes(`inputs_embeds`)&&!r.inputs_embeds){if(!t.input_ids)throw Error("Both `input_ids` and `inputs_embeds` are missing in the model inputs.");r.inputs_embeds=await e.encode_text({input_ids:t.input_ids})}if(n.inputNames.includes(`token_type_ids`)&&!r.token_type_ids){if(!r.input_ids)throw Error("Both `input_ids` and `token_type_ids` are missing in the model inputs.");r.token_type_ids=(0,f.zeros_like)(r.input_ids)}if(n.inputNames.includes(`pixel_mask`)&&!r.pixel_mask){if(!r.pixel_values)throw Error("Both `pixel_values` and `pixel_mask` are missing in the model inputs.");let e=r.pixel_values.dims;r.pixel_mask=(0,f.ones)([e[0],e[2],e[3]])}return await O(n,r)}async function j(e,t){let n=await e.encode(t);return await e.decode(n)}async function re(e,t,n=!1){let r=e.sessions[n?`decoder_model_merged`:`model`],{past_key_values:i,...a}=t;return r.inputNames.includes(`use_cache_branch`)&&(a.use_cache_branch=ee(!!i)),r.inputNames.includes(`position_ids`)&&a.attention_mask&&!a.position_ids&&(a.position_ids=le(a,i,+!![`paligemma`,`gemma3_text`,`gemma3`].includes(e.config.model_type))),e.addPastKeyValues(a,i),await O(r,(0,s.pick)(a,r.inputNames))}function ie({modality_token_id:e,inputs_embeds:t,modality_features:n,input_ids:r,attention_mask:i}){let a=r.tolist().map(t=>t.reduce((t,n,r)=>(n==e&&t.push(r),t),[])),o=a.reduce((e,t)=>e+t.length,0),s=n.dims[0];if(o!==s)throw Error(`Number of tokens and features do not match: tokens: ${o}, features ${s}`);let c=0;for(let e=0;e<a.length;++e){let r=a[e],i=t[e];for(let e=0;e<r.length;++e)i[r[e]].data.set(n[c++].data)}return{inputs_embeds:t,attention_mask:i}}function ae({image_token_id:e,inputs_embeds:t,image_features:n,input_ids:r,attention_mask:i}){return ie({modality_token_id:e,inputs_embeds:t,modality_features:n,input_ids:r,attention_mask:i})}function oe({audio_token_id:e,inputs_embeds:t,audio_features:n,input_ids:r,attention_mask:i}){return ie({modality_token_id:e,inputs_embeds:t,modality_features:n,input_ids:r,attention_mask:i})}async function se(e,{encode_function:t,merge_function:n,modality_input_name:r,modality_output_name:i,input_ids:a=null,attention_mask:o=null,position_ids:s=null,inputs_embeds:c=null,past_key_values:l=null,generation_config:u=null,logits_processor:d=null,...p}){let m=p[r];if(!c){if(c=await e.encode_text({input_ids:a,...p}),m&&a.dims[1]!==1){let e=await t({[r]:m,...p});({inputs_embeds:c,attention_mask:o}=n({[i]:e,inputs_embeds:c,input_ids:a,attention_mask:o}))}else if(l&&m&&a.dims[1]===1){let e=a.dims[1],t=Object.values(l)[0].dims.at(-2);o=(0,f.cat)([(0,f.ones)([a.dims[0],t]),o.slice(null,[o.dims[1]-e,o.dims[1]])],1)}}if(!s&&e.config.model_type===`qwen2_vl`){let{image_grid_thw:t,video_grid_thw:n}=p;[s]=e.get_rope_index(a,t,n,o)}return await re(e,{inputs_embeds:c,past_key_values:l,attention_mask:o,position_ids:s,generation_config:u,logits_processor:d},!0)}async function M(e,t){return await se(e,{...t,modality_input_name:`audio_values`,modality_output_name:`audio_features`,encode_function:e.encode_audio.bind(e),merge_function:e._merge_input_ids_with_audio_features.bind(e)})}async function N(e,t){return await se(e,{...t,modality_input_name:`pixel_values`,modality_output_name:`image_features`,encode_function:e.encode_image.bind(e),merge_function:e._merge_input_ids_with_image_features.bind(e)})}function ce(e,t=0){let[n,r]=e.dims,i=e.data,a=new BigInt64Array(i.length);for(let e=0;e<n;++e){let n=e*r,o=BigInt(t);for(let e=0;e<r;++e){let t=n+e;i[t]===0n?a[t]=BigInt(1):(a[t]=o,o+=i[t])}}return{data:a,dims:e.dims}}function le(e,t=null,n=0){let{input_ids:r,inputs_embeds:i,attention_mask:a}=e,{data:o,dims:s}=ce(a,n),c=new f.Tensor(`int64`,o,s);if(t){let e=-(r??i).dims.at(1);c=c.slice(null,[e,null])}return c}function ue(e,t,n,r){let i=n.past_key_values?Object.values(n.past_key_values)[0].dims.at(-2):0;if(!n.attention_mask){let e;for(let t of[`input_ids`,`inputs_embeds`,`position_ids`])if(n[t]){e=n[t].dims;break}if(!e)throw Error(`attention_mask is not provided, and unable to infer its shape from model inputs.`);n.attention_mask=(0,f.ones)([e[0],i+e[1]])}if(n.past_key_values){let{input_ids:e,attention_mask:t}=n;t&&t.dims[1]>e.dims[1]||i<e.dims[1]&&(n.input_ids=e.slice(null,[i,null]))}return n}function de(e,t,n,r){return n.past_key_values&&(t=t.map(e=>[e.at(-1)])),{...n,decoder_input_ids:A(t)}}function fe(e,...t){return e.config.is_encoder_decoder?de(e,...t):ue(e,...t)}function pe(e,t,n,r){let i=!!n.past_key_values;return r.guidance_scale!==null&&r.guidance_scale>1&&(i?n.input_ids=(0,f.cat)([n.input_ids,n.input_ids],0):(n.input_ids=(0,f.cat)([n.input_ids,(0,f.full_like)(n.input_ids,BigInt(r.pad_token_id))],0),n.attention_mask=(0,f.cat)([n.attention_mask,(0,f.full_like)(n.attention_mask,0n)],0))),(i||!n.pixel_values)&&(n.pixel_values=(0,f.full)([0,0,3,384,384],1)),i&&(n.images_seq_mask=new f.Tensor(`bool`,[,].fill(!0).fill(!1,0,1),[1,1]),n.images_emb_mask=new f.Tensor(`bool`,[].fill(!1),[1,1,0])),n}class P extends o.Callable{main_input_name=`input_ids`;forward_params=[`input_ids`,`attention_mask`];constructor(e,t,n){super(),this.config=e,this.sessions=t,this.configs=n;let r=C.get(this.constructor),i=x.get(r);switch(this.can_generate=!1,this._forward=null,this._prepare_inputs_for_generation=null,i){case b.DecoderOnly:this.can_generate=!0,this._forward=re,this._prepare_inputs_for_generation=ue;break;case b.Seq2Seq:case b.Vision2Seq:case b.Musicgen:this.can_generate=!0,this._forward=te,this._prepare_inputs_for_generation=de;break;case b.EncoderDecoder:this._forward=te;break;case b.ImageTextToText:this.can_generate=!0,this._forward=N,this._prepare_inputs_for_generation=fe;break;case b.AudioTextToText:this.can_generate=!0,this._forward=M,this._prepare_inputs_for_generation=fe;break;case b.Phi3V:case b.ImageAudioTextToText:this.can_generate=!0,this._prepare_inputs_for_generation=fe;break;case b.MultiModality:this.can_generate=!0,this._prepare_inputs_for_generation=pe;break;case b.AutoEncoder:this._forward=j;break;default:this._forward=ne;break}this.can_generate&&this.forward_params.push(`past_key_values`),this.custom_config=this.config[`transformers.js_config`]??{}}async dispose(){let e=[];for(let t of Object.values(this.sessions))t?.handler?.dispose&&e.push(t.handler.dispose());return await Promise.all(e)}static async from_pretrained(e,{progress_callback:t=null,config:n=null,cache_dir:i=null,local_files_only:a=!1,revision:o=`main`,model_file_name:s=null,subfolder:c=`onnx`,device:u=null,dtype:d=null,use_external_data_format:f=null,session_options:p={}}={}){let m={progress_callback:t,config:n,cache_dir:i,local_files_only:a,revision:o,model_file_name:s,subfolder:c,device:u,dtype:d,use_external_data_format:f,session_options:p},h=C.get(this),g=x.get(h);n=m.config=await r.AutoConfig.from_pretrained(e,m);let _;if(g===b.DecoderOnly)_=await Promise.all([T(e,{model:m.model_file_name??`model`},m),E(e,{generation_config:`generation_config.json`},m)]);else if(g===b.Seq2Seq||g===b.Vision2Seq)_=await Promise.all([T(e,{model:`encoder_model`,decoder_model_merged:`decoder_model_merged`},m),E(e,{generation_config:`generation_config.json`},m)]);else if(g===b.MaskGeneration)_=await Promise.all([T(e,{model:`vision_encoder`,prompt_encoder_mask_decoder:`prompt_encoder_mask_decoder`},m)]);else if(g===b.EncoderDecoder)_=await Promise.all([T(e,{model:`encoder_model`,decoder_model_merged:`decoder_model_merged`},m)]);else if(g===b.ImageTextToText){let t={embed_tokens:`embed_tokens`,vision_encoder:`vision_encoder`,decoder_model_merged:`decoder_model_merged`};n.is_encoder_decoder&&(t.model=`encoder_model`),_=await Promise.all([T(e,t,m),E(e,{generation_config:`generation_config.json`},m)])}else if(g===b.AudioTextToText)_=await Promise.all([T(e,{embed_tokens:`embed_tokens`,audio_encoder:`audio_encoder`,decoder_model_merged:`decoder_model_merged`},m),E(e,{generation_config:`generation_config.json`},m)]);else if(g===b.ImageAudioTextToText)_=await Promise.all([T(e,{embed_tokens:`embed_tokens`,audio_encoder:`audio_encoder`,vision_encoder:`vision_encoder`,decoder_model_merged:`decoder_model_merged`},m),E(e,{generation_config:`generation_config.json`},m)]);else if(g===b.Musicgen)_=await Promise.all([T(e,{model:`text_encoder`,decoder_model_merged:`decoder_model_merged`,encodec_decode:`encodec_decode`},m),E(e,{generation_config:`generation_config.json`},m)]);else if(g===b.MultiModality)_=await Promise.all([T(e,{prepare_inputs_embeds:`prepare_inputs_embeds`,model:`language_model`,lm_head:`lm_head`,gen_head:`gen_head`,gen_img_embeds:`gen_img_embeds`,image_decode:`image_decode`},m),E(e,{generation_config:`generation_config.json`},m)]);else if(g===b.Phi3V)_=await Promise.all([T(e,{prepare_inputs_embeds:`prepare_inputs_embeds`,model:`model`,vision_encoder:`vision_encoder`},m),E(e,{generation_config:`generation_config.json`},m)]);else if(g===b.AutoEncoder)_=await Promise.all([T(e,{encoder_model:`encoder_model`,decoder_model:`decoder_model`},m)]);else if(g===b.Supertonic)_=await Promise.all([T(e,{text_encoder:`text_encoder`,latent_denoiser:`latent_denoiser`,voice_decoder:`voice_decoder`},m)]);else{if(g!==b.EncoderOnly){let e=h??n?.model_type;e!==`custom`&&console.warn(`Model type for '${e}' not found, assuming encoder-only architecture. Please report this at ${l.GITHUB_ISSUE_URL}.`)}_=await Promise.all([T(e,{model:m.model_file_name??`model`},m)])}return new this(n,..._)}async _call(e){return await this.forward(e)}async forward(e){return await this._forward(this,e)}get generation_config(){return this.configs?.generation_config??null}_get_logits_processor(e,t,n=null){let r=new u.LogitsProcessorList;if(e.repetition_penalty!==null&&e.repetition_penalty!==1&&r.push(new u.RepetitionPenaltyLogitsProcessor(e.repetition_penalty)),e.no_repeat_ngram_size!==null&&e.no_repeat_ngram_size>0&&r.push(new u.NoRepeatNGramLogitsProcessor(e.no_repeat_ngram_size)),e.bad_words_ids!==null&&r.push(new u.NoBadWordsLogitsProcessor(e.bad_words_ids,e.eos_token_id)),e.min_length!==null&&e.eos_token_id!==null&&e.min_length>0&&r.push(new u.MinLengthLogitsProcessor(e.min_length,e.eos_token_id)),e.min_new_tokens!==null&&e.eos_token_id!==null&&e.min_new_tokens>0&&r.push(new u.MinNewTokensLengthLogitsProcessor(t,e.min_new_tokens,e.eos_token_id)),e.forced_bos_token_id!==null&&r.push(new u.ForcedBOSTokenLogitsProcessor(e.forced_bos_token_id)),e.forced_eos_token_id!==null&&r.push(new u.ForcedEOSTokenLogitsProcessor(e.max_length,e.forced_eos_token_id)),e.begin_suppress_tokens!==null){let n=t>1||e.forced_bos_token_id===null?t:t+1;r.push(new u.SuppressTokensAtBeginLogitsProcessor(e.begin_suppress_tokens,n))}return e.guidance_scale!==null&&e.guidance_scale>1&&r.push(new u.ClassifierFreeGuidanceLogitsProcessor(e.guidance_scale)),e.temperature===0&&e.do_sample&&(console.warn("`do_sample` changed to false because `temperature: 0` implies greedy sampling (always selecting the most likely token), which is incompatible with `do_sample: true`."),e.do_sample=!1),e.do_sample&&e.temperature!==null&&e.temperature!==1&&r.push(new u.TemperatureLogitsWarper(e.temperature)),n!==null&&r.extend(n),r}_prepare_generation_config(e,t,n=d.GenerationConfig){let r={...this.config};for(let e of[`decoder`,`generator`,`text_config`])e in r&&Object.assign(r,r[e]);let i=new n(r);return Object.assign(i,this.generation_config??{}),e&&Object.assign(i,e),t&&Object.assign(i,(0,s.pick)(t,Object.getOwnPropertyNames(i))),i}_get_stopping_criteria(e,t=null){let n=new h.StoppingCriteriaList;return e.max_length!==null&&n.push(new h.MaxLengthCriteria(e.max_length,this.config.max_position_embeddings??null)),e.eos_token_id!==null&&n.push(new h.EosTokenCriteria(e.eos_token_id)),t&&n.extend(t),n}_validate_model_class(){if(!this.can_generate){let e=[wu,Ou,Cu,vu],t=C.get(this.constructor),n=new Set,r=this.config.model_type;for(let t of e){let e=t.get(r);e&&n.add(e[0])}let i=`The current model class (${t}) is not compatible with \`.generate()\`, as it doesn't have a language model head.`;throw n.size>0&&(i+=` Please use the following class instead: ${[...n].join(`, `)}`),Error(i)}}prepare_inputs_for_generation(...e){return this._prepare_inputs_for_generation(this,...e)}_update_model_kwargs_for_generation({generated_input_ids:e,outputs:t,model_inputs:n,is_encoder_decoder:r}){return n.past_key_values=this.getPastKeyValues(t,n.past_key_values),n.input_ids=new f.Tensor(`int64`,e.flat(),[e.length,1]),r?`decoder_attention_mask`in n:n.attention_mask=(0,f.cat)([n.attention_mask,(0,f.ones)([n.attention_mask.dims[0],1])],1),n.position_ids=null,n}_prepare_model_inputs({inputs:e,bos_token_id:t,model_kwargs:n}){let r=(0,s.pick)(n,this.forward_params),i=this.main_input_name;if(i in r){if(e)throw Error("`inputs`: {inputs}` were passed alongside {input_name} which is not allowed. Make sure to either pass {inputs} or {input_name}=...")}else r[i]=e;return{inputs_tensor:r[i],model_inputs:r,model_input_name:i}}async _prepare_encoder_decoder_kwargs_for_generation({inputs_tensor:e,model_inputs:t,model_input_name:n,generation_config:r}){if(this.sessions.model.inputNames.includes(`inputs_embeds`)&&!t.inputs_embeds&&`_prepare_inputs_embeds`in this){let{input_ids:e,pixel_values:n,attention_mask:r,...i}=t,a=await this._prepare_inputs_embeds(t);t={...i,...(0,s.pick)(a,[`inputs_embeds`,`attention_mask`])}}let{last_hidden_state:i}=await ne(this,t);if(r.guidance_scale!==null&&r.guidance_scale>1)i=(0,f.cat)([i,(0,f.full_like)(i,0)],0),`attention_mask`in t&&(t.attention_mask=(0,f.cat)([t.attention_mask,(0,f.zeros_like)(t.attention_mask)],0));else if(t.decoder_input_ids){let e=A(t.decoder_input_ids).dims[0];if(e!==i.dims[0]){if(i.dims[0]!==1)throw Error(`The encoder outputs have a different batch size (${i.dims[0]}) than the decoder inputs (${e}).`);i=(0,f.cat)(Array.from({length:e},()=>i),0)}}return t.encoder_outputs=i,t}_prepare_decoder_input_ids_for_generation({batch_size:e,model_input_name:t,model_kwargs:n,decoder_start_token_id:r,bos_token_id:i,generation_config:a}){let{decoder_input_ids:o,...s}=n;if(!(o instanceof f.Tensor)){if(o)Array.isArray(o[0])||(o=Array.from({length:e},()=>o));else if(r??=i,this.config.model_type===`musicgen`)o=Array.from({length:e*this.config.decoder.num_codebooks},()=>[r]);else if(Array.isArray(r)){if(r.length!==e)throw Error(`\`decoder_start_token_id\` expcted to have length ${e} but got ${r.length}`);o=r}else o=Array.from({length:e},()=>[r]);o=A(o)}return n.decoder_attention_mask=(0,f.ones_like)(o),{input_ids:o,model_inputs:s}}async generate({inputs:e=null,generation_config:t=null,logits_processor:n=null,stopping_criteria:r=null,streamer:i=null,...a}){this._validate_model_class(),t=this._prepare_generation_config(t,a);let{inputs_tensor:o,model_inputs:s,model_input_name:c}=this._prepare_model_inputs({inputs:e,model_kwargs:a}),l=this.config.is_encoder_decoder;l&&(`encoder_outputs`in s||(s=await this._prepare_encoder_decoder_kwargs_for_generation({inputs_tensor:o,model_inputs:s,model_input_name:c,generation_config:t})));let u;l?{input_ids:u,model_inputs:s}=this._prepare_decoder_input_ids_for_generation({batch_size:s[c].dims.at(0),model_input_name:c,model_kwargs:s,decoder_start_token_id:t.decoder_start_token_id,bos_token_id:t.bos_token_id,generation_config:t}):u=s[c];let d=u.dims.at(-1);t.max_new_tokens!==null&&(t.max_length=d+t.max_new_tokens);let p=this._get_logits_processor(t,d,n),m=this._get_stopping_criteria(t,r),h=s[c].dims.at(0),_=g.LogitsSampler.getSampler(t),v=Array(h).fill(0),y=u.tolist();i&&i.put(y);let b,x={};for(;;){if(s=this.prepare_inputs_for_generation(y,s,t),b=await this.forward(s),t.output_attentions&&t.return_dict_in_generate){let e=this.getAttentions(b);for(let t in e)t in x||(x[t]=[]),x[t].push(e[t])}let e=p(y,b.logits.slice(null,-1,null)),n=[];for(let t=0;t<e.dims.at(0);++t){let r=e[t],i=await _(r);for(let[e,r]of i){let i=BigInt(e);v[t]+=r,y[t].push(i),n.push([i]);break}}if(i&&i.put(n),m(y).every(e=>e))break;s=this._update_model_kwargs_for_generation({generated_input_ids:n,outputs:b,model_inputs:s,is_encoder_decoder:l})}i&&i.end();let S=this.getPastKeyValues(b,s.past_key_values,!0),C=new f.Tensor(`int64`,y.flat(),[y.length,y[0].length]);if(t.return_dict_in_generate)return{sequences:C,past_key_values:S,...x};for(let e of Object.values(b))e.location===`gpu-buffer`&&e.dispose();return C}getPastKeyValues(e,t,n=!1){let r=Object.create(null);for(let i in e)if(i.startsWith(`present`)){let a=i.replace(`present_conv`,`past_conv`).replace(`present`,`past_key_values`),o=i.includes(`encoder`);if(o&&t?r[a]=t[a]:r[a]=e[i],t&&(!o||n)){let e=t[a];e.location===`gpu-buffer`&&e.dispose()}}return r}getAttentions(e){let t={};for(let n of[`cross_attentions`,`encoder_attentions`,`decoder_attentions`])for(let r in e)r.startsWith(n)&&(n in t||(t[n]=[]),t[n].push(e[r]));return t}addPastKeyValues(e,t){if(t)Object.assign(e,t);else{let t=this.sessions.decoder_model_merged??this.sessions.model,n=(e[this.main_input_name]??e.attention_mask)?.dims?.[0]??1,i=t?.config?.kv_cache_dtype??`float32`,a=i===`float16`?f.DataTypeMap.float16:f.DataTypeMap.float32,o=(0,r.getCacheShapes)(this.config,{batch_size:n});for(let t in o){let n=o[t].reduce((e,t)=>e*t,1);e[t]=new f.Tensor(i,new a(n),o[t])}}}async encode_image({pixel_values:e}){return(await O(this.sessions.vision_encoder,{pixel_values:e})).image_features}async encode_text({input_ids:e}){return(await O(this.sessions.embed_tokens,{input_ids:e})).inputs_embeds}async encode_audio({audio_values:e}){return(await O(this.sessions.audio_encoder,{audio_values:e})).audio_features}}class me{}class he extends me{constructor({last_hidden_state:e,hidden_states:t=null,attentions:n=null}){super(),this.last_hidden_state=e,this.hidden_states=t,this.attentions=n}}class ge extends P{}class _e extends ge{}class ve extends ge{async _call(e){return new Nd(await super._call(e))}}class F extends ge{async _call(e){return new Q(await super._call(e))}}class ye extends ge{async _call(e){return new Md(await super._call(e))}}class I extends ge{async _call(e){return new Pd(await super._call(e))}}class L extends P{}class be extends L{}class xe extends L{async _call(e){return new Nd(await super._call(e))}}class Se extends L{async _call(e){return new Q(await super._call(e))}}class R extends L{async _call(e){return new Md(await super._call(e))}}class Ce extends L{async _call(e){return new Pd(await super._call(e))}}class z extends P{}class we extends z{}class Te extends z{async _call(e){return new Nd(await super._call(e))}}class Ee extends z{async _call(e){return new Q(await super._call(e))}}class De extends z{async _call(e){return new Md(await super._call(e))}}class Oe extends P{}class ke extends Oe{}class Ae extends Oe{}class je extends P{}class Me extends je{}class Ne extends P{}class Pe extends Ne{}class Fe extends Ne{async _call(e){return new Nd(await super._call(e))}}class Ie extends Ne{async _call(e){return new Q(await super._call(e))}}class Le extends Ne{async _call(e){return new Md(await super._call(e))}}class Re extends Ne{async _call(e){return new Pd(await super._call(e))}}class ze extends P{}class Be extends ze{}class B extends ze{async _call(e){return new Nd(await super._call(e))}}class Ve extends ze{async _call(e){return new Q(await super._call(e))}}class He extends ze{async _call(e){return new Md(await super._call(e))}}class Ue extends ze{async _call(e){return new Pd(await super._call(e))}}class We extends P{}class V extends We{}class Ge extends We{async _call(e){return new Nd(await super._call(e))}}class Ke extends We{async _call(e){return new Q(await super._call(e))}}class qe extends We{async _call(e){return new Md(await super._call(e))}}class Je extends We{async _call(e){return new Pd(await super._call(e))}}class Ye extends P{}class Xe extends Ye{}class Ze extends Ye{async _call(e){return new Nd(await super._call(e))}}class Qe extends Ye{async _call(e){return new Q(await super._call(e))}}class $e extends Ye{async _call(e){return new Md(await super._call(e))}}class et extends Ye{async _call(e){return new Pd(await super._call(e))}}class tt extends P{}class nt extends tt{}class rt extends tt{async _call(e){return new Nd(await super._call(e))}}class it extends tt{async _call(e){return new Q(await super._call(e))}}class at extends tt{async _call(e){return new Md(await super._call(e))}}class ot extends tt{async _call(e){return new Pd(await super._call(e))}}class st extends P{}class ct extends st{}class lt extends st{async _call(e){return new Nd(await super._call(e))}}class ut extends st{async _call(e){return new Q(await super._call(e))}}class dt extends st{async _call(e){return new Md(await super._call(e))}}class ft extends st{async _call(e){return new Pd(await super._call(e))}}class pt extends P{}class mt extends pt{}class ht extends pt{async _call(e){return new Q(await super._call(e))}}class gt extends pt{async _call(e){return new Md(await super._call(e))}}class _t extends pt{async _call(e){return new Pd(await super._call(e))}}class vt extends pt{async _call(e){return new Nd(await super._call(e))}}class yt extends P{}class bt extends yt{}class xt extends yt{async _call(e){return new Nd(await super._call(e))}}class St extends yt{async _call(e){return new Q(await super._call(e))}}class Ct extends yt{async _call(e){return new Md(await super._call(e))}}class wt extends P{}class Tt extends wt{}class Et extends wt{async _call(e){return new Nd(await super._call(e))}}class Dt extends wt{async _call(e){return new Q(await super._call(e))}}class Ot extends wt{async _call(e){return new Pd(await super._call(e))}}class kt extends P{}class At extends kt{}class jt extends kt{async _call(e){return new Nd(await super._call(e))}}class Mt extends kt{async _call(e){return new Q(await super._call(e))}}class Nt extends kt{async _call(e){return new Md(await super._call(e))}}class Pt extends kt{async _call(e){return new Pd(await super._call(e))}}class Ft extends P{}class It extends Ft{}class Lt extends Ft{async _call(e){return new Nd(await super._call(e))}}class Rt extends Ft{async _call(e){return new Q(await super._call(e))}}class zt extends Ft{async _call(e){return new Pd(await super._call(e))}}class Bt extends P{}class Vt extends Bt{}class Ht extends Bt{async _call(e){return new Q(await super._call(e))}}class Ut extends Bt{async _call(e){return new Pd(await super._call(e))}}class Wt extends Bt{async _call(e){return new Nd(await super._call(e))}}class Gt extends P{forward_params=[`input_ids`,`attention_mask`,`encoder_outputs`,`decoder_input_ids`,`decoder_attention_mask`,`past_key_values`]}class Kt extends Gt{}class qt extends Gt{}class Jt extends P{}class Yt extends Jt{}class Xt extends Jt{}class Zt extends P{}class Qt extends Zt{}class $t extends Zt{}class en extends P{}class tn extends en{}class nn extends en{}class H extends en{async _call(e){return new Q(await super._call(e))}}class rn extends P{}class an extends rn{}class on extends rn{}class sn extends rn{async _call(e){return new Q(await super._call(e))}}class cn extends rn{}class ln extends P{}class un extends ln{}class dn extends ln{}class U extends P{}class fn extends U{}class pn extends U{}class mn extends P{}class W extends mn{}class hn extends mn{async _call(e){return new Nd(await super._call(e))}}class gn extends mn{async _call(e){return new Q(await super._call(e))}}class _n extends mn{async _call(e){return new Md(await super._call(e))}}class vn extends mn{async _call(e){return new Pd(await super._call(e))}}class G extends P{}class yn extends G{}class bn extends G{async _call(e){return new Nd(await super._call(e))}}class xn extends G{async _call(e){return new Q(await super._call(e))}}class Sn extends G{async _call(e){return new Md(await super._call(e))}}class Cn extends G{async _call(e){return new Pd(await super._call(e))}}class wn extends P{}class Tn extends wn{}class En extends wn{async _call(e){return new Nd(await super._call(e))}}class Dn extends wn{async _call(e){return new Q(await super._call(e))}}class On extends wn{async _call(e){return new Md(await super._call(e))}}class kn extends wn{async _call(e){return new Pd(await super._call(e))}}class An extends P{}class jn extends An{}class Mn extends An{}class Nn extends P{requires_attention_mask=!1;main_input_name=`input_features`;forward_params=[`input_features`,`attention_mask`,`decoder_input_ids`,`decoder_attention_mask`,`past_key_values`]}class Pn extends Nn{}class Fn extends Nn{_prepare_generation_config(e,t){return super._prepare_generation_config(e,t,v.WhisperGenerationConfig)}_retrieve_init_tokens(e){let t=[e.decoder_start_token_id],n=e.language,r=e.task;if(e.is_multilingual){n||=(console.warn(`No language specified - defaulting to English (en).`),`en`);let i=`<|${(0,y.whisper_language_to_code)(n)}|>`;t.push(e.lang_to_id[i]),t.push(e.task_to_id[r??`transcribe`])}else if(n||r)throw Error("Cannot specify `task` or `language` for an English-only model. If the model is intended to be multilingual, pass `is_multilingual=true` to generate, or update the generation config.");return!e.return_timestamps&&e.no_timestamps_token_id&&t.at(-1)!==e.no_timestamps_token_id?t.push(e.no_timestamps_token_id):e.return_timestamps&&t.at(-1)===e.no_timestamps_token_id&&(console.warn("<|notimestamps|> prompt token is removed from generation_config since `return_timestamps` is set to `true`."),t.pop()),t.filter(e=>e!=null)}async generate({inputs:e=null,generation_config:t=null,logits_processor:n=null,stopping_criteria:r=null,...i}){t=this._prepare_generation_config(t,i);let a=i.decoder_input_ids??this._retrieve_init_tokens(t);if(t.return_timestamps&&(n??=new u.LogitsProcessorList,n.push(new u.WhisperTimeStampLogitsProcessor(t,a))),t.begin_suppress_tokens&&(n??=new u.LogitsProcessorList,n.push(new u.SuppressTokensAtBeginLogitsProcessor(t.begin_suppress_tokens,a.length))),t.return_token_timestamps){if(!t.alignment_heads)throw Error("Model generation config has no `alignment_heads`, token-level timestamps not available. See https://gist.github.com/hollance/42e32852f24243b748ae6bc1f985b13a on how to add this property to the generation config.");t.task===`translate`&&console.warn(`Token-level timestamps may not be reliable for task 'translate'.`),t.output_attentions=!0,t.return_dict_in_generate=!0}let o=await super.generate({inputs:e,generation_config:t,logits_processor:n,decoder_input_ids:a,...i});return t.return_token_timestamps&&(o.token_timestamps=this._extract_token_timestamps(o,t.alignment_heads,t.num_frames)),o}_extract_token_timestamps(e,t,n=null,r=.02){if(!e.cross_attentions)throw Error("Model outputs must contain cross attentions to extract timestamps. This is most likely because the model was not exported with `output_attentions=True`.");n??console.warn("`num_frames` has not been set, meaning the entire audio will be analyzed. This may lead to inaccurate token-level timestamps for short audios (< 30 seconds).");let i=this.config.median_filter_width;i===void 0&&(console.warn("Model config has no `median_filter_width`, using default value of 7."),i=7);let a=e.cross_attentions,o=Array.from({length:this.config.decoder_layers},(e,t)=>(0,f.cat)(a.map(e=>e[t]),2)),c=(0,f.stack)(t.map(([e,t])=>{if(e>=o.length)throw Error(`Layer index ${e} is out of bounds for cross attentions (length ${o.length}).`);return n?o[e].slice(null,t,null,[0,n]):o[e].slice(null,t)})).transpose(1,0,2,3),[l,u]=(0,f.std_mean)(c,-2,0,!0),d=c.clone();for(let e=0;e<d.dims[0];++e){let t=d[e];for(let n=0;n<t.dims[0];++n){let r=t[n],a=l[e][n][0].data,o=u[e][n][0].data;for(let e=0;e<r.dims[0];++e){let t=r[e].data;for(let e=0;e<t.length;++e)t[e]=(t[e]-o[e])/a[e];t.set((0,m.medianFilter)(t,i))}}}let p=[(0,f.mean)(d,1)],h=e.sequences.dims,g=new f.Tensor(`float32`,new Float32Array(h[0]*h[1]),h);for(let e=0;e<h[0];++e){let t=p[e].neg().squeeze_(0),[n,i]=(0,m.dynamic_time_warping)(t.tolist()),a=Array.from({length:n.length-1},(e,t)=>n[t+1]-n[t]),o=(0,s.mergeArrays)([1],a).map(e=>!!e),c=[];for(let e=0;e<o.length;++e)o[e]&&c.push(i[e]*r);g[e].data.set(c,1)}return g}}class In extends Fn{}class Ln extends P{requires_attention_mask=!1;main_input_name=`input_values`;forward_params=[`input_values`,`decoder_input_ids`,`past_key_values`]}class Rn extends Ln{}class zn extends Ln{}class Bn extends P{main_input_name=`pixel_values`;forward_params=[`pixel_values`,`decoder_input_ids`,`encoder_hidden_states`,`past_key_values`]}class Vn extends P{forward_params=[`input_ids`,`attention_mask`,`pixel_values`,`position_ids`,`past_key_values`]}class Hn extends Vn{_merge_input_ids_with_image_features(e){let t=e.image_features.dims.at(-1),n=e.image_features.view(-1,t);return ae({image_token_id:this.config.image_token_index,...e,image_features:n})}}class Un extends Hn{}class Wn extends Hn{}class Gn extends P{forward_params=[`input_ids`,`inputs_embeds`,`attention_mask`,`pixel_values`,`encoder_outputs`,`decoder_input_ids`,`decoder_inputs_embeds`,`decoder_attention_mask`,`past_key_values`];main_input_name=`inputs_embeds`}class Kn extends Gn{_merge_input_ids_with_image_features({inputs_embeds:e,image_features:t,input_ids:n,attention_mask:r}){return{inputs_embeds:(0,f.cat)([t,e],1),attention_mask:(0,f.cat)([(0,f.ones)(t.dims.slice(0,2)),r],1)}}async _prepare_inputs_embeds({input_ids:e,pixel_values:t,inputs_embeds:n,attention_mask:r}){if(!e&&!t)throw Error("Either `input_ids` or `pixel_values` should be provided.");let i,a;return e&&(i=await this.encode_text({input_ids:e})),t&&(a=await this.encode_image({pixel_values:t})),i&&a?{inputs_embeds:n,attention_mask:r}=this._merge_input_ids_with_image_features({inputs_embeds:i,image_features:a,input_ids:e,attention_mask:r}):n=i||a,{inputs_embeds:n,attention_mask:r}}async forward({input_ids:e,pixel_values:t,attention_mask:n,decoder_input_ids:r,decoder_attention_mask:i,encoder_outputs:a,past_key_values:o,inputs_embeds:s,decoder_inputs_embeds:c}){if(s||({inputs_embeds:s,attention_mask:n}=await this._prepare_inputs_embeds({input_ids:e,pixel_values:t,inputs_embeds:s,attention_mask:n})),!a){let{last_hidden_state:e}=await ne(this,{inputs_embeds:s,attention_mask:n});a=e}if(!c){if(!r)throw Error("Either `decoder_input_ids` or `decoder_inputs_embeds` should be provided.");c=await this.encode_text({input_ids:r})}return await re(this,{inputs_embeds:c,attention_mask:i,encoder_attention_mask:n,encoder_hidden_states:a,past_key_values:o},!0)}}class qn extends P{forward_params=[`input_ids`,`attention_mask`,`pixel_values`,`position_ids`,`past_key_values`]}class Jn extends qn{_merge_input_ids_with_image_features(e){let t=e.image_features.dims.at(-1),n=e.image_features.view(-1,t);return ae({image_token_id:this.config.image_token_index,...e,image_features:n})}}class Yn extends Vn{_merge_input_ids_with_image_features(e){let t=e.image_features.dims.at(-1),n=e.image_features.view(-1,t);return ae({image_token_id:this.config.image_token_index,...e,image_features:n})}}class Xn extends Yn{}class Zn extends P{forward_params=[`input_ids`,`attention_mask`,`inputs_embeds`,`per_layer_inputs`,`position_ids`,`pixel_values`,`input_features`,`input_features_mask`,`past_key_values`]}class Qn extends Zn{async forward({input_ids:e=null,attention_mask:t=null,pixel_values:n=null,input_features:r=null,input_features_mask:i=null,position_ids:a=null,inputs_embeds:o=null,per_layer_inputs:s=null,past_key_values:c=null,generation_config:l=null,logits_processor:u=null,...d}){if((!o||!s)&&({inputs_embeds:o,per_layer_inputs:s}=await O(this.sessions.embed_tokens,{input_ids:e}),e.dims[1]!==1)){if(n){let{image_features:r}=await O(this.sessions.vision_encoder,{pixel_values:n});({inputs_embeds:o,attention_mask:t}=this._merge_input_ids_with_image_features({image_features:r,inputs_embeds:o,input_ids:e,attention_mask:t}))}if(r){let{audio_features:n}=await O(this.sessions.audio_encoder,{input_features:r,input_features_mask:i});({inputs_embeds:o,attention_mask:t}=this._merge_input_ids_with_audio_features({audio_features:n,inputs_embeds:o,input_ids:e,attention_mask:t}))}}return await re(this,{inputs_embeds:o,per_layer_inputs:s,past_key_values:c,attention_mask:t,position_ids:a,generation_config:l,logits_processor:u},!0)}_merge_input_ids_with_image_features(e){let t=e.image_features.dims.at(-1),n=e.image_features.view(-1,t);return ae({image_token_id:this.config.image_token_id,...e,image_features:n})}_merge_input_ids_with_audio_features(e){let t=e.audio_features.dims.at(-1),n=e.audio_features.view(-1,t);return oe({audio_token_id:this.config.audio_token_id,...e,audio_features:n})}}class $n extends P{forward_params=[`input_ids`,`attention_mask`,`pixel_values`,`pixel_attention_mask`,`position_ids`,`past_key_values`]}class K extends $n{async encode_image({pixel_values:e,pixel_attention_mask:t}){return(await O(this.sessions.vision_encoder,{pixel_values:e,pixel_attention_mask:t})).image_features}_merge_input_ids_with_image_features(e){let t=e.image_features.dims.at(-1),n=e.image_features.view(-1,t);return ae({image_token_id:this.config.image_token_id,...e,image_features:n})}}class er extends K{}class tr extends P{forward_params=[`input_ids`,`inputs_embeds`,`attention_mask`,`position_ids`,`pixel_values`,`image_sizes`,`past_key_values`]}class nr extends tr{async forward({input_ids:e=null,attention_mask:t=null,pixel_values:n=null,image_sizes:r=null,position_ids:i=null,inputs_embeds:a=null,past_key_values:o=null,generation_config:s=null,logits_processor:c=null,...l}){if(!a){let t;if(n&&e.dims[1]!==1){if(!r)throw Error("`image_sizes` must be provided when `pixel_values` is provided.");({image_features:t}=await O(this.sessions.vision_encoder,{pixel_values:n,image_sizes:r}))}else{let e=this.config.normalized_config.hidden_size;t=new f.Tensor(`float32`,[],[0,e])}({inputs_embeds:a}=await O(this.sessions.prepare_inputs_embeds,{input_ids:e,image_features:t}))}return await re(this,{inputs_embeds:a,past_key_values:o,attention_mask:t,position_ids:i,generation_config:s,logits_processor:c},!1)}}class rr extends P{}class q extends rr{}class ir extends rr{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??`text_model`})}}class J extends rr{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??`text_model`})}}class Y extends rr{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??`vision_model`})}}class ar extends rr{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??`vision_model`})}}class or extends P{}class sr extends or{}class cr extends or{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??`text_model`})}}class X extends rr{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??`vision_model`})}}class lr extends P{}class ur extends lr{}class Z extends P{}class dr extends Z{async forward(e){let t=!e.input_ids,n=!e.pixel_values;if(t&&n)throw Error("Either `input_ids` or `pixel_values` should be provided.");if(t&&(e.input_ids=(0,f.ones)([e.pixel_values.dims[0],1])),n){let{image_size:t}=this.config.vision_config;e.pixel_values=(0,f.full)([0,3,t,t],0)}let{text_embeddings:r,image_embeddings:i,l2norm_text_embeddings:a,l2norm_image_embeddings:o}=await super.forward(e),s={};return t||(s.text_embeddings=r,s.l2norm_text_embeddings=a),n||(s.image_embeddings=i,s.l2norm_image_embeddings=o),s}}class fr extends Z{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??`text_model`})}}class pr extends Z{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??`vision_model`})}}class mr extends P{}class hr extends mr{}class gr extends mr{}class _r extends P{}class vr extends _r{}class yr extends _r{}class br extends P{}class xr extends br{}class Sr extends br{}class Cr extends P{}class wr extends Cr{}class Tr extends Cr{}class Er extends P{}class Dr extends Er{}class Or extends Er{}class kr extends P{}class Ar extends kr{}class jr extends kr{}class Mr extends P{}class Nr extends Mr{}class Pr extends Mr{}class Fr extends P{}class Ir extends Fr{}class Lr extends Fr{}class Rr extends P{}class zr extends Rr{}class Br extends Rr{}class Vr extends P{}class Hr extends Vr{}class Ur extends P{}class Wr extends Ur{}class Gr extends Ur{}class Kr extends P{}class qr extends Kr{}class Jr extends Kr{}class Yr extends P{}class Xr extends Yr{}class Zr extends Yr{}class Qr extends P{}class $r extends Qr{}class ei extends Qr{}class ti extends P{}class ni extends ti{}class ri extends ti{}class ii extends P{}class ai extends ii{}class oi extends ii{}class si extends P{}class ci extends si{}class li extends si{}class ui extends P{}class di extends ui{}class fi extends ui{}class pi extends P{}class mi extends pi{}class hi extends pi{}class gi extends P{}class _i extends gi{}class vi extends gi{}class yi extends P{}class bi extends yi{}class xi extends yi{}class Si extends P{}class Ci extends Si{}class wi extends Si{}class Ti extends P{}class Ei extends Ti{}class Di extends Ti{}class Oi extends P{}class ki extends Oi{}class Ai extends Oi{}class ji extends P{}class Mi extends ji{}class Ni extends ji{}class Pi extends P{}class Fi extends Pi{}class Ii extends Pi{}class Li extends P{}class Ri extends Li{}class zi extends Li{}class Bi extends P{}class Vi extends Bi{}class Hi extends Bi{}class Ui extends P{}class Wi extends Ui{}class Gi extends Ui{}class Ki extends P{}class qi extends Ki{}class Ji extends Ki{}class Yi extends P{forward_params=[`input_ids`,`attention_mask`,`position_ids`,`past_key_values`,`pixel_values`,`image_grid_thw`]}class Xi extends Yi{get_rope_index(e,t,n,r){let{vision_config:i,image_token_id:a,video_token_id:o,vision_start_token_id:s}=this.config,c=i.spatial_merge_size??2,l=[];if(t||n){let i=e.tolist();r||=(0,f.ones_like)(e);let u=r.tolist(),d=Array.from({length:3},t=>Array.from({length:e.dims[0]},t=>Array.from({length:e.dims[1]},e=>1))),p=t?t.tolist():[],h=n?n.tolist():[],g=0,_=0;for(let e=0;e<i.length;++e){let t=i[e].filter((t,n)=>u[e][n]==1),n=t.reduce((e,t,n)=>(t==s&&e.push(n),e),[]).map(e=>t[e+1]),r=n.filter(e=>e==a).length,f=n.filter(e=>e==o).length,v=[],y=0,b=r,x=f;for(let e=0;e<n.length;++e){let e=t.findIndex((e,t)=>t>y&&e==a),n=t.findIndex((e,t)=>t>y&&e==o),r=b>0&&e!==-1?e:t.length+1,i=x>0&&n!==-1?n:t.length+1,s,l,u,d;r<i?([l,u,d]=p[g],++g,--b,s=r):([l,u,d]=h[_],++_,--x,s=i);let[f,S,C]=[Number(l),Math.floor(Number(u)/c),Math.floor(Number(d)/c)],w=s-y,T=v.length>0?(0,m.max)(v.at(-1))[0]+1:0;v.push(Array.from({length:3*w},(e,t)=>T+t%w));let E=w+T,D=f*S*C,O=Array.from({length:D},(e,t)=>E+Math.floor(t/(S*C))),k=Array.from({length:D},(e,t)=>E+Math.floor(t/C)%S),A=Array.from({length:D},(e,t)=>E+t%C);v.push([O,k,A].flat()),y=s+D}if(y<t.length){let e=v.length>0?(0,m.max)(v.at(-1))[0]+1:0,n=t.length-y;v.push(Array.from({length:3*n},(t,r)=>e+r%n))}let S=v.reduce((e,t)=>e+t.length,0),C=Array(S),w=0;for(let e=0;e<3;++e)for(let t=0;t<v.length;++t){let n=v[t],r=n.length/3;for(let t=e*r;t<(e+1)*r;++t)C[w++]=n[t]}let T=0,E=u[e];for(let t=0;t<E.length;++t)if(E[t]==1){for(let n=0;n<3;++n)d[n][e][t]=C[n*S/3+T];++T}let D=(0,m.max)(C)[0];l.push(D+1-i[e].length)}return[new f.Tensor(`int64`,d.flat(1/0),[3,e.dims[0],e.dims[1]]),new f.Tensor(`int64`,l,[l.length,1])]}else if(r){let{data:e,dims:t}=ce(r),n=BigInt64Array.from({length:3*e.length},(t,n)=>e[n%e.length]),i=Array.from({length:t[0]},(n,r)=>(0,m.max)(e.subarray(t[1]*r,t[1]*(r+1)))[0]+1n+BigInt(t[1]));return[new f.Tensor(`int64`,n,[3,...t]),new f.Tensor(`int64`,i,[i.length,1])]}else{let[t,n]=e.dims,r=BigInt64Array.from({length:3*t*n},(e,r)=>BigInt(Math.floor(r%n/t)));return[new f.Tensor(`int64`,r,[3,...e.dims]),(0,f.zeros)([t,1])]}}async encode_image({pixel_values:e,image_grid_thw:t}){return(await O(this.sessions.vision_encoder,{pixel_values:e,grid_thw:t})).image_features}_merge_input_ids_with_image_features(e){return ae({image_token_id:this.config.image_token_id,...e})}prepare_inputs_for_generation(e,t,n){if(t.attention_mask&&!t.position_ids)if(!t.past_key_values)[t.position_ids,t.rope_deltas]=this.get_rope_index(t.input_ids,t.image_grid_thw,t.video_grid_thw,t.attention_mask);else{t.pixel_values=null;let e=BigInt(Object.values(t.past_key_values)[0].dims.at(-2)),n=t.rope_deltas.map(t=>e+t);t.position_ids=(0,f.stack)([n,n,n],0)}return t}}class Zi extends P{}class Qi extends Zi{}class $i extends Zi{}class ea extends P{}class ta extends ea{}class na extends ea{}class ra extends P{}class ia extends ra{}class aa extends ra{}class oa extends P{}class sa extends oa{}class ca extends oa{}class la extends P{}class ua extends la{}class da extends la{}class fa extends P{}class pa extends fa{}class ma extends fa{async _call(e){return new Q(await super._call(e))}}class ha extends P{}class ga extends ha{}class _a extends ha{async _call(e){return new Q(await super._call(e))}}class va extends P{}class ya extends va{}class ba extends P{}class xa extends ba{}class Sa extends ba{async _call(e){return new Q(await super._call(e))}}class Ca extends P{}class wa extends Ca{}class Ta extends P{}class Ea extends Ta{}class Da extends Ta{async _call(e){return new Q(await super._call(e))}}class Oa extends P{}class ka extends Oa{}class Aa extends P{}class ja extends Aa{}class Ma extends Aa{async _call(e){return new Q(await super._call(e))}}class Na extends P{}class Pa extends Na{async _call(e){return new Ld(await super._call(e))}}class Fa extends P{}class Ia extends Fa{}class La extends Fa{async _call(e){return new Q(await super._call(e))}}class Ra extends P{}class za extends Ra{}class Ba extends Ra{async _call(e){return new Q(await super._call(e))}}class Va extends P{}class Ha extends Va{}class Ua extends Va{}class Wa extends P{}class Ga extends Wa{}class Ka extends Wa{}class qa extends P{}class Ja extends qa{}class Ya extends qa{async _call(e){return new Q(await super._call(e))}}class Xa extends P{}class Za extends Xa{}class Qa extends Xa{async _call(e){return new eo(await super._call(e))}}class $a extends Xa{async _call(e){return new to(await super._call(e))}}class eo extends me{constructor({logits:e,pred_boxes:t}){super(),this.logits=e,this.pred_boxes=t}}class to extends me{constructor({logits:e,pred_boxes:t,pred_masks:n}){super(),this.logits=e,this.pred_boxes=t,this.pred_masks=n}}class no extends P{}class ro extends no{}class io extends no{async _call(e){return new ao(await super._call(e))}}class ao extends me{constructor({logits:e,pred_boxes:t}){super(),this.logits=e,this.pred_boxes=t}}class oo extends P{}class so extends oo{}class co extends oo{async _call(e){return new lo(await super._call(e))}}class lo extends ao{}class uo extends P{}class fo extends uo{}class po extends uo{async _call(e){return new mo(await super._call(e))}}class mo extends ao{}class ho extends P{}class go extends ho{}class _o extends ho{async _call(e){return new ao(await super._call(e))}}class vo extends P{}class yo extends vo{}class bo extends vo{async _call(e){return new xo(await super._call(e))}}class xo extends eo{}class So extends P{}class Co extends So{}class wo extends So{async _call(e){return new Q(await super._call(e))}}class To extends P{}class Eo extends To{}class Do extends To{async _call(e){return new Q(await super._call(e))}}class Oo extends P{}class ko extends Oo{}class Ao extends Oo{async _call(e){return new Q(await super._call(e))}}class jo extends P{}class Mo extends jo{}class No extends jo{async _call(e){return new Q(await super._call(e))}}class Po extends jo{}class Fo extends P{}class Io extends Fo{}class Lo extends Fo{}class Ro extends P{}class zo extends Ro{}class Bo extends Ro{}class Vo extends P{}class Ho extends Vo{}class Uo extends P{}class Wo extends Uo{}class Go extends Uo{}class Ko extends Uo{}class qo extends P{}class Jo extends qo{}class Yo extends P{}class Xo extends Yo{}class Zo extends P{}class Qo extends Zo{}class $o extends P{}class es extends $o{}class ts extends $o{}class ns extends P{}class rs extends ns{}class is extends ns{}class as extends P{}class os extends as{}class ss extends P{}class cs extends ss{}class ls extends ss{async _call(e){return new Q(await super._call(e))}}class us extends P{}class ds extends us{}class fs extends us{async _call(e){return new Q(await super._call(e))}}class ps extends P{}class ms extends ps{}class hs extends ps{async _call(e){return new Q(await super._call(e))}}class gs extends P{}class _s extends gs{}class vs extends gs{async _call(e){return new Q(await super._call(e))}}class ys extends P{}class bs extends ys{}class xs extends P{}class Ss extends xs{}class Cs extends P{}class ws extends Cs{}class Ts extends P{}class Es extends Ts{}class Ds extends Ts{async _call(e){return new Os(await super._call(e))}}class Os extends me{constructor({logits:e,pred_boxes:t}){super(),this.logits=e,this.pred_boxes=t}}class ks extends P{}class As extends ks{async get_image_embeddings({pixel_values:e}){return await ne(this,{pixel_values:e})}async forward(e){e=!e.image_embeddings||!e.image_positional_embeddings?{...e,...await this.get_image_embeddings(e)}:{...e},e.input_labels??=(0,f.ones)(e.input_points.dims.slice(0,-1));let t={image_embeddings:e.image_embeddings,image_positional_embeddings:e.image_positional_embeddings};return e.input_points&&(t.input_points=e.input_points),e.input_labels&&(t.input_labels=e.input_labels),e.input_boxes&&(t.input_boxes=e.input_boxes),await O(this.sessions.prompt_encoder_mask_decoder,t)}async _call(e){return new js(await super._call(e))}}class js extends me{constructor({iou_scores:e,pred_masks:t}){super(),this.iou_scores=e,this.pred_masks=t}}class Ms extends me{constructor({iou_scores:e,pred_masks:t,object_score_logits:n}){super(),this.iou_scores=e,this.pred_masks=t,this.object_score_logits=n}}class Ns extends P{}class Ps extends Ns{async get_image_embeddings({pixel_values:e}){return await ne(this,{pixel_values:e})}async forward(e){let{num_feature_levels:t}=this.config.vision_config;if(e=Array.from({length:t},(e,t)=>`image_embeddings.${t}`).some(t=>!e[t])?{...e,...await this.get_image_embeddings(e)}:{...e},e.input_points){if(e.input_boxes&&e.input_boxes.dims[1]!==1)throw Error("When both `input_points` and `input_boxes` are provided, the number of boxes per image must be 1.");let t=e.input_points.dims;e.input_labels??=(0,f.ones)(t.slice(0,-1)),e.input_boxes??=(0,f.full)([t[0],0,4],0)}else if(e.input_boxes){let t=e.input_boxes.dims;e.input_labels=(0,f.full)([t[0],t[1],0],-1n),e.input_points=(0,f.full)([t[0],1,0,2],0)}else throw Error("At least one of `input_points` or `input_boxes` must be provided.");let n=this.sessions.prompt_encoder_mask_decoder;return await O(n,(0,s.pick)(e,n.inputNames))}async _call(e){return new Ms(await super._call(e))}}class Fs extends Ps{}class Is extends Ps{}class Ls extends P{}class Rs extends Ls{}class zs extends Ls{}class Bs extends P{}class Vs extends Bs{}class Hs extends Bs{}class Us extends P{}class Ws extends Us{}class Gs extends Us{async _call(e){return new Fd(await super._call(e))}}class Ks extends Us{async _call(e){return new Q(await super._call(e))}}class qs extends Us{async _call(e){return new Md(await super._call(e))}}class Js extends P{}class Ys extends Js{async _call(e){return new Fd(await super._call(e))}}class Xs extends P{}class Zs extends Xs{}class Qs extends Xs{async _call(e){return new Md(await super._call(e))}}class $s extends P{}class ec extends $s{}class tc extends P{}class nc extends tc{}class rc extends tc{async _call(e){return new Fd(await super._call(e))}}class ic extends tc{async _call(e){return new Q(await super._call(e))}}class ac extends P{}class oc extends ac{}class sc extends ac{async _call(e){return new Fd(await super._call(e))}}class cc extends ac{async _call(e){return new Q(await super._call(e))}}class lc extends ac{async _call(e){return new Md(await super._call(e))}}class uc extends P{}class dc extends uc{}class fc extends uc{async _call(e){return new Fd(await super._call(e))}}class pc extends uc{async _call(e){return new Q(await super._call(e))}}class mc extends P{}class hc extends Us{}class gc extends Us{async _call(e){return new Fd(await super._call(e))}}class _c extends Us{async _call(e){return new Q(await super._call(e))}}class vc extends P{}class yc extends vc{}class bc extends vc{async _call(e){return new Fd(await super._call(e))}}class xc extends vc{async _call(e){return new Q(await super._call(e))}}class Sc extends vc{async _call(e){return new jd(await super._call(e))}}class Cc extends vc{async _call(e){return new Md(await super._call(e))}}class wc extends P{}class Tc extends wc{}class Ec extends P{}class Dc extends Ec{}class Oc extends Ec{}class kc extends Ec{async generate_speech(e,t,{threshold:n=.5,minlenratio:r=0,maxlenratio:i=20,vocoder:a=null}={}){let{encoder_outputs:o,encoder_attention_mask:s}=await ne(this,{input_ids:e}),c=o.dims[1]/this.config.reduction_factor,l=Math.floor(c*i),u=Math.floor(c*r),d=this.config.num_mel_bins,p=[],m=null,h=null,g=0;for(;;){++g;let e=ee(!!h),r;r=h?h.output_sequence_out:new f.Tensor(`float32`,new Float32Array(d),[1,1,d]);let i={use_cache_branch:e,output_sequence:r,encoder_attention_mask:s,speaker_embeddings:t,encoder_hidden_states:o};this.addPastKeyValues(i,m),h=await O(this.sessions.decoder_model_merged,i),m=this.getPastKeyValues(h,m);let{prob:a,spectrum:c}=h;if(p.push(c),g>=u&&(Array.from(a.data).filter(e=>e>=n).length>0||g>=l))break}let _=(0,f.cat)(p),{waveform:v}=await O(a.sessions.model,{spectrogram:_});return{spectrogram:_,waveform:v}}}class Ac extends P{main_input_name=`spectrogram`}class jc extends P{}class Mc extends jc{async generate_speech({input_ids:e,attention_mask:t,style:n,num_inference_steps:r=5,speed:i=1.05}){let{sampling_rate:a,chunk_compress_factor:o,base_chunk_size:s,latent_dim:c}=this.config,{last_hidden_state:l,durations:u}=await O(this.sessions.text_encoder,{input_ids:e,attention_mask:t,style:n});u.div_(i);let d=u.max().item()*a,p=s*o,m=Math.floor((d+p-1)/p),h=e.dims[0],g=(0,f.ones)([h,m]),_=(0,f.full)([h],r),v=(0,f.randn)([h,c*o,m]);for(let e=0;e<r;++e){let r=(0,f.full)([h],e);({denoised_latents:v}=await O(this.sessions.latent_denoiser,{style:n,noisy_latents:v,latent_mask:g,encoder_outputs:l,attention_mask:t,timestep:r,num_inference_steps:_}))}let{waveform:y}=await O(this.sessions.voice_decoder,{latents:v});return{waveform:y,durations:u}}}class Nc extends P{}class Pc extends Nc{}class Fc extends P{}class Ic extends Fc{}class Lc extends Fc{}class Rc extends P{}class zc extends Rc{}class Bc extends Rc{}class Vc extends P{}class Hc extends Vc{}class Uc extends Vc{}class Wc extends P{}class Gc extends Wc{}class Kc extends Wc{}class qc extends P{}class Jc extends qc{}class Yc extends qc{}class Xc extends P{}class Zc extends Xc{}class Qc extends Xc{}class $c extends P{}class el extends $c{}class tl extends $c{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??`text_model`})}}class nl extends $c{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??`audio_model`})}}class rl extends P{}class il extends rl{async _call(e){return new Rd(await super._call(e))}}class al extends P{}class ol extends al{}class sl extends al{}class cl extends al{}class ll extends P{}class ul extends ll{}class dl extends ll{}class fl extends P{}class pl extends fl{}class ml extends fl{async _call(e){return new Q(await super._call(e))}}class hl extends P{}class gl extends hl{}class _l extends hl{}class vl extends P{forward_params=[`input_ids`,`attention_mask`,`encoder_outputs`,`decoder_input_ids`,`decoder_attention_mask`,`past_key_values`];_apply_and_filter_by_delay_pattern_mask(e){let[t,n]=e.dims,r=this.config.decoder.num_codebooks,i=n-r,a=0;for(let t=0;t<e.size;++t){if(e.data[t]===this.config.decoder.pad_token_id)continue;let o=t%n-Math.floor(t/n)%r;o>0&&o<=i&&(e.data[a++]=e.data[t])}let o=Math.floor(t/r),s=a/(o*r);return new f.Tensor(e.type,e.data.slice(0,a),[o,r,s])}prepare_inputs_for_generation(e,t,n){let r=structuredClone(e);for(let e=0;e<r.length;++e)for(let t=0;t<r[e].length;++t)e%this.config.decoder.num_codebooks>=t&&(r[e][t]=BigInt(this.config.decoder.pad_token_id));return n.guidance_scale!==null&&n.guidance_scale>1&&(r=r.concat(r)),super.prepare_inputs_for_generation(r,t,n)}async generate(e){let t=await super.generate(e),n=this._apply_and_filter_by_delay_pattern_mask(t).unsqueeze_(0),{audio_values:r}=await O(this.sessions.encodec_decode,{audio_codes:n});return r}}class yl extends P{}class bl extends yl{}class xl extends yl{async _call(e){return new Q(await super._call(e))}}class Sl extends yl{}class Cl extends P{}class wl extends Cl{}class Tl extends Cl{async _call(e){return new Q(await super._call(e))}}class El extends Cl{}class Dl extends P{}class Ol extends Dl{}class kl extends Dl{async _call(e){return new Q(await super._call(e))}}class Al extends Dl{}class jl extends P{}class Ml extends jl{}class Nl extends jl{async _call(e){return new Q(await super._call(e))}}class Pl extends jl{}class Fl extends P{}class Il extends Fl{}class Ll extends P{}class Rl extends Ll{forward_params=[`input_ids`,`pixel_values`,`images_seq_mask`,`images_emb_mask`,`attention_mask`,`position_ids`,`past_key_values`];constructor(...e){super(...e),this._generation_mode=`text`}async forward(e){let t=this._generation_mode??`text`,n;if(t===`text`||!e.past_key_values){let t=this.sessions.prepare_inputs_embeds;n=await O(t,(0,s.pick)(e,t.inputNames))}else{let t=this.sessions.gen_img_embeds;n=await O(t,(0,s.pick)({image_ids:e.input_ids},t.inputNames))}let r={...e,...n},i=await re(this,r),a=this.sessions[t===`text`?`lm_head`:`gen_head`];if(!a)throw Error(`Unable to find "${a}" generation head`);let o=await O(a,(0,s.pick)(i,a.inputNames));return{...n,...i,...o}}async generate(e){return this._generation_mode=`text`,super.generate(e)}async generate_images(e){this._generation_mode=`image`;let t=(e.inputs??e[this.main_input_name]).dims[1],n=(await super.generate(e)).slice(null,[t,null]),r=this.sessions.image_decode,{decoded_image:i}=await O(r,{generated_tokens:n}),a=i.add_(1).mul_(255/2).clamp_(0,255).to(`uint8`),o=[];for(let e of a){let t=p.RawImage.fromTensor(e);o.push(t)}return o}}class zl extends me{constructor({char_logits:e,bpe_logits:t,wp_logits:n}){super(),this.char_logits=e,this.bpe_logits=t,this.wp_logits=n}get logits(){return[this.char_logits,this.bpe_logits,this.wp_logits]}}class Bl extends P{}class Vl extends Bl{async _call(e){return new zl(await super._call(e))}}class Hl extends P{}class Ul extends Hl{}class Wl extends Hl{}class Gl extends P{}class Kl extends Gl{}class ql extends Gl{}class Jl extends P{forward_params=[`input_ids`,`attention_mask`,`position_ids`,`audio_values`,`past_key_values`]}class Yl extends Jl{_merge_input_ids_with_audio_features(e){let t=e.audio_features.dims.at(-1),n=e.audio_features.view(-1,t);return oe({audio_token_id:this.config.ignore_index??this.config.audio_token_id,...e,audio_features:n})}}class Xl extends Yl{}class Zl extends P{main_input_name=`input_values`;forward_params=[`input_values`]}class Ql extends me{constructor({audio_codes:e}){super(),this.audio_codes=e}}class $l extends me{constructor({audio_values:e}){super(),this.audio_values=e}}class eu extends Zl{async encode(e){return new Ql(await O(this.sessions.encoder_model,e))}async decode(e){return new $l(await O(this.sessions.decoder_model,e))}}class tu extends Zl{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??`encoder_model`})}}class nu extends Zl{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??`decoder_model`})}}class ru extends P{main_input_name=`input_values`;forward_params=[`input_values`]}class iu extends me{constructor({audio_codes:e}){super(),this.audio_codes=e}}class au extends me{constructor({audio_values:e}){super(),this.audio_values=e}}class ou extends ru{async encode(e){return new iu(await O(this.sessions.encoder_model,e))}async decode(e){return new au(await O(this.sessions.decoder_model,e))}}class su extends ru{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??`encoder_model`})}}class cu extends ru{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??`decoder_model`})}}class lu extends P{main_input_name=`input_values`;forward_params=[`input_values`]}class uu extends lu{async encode(e){return await O(this.sessions.encoder_model,e)}async decode(e){return await O(this.sessions.decoder_model,e)}}class du extends lu{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??`encoder_model`})}}class fu extends lu{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??`decoder_model`})}}class pu{static MODEL_CLASS_MAPPINGS=null;static BASE_IF_FAIL=!1;static async from_pretrained(e,{progress_callback:t=null,config:n=null,cache_dir:i=null,local_files_only:a=!1,revision:o=`main`,model_file_name:s=null,subfolder:c=`onnx`,device:l=null,dtype:u=null,use_external_data_format:d=null,session_options:f={}}={}){let p={progress_callback:t,config:n,cache_dir:i,local_files_only:a,revision:o,model_file_name:s,subfolder:c,device:l,dtype:u,use_external_data_format:d,session_options:f};if(p.config=await r.AutoConfig.from_pretrained(e,p),!this.MODEL_CLASS_MAPPINGS)throw Error("`MODEL_CLASS_MAPPINGS` not implemented for this type of `AutoClass`: "+this.name);let m=p.config.model_type;for(let t of this.MODEL_CLASS_MAPPINGS){let n=t.get(m);if(!n){for(let e of t.values())if(e[0]===m){n=e;break}if(!n)continue}return await n[1].from_pretrained(e,p)}if(this.BASE_IF_FAIL)return Qu.has(m)||console.warn(`Unknown model class "${m}", attempting to construct from base class.`),await P.from_pretrained(e,p);throw Error(`Unsupported model type: ${m}`)}}let mu=new Map([[`bert`,[`BertModel`,_e]],[`neobert`,[`NeoBertModel`,be]],[`modernbert`,[`ModernBertModel`,we]],[`nomic_bert`,[`NomicBertModel`,Me]],[`roformer`,[`RoFormerModel`,Pe]],[`electra`,[`ElectraModel`,V]],[`esm`,[`EsmModel`,bt]],[`convbert`,[`ConvBertModel`,Be]],[`camembert`,[`CamembertModel`,Xe]],[`deberta`,[`DebertaModel`,nt]],[`deberta-v2`,[`DebertaV2Model`,ct]],[`mpnet`,[`MPNetModel`,At]],[`albert`,[`AlbertModel`,Vt]],[`distilbert`,[`DistilBertModel`,mt]],[`roberta`,[`RobertaModel`,W]],[`xlm`,[`XLMModel`,yn]],[`xlm-roberta`,[`XLMRobertaModel`,Tn]],[`clap`,[`ClapModel`,el]],[`clip`,[`CLIPModel`,q]],[`clipseg`,[`CLIPSegModel`,hr]],[`chinese_clip`,[`ChineseCLIPModel`,ur]],[`siglip`,[`SiglipModel`,sr]],[`jina_clip`,[`JinaCLIPModel`,dr]],[`mobilebert`,[`MobileBertModel`,Tt]],[`squeezebert`,[`SqueezeBertModel`,It]],[`wav2vec2`,[`Wav2Vec2Model`,Ws]],[`wav2vec2-bert`,[`Wav2Vec2BertModel`,dc]],[`unispeech`,[`UniSpeechModel`,nc]],[`unispeech-sat`,[`UniSpeechSatModel`,oc]],[`hubert`,[`HubertModel`,hc]],[`wavlm`,[`WavLMModel`,yc]],[`audio-spectrogram-transformer`,[`ASTModel`,jn]],[`vits`,[`VitsModel`,il]],[`pyannote`,[`PyAnnoteModel`,Zs]],[`wespeaker-resnet`,[`WeSpeakerResNetModel`,ec]],[`detr`,[`DetrModel`,Za]],[`rt_detr`,[`RTDetrModel`,ro]],[`rt_detr_v2`,[`RTDetrV2Model`,so]],[`rf_detr`,[`RFDetrModel`,fo]],[`d_fine`,[`DFineModel`,go]],[`table-transformer`,[`TableTransformerModel`,yo]],[`vit`,[`ViTModel`,pa]],[`ijepa`,[`IJepaModel`,ga]],[`pvt`,[`PvtModel`,xa]],[`vit_msn`,[`ViTMSNModel`,Ea]],[`vit_mae`,[`ViTMAEModel`,wa]],[`groupvit`,[`GroupViTModel`,ka]],[`fastvit`,[`FastViTModel`,ja]],[`mobilevit`,[`MobileViTModel`,Ia]],[`mobilevitv2`,[`MobileViTV2Model`,za]],[`owlvit`,[`OwlViTModel`,Ha]],[`owlv2`,[`Owlv2Model`,Ga]],[`beit`,[`BeitModel`,Ja]],[`deit`,[`DeiTModel`,Co]],[`hiera`,[`HieraModel`,Eo]],[`convnext`,[`ConvNextModel`,cs]],[`convnextv2`,[`ConvNextV2Model`,ds]],[`dinov2`,[`Dinov2Model`,ms]],[`dinov2_with_registers`,[`Dinov2WithRegistersModel`,_s]],[`dinov3_vit`,[`DINOv3ViTModel`,bs]],[`dinov3_convnext`,[`DINOv3ConvNextModel`,Ss]],[`resnet`,[`ResNetModel`,ko]],[`swin`,[`SwinModel`,Mo]],[`swin2sr`,[`Swin2SRModel`,Io]],[`donut-swin`,[`DonutSwinModel`,os]],[`yolos`,[`YolosModel`,Es]],[`dpt`,[`DPTModel`,zo]],[`glpn`,[`GLPNModel`,rs]],[`hifigan`,[`SpeechT5HifiGan`,Ac]],[`efficientnet`,[`EfficientNetModel`,pl]],[`decision_transformer`,[`DecisionTransformerModel`,Il]],[`patchtst`,[`PatchTSTForPrediction`,Ul]],[`patchtsmixer`,[`PatchTSMixerForPrediction`,Kl]],[`mobilenet_v1`,[`MobileNetV1Model`,bl]],[`mobilenet_v2`,[`MobileNetV2Model`,wl]],[`mobilenet_v3`,[`MobileNetV3Model`,Ol]],[`mobilenet_v4`,[`MobileNetV4Model`,Ml]],[`maskformer`,[`MaskFormerModel`,es]],[`mgp-str`,[`MgpstrForSceneTextRecognition`,Vl]],[`style_text_to_speech_2`,[`StyleTextToSpeech2Model`,Tc]]]),hu=new Map([[`t5`,[`T5Model`,Kt]],[`longt5`,[`LongT5Model`,Yt]],[`mt5`,[`MT5Model`,Qt]],[`bart`,[`BartModel`,tn]],[`mbart`,[`MBartModel`,an]],[`marian`,[`MarianModel`,Rs]],[`whisper`,[`WhisperModel`,Pn]],[`m2m_100`,[`M2M100Model`,Vs]],[`blenderbot`,[`BlenderbotModel`,un]],[`blenderbot-small`,[`BlenderbotSmallModel`,fn]]]),gu=new Map([[`mimi`,[`MimiModel`,eu]],[`dac`,[`DacModel`,ou]],[`snac`,[`SnacModel`,uu]]]),_u=new Map([[`bloom`,[`BloomModel`,ia]],[`jais`,[`JAISModel`,xr]],[`gpt2`,[`GPT2Model`,vr]],[`gptj`,[`GPTJModel`,Ar]],[`gpt_bigcode`,[`GPTBigCodeModel`,Nr]],[`gpt_neo`,[`GPTNeoModel`,wr]],[`gpt_neox`,[`GPTNeoXModel`,Dr]],[`codegen`,[`CodeGenModel`,Ir]],[`llama`,[`LlamaModel`,zr]],[`nanochat`,[`NanoChatModel`,Wr]],[`arcee`,[`ArceeModel`,qr]],[`lfm2`,[`Lfm2Model`,Xr]],[`smollm3`,[`SmolLM3Model`,$r]],[`exaone`,[`ExaoneModel`,ci]],[`olmo`,[`OlmoModel`,mi]],[`olmo2`,[`Olmo2Model`,_i]],[`mobilellm`,[`MobileLLMModel`,di]],[`granite`,[`GraniteModel`,bi]],[`granitemoehybrid`,[`GraniteMoeHybridModel`,Ci]],[`cohere`,[`CohereModel`,Ei]],[`gemma`,[`GemmaModel`,ki]],[`gemma2`,[`Gemma2Model`,Mi]],[`vaultgemma`,[`VaultGemmaModel`,Fi]],[`gemma3_text`,[`Gemma3Model`,Ri]],[`helium`,[`HeliumModel`,ni]],[`glm`,[`GlmModel`,ai]],[`openelm`,[`OpenELMModel`,Vi]],[`qwen2`,[`Qwen2Model`,Wi]],[`qwen3`,[`Qwen3Model`,qi]],[`phi`,[`PhiModel`,Qi]],[`phi3`,[`Phi3Model`,ta]],[`mpt`,[`MptModel`,sa]],[`opt`,[`OPTModel`,ua]],[`mistral`,[`MistralModel`,Ic]],[`ministral`,[`MinistralModel`,zc]],[`ministral3`,[`Ministral3Model`,Hc]],[`ernie4_5`,[`Ernie4_5Model`,Gc]],[`starcoder2`,[`Starcoder2Model`,Jc]],[`falcon`,[`FalconModel`,Zc]],[`stablelm`,[`StableLmModel`,ul]],[`modernbert-decoder`,[`ModernBertDecoderModel`,ke]]]),vu=new Map([[`speecht5`,[`SpeechT5ForSpeechToText`,Oc]],[`whisper`,[`WhisperForConditionalGeneration`,Fn]],[`lite-whisper`,[`LiteWhisperForConditionalGeneration`,In]],[`moonshine`,[`MoonshineForConditionalGeneration`,zn]]]),yu=new Map([[`speecht5`,[`SpeechT5ForTextToSpeech`,kc]]]),bu=new Map([[`vits`,[`VitsModel`,il]],[`musicgen`,[`MusicgenForConditionalGeneration`,vl]],[`supertonic`,[`SupertonicForConditionalGeneration`,Mc]]]),xu=new Map([[`bert`,[`BertForSequenceClassification`,F]],[`neobert`,[`NeoBertForSequenceClassification`,Se]],[`modernbert`,[`ModernBertForSequenceClassification`,Ee]],[`roformer`,[`RoFormerForSequenceClassification`,Ie]],[`electra`,[`ElectraForSequenceClassification`,Ke]],[`esm`,[`EsmForSequenceClassification`,St]],[`convbert`,[`ConvBertForSequenceClassification`,Ve]],[`camembert`,[`CamembertForSequenceClassification`,Qe]],[`deberta`,[`DebertaForSequenceClassification`,it]],[`deberta-v2`,[`DebertaV2ForSequenceClassification`,ut]],[`mpnet`,[`MPNetForSequenceClassification`,Mt]],[`albert`,[`AlbertForSequenceClassification`,Ht]],[`distilbert`,[`DistilBertForSequenceClassification`,ht]],[`roberta`,[`RobertaForSequenceClassification`,gn]],[`xlm`,[`XLMForSequenceClassification`,xn]],[`xlm-roberta`,[`XLMRobertaForSequenceClassification`,Dn]],[`bart`,[`BartForSequenceClassification`,H]],[`mbart`,[`MBartForSequenceClassification`,sn]],[`mobilebert`,[`MobileBertForSequenceClassification`,Dt]],[`squeezebert`,[`SqueezeBertForSequenceClassification`,Rt]]]),Su=new Map([[`bert`,[`BertForTokenClassification`,ye]],[`neobert`,[`NeoBertForTokenClassification`,R]],[`modernbert`,[`ModernBertForTokenClassification`,De]],[`roformer`,[`RoFormerForTokenClassification`,Le]],[`electra`,[`ElectraForTokenClassification`,qe]],[`esm`,[`EsmForTokenClassification`,Ct]],[`convbert`,[`ConvBertForTokenClassification`,He]],[`camembert`,[`CamembertForTokenClassification`,$e]],[`deberta`,[`DebertaForTokenClassification`,at]],[`deberta-v2`,[`DebertaV2ForTokenClassification`,dt]],[`mpnet`,[`MPNetForTokenClassification`,Nt]],[`distilbert`,[`DistilBertForTokenClassification`,gt]],[`roberta`,[`RobertaForTokenClassification`,_n]],[`xlm`,[`XLMForTokenClassification`,Sn]],[`xlm-roberta`,[`XLMRobertaForTokenClassification`,On]]]),Cu=new Map([[`t5`,[`T5ForConditionalGeneration`,qt]],[`longt5`,[`LongT5ForConditionalGeneration`,Xt]],[`mt5`,[`MT5ForConditionalGeneration`,$t]],[`bart`,[`BartForConditionalGeneration`,nn]],[`mbart`,[`MBartForConditionalGeneration`,on]],[`marian`,[`MarianMTModel`,zs]],[`m2m_100`,[`M2M100ForConditionalGeneration`,Hs]],[`blenderbot`,[`BlenderbotForConditionalGeneration`,dn]],[`blenderbot-small`,[`BlenderbotSmallForConditionalGeneration`,pn]]]),wu=new Map([[`bloom`,[`BloomForCausalLM`,aa]],[`gpt2`,[`GPT2LMHeadModel`,yr]],[`jais`,[`JAISLMHeadModel`,Sr]],[`gptj`,[`GPTJForCausalLM`,jr]],[`gpt_bigcode`,[`GPTBigCodeForCausalLM`,Pr]],[`gpt_neo`,[`GPTNeoForCausalLM`,Tr]],[`gpt_neox`,[`GPTNeoXForCausalLM`,Or]],[`codegen`,[`CodeGenForCausalLM`,Lr]],[`llama`,[`LlamaForCausalLM`,Br]],[`nanochat`,[`NanoChatForCausalLM`,Gr]],[`llama4_text`,[`Llama4ForCausalLM`,Hr]],[`arcee`,[`ArceeForCausalLM`,Jr]],[`lfm2`,[`Lfm2ForCausalLM`,Zr]],[`smollm3`,[`SmolLM3ForCausalLM`,ei]],[`exaone`,[`ExaoneForCausalLM`,li]],[`olmo`,[`OlmoForCausalLM`,hi]],[`olmo2`,[`Olmo2ForCausalLM`,vi]],[`mobilellm`,[`MobileLLMForCausalLM`,fi]],[`granite`,[`GraniteForCausalLM`,xi]],[`granitemoehybrid`,[`GraniteMoeHybridForCausalLM`,wi]],[`cohere`,[`CohereForCausalLM`,Di]],[`gemma`,[`GemmaForCausalLM`,Ai]],[`gemma2`,[`Gemma2ForCausalLM`,Ni]],[`vaultgemma`,[`VaultGemmaForCausalLM`,Ii]],[`gemma3_text`,[`Gemma3ForCausalLM`,zi]],[`helium`,[`HeliumForCausalLM`,ri]],[`glm`,[`GlmForCausalLM`,oi]],[`openelm`,[`OpenELMForCausalLM`,Hi]],[`qwen2`,[`Qwen2ForCausalLM`,Gi]],[`qwen3`,[`Qwen3ForCausalLM`,Ji]],[`phi`,[`PhiForCausalLM`,$i]],[`phi3`,[`Phi3ForCausalLM`,na]],[`mpt`,[`MptForCausalLM`,ca]],[`opt`,[`OPTForCausalLM`,da]],[`mbart`,[`MBartForCausalLM`,cn]],[`mistral`,[`MistralForCausalLM`,Lc]],[`ministral`,[`MinistralForCausalLM`,Bc]],[`ministral3`,[`Ministral3ForCausalLM`,Uc]],[`ernie4_5`,[`Ernie4_5ForCausalLM`,Kc]],[`starcoder2`,[`Starcoder2ForCausalLM`,Yc]],[`falcon`,[`FalconForCausalLM`,Qc]],[`trocr`,[`TrOCRForCausalLM`,Pc]],[`stablelm`,[`StableLmForCausalLM`,dl]],[`modernbert-decoder`,[`ModernBertDecoderForCausalLM`,Ae]],[`phi3_v`,[`Phi3VForCausalLM`,nr]]]),Tu=new Map([[`multi_modality`,[`MultiModalityCausalLM`,Rl]]]),Eu=new Map([[`bert`,[`BertForMaskedLM`,ve]],[`neobert`,[`NeoBertForMaskedLM`,xe]],[`modernbert`,[`ModernBertForMaskedLM`,Te]],[`roformer`,[`RoFormerForMaskedLM`,Fe]],[`electra`,[`ElectraForMaskedLM`,Ge]],[`esm`,[`EsmForMaskedLM`,xt]],[`convbert`,[`ConvBertForMaskedLM`,B]],[`camembert`,[`CamembertForMaskedLM`,Ze]],[`deberta`,[`DebertaForMaskedLM`,rt]],[`deberta-v2`,[`DebertaV2ForMaskedLM`,lt]],[`mpnet`,[`MPNetForMaskedLM`,jt]],[`albert`,[`AlbertForMaskedLM`,Wt]],[`distilbert`,[`DistilBertForMaskedLM`,vt]],[`roberta`,[`RobertaForMaskedLM`,hn]],[`xlm`,[`XLMWithLMHeadModel`,bn]],[`xlm-roberta`,[`XLMRobertaForMaskedLM`,En]],[`mobilebert`,[`MobileBertForMaskedLM`,Et]],[`squeezebert`,[`SqueezeBertForMaskedLM`,Lt]]]),Du=new Map([[`bert`,[`BertForQuestionAnswering`,I]],[`neobert`,[`NeoBertForQuestionAnswering`,Ce]],[`roformer`,[`RoFormerForQuestionAnswering`,Re]],[`electra`,[`ElectraForQuestionAnswering`,Je]],[`convbert`,[`ConvBertForQuestionAnswering`,Ue]],[`camembert`,[`CamembertForQuestionAnswering`,et]],[`deberta`,[`DebertaForQuestionAnswering`,ot]],[`deberta-v2`,[`DebertaV2ForQuestionAnswering`,ft]],[`mpnet`,[`MPNetForQuestionAnswering`,Pt]],[`albert`,[`AlbertForQuestionAnswering`,Ut]],[`distilbert`,[`DistilBertForQuestionAnswering`,_t]],[`roberta`,[`RobertaForQuestionAnswering`,vn]],[`xlm`,[`XLMForQuestionAnswering`,Cn]],[`xlm-roberta`,[`XLMRobertaForQuestionAnswering`,kn]],[`mobilebert`,[`MobileBertForQuestionAnswering`,Ot]],[`squeezebert`,[`SqueezeBertForQuestionAnswering`,zt]]]),Ou=new Map([[`vision-encoder-decoder`,[`VisionEncoderDecoderModel`,Bn]],[`idefics3`,[`Idefics3ForConditionalGeneration`,K]],[`smolvlm`,[`SmolVLMForConditionalGeneration`,er]]]),ku=new Map([[`llava`,[`LlavaForConditionalGeneration`,Hn]],[`llava_onevision`,[`LlavaOnevisionForConditionalGeneration`,Un]],[`moondream1`,[`Moondream1ForConditionalGeneration`,Wn]],[`florence2`,[`Florence2ForConditionalGeneration`,Kn]],[`qwen2-vl`,[`Qwen2VLForConditionalGeneration`,Xi]],[`idefics3`,[`Idefics3ForConditionalGeneration`,K]],[`smolvlm`,[`SmolVLMForConditionalGeneration`,er]],[`paligemma`,[`PaliGemmaForConditionalGeneration`,Jn]],[`llava_qwen2`,[`LlavaQwen2ForCausalLM`,Yn]],[`gemma3n`,[`Gemma3nForConditionalGeneration`,Qn]],[`mistral3`,[`Mistral3ForConditionalGeneration`,Xn]]]),Au=new Map([[`ultravox`,[`UltravoxModel`,Yl]],[`voxtral`,[`VoxtralForConditionalGeneration`,Xl]]]),ju=new Map([[`vision-encoder-decoder`,[`VisionEncoderDecoderModel`,Bn]]]),Mu=new Map([[`vit`,[`ViTForImageClassification`,ma]],[`ijepa`,[`IJepaForImageClassification`,_a]],[`pvt`,[`PvtForImageClassification`,Sa]],[`vit_msn`,[`ViTMSNForImageClassification`,Da]],[`fastvit`,[`FastViTForImageClassification`,Ma]],[`mobilevit`,[`MobileViTForImageClassification`,La]],[`mobilevitv2`,[`MobileViTV2ForImageClassification`,Ba]],[`beit`,[`BeitForImageClassification`,Ya]],[`deit`,[`DeiTForImageClassification`,wo]],[`hiera`,[`HieraForImageClassification`,Do]],[`convnext`,[`ConvNextForImageClassification`,ls]],[`convnextv2`,[`ConvNextV2ForImageClassification`,fs]],[`dinov2`,[`Dinov2ForImageClassification`,hs]],[`dinov2_with_registers`,[`Dinov2WithRegistersForImageClassification`,vs]],[`resnet`,[`ResNetForImageClassification`,Ao]],[`swin`,[`SwinForImageClassification`,No]],[`segformer`,[`SegformerForImageClassification`,sl]],[`efficientnet`,[`EfficientNetForImageClassification`,ml]],[`mobilenet_v1`,[`MobileNetV1ForImageClassification`,xl]],[`mobilenet_v2`,[`MobileNetV2ForImageClassification`,Tl]],[`mobilenet_v3`,[`MobileNetV3ForImageClassification`,kl]],[`mobilenet_v4`,[`MobileNetV4ForImageClassification`,Nl]]]),Nu=new Map([[`detr`,[`DetrForObjectDetection`,Qa]],[`rt_detr`,[`RTDetrForObjectDetection`,io]],[`rt_detr_v2`,[`RTDetrV2ForObjectDetection`,co]],[`rf_detr`,[`RFDetrForObjectDetection`,po]],[`d_fine`,[`DFineForObjectDetection`,_o]],[`table-transformer`,[`TableTransformerForObjectDetection`,bo]],[`yolos`,[`YolosForObjectDetection`,Ds]]]),Pu=new Map([[`owlvit`,[`OwlViTForObjectDetection`,Ua]],[`owlv2`,[`Owlv2ForObjectDetection`,Ka]],[`grounding-dino`,[`GroundingDinoForObjectDetection`,ws]]]),Fu=new Map([[`detr`,[`DetrForSegmentation`,$a]],[`clipseg`,[`CLIPSegForImageSegmentation`,gr]]]),Iu=new Map([[`segformer`,[`SegformerForSemanticSegmentation`,cl]],[`sapiens`,[`SapiensForSemanticSegmentation`,Wo]],[`swin`,[`SwinForSemanticSegmentation`,Po]],[`mobilenet_v1`,[`MobileNetV1ForSemanticSegmentation`,Sl]],[`mobilenet_v2`,[`MobileNetV2ForSemanticSegmentation`,El]],[`mobilenet_v3`,[`MobileNetV3ForSemanticSegmentation`,Al]],[`mobilenet_v4`,[`MobileNetV4ForSemanticSegmentation`,Pl]]]),Lu=new Map([[`detr`,[`DetrForSegmentation`,$a]],[`maskformer`,[`MaskFormerForInstanceSegmentation`,ts]]]),Ru=new Map([[`sam`,[`SamModel`,As]],[`sam2`,[`Sam2Model`,Ps]],[`edgetam`,[`EdgeTamModel`,Fs]],[`sam3_tracker`,[`Sam3TrackerModel`,Is]]]),zu=new Map([[`wav2vec2`,[`Wav2Vec2ForCTC`,Gs]],[`wav2vec2-bert`,[`Wav2Vec2BertForCTC`,fc]],[`unispeech`,[`UniSpeechForCTC`,rc]],[`unispeech-sat`,[`UniSpeechSatForCTC`,sc]],[`wavlm`,[`WavLMForCTC`,bc]],[`hubert`,[`HubertForCTC`,gc]],[`parakeet_ctc`,[`ParakeetForCTC`,Ys]]]),Bu=new Map([[`wav2vec2`,[`Wav2Vec2ForSequenceClassification`,Ks]],[`wav2vec2-bert`,[`Wav2Vec2BertForSequenceClassification`,pc]],[`unispeech`,[`UniSpeechForSequenceClassification`,ic]],[`unispeech-sat`,[`UniSpeechSatForSequenceClassification`,cc]],[`wavlm`,[`WavLMForSequenceClassification`,xc]],[`hubert`,[`HubertForSequenceClassification`,_c]],[`audio-spectrogram-transformer`,[`ASTForAudioClassification`,Mn]]]),Vu=new Map([[`wavlm`,[`WavLMForXVector`,Sc]]]),Hu=new Map([[`unispeech-sat`,[`UniSpeechSatForAudioFrameClassification`,lc]],[`wavlm`,[`WavLMForAudioFrameClassification`,Cc]],[`wav2vec2`,[`Wav2Vec2ForAudioFrameClassification`,qs]],[`pyannote`,[`PyAnnoteForAudioFrameClassification`,Qs]]]),Uu=new Map([[`vitmatte`,[`VitMatteForImageMatting`,Pa]]]),Wu=new Map([[`patchtst`,[`PatchTSTForPrediction`,Wl]],[`patchtsmixer`,[`PatchTSMixerForPrediction`,ql]]]),Gu=new Map([[`swin2sr`,[`Swin2SRForImageSuperResolution`,Lo]]]),Ku=new Map([[`dpt`,[`DPTForDepthEstimation`,Bo]],[`depth_anything`,[`DepthAnythingForDepthEstimation`,Ho]],[`glpn`,[`GLPNForDepthEstimation`,is]],[`sapiens`,[`SapiensForDepthEstimation`,Go]],[`depth_pro`,[`DepthProForDepthEstimation`,Jo]],[`metric3d`,[`Metric3DForDepthEstimation`,Xo]],[`metric3dv2`,[`Metric3Dv2ForDepthEstimation`,Qo]]]),qu=new Map([[`sapiens`,[`SapiensForNormalEstimation`,Ko]]]),Ju=new Map([[`vitpose`,[`VitPoseForPoseEstimation`,ya]]]),Yu=new Map([[`clip`,[`CLIPVisionModelWithProjection`,ar]],[`siglip`,[`SiglipVisionModel`,X]],[`jina_clip`,[`JinaCLIPVisionModel`,pr]]]),Xu=[[mu,b.EncoderOnly],[hu,b.EncoderDecoder],[_u,b.DecoderOnly],[gu,b.AutoEncoder],[xu,b.EncoderOnly],[Su,b.EncoderOnly],[Cu,b.Seq2Seq],[vu,b.Seq2Seq],[wu,b.DecoderOnly],[Tu,b.MultiModality],[Eu,b.EncoderOnly],[Du,b.EncoderOnly],[Ou,b.Vision2Seq],[ku,b.ImageTextToText],[Au,b.AudioTextToText],[Mu,b.EncoderOnly],[Fu,b.EncoderOnly],[Lu,b.EncoderOnly],[Iu,b.EncoderOnly],[Uu,b.EncoderOnly],[Wu,b.EncoderOnly],[Gu,b.EncoderOnly],[Ku,b.EncoderOnly],[qu,b.EncoderOnly],[Ju,b.EncoderOnly],[Nu,b.EncoderOnly],[Pu,b.EncoderOnly],[Ru,b.MaskGeneration],[zu,b.EncoderOnly],[Bu,b.EncoderOnly],[yu,b.Seq2Seq],[bu,b.EncoderOnly],[Vu,b.EncoderOnly],[Hu,b.EncoderOnly],[Yu,b.EncoderOnly]];for(let[e,t]of Xu)for(let[n,r]of e.values())x.set(n,t),C.set(r,n),S.set(n,r);let Zu=[[`MusicgenForConditionalGeneration`,vl,b.Musicgen],[`Phi3VForCausalLM`,nr,b.Phi3V],[`CLIPTextModelWithProjection`,J,b.EncoderOnly],[`SiglipTextModel`,cr,b.EncoderOnly],[`JinaCLIPTextModel`,fr,b.EncoderOnly],[`ClapTextModelWithProjection`,tl,b.EncoderOnly],[`ClapAudioModelWithProjection`,nl,b.EncoderOnly],[`DacEncoderModel`,su,b.EncoderOnly],[`DacDecoderModel`,cu,b.EncoderOnly],[`MimiEncoderModel`,tu,b.EncoderOnly],[`MimiDecoderModel`,nu,b.EncoderOnly],[`SnacEncoderModel`,du,b.EncoderOnly],[`SnacDecoderModel`,fu,b.EncoderOnly],[`Gemma3nForConditionalGeneration`,Qn,b.ImageAudioTextToText],[`SupertonicForConditionalGeneration`,Mc,b.Supertonic]];for(let[e,t,n]of Zu)x.set(e,n),C.set(t,e),S.set(e,t);let Qu=new Map([[`modnet`,Fu],[`birefnet`,Fu],[`isnet`,Fu],[`ben`,Fu]]);for(let[e,t]of Qu.entries())t.set(e,[`PreTrainedModel`,P]),x.set(e,b.EncoderOnly),C.set(P,e),S.set(e,P);class $u extends pu{static MODEL_CLASS_MAPPINGS=Xu.map(e=>e[0]);static BASE_IF_FAIL=!0}class ed extends pu{static MODEL_CLASS_MAPPINGS=[xu]}class td extends pu{static MODEL_CLASS_MAPPINGS=[Su]}class nd extends pu{static MODEL_CLASS_MAPPINGS=[Cu]}class rd extends pu{static MODEL_CLASS_MAPPINGS=[vu]}class id extends pu{static MODEL_CLASS_MAPPINGS=[yu]}class ad extends pu{static MODEL_CLASS_MAPPINGS=[bu]}class od extends pu{static MODEL_CLASS_MAPPINGS=[wu]}class sd extends pu{static MODEL_CLASS_MAPPINGS=[Eu]}class cd extends pu{static MODEL_CLASS_MAPPINGS=[Du]}class ld extends pu{static MODEL_CLASS_MAPPINGS=[Ou]}class ud extends pu{static MODEL_CLASS_MAPPINGS=[Mu]}class dd extends pu{static MODEL_CLASS_MAPPINGS=[Fu]}class fd extends pu{static MODEL_CLASS_MAPPINGS=[Iu]}class pd extends pu{static MODEL_CLASS_MAPPINGS=[Lu]}class md extends pu{static MODEL_CLASS_MAPPINGS=[Nu]}class hd extends pu{static MODEL_CLASS_MAPPINGS=[Pu]}class gd extends pu{static MODEL_CLASS_MAPPINGS=[Ru]}class _d extends pu{static MODEL_CLASS_MAPPINGS=[zu]}class vd extends pu{static MODEL_CLASS_MAPPINGS=[Bu]}class yd extends pu{static MODEL_CLASS_MAPPINGS=[Vu]}class bd extends pu{static MODEL_CLASS_MAPPINGS=[Hu]}class xd extends pu{static MODEL_CLASS_MAPPINGS=[ju]}class Sd extends pu{static MODEL_CLASS_MAPPINGS=[Uu]}class Cd extends pu{static MODEL_CLASS_MAPPINGS=[Gu]}class wd extends pu{static MODEL_CLASS_MAPPINGS=[Ku]}class Td extends pu{static MODEL_CLASS_MAPPINGS=[qu]}class Ed extends pu{static MODEL_CLASS_MAPPINGS=[Ju]}class Dd extends pu{static MODEL_CLASS_MAPPINGS=[Yu]}class Od extends pu{static MODEL_CLASS_MAPPINGS=[ku]}class kd extends pu{static MODEL_CLASS_MAPPINGS=[Au]}class Ad extends me{constructor({logits:e,past_key_values:t,encoder_outputs:n,decoder_attentions:r=null,cross_attentions:i=null}){super(),this.logits=e,this.past_key_values=t,this.encoder_outputs=n,this.decoder_attentions=r,this.cross_attentions=i}}class Q extends me{constructor({logits:e,...t}){super(),this.logits=e;let n=Object.values(t);n.length>0&&(this.attentions=n)}}class jd extends me{constructor({logits:e,embeddings:t}){super(),this.logits=e,this.embeddings=t}}class Md extends me{constructor({logits:e}){super(),this.logits=e}}class Nd extends me{constructor({logits:e}){super(),this.logits=e}}class Pd extends me{constructor({start_logits:e,end_logits:t}){super(),this.start_logits=e,this.end_logits=t}}class Fd extends me{constructor({logits:e}){super(),this.logits=e}}class Id extends me{constructor({logits:e,past_key_values:t}){super(),this.logits=e,this.past_key_values=t}}class Ld extends me{constructor({alphas:e}){super(),this.alphas=e}}class Rd extends me{constructor({waveform:e,spectrogram:t}){super(),this.waveform=e,this.spectrogram=t}}}),"./src/models/audio_spectrogram_transformer/feature_extraction_audio_spectrogram_transformer.js":((e,t,n)=>{n.r(t),n.d(t,{ASTFeatureExtractor:()=>a});var r=n(`./src/base/feature_extraction_utils.js`);n(`./src/utils/tensor.js`);var i=n(`./src/utils/audio.js`);class a extends r.FeatureExtractor{constructor(e){super(e);let t=this.config.sampling_rate;this.mel_filters=(0,i.mel_filter_bank)(257,this.config.num_mel_bins,20,Math.floor(t/2),t,null,`kaldi`,!0),this.window=(0,i.window_function)(400,`hann`,{periodic:!1}),this.mean=this.config.mean,this.std=this.config.std}async _extract_fbank_features(e,t){return(0,i.spectrogram)(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:`log`,mel_floor:1.192092955078125e-7,remove_dc_offset:!0,max_num_frames:t,transpose:!0})}async _call(e){(0,r.validate_audio_inputs)(e,`ASTFeatureExtractor`);let t=await this._extract_fbank_features(e,this.config.max_length);if(this.config.do_normalize){let e=this.std*2,n=t.data;for(let t=0;t<n.length;++t)n[t]=(n[t]-this.mean)/e}return{input_values:t.unsqueeze_(0)}}}}),"./src/models/auto/feature_extraction_auto.js":((e,t,n)=>{n.r(t),n.d(t,{AutoFeatureExtractor:()=>o});var r=n(`./src/utils/constants.js`),i=n(`./src/utils/hub.js`);n(`./src/base/feature_extraction_utils.js`);var a=n(`./src/models/feature_extractors.js`);class o{static async from_pretrained(e,t={}){let n=await(0,i.getModelJSON)(e,r.FEATURE_EXTRACTOR_NAME,!0,t),o=n.feature_extractor_type,s=a[o];if(!s)throw Error(`Unknown feature_extractor_type: '${o}'. Please report this at ${r.GITHUB_ISSUE_URL}.`);return new s(n)}}}),"./src/models/auto/image_processing_auto.js":((e,t,n)=>{n.r(t),n.d(t,{AutoImageProcessor:()=>s});var r=n(`./src/utils/constants.js`),i=n(`./src/utils/hub.js`),a=n(`./src/base/image_processors_utils.js`),o=n(`./src/models/image_processors.js`);class s{static async from_pretrained(e,t={}){let n=await(0,i.getModelJSON)(e,r.IMAGE_PROCESSOR_NAME,!0,t),s=n.image_processor_type??n.feature_extractor_type,c=o[s?.replace(/Fast$/,``)];return c||=(s!==void 0&&console.warn(`Image processor type '${s}' not found, assuming base ImageProcessor. Please report this at ${r.GITHUB_ISSUE_URL}.`),a.ImageProcessor),new c(n)}}}),"./src/models/auto/processing_auto.js":((e,t,n)=>{n.r(t),n.d(t,{AutoProcessor:()=>l});var r=n(`./src/utils/constants.js`),i=n(`./src/utils/hub.js`),a=n(`./src/base/processing_utils.js`),o=n(`./src/models/processors.js`),s=n(`./src/models/image_processors.js`),c=n(`./src/models/feature_extractors.js`);class l{static async from_pretrained(e,t={}){let n=await(0,i.getModelJSON)(e,r.IMAGE_PROCESSOR_NAME,!0,t),{image_processor_type:l,feature_extractor_type:u,processor_class:d}=n;if(d&&o[d])return o[d].from_pretrained(e,t);if(!l&&!u)throw Error("No `image_processor_type` or `feature_extractor_type` found in the config.");let f={};if(l){let e=s[l.replace(/Fast$/,``)];if(!e)throw Error(`Unknown image_processor_type: '${l}'.`);f.image_processor=new e(n)}if(u){let e=s[u];if(e)f.image_processor=new e(n);else{let e=c[u];if(!e)throw Error(`Unknown feature_extractor_type: '${u}'.`);f.feature_extractor=new e(n)}}return new a.Processor({},f,null)}}}),"./src/models/beit/image_processing_beit.js":((e,t,n)=>{n.r(t),n.d(t,{BeitFeatureExtractor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{}}),"./src/models/bit/image_processing_bit.js":((e,t,n)=>{n.r(t),n.d(t,{BitImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{}}),"./src/models/chinese_clip/image_processing_chinese_clip.js":((e,t,n)=>{n.r(t),n.d(t,{ChineseCLIPFeatureExtractor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{}}),"./src/models/clap/feature_extraction_clap.js":((e,t,n)=>{n.r(t),n.d(t,{ClapFeatureExtractor:()=>a});var r=n(`./src/base/feature_extraction_utils.js`);n(`./src/utils/tensor.js`);var i=n(`./src/utils/audio.js`);class a extends r.FeatureExtractor{constructor(e){super(e),this.mel_filters=(0,i.mel_filter_bank)(this.config.nb_frequency_bins,this.config.feature_size,this.config.frequency_min,this.config.frequency_max,this.config.sampling_rate,null,`htk`),this.mel_filters_slaney=(0,i.mel_filter_bank)(this.config.nb_frequency_bins,this.config.feature_size,this.config.frequency_min,this.config.frequency_max,this.config.sampling_rate,`slaney`,`slaney`),this.window=(0,i.window_function)(this.config.fft_window_size,`hann`)}async _get_input_mel(e,t,n,r){let i,a=e.length-t;if(a>0)if(n===`rand_trunc`){let n=Math.floor(Math.random()*(a+1));e=e.subarray(n,n+t),i=await this._extract_fbank_features(e,this.mel_filters_slaney,this.config.nb_max_samples)}else throw Error(`Truncation strategy "${n}" not implemented`);else{if(a<0){let n=new Float64Array(t);if(n.set(e),r===`repeat`)for(let r=e.length;r<t;r+=e.length)n.set(e.subarray(0,Math.min(e.length,t-r)),r);else if(r===`repeatpad`)for(let t=e.length;t<-a;t+=e.length)n.set(e,t);e=n}if(n===`fusion`)throw Error(`Truncation strategy "${n}" not implemented`);i=await this._extract_fbank_features(e,this.mel_filters_slaney,this.config.nb_max_samples)}return i.unsqueeze_(0)}async _extract_fbank_features(e,t,n=null){return(0,i.spectrogram)(e,this.window,this.config.fft_window_size,this.config.hop_length,{power:2,mel_filters:t,log_mel:`dB`,max_num_frames:n,do_pad:!1,transpose:!0})}async _call(e,{max_length:t=null}={}){return(0,r.validate_audio_inputs)(e,`ClapFeatureExtractor`),{input_features:(await this._get_input_mel(e,t??this.config.nb_max_samples,this.config.truncation,this.config.padding)).unsqueeze_(0)}}}}),"./src/models/clip/image_processing_clip.js":((e,t,n)=>{n.r(t),n.d(t,{CLIPFeatureExtractor:()=>a,CLIPImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{}class a extends i{}}),"./src/models/convnext/image_processing_convnext.js":((e,t,n)=>{n.r(t),n.d(t,{ConvNextFeatureExtractor:()=>a,ConvNextImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{constructor(e){super(e),this.crop_pct=this.config.crop_pct??224/256}async resize(e){let t=this.size?.shortest_edge;if(t===void 0)throw Error(`Size dictionary must contain 'shortest_edge' key.`);if(t<384){let n=Math.floor(t/this.crop_pct),[r,i]=this.get_resize_output_image_size(e,{shortest_edge:n});e=await e.resize(r,i,{resample:this.resample}),e=await e.center_crop(t,t)}else e=await e.resize(t,t,{resample:this.resample});return e}}class a extends i{}}),"./src/models/dac/feature_extraction_dac.js":((e,t,n)=>{n.r(t),n.d(t,{DacFeatureExtractor:()=>i});var r=n(`./src/models/encodec/feature_extraction_encodec.js`);class i extends r.EncodecFeatureExtractor{}}),"./src/models/deit/image_processing_deit.js":((e,t,n)=>{n.r(t),n.d(t,{DeiTFeatureExtractor:()=>a,DeiTImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{}class a extends i{}}),"./src/models/detr/image_processing_detr.js":((e,t,n)=>{n.r(t),n.d(t,{DetrFeatureExtractor:()=>o,DetrImageProcessor:()=>a});var r=n(`./src/base/image_processors_utils.js`),i=n(`./src/utils/tensor.js`);class a extends r.ImageProcessor{async _call(e){let t=await super._call(e),n=[t.pixel_values.dims[0],64,64],r=(0,i.full)(n,1n);return{...t,pixel_mask:r}}post_process_object_detection(...e){return(0,r.post_process_object_detection)(...e)}post_process_panoptic_segmentation(...e){return(0,r.post_process_panoptic_segmentation)(...e)}post_process_instance_segmentation(...e){return(0,r.post_process_instance_segmentation)(...e)}}class o extends a{}}),"./src/models/dinov3_vit/image_processing_dinov3_vit.js":((e,t,n)=>{n.r(t),n.d(t,{DINOv3ViTImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{}}),"./src/models/donut/image_processing_donut.js":((e,t,n)=>{n.r(t),n.d(t,{DonutFeatureExtractor:()=>a,DonutImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{pad_image(e,t,n,r={}){let[i,a,o]=t,s=this.image_mean;Array.isArray(this.image_mean)||(s=Array(o).fill(s));let c=this.image_std;Array.isArray(c)||(c=Array(o).fill(s));let l=s.map((e,t)=>-e/c[t]);return super.pad_image(e,t,n,{center:!0,constant_values:l,...r})}}class a extends i{}}),"./src/models/dpt/image_processing_dpt.js":((e,t,n)=>{n.r(t),n.d(t,{DPTFeatureExtractor:()=>a,DPTImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{}class a extends i{}}),"./src/models/efficientnet/image_processing_efficientnet.js":((e,t,n)=>{n.r(t),n.d(t,{EfficientNetImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{constructor(e){super(e),this.include_top=this.config.include_top??!0,this.include_top&&(this.image_std=this.image_std.map(e=>e*e))}}}),"./src/models/encodec/feature_extraction_encodec.js":((e,t,n)=>{n.r(t),n.d(t,{EncodecFeatureExtractor:()=>a});var r=n(`./src/base/feature_extraction_utils.js`),i=n(`./src/utils/tensor.js`);class a extends r.FeatureExtractor{async _call(e){(0,r.validate_audio_inputs)(e,`EncodecFeatureExtractor`),e instanceof Float64Array&&(e=new Float32Array(e));let t=this.config.feature_size;if(e.length%t!==0)throw Error(`The length of the audio data must be a multiple of the number of channels (${t}).`);let n=[1,t,e.length/t];return{input_values:new i.Tensor(`float32`,e,n)}}}}),"./src/models/feature_extractors.js":((e,t,n)=>{n.r(t),n.d(t,{ASTFeatureExtractor:()=>r.ASTFeatureExtractor,ClapFeatureExtractor:()=>a.ClapFeatureExtractor,DacFeatureExtractor:()=>o.DacFeatureExtractor,EncodecFeatureExtractor:()=>i.EncodecFeatureExtractor,Gemma3nAudioFeatureExtractor:()=>s.Gemma3nAudioFeatureExtractor,ImageFeatureExtractor:()=>_.ImageProcessor,MoonshineFeatureExtractor:()=>c.MoonshineFeatureExtractor,ParakeetFeatureExtractor:()=>l.ParakeetFeatureExtractor,PyAnnoteFeatureExtractor:()=>u.PyAnnoteFeatureExtractor,SeamlessM4TFeatureExtractor:()=>d.SeamlessM4TFeatureExtractor,SnacFeatureExtractor:()=>f.SnacFeatureExtractor,SpeechT5FeatureExtractor:()=>p.SpeechT5FeatureExtractor,Wav2Vec2FeatureExtractor:()=>m.Wav2Vec2FeatureExtractor,WeSpeakerFeatureExtractor:()=>h.WeSpeakerFeatureExtractor,WhisperFeatureExtractor:()=>g.WhisperFeatureExtractor});var r=n(`./src/models/audio_spectrogram_transformer/feature_extraction_audio_spectrogram_transformer.js`),i=n(`./src/models/encodec/feature_extraction_encodec.js`),a=n(`./src/models/clap/feature_extraction_clap.js`),o=n(`./src/models/dac/feature_extraction_dac.js`),s=n(`./src/models/gemma3n/feature_extraction_gemma3n.js`),c=n(`./src/models/moonshine/feature_extraction_moonshine.js`),l=n(`./src/models/parakeet/feature_extraction_parakeet.js`),u=n(`./src/models/pyannote/feature_extraction_pyannote.js`),d=n(`./src/models/seamless_m4t/feature_extraction_seamless_m4t.js`),f=n(`./src/models/snac/feature_extraction_snac.js`),p=n(`./src/models/speecht5/feature_extraction_speecht5.js`),m=n(`./src/models/wav2vec2/feature_extraction_wav2vec2.js`),h=n(`./src/models/wespeaker/feature_extraction_wespeaker.js`),g=n(`./src/models/whisper/feature_extraction_whisper.js`),_=n(`./src/base/image_processors_utils.js`)}),"./src/models/florence2/processing_florence2.js":((e,t,n)=>{n.r(t),n.d(t,{Florence2Processor:()=>o});var r=n(`./src/base/processing_utils.js`),i=n(`./src/models/auto/image_processing_auto.js`),a=n(`./src/tokenizers.js`);class o extends r.Processor{static tokenizer_class=a.AutoTokenizer;static image_processor_class=i.AutoImageProcessor;constructor(e,t,n){super(e,t,n);let{tasks_answer_post_processing_type:r,task_prompts_without_inputs:i,task_prompts_with_input:a}=this.image_processor.config;this.tasks_answer_post_processing_type=new Map(Object.entries(r??{})),this.task_prompts_without_inputs=new Map(Object.entries(i??{})),this.task_prompts_with_input=new Map(Object.entries(a??{})),this.regexes={quad_boxes:/(.+?)<loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)>/gm,bboxes:/([^<]+)?<loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)>/gm},this.size_per_bin=1e3}construct_prompts(e){typeof e==`string`&&(e=[e]);let t=[];for(let n of e)if(this.task_prompts_without_inputs.has(n))t.push(this.task_prompts_without_inputs.get(n));else{for(let[e,r]of this.task_prompts_with_input)if(n.includes(e)){t.push(r.replaceAll(`{input}`,n).replaceAll(e,``));break}t.length!==e.length&&t.push(n)}return t}post_process_generation(e,t,n){let r=this.tasks_answer_post_processing_type.get(t)??`pure_text`;e=e.replaceAll(`<s>`,``).replaceAll(`</s>`,``);let i;switch(r){case`pure_text`:i=e;break;case`description_with_bboxes`:case`bboxes`:case`phrase_grounding`:case`ocr`:let a=r===`ocr`?`quad_boxes`:`bboxes`,o=e.matchAll(this.regexes[a]),s=[],c=[];for(let[e,t,...r]of o)s.push(t?t.trim():s.at(-1)??``),c.push(r.map((e,t)=>(Number(e)+.5)/this.size_per_bin*n[t%2]));i={labels:s,[a]:c};break;default:throw Error(`Task "${t}" (of type "${r}") not yet implemented.`)}return{[t]:i}}async _call(e,t=null,n={}){if(!e&&!t)throw Error(`Either text or images must be provided`);let r=await this.image_processor(e,n),i=t?this.tokenizer(this.construct_prompts(t),n):{};return{...r,...i}}}}),"./src/models/gemma3n/feature_extraction_gemma3n.js":((e,t,n)=>{n.r(t),n.d(t,{Gemma3nAudioFeatureExtractor:()=>o});var r=n(`./src/base/feature_extraction_utils.js`),i=n(`./src/utils/tensor.js`),a=n(`./src/utils/audio.js`);class o extends r.FeatureExtractor{constructor(e){super(e);let{fft_length:t,feature_size:n,min_frequency:r,max_frequency:i,sampling_rate:o,frame_length:s}=this.config;this.mel_filters=(0,a.mel_filter_bank)(Math.floor(1+t/2),n,r,i,o,null,`htk`,!1),this.window=(0,a.window_function)(s,`hann`)}async _extract_fbank_features(e,t){return(0,a.spectrogram)(e,this.window,this.config.frame_length,this.config.hop_length,{fft_length:this.config.fft_length,center:!1,onesided:!0,preemphasis:this.config.preemphasis,preemphasis_htk_flavor:this.config.preemphasis_htk_flavor,mel_filters:this.mel_filters,log_mel:`log`,mel_floor:this.config.mel_floor,remove_dc_offset:!1,transpose:!0})}async _call(e,{max_length:t=48e4,truncation:n=!0,padding:a=!0,pad_to_multiple_of:o=128}={}){if((0,r.validate_audio_inputs)(e,`Gemma3nAudioFeatureExtractor`),n&&e.length>t&&(e=e.slice(0,t)),a&&e.length%o!==0){let t=o-e.length%o,n=new Float64Array(e.length+t);n.set(e),this.config.padding_value!==0&&n.fill(this.config.padding_value,e.length),e=n}let s=await this._extract_fbank_features(e,this.config.max_length),c=(0,i.full)([1,s.dims[0]],!0);return{input_features:s.unsqueeze_(0),input_features_mask:c}}}}),"./src/models/gemma3n/processing_gemma3n.js":((e,t,n)=>{n.r(t),n.d(t,{Gemma3nProcessor:()=>s});var r=n(`./src/base/processing_utils.js`),i=n(`./src/models/auto/image_processing_auto.js`),a=n(`./src/models/auto/feature_extraction_auto.js`),o=n(`./src/tokenizers.js`);n(`./src/utils/image.js`),n(`./src/utils/audio.js`);class s extends r.Processor{static image_processor_class=i.AutoImageProcessor;static feature_extractor_class=a.AutoFeatureExtractor;static tokenizer_class=o.AutoTokenizer;static uses_processor_config=!0;static uses_chat_template_file=!0;constructor(e,t,n){super(e,t,n),this.audio_seq_length=this.config.audio_seq_length,this.image_seq_length=this.config.image_seq_length;let{audio_token_id:r,boa_token:i,audio_token:a,eoa_token:o,image_token_id:s,boi_token:c,image_token:l,eoi_token:u}=this.tokenizer.config;this.audio_token_id=r,this.boa_token=i,this.audio_token=a,this.full_audio_sequence=`\n\n${i}${a.repeat(this.audio_seq_length)}${o}\n\n`,this.image_token_id=s,this.boi_token=c,this.image_token=l,this.full_image_sequence=`\n\n${c}${l.repeat(this.image_seq_length)}${u}\n\n`}async _call(e,t=null,n=null,r={}){typeof e==`string`&&(e=[e]);let i;n&&(i=await this.feature_extractor(n,r),e=e.map(e=>e.replaceAll(this.audio_token,this.full_audio_sequence)));let a;return t&&(a=await this.image_processor(t,r),e=e.map(e=>e.replaceAll(this.image_token,this.full_image_sequence))),{...this.tokenizer(e,r),...a,...i}}}}),"./src/models/glpn/image_processing_glpn.js":((e,t,n)=>{n.r(t),n.d(t,{GLPNFeatureExtractor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{}}),"./src/models/grounding_dino/image_processing_grounding_dino.js":((e,t,n)=>{n.r(t),n.d(t,{GroundingDinoImageProcessor:()=>a});var r=n(`./src/base/image_processors_utils.js`),i=n(`./src/utils/tensor.js`);class a extends r.ImageProcessor{async _call(e){let t=await super._call(e),n=t.pixel_values.dims,r=(0,i.ones)([n[0],n[2],n[3]]);return{...t,pixel_mask:r}}}}),"./src/models/grounding_dino/processing_grounding_dino.js":((e,t,n)=>{n.r(t),n.d(t,{GroundingDinoProcessor:()=>c});var r=n(`./src/base/processing_utils.js`),i=n(`./src/models/auto/image_processing_auto.js`),a=n(`./src/tokenizers.js`),o=n(`./src/base/image_processors_utils.js`);function s(e,t){let n=e.dims.at(-1)-1,r=e.tolist();r.fill(!1,0,1),r.fill(!1,n);let i=t.tolist();return r.map((e,t)=>e?t:null).filter(e=>e!==null).map(e=>i[e])}class c extends r.Processor{static tokenizer_class=a.AutoTokenizer;static image_processor_class=i.AutoImageProcessor;async _call(e,t,n={}){let r=e?await this.image_processor(e,n):{};return{...t?this.tokenizer(t,n):{},...r}}post_process_grounded_object_detection(e,t,{box_threshold:n=.25,text_threshold:r=.25,target_sizes:i=null}={}){let{logits:a,pred_boxes:c}=e,l=a.dims[0];if(i!==null&&i.length!==l)throw Error(`Make sure that you pass in as many target sizes as the batch dimension of the logits`);let u=a.dims.at(1),d=a.sigmoid(),f=d.max(-1).tolist(),p=c.tolist().map(e=>e.map(e=>(0,o.center_to_corners_format)(e))),m=[];for(let e=0;e<l;++e){let a=i===null?null:i[e];a!==null&&(p[e]=p[e].map(e=>e.map((e,t)=>e*a[(t+1)%2])));let o=f[e],c=[],l=[],h=[];for(let i=0;i<u;++i){let a=o[i];if(a<=n)continue;let u=p[e][i],f=d[e][i];c.push(a),h.push(u);let m=s(f.gt(r),t[e]);l.push(m)}m.push({scores:c,boxes:h,labels:this.batch_decode(l)})}return m}}}),"./src/models/idefics3/image_processing_idefics3.js":((e,t,n)=>{n.r(t),n.d(t,{Idefics3ImageProcessor:()=>a});var r=n(`./src/base/image_processors_utils.js`),i=n(`./src/utils/tensor.js`);class a extends r.ImageProcessor{constructor(e){super(e),this.do_image_splitting=e.do_image_splitting??!0,this.max_image_size=e.max_image_size}get_resize_for_vision_encoder(e,t){let[n,r]=e.dims.slice(-2),i=r/n;return r>=n?(r=Math.ceil(r/t)*t,n=Math.floor(r/i),n=Math.ceil(n/t)*t):(n=Math.ceil(n/t)*t,r=Math.floor(n*i),r=Math.ceil(r/t)*t),{height:n,width:r}}async _call(e,{do_image_splitting:t=null,return_row_col_info:n=!1}={}){let r;if(!Array.isArray(e))r=[[e]];else{if(e.length===0||!e[0])throw Error(`No images provided.`);r=Array.isArray(e[0])?e:[e]}let a=[],o=[],s=[],c=[],l=[];for(let e of r){let n=await Promise.all(e.map(e=>this.preprocess(e)));c.push(...n.map(e=>e.original_size)),l.push(...n.map(e=>e.reshaped_input_size)),n.forEach(e=>e.pixel_values.unsqueeze_(0));let{longest_edge:r}=this.max_image_size,u;if(t??this.do_image_splitting){let e=Array(n.length),t=Array(n.length);u=await Promise.all(n.map(async(n,a)=>{let o=this.get_resize_for_vision_encoder(n.pixel_values,r),s=await(0,i.interpolate_4d)(n.pixel_values,{size:[o.height,o.width]}),{frames:c,num_splits_h:l,num_splits_w:u}=await this.split_image(s,this.max_image_size);return e[a]=l,t[a]=u,(0,i.cat)(c,0)})),o.push(e),s.push(t)}else{let e=[r,r];u=await Promise.all(n.map(t=>(0,i.interpolate_4d)(t.pixel_values,{size:e}))),o.push(Array(n.length).fill(0)),s.push(Array(n.length).fill(0))}a.push((0,i.cat)(u,0))}let u=a.length,[d,f,p,m]=a[0].dims,h,g;if(u===1)h=a[0].unsqueeze_(0),g=(0,i.full)([u,d,p,m],!0);else{let e=Math.max(...a.map(e=>e.dims.at(0)));g=(0,i.full)([u,e,p,m],!0);let t=g.data,n=e*p*m;for(let r=0;r<u;++r){let o=a[r].dims[0];if(o<e){a[r]=(0,i.cat)([a[r],(0,i.full)([e-o,f,p,m],0)],0);let s=r*n+o*p*m,c=(r+1)*n;t.fill(!1,s,c)}}h=(0,i.stack)(a,0)}return{pixel_values:h,pixel_attention_mask:g,original_sizes:c,reshaped_input_sizes:l,...n?{rows:o,cols:s}:{}}}async split_image(e,{longest_edge:t}){let n=t,r=t,a=[],[o,s]=e.dims.slice(-2),c=0,l=0;if(o>n||s>r){c=Math.ceil(o/n),l=Math.ceil(s/r);let t=Math.ceil(o/c),u=Math.ceil(s/l);for(let n=0;n<c;++n)for(let r=0;r<l;++r){let d,f,p,m;n===c-1?(f=o-t,m=o):(f=n*t,m=(n+1)*t),r===l-1?(d=s-u,p=s):(d=r*u,p=(r+1)*u);let h=[f,d],g=[m,p],_=await(0,i.slice)(e,h,g,[2,3]);a.push(_)}let d=n,f=r;(o!==d||s!==f)&&(e=await(0,i.interpolate_4d)(e,{size:[d,f]}))}return a.push(e),{frames:a,num_splits_h:c,num_splits_w:l}}}}),"./src/models/idefics3/processing_idefics3.js":((e,t,n)=>{n.r(t),n.d(t,{Idefics3Processor:()=>u});var r=n(`./src/base/processing_utils.js`),i=n(`./src/models/auto/image_processing_auto.js`),a=n(`./src/tokenizers.js`);n(`./src/utils/image.js`);var o=n(`./src/utils/core.js`);function s(e,t,n,r,i,a){let o=``;for(let a=0;a<t;++a){for(let t=0;t<n;++t)o+=r+`<row_${a+1}_col_${t+1}>`+i.repeat(e);o+=`
2816
+ `}return o+=`\n${r}${a}`+i.repeat(e)+`${r}`,o}function c(e,t,n,r){return`${t}${r}`+n.repeat(e)+`${t}`}function l(e,t,n,r,i,a){return e===0&&t===0?c(n,r,i,a):s(n,e,t,r,i,a)}class u extends r.Processor{static image_processor_class=i.AutoImageProcessor;static tokenizer_class=a.AutoTokenizer;static uses_processor_config=!0;fake_image_token=`<fake_token_around_image>`;image_token=`<image>`;global_img_token=`<global-img>`;async _call(e,t=null,n={}){n.return_row_col_info??=!0;let r;t&&(r=await this.image_processor(t,n)),Array.isArray(e)||(e=[e]);let i=r.rows??[Array(e.length).fill(0)],a=r.cols??[Array(e.length).fill(0)],s=this.config.image_seq_len,c=[],u=[];for(let t=0;t<e.length;++t){let n=e[t],r=i[t],d=a[t];c.push((0,o.count)(n,this.image_token));let f=r.map((e,t)=>l(e,d[t],s,this.fake_image_token,this.image_token,this.global_img_token)),p=n.split(this.image_token);if(p.length===0)throw Error(`The image token should be present in the text.`);let m=p[0];for(let e=0;e<f.length;++e)m+=f[e]+p[e+1];u.push(m)}return{...this.tokenizer(u),...r}}}}),"./src/models/image_processors.js":((e,t,n)=>{n.r(t),n.d(t,{BeitFeatureExtractor:()=>r.BeitFeatureExtractor,BitImageProcessor:()=>i.BitImageProcessor,CLIPFeatureExtractor:()=>o.CLIPFeatureExtractor,CLIPImageProcessor:()=>o.CLIPImageProcessor,ChineseCLIPFeatureExtractor:()=>a.ChineseCLIPFeatureExtractor,ConvNextFeatureExtractor:()=>s.ConvNextFeatureExtractor,ConvNextImageProcessor:()=>s.ConvNextImageProcessor,DINOv3ViTImageProcessor:()=>u.DINOv3ViTImageProcessor,DPTFeatureExtractor:()=>f.DPTFeatureExtractor,DPTImageProcessor:()=>f.DPTImageProcessor,DeiTFeatureExtractor:()=>c.DeiTFeatureExtractor,DeiTImageProcessor:()=>c.DeiTImageProcessor,DetrFeatureExtractor:()=>l.DetrFeatureExtractor,DetrImageProcessor:()=>l.DetrImageProcessor,DonutFeatureExtractor:()=>d.DonutFeatureExtractor,DonutImageProcessor:()=>d.DonutImageProcessor,EfficientNetImageProcessor:()=>p.EfficientNetImageProcessor,GLPNFeatureExtractor:()=>m.GLPNFeatureExtractor,GroundingDinoImageProcessor:()=>h.GroundingDinoImageProcessor,Idefics3ImageProcessor:()=>g.Idefics3ImageProcessor,JinaCLIPImageProcessor:()=>v.JinaCLIPImageProcessor,LlavaOnevisionImageProcessor:()=>y.LlavaOnevisionImageProcessor,Mask2FormerImageProcessor:()=>b.Mask2FormerImageProcessor,MaskFormerFeatureExtractor:()=>x.MaskFormerFeatureExtractor,MaskFormerImageProcessor:()=>x.MaskFormerImageProcessor,MobileNetV1FeatureExtractor:()=>S.MobileNetV1FeatureExtractor,MobileNetV1ImageProcessor:()=>S.MobileNetV1ImageProcessor,MobileNetV2FeatureExtractor:()=>C.MobileNetV2FeatureExtractor,MobileNetV2ImageProcessor:()=>C.MobileNetV2ImageProcessor,MobileNetV3FeatureExtractor:()=>w.MobileNetV3FeatureExtractor,MobileNetV3ImageProcessor:()=>w.MobileNetV3ImageProcessor,MobileNetV4FeatureExtractor:()=>T.MobileNetV4FeatureExtractor,MobileNetV4ImageProcessor:()=>T.MobileNetV4ImageProcessor,MobileViTFeatureExtractor:()=>E.MobileViTFeatureExtractor,MobileViTImageProcessor:()=>E.MobileViTImageProcessor,NougatImageProcessor:()=>D.NougatImageProcessor,OwlViTFeatureExtractor:()=>k.OwlViTFeatureExtractor,OwlViTImageProcessor:()=>k.OwlViTImageProcessor,Owlv2ImageProcessor:()=>O.Owlv2ImageProcessor,Phi3VImageProcessor:()=>A.Phi3VImageProcessor,PixtralImageProcessor:()=>ee.PixtralImageProcessor,PvtImageProcessor:()=>te.PvtImageProcessor,Qwen2VLImageProcessor:()=>ne.Qwen2VLImageProcessor,RTDetrImageProcessor:()=>j.RTDetrImageProcessor,Sam2ImageProcessor:()=>ie.Sam2ImageProcessor,Sam3ImageProcessor:()=>ae.Sam3ImageProcessor,SamImageProcessor:()=>re.SamImageProcessor,SegformerFeatureExtractor:()=>oe.SegformerFeatureExtractor,SegformerImageProcessor:()=>oe.SegformerImageProcessor,SiglipImageProcessor:()=>se.SiglipImageProcessor,SmolVLMImageProcessor:()=>M.SmolVLMImageProcessor,Swin2SRImageProcessor:()=>N.Swin2SRImageProcessor,VLMImageProcessor:()=>_.VLMImageProcessor,ViTFeatureExtractor:()=>ce.ViTFeatureExtractor,ViTImageProcessor:()=>ce.ViTImageProcessor,VitMatteImageProcessor:()=>le.VitMatteImageProcessor,VitPoseImageProcessor:()=>ue.VitPoseImageProcessor,YolosFeatureExtractor:()=>de.YolosFeatureExtractor,YolosImageProcessor:()=>de.YolosImageProcessor});var r=n(`./src/models/beit/image_processing_beit.js`),i=n(`./src/models/bit/image_processing_bit.js`),a=n(`./src/models/chinese_clip/image_processing_chinese_clip.js`),o=n(`./src/models/clip/image_processing_clip.js`),s=n(`./src/models/convnext/image_processing_convnext.js`),c=n(`./src/models/deit/image_processing_deit.js`),l=n(`./src/models/detr/image_processing_detr.js`),u=n(`./src/models/dinov3_vit/image_processing_dinov3_vit.js`),d=n(`./src/models/donut/image_processing_donut.js`),f=n(`./src/models/dpt/image_processing_dpt.js`),p=n(`./src/models/efficientnet/image_processing_efficientnet.js`),m=n(`./src/models/glpn/image_processing_glpn.js`),h=n(`./src/models/grounding_dino/image_processing_grounding_dino.js`),g=n(`./src/models/idefics3/image_processing_idefics3.js`),_=n(`./src/models/janus/image_processing_janus.js`),v=n(`./src/models/jina_clip/image_processing_jina_clip.js`),y=n(`./src/models/llava_onevision/image_processing_llava_onevision.js`),b=n(`./src/models/mask2former/image_processing_mask2former.js`),x=n(`./src/models/maskformer/image_processing_maskformer.js`),S=n(`./src/models/mobilenet_v1/image_processing_mobilenet_v1.js`),C=n(`./src/models/mobilenet_v2/image_processing_mobilenet_v2.js`),w=n(`./src/models/mobilenet_v3/image_processing_mobilenet_v3.js`),T=n(`./src/models/mobilenet_v4/image_processing_mobilenet_v4.js`),E=n(`./src/models/mobilevit/image_processing_mobilevit.js`),D=n(`./src/models/nougat/image_processing_nougat.js`),O=n(`./src/models/owlv2/image_processing_owlv2.js`),k=n(`./src/models/owlvit/image_processing_owlvit.js`),A=n(`./src/models/phi3_v/image_processing_phi3_v.js`),ee=n(`./src/models/pixtral/image_processing_pixtral.js`),te=n(`./src/models/pvt/image_processing_pvt.js`),ne=n(`./src/models/qwen2_vl/image_processing_qwen2_vl.js`),j=n(`./src/models/rt_detr/image_processing_rt_detr.js`),re=n(`./src/models/sam/image_processing_sam.js`),ie=n(`./src/models/sam2/image_processing_sam2.js`),ae=n(`./src/models/sam3/image_processing_sam3.js`),oe=n(`./src/models/segformer/image_processing_segformer.js`),se=n(`./src/models/siglip/image_processing_siglip.js`),M=n(`./src/models/smolvlm/image_processing_smolvlm.js`),N=n(`./src/models/swin2sr/image_processing_swin2sr.js`),ce=n(`./src/models/vit/image_processing_vit.js`),le=n(`./src/models/vitmatte/image_processing_vitmatte.js`),ue=n(`./src/models/vitpose/image_processing_vitpose.js`),de=n(`./src/models/yolos/image_processing_yolos.js`)}),"./src/models/janus/image_processing_janus.js":((e,t,n)=>{n.r(t),n.d(t,{VLMImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{constructor(e){super({do_pad:!0,pad_size:{width:e.image_size,height:e.image_size},...e}),this.constant_values=this.config.background_color.map(e=>e*this.rescale_factor)}pad_image(e,t,n,r){return super.pad_image(e,t,n,{constant_values:this.constant_values,center:!0,...r})}}}),"./src/models/janus/processing_janus.js":((e,t,n)=>{n.r(t),n.d(t,{VLChatProcessor:()=>l});var r=n(`./src/base/processing_utils.js`),i=n(`./src/models/auto/image_processing_auto.js`),a=n(`./src/tokenizers.js`),o=n(`./src/utils/core.js`),s=n(`./src/utils/tensor.js`),c=n(`./src/utils/image.js`);class l extends r.Processor{static image_processor_class=i.AutoImageProcessor;static tokenizer_class=a.AutoTokenizer;static uses_processor_config=!0;constructor(e,t,n){super(e,t,n),this.image_tag=this.config.image_tag,this.image_start_tag=this.config.image_start_tag,this.image_end_tag=this.config.image_end_tag,this.num_image_tokens=this.config.num_image_tokens}async _call(e,{images:t=null,chat_template:n=`default`}={}){t?Array.isArray(t)||(t=[t]):t=await Promise.all(e.filter(e=>e.images).flatMap(e=>e.images).map(e=>c.RawImage.read(e)));let r=this.tokenizer,i=r.apply_chat_template(e,{tokenize:!1,add_generation_prompt:!0,chat_template:n}),a=e=>r.encode(e,{add_special_tokens:!1}),l=i.split(this.image_tag),u=l.length-1;if(t.length!==u)throw Error(`Number of images provided (${t.length}) does not match number of "${this.image_tag}" image tags (${u})`);let[d,f,p]=r.model.convert_tokens_to_ids([this.image_tag,this.image_start_tag,this.image_end_tag]),m=a(l[0]),h=Array(m.length).fill(!1);for(let e=1;e<l.length;++e){let t=Array(this.num_image_tokens).fill(d),n=a(l[e]);m=(0,o.mergeArrays)(m,[f],t,[p],n);let r=Array(this.num_image_tokens).fill(!0);h=(0,o.mergeArrays)(h,[!1],r,[!1],Array(n.length).fill(!1))}let g=[1,m.length],_={input_ids:new s.Tensor(`int64`,m,g),attention_mask:new s.Tensor(`int64`,Array(m.length).fill(1),g),images_seq_mask:new s.Tensor(`bool`,h,g),images_emb_mask:new s.Tensor(`bool`,Array(u*this.num_image_tokens).fill(!0),[1,u,this.num_image_tokens])};if(t&&t.length>0){let e=await this.image_processor(t);return e.pixel_values.unsqueeze_(0),{..._,...e}}return _}}}),"./src/models/jina_clip/image_processing_jina_clip.js":((e,t,n)=>{n.r(t),n.d(t,{JinaCLIPImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{constructor(e){let{resize_mode:t,fill_color:n,interpolation:r,size:i,...a}=e,o=t===`squash`?{width:i,height:i}:t===`shortest`?{shortest_edge:i}:{longest_edge:i},s=r===`bicubic`?3:2;super({...a,size:o,resample:s,do_center_crop:!0,crop_size:i,do_normalize:!0})}}}),"./src/models/jina_clip/processing_jina_clip.js":((e,t,n)=>{n.r(t),n.d(t,{JinaCLIPProcessor:()=>o});var r=n(`./src/base/processing_utils.js`),i=n(`./src/models/auto/image_processing_auto.js`),a=n(`./src/tokenizers.js`);class o extends r.Processor{static tokenizer_class=a.AutoTokenizer;static image_processor_class=i.AutoImageProcessor;async _call(e=null,t=null,n={}){if(!e&&!t)throw Error(`Either text or images must be provided`);let r=e?this.tokenizer(e,n):{},i=t?await this.image_processor(t,n):{};return{...r,...i}}}}),"./src/models/llava/processing_llava.js":((e,t,n)=>{n.r(t),n.d(t,{LlavaProcessor:()=>o});var r=n(`./src/base/processing_utils.js`),i=n(`./src/models/auto/image_processing_auto.js`),a=n(`./src/tokenizers.js`);class o extends r.Processor{static tokenizer_class=a.AutoTokenizer;static image_processor_class=i.AutoImageProcessor;static uses_processor_config=!0;async _call(e,t=null,n={}){let r=await this.image_processor(e,n);if(t){let[e,n]=r.pixel_values.dims.slice(-2),{image_token:i,patch_size:a,num_additional_image_tokens:o}=this.config,s=Math.floor(e/a)*Math.floor(n/a)+o;t=structuredClone(t),Array.isArray(t)||(t=[t]);for(let e=0;e<t.length;++e)t[e]=t[e].replace(i,i.repeat(s))}let i=t?this.tokenizer(t,n):{};return{...r,...i}}}}),"./src/models/llava_onevision/image_processing_llava_onevision.js":((e,t,n)=>{n.r(t),n.d(t,{LlavaOnevisionImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{}}),"./src/models/mask2former/image_processing_mask2former.js":((e,t,n)=>{n.r(t),n.d(t,{Mask2FormerImageProcessor:()=>i});var r=n(`./src/models/maskformer/image_processing_maskformer.js`);class i extends r.MaskFormerImageProcessor{}}),"./src/models/maskformer/image_processing_maskformer.js":((e,t,n)=>{n.r(t),n.d(t,{MaskFormerFeatureExtractor:()=>a,MaskFormerImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{post_process_panoptic_segmentation(...e){return(0,r.post_process_panoptic_segmentation)(...e)}post_process_instance_segmentation(...e){return(0,r.post_process_instance_segmentation)(...e)}}class a extends i{}}),"./src/models/mgp_str/processing_mgp_str.js":((e,t,n)=>{n.r(t),n.d(t,{MgpstrProcessor:()=>c});var r=n(`./src/base/processing_utils.js`),i=n(`./src/models/auto/image_processing_auto.js`),a=n(`./src/tokenizers.js`),o=n(`./src/utils/maths.js`);let s={char:[`char_decode`,1],bpe:[`bpe_decode`,2],wp:[`wp_decode`,102]};class c extends r.Processor{static tokenizer_class=a.AutoTokenizer;static image_processor_class=i.AutoImageProcessor;get char_tokenizer(){return this.components.char_tokenizer}get bpe_tokenizer(){return this.components.bpe_tokenizer}get wp_tokenizer(){return this.components.wp_tokenizer}_decode_helper(e,t){if(!s.hasOwnProperty(t))throw Error(`Format ${t} is not supported.`);let[n,r]=s[t],i=this[n].bind(this),[a,c]=e.dims,l=[],u=[],d=e.tolist();for(let e=0;e<a;++e){let t=d[e],n=[],i=[];for(let e=1;e<c;++e){let[a,s]=(0,o.max)((0,o.softmax)(t[e]));if(i.push(a),s==r)break;n.push(s)}let a=i.length>0?i.reduce((e,t)=>e*t,1):0;u.push(n),l.push(a)}return[i(u),l]}char_decode(e){return this.char_tokenizer.batch_decode(e).map(e=>e.replaceAll(` `,``))}bpe_decode(e){return this.bpe_tokenizer.batch_decode(e)}wp_decode(e){return this.wp_tokenizer.batch_decode(e).map(e=>e.replaceAll(` `,``))}batch_decode([e,t,n]){let[r,i]=this._decode_helper(e,`char`),[a,s]=this._decode_helper(t,`bpe`),[c,l]=this._decode_helper(n,`wp`),u=[],d=[];for(let e=0;e<r.length;++e){let[t,n]=(0,o.max)([i[e],s[e],l[e]]);u.push([r[e],a[e],c[e]][n]),d.push(t)}return{generated_text:u,scores:d,char_preds:r,bpe_preds:a,wp_preds:c}}static async from_pretrained(...e){let t=await super.from_pretrained(...e),n=await a.AutoTokenizer.from_pretrained(`Xenova/gpt2`),r=await a.AutoTokenizer.from_pretrained(`Xenova/bert-base-uncased`);return t.components={image_processor:t.image_processor,char_tokenizer:t.tokenizer,bpe_tokenizer:n,wp_tokenizer:r},t}async _call(e,t=null){let n=await this.image_processor(e);return t&&(n.labels=this.tokenizer(t).input_ids),n}}}),"./src/models/mobilenet_v1/image_processing_mobilenet_v1.js":((e,t,n)=>{n.r(t),n.d(t,{MobileNetV1FeatureExtractor:()=>a,MobileNetV1ImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{}class a extends i{}}),"./src/models/mobilenet_v2/image_processing_mobilenet_v2.js":((e,t,n)=>{n.r(t),n.d(t,{MobileNetV2FeatureExtractor:()=>a,MobileNetV2ImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{}class a extends i{}}),"./src/models/mobilenet_v3/image_processing_mobilenet_v3.js":((e,t,n)=>{n.r(t),n.d(t,{MobileNetV3FeatureExtractor:()=>a,MobileNetV3ImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{}class a extends i{}}),"./src/models/mobilenet_v4/image_processing_mobilenet_v4.js":((e,t,n)=>{n.r(t),n.d(t,{MobileNetV4FeatureExtractor:()=>a,MobileNetV4ImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{}class a extends i{}}),"./src/models/mobilevit/image_processing_mobilevit.js":((e,t,n)=>{n.r(t),n.d(t,{MobileViTFeatureExtractor:()=>a,MobileViTImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{}class a extends i{}}),"./src/models/moonshine/feature_extraction_moonshine.js":((e,t,n)=>{n.r(t),n.d(t,{MoonshineFeatureExtractor:()=>a});var r=n(`./src/base/feature_extraction_utils.js`),i=n(`./src/utils/tensor.js`);class a extends r.FeatureExtractor{async _call(e){(0,r.validate_audio_inputs)(e,`MoonshineFeatureExtractor`),e instanceof Float64Array&&(e=new Float32Array(e));let t=[1,e.length];return{input_values:new i.Tensor(`float32`,e,t)}}}}),"./src/models/moonshine/processing_moonshine.js":((e,t,n)=>{n.r(t),n.d(t,{MoonshineProcessor:()=>o});var r=n(`./src/models/auto/feature_extraction_auto.js`),i=n(`./src/tokenizers.js`),a=n(`./src/base/processing_utils.js`);class o extends a.Processor{static tokenizer_class=i.AutoTokenizer;static feature_extractor_class=r.AutoFeatureExtractor;async _call(e){return await this.feature_extractor(e)}}}),"./src/models/nougat/image_processing_nougat.js":((e,t,n)=>{n.r(t),n.d(t,{NougatImageProcessor:()=>i});var r=n(`./src/models/donut/image_processing_donut.js`);class i extends r.DonutImageProcessor{}}),"./src/models/owlv2/image_processing_owlv2.js":((e,t,n)=>{n.r(t),n.d(t,{Owlv2ImageProcessor:()=>i});var r=n(`./src/models/owlvit/image_processing_owlvit.js`);class i extends r.OwlViTImageProcessor{}}),"./src/models/owlvit/image_processing_owlvit.js":((e,t,n)=>{n.r(t),n.d(t,{OwlViTFeatureExtractor:()=>a,OwlViTImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{post_process_object_detection(...e){return(0,r.post_process_object_detection)(...e)}}class a extends i{}}),"./src/models/owlvit/processing_owlvit.js":((e,t,n)=>{n.r(t),n.d(t,{OwlViTProcessor:()=>o});var r=n(`./src/base/processing_utils.js`),i=n(`./src/models/auto/image_processing_auto.js`),a=n(`./src/tokenizers.js`);class o extends r.Processor{static tokenizer_class=a.AutoTokenizer;static image_processor_class=i.AutoImageProcessor}}),"./src/models/paligemma/processing_paligemma.js":((e,t,n)=>{n.r(t),n.d(t,{PaliGemmaProcessor:()=>c});var r=n(`./src/base/processing_utils.js`),i=n(`./src/models/auto/image_processing_auto.js`),a=n(`./src/tokenizers.js`);let o=`<image>`;function s(e,t,n,r,i){return`${r.repeat(n*i)}${t}${e}\n`}class c extends r.Processor{static tokenizer_class=a.AutoTokenizer;static image_processor_class=i.AutoImageProcessor;static uses_processor_config=!1;async _call(e,t=null,n={}){t||=(console.warn(`You are using PaliGemma without a text prefix. It will perform as a picture-captioning model.`),``),Array.isArray(e)||(e=[e]),Array.isArray(t)||(t=[t]);let r=this.tokenizer.bos_token,i=this.image_processor.config.image_seq_length,a;t.some(e=>e.includes(o))?a=t.map(e=>{let t=e.replaceAll(o,o.repeat(i)),n=t.lastIndexOf(o),a=n===-1?0:n+7;return t.slice(0,a)+r+t.slice(a)+`
2817
+ `}):(console.warn("You are passing both `text` and `images` to `PaliGemmaProcessor`. The processor expects special image tokens in the text, as many tokens as there are images per each text. It is recommended to add `<image>` tokens in the very beginning of your text. For this call, we will infer how many images each text has and add special tokens."),a=t.map(t=>s(t,r,i,o,e.length)));let c=this.tokenizer(a,n);return{...await this.image_processor(e,n),...c}}}}),"./src/models/parakeet/feature_extraction_parakeet.js":((e,t,n)=>{n.r(t),n.d(t,{ParakeetFeatureExtractor:()=>o});var r=n(`./src/base/feature_extraction_utils.js`),i=n(`./src/utils/tensor.js`),a=n(`./src/utils/audio.js`);class o extends r.FeatureExtractor{constructor(e){super(e),this.config.mel_filters??=(0,a.mel_filter_bank)(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,this.config.sampling_rate/2,this.config.sampling_rate,`slaney`,`slaney`);let t=(0,a.window_function)(this.config.win_length,`hann`,{periodic:!1});this.window=new Float64Array(this.config.n_fft);let n=Math.floor((this.config.n_fft-this.config.win_length)/2);this.window.set(t,n)}async _extract_fbank_features(e){let t=this.config.preemphasis;e=new Float64Array(e);for(let n=e.length-1;n>=1;--n)e[n]-=t*e[n-1];return await(0,a.spectrogram)(e,this.window,this.window.length,this.config.hop_length,{fft_length:this.config.n_fft,power:2,mel_filters:this.config.mel_filters,log_mel:`log`,mel_floor:-1/0,pad_mode:`constant`,center:!0,transpose:!0,mel_offset:2**-24})}async _call(e){(0,r.validate_audio_inputs)(e,`ParakeetFeatureExtractor`);let t=await this._extract_fbank_features(e),n=Math.floor((e.length+Math.floor(this.config.n_fft/2)*2-this.config.n_fft)/this.config.hop_length),a=t.data;a.fill(0,n*t.dims[1]);let[o,s]=t.dims,c=new Float64Array(s),l=new Float64Array(s);for(let e=0;e<n;++e){let t=e*s;for(let e=0;e<s;++e){let n=a[t+e];c[e]+=n,l[e]+=n*n}}let u=n>1?n-1:1;for(let e=0;e<s;++e){let t=c[e]/n,r=(l[e]-n*t*t)/u,i=1/(Math.sqrt(r)+1e-5);for(let r=0;r<n;++r){let n=r*s+e;a[n]=(a[n]-t)*i}}let d=new BigInt64Array(o);return d.fill(1n,0,n),{input_features:t.unsqueeze_(0),attention_mask:new i.Tensor(`int64`,d,[1,o])}}}}),"./src/models/phi3_v/image_processing_phi3_v.js":((e,t,n)=>{n.r(t),n.d(t,{Phi3VImageProcessor:()=>l});var r=n(`./src/base/image_processors_utils.js`),i=n(`./src/utils/tensor.js`);let a=[2,3],{ceil:o,floor:s,sqrt:c}=Math;class l extends r.ImageProcessor{constructor(e){super({...e,do_normalize:!0,do_pad:!0,pad_size:`custom`,do_convert_rgb:!0,do_resize:!0}),this._num_crops=e.num_crops}calc_num_image_tokens_from_image_size(e,t){let{num_img_tokens:n}=this.config;return s((s(t/336)*s(e/336)+1)*n+1+(s(t/336)+1)*c(n))}get_resize_output_image_size(e,t){let n=this._num_crops,[r,i]=e.size,a=r/i,o=1;for(;o*Math.ceil(o/a)<=n;)o+=1;--o;let s=Math.floor(o*336);return[s,Math.floor(s/a)]}pad_image(e,t,n,r={}){let[i,a]=t,s=336*o(i/336),c=336*o(a/336),l=[1,1,1].map((e,t)=>(e-this.image_mean[t])/this.image_std[t]);return super.pad_image(e,t,{width:c,height:s},{center:!0,constant_values:l,...r})}async _call(e,{num_crops:t=null}={}){if(this._num_crops=t??=this.config.num_crops,t<4||c(t)%1!=0)throw Error(`num_crops must be a square number >= 4`);Array.isArray(e)||(e=[e]);let n=e.length,r=await Promise.all(e.map(e=>this.preprocess(e))),l=r.map(e=>e.original_size),u=r.map(e=>e.reshaped_input_size),d=[];for(let{pixel_values:e}of r){e.unsqueeze_(0);let[n,r]=e.dims.slice(-2),o=await(0,i.interpolate_4d)(e,{size:[336,336],mode:`bicubic`});if(t>0){let l=[],u=c(t),f=s(r/u),p=s(n/u);for(let t=0;t<u;++t)for(let o=0;o<u;++o){let s,c,d,m;t===u-1?(c=n-p,m=n):(c=t*p,m=(t+1)*p),o===u-1?(s=r-f,d=r):(s=o*f,d=(o+1)*f);let h=[c,s],g=[m,d],_=await(0,i.slice)(e,h,g,a);l.push(_)}let m=await(0,i.interpolate_4d)((0,i.cat)(l,0),{size:[336,336],mode:`bicubic`});d.push((0,i.cat)([o,m],0))}else d.push(o)}let f=(0,i.stack)(d,0),p=u.map(e=>e.map(e=>336*o(e/336)));return{pixel_values:f,original_sizes:l,reshaped_input_sizes:u,image_sizes:new i.Tensor(`int64`,p.flat(),[n,2]),num_img_tokens:p.map(([e,t])=>this.calc_num_image_tokens_from_image_size(t,e))}}}}),"./src/models/phi3_v/processing_phi3_v.js":((e,t,n)=>{n.r(t),n.d(t,{Phi3VProcessor:()=>c});var r=n(`./src/base/processing_utils.js`),i=n(`./src/models/auto/image_processing_auto.js`),a=n(`./src/tokenizers.js`);n(`./src/utils/image.js`);let o=`<|image|>`,s=/<\|image_\d+\|>/g;class c extends r.Processor{static image_processor_class=i.AutoImageProcessor;static tokenizer_class=a.AutoTokenizer;async _call(e,t=null,{padding:n=!0,truncation:r=!0,num_crops:i=null}={}){Array.isArray(e)||(e=[e]);let a,c;if(t){c=await this.image_processor(t,{num_crops:i});let{num_img_tokens:l}=c,u=e.map((e,t)=>e.split(s).join(o.repeat(l[t])));a=this.tokenizer(u,{padding:n,truncation:r});let d=this.tokenizer.model.convert_tokens_to_ids([o])[0];a.input_ids.map_(e=>e==d?-e:e)}else a=this.tokenizer(e);return{...a,...c}}}}),"./src/models/pixtral/image_processing_pixtral.js":((e,t,n)=>{n.r(t),n.d(t,{PixtralImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{get_resize_output_image_size(e,t){let{longest_edge:n}=t;if(n===void 0)throw Error(`size must contain 'longest_edge'`);let[r,i]=e.size,a=Math.max(r,i)/n,o=r,s=i;a>1&&(o=Math.floor(r/a),s=Math.floor(i/a));let{patch_size:c,spatial_merge_size:l}=this.config;if(!l)throw Error(`config must contain 'spatial_merge_size'`);let u=c*l,d=Math.floor((o-1)/u)+1,f=Math.floor((s-1)/u)+1;return[d*u,f*u]}}}),"./src/models/pixtral/processing_pixtral.js":((e,t,n)=>{n.r(t),n.d(t,{PixtralProcessor:()=>o});var r=n(`./src/base/processing_utils.js`),i=n(`./src/models/auto/image_processing_auto.js`),a=n(`./src/tokenizers.js`);class o extends r.Processor{static tokenizer_class=a.AutoTokenizer;static image_processor_class=i.AutoImageProcessor;static uses_processor_config=!0;async _call(e,t=null,n={}){let r=await this.image_processor(e,n);if(t){let[e,n]=r.pixel_values.dims.slice(-2),{image_token:i,image_break_token:a,image_end_token:o,patch_size:s,spatial_merge_size:c}=this.config,l=s*c,u=Math.floor(e/l),d=Math.floor(n/l);t=structuredClone(t),Array.isArray(t)||(t=[t]);for(let e=0;e<t.length;++e){let n=i.repeat(d),r=n+a,s=n+o,c=r.repeat(u-1)+s;t[e]=t[e].replace(i,c)}}let i=t?this.tokenizer(t,n):{};return{...r,...i}}}}),"./src/models/processors.js":((e,t,n)=>{n.r(t),n.d(t,{Florence2Processor:()=>r.Florence2Processor,Gemma3nProcessor:()=>i.Gemma3nProcessor,GroundingDinoProcessor:()=>a.GroundingDinoProcessor,Idefics3Processor:()=>o.Idefics3Processor,JinaCLIPProcessor:()=>c.JinaCLIPProcessor,LlavaProcessor:()=>l.LlavaProcessor,MgpstrProcessor:()=>u.MgpstrProcessor,MoonshineProcessor:()=>d.MoonshineProcessor,OwlViTProcessor:()=>f.OwlViTProcessor,PaliGemmaProcessor:()=>p.PaliGemmaProcessor,Phi3VProcessor:()=>m.Phi3VProcessor,PixtralProcessor:()=>h.PixtralProcessor,PyAnnoteProcessor:()=>g.PyAnnoteProcessor,Qwen2VLProcessor:()=>_.Qwen2VLProcessor,Sam2Processor:()=>y.Sam2Processor,Sam2VideoProcessor:()=>y.Sam2VideoProcessor,SamProcessor:()=>v.SamProcessor,SmolVLMProcessor:()=>b.SmolVLMProcessor,SpeechT5Processor:()=>x.SpeechT5Processor,UltravoxProcessor:()=>S.UltravoxProcessor,VLChatProcessor:()=>s.VLChatProcessor,VoxtralProcessor:()=>C.VoxtralProcessor,Wav2Vec2Processor:()=>w.Wav2Vec2Processor,Wav2Vec2ProcessorWithLM:()=>T.Wav2Vec2ProcessorWithLM,WhisperProcessor:()=>E.WhisperProcessor});var r=n(`./src/models/florence2/processing_florence2.js`),i=n(`./src/models/gemma3n/processing_gemma3n.js`),a=n(`./src/models/grounding_dino/processing_grounding_dino.js`),o=n(`./src/models/idefics3/processing_idefics3.js`),s=n(`./src/models/janus/processing_janus.js`),c=n(`./src/models/jina_clip/processing_jina_clip.js`),l=n(`./src/models/llava/processing_llava.js`),u=n(`./src/models/mgp_str/processing_mgp_str.js`),d=n(`./src/models/moonshine/processing_moonshine.js`),f=n(`./src/models/owlvit/processing_owlvit.js`),p=n(`./src/models/paligemma/processing_paligemma.js`),m=n(`./src/models/phi3_v/processing_phi3_v.js`),h=n(`./src/models/pixtral/processing_pixtral.js`),g=n(`./src/models/pyannote/processing_pyannote.js`),_=n(`./src/models/qwen2_vl/processing_qwen2_vl.js`),v=n(`./src/models/sam/processing_sam.js`),y=n(`./src/models/sam2/processing_sam2.js`),b=n(`./src/models/smolvlm/processing_smolvlm.js`),x=n(`./src/models/speecht5/processing_speecht5.js`),S=n(`./src/models/ultravox/processing_ultravox.js`),C=n(`./src/models/voxtral/processing_voxtral.js`),w=n(`./src/models/wav2vec2/processing_wav2vec2.js`),T=n(`./src/models/wav2vec2_with_lm/processing_wav2vec2_with_lm.js`),E=n(`./src/models/whisper/processing_whisper.js`)}),"./src/models/pvt/image_processing_pvt.js":((e,t,n)=>{n.r(t),n.d(t,{PvtImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{}}),"./src/models/pyannote/feature_extraction_pyannote.js":((e,t,n)=>{n.r(t),n.d(t,{PyAnnoteFeatureExtractor:()=>o});var r=n(`./src/base/feature_extraction_utils.js`),i=n(`./src/utils/tensor.js`),a=n(`./src/utils/maths.js`);class o extends r.FeatureExtractor{async _call(e){(0,r.validate_audio_inputs)(e,`PyAnnoteFeatureExtractor`),e instanceof Float64Array&&(e=new Float32Array(e));let t=[1,1,e.length];return{input_values:new i.Tensor(`float32`,e,t)}}samples_to_frames(e){return(e-this.config.offset)/this.config.step}post_process_speaker_diarization(e,t){let n=t/this.samples_to_frames(t)/this.config.sampling_rate,r=[];for(let t of e.tolist()){let e=[],i=-1;for(let n=0;n<t.length;++n){let r=(0,a.softmax)(t[n]),[o,s]=(0,a.max)(r),[c,l]=[n,n+1];s===i?(e.at(-1).end=l,e.at(-1).score+=o):(i=s,e.push({id:s,start:c,end:l,score:o}))}r.push(e.map(({id:e,start:t,end:r,score:i})=>({id:e,start:t*n,end:r*n,confidence:i/(r-t)})))}return r}}}),"./src/models/pyannote/processing_pyannote.js":((e,t,n)=>{n.r(t),n.d(t,{PyAnnoteProcessor:()=>a});var r=n(`./src/base/processing_utils.js`),i=n(`./src/models/pyannote/feature_extraction_pyannote.js`);class a extends r.Processor{static feature_extractor_class=i.PyAnnoteFeatureExtractor;async _call(e){return await this.feature_extractor(e)}post_process_speaker_diarization(...e){return this.feature_extractor.post_process_speaker_diarization(...e)}get sampling_rate(){return this.feature_extractor.config.sampling_rate}}}),"./src/models/qwen2_vl/image_processing_qwen2_vl.js":((e,t,n)=>{n.r(t),n.d(t,{Qwen2VLImageProcessor:()=>a});var r=n(`./src/base/image_processors_utils.js`),i=n(`./src/utils/tensor.js`);class a extends r.ImageProcessor{async _call(e,...t){let{pixel_values:n,original_sizes:r,reshaped_input_sizes:a}=await super._call(e,...t),o=n,{temporal_patch_size:s,merge_size:c,patch_size:l}=this.config;o.dims[0]===1&&(o=(0,i.cat)(Array.from({length:s},()=>o),0));let u=o.dims[0]/s,d=o.dims[1],f=Math.floor(o.dims[2]/l),p=Math.floor(o.dims[3]/l);return{pixel_values:o.view(u,s,d,Math.floor(f/c),c,l,Math.floor(p/c),c,l).permute(0,3,6,4,7,2,1,5,8).view(u*f*p,d*s*l*l),image_grid_thw:new i.Tensor(`int64`,[u,f,p],[1,3]),original_sizes:r,reshaped_input_sizes:a}}}}),"./src/models/qwen2_vl/processing_qwen2_vl.js":((e,t,n)=>{n.r(t),n.d(t,{Qwen2VLProcessor:()=>o});var r=n(`./src/base/processing_utils.js`),i=n(`./src/models/auto/image_processing_auto.js`),a=n(`./src/tokenizers.js`);n(`./src/utils/image.js`);class o extends r.Processor{static image_processor_class=i.AutoImageProcessor;static tokenizer_class=a.AutoTokenizer;async _call(e,t=null,...n){Array.isArray(e)||(e=[e]);let r,i;if(t&&(r=await this.image_processor(t),i=r.image_grid_thw),i){let t=this.image_processor.config.merge_size**2,n=0,r=i.tolist();e=e.map(e=>{for(;e.includes(`<|image_pad|>`);){let i=Number(r[n++].reduce((e,t)=>e*t,1n));e=e.replace(`<|image_pad|>`,`<|placeholder|>`.repeat(Math.floor(i/t)))}return e.replaceAll(`<|placeholder|>`,`<|image_pad|>`)})}return{...this.tokenizer(e),...r}}}}),"./src/models/rt_detr/image_processing_rt_detr.js":((e,t,n)=>{n.r(t),n.d(t,{RTDetrImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{post_process_object_detection(...e){return(0,r.post_process_object_detection)(...e)}}}),"./src/models/sam/image_processing_sam.js":((e,t,n)=>{n.r(t),n.d(t,{SamImageProcessor:()=>o});var r=n(`./src/base/image_processors_utils.js`),i=n(`./src/utils/core.js`),a=n(`./src/utils/tensor.js`);class o extends r.ImageProcessor{reshape_input_points(e,t,n,r=!1){e=structuredClone(e);let o=(0,i.calculateDimensions)(e);if(o.length===3)r||(o=[1,...o]),e=[e];else if(o.length!==4)throw Error("The input_points must be a 4D tensor of shape `batch_size`, `point_batch_size`, `nb_points_per_image`, `2`.");for(let r=0;r<e.length;++r){let[i,a]=t[r],[o,s]=n[r],c=[s/a,o/i];for(let t=0;t<e[r].length;++t)for(let n=0;n<e[r][t].length;++n)for(let i=0;i<e[r][t][n].length;++i)e[r][t][n][i]*=c[i%2]}return new a.Tensor(`float32`,Float32Array.from(e.flat(1/0)),o)}add_input_labels(e,t){let n=(0,i.calculateDimensions)(e);if(n.length===2)n=[1,...n],e=[e];else if(n.length!==3)throw Error("The input_points must be a 4D tensor of shape `batch_size`, `point_batch_size`, `nb_points_per_image`, `2`.");if(n.some((e,n)=>e!==t.dims[n]))throw Error(`The first ${n.length} dimensions of 'input_points' and 'input_labels' must be the same.`);return new a.Tensor(`int64`,e.flat(1/0).map(BigInt),n)}async _call(e,{input_points:t=null,input_labels:n=null,input_boxes:r=null}={}){let i=await super._call(e);if(t&&(i.input_points=this.reshape_input_points(t,i.original_sizes,i.reshaped_input_sizes)),n){if(!i.input_points)throw Error("`input_points` must be provided if `input_labels` are provided.");i.input_labels=this.add_input_labels(n,i.input_points)}return r&&(i.input_boxes=this.reshape_input_points(r,i.original_sizes,i.reshaped_input_sizes,!0)),i}async post_process_masks(e,t,n,{mask_threshold:r=0,binarize:i=!0,pad_size:o=null}={}){let s=[];o=o??this.pad_size??this.size;let c=[o.height,o.width];for(let o=0;o<t.length;++o){let l=t[o],u=n[o],d=await(0,a.interpolate_4d)(e[o],{mode:`bilinear`,size:c});if(d=d.slice(null,null,[0,u[0]],[0,u[1]]),d=await(0,a.interpolate_4d)(d,{mode:`bilinear`,size:l}),i){let e=d.data,t=new Uint8Array(e.length);for(let n=0;n<e.length;++n)e[n]>r&&(t[n]=1);d=new a.Tensor(`bool`,t,d.dims)}s.push(d)}return s}generate_crop_boxes(e,t,{crop_n_layers:n=0,overlap_ratio:r=512/1500,points_per_crop:i=32,crop_n_points_downscale_factor:a=1}={}){}}}),"./src/models/sam/processing_sam.js":((e,t,n)=>{n.r(t),n.d(t,{SamProcessor:()=>a});var r=n(`./src/base/processing_utils.js`),i=n(`./src/models/auto/image_processing_auto.js`);class a extends r.Processor{static image_processor_class=i.AutoImageProcessor;async _call(...e){return await this.image_processor(...e)}post_process_masks(...e){return this.image_processor.post_process_masks(...e)}reshape_input_points(...e){return this.image_processor.reshape_input_points(...e)}}}),"./src/models/sam2/image_processing_sam2.js":((e,t,n)=>{n.r(t),n.d(t,{Sam2ImageProcessor:()=>r.SamImageProcessor});var r=n(`./src/models/sam/image_processing_sam.js`)}),"./src/models/sam2/processing_sam2.js":((e,t,n)=>{n.r(t),n.d(t,{Sam2Processor:()=>i,Sam2VideoProcessor:()=>a});var r=n(`./src/models/sam/processing_sam.js`);class i extends r.SamProcessor{}class a extends i{}}),"./src/models/sam3/image_processing_sam3.js":((e,t,n)=>{n.r(t),n.d(t,{Sam3ImageProcessor:()=>r.Sam2ImageProcessor});var r=n(`./src/models/sam2/image_processing_sam2.js`)}),"./src/models/seamless_m4t/feature_extraction_seamless_m4t.js":((e,t,n)=>{n.r(t),n.d(t,{SeamlessM4TFeatureExtractor:()=>o});var r=n(`./src/base/feature_extraction_utils.js`),i=n(`./src/utils/tensor.js`),a=n(`./src/utils/audio.js`);class o extends r.FeatureExtractor{constructor(e){super(e);let t=this.config.sampling_rate;this.mel_filters=(0,a.mel_filter_bank)(257,this.config.num_mel_bins,20,Math.floor(t/2),t,null,`kaldi`,!0),this.window=(0,a.window_function)(400,`povey`,{periodic:!1})}async _extract_fbank_features(e,t){return e=e.map(e=>e*32768),(0,a.spectrogram)(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:`log`,mel_floor:1.192092955078125e-7,remove_dc_offset:!0,max_num_frames:t,transpose:!0})}async _call(e,{padding:t=!0,pad_to_multiple_of:n=2,do_normalize_per_mel_bins:a=!0,return_attention_mask:o=!0}={}){(0,r.validate_audio_inputs)(e,`SeamlessM4TFeatureExtractor`);let s=await this._extract_fbank_features(e,this.config.max_length);if(a){let[e,t]=s.dims,n=s.data;for(let r=0;r<t;++r){let i=0;for(let a=0;a<e;++a)i+=n[a*t+r];let a=i/e,o=0;for(let i=0;i<e;++i)o+=(n[i*t+r]-a)**2;o/=e-1;let s=Math.sqrt(o+1e-7);for(let i=0;i<e;++i){let e=i*t+r;n[e]=(n[e]-a)/s}}}let c;if(t){let[e,t]=s.dims,r=s.data,a=e%n;if(a>0){let n=new Float32Array(t*(e+a));n.set(r),n.fill(this.config.padding_value,r.length);let l=e+a;s=new i.Tensor(s.type,n,[l,t]),o&&(c=new i.Tensor(`int64`,new BigInt64Array(l),[1,l]),c.data.fill(1n,0,e))}}let[l,u]=s.dims,d=this.config.stride;if(l%d!==0)throw Error(`The number of frames (${l}) must be a multiple of the stride (${d}).`);let f=s.view(1,Math.floor(l/d),u*d),p={input_features:f};if(o){let e=f.dims[1],t=new BigInt64Array(e);if(c){let e=c.data;for(let n=1,r=0;n<l;n+=d,++r)t[r]=e[n]}else t.fill(1n);p.attention_mask=new i.Tensor(`int64`,t,[1,e])}return p}}}),"./src/models/segformer/image_processing_segformer.js":((e,t,n)=>{n.r(t),n.d(t,{SegformerFeatureExtractor:()=>a,SegformerImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{post_process_semantic_segmentation(...e){return(0,r.post_process_semantic_segmentation)(...e)}}class a extends i{}}),"./src/models/siglip/image_processing_siglip.js":((e,t,n)=>{n.r(t),n.d(t,{SiglipImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{}}),"./src/models/smolvlm/image_processing_smolvlm.js":((e,t,n)=>{n.r(t),n.d(t,{SmolVLMImageProcessor:()=>r.Idefics3ImageProcessor});var r=n(`./src/models/idefics3/image_processing_idefics3.js`)}),"./src/models/smolvlm/processing_smolvlm.js":((e,t,n)=>{n.r(t),n.d(t,{SmolVLMProcessor:()=>r.Idefics3Processor});var r=n(`./src/models/idefics3/processing_idefics3.js`)}),"./src/models/snac/feature_extraction_snac.js":((e,t,n)=>{n.r(t),n.d(t,{SnacFeatureExtractor:()=>i});var r=n(`./src/models/dac/feature_extraction_dac.js`);class i extends r.DacFeatureExtractor{}}),"./src/models/speecht5/feature_extraction_speecht5.js":((e,t,n)=>{n.r(t),n.d(t,{SpeechT5FeatureExtractor:()=>i});var r=n(`./src/base/feature_extraction_utils.js`);class i extends r.FeatureExtractor{}}),"./src/models/speecht5/processing_speecht5.js":((e,t,n)=>{n.r(t),n.d(t,{SpeechT5Processor:()=>o});var r=n(`./src/base/processing_utils.js`),i=n(`./src/tokenizers.js`),a=n(`./src/models/auto/feature_extraction_auto.js`);class o extends r.Processor{static tokenizer_class=i.AutoTokenizer;static feature_extractor_class=a.AutoFeatureExtractor;async _call(e){return await this.feature_extractor(e)}}}),"./src/models/swin2sr/image_processing_swin2sr.js":((e,t,n)=>{n.r(t),n.d(t,{Swin2SRImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{pad_image(e,t,n,r={}){let[i,a,o]=t;return super.pad_image(e,t,{width:a+(n-a%n)%n,height:i+(n-i%n)%n},{mode:`symmetric`,center:!1,constant_values:-1,...r})}}}),"./src/models/ultravox/processing_ultravox.js":((e,t,n)=>{n.r(t),n.d(t,{UltravoxProcessor:()=>o});var r=n(`./src/models/auto/feature_extraction_auto.js`),i=n(`./src/tokenizers.js`),a=n(`./src/base/processing_utils.js`);class o extends a.Processor{static tokenizer_class=i.AutoTokenizer;static feature_extractor_class=r.AutoFeatureExtractor;static uses_processor_config=!0;async _call(e,t=null,n={}){if(Array.isArray(e))throw Error(`Batched inputs are not supported yet.`);let r={};if(t){let i=t.length,{input_features:a}=await this.feature_extractor(t,{...n,max_length:i}),o=Math.round(i/this.config.encoder_ds_factor+1e-4),s=1+Math.ceil(o/this.config.stack_factor);r.audio_token_len=[s],r.audio_values=a;let c=this.config.audio_placeholder;if(!e.includes(c))throw Error(`The input text does not contain the image token ${c}.`);e=e.replaceAll(c,c.repeat(s))}return{...this.tokenizer(e,{add_special_tokens:!1,...n}),...r}}}}),"./src/models/vit/image_processing_vit.js":((e,t,n)=>{n.r(t),n.d(t,{ViTFeatureExtractor:()=>a,ViTImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{}class a extends i{}}),"./src/models/vitmatte/image_processing_vitmatte.js":((e,t,n)=>{n.r(t),n.d(t,{VitMatteImageProcessor:()=>a});var r=n(`./src/base/image_processors_utils.js`),i=n(`./src/utils/tensor.js`);class a extends r.ImageProcessor{async _call(e,t){Array.isArray(e)||(e=[e]),Array.isArray(t)||(t=[t]);let n=await Promise.all(e.map(e=>this.preprocess(e))),r=await Promise.all(t.map(e=>this.preprocess(e,{do_normalize:!1,do_convert_rgb:!1,do_convert_grayscale:!0})));return{pixel_values:(0,i.stack)(n.map((e,t)=>(0,i.cat)([e.pixel_values,r[t].pixel_values],0)),0),original_sizes:n.map(e=>e.original_size),reshaped_input_sizes:n.map(e=>e.reshaped_input_size)}}}}),"./src/models/vitpose/image_processing_vitpose.js":((e,t,n)=>{n.r(t),n.d(t,{VitPoseImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{post_process_pose_estimation(e,t,{threshold:n=null}={}){let r=e.tolist(),[i,a,o,s]=e.dims,c=[];for(let e=0;e<i;++e){let i=r[e],a=t[e],l=[];for(let e=0;e<a.length;++e){let t=a[e],r=[],c=[],u=[],d=t.at(-2)/s,f=t.at(-1)/o;for(let e=0;e<i.length;++e){let[t,a]=[0,0],o=0,s=-1/0,l=i[e];for(let e=0;e<l.length;++e){let n=l[e];for(let r=0;r<n.length;++r){let i=n[r];o+=i,s=Math.max(s,i),t+=(r+.5)*i,a+=e*i}}if(n!=null&&s<n)continue;let p=[d*t/o,f*a/o];r.push(p),u.push(e),c.push(s)}l.push({bbox:t,scores:c,labels:u,keypoints:r})}c.push(l)}return c}}}),"./src/models/voxtral/processing_voxtral.js":((e,t,n)=>{n.r(t),n.d(t,{VoxtralProcessor:()=>l});var r=n(`./src/models/auto/feature_extraction_auto.js`),i=n(`./src/tokenizers.js`),a=n(`./src/base/processing_utils.js`),o=n(`./src/utils/tensor.js`);let s=`[AUDIO]`;function c(e,t){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.subarray(r,Math.min(r+t,e.length)));return n}class l extends a.Processor{static tokenizer_class=i.AutoTokenizer;static feature_extractor_class=r.AutoFeatureExtractor;static uses_processor_config=!1;async _call(e,t=null,n={}){if(Array.isArray(e))throw Error(`Batched inputs are not supported yet.`);let r={};if(t){if(!e.includes(s))throw Error(`The input text does not contain the audio token ${s}.`);Array.isArray(t)||(t=[t]);let i=e.split(s),a=i.length-1;if(a!==t.length)throw Error(`The number of audio inputs (${t.length}) does not match the number of audio tokens in the text (${a}).`);let l=this.feature_extractor.config.n_samples,u=t.map(e=>c(e,l)),d=u.map(e=>e.length),f=u.flat(),p=(await Promise.all(f.map(e=>this.feature_extractor(e,n)))).map(e=>e.input_features);r.audio_values=p.length>1?(0,o.cat)(p,0):p[0];let m=i[0];for(let e=0;e<d.length;++e){m+=`[BEGIN_AUDIO]`;for(let t=0;t<d[e];++t)m+=s.repeat(375);m+=i[e+1]}e=m}return{...this.tokenizer(e,{add_special_tokens:!1,...n}),...r}}}}),"./src/models/wav2vec2/feature_extraction_wav2vec2.js":((e,t,n)=>{n.r(t),n.d(t,{Wav2Vec2FeatureExtractor:()=>a});var r=n(`./src/base/feature_extraction_utils.js`),i=n(`./src/utils/tensor.js`);class a extends r.FeatureExtractor{_zero_mean_unit_var_norm(e){let t=e.reduce((e,t)=>e+t,0)/e.length,n=e.reduce((e,n)=>e+(n-t)**2,0)/e.length;return e.map(e=>(e-t)/Math.sqrt(n+1e-7))}async _call(e){(0,r.validate_audio_inputs)(e,`Wav2Vec2FeatureExtractor`),e instanceof Float64Array&&(e=new Float32Array(e));let t=e;this.config.do_normalize&&(t=this._zero_mean_unit_var_norm(t));let n=[1,t.length];return{input_values:new i.Tensor(`float32`,t,n),attention_mask:new i.Tensor(`int64`,new BigInt64Array(t.length).fill(1n),n)}}}}),"./src/models/wav2vec2/processing_wav2vec2.js":((e,t,n)=>{n.r(t),n.d(t,{Wav2Vec2Processor:()=>o});var r=n(`./src/tokenizers.js`),i=n(`./src/models/auto/feature_extraction_auto.js`),a=n(`./src/base/processing_utils.js`);class o extends a.Processor{static tokenizer_class=r.AutoTokenizer;static feature_extractor_class=i.AutoFeatureExtractor;async _call(e){return await this.feature_extractor(e)}}}),"./src/models/wav2vec2_with_lm/processing_wav2vec2_with_lm.js":((e,t,n)=>{n.r(t),n.d(t,{Wav2Vec2ProcessorWithLM:()=>o});var r=n(`./src/tokenizers.js`),i=n(`./src/models/auto/feature_extraction_auto.js`),a=n(`./src/base/processing_utils.js`);class o extends a.Processor{static tokenizer_class=r.AutoTokenizer;static feature_extractor_class=i.AutoFeatureExtractor;async _call(e){return await this.feature_extractor(e)}}}),"./src/models/wespeaker/feature_extraction_wespeaker.js":((e,t,n)=>{n.r(t),n.d(t,{WeSpeakerFeatureExtractor:()=>a});var r=n(`./src/base/feature_extraction_utils.js`);n(`./src/utils/tensor.js`);var i=n(`./src/utils/audio.js`);class a extends r.FeatureExtractor{constructor(e){super(e);let t=this.config.sampling_rate;this.mel_filters=(0,i.mel_filter_bank)(257,this.config.num_mel_bins,20,Math.floor(t/2),t,null,`kaldi`,!0),this.window=(0,i.window_function)(400,`hamming`,{periodic:!1}),this.min_num_frames=this.config.min_num_frames}async _extract_fbank_features(e){return e=e.map(e=>e*32768),(0,i.spectrogram)(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:`log`,mel_floor:1.192092955078125e-7,remove_dc_offset:!0,transpose:!0,min_num_frames:this.min_num_frames})}async _call(e){(0,r.validate_audio_inputs)(e,`WeSpeakerFeatureExtractor`);let t=(await this._extract_fbank_features(e)).unsqueeze_(0);if(this.config.fbank_centering_span===null){let e=t.mean(1).data,n=t.data,[r,i,a]=t.dims;for(let t=0;t<r;++t){let r=t*i*a,o=t*a;for(let t=0;t<i;++t){let i=r+t*a;for(let t=0;t<a;++t)n[i+t]-=e[o+t]}}}return{input_features:t}}}}),"./src/models/whisper/common_whisper.js":((e,t,n)=>{n.r(t),n.d(t,{WHISPER_LANGUAGE_MAPPING:()=>i,WHISPER_TO_LANGUAGE_CODE_MAPPING:()=>a,whisper_language_to_code:()=>o});let r=[[`en`,`english`],[`zh`,`chinese`],[`de`,`german`],[`es`,`spanish`],[`ru`,`russian`],[`ko`,`korean`],[`fr`,`french`],[`ja`,`japanese`],[`pt`,`portuguese`],[`tr`,`turkish`],[`pl`,`polish`],[`ca`,`catalan`],[`nl`,`dutch`],[`ar`,`arabic`],[`sv`,`swedish`],[`it`,`italian`],[`id`,`indonesian`],[`hi`,`hindi`],[`fi`,`finnish`],[`vi`,`vietnamese`],[`he`,`hebrew`],[`uk`,`ukrainian`],[`el`,`greek`],[`ms`,`malay`],[`cs`,`czech`],[`ro`,`romanian`],[`da`,`danish`],[`hu`,`hungarian`],[`ta`,`tamil`],[`no`,`norwegian`],[`th`,`thai`],[`ur`,`urdu`],[`hr`,`croatian`],[`bg`,`bulgarian`],[`lt`,`lithuanian`],[`la`,`latin`],[`mi`,`maori`],[`ml`,`malayalam`],[`cy`,`welsh`],[`sk`,`slovak`],[`te`,`telugu`],[`fa`,`persian`],[`lv`,`latvian`],[`bn`,`bengali`],[`sr`,`serbian`],[`az`,`azerbaijani`],[`sl`,`slovenian`],[`kn`,`kannada`],[`et`,`estonian`],[`mk`,`macedonian`],[`br`,`breton`],[`eu`,`basque`],[`is`,`icelandic`],[`hy`,`armenian`],[`ne`,`nepali`],[`mn`,`mongolian`],[`bs`,`bosnian`],[`kk`,`kazakh`],[`sq`,`albanian`],[`sw`,`swahili`],[`gl`,`galician`],[`mr`,`marathi`],[`pa`,`punjabi`],[`si`,`sinhala`],[`km`,`khmer`],[`sn`,`shona`],[`yo`,`yoruba`],[`so`,`somali`],[`af`,`afrikaans`],[`oc`,`occitan`],[`ka`,`georgian`],[`be`,`belarusian`],[`tg`,`tajik`],[`sd`,`sindhi`],[`gu`,`gujarati`],[`am`,`amharic`],[`yi`,`yiddish`],[`lo`,`lao`],[`uz`,`uzbek`],[`fo`,`faroese`],[`ht`,`haitian creole`],[`ps`,`pashto`],[`tk`,`turkmen`],[`nn`,`nynorsk`],[`mt`,`maltese`],[`sa`,`sanskrit`],[`lb`,`luxembourgish`],[`my`,`myanmar`],[`bo`,`tibetan`],[`tl`,`tagalog`],[`mg`,`malagasy`],[`as`,`assamese`],[`tt`,`tatar`],[`haw`,`hawaiian`],[`ln`,`lingala`],[`ha`,`hausa`],[`ba`,`bashkir`],[`jw`,`javanese`],[`su`,`sundanese`]],i=new Map(r),a=new Map([...r.map(([e,t])=>[t,e]),...[[`burmese`,`my`],[`valencian`,`ca`],[`flemish`,`nl`],[`haitian`,`ht`],[`letzeburgesch`,`lb`],[`pushto`,`ps`],[`panjabi`,`pa`],[`moldavian`,`ro`],[`moldovan`,`ro`],[`sinhalese`,`si`],[`castilian`,`es`]]]);function o(e){e=e.toLowerCase();let t=a.get(e);if(t===void 0){let n=e.match(/^<\|([a-z]{2})\|>$/);if(n&&(e=n[1]),i.has(e))t=e;else{let t=e.length===2?i.keys():i.values();throw Error(`Language "${e}" is not supported. Must be one of: ${JSON.stringify(Array.from(t))}`)}}return t}}),"./src/models/whisper/feature_extraction_whisper.js":((e,t,n)=>{n.r(t),n.d(t,{WhisperFeatureExtractor:()=>o});var r=n(`./src/base/feature_extraction_utils.js`);n(`./src/utils/tensor.js`);var i=n(`./src/utils/audio.js`),a=n(`./src/utils/maths.js`);class o extends r.FeatureExtractor{constructor(e){super(e),this.config.mel_filters??=(0,i.mel_filter_bank)(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,8e3,this.config.sampling_rate,`slaney`,`slaney`),this.window=(0,i.window_function)(this.config.n_fft,`hann`)}async _extract_fbank_features(e){let t=await(0,i.spectrogram)(e,this.window,this.config.n_fft,this.config.hop_length,{power:2,mel_filters:this.config.mel_filters,log_mel:`log10`,max_num_frames:Math.min(Math.floor(e.length/this.config.hop_length),this.config.nb_max_frames)}),n=t.data,r=(0,a.max)(n)[0];for(let e=0;e<n.length;++e)n[e]=(Math.max(n[e],r-8)+4)/4;return t}async _call(e,{max_length:t=null}={}){(0,r.validate_audio_inputs)(e,`WhisperFeatureExtractor`);let n,i=t??this.config.n_samples;return e.length>i?(e.length>this.config.n_samples&&console.warn("Attempting to extract features for audio longer than 30 seconds. If using a pipeline to extract transcript from a long audio clip, remember to specify `chunk_length_s` and/or `stride_length_s`."),n=e.slice(0,i)):(n=new Float32Array(i),n.set(e)),{input_features:(await this._extract_fbank_features(n)).unsqueeze_(0)}}}}),"./src/models/whisper/generation_whisper.js":((e,t,n)=>{n.r(t),n.d(t,{WhisperGenerationConfig:()=>i});var r=n(`./src/generation/configuration_utils.js`);class i extends r.GenerationConfig{return_timestamps=null;return_token_timestamps=null;num_frames=null;alignment_heads=null;task=null;language=null;no_timestamps_token_id=null;prompt_ids=null;is_multilingual=null;lang_to_id=null;task_to_id=null;max_initial_timestamp_index=1}}),"./src/models/whisper/processing_whisper.js":((e,t,n)=>{n.r(t),n.d(t,{WhisperProcessor:()=>o});var r=n(`./src/models/auto/feature_extraction_auto.js`),i=n(`./src/tokenizers.js`),a=n(`./src/base/processing_utils.js`);class o extends a.Processor{static tokenizer_class=i.AutoTokenizer;static feature_extractor_class=r.AutoFeatureExtractor;async _call(e){return await this.feature_extractor(e)}}}),"./src/models/yolos/image_processing_yolos.js":((e,t,n)=>{n.r(t),n.d(t,{YolosFeatureExtractor:()=>a,YolosImageProcessor:()=>i});var r=n(`./src/base/image_processors_utils.js`);class i extends r.ImageProcessor{post_process_object_detection(...e){return(0,r.post_process_object_detection)(...e)}}class a extends i{}}),"./src/ops/registry.js":((e,t,n)=>{n.r(t),n.d(t,{TensorOpRegistry:()=>o});var r=n(`./src/backends/onnx.js`),i=n(`./src/utils/tensor.js`);let a=async(e,t,n)=>{let a=await(0,r.createInferenceSession)(new Uint8Array(e),t);return(async e=>{let t=(0,r.isONNXProxy)(),o=Object.fromEntries(Object.entries(e).map(([e,n])=>[e,(t?n.clone():n).ort_tensor])),s=await(0,r.runInferenceSession)(a,o);return Array.isArray(n)?n.map(e=>new i.Tensor(s[e])):new i.Tensor(s[n])})};class o{static session_options={};static get nearest_interpolate_4d(){return this._nearest_interpolate_4d||=a([8,10,18,0,58,129,1,10,41,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,18,10,4,109,111,100,101,34,7,110,101,97,114,101,115,116,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,21],this.session_options,`y`),this._nearest_interpolate_4d}static get bilinear_interpolate_4d(){return this._bilinear_interpolate_4d||=a([8,9,18,0,58,128,1,10,40,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,17,10,4,109,111,100,101,34,6,108,105,110,101,97,114,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,20],this.session_options,`y`),this._bilinear_interpolate_4d}static get bicubic_interpolate_4d(){return this._bicubic_interpolate_4d||=a([8,9,18,0,58,127,10,39,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,16,10,4,109,111,100,101,34,5,99,117,98,105,99,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,20],this.session_options,`y`),this._bicubic_interpolate_4d}static get matmul(){return this._matmul||=a([8,9,18,0,58,55,10,17,10,1,97,10,1,98,18,1,99,34,6,77,97,116,77,117,108,18,1,114,90,9,10,1,97,18,4,10,2,8,1,90,9,10,1,98,18,4,10,2,8,1,98,9,10,1,99,18,4,10,2,8,1,66,2,16,20],this.session_options,`c`),this._matmul}static get stft(){return this._stft||=a([8,7,18,0,58,148,1,10,38,10,1,115,10,1,106,10,1,119,10,1,108,18,1,111,34,4,83,84,70,84,42,15,10,8,111,110,101,115,105,100,101,100,24,1,160,1,2,18,1,115,90,26,10,1,115,18,21,10,19,8,1,18,15,10,3,18,1,98,10,3,18,1,115,10,3,18,1,99,90,11,10,1,106,18,6,10,4,8,7,18,0,90,16,10,1,119,18,11,10,9,8,1,18,5,10,3,18,1,119,90,11,10,1,108,18,6,10,4,8,7,18,0,98,31,10,1,111,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,102,10,3,18,1,100,10,3,18,1,99,66,2,16,17],this.session_options,`o`),this._stft}static get rfft(){return this._rfft||=a([8,9,18,0,58,97,10,33,10,1,120,10,0,10,1,97,18,1,121,34,3,68,70,84,42,15,10,8,111,110,101,115,105,100,101,100,24,1,160,1,2,18,1,100,90,21,10,1,120,18,16,10,14,8,1,18,10,10,3,18,1,115,10,3,18,1,99,90,11,10,1,97,18,6,10,4,8,7,18,0,98,21,10,1,121,18,16,10,14,8,1,18,10,10,3,18,1,115,10,3,18,1,99,66,2,16,20],this.session_options,`y`),this._rfft}static get top_k(){return this._top_k||=a([8,10,18,0,58,73,10,18,10,1,120,10,1,107,18,1,118,18,1,105,34,4,84,111,112,75,18,1,116,90,9,10,1,120,18,4,10,2,8,1,90,15,10,1,107,18,10,10,8,8,7,18,4,10,2,8,1,98,9,10,1,118,18,4,10,2,8,1,98,9,10,1,105,18,4,10,2,8,7,66,2,16,21],this.session_options,[`v`,`i`]),this._top_k}static get slice(){return this._slice||=a([8,7,18,0,58,96,10,25,10,1,120,10,1,115,10,1,101,10,1,97,10,1,116,18,1,121,34,5,83,108,105,99,101,18,1,114,90,9,10,1,120,18,4,10,2,8,1,90,9,10,1,115,18,4,10,2,8,7,90,9,10,1,101,18,4,10,2,8,7,90,9,10,1,97,18,4,10,2,8,7,90,9,10,1,116,18,4,10,2,8,7,98,9,10,1,121,18,4,10,2,8,1,66,2,16,13],this.session_options,`y`),this._slice}}}),"./src/pipelines.js":((e,t,n)=>{n.r(t),n.d(t,{AudioClassificationPipeline:()=>O,AutomaticSpeechRecognitionPipeline:()=>A,BackgroundRemovalPipeline:()=>j,DepthEstimationPipeline:()=>N,DocumentQuestionAnsweringPipeline:()=>oe,FeatureExtractionPipeline:()=>E,FillMaskPipeline:()=>y,ImageClassificationPipeline:()=>te,ImageFeatureExtractionPipeline:()=>D,ImageSegmentationPipeline:()=>ne,ImageToImagePipeline:()=>M,ImageToTextPipeline:()=>ee,ObjectDetectionPipeline:()=>ie,Pipeline:()=>h,QuestionAnsweringPipeline:()=>v,SummarizationPipeline:()=>x,Text2TextGenerationPipeline:()=>b,TextClassificationPipeline:()=>g,TextGenerationPipeline:()=>w,TextToAudioPipeline:()=>se,TokenClassificationPipeline:()=>_,TranslationPipeline:()=>S,ZeroShotAudioClassificationPipeline:()=>k,ZeroShotClassificationPipeline:()=>T,ZeroShotImageClassificationPipeline:()=>re,ZeroShotObjectDetectionPipeline:()=>ae,pipeline:()=>ue});var r=n(`./src/tokenizers.js`),i=n(`./src/models.js`),a=n(`./src/models/auto/processing_auto.js`);n(`./src/base/processing_utils.js`);var o=n(`./src/utils/generic.js`),s=n(`./src/utils/core.js`),c=n(`./src/utils/maths.js`),l=n(`./src/utils/audio.js`),u=n(`./src/utils/tensor.js`),d=n(`./src/utils/image.js`);async function f(e){return Array.isArray(e)||(e=[e]),await Promise.all(e.map(e=>d.RawImage.read(e)))}async function p(e,t){return Array.isArray(e)||(e=[e]),await Promise.all(e.map(e=>typeof e==`string`||e instanceof URL?(0,l.read_audio)(e,t):e instanceof Float64Array?new Float32Array(e):e))}function m(e,t){t&&(e=e.map(e=>e|0));let[n,r,i,a]=e;return{xmin:n,ymin:r,xmax:i,ymax:a}}class h extends o.Callable{constructor({task:e,model:t,tokenizer:n=null,processor:r=null}){super(),this.task=e,this.model=t,this.tokenizer=n,this.processor=r}async dispose(){await this.model.dispose()}}class g extends h{constructor(e){super(e)}async _call(e,{top_k:t=1}={}){let n=this.tokenizer(e,{padding:!0,truncation:!0}),r=await this.model(n),i=this.model.config.problem_type===`multi_label_classification`?e=>e.sigmoid():e=>new u.Tensor(`float32`,(0,c.softmax)(e.data),e.dims),a=this.model.config.id2label,o=[];for(let e of r.logits){let n=i(e),r=await(0,u.topk)(n,t),s=r[0].tolist(),c=r[1].tolist().map((e,t)=>({label:a?a[e]:`LABEL_${e}`,score:s[t]}));t===1?o.push(...c):o.push(c)}return Array.isArray(e)||t===1?o:o[0]}}class _ extends h{constructor(e){super(e)}async _call(e,{ignore_labels:t=[`O`]}={}){let n=Array.isArray(e),r=this.tokenizer(n?e:[e],{padding:!0,truncation:!0}),i=(await this.model(r)).logits,a=this.model.config.id2label,o=[];for(let e=0;e<i.dims[0];++e){let n=r.input_ids[e],s=i[e],l=[];for(let e=0;e<s.dims[0];++e){let r=s[e],i=(0,c.max)(r.data)[1],o=a?a[i]:`LABEL_${i}`;if(t.includes(o))continue;let u=this.tokenizer.decode([n[e].item()],{skip_special_tokens:!0});if(u===``)continue;let d=(0,c.softmax)(r.data);l.push({entity:o,score:d[i],index:e,word:u})}o.push(l)}return n?o:o[0]}}class v extends h{constructor(e){super(e)}async _call(e,t,{top_k:n=1}={}){let r=this.tokenizer(e,{text_pair:t,padding:!0,truncation:!0}),{start_logits:i,end_logits:a}=await this.model(r),o=r.input_ids.tolist(),l=r.attention_mask.tolist(),u=this.tokenizer.all_special_ids,d=[];for(let e=0;e<i.dims[0];++e){let t=o[e],r=t.findIndex(e=>e==this.tokenizer.sep_token_id);l[e].map((e,n)=>e==1&&(n===0||n>r&&u.findIndex(e=>e==t[n])===-1));let f=i[e].tolist(),p=a[e].tolist();for(let n=1;n<f.length;++n)(l[e]==0||n<=r||u.findIndex(e=>e==t[n])!==-1)&&(f[n]=-1/0,p[n]=-1/0);let m=(0,c.softmax)(f).map((e,t)=>[e,t]),h=(0,c.softmax)(p).map((e,t)=>[e,t]);m[0][0]=0,h[0][0]=0;let g=(0,s.product)(m,h).filter(e=>e[0][1]<=e[1][1]).map(e=>[e[0][1],e[1][1],e[0][0]*e[1][0]]).sort((e,t)=>t[2]-e[2]);for(let e=0;e<Math.min(g.length,n);++e){let[n,r,i]=g[e],a=t.slice(n,r+1),o=this.tokenizer.decode(a,{skip_special_tokens:!0});d.push({answer:o,score:i})}}return n===1?d[0]:d}}class y extends h{constructor(e){super(e)}async _call(e,{top_k:t=5}={}){let n=this.tokenizer(e,{padding:!0,truncation:!0}),{logits:r}=await this.model(n),i=[],a=n.input_ids.tolist();for(let e=0;e<a.length;++e){let n=a[e],o=n.findIndex(e=>e==this.tokenizer.mask_token_id);if(o===-1)throw Error(`Mask token (${this.tokenizer.mask_token}) not found in text.`);let s=r[e][o],l=await(0,u.topk)(new u.Tensor(`float32`,(0,c.softmax)(s.data),s.dims),t),d=l[0].tolist(),f=l[1].tolist();i.push(f.map((e,t)=>{let r=n.slice();return r[o]=e,{score:d[t],token:Number(e),token_str:this.tokenizer.decode([e]),sequence:this.tokenizer.decode(r,{skip_special_tokens:!0})}}))}return Array.isArray(e)?i:i[0]}}class b extends h{_key=`generated_text`;constructor(e){super(e)}async _call(e,t={}){Array.isArray(e)||(e=[e]),this.model.config.prefix&&(e=e.map(e=>this.model.config.prefix+e));let n=this.model.config.task_specific_params;n&&n[this.task]&&n[this.task].prefix&&(e=e.map(e=>n[this.task].prefix+e));let r=this.tokenizer,i={padding:!0,truncation:!0},a;a=this instanceof S&&`_build_translation_inputs`in r?r._build_translation_inputs(e,i,t):r(e,i);let o=await this.model.generate({...a,...t});return r.batch_decode(o,{skip_special_tokens:!0}).map(e=>({[this._key]:e}))}}class x extends b{_key=`summary_text`;constructor(e){super(e)}}class S extends b{_key=`translation_text`;constructor(e){super(e)}}function C(e){return Array.isArray(e)&&e.every(e=>`role`in e&&`content`in e)}class w extends h{constructor(e){super(e)}async _call(e,t={}){let n=!1,r=!1,i=t.add_special_tokens??(this.tokenizer.add_bos_token||this.tokenizer.add_eos_token)??!1,a;if(typeof e==`string`)a=e=[e];else if(Array.isArray(e)&&e.every(e=>typeof e==`string`))n=!0,a=e;else{if(C(e))e=[e];else if(Array.isArray(e)&&e.every(C))n=!0;else throw Error(`Input must be a string, an array of strings, a Chat, or an array of Chats`);r=!0,a=e.map(e=>this.tokenizer.apply_chat_template(e,{tokenize:!1,add_generation_prompt:!0})),i=!1}let o=r?!1:t.return_full_text??!0;this.tokenizer.padding_side=`left`;let s=this.tokenizer(a,{add_special_tokens:i,padding:!0,truncation:!0}),c=await this.model.generate({...s,...t}),l=this.tokenizer.batch_decode(c,{skip_special_tokens:!0}),u;!o&&s.input_ids.dims.at(-1)>0&&(u=this.tokenizer.batch_decode(s.input_ids,{skip_special_tokens:!0}).map(e=>e.length));let d=Array.from({length:e.length},e=>[]);for(let t=0;t<l.length;++t){let n=Math.floor(t/c.dims[0]*e.length);u&&(l[t]=l[t].slice(u[n])),d[n].push({generated_text:r?[...e[n],{role:`assistant`,content:l[t]}]:l[t]})}return!n&&d.length===1?d[0]:d}}class T extends h{constructor(e){super(e),this.label2id=Object.fromEntries(Object.entries(this.model.config.label2id).map(([e,t])=>[e.toLowerCase(),t])),this.entailment_id=this.label2id.entailment,this.entailment_id===void 0&&(console.warn(`Could not find 'entailment' in label2id mapping. Using 2 as entailment_id.`),this.entailment_id=2),this.contradiction_id=this.label2id.contradiction??this.label2id.not_entailment,this.contradiction_id===void 0&&(console.warn(`Could not find 'contradiction' in label2id mapping. Using 0 as contradiction_id.`),this.contradiction_id=0)}async _call(e,t,{hypothesis_template:n=`This example is {}.`,multi_label:r=!1}={}){let i=Array.isArray(e);i||(e=[e]),Array.isArray(t)||(t=[t]);let a=t.map(e=>n.replace(`{}`,e)),o=r||t.length===1,s=[];for(let n of e){let e=[];for(let t of a){let r=this.tokenizer(n,{text_pair:t,padding:!0,truncation:!0}),i=await this.model(r);o?e.push([i.logits.data[this.contradiction_id],i.logits.data[this.entailment_id]]):e.push(i.logits.data[this.entailment_id])}let r=(o?e.map(e=>(0,c.softmax)(e)[1]):(0,c.softmax)(e)).map((e,t)=>[e,t]).sort((e,t)=>t[0]-e[0]);s.push({sequence:n,labels:r.map(e=>t[e[1]]),scores:r.map(e=>e[0])})}return i?s:s[0]}}class E extends h{constructor(e){super(e)}async _call(e,{pooling:t=`none`,normalize:n=!1,quantize:r=!1,precision:i=`binary`}={}){let a=this.tokenizer(e,{padding:!0,truncation:!0}),o=await this.model(a),s=o.last_hidden_state??o.logits??o.token_embeddings;switch(t){case`none`:break;case`mean`:s=(0,u.mean_pooling)(s,a.attention_mask);break;case`first_token`:case`cls`:s=s.slice(null,0);break;case`last_token`:case`eos`:s=s.slice(null,-1);break;default:throw Error(`Pooling method '${t}' not supported.`)}return n&&(s=s.normalize(2,-1)),r&&(s=(0,u.quantize_embeddings)(s,i)),s}}class D extends h{constructor(e){super(e)}async _call(e,{pool:t=null}={}){let n=await f(e),{pixel_values:r}=await this.processor(n),i=await this.model({pixel_values:r}),a;if(t){if(!(`pooler_output`in i))throw Error(`No pooled output was returned. Make sure the model has a 'pooler' layer when using the 'pool' option.`);a=i.pooler_output}else a=i.last_hidden_state??i.logits??i.image_embeds;return a}}class O extends h{constructor(e){super(e)}async _call(e,{top_k:t=5}={}){let n=this.processor.feature_extractor.config.sampling_rate,r=await p(e,n),i=this.model.config.id2label,a=[];for(let e of r){let n=await this.processor(e),r=(await this.model(n)).logits[0],o=await(0,u.topk)(new u.Tensor(`float32`,(0,c.softmax)(r.data),r.dims),t),s=o[0].tolist(),l=o[1].tolist().map((e,t)=>({label:i?i[e]:`LABEL_${e}`,score:s[t]}));a.push(l)}return Array.isArray(e)?a:a[0]}}class k extends h{constructor(e){super(e)}async _call(e,t,{hypothesis_template:n=`This is a sound of {}.`}={}){let r=!Array.isArray(e);r&&(e=[e]);let i=t.map(e=>n.replace(`{}`,e)),a=this.tokenizer(i,{padding:!0,truncation:!0}),o=this.processor.feature_extractor.config.sampling_rate,s=await p(e,o),l=[];for(let e of s){let n=await this.processor(e),r=await this.model({...a,...n}),i=(0,c.softmax)(r.logits_per_audio.data);l.push([...i].map((e,n)=>({score:e,label:t[n]})))}return r?l[0]:l}}class A extends h{constructor(e){super(e)}async _call(e,t={}){switch(this.model.config.model_type){case`whisper`:case`lite-whisper`:return this._call_whisper(e,t);case`wav2vec2`:case`wav2vec2-bert`:case`unispeech`:case`unispeech-sat`:case`hubert`:case`parakeet_ctc`:return this._call_wav2vec2(e,t);case`moonshine`:return this._call_moonshine(e,t);default:throw Error(`AutomaticSpeechRecognitionPipeline does not support model type '${this.model.config.model_type}'.`)}}async _call_wav2vec2(e,t){t.language&&console.warn('`language` parameter is not yet supported for `wav2vec2` models, defaulting to "English".'),t.task&&console.warn('`task` parameter is not yet supported for `wav2vec2` models, defaulting to "transcribe".');let n=!Array.isArray(e);n&&(e=[e]);let r=this.processor.feature_extractor.config.sampling_rate,i=await p(e,r),a=[];for(let e of i){let t=await this.processor(e),n=(await this.model(t)).logits[0],r=[];for(let e of n)r.push((0,c.max)(e.data)[1]);let i=this.tokenizer.decode(r,{skip_special_tokens:!0}).trim();a.push({text:i})}return n?a[0]:a}async _call_whisper(e,t){let n=t.return_timestamps??!1,r=t.chunk_length_s??0,i=t.force_full_sequences??!1,a=t.stride_length_s??null,o={...t};n===`word`&&(o.return_token_timestamps=!0,o.return_timestamps=!1);let s=!Array.isArray(e);s&&(e=[e]);let l=this.processor.feature_extractor.config.chunk_length/this.model.config.max_source_positions,u=this.processor.feature_extractor.config.hop_length,d=this.processor.feature_extractor.config.sampling_rate,f=await p(e,d),m=[];for(let e of f){let t=[];if(r>0){if(a===null)a=r/6;else if(r<=a)throw Error("`chunk_length_s` must be larger than `stride_length_s`.");let n=d*r,i=d*a,o=n-2*i,s=0;for(;;){let r=s+n,a=e.subarray(s,r),c=await this.processor(a),l=s===0,u=r>=e.length;if(t.push({stride:[a.length,l?0:i,u?0:i],input_features:c.input_features,is_last:u}),u)break;s+=o}}else t=[{stride:[e.length,0,0],input_features:(await this.processor(e)).input_features,is_last:!0}];for(let e of t){o.num_frames=Math.floor(e.stride[0]/u);let t=await this.model.generate({inputs:e.input_features,...o});n===`word`?(e.tokens=t.sequences.tolist()[0],e.token_timestamps=t.token_timestamps.tolist()[0].map(e=>(0,c.round)(e,2))):e.tokens=t[0].tolist(),e.stride=e.stride.map(e=>e/d)}let[s,f]=this.tokenizer._decode_asr(t,{time_precision:l,return_timestamps:n,force_full_sequences:i});m.push({text:s,...f})}return s?m[0]:m}async _call_moonshine(e,t){let n=!Array.isArray(e);n&&(e=[e]);let r=this.processor.feature_extractor.config.sampling_rate,i=await p(e,r),a=[];for(let e of i){let n=await this.processor(e),i=Math.floor(e.length/r)*6,o=await this.model.generate({max_new_tokens:i,...t,...n}),s=this.processor.batch_decode(o,{skip_special_tokens:!0})[0];a.push({text:s})}return n?a[0]:a}}class ee extends h{constructor(e){super(e)}async _call(e,t={}){let n=Array.isArray(e),r=await f(e),{pixel_values:i}=await this.processor(r),a=[];for(let e of i){e.dims=[1,...e.dims];let n=await this.model.generate({inputs:e,...t}),r=this.tokenizer.batch_decode(n,{skip_special_tokens:!0}).map(e=>({generated_text:e.trim()}));a.push(r)}return n?a:a[0]}}class te extends h{constructor(e){super(e)}async _call(e,{top_k:t=5}={}){let n=await f(e),{pixel_values:r}=await this.processor(n),i=await this.model({pixel_values:r}),a=this.model.config.id2label,o=[];for(let e of i.logits){let n=await(0,u.topk)(new u.Tensor(`float32`,(0,c.softmax)(e.data),e.dims),t),r=n[0].tolist(),i=n[1].tolist().map((e,t)=>({label:a?a[e]:`LABEL_${e}`,score:r[t]}));o.push(i)}return Array.isArray(e)?o:o[0]}}class ne extends h{constructor(e){super(e),this.subtasks_mapping={panoptic:`post_process_panoptic_segmentation`,instance:`post_process_instance_segmentation`,semantic:`post_process_semantic_segmentation`}}async _call(e,{threshold:t=.5,mask_threshold:n=.5,overlap_mask_area_threshold:r=.8,label_ids_to_fuse:i=null,target_sizes:a=null,subtask:o=null}={}){if(Array.isArray(e)&&e.length!==1)throw Error(`Image segmentation pipeline currently only supports a batch size of 1.`);let s=await f(e),c=s.map(e=>[e.height,e.width]),l=await this.processor(s),{inputNames:u,outputNames:p}=this.model.sessions.model;if(!u.includes(`pixel_values`)){if(u.length!==1)throw Error(`Expected a single input name, but got ${u.length} inputs: ${u}.`);let e=u[0];if(e in l)throw Error(`Input name ${e} already exists in the inputs.`);l[e]=l.pixel_values}let m=await this.model(l),h=null;if(o!==null)h=this.subtasks_mapping[o];else if(this.processor.image_processor){for(let[e,t]of Object.entries(this.subtasks_mapping))if(t in this.processor.image_processor){h=this.processor.image_processor[t].bind(this.processor.image_processor),o=e;break}}let g=this.model.config.id2label,_=[];if(!o){let e=1e-5,t=m[p[0]];for(let n=0;n<c.length;++n){let r=c[n],i=t[n];i.data.some(t=>t<-e||t>1+e)&&i.sigmoid_();let a=await d.RawImage.fromTensor(i.mul_(255).to(`uint8`)).resize(r[1],r[0]);_.push({label:null,score:null,mask:a})}}else if(o===`panoptic`||o===`instance`){let e=h(m,t,n,r,i,a??c)[0],o=e.segmentation;for(let t of e.segments_info){let e=new Uint8ClampedArray(o.data.length);for(let n=0;n<o.data.length;++n)o.data[n]===t.id&&(e[n]=255);let n=new d.RawImage(e,o.dims[1],o.dims[0],1);_.push({score:t.score,label:g[t.label_id],mask:n})}}else if(o===`semantic`){let{segmentation:e,labels:t}=h(m,a??c)[0];for(let n of t){let t=new Uint8ClampedArray(e.data.length);for(let r=0;r<e.data.length;++r)e.data[r]===n&&(t[r]=255);let r=new d.RawImage(t,e.dims[1],e.dims[0],1);_.push({score:null,label:g[n],mask:r})}}else throw Error(`Subtask ${o} not supported.`);return _}}class j extends ne{constructor(e){super(e)}async _call(e,t={}){if(Array.isArray(e)&&e.length!==1)throw Error(`Background removal pipeline currently only supports a batch size of 1.`);let n=await f(e),r=await super._call(e,t);return n.map((e,t)=>{let n=e.clone();return n.putAlpha(r[t].mask),n})}}class re extends h{constructor(e){super(e)}async _call(e,t,{hypothesis_template:n=`This is a photo of {}`}={}){let r=Array.isArray(e),i=await f(e),a=t.map(e=>n.replace(`{}`,e)),o=this.tokenizer(a,{padding:this.model.config.model_type===`siglip`?`max_length`:!0,truncation:!0}),{pixel_values:s}=await this.processor(i),l=await this.model({...o,pixel_values:s}),u=this.model.config.model_type===`siglip`?e=>e.sigmoid().data:e=>(0,c.softmax)(e.data),d=[];for(let e of l.logits_per_image){let n=[...u(e)].map((e,n)=>({score:e,label:t[n]}));n.sort((e,t)=>t.score-e.score),d.push(n)}return r?d:d[0]}}class ie extends h{constructor(e){super(e)}async _call(e,{threshold:t=.9,percentage:n=!1}={}){let r=Array.isArray(e);if(r&&e.length!==1)throw Error(`Object detection pipeline currently only supports a batch size of 1.`);let i=await f(e),a=n?null:i.map(e=>[e.height,e.width]),{pixel_values:o,pixel_mask:s}=await this.processor(i),c=await this.model({pixel_values:o,pixel_mask:s}),l=this.processor.image_processor.post_process_object_detection(c,t,a),u=this.model.config.id2label,d=l.map(e=>e.boxes.map((t,r)=>({score:e.scores[r],label:u[e.classes[r]],box:m(t,!n)})));return r?d:d[0]}}class ae extends h{constructor(e){super(e)}async _call(e,t,{threshold:n=.1,top_k:r=null,percentage:i=!1}={}){let a=Array.isArray(e),o=await f(e),s=this.tokenizer(t,{padding:!0,truncation:!0}),c=await this.processor(o),l=[];for(let e=0;e<o.length;++e){let a=o[e],u=i?null:[[a.height,a.width]],d=c.pixel_values[e].unsqueeze_(0),f=await this.model({...s,pixel_values:d}),p;if(`post_process_grounded_object_detection`in this.processor){let e=this.processor.post_process_grounded_object_detection(f,s.input_ids,{box_threshold:n,text_threshold:n,target_sizes:u})[0];p=e.boxes.map((t,n)=>({score:e.scores[n],label:e.labels[n],box:m(t,!i)}))}else{let e=this.processor.image_processor.post_process_object_detection(f,n,u,!0)[0];p=e.boxes.map((n,r)=>({score:e.scores[r],label:t[e.classes[r]],box:m(n,!i)}))}p.sort((e,t)=>t.score-e.score),r!==null&&(p=p.slice(0,r)),l.push(p)}return a?l:l[0]}}class oe extends h{constructor(e){super(e)}async _call(e,t,n={}){let r=(await f(e))[0],{pixel_values:i}=await this.processor(r),a=`<s_docvqa><s_question>${t}</s_question><s_answer>`,o=this.tokenizer(a,{add_special_tokens:!1,padding:!0,truncation:!0}).input_ids,s=await this.model.generate({inputs:i,max_length:this.model.config.decoder.max_position_embeddings,decoder_input_ids:o,...n}),c=this.tokenizer.batch_decode(s)[0].match(/<s_answer>(.*?)<\/s_answer>/),l=null;return c&&c.length>=2&&(l=c[1].trim()),[{answer:l}]}}class se extends h{DEFAULT_VOCODER_ID=`Xenova/speecht5_hifigan`;constructor(e){super(e),this.vocoder=e.vocoder??null}async _prepare_speaker_embeddings(e){if((typeof e==`string`||e instanceof URL)&&(e=new Float32Array(await(await fetch(e)).arrayBuffer())),e instanceof Float32Array)e=new u.Tensor(`float32`,e,[e.length]);else if(!(e instanceof u.Tensor))throw Error("Speaker embeddings must be a `Tensor`, `Float32Array`, `string`, or `URL`.");return e}async _call(e,{speaker_embeddings:t=null,num_inference_steps:n,speed:r}={}){return this.processor?this._call_text_to_spectrogram(e,{speaker_embeddings:t}):this.model.config.model_type===`supertonic`?this._call_supertonic(e,{speaker_embeddings:t,num_inference_steps:n,speed:r}):this._call_text_to_waveform(e)}async _call_supertonic(e,{speaker_embeddings:t,num_inference_steps:n,speed:r}){if(!t)throw Error(`Speaker embeddings must be provided for Supertonic models.`);t=await this._prepare_speaker_embeddings(t);let{sampling_rate:i,style_dim:a}=this.model.config;t=t.view(1,-1,a);let o=this.tokenizer(e,{padding:!0,truncation:!0}),{waveform:s}=await this.model.generate_speech({...o,style:t,num_inference_steps:n,speed:r});return new l.RawAudio(s.data,i)}async _call_text_to_waveform(e){let t=this.tokenizer(e,{padding:!0,truncation:!0}),{waveform:n}=await this.model(t),r=this.model.config.sampling_rate;return new l.RawAudio(n.data,r)}async _call_text_to_spectrogram(e,{speaker_embeddings:t}){this.vocoder||=(console.log(`No vocoder specified, using default HifiGan vocoder.`),await i.AutoModel.from_pretrained(this.DEFAULT_VOCODER_ID,{dtype:`fp32`}));let{input_ids:n}=this.tokenizer(e,{padding:!0,truncation:!0});t=await this._prepare_speaker_embeddings(t),t=t.view(1,-1);let{waveform:r}=await this.model.generate_speech(n,t,{vocoder:this.vocoder}),a=this.processor.feature_extractor.config.sampling_rate;return new l.RawAudio(r.data,a)}}class M extends h{constructor(e){super(e)}async _call(e){let t=await f(e),n=await this.processor(t),r=await this.model(n),i=[];for(let e of r.reconstruction){let t=e.squeeze().clamp_(0,1).mul_(255).round_().to(`uint8`);i.push(d.RawImage.fromTensor(t))}return i.length>1?i:i[0]}}class N extends h{constructor(e){super(e)}async _call(e){let t=await f(e),n=await this.processor(t),{predicted_depth:r}=await this.model(n),i=[];for(let e=0;e<t.length;++e){let n=r[e],[a,o]=n.dims.slice(-2),[s,c]=t[e].size,l=(await(0,u.interpolate_4d)(n.view(1,1,a,o),{size:[c,s],mode:`bilinear`})).view(c,s),f=l.min().item(),p=l.max().item(),m=l.sub(f).div_(p-f).mul_(255).to(`uint8`).unsqueeze(0),h=d.RawImage.fromTensor(m);i.push({predicted_depth:l,depth:h})}return i.length>1?i:i[0]}}let ce=Object.freeze({"text-classification":{tokenizer:r.AutoTokenizer,pipeline:g,model:i.AutoModelForSequenceClassification,default:{model:`Xenova/distilbert-base-uncased-finetuned-sst-2-english`},type:`text`},"token-classification":{tokenizer:r.AutoTokenizer,pipeline:_,model:i.AutoModelForTokenClassification,default:{model:`Xenova/bert-base-multilingual-cased-ner-hrl`},type:`text`},"question-answering":{tokenizer:r.AutoTokenizer,pipeline:v,model:i.AutoModelForQuestionAnswering,default:{model:`Xenova/distilbert-base-cased-distilled-squad`},type:`text`},"fill-mask":{tokenizer:r.AutoTokenizer,pipeline:y,model:i.AutoModelForMaskedLM,default:{model:`Xenova/bert-base-uncased`},type:`text`},summarization:{tokenizer:r.AutoTokenizer,pipeline:x,model:i.AutoModelForSeq2SeqLM,default:{model:`Xenova/distilbart-cnn-6-6`},type:`text`},translation:{tokenizer:r.AutoTokenizer,pipeline:S,model:i.AutoModelForSeq2SeqLM,default:{model:`Xenova/t5-small`},type:`text`},"text2text-generation":{tokenizer:r.AutoTokenizer,pipeline:b,model:i.AutoModelForSeq2SeqLM,default:{model:`Xenova/flan-t5-small`},type:`text`},"text-generation":{tokenizer:r.AutoTokenizer,pipeline:w,model:i.AutoModelForCausalLM,default:{model:`Xenova/gpt2`},type:`text`},"zero-shot-classification":{tokenizer:r.AutoTokenizer,pipeline:T,model:i.AutoModelForSequenceClassification,default:{model:`Xenova/distilbert-base-uncased-mnli`},type:`text`},"audio-classification":{pipeline:O,model:i.AutoModelForAudioClassification,processor:a.AutoProcessor,default:{model:`Xenova/wav2vec2-base-superb-ks`},type:`audio`},"zero-shot-audio-classification":{tokenizer:r.AutoTokenizer,pipeline:k,model:i.AutoModel,processor:a.AutoProcessor,default:{model:`Xenova/clap-htsat-unfused`},type:`multimodal`},"automatic-speech-recognition":{tokenizer:r.AutoTokenizer,pipeline:A,model:[i.AutoModelForSpeechSeq2Seq,i.AutoModelForCTC],processor:a.AutoProcessor,default:{model:`Xenova/whisper-tiny.en`},type:`multimodal`},"text-to-audio":{tokenizer:r.AutoTokenizer,pipeline:se,model:[i.AutoModelForTextToWaveform,i.AutoModelForTextToSpectrogram],processor:[a.AutoProcessor,null],default:{model:`Xenova/speecht5_tts`},type:`text`},"image-to-text":{tokenizer:r.AutoTokenizer,pipeline:ee,model:i.AutoModelForVision2Seq,processor:a.AutoProcessor,default:{model:`Xenova/vit-gpt2-image-captioning`},type:`multimodal`},"image-classification":{pipeline:te,model:i.AutoModelForImageClassification,processor:a.AutoProcessor,default:{model:`Xenova/vit-base-patch16-224`},type:`multimodal`},"image-segmentation":{pipeline:ne,model:[i.AutoModelForImageSegmentation,i.AutoModelForSemanticSegmentation,i.AutoModelForUniversalSegmentation],processor:a.AutoProcessor,default:{model:`Xenova/detr-resnet-50-panoptic`},type:`multimodal`},"background-removal":{pipeline:j,model:[i.AutoModelForImageSegmentation,i.AutoModelForSemanticSegmentation,i.AutoModelForUniversalSegmentation],processor:a.AutoProcessor,default:{model:`Xenova/modnet`},type:`image`},"zero-shot-image-classification":{tokenizer:r.AutoTokenizer,pipeline:re,model:i.AutoModel,processor:a.AutoProcessor,default:{model:`Xenova/clip-vit-base-patch32`},type:`multimodal`},"object-detection":{pipeline:ie,model:i.AutoModelForObjectDetection,processor:a.AutoProcessor,default:{model:`Xenova/detr-resnet-50`},type:`multimodal`},"zero-shot-object-detection":{tokenizer:r.AutoTokenizer,pipeline:ae,model:i.AutoModelForZeroShotObjectDetection,processor:a.AutoProcessor,default:{model:`Xenova/owlvit-base-patch32`},type:`multimodal`},"document-question-answering":{tokenizer:r.AutoTokenizer,pipeline:oe,model:i.AutoModelForDocumentQuestionAnswering,processor:a.AutoProcessor,default:{model:`Xenova/donut-base-finetuned-docvqa`},type:`multimodal`},"image-to-image":{pipeline:M,model:i.AutoModelForImageToImage,processor:a.AutoProcessor,default:{model:`Xenova/swin2SR-classical-sr-x2-64`},type:`image`},"depth-estimation":{pipeline:N,model:i.AutoModelForDepthEstimation,processor:a.AutoProcessor,default:{model:`Xenova/dpt-large`},type:`image`},"feature-extraction":{tokenizer:r.AutoTokenizer,pipeline:E,model:i.AutoModel,default:{model:`Xenova/all-MiniLM-L6-v2`},type:`text`},"image-feature-extraction":{processor:a.AutoProcessor,pipeline:D,model:[i.AutoModelForImageFeatureExtraction,i.AutoModel],default:{model:`Xenova/vit-base-patch16-224-in21k`},type:`image`}}),le=Object.freeze({"sentiment-analysis":`text-classification`,ner:`token-classification`,asr:`automatic-speech-recognition`,"text-to-speech":`text-to-audio`,embeddings:`feature-extraction`});async function ue(e,t=null,{progress_callback:n=null,config:r=null,cache_dir:i=null,local_files_only:a=!1,revision:o=`main`,device:c=null,dtype:l=null,subfolder:u=`onnx`,use_external_data_format:d=null,model_file_name:f=null,session_options:p={}}={}){e=le[e]??e;let m=ce[e.split(`_`,1)[0]];if(!m)throw Error(`Unsupported pipeline: ${e}. Must be one of [${Object.keys(ce)}]`);t||(t=m.default.model,console.log(`No model specified. Using default model: "${t}".`));let h={progress_callback:n,config:r,cache_dir:i,local_files_only:a,revision:o,device:c,dtype:l,subfolder:u,use_external_data_format:d,model_file_name:f,session_options:p},g=await de(new Map([[`tokenizer`,m.tokenizer],[`model`,m.model],[`processor`,m.processor]]),t,h);g.task=e,(0,s.dispatchCallback)(n,{status:`ready`,task:e,model:t});let _=m.pipeline;return new _(g)}async function de(e,t,n){let r=Object.create(null),i=[];for(let[a,o]of e.entries()){if(!o)continue;let e;e=Array.isArray(o)?new Promise(async(e,r)=>{let i;for(let a of o){if(a===null){e(null);return}try{e(await a.from_pretrained(t,n));return}catch(e){if(e.message?.includes(`Unsupported model type`))i=e;else if(e.message?.includes(`Could not locate file`))i=e;else{r(e);return}}}r(i)}):o.from_pretrained(t,n),r[a]=e,i.push(e)}await Promise.all(i);for(let[e,t]of Object.entries(r))r[e]=await t;return r}}),"./src/tokenizers.js":((e,t,n)=>{n.r(t),n.d(t,{AlbertTokenizer:()=>He,AutoTokenizer:()=>Mt,BartTokenizer:()=>tt,BertTokenizer:()=>Ve,BlenderbotSmallTokenizer:()=>Et,BlenderbotTokenizer:()=>Tt,BloomTokenizer:()=>at,CLIPTokenizer:()=>xt,CamembertTokenizer:()=>Xe,CodeGenTokenizer:()=>bt,CodeLlamaTokenizer:()=>st,CohereTokenizer:()=>At,ConvBertTokenizer:()=>qe,DebertaTokenizer:()=>V,DebertaV2Tokenizer:()=>Ge,DistilBertTokenizer:()=>Ye,ElectraTokenizer:()=>Qe,EsmTokenizer:()=>ft,FalconTokenizer:()=>ut,GPT2Tokenizer:()=>et,GPTNeoXTokenizer:()=>dt,GemmaTokenizer:()=>mt,Grok1Tokenizer:()=>ht,HerbertTokenizer:()=>Ke,LlamaTokenizer:()=>ot,M2M100Tokenizer:()=>vt,MBart50Tokenizer:()=>rt,MBartTokenizer:()=>nt,MPNetTokenizer:()=>lt,MarianTokenizer:()=>Ct,MgpstrTokenizer:()=>jt,MobileBertTokenizer:()=>Ue,NllbTokenizer:()=>_t,NougatTokenizer:()=>Ot,PreTrainedTokenizer:()=>B,Qwen2Tokenizer:()=>pt,RoFormerTokenizer:()=>Je,RobertaTokenizer:()=>it,SiglipTokenizer:()=>St,SpeechT5Tokenizer:()=>Dt,SqueezeBertTokenizer:()=>We,T5Tokenizer:()=>$e,TokenizerModel:()=>D,VitsTokenizer:()=>kt,Wav2Vec2CTCTokenizer:()=>wt,WhisperTokenizer:()=>yt,XLMRobertaTokenizer:()=>ct,XLMTokenizer:()=>Ze,is_chinese_char:()=>y});var r=n(`./src/utils/generic.js`),i=n(`./src/utils/core.js`),a=n(`./src/utils/hub.js`),o=n(`./src/utils/maths.js`),s=n(`./src/utils/tensor.js`),c=n(`./src/utils/data-structures.js`),l=n(`./node_modules/@huggingface/jinja/dist/index.js`),u=n(`./src/models/whisper/common_whisper.js`);async function d(e,t){let n=await Promise.all([(0,a.getModelJSON)(e,`tokenizer.json`,!0,t),(0,a.getModelJSON)(e,`tokenizer_config.json`,!0,t)]);return t.legacy!==null&&(n[1].legacy=t.legacy),n}function f(e,t){let n=[],r=0;for(let i of e.matchAll(t)){let t=i[0];r<i.index&&n.push(e.slice(r,i.index)),t.length>0&&n.push(t),r=i.index+t.length}return r<e.length&&n.push(e.slice(r)),n}function p(e,t=!0){if(e.Regex!==void 0){let t=e.Regex.replace(/\\([#&~])/g,`$1`);for(let[e,n]of T)t=t.replaceAll(e,n);return new RegExp(t,`gu`)}else if(e.String!==void 0){let n=(0,i.escapeRegExp)(e.String);return new RegExp(t?n:`(${n})`,`gu`)}else return console.warn(`Unknown pattern type:`,e),null}function m(e){return new Map(Object.entries(e))}function h(e){let t=e.dims;switch(t.length){case 1:return e.tolist();case 2:if(t[0]!==1)throw Error("Unable to decode tensor with `batch size !== 1`. Use `tokenizer.batch_decode(...)` for batched inputs.");return e.tolist()[0];default:throw Error(`Expected tensor to have 1-2 dimensions, got ${t.length}.`)}}function g(e){return e.replace(/ \./g,`.`).replace(/ \?/g,`?`).replace(/ \!/g,`!`).replace(/ ,/g,`,`).replace(/ \' /g,`'`).replace(/ n\'t/g,`n't`).replace(/ \'m/g,`'m`).replace(/ \'s/g,`'s`).replace(/ \'ve/g,`'ve`).replace(/ \'re/g,`'re`)}function _(e){return e.replace(/\p{M}/gu,``)}function v(e){return _(e.toLowerCase())}function y(e){return e>=19968&&e<=40959||e>=13312&&e<=19903||e>=131072&&e<=173791||e>=173824&&e<=177983||e>=177984&&e<=178207||e>=178208&&e<=183983||e>=63744&&e<=64255||e>=194560&&e<=195103}function b(e,t,n){let r=[],i=0;for(;i<e.length;){if(r.push(e[i]),(t.get(e[i])??n)!==n){++i;continue}for(;++i<e.length&&(t.get(e[i])??n)===n;)t.get(r.at(-1))!==n&&(r[r.length-1]+=e[i])}return r}function x(e){return e.match(/\S+/g)||[]}let S=`\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E`,C=RegExp(`^[${S}]+$`,`gu`),w=`.,!?…。,、।۔،`,T=new Map([[`(?i:'s|'t|'re|'ve|'m|'ll|'d)`,`(?:'([sS]|[tT]|[rR][eE]|[vV][eE]|[mM]|[lL][lL]|[dD]))`],[`(?i:[sdmt]|ll|ve|re)`,`(?:[sS]|[dD]|[mM]|[tT]|[lL][lL]|[vV][eE]|[rR][eE])`],[`[^\\r\\n\\p{L}\\p{N}]?+`,`[^\\r\\n\\p{L}\\p{N}]?`],[`[^\\s\\p{L}\\p{N}]++`,`[^\\s\\p{L}\\p{N}]+`],[` ?[^(\\s|[${w}])]+`,` ?[^\\s${w}]+`]]);class E{constructor(e){this.content=e.content,this.id=e.id,this.single_word=e.single_word??!1,this.lstrip=e.lstrip??!1,this.rstrip=e.rstrip??!1,this.special=e.special??!1,this.normalized=e.normalized??null}}class D extends r.Callable{constructor(e){super(),this.config=e,this.vocab=[],this.tokens_to_ids=new Map,this.unk_token_id=void 0,this.unk_token=void 0,this.end_of_word_suffix=void 0,this.fuse_unk=this.config.fuse_unk??!1}static fromConfig(e,...t){switch(e.type){case`WordPiece`:return new O(e);case`Unigram`:return new k(e,...t);case`BPE`:return new te(e);default:if(e.vocab)return Array.isArray(e.vocab)?new k(e,...t):Object.hasOwn(e,`continuing_subword_prefix`)&&Object.hasOwn(e,`unk_token`)?Object.hasOwn(e,`merges`)?new te(e):new O(e):new ne(e,...t);throw Error(`Unknown TokenizerModel type: ${e.type}`)}}_call(e){return e=this.encode(e),this.fuse_unk&&(e=b(e,this.tokens_to_ids,this.unk_token_id)),e}encode(e){throw Error(`encode should be implemented in subclass.`)}convert_tokens_to_ids(e){return e.map(e=>this.tokens_to_ids.get(e)??this.unk_token_id)}convert_ids_to_tokens(e){return e.map(e=>this.vocab[e]??this.unk_token)}}class O extends D{constructor(e){super(e),this.tokens_to_ids=m(e.vocab),this.unk_token_id=this.tokens_to_ids.get(e.unk_token),this.unk_token=e.unk_token,this.max_input_chars_per_word=e.max_input_chars_per_word??100,this.vocab=Array(this.tokens_to_ids.size);for(let[e,t]of this.tokens_to_ids)this.vocab[t]=e}encode(e){let t=[];for(let n of e){let e=[...n];if(e.length>this.max_input_chars_per_word){t.push(this.unk_token);continue}let r=!1,i=0,a=[];for(;i<e.length;){let t=e.length,n=null;for(;i<t;){let r=e.slice(i,t).join(``);if(i>0&&(r=this.config.continuing_subword_prefix+r),this.tokens_to_ids.has(r)){n=r;break}--t}if(n===null){r=!0;break}a.push(n),i=t}r?t.push(this.unk_token):t.push(...a)}return t}}class k extends D{constructor(e,t){super(e);let n=e.vocab.length;this.vocab=Array(n),this.scores=Array(n);for(let t=0;t<n;++t)[this.vocab[t],this.scores[t]]=e.vocab[t];this.unk_token_id=e.unk_id,this.unk_token=this.vocab[e.unk_id],this.tokens_to_ids=new Map(this.vocab.map((e,t)=>[e,t])),this.bos_token=` `,this.bos_token_id=this.tokens_to_ids.get(this.bos_token),this.eos_token=t.eos_token,this.eos_token_id=this.tokens_to_ids.get(this.eos_token),this.unk_token=this.vocab[this.unk_token_id],this.minScore=(0,o.min)(this.scores)[0],this.unk_score=this.minScore-10,this.scores[this.unk_token_id]=this.unk_score,this.trie=new c.CharTrie,this.trie.extend(this.vocab),this.fuse_unk=!0}populateNodes(e){let t=e.chars,n=0;for(;n<t.length;){let r=!1,a=[],o=t.slice(n).join(``),s=this.trie.commonPrefixSearch(o);for(let t of s){a.push(t);let o=this.tokens_to_ids.get(t),s=this.scores[o],c=(0,i.len)(t);e.insert(n,c,s,o),!r&&c===1&&(r=!0)}r||e.insert(n,1,this.unk_score,this.unk_token_id),n+=1}}tokenize(e){let t=new c.TokenLattice(e,this.bos_token_id,this.eos_token_id);return this.populateNodes(t),t.tokens()}encode(e){let t=[];for(let n of e){let e=this.tokenize(n);t.push(...e)}return t}}let A=(()=>{let e=[...Array.from({length:94},(e,t)=>t+33),...Array.from({length:12},(e,t)=>t+161),...Array.from({length:82},(e,t)=>t+174)],t=e.slice(),n=0;for(let r=0;r<256;++r)e.includes(r)||(e.push(r),t.push(256+n),n+=1);let r=t.map(e=>String.fromCharCode(e));return Object.fromEntries(e.map((e,t)=>[e,r[t]]))})(),ee=(0,i.reverseDictionary)(A);class te extends D{constructor(e){super(e),this.tokens_to_ids=m(e.vocab),this.unk_token_id=this.tokens_to_ids.get(e.unk_token),this.unk_token=e.unk_token,this.vocab=Array(this.tokens_to_ids.size);for(let[e,t]of this.tokens_to_ids)this.vocab[t]=e;this.merges=Array.isArray(e.merges[0])?e.merges:e.merges.map(e=>e.split(` `,2)),this.bpe_ranks=new Map(this.merges.map((e,t)=>[JSON.stringify(e),t])),this.end_of_word_suffix=e.end_of_word_suffix,this.continuing_subword_suffix=e.continuing_subword_suffix??null,this.byte_fallback=this.config.byte_fallback??!1,this.byte_fallback&&(this.text_encoder=new TextEncoder),this.ignore_merges=this.config.ignore_merges??!1,this.max_length_to_cache=256,this.cache_capacity=1e4,this.cache=new c.LRUCache(this.cache_capacity)}clear_cache(){this.cache.clear()}bpe(e){if(e.length===0)return[];let t=this.cache.get(e);if(t!==void 0)return t;let n=Array.from(e);this.end_of_word_suffix&&(n[n.length-1]+=this.end_of_word_suffix);let r=[];if(n.length>1){let e=new c.PriorityQueue((e,t)=>e.score<t.score),t={token:n[0],bias:0,prev:null,next:null},i=t;for(let t=1;t<n.length;++t){let r={bias:t/n.length,token:n[t],prev:i,next:null};i.next=r,this._add_node(e,i),i=r}for(;!e.isEmpty();){let n=e.pop();if(n.deleted||!n.next||n.next.deleted)continue;if(n.deleted=!0,n.next.deleted=!0,n.prev){let e={...n.prev};n.prev.deleted=!0,n.prev=e,e.prev?e.prev.next=e:t=e}let r={token:n.token+n.next.token,bias:n.bias,prev:n.prev,next:n.next.next};r.prev?(r.prev.next=r,this._add_node(e,r.prev)):t=r,r.next&&(r.next.prev=r,this._add_node(e,r))}for(let e=t;e!==null;e=e.next)r.push(e.token)}else r=n;if(this.continuing_subword_suffix)for(let e=0;e<r.length-1;++e)r[e]+=this.continuing_subword_suffix;return e.length<this.max_length_to_cache&&this.cache.put(e,r),r}_add_node(e,t){let n=this.bpe_ranks.get(JSON.stringify([t.token,t.next.token]));n!==void 0&&(t.score=n+t.bias,e.push(t))}encode(e){let t=[];for(let n of e){if(this.ignore_merges&&this.tokens_to_ids.has(n)){t.push(n);continue}let e=this.bpe(n);for(let n of e)if(this.tokens_to_ids.has(n))t.push(n);else if(this.byte_fallback){let e=Array.from(this.text_encoder.encode(n)).map(e=>`<0x${e.toString(16).toUpperCase().padStart(2,`0`)}>`);e.every(e=>this.tokens_to_ids.has(e))?t.push(...e):t.push(this.unk_token)}else t.push(this.unk_token)}return t}}class ne extends D{constructor(e,t){super(e),this.tokens_to_ids=m(t.target_lang?e.vocab[t.target_lang]:e.vocab),this.bos_token=t.bos_token,this.bos_token_id=this.tokens_to_ids.get(this.bos_token),this.eos_token=t.eos_token,this.eos_token_id=this.tokens_to_ids.get(this.eos_token),this.pad_token=t.pad_token,this.pad_token_id=this.tokens_to_ids.get(this.pad_token),this.unk_token=t.unk_token,this.unk_token_id=this.tokens_to_ids.get(this.unk_token),this.vocab=Array(this.tokens_to_ids.size);for(let[e,t]of this.tokens_to_ids)this.vocab[t]=e}encode(e){return e}}class j extends r.Callable{constructor(e){super(),this.config=e}static fromConfig(e){if(e===null)return null;switch(e.type){case`BertNormalizer`:return new fe(e);case`Precompiled`:return new Me(e);case`Sequence`:return new de(e);case`Replace`:return new re(e);case`NFC`:return new ae(e);case`NFD`:return new oe(e);case`NFKC`:return new se(e);case`NFKD`:return new M(e);case`Strip`:return new N(e);case`StripAccents`:return new ce(e);case`Lowercase`:return new le(e);case`Prepend`:return new ue(e);default:throw Error(`Unknown Normalizer type: ${e.type}`)}}normalize(e){throw Error(`normalize should be implemented in subclass.`)}_call(e){return this.normalize(e)}}class re extends j{normalize(e){let t=p(this.config.pattern);return t===null?e:e.replaceAll(t,this.config.content)}}class ie extends j{form=void 0;normalize(e){return e=e.normalize(this.form),e}}class ae extends ie{form=`NFC`}class oe extends ie{form=`NFD`}class se extends ie{form=`NFKC`}class M extends ie{form=`NFKD`}class N extends j{normalize(e){return this.config.strip_left&&this.config.strip_right?e=e.trim():(this.config.strip_left&&(e=e.trimStart()),this.config.strip_right&&(e=e.trimEnd())),e}}class ce extends j{normalize(e){return e=_(e),e}}class le extends j{normalize(e){return e=e.toLowerCase(),e}}class ue extends j{normalize(e){return e=this.config.prepend+e,e}}class de extends j{constructor(e){super(e),this.normalizers=e.normalizers.map(e=>j.fromConfig(e))}normalize(e){return this.normalizers.reduce((e,t)=>t.normalize(e),e)}}class fe extends j{_tokenize_chinese_chars(e){let t=[];for(let n=0;n<e.length;++n){let r=e[n];y(r.charCodeAt(0))?(t.push(` `),t.push(r),t.push(` `)):t.push(r)}return t.join(``)}stripAccents(e){return e.normalize(`NFD`).replace(/\p{Mn}/gu,``)}_is_control(e){switch(e){case` `:case`
2818
+ `:case`\r`:return!1;default:return/^\p{Cc}|\p{Cf}|\p{Co}|\p{Cs}$/u.test(e)}}_clean_text(e){let t=[];for(let n of e){let e=n.charCodeAt(0);e===0||e===65533||this._is_control(n)||(/^\s$/.test(n)?t.push(` `):t.push(n))}return t.join(``)}normalize(e){return this.config.clean_text&&(e=this._clean_text(e)),this.config.handle_chinese_chars&&(e=this._tokenize_chinese_chars(e)),this.config.lowercase?(e=e.toLowerCase(),this.config.strip_accents!==!1&&(e=this.stripAccents(e))):this.config.strip_accents&&(e=this.stripAccents(e)),e}}class pe extends r.Callable{static fromConfig(e){if(e===null)return null;switch(e.type){case`BertPreTokenizer`:return new P(e);case`Sequence`:return new Ne(e);case`Whitespace`:return new Pe(e);case`WhitespaceSplit`:return new Fe(e);case`Metaspace`:return new Ae(e);case`ByteLevel`:return new me(e);case`Split`:return new he(e);case`Punctuation`:return new ge(e);case`Digits`:return new _e(e);case`Replace`:return new Ie(e);case`FixedLength`:return new Le(e);default:throw Error(`Unknown PreTokenizer type: ${e.type}`)}}pre_tokenize_text(e,t){throw Error(`pre_tokenize_text should be implemented in subclass.`)}pre_tokenize(e,t){return(Array.isArray(e)?e.map(e=>this.pre_tokenize_text(e,t)):this.pre_tokenize_text(e,t)).flat()}_call(e,t){return this.pre_tokenize(e,t)}}class P extends pe{constructor(e){super(),this.pattern=RegExp(`[^\\s${S}]+|[${S}]`,`gu`)}pre_tokenize_text(e,t){return e.trim().match(this.pattern)||[]}}class me extends pe{constructor(e){super(),this.config=e,this.add_prefix_space=this.config.add_prefix_space,this.trim_offsets=this.config.trim_offsets,this.use_regex=this.config.use_regex??!0,this.pattern=/'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+/gu,this.byte_encoder=A,this.text_encoder=new TextEncoder}pre_tokenize_text(e,t){return this.add_prefix_space&&!e.startsWith(` `)&&(e=` `+e),(this.use_regex?e.match(this.pattern)||[]:[e]).map(e=>Array.from(this.text_encoder.encode(e),e=>this.byte_encoder[e]).join(``))}}class he extends pe{constructor(e){super(),this.config=e,this.pattern=p(this.config.pattern,this.config.invert)}pre_tokenize_text(e,t){return this.pattern===null?[]:this.config.invert?e.match(this.pattern)||[]:this.config.behavior?.toLowerCase()===`removed`?e.split(this.pattern).filter(e=>e):f(e,this.pattern)}}class ge extends pe{constructor(e){super(),this.config=e,this.pattern=RegExp(`[^${S}]+|[${S}]+`,`gu`)}pre_tokenize_text(e,t){return e.match(this.pattern)||[]}}class _e extends pe{constructor(e){super(),this.config=e;let t=`[^\\d]+|\\d${this.config.individual_digits?``:`+`}`;this.pattern=new RegExp(t,`gu`)}pre_tokenize_text(e,t){return e.match(this.pattern)||[]}}class ve extends r.Callable{constructor(e){super(),this.config=e}static fromConfig(e){if(e===null)return null;switch(e.type){case`TemplateProcessing`:return new I(e);case`ByteLevel`:return new L(e);case`RobertaProcessing`:return new ye(e);case`BertProcessing`:return new F(e);case`Sequence`:return new be(e);default:throw Error(`Unknown PostProcessor type: ${e.type}`)}}post_process(e,...t){throw Error(`post_process should be implemented in subclass.`)}_call(e,...t){return this.post_process(e,...t)}}class F extends ve{constructor(e){super(e),this.cls=e.cls[0],this.sep=e.sep[0]}post_process(e,t=null,{add_special_tokens:n=!0}={}){n&&(e=(0,i.mergeArrays)([this.cls],e,[this.sep]));let r=Array(e.length).fill(0);if(t!==null){let a=n&&this instanceof ye?[this.sep]:[],o=n?[this.sep]:[];e=(0,i.mergeArrays)(e,a,t,o),r=(0,i.mergeArrays)(r,Array(t.length+a.length+o.length).fill(1))}return{tokens:e,token_type_ids:r}}}class ye extends F{}class I extends ve{constructor(e){super(e),this.single=e.single,this.pair=e.pair}post_process(e,t=null,{add_special_tokens:n=!0}={}){let r=t===null?this.single:this.pair,a=[],o=[];for(let s of r)`SpecialToken`in s?n&&(a.push(s.SpecialToken.id),o.push(s.SpecialToken.type_id)):`Sequence`in s&&(s.Sequence.id===`A`?(a=(0,i.mergeArrays)(a,e),o=(0,i.mergeArrays)(o,Array(e.length).fill(s.Sequence.type_id))):s.Sequence.id===`B`&&(a=(0,i.mergeArrays)(a,t),o=(0,i.mergeArrays)(o,Array(t.length).fill(s.Sequence.type_id))));return{tokens:a,token_type_ids:o}}}class L extends ve{post_process(e,t=null){return t&&(e=(0,i.mergeArrays)(e,t)),{tokens:e}}}class be extends ve{constructor(e){super(e),this.processors=e.processors.map(e=>ve.fromConfig(e))}post_process(e,t=null,n={}){let r;for(let i of this.processors)if(i instanceof L)e=i.post_process(e).tokens,t&&=i.post_process(t).tokens;else{let a=i.post_process(e,t,n);e=a.tokens,r=a.token_type_ids}return{tokens:e,token_type_ids:r}}}class xe extends r.Callable{constructor(e){super(),this.config=e,this.added_tokens=[],this.end_of_word_suffix=null,this.trim_offsets=e.trim_offsets}static fromConfig(e){if(e===null)return null;switch(e.type){case`WordPiece`:return new we(e);case`Metaspace`:return new je(e);case`ByteLevel`:return new Te(e);case`Replace`:return new Se(e);case`ByteFallback`:return new R(e);case`Fuse`:return new Ce(e);case`Strip`:return new z(e);case`Sequence`:return new De(e);case`CTC`:return new Ee(e);case`BPEDecoder`:return new Oe(e);default:throw Error(`Unknown Decoder type: ${e.type}`)}}_call(e){return this.decode(e)}decode(e){return this.decode_chain(e).join(``)}decode_chain(e){throw Error("`decode_chain` should be implemented in subclass.")}}class Se extends xe{decode_chain(e){let t=p(this.config.pattern);return t===null?e:e.map(e=>e.replaceAll(t,this.config.content))}}class R extends xe{constructor(e){super(e),this.text_decoder=new TextDecoder}decode_chain(e){let t=[],n=[];for(let r of e){let e=null;if(r.length===6&&r.startsWith(`<0x`)&&r.endsWith(`>`)){let t=parseInt(r.slice(3,5),16);isNaN(t)||(e=t)}if(e!==null)n.push(e);else{if(n.length>0){let e=this.text_decoder.decode(Uint8Array.from(n));t.push(e),n=[]}t.push(r)}}if(n.length>0){let e=this.text_decoder.decode(Uint8Array.from(n));t.push(e),n=[]}return t}}class Ce extends xe{decode_chain(e){return[e.join(``)]}}class z extends xe{constructor(e){super(e),this.content=this.config.content,this.start=this.config.start,this.stop=this.config.stop}decode_chain(e){return e.map(e=>{let t=0;for(let n=0;n<this.start&&e[n]===this.content;++n)t=n+1;let n=e.length;for(let t=0;t<this.stop;++t){let r=e.length-t-1;if(e[r]===this.content){n=r;continue}else break}return e.slice(t,n)})}}class we extends xe{constructor(e){super(e),this.cleanup=e.cleanup}decode_chain(e){return e.map((e,t)=>(t!==0&&(e=e.startsWith(this.config.prefix)?e.replace(this.config.prefix,``):` `+e),this.cleanup&&(e=g(e)),e))}}class Te extends xe{constructor(e){super(e),this.byte_decoder=ee,this.text_decoder=new TextDecoder(`utf-8`,{fatal:!1,ignoreBOM:!0}),this.end_of_word_suffix=null}convert_tokens_to_string(e){let t=e.join(``),n=new Uint8Array([...t].map(e=>this.byte_decoder[e]));return this.text_decoder.decode(n)}decode_chain(e){let t=[],n=[];for(let r of e)this.added_tokens.find(e=>e.content===r)===void 0?n.push(r):(n.length>0&&(t.push(this.convert_tokens_to_string(n)),n=[]),t.push(r));return n.length>0&&t.push(this.convert_tokens_to_string(n)),t}}class Ee extends xe{constructor(e){super(e),this.pad_token=this.config.pad_token,this.word_delimiter_token=this.config.word_delimiter_token,this.cleanup=this.config.cleanup}convert_tokens_to_string(e){if(e.length===0)return``;let t=[e[0]];for(let n=1;n<e.length;++n)e[n]!==t.at(-1)&&t.push(e[n]);let n=t.filter(e=>e!==this.pad_token).join(``);return this.cleanup&&(n=g(n).replaceAll(this.word_delimiter_token,` `).trim()),n}decode_chain(e){return[this.convert_tokens_to_string(e)]}}class De extends xe{constructor(e){super(e),this.decoders=e.decoders.map(e=>xe.fromConfig(e))}decode_chain(e){return this.decoders.reduce((e,t)=>t.decode_chain(e),e)}}class Oe extends xe{constructor(e){super(e),this.suffix=this.config.suffix}decode_chain(e){return e.map((t,n)=>t.replaceAll(this.suffix,n===e.length-1?``:` `))}}class ke extends xe{decode_chain(e){let t=``;for(let n=1;n<e.length;n+=2)t+=e[n];return[t]}}class Ae extends pe{constructor(e){super(),this.replacement=e.replacement,this.strRep=e.str_rep||this.replacement,this.prepend_scheme=e.prepend_scheme??`always`}pre_tokenize_text(e,{section_index:t=void 0}={}){let n=e.replaceAll(` `,this.strRep);return!n.startsWith(this.replacement)&&(this.prepend_scheme===`always`||this.prepend_scheme===`first`&&t===0)&&(n=this.strRep+n),[n]}}class je extends xe{constructor(e){super(e),this.replacement=e.replacement}decode_chain(e){let t=[];for(let n=0;n<e.length;++n){let r=e[n].replaceAll(this.replacement,` `);n==0&&r.startsWith(` `)&&(r=r.substring(1)),t.push(r)}return t}}class Me extends j{constructor(e){super(e),this.charsmap=e.precompiled_charsmap}normalize(e){return e=e.replace(/[\u0001-\u0008\u000B\u000E-\u001F\u007F\u008F\u009F]/gm,``),e=e.replace(/[\u0009\u000A\u000C\u000D\u00A0\u1680\u2000-\u200F\u2028\u2029\u202F\u205F\u2581\u3000\uFEFF\uFFFD]/gm,` `),e=e.includes(`~`)?e.split(`~`).map(e=>e.normalize(`NFKC`)).join(`~`):e.normalize(`NFKC`),e}}class Ne extends pe{constructor(e){super(),this.tokenizers=e.pretokenizers.map(e=>pe.fromConfig(e))}pre_tokenize_text(e,t){return this.tokenizers.reduce((e,n)=>n.pre_tokenize(e,t),[e])}}class Pe extends pe{constructor(e){super()}pre_tokenize_text(e,t){return e.match(/\w+|[^\w\s]+/g)||[]}}class Fe extends pe{constructor(e){super()}pre_tokenize_text(e,t){return x(e)}}class Ie extends pe{constructor(e){super(),this.config=e,this.pattern=p(this.config.pattern),this.content=this.config.content}pre_tokenize_text(e,t){return this.pattern===null?[e]:[e.replaceAll(this.pattern,this.config.content)]}}class Le extends pe{constructor(e){super(),this._length=e.length}pre_tokenize_text(e,t){let n=[];for(let t=0;t<e.length;t+=this._length)n.push(e.slice(t,t+this._length));return n}}let Re=[`bos_token`,`eos_token`,`unk_token`,`sep_token`,`pad_token`,`cls_token`,`mask_token`];function ze(e,t,n,r){for(let a of Object.keys(e)){let o=t-e[a].length,s=n(a),c=Array(o).fill(s);e[a]=r===`right`?(0,i.mergeArrays)(e[a],c):(0,i.mergeArrays)(c,e[a])}}function Be(e,t){for(let n of Object.keys(e))e[n].length=t}class B extends r.Callable{return_token_type_ids=!1;padding_side=`right`;constructor(e,t){super(),this.config=t,this.normalizer=j.fromConfig(e.normalizer),this.pre_tokenizer=pe.fromConfig(e.pre_tokenizer),this.model=D.fromConfig(e.model,t),this.post_processor=ve.fromConfig(e.post_processor),this.decoder=xe.fromConfig(e.decoder),this.special_tokens=[],this.all_special_ids=[],this.added_tokens=[];for(let t of e.added_tokens){let e=new E(t);this.added_tokens.push(e),this.model.tokens_to_ids.set(e.content,e.id),this.model.vocab[e.id]=e.content,e.special&&(this.special_tokens.push(e.content),this.all_special_ids.push(e.id))}if(this.additional_special_tokens=t.additional_special_tokens??[],this.special_tokens.push(...this.additional_special_tokens),this.special_tokens=[...new Set(this.special_tokens)],this.decoder&&(this.decoder.added_tokens=this.added_tokens,this.decoder.end_of_word_suffix=this.model.end_of_word_suffix),this.added_tokens_splitter=new c.DictionarySplitter(this.added_tokens.map(e=>e.content)),this.added_tokens_map=new Map(this.added_tokens.map(e=>[e.content,e])),this.mask_token=this.getToken(`mask_token`),this.mask_token_id=this.model.tokens_to_ids.get(this.mask_token),this.pad_token=this.getToken(`pad_token`,`eos_token`),this.pad_token_id=this.model.tokens_to_ids.get(this.pad_token),this.sep_token=this.getToken(`sep_token`),this.sep_token_id=this.model.tokens_to_ids.get(this.sep_token),this.unk_token=this.getToken(`unk_token`),this.unk_token_id=this.model.tokens_to_ids.get(this.unk_token),this.bos_token=this.getToken(`bos_token`),this.bos_token_id=this.model.tokens_to_ids.get(this.bos_token),this.eos_token=this.getToken(`eos_token`),this.eos_token_id=this.model.tokens_to_ids.get(this.eos_token),this.model_max_length=t.model_max_length,this.remove_space=t.remove_space,this.clean_up_tokenization_spaces=t.clean_up_tokenization_spaces??!0,this.do_lowercase_and_remove_accent=t.do_lowercase_and_remove_accent??!1,t.padding_side&&(this.padding_side=t.padding_side),this.add_bos_token=t.add_bos_token,this.add_eos_token=t.add_eos_token,this.legacy=!1,this.chat_template=t.chat_template??null,Array.isArray(this.chat_template)){let e=Object.create(null);for(let{name:t,template:n}of this.chat_template){if(typeof t!=`string`||typeof n!=`string`)throw Error(`Chat template must be a list of objects with "name" and "template" properties`);e[t]=n}this.chat_template=e}this._compiled_template_cache=new Map}getToken(...e){for(let t of e){let e=this.config[t];if(e)if(typeof e==`object`){if(e.__type===`AddedToken`)return e.content;throw Error(`Unknown token: ${e}`)}else return e}return null}static async from_pretrained(e,{progress_callback:t=null,config:n=null,cache_dir:r=null,local_files_only:i=!1,revision:a=`main`,legacy:o=null}={}){let s=await d(e,{progress_callback:t,config:n,cache_dir:r,local_files_only:i,revision:a,legacy:o});return new this(...s)}_call(e,{text_pair:t=null,add_special_tokens:n=!0,padding:r=!1,truncation:i=null,max_length:a=null,return_tensor:c=!0,return_token_type_ids:l=null}={}){let u=Array.isArray(e),d;if(u){if(e.length===0)throw Error(`text array must be non-empty`);if(t!==null){if(!Array.isArray(t))throw Error(`text_pair must also be an array`);if(e.length!==t.length)throw Error(`text and text_pair must have the same length`);d=e.map((e,r)=>this._encode_plus(e,{text_pair:t[r],add_special_tokens:n,return_token_type_ids:l}))}else d=e.map(e=>this._encode_plus(e,{add_special_tokens:n,return_token_type_ids:l}))}else{if(e==null)throw Error(`text may not be null or undefined`);if(Array.isArray(t))throw Error("When specifying `text_pair`, since `text` is a string, `text_pair` must also be a string (i.e., not an array).");d=[this._encode_plus(e,{text_pair:t,add_special_tokens:n,return_token_type_ids:l})]}if(a===null?a=this.model_max_length:i===null&&(r===!0?(console.warn("`max_length` is ignored when `padding: true` and there is no truncation strategy. To pad to max length, use `padding: 'max_length'`."),a=this.model_max_length):r===!1&&(console.warn("Truncation was not explicitly activated but `max_length` is provided a specific value, please use `truncation: true` to explicitly truncate examples to max length."),i=!0)),r===!0&&(a=Math.min((0,o.max)(d.map(e=>e.input_ids.length))[0],a??1/0)),a=Math.min(a,this.model_max_length??1/0),r||i)for(let e=0;e<d.length;++e)if(d[e].input_ids.length===a)continue;else d[e].input_ids.length>a?i&&Be(d[e],a):r&&ze(d[e],a,e=>e===`input_ids`?this.pad_token_id:0,this.padding_side);let f={};if(c){if(!(r&&i)&&d.some(e=>{for(let t of Object.keys(e))if(e[t].length!==d[0][t]?.length)return!0;return!1}))throw Error(`Unable to create tensor, you should probably activate truncation and/or padding with 'padding=true' and 'truncation=true' to have batched tensors with the same length.`);let e=[d.length,d[0].input_ids.length];for(let t of Object.keys(d[0]))f[t]=new s.Tensor(`int64`,BigInt64Array.from(d.flatMap(e=>e[t]).map(BigInt)),e)}else{for(let e of Object.keys(d[0]))f[e]=d.map(t=>t[e]);if(!u)for(let e of Object.keys(f))f[e]=f[e][0]}return f}_encode_text(e){if(e===null)return null;let t=this.added_tokens_splitter.split(e);for(let e=0;e<t.length;++e){let n=this.added_tokens_map.get(t[e]);n&&(n.lstrip&&e>0&&(t[e-1]=t[e-1].trimEnd()),n.rstrip&&e<t.length-1&&(t[e+1]=t[e+1].trimStart()))}return t.flatMap((e,t)=>{if(e.length===0)return[];if(this.added_tokens_map.has(e))return[e];if(this.remove_space===!0&&(e=e.trim().split(/\s+/).join(` `)),this.do_lowercase_and_remove_accent&&(e=v(e)),this.normalizer!==null&&(e=this.normalizer(e)),e.length===0)return[];let n=this.pre_tokenizer===null?[e]:this.pre_tokenizer(e,{section_index:t});return this.model(n)})}_encode_plus(e,{text_pair:t=null,add_special_tokens:n=!0,return_token_type_ids:r=null}={}){let{tokens:i,token_type_ids:a}=this._tokenize_helper(e,{pair:t,add_special_tokens:n}),o=this.model.convert_tokens_to_ids(i),s={input_ids:o,attention_mask:Array(o.length).fill(1)};return(r??this.return_token_type_ids)&&a&&(s.token_type_ids=a),s}_tokenize_helper(e,{pair:t=null,add_special_tokens:n=!1}={}){let r=this._encode_text(e),a=this._encode_text(t);return this.post_processor?this.post_processor(r,a,{add_special_tokens:n}):{tokens:(0,i.mergeArrays)(r??[],a??[])}}tokenize(e,{pair:t=null,add_special_tokens:n=!1}={}){return this._tokenize_helper(e,{pair:t,add_special_tokens:n}).tokens}encode(e,{text_pair:t=null,add_special_tokens:n=!0,return_token_type_ids:r=null}={}){return this._encode_plus(e,{text_pair:t,add_special_tokens:n,return_token_type_ids:r}).input_ids}batch_decode(e,t={}){return e instanceof s.Tensor&&(e=e.tolist()),e.map(e=>this.decode(e,t))}decode(e,t={}){if(e instanceof s.Tensor&&(e=h(e)),!Array.isArray(e)||e.length===0||!(0,i.isIntegralNumber)(e[0]))throw Error(`token_ids must be a non-empty array of integers.`);return this.decode_single(e,t)}decode_single(e,{skip_special_tokens:t=!1,clean_up_tokenization_spaces:n=null}){let r=this.model.convert_ids_to_tokens(e);t&&(r=r.filter(e=>!this.special_tokens.includes(e)));let i=this.decoder?this.decoder(r):r.join(` `);return this.decoder&&this.decoder.end_of_word_suffix&&(i=i.replaceAll(this.decoder.end_of_word_suffix,` `),t&&(i=i.trim())),(n??this.clean_up_tokenization_spaces)&&(i=g(i)),i}get_chat_template({chat_template:e=null,tools:t=null}={}){if(this.chat_template&&typeof this.chat_template==`object`){let n=this.chat_template;if(e!==null&&Object.hasOwn(n,e))e=n[e];else if(e===null)if(t!==null&&`tool_use`in n)e=n.tool_use;else if(`default`in n)e=n.default;else throw Error(`This model has multiple chat templates with no default specified! Please either pass a chat template or the name of the template you wish to use to the 'chat_template' argument. Available template names are ${Object.keys(n).sort()}.`)}else if(e===null)if(this.chat_template)e=this.chat_template;else throw Error(`Cannot use apply_chat_template() because tokenizer.chat_template is not set and no template argument was passed! For information about writing templates and setting the tokenizer.chat_template attribute, please see the documentation at https://huggingface.co/docs/transformers/main/en/chat_templating`);return e}apply_chat_template(e,{tools:t=null,documents:n=null,chat_template:r=null,add_generation_prompt:i=!1,tokenize:a=!0,padding:o=!1,truncation:s=!1,max_length:c=null,return_tensor:u=!0,return_dict:d=!1,tokenizer_kwargs:f={},...p}={}){if(r=this.get_chat_template({chat_template:r,tools:t}),typeof r!=`string`)throw Error(`chat_template must be a string, but got ${typeof r}`);let m=this._compiled_template_cache.get(r);m===void 0&&(m=new l.Template(r),this._compiled_template_cache.set(r,m));let h=Object.create(null);for(let e of Re){let t=this.getToken(e);t&&(h[e]=t)}let g=m.render({messages:e,add_generation_prompt:i,tools:t,documents:n,...h,...p});if(a){let e=this._call(g,{add_special_tokens:!1,padding:o,truncation:s,max_length:c,return_tensor:u,...f});return d?e:e.input_ids}return g}}class Ve extends B{return_token_type_ids=!0}class He extends B{return_token_type_ids=!0}class Ue extends B{return_token_type_ids=!0}class We extends B{return_token_type_ids=!0}class V extends B{return_token_type_ids=!0}class Ge extends B{return_token_type_ids=!0}class Ke extends B{return_token_type_ids=!0}class qe extends B{return_token_type_ids=!0}class Je extends B{return_token_type_ids=!0}class Ye extends B{}class Xe extends B{}class Ze extends B{return_token_type_ids=!0;constructor(e,t){super(e,t),console.warn('WARNING: `XLMTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}}class Qe extends B{return_token_type_ids=!0}class $e extends B{}class et extends B{}class tt extends B{}class nt extends B{constructor(e,t){super(e,t),this.languageRegex=/^[a-z]{2}_[A-Z]{2}$/,this.language_codes=this.special_tokens.filter(e=>this.languageRegex.test(e)),this.lang_to_token=e=>e}_build_translation_inputs(e,t,n){return gt(this,e,t,n)}}class rt extends nt{}class it extends B{}class at extends B{}class ot extends B{padding_side=`left`;constructor(e,t){super(e,t),this.legacy=t.legacy??!0,this.legacy||(this.normalizer=null,this.pre_tokenizer=new Ae({replacement:`▁`,prepend_scheme:`first`}))}_encode_text(e){if(e===null)return null;if(this.legacy||e.length===0)return super._encode_text(e);let t=super._encode_text(`▁`+e.replaceAll(`▁`,` `));return t.length>1&&t[0]===`▁`&&this.special_tokens.includes(t[1])&&(t=t.slice(1)),t}}class st extends B{}class ct extends B{}class lt extends B{}class ut extends B{}class dt extends B{}class ft extends B{}class pt extends B{}class mt extends B{}class ht extends B{}function gt(e,t,n,r){if(!(`language_codes`in e)||!Array.isArray(e.language_codes))throw Error("Tokenizer must have `language_codes` attribute set and it should be an array of language ids.");if(!(`languageRegex`in e)||!(e.languageRegex instanceof RegExp))throw Error("Tokenizer must have `languageRegex` attribute set and it should be a regular expression.");if(!(`lang_to_token`in e)||typeof e.lang_to_token!=`function`)throw Error("Tokenizer must have `lang_to_token` attribute set and it should be a function.");let i=r.src_lang,a=r.tgt_lang;if(!e.language_codes.includes(a))throw Error(`Target language code "${a}" is not valid. Must be one of: {${e.language_codes.join(`, `)}}`);if(i!==void 0){if(!e.language_codes.includes(i))throw Error(`Source language code "${i}" is not valid. Must be one of: {${e.language_codes.join(`, `)}}`);for(let t of e.post_processor.config.single)if(`SpecialToken`in t&&e.languageRegex.test(t.SpecialToken.id)){t.SpecialToken.id=e.lang_to_token(i);break}}return r.forced_bos_token_id=e.model.convert_tokens_to_ids([e.lang_to_token(a)])[0],e._call(t,n)}class _t extends B{constructor(e,t){super(e,t),this.languageRegex=/^[a-z]{3}_[A-Z][a-z]{3}$/,this.language_codes=this.special_tokens.filter(e=>this.languageRegex.test(e)),this.lang_to_token=e=>e}_build_translation_inputs(e,t,n){return gt(this,e,t,n)}}class vt extends B{constructor(e,t){super(e,t),this.languageRegex=/^__[a-z]{2,3}__$/,this.language_codes=this.special_tokens.filter(e=>this.languageRegex.test(e)).map(e=>e.slice(2,-2)),this.lang_to_token=e=>`__${e}__`}_build_translation_inputs(e,t,n){return gt(this,e,t,n)}}class yt extends B{get timestamp_begin(){return this.model.convert_tokens_to_ids([`<|notimestamps|>`])[0]+1}_decode_asr(e,{return_timestamps:t=!1,return_language:n=!1,time_precision:r=null,force_full_sequences:i=!0}={}){if(r===null)throw Error(`Must specify time_precision`);let a=null,s=t===`word`;function c(){return{language:a,timestamp:[null,null],text:``}}let l=[],d=c(),f=0,p=this.timestamp_begin,m=p+1500,h=[],g=[],_=!1,v=null,y=new Set(this.all_special_ids);for(let n of e){let e=n.tokens,i=s?n.token_timestamps:null,b=null,x=p;if(`stride`in n){let[t,i,a]=n.stride;if(f-=i,v=t-a,i&&(x=i/r+p),a)for(let t=e.length-1;t>=0;--t){let n=Number(e[t]);if(n>=p){if(b!==null&&(n-p)*r<v)break;b=n}}}let S=[],w=[];for(let n=0;n<e.length;++n){let v=Number(e[n]);if(y.has(v)){let e=this.decode([v]),n=u.WHISPER_LANGUAGE_MAPPING.get(e.slice(2,-2));if(n!==void 0){if(a!==null&&n!==a&&!t){h.push(S);let e=this.findLongestCommonSequence(h)[0],t=this.decode(e);d.text=t,l.push(d),h=[],S=[],d=c()}a=d.language=n}}else if(v>=p&&v<=m){let e=(v-p)*r+f,t=(0,o.round)(e,2);if(b!==null&&v>=b)_=!0;else if(_||h.length>0&&v<x)_=!1;else if(d.timestamp[0]===null)d.timestamp[0]=t;else if(t!==d.timestamp[0]){d.timestamp[1]=t,h.push(S),s&&g.push(w);let[e,n]=this.findLongestCommonSequence(h,g),r=this.decode(e);d.text=r,s&&(d.words=this.collateWordTimestamps(e,n,a)),l.push(d),h=[],S=[],g=[],w=[],d=c()}}else if(S.push(v),s){let e=(0,o.round)(i[n]+f,2),t;if(n+1<i.length){t=(0,o.round)(i[n+1]+f,2);let a=this.decode([v]);C.test(a)&&(t=(0,o.round)(Math.min(e+r,t),2))}else t=null;w.push([e,t])}}if(`stride`in n){let[e,t,r]=n.stride;f+=e-r}S.length>0?(h.push(S),s&&g.push(w)):h.every(e=>e.length===0)&&(d=c(),h=[],S=[],g=[],w=[])}if(h.length>0){if(i&&t)throw Error(`Whisper did not predict an ending timestamp, which can happen if audio is cut off in the middle of a word. Also make sure WhisperTimeStampLogitsProcessor was used during generation.`);let[e,n]=this.findLongestCommonSequence(h,g),r=this.decode(e);d.text=r,s&&(d.words=this.collateWordTimestamps(e,n,a)),l.push(d)}let b=Object.create(null),x=l.map(e=>e.text).join(``);if(t||n){for(let e=0;e<l.length;++e){let r=l[e];t||delete r.timestamp,n||delete r.language}if(s){let e=[];for(let t of l)for(let n of t.words)e.push(n);b={chunks:e}}else b={chunks:l}}return[x,b]}findLongestCommonSequence(e,t=null){let n=e[0],r=n.length,i=[],a=Array.isArray(t)&&t.length>0,o=a?[]:null,s=a?t[0]:null;for(let c=1;c<e.length;++c){let l=e[c],u=0,d=[r,r,0,0],f=l.length;for(let e=1;e<r+f;++e){let i=Math.max(0,r-e),o=Math.min(r,r+f-e),p=n.slice(i,o),m=Math.max(0,e-r),h=Math.min(f,e),g=l.slice(m,h);if(p.length!==g.length)throw Error("There is a bug within whisper `decode_asr` function, please report it. Dropping to prevent bad inference.");let _;_=a?p.filter((e,n)=>e===g[n]&&s[i+n]<=t[c][m+n]).length:p.filter((e,t)=>e===g[t]).length;let v=e/1e4,y=_/e+v;_>1&&y>u&&(u=y,d=[i,o,m,h])}let[p,m,h,g]=d,_=Math.floor((m+p)/2),v=Math.floor((g+h)/2);i.push(...n.slice(0,_)),n=l.slice(v),r=n.length,a&&(o.push(...s.slice(0,_)),s=t[c].slice(v))}return i.push(...n),a?(o.push(...s),[i,o]):[i,[]]}collateWordTimestamps(e,t,n){let[r,i,a]=this.combineTokensIntoWords(e,n),o=[];for(let e=0;e<r.length;++e){let n=a[e];o.push({text:r[e],timestamp:[t[n.at(0)][0],t[n.at(-1)][1]]})}return o}combineTokensIntoWords(e,t,n=`"'“¡¿([{-`,r=`"'.。,,!!??::”)]}、`){t??=`english`;let i,a,o;return[`chinese`,`japanese`,`thai`,`lao`,`myanmar`].includes(t)?[i,a,o]=this.splitTokensOnUnicode(e):[i,a,o]=this.splitTokensOnSpaces(e),this.mergePunctuations(i,a,o,n,r)}decode(e,t){let n;return t?.decode_with_timestamps?(e instanceof s.Tensor&&(e=h(e)),n=this.decodeWithTimestamps(e,t)):n=super.decode(e,t),n}decodeWithTimestamps(e,t){let n=t?.time_precision??.02,r=Array.from(this.all_special_ids).at(-1)+1,i=[[]];for(let t of e)if(t=Number(t),t>=r){let e=((t-r)*n).toFixed(2);i.push(`<|${e}|>`),i.push([])}else i[i.length-1].push(t);return i=i.map(e=>typeof e==`string`?e:super.decode(e,t)),i.join(``)}splitTokensOnUnicode(e){let t=this.decode(e,{decode_with_timestamps:!0}),n=[],r=[],i=[],a=[],o=[],s=0;for(let c=0;c<e.length;++c){let l=e[c];a.push(l),o.push(c);let u=this.decode(a,{decode_with_timestamps:!0});(!u.includes(`�`)||t[s+u.indexOf(`�`)]===`�`)&&(n.push(u),r.push(a),i.push(o),a=[],o=[],s+=u.length)}return[n,r,i]}splitTokensOnSpaces(e){let[t,n,r]=this.splitTokensOnUnicode(e),i=[],a=[],o=[],s=RegExp(`^[${S}]$`,`gu`);for(let e=0;e<t.length;++e){let c=t[e],l=n[e],u=r[e],d=l[0]>=this.model.tokens_to_ids.get(`<|endoftext|>`),f=c.startsWith(` `),p=c.trim(),m=s.test(p);if(d||f||m||i.length===0)i.push(c),a.push(l),o.push(u);else{let e=i.length-1;i[e]+=c,a[e].push(...l),o[e].push(...u)}}return[i,a,o]}mergePunctuations(e,t,n,r,a){let o=structuredClone(e),s=structuredClone(t),c=structuredClone(n),l=o.length-2,u=o.length-1;for(;l>=0;)o[l].startsWith(` `)&&r.includes(o[l].trim())?(o[u]=o[l]+o[u],s[u]=(0,i.mergeArrays)(s[l],s[u]),c[u]=(0,i.mergeArrays)(c[l],c[u]),o[l]=``,s[l]=[],c[l]=[]):u=l,--l;for(l=0,u=1;u<o.length;)!o[l].endsWith(` `)&&a.includes(o[u])?(o[l]+=o[u],s[l]=(0,i.mergeArrays)(s[l],s[u]),c[l]=(0,i.mergeArrays)(c[l],c[u]),o[u]=``,s[u]=[],c[u]=[]):l=u,++u;return[o.filter(e=>e),s.filter(e=>e.length>0),c.filter(e=>e.length>0)]}}class bt extends B{}class xt extends B{}class St extends B{}class Ct extends B{constructor(e,t){super(e,t),this.languageRegex=/^(>>\w+<<)\s*/g,this.supported_language_codes=this.model.vocab.filter(e=>this.languageRegex.test(e)),console.warn('WARNING: `MarianTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}_encode_text(e){if(e===null)return null;let[t,...n]=e.trim().split(this.languageRegex);if(n.length===0)return super._encode_text(t);if(n.length===2){let[e,t]=n;return this.supported_language_codes.includes(e)||console.warn(`Unsupported language code "${e}" detected, which may lead to unexpected behavior. Should be one of: ${JSON.stringify(this.supported_language_codes)}`),(0,i.mergeArrays)([e],super._encode_text(t))}}}class wt extends B{}class Tt extends B{}class Et extends B{}class Dt extends B{}class Ot extends B{}class kt extends B{constructor(e,t){super(e,t),this.decoder=new ke({})}}class At extends B{}class jt extends B{}class Mt{static TOKENIZER_CLASS_MAPPING={T5Tokenizer:$e,DistilBertTokenizer:Ye,CamembertTokenizer:Xe,DebertaTokenizer:V,DebertaV2Tokenizer:Ge,BertTokenizer:Ve,HerbertTokenizer:Ke,ConvBertTokenizer:qe,RoFormerTokenizer:Je,XLMTokenizer:Ze,ElectraTokenizer:Qe,MobileBertTokenizer:Ue,SqueezeBertTokenizer:We,AlbertTokenizer:He,GPT2Tokenizer:et,BartTokenizer:tt,MBartTokenizer:nt,MBart50Tokenizer:rt,RobertaTokenizer:it,WhisperTokenizer:yt,CodeGenTokenizer:bt,CLIPTokenizer:xt,SiglipTokenizer:St,MarianTokenizer:Ct,BloomTokenizer:at,NllbTokenizer:_t,M2M100Tokenizer:vt,LlamaTokenizer:ot,CodeLlamaTokenizer:st,XLMRobertaTokenizer:ct,MPNetTokenizer:lt,FalconTokenizer:ut,GPTNeoXTokenizer:dt,EsmTokenizer:ft,Wav2Vec2CTCTokenizer:wt,BlenderbotTokenizer:Tt,BlenderbotSmallTokenizer:Et,SpeechT5Tokenizer:Dt,NougatTokenizer:Ot,VitsTokenizer:kt,Qwen2Tokenizer:pt,GemmaTokenizer:mt,Grok1Tokenizer:ht,CohereTokenizer:At,MgpstrTokenizer:jt,PreTrainedTokenizer:B};static async from_pretrained(e,{progress_callback:t=null,config:n=null,cache_dir:r=null,local_files_only:i=!1,revision:a=`main`,legacy:o=null}={}){let[s,c]=await d(e,{progress_callback:t,config:n,cache_dir:r,local_files_only:i,revision:a,legacy:o}),l=c.tokenizer_class?.replace(/Fast$/,``)??`PreTrainedTokenizer`,u=this.TOKENIZER_CLASS_MAPPING[l];return u||=(console.warn(`Unknown tokenizer class "${l}", attempting to construct from base class.`),B),new u(s,c)}}}),"./src/utils/audio.js":((e,t,n)=>{n.r(t),n.d(t,{RawAudio:()=>O,hamming:()=>f,hanning:()=>d,mel_filter_bank:()=>y,read_audio:()=>l,spectrogram:()=>w,window_function:()=>T});var r=n(`./src/utils/hub.js`),i=n(`./src/utils/maths.js`),a=n(`./src/utils/core.js`),o=n(`./src/env.js`),s=n(`./src/utils/tensor.js`),c=n(`?7992`);async function l(e,t){if(typeof AudioContext>`u`)throw Error("Unable to load audio from path/URL since `AudioContext` is not available in your environment. Instead, audio data should be passed directly to the pipeline/processor. For more information and some example code, see https://huggingface.co/docs/transformers.js/guides/node-audio-processing.");let n=await(await(0,r.getFile)(e)).arrayBuffer(),i=new AudioContext({sampleRate:t});t===void 0&&console.warn(`No sampling rate provided, using default of ${i.sampleRate}Hz.`);let a=await i.decodeAudioData(n),o;if(a.numberOfChannels===2){let e=Math.sqrt(2),t=a.getChannelData(0),n=a.getChannelData(1);o=new Float32Array(t.length);for(let r=0;r<a.length;++r)o[r]=e*(t[r]+n[r])/2}else o=a.getChannelData(0);return o}function u(e,t){if(e<1)return new Float64Array;if(e===1)return new Float64Array([1]);let n=1-t,r=2*Math.PI/(e-1),i=new Float64Array(e);for(let a=0;a<e;++a)i[a]=t-n*Math.cos(a*r);return i}function d(e){return u(e,.5)}function f(e){return u(e,.54)}let p={htk:e=>2595*Math.log10(1+e/700),kaldi:e=>1127*Math.log(1+e/700),slaney:(e,t=1e3,n=15,r=27/Math.log(6.4))=>e>=t?n+Math.log(e/t)*r:3*e/200};function m(e,t=`htk`){let n=p[t];if(!n)throw Error(`mel_scale should be one of "htk", "slaney" or "kaldi".`);return typeof e==`number`?n(e):e.map(e=>n(e))}let h={htk:e=>700*(10**(e/2595)-1),kaldi:e=>700*(Math.exp(e/1127)-1),slaney:(e,t=1e3,n=15,r=Math.log(6.4)/27)=>e>=n?t*Math.exp(r*(e-n)):200*e/3};function g(e,t=`htk`){let n=h[t];if(!n)throw Error(`mel_scale should be one of "htk", "slaney" or "kaldi".`);return typeof e==`number`?n(e):e.map(e=>n(e))}function _(e,t){let n=Float64Array.from({length:t.length-1},(e,n)=>t[n+1]-t[n]),r=Array.from({length:e.length},()=>Array(t.length));for(let n=0;n<e.length;++n){let i=r[n];for(let r=0;r<t.length;++r)i[r]=t[r]-e[n]}let i=t.length-2,a=Array.from({length:i},()=>Array(e.length));for(let t=0;t<e.length;++t){let e=r[t];for(let r=0;r<i;++r){let i=-e[r]/n[r],o=e[r+2]/n[r+1];a[r][t]=Math.max(0,Math.min(i,o))}}return a}function v(e,t,n){let r=(t-e)/(n-1);return Float64Array.from({length:n},(t,n)=>e+r*n)}function y(e,t,n,r,i,a=null,o=`htk`,s=!1){if(a!==null&&a!==`slaney`)throw Error(`norm must be one of null or "slaney"`);if(e<2)throw Error(`Require num_frequency_bins: ${e} >= 2`);if(n>r)throw Error(`Require min_frequency: ${n} <= max_frequency: ${r}`);let c=v(m(n,o),m(r,o),t+2),l=g(c,o),u;if(s){let t=i/((e-1)*2);u=m(Float64Array.from({length:e},(e,n)=>n*t),o),l=c}else u=v(0,Math.floor(i/2),e);let d=_(u,l);if(a!==null&&a===`slaney`)for(let n=0;n<t;++n){let t=d[n],r=2/(l[n+2]-l[n]);for(let n=0;n<e;++n)t[n]*=r}return d}function b(e,t,n){let r=new e.constructor(e.length+t+n),i=e.length-1;for(let n=0;n<e.length;++n)r[t+n]=e[n];for(let n=1;n<=t;++n)r[t-n]=e[(0,a.calculateReflectOffset)(n,i)];for(let o=1;o<=n;++o)r[i+t+o]=e[(0,a.calculateReflectOffset)(i-o,i)];return r}function x(e,t,n,r,a){if(n<=0)throw Error(`reference must be greater than zero`);if(r<=0)throw Error(`min_value must be greater than zero`);n=Math.max(r,n);let o=Math.log10(n);for(let n=0;n<e.length;++n)e[n]=t*Math.log10(Math.max(r,e[n])-o);if(a!==null){if(a<=0)throw Error(`db_range must be greater than zero`);let t=(0,i.max)(e)[0]-a;for(let n=0;n<e.length;++n)e[n]=Math.max(e[n],t)}return e}function S(e,t=1,n=1e-5,r=null){return x(e,20,t,n,r)}function C(e,t=1,n=1e-10,r=null){return x(e,10,t,n,r)}async function w(e,t,n,r,{fft_length:a=null,power:o=1,center:c=!0,pad_mode:l=`reflect`,onesided:u=!0,preemphasis:d=null,preemphasis_htk_flavor:f=!0,mel_filters:p=null,mel_floor:m=1e-10,log_mel:h=null,reference:g=1,min_value:_=1e-10,db_range:v=null,remove_dc_offset:y=null,min_num_frames:x=null,max_num_frames:w=null,do_pad:T=!0,transpose:E=!1,mel_offset:D=0}={}){let O=t.length;if(a===null&&(a=n),n>a)throw Error(`frame_length (${n}) may not be larger than fft_length (${a})`);if(O!==n)throw Error(`Length of the window (${O}) must equal frame_length (${n})`);if(r<=0)throw Error(`hop_length must be greater than zero`);if(o===null&&p!==null)throw Error("You have provided `mel_filters` but `power` is `None`. Mel spectrogram computation is not yet supported for complex-valued spectrogram. Specify `power` to fix this issue.");if(!f)throw Error("`preemphasis_htk_flavor=false` is not currently supported.");if(c)switch(l){case`reflect`:{let t=Math.floor((a-1)/2)+1;e=b(e,t,t);break}case`constant`:{let t=Math.floor(a/2),n=new e.constructor(e.length+2*t);n.set(e,t),e=n;break}default:throw Error(`pad_mode="${l}" not implemented yet.`)}let k=Math.floor(1+Math.floor((e.length-n)/r));x!==null&&k<x&&(k=x);let A=u?Math.floor(a/2)+1:a,ee=k,te=k;w!==null&&(w>k?T&&(te=w):te=ee=w);let ne=new i.FFT(a),j=new Float64Array(a),re=new Float64Array(ne.outputBufferSize),ie=new Float32Array(A*te);for(let i=0;i<ee;++i){let a=i*r,o=Math.min(e.length-a,n);o!==n&&j.fill(0,0,n);for(let t=0;t<o;++t)j[t]=e[a+t];if(y){let e=0;for(let t=0;t<o;++t)e+=j[t];let t=e/o;for(let e=0;e<o;++e)j[e]-=t}if(d!==null){for(let e=o-1;e>=1;--e)j[e]-=d*j[e-1];j[0]*=1-d}for(let e=0;e<t.length;++e)j[e]*=t[e];ne.realTransform(re,j);for(let e=0;e<A;++e){let t=e<<1;ie[e*te+i]=re[t]**2+re[t+1]**2}}if(o!==null&&o!==2){let e=o/2;for(let t=0;t<ie.length;++t)ie[t]**=e}let ae=p.length,oe=await(0,s.matmul)(new s.Tensor(`float32`,p.flat(),[ae,A]),new s.Tensor(`float32`,ie,[A,te]));E&&(oe=oe.transpose(1,0));let se=oe.data;for(let e=0;e<se.length;++e)se[e]=D+Math.max(m,se[e]);if(o!==null&&h!==null){let e=Math.min(se.length,ee*ae);switch(h){case`log`:for(let t=0;t<e;++t)se[t]=Math.log(se[t]);break;case`log10`:for(let t=0;t<e;++t)se[t]=Math.log10(se[t]);break;case`dB`:if(o===1)S(se,g,_,v);else if(o===2)C(se,g,_,v);else throw Error(`Cannot use log_mel option '${h}' with power ${o}`);break;default:throw Error(`log_mel must be one of null, 'log', 'log10' or 'dB'. Got '${h}'`)}}return oe}function T(e,t,{periodic:n=!0,frame_length:r=null,center:i=!0}={}){let a=n?e+1:e,o;switch(t){case`boxcar`:o=new Float64Array(a).fill(1);break;case`hann`:case`hann_window`:o=d(a);break;case`hamming`:o=f(a);break;case`povey`:o=d(a).map(e=>e**.85);break;default:throw Error(`Unknown window type ${t}.`)}if(n&&(o=o.subarray(0,e)),r===null)return o;if(e>r)throw Error(`Length of the window (${e}) may not be larger than frame_length (${r})`);return o}function E(e,t){let n=44,r=new ArrayBuffer(n+e.length*4),i=new DataView(r);D(i,0,`RIFF`),i.setUint32(4,36+e.length*4,!0),D(i,8,`WAVE`),D(i,12,`fmt `),i.setUint32(16,16,!0),i.setUint16(20,3,!0),i.setUint16(22,1,!0),i.setUint32(24,t,!0),i.setUint32(28,t*4,!0),i.setUint16(32,4,!0),i.setUint16(34,32,!0),D(i,36,`data`),i.setUint32(40,e.length*4,!0);for(let t=0;t<e.length;++t,n+=4)i.setFloat32(n,e[t],!0);return r}function D(e,t,n){for(let r=0;r<n.length;++r)e.setUint8(t+r,n.charCodeAt(r))}class O{constructor(e,t){this.audio=e,this.sampling_rate=t}toWav(){return E(this.audio,this.sampling_rate)}toBlob(){let e=this.toWav();return new Blob([e],{type:`audio/wav`})}async save(e){let t;if(o.apis.IS_BROWSER_ENV){if(o.apis.IS_WEBWORKER_ENV)throw Error(`Unable to save a file from a Web Worker.`);t=a.saveBlob}else if(o.apis.IS_FS_AVAILABLE)t=async(e,t)=>{let n=await t.arrayBuffer();c.writeFileSync(e,Buffer.from(n))};else throw Error(`Unable to save because filesystem is disabled in this environment.`);await t(e,this.toBlob())}}}),"./src/utils/constants.js":((e,t,n)=>{n.r(t),n.d(t,{CHAT_TEMPLATE_NAME:()=>c,CONFIG_NAME:()=>i,FEATURE_EXTRACTOR_NAME:()=>a,GENERATION_CONFIG_NAME:()=>l,GITHUB_ISSUE_URL:()=>r,IMAGE_PROCESSOR_NAME:()=>o,PROCESSOR_NAME:()=>s});let r=`https://github.com/huggingface/transformers.js/issues/new/choose`,i=`config.json`,a=`preprocessor_config.json`,o=a,s=`processor_config.json`,c=`chat_template.jinja`,l=`generation_config.json`}),"./src/utils/core.js":((e,t,n)=>{n.r(t),n.d(t,{calculateDimensions:()=>l,calculateReflectOffset:()=>p,count:()=>_,dispatchCallback:()=>r,escapeRegExp:()=>a,isIntegralNumber:()=>s,isNullishDimension:()=>c,isTypedArray:()=>o,len:()=>g,mergeArrays:()=>d,pick:()=>h,pop:()=>u,product:()=>f,reverseDictionary:()=>i,saveBlob:()=>m});function r(e,t){e&&e(t)}function i(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[t,e]))}function a(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function o(e){return e?.prototype?.__proto__?.constructor?.name===`TypedArray`}function s(e){return Number.isInteger(e)||typeof e==`bigint`}function c(e){return e==null||e===-1}function l(e){let t=[],n=e;for(;Array.isArray(n);)t.push(n.length),n=n[0];return t}function u(e,t,n=void 0){let r=e[t];if(r!==void 0)return delete e[t],r;if(n===void 0)throw Error(`Key ${t} does not exist in object.`);return n}function d(...e){return Array.prototype.concat.apply([],e)}function f(...e){return e.reduce((e,t)=>e.flatMap(e=>t.map(t=>[e,t])))}function p(e,t){return Math.abs((e+t)%(2*t)-t)}function m(e,t){let n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=e,r.click(),r.remove(),URL.revokeObjectURL(n)}function h(e,t){return Object.assign({},...t.map(t=>{if(e[t]!==void 0)return{[t]:e[t]}}))}function g(e){let t=0;for(let n of e)++t;return t}function _(e,t){let n=0;for(let r of e)r===t&&++n;return n}}),"./src/utils/data-structures.js":((e,t,n)=>{n.r(t),n.d(t,{CharTrie:()=>i,DictionarySplitter:()=>c,LRUCache:()=>l,PriorityQueue:()=>r,TokenLattice:()=>o});class r{constructor(e=(e,t)=>e>t,t=1/0){this._heap=[],this._comparator=e,this._maxSize=t}get size(){return this._heap.length}isEmpty(){return this.size===0}peek(){return this._heap[0]}push(...e){return this.extend(e)}extend(e){for(let t of e)if(this.size<this._maxSize)this._heap.push(t),this._siftUp();else{let e=this._smallest();this._comparator(t,this._heap[e])&&(this._heap[e]=t,this._siftUpFrom(e))}return this.size}pop(){let e=this.peek(),t=this.size-1;return t>0&&this._swap(0,t),this._heap.pop(),this._siftDown(),e}replace(e){let t=this.peek();return this._heap[0]=e,this._siftDown(),t}_parent(e){return(e+1>>>1)-1}_left(e){return(e<<1)+1}_right(e){return e+1<<1}_greater(e,t){return this._comparator(this._heap[e],this._heap[t])}_swap(e,t){let n=this._heap[e];this._heap[e]=this._heap[t],this._heap[t]=n}_siftUp(){this._siftUpFrom(this.size-1)}_siftUpFrom(e){for(;e>0&&this._greater(e,this._parent(e));)this._swap(e,this._parent(e)),e=this._parent(e)}_siftDown(){let e=0;for(;this._left(e)<this.size&&this._greater(this._left(e),e)||this._right(e)<this.size&&this._greater(this._right(e),e);){let t=this._right(e)<this.size&&this._greater(this._right(e),this._left(e))?this._right(e):this._left(e);this._swap(e,t),e=t}}_smallest(){return 2**Math.floor(Math.log2(this.size))-1}}class i{constructor(){this.root=a.default()}extend(e){for(let t of e)this.push(t)}push(e){let t=this.root;for(let n of e){let e=t.children.get(n);e===void 0&&(e=a.default(),t.children.set(n,e)),t=e}t.isLeaf=!0}*commonPrefixSearch(e){let t=this.root;if(t===void 0)return;let n=``;for(let r of e){if(n+=r,t=t.children.get(r),t===void 0)return;t.isLeaf&&(yield n)}}}class a{constructor(e,t){this.isLeaf=e,this.children=t}static default(){return new a(!1,new Map)}}class o{constructor(e,t,n){this.chars=Array.from(e),this.len=this.chars.length,this.bosTokenId=t,this.eosTokenId=n,this.nodes=[],this.beginNodes=Array.from({length:this.len+1},()=>[]),this.endNodes=Array.from({length:this.len+1},()=>[]);let r=new s(this.bosTokenId,0,0,0,0),i=new s(this.eosTokenId,1,this.len,0,0);this.nodes.push(r.clone()),this.nodes.push(i.clone()),this.beginNodes[this.len].push(i),this.endNodes[0].push(r)}insert(e,t,n,r){let i=this.nodes.length,a=new s(r,i,e,t,n);this.beginNodes[e].push(a),this.endNodes[e+t].push(a),this.nodes.push(a)}viterbi(){let e=this.len,t=0;for(;t<=e;){if(this.beginNodes[t].length==0)return[];for(let e of this.beginNodes[t]){e.prev=null;let n=0,r=null;for(let i of this.endNodes[t]){let t=i.backtraceScore+e.score;(r===null||t>n)&&(r=i.clone(),n=t)}if(r!==null)e.prev=r,e.backtraceScore=n;else return[]}++t}let n=[],r=this.beginNodes[e][0].prev;if(r===null)return[];let i=r.clone();for(;i.prev!==null;)n.push(i.clone()),i=i.clone().prev.clone();return n.reverse(),n}piece(e){return this.chars.slice(e.pos,e.pos+e.length).join(``)}tokens(){return this.viterbi().map(e=>this.piece(e))}tokenIds(){return this.viterbi().map(e=>e.tokenId)}}class s{constructor(e,t,n,r,i){this.tokenId=e,this.nodeId=t,this.pos=n,this.length=r,this.score=i,this.prev=null,this.backtraceScore=0}clone(){let e=new s(this.tokenId,this.nodeId,this.pos,this.length,this.score);return e.prev=this.prev,e.backtraceScore=this.backtraceScore,e}}class c{constructor(e){this.trie=this._buildTrie(e)}_buildTrie(e){let t=Object.create(null);for(let n of e){let e=t;for(let t=0;t<n.length;++t)e=e[n[t]]??=Object.create(null);e.end=n}return t}split(e){let t=[],n=e.length,r=0,i=0;for(;i<n;){let a=this.trie,o=null,s=i;for(;s<n&&(a=a[e[s]]);)a.end&&(o=a.end),++s;o?(i>r&&t.push(e.slice(r,i)),t.push(o),i+=o.length,r=i):++i}return r<n&&t.push(e.slice(r)),t}}class l{constructor(e){this.capacity=e,this.cache=new Map}get(e){if(!this.cache.has(e))return;let t=this.cache.get(e);return this.cache.delete(e),this.cache.set(e,t),t}put(e,t){this.cache.has(e)&&this.cache.delete(e),this.cache.set(e,t),this.cache.size>this.capacity&&this.cache.delete(this.cache.keys().next().value)}clear(){this.cache.clear()}}}),"./src/utils/devices.js":((e,t,n)=>{n.r(t),n.d(t,{DEVICE_TYPES:()=>r});let r=Object.freeze({auto:`auto`,gpu:`gpu`,cpu:`cpu`,wasm:`wasm`,webgpu:`webgpu`,cuda:`cuda`,dml:`dml`,webnn:`webnn`,"webnn-npu":`webnn-npu`,"webnn-gpu":`webnn-gpu`,"webnn-cpu":`webnn-cpu`})}),"./src/utils/dtypes.js":((e,t,n)=>{n.r(t),n.d(t,{DATA_TYPES:()=>o,DEFAULT_DEVICE_DTYPE_MAPPING:()=>s,DEFAULT_DTYPE_SUFFIX_MAPPING:()=>c,isWebGpuFp16Supported:()=>a});var r=n(`./src/env.js`),i=n(`./src/utils/devices.js`);let a=(function(){let e;return async function(){if(e===void 0)if(!r.apis.IS_WEBGPU_AVAILABLE)e=!1;else try{e=(await navigator.gpu.requestAdapter()).features.has(`shader-f16`)}catch{e=!1}return e}})(),o=Object.freeze({auto:`auto`,fp32:`fp32`,fp16:`fp16`,q8:`q8`,int8:`int8`,uint8:`uint8`,q4:`q4`,bnb4:`bnb4`,q4f16:`q4f16`}),s=Object.freeze({[i.DEVICE_TYPES.wasm]:o.q8}),c=Object.freeze({[o.fp32]:``,[o.fp16]:`_fp16`,[o.int8]:`_int8`,[o.uint8]:`_uint8`,[o.q8]:`_quantized`,[o.q4]:`_q4`,[o.q4f16]:`_q4f16`,[o.bnb4]:`_bnb4`})}),"./src/utils/generic.js":((e,t,n)=>{n.r(t),n.d(t,{Callable:()=>r});let r=class{constructor(){let e=function(...t){return e._call(...t)};return Object.setPrototypeOf(e,new.target.prototype)}_call(...e){throw Error(`Must implement _call method in subclass`)}}}),"./src/utils/hub.js":((e,t,n)=>{n.r(t),n.d(t,{MAX_EXTERNAL_DATA_CHUNKS:()=>s,getFile:()=>p,getModelFile:()=>v,getModelJSON:()=>b,getModelText:()=>y});var r=n(`?7992`),i=n(`?5af5`),a=n(`./src/env.js`),o=n(`./src/utils/core.js`);let s=100,c={txt:`text/plain`,html:`text/html`,css:`text/css`,js:`text/javascript`,json:`application/json`,png:`image/png`,jpg:`image/jpeg`,jpeg:`image/jpeg`,gif:`image/gif`};class l{constructor(e){if(this.filePath=e,this.headers=new Headers,this.exists=r.existsSync(e),this.exists){this.status=200,this.statusText=`OK`;let t=r.statSync(e);this.headers.set(`content-length`,t.size.toString()),this.updateContentType();let n=r.createReadStream(e);this.body=new ReadableStream({start(e){n.on(`data`,t=>e.enqueue(t)),n.on(`end`,()=>e.close()),n.on(`error`,t=>e.error(t))},cancel(){n.destroy()}})}else this.status=404,this.statusText=`Not Found`,this.body=null}updateContentType(){let e=this.filePath.toString().split(`.`).pop().toLowerCase();this.headers.set(`content-type`,c[e]??`application/octet-stream`)}clone(){let e=new l(this.filePath);return e.exists=this.exists,e.status=this.status,e.statusText=this.statusText,e.headers=new Headers(this.headers),e}async arrayBuffer(){return(await r.promises.readFile(this.filePath)).buffer}async blob(){let e=await r.promises.readFile(this.filePath);return new Blob([e],{type:this.headers.get(`content-type`)})}async text(){return await r.promises.readFile(this.filePath,`utf8`)}async json(){return JSON.parse(await this.text())}}function u(e,t=null,n=null){let r;try{r=new URL(e)}catch{return!1}return!(t&&!t.includes(r.protocol)||n&&!n.includes(r.hostname))}let d=/^(\b[\w\-.]+\b\/)?\b[\w\-.]{1,96}\b$/;function f(e){return!(!d.test(e)||e.includes(`..`)||e.includes(`--`)||e.endsWith(`.git`)||e.endsWith(`.ipynb`))}async function p(e){if(a.env.useFS&&!u(e,[`http:`,`https:`,`blob:`]))return new l(e instanceof URL?e.protocol===`file:`?e.pathname:e.toString():e);if(typeof process<`u`&&process?.release?.name===`node`){let t=!!{}?.TESTING_REMOTELY,n=a.env.version,r=new Headers;if(r.set(`User-Agent`,`transformers.js/${n}; is_ci/${t};`),u(e,[`http:`,`https:`],[`huggingface.co`,`hf.co`])){let e={}?.HF_TOKEN??{}?.HF_ACCESS_TOKEN;e&&r.set(`Authorization`,`Bearer ${e}`)}return fetch(e,{headers:r})}else return fetch(e)}let m={400:`Bad request error occurred while trying to load file`,401:`Unauthorized access to file`,403:`Forbidden access to file`,404:`Could not locate file`,408:`Request timeout error occurred while trying to load file`,500:`Internal server error error occurred while trying to load file`,502:`Bad gateway error occurred while trying to load file`,503:`Service unavailable error occurred while trying to load file`,504:`Gateway timeout error occurred while trying to load file`};function h(e,t,n){if(!n)return null;let r=m[e]??`Error (${e}) occurred while trying to load file`;throw Error(`${r}: "${t}".`)}class g{constructor(e){this.path=e}async match(e){let t=new l(i.join(this.path,e));if(t.exists)return t}async put(e,t,n=void 0){let a=i.join(this.path,e);try{let e=t.headers.get(`Content-Length`),o=parseInt(e??`0`),s=0;await r.promises.mkdir(i.dirname(a),{recursive:!0});let c=r.createWriteStream(a),l=t.body.getReader();for(;;){let{done:e,value:t}=await l.read();if(e)break;await new Promise((e,n)=>{c.write(t,t=>{if(t){n(t);return}e()})}),s+=t.length;let r=o?s/o*100:0;n?.({progress:r,loaded:s,total:o})}c.close()}catch(e){try{await r.promises.unlink(a)}catch{}throw e}}}async function _(e,...t){for(let n of t)try{let t=await e.match(n);if(t)return t}catch{continue}}async function v(e,t,n=!0,r={},i=!1){if(!a.env.allowLocalModels){if(r.local_files_only)throw Error("Invalid configuration detected: local models are disabled (`env.allowLocalModels=false`) but you have requested to only use local models (`local_files_only=true`).");if(!a.env.allowRemoteModels)throw Error("Invalid configuration detected: both local and remote models are disabled. Fix by setting `env.allowLocalModels` or `env.allowRemoteModels` to `true`.")}(0,o.dispatchCallback)(r.progress_callback,{status:`initiate`,name:e,file:t});let s;if(!s&&a.env.useCustomCache){if(!a.env.customCache)throw Error("`env.useCustomCache=true`, but `env.customCache` is not defined.");if(!a.env.customCache.match||!a.env.customCache.put)throw Error("`env.customCache` must be an object which implements the `match` and `put` functions of the Web Cache API. For more information, see https://developer.mozilla.org/en-US/docs/Web/API/Cache");s=a.env.customCache}if(!s&&a.env.useBrowserCache){if(typeof caches>`u`)throw Error(`Browser cache is not available in this environment.`);try{s=await caches.open(`transformers-cache`)}catch(e){console.warn(`An error occurred while opening the browser cache:`,e)}}if(!s&&a.env.useFSCache){if(!a.apis.IS_FS_AVAILABLE)throw Error(`File System Cache is not available in this environment.`);s=new g(r.cache_dir??a.env.cacheDir)}let c=r.revision??`main`,d=S(e,t),m=f(e),v=m?S(a.env.localModelPath,d):d,y=S(a.env.remoteHost,a.env.remotePathTemplate.replaceAll(`{model}`,e).replaceAll(`{revision}`,encodeURIComponent(c)),t),b,C=s instanceof g?c===`main`?d:S(e,c,t):y,w=!1,T;s&&(T=await _(s,v,C));let E=T!==void 0;if(T===void 0){if(a.env.allowLocalModels){if(!u(d,[`http:`,`https:`]))try{T=await p(v),b=v}catch(e){console.warn(`Unable to load from local path "${v}": "${e}"`)}else if(r.local_files_only)throw Error(`\`local_files_only=true\`, but attempted to load a remote file from: ${d}.`);else if(!a.env.allowRemoteModels)throw Error(`\`env.allowRemoteModels=false\`, but attempted to load a remote file from: ${d}.`)}if(T===void 0||T.status===404){if(r.local_files_only||!a.env.allowRemoteModels){if(n)throw Error(`\`local_files_only=true\` or \`env.allowRemoteModels=false\` and file was not found locally at "${v}".`);return null}if(!m)throw Error(`Local file missing at "${v}" and download aborted due to invalid model ID "${e}".`);if(T=await p(y),T.status!==200)return h(T.status,y,n);b=C}w=s&&typeof Response<`u`&&T instanceof Response&&T.status===200}(0,o.dispatchCallback)(r.progress_callback,{status:`download`,name:e,file:t});let D;if(!(a.apis.IS_NODE_ENV&&i)){let n;r.progress_callback?E&&typeof navigator<`u`&&/firefox/i.test(navigator.userAgent)?(n=new Uint8Array(await T.arrayBuffer()),(0,o.dispatchCallback)(r.progress_callback,{status:`progress`,name:e,file:t,progress:100,loaded:n.length,total:n.length})):n=await x(T,n=>{(0,o.dispatchCallback)(r.progress_callback,{status:`progress`,name:e,file:t,...n})}):n=new Uint8Array(await T.arrayBuffer()),D=n}if(w&&b&&await s.match(b)===void 0)if(D)await s.put(b,new Response(D,{headers:T.headers})).catch(e=>{console.warn(`Unable to add response to browser cache: ${e}.`)});else{let n=r.progress_callback?n=>(0,o.dispatchCallback)(r.progress_callback,{status:`progress`,name:e,file:t,...n}):void 0;await s.put(b,T,n)}if((0,o.dispatchCallback)(r.progress_callback,{status:`done`,name:e,file:t}),D){if(!a.apis.IS_NODE_ENV&&i)throw Error(`Cannot return path in a browser environment.`);return D}if(T instanceof l)return T.filePath;let O=await s?.match(b);if(O instanceof l)return O.filePath;if(O instanceof Response)return new Uint8Array(await O.arrayBuffer());if(typeof O==`string`)return O;throw Error(`Unable to get model file path or buffer.`)}async function y(e,t,n=!0,r={}){let i=await v(e,t,n,r,!1);return i===null?null:new TextDecoder(`utf-8`).decode(i)}async function b(e,t,n=!0,r={}){let i=await y(e,t,n,r);return i===null?{}:JSON.parse(i)}async function x(e,t){let n=e.headers.get(`Content-Length`);n===null&&console.warn(`Unable to determine content-length from response headers. Will expand buffer when needed.`);let r=parseInt(n??`0`),i=new Uint8Array(r),a=0,o=e.body.getReader();async function s(){let{done:e,value:n}=await o.read();if(e)return;let c=a+n.length;if(c>r){r=c;let e=new Uint8Array(r);e.set(i),i=e}return i.set(n,a),a=c,t({progress:a/r*100,loaded:a,total:r}),s()}return await s(),i}function S(...e){return e=e.map((t,n)=>(n&&(t=t.replace(RegExp(`^/`),``)),n!==e.length-1&&(t=t.replace(RegExp(`/$`),``)),t)),e.join(`/`)}}),"./src/utils/image.js":((e,t,n)=>{n.r(t),n.d(t,{RawImage:()=>m,load_image:()=>h});var r=n(`./src/utils/core.js`),i=n(`./src/utils/hub.js`),a=n(`./src/env.js`),o=n(`./src/utils/tensor.js`),s=n(`?2b25`);let c,l,u,d=a.apis.IS_BROWSER_ENV||a.apis.IS_WEBWORKER_ENV;if(d)c=(e,t)=>{if(!self.OffscreenCanvas)throw Error(`OffscreenCanvas not supported by this browser.`);return new self.OffscreenCanvas(e,t)},u=self.createImageBitmap,l=self.ImageData;else if(s)u=async e=>{let t=(await e.metadata()).channels,{data:n,info:r}=await e.rotate().raw().toBuffer({resolveWithObject:!0}),i=new m(new Uint8ClampedArray(n),r.width,r.height,r.channels);return t!==void 0&&t!==r.channels&&i.convert(t),i};else throw Error(`Unable to load image processing library.`);let f={0:`nearest`,1:`lanczos`,2:`bilinear`,3:`bicubic`,4:`box`,5:`hamming`},p=new Map([[`png`,`image/png`],[`jpg`,`image/jpeg`],[`jpeg`,`image/jpeg`],[`gif`,`image/gif`]]);class m{constructor(e,t,n,r){this.data=e,this.width=t,this.height=n,this.channels=r}get size(){return[this.width,this.height]}static async read(e){if(e instanceof m)return e;if(typeof e==`string`||e instanceof URL)return await this.fromURL(e);if(e instanceof Blob)return await this.fromBlob(e);if(typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement||typeof OffscreenCanvas<`u`&&e instanceof OffscreenCanvas)return this.fromCanvas(e);throw Error(`Unsupported input type: ${typeof e}`)}static fromCanvas(e){if(!d)throw Error(`fromCanvas() is only supported in browser environments.`);let t=e.getContext(`2d`).getImageData(0,0,e.width,e.height).data;return new m(t,e.width,e.height,4)}static async fromURL(e){let t=await(0,i.getFile)(e);if(t.status!==200)throw Error(`Unable to read image from "${e}" (${t.status} ${t.statusText})`);let n=await t.blob();return this.fromBlob(n)}static async fromBlob(e){if(d){let t=await u(e),n=c(t.width,t.height).getContext(`2d`);return n.drawImage(t,0,0),new this(n.getImageData(0,0,t.width,t.height).data,t.width,t.height,4)}else{let t=s(await e.arrayBuffer());return await u(t)}}static fromTensor(e,t=`CHW`){if(e.dims.length!==3)throw Error(`Tensor should have 3 dimensions, but has ${e.dims.length} dimensions.`);if(t===`CHW`)e=e.transpose(1,2,0);else if(t!==`HWC`)throw Error(`Unsupported channel format: ${t}`);if(!(e.data instanceof Uint8ClampedArray||e.data instanceof Uint8Array))throw Error(`Unsupported tensor type: ${e.type}`);switch(e.dims[2]){case 1:case 2:case 3:case 4:return new m(e.data,e.dims[1],e.dims[0],e.dims[2]);default:throw Error(`Unsupported number of channels: ${e.dims[2]}`)}}grayscale(){if(this.channels===1)return this;let e=new Uint8ClampedArray(this.width*this.height*1);switch(this.channels){case 3:case 4:for(let t=0,n=0;t<this.data.length;t+=this.channels){let r=this.data[t],i=this.data[t+1],a=this.data[t+2];e[n++]=Math.round(.2989*r+.587*i+.114*a)}break;default:throw Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,1)}rgb(){if(this.channels===3)return this;let e=new Uint8ClampedArray(this.width*this.height*3);switch(this.channels){case 1:for(let t=0,n=0;t<this.data.length;++t)e[n++]=this.data[t],e[n++]=this.data[t],e[n++]=this.data[t];break;case 4:for(let t=0,n=0;t<this.data.length;t+=4)e[n++]=this.data[t],e[n++]=this.data[t+1],e[n++]=this.data[t+2];break;default:throw Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,3)}rgba(){if(this.channels===4)return this;let e=new Uint8ClampedArray(this.width*this.height*4);switch(this.channels){case 1:for(let t=0,n=0;t<this.data.length;++t)e[n++]=this.data[t],e[n++]=this.data[t],e[n++]=this.data[t],e[n++]=255;break;case 3:for(let t=0,n=0;t<this.data.length;t+=3)e[n++]=this.data[t],e[n++]=this.data[t+1],e[n++]=this.data[t+2],e[n++]=255;break;default:throw Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,4)}putAlpha(e){if(e.width!==this.width||e.height!==this.height)throw Error(`Expected mask size to be ${this.width}x${this.height}, but got ${e.width}x${e.height}`);if(e.channels!==1)throw Error(`Expected mask to have 1 channel, but got ${e.channels}`);let t=this.data,n=e.data,r=this.width*this.height;if(this.channels===3){let e=new Uint8ClampedArray(r*4);for(let i=0,a=0,o=0;i<r;++i)e[o++]=t[a++],e[o++]=t[a++],e[o++]=t[a++],e[o++]=n[i];return this._update(e,this.width,this.height,4)}else if(this.channels===4){for(let e=0;e<r;++e)t[4*e+3]=n[e];return this}throw Error(`Expected image to have 3 or 4 channels, but got ${this.channels}`)}async resize(e,t,{resample:n=2}={}){if(this.width===e&&this.height===t)return this;let i=f[n]??n,a=(0,r.isNullishDimension)(e),o=(0,r.isNullishDimension)(t);if(a&&o)return this;if(a?e=t/this.height*this.width:o&&(t=e/this.width*this.height),d){let n=this.channels,r=this.toCanvas(),i=c(e,t).getContext(`2d`);return i.drawImage(r,0,0,e,t),new m(i.getImageData(0,0,e,t).data,e,t,4).convert(n)}else{let n=this.toSharp();switch(i){case`box`:case`hamming`:(i===`box`||i===`hamming`)&&(console.warn(`Resampling method ${i} is not yet supported. Using bilinear instead.`),i=`bilinear`);case`nearest`:case`bilinear`:case`bicubic`:n=n.affine([e/this.width,0,0,t/this.height],{interpolator:i});break;case`lanczos`:n=n.resize({width:e,height:t,fit:`fill`,kernel:`lanczos3`});break;default:throw Error(`Resampling method ${i} is not supported.`)}return await u(n)}}async pad([e,t,n,r]){if(e=Math.max(e,0),t=Math.max(t,0),n=Math.max(n,0),r=Math.max(r,0),e===0&&t===0&&n===0&&r===0)return this;if(d){let i=this.channels,a=this.toCanvas(),o=this.width+e+t,s=this.height+n+r,l=c(o,s).getContext(`2d`);return l.drawImage(a,0,0,this.width,this.height,e,n,this.width,this.height),new m(l.getImageData(0,0,o,s).data,o,s,4).convert(i)}else{let i=this.toSharp().extend({left:e,right:t,top:n,bottom:r});return await u(i)}}async crop([e,t,n,r]){if(e=Math.max(e,0),t=Math.max(t,0),n=Math.min(n,this.width-1),r=Math.min(r,this.height-1),e===0&&t===0&&n===this.width-1&&r===this.height-1)return this;let i=n-e+1,a=r-t+1;if(d){let n=this.channels,r=this.toCanvas(),o=c(i,a).getContext(`2d`);return o.drawImage(r,e,t,i,a,0,0,i,a),new m(o.getImageData(0,0,i,a).data,i,a,4).convert(n)}else{let n=this.toSharp().extract({left:e,top:t,width:i,height:a});return await u(n)}}async center_crop(e,t){if(this.width===e&&this.height===t)return this;let n=(this.width-e)/2,r=(this.height-t)/2;if(d){let i=this.channels,a=this.toCanvas(),o=c(e,t).getContext(`2d`),s=0,l=0,u=0,d=0;return n>=0?s=n:u=-n,r>=0?l=r:d=-r,o.drawImage(a,s,l,e,t,u,d,e,t),new m(o.getImageData(0,0,e,t).data,e,t,4).convert(i)}else{let i=this.toSharp();if(n>=0&&r>=0)i=i.extract({left:Math.floor(n),top:Math.floor(r),width:e,height:t});else if(n<=0&&r<=0){let a=Math.floor(-r),o=Math.floor(-n);i=i.extend({top:a,left:o,right:e-this.width-o,bottom:t-this.height-a})}else{let a=[0,0],o=0;r<0?(a[0]=Math.floor(-r),a[1]=t-this.height-a[0]):o=Math.floor(r);let s=[0,0],c=0;n<0?(s[0]=Math.floor(-n),s[1]=e-this.width-s[0]):c=Math.floor(n),i=i.extend({top:a[0],bottom:a[1],left:s[0],right:s[1]}).extract({left:c,top:o,width:e,height:t})}return await u(i)}}async toBlob(e=`image/png`,t=1){if(!d)throw Error(`toBlob() is only supported in browser environments.`);return await this.toCanvas().convertToBlob({type:e,quality:t})}toTensor(e=`CHW`){let t=new o.Tensor(`uint8`,new Uint8Array(this.data),[this.height,this.width,this.channels]);if(e!==`HWC`)if(e===`CHW`)t=t.permute(2,0,1);else throw Error(`Unsupported channel format: ${e}`);return t}toCanvas(){if(!d)throw Error(`toCanvas() is only supported in browser environments.`);let e=this.clone().rgba(),t=c(e.width,e.height),n=new l(e.data,e.width,e.height);return t.getContext(`2d`).putImageData(n,0,0),t}split(){let{data:e,width:t,height:n,channels:r}=this,i=e.constructor,a=e.length/r,o=Array.from({length:r},()=>new i(a));for(let t=0;t<a;++t){let n=r*t;for(let i=0;i<r;++i)o[i][t]=e[n+i]}return o.map(e=>new m(e,t,n,1))}_update(e,t,n,r=null){return this.data=e,this.width=t,this.height=n,r!==null&&(this.channels=r),this}clone(){return new m(this.data.slice(),this.width,this.height,this.channels)}convert(e){if(this.channels===e)return this;switch(e){case 1:this.grayscale();break;case 3:this.rgb();break;case 4:this.rgba();break;default:throw Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this}async save(e){if(d){if(a.apis.IS_WEBWORKER_ENV)throw Error(`Unable to save an image from a Web Worker.`);let t=e.split(`.`).pop().toLowerCase(),n=p.get(t)??`image/png`,i=await this.toBlob(n);(0,r.saveBlob)(e,i)}else if(a.apis.IS_FS_AVAILABLE)return await this.toSharp().toFile(e);else throw Error(`Unable to save the image because filesystem is disabled in this environment.`)}toSharp(){if(d)throw Error(`toSharp() is only supported in server-side environments.`);return s(this.data,{raw:{width:this.width,height:this.height,channels:this.channels}})}}let h=m.read.bind(m)}),"./src/utils/maths.js":((e,t,n)=>{n.r(t),n.d(t,{FFT:()=>h,bankers_round:()=>v,cos_sim:()=>c,dot:()=>s,dynamic_time_warping:()=>y,interpolate_data:()=>r,log_softmax:()=>o,magnitude:()=>l,max:()=>d,medianFilter:()=>g,min:()=>u,permute_data:()=>i,round:()=>_,softmax:()=>a});function r(e,[t,n,r],[i,a],o=`bilinear`,s=!1){let c=a/r,l=i/n,u=new e.constructor(i*a*t),d=n*r,f=i*a;for(let o=0;o<i;++o)for(let i=0;i<a;++i){let s=o*a+i,p=(i+.5)/c-.5,m=(o+.5)/l-.5,h=Math.floor(p),g=Math.floor(m),_=Math.min(h+1,r-1),v=Math.min(g+1,n-1);h=Math.max(h,0),g=Math.max(g,0);let y=p-h,b=m-g,x=(1-y)*(1-b),S=y*(1-b),C=(1-y)*b,w=y*b,T=g*r,E=v*r,D=T+h,O=T+_,k=E+h,A=E+_;for(let n=0;n<t;++n){let t=n*d;u[n*f+s]=x*e[t+D]+S*e[t+O]+C*e[t+k]+w*e[t+A]}}return u}function i(e,t,n){let r=Array(n.length),i=Array(n.length);for(let e=n.length-1,a=1;e>=0;--e)i[e]=a,r[e]=t[n[e]],a*=r[e];let a=n.map((e,t)=>i[n.indexOf(t)]),o=new e.constructor(e.length);for(let n=0;n<e.length;++n){let r=0;for(let e=t.length-1,i=n;e>=0;--e)r+=i%t[e]*a[e],i=Math.floor(i/t[e]);o[r]=e[n]}return[o,r]}function a(e){let t=d(e)[0],n=e.map(e=>Math.exp(e-t)),r=n.reduce((e,t)=>e+t,0);return n.map(e=>e/r)}function o(e){let t=d(e)[0],n=0;for(let r=0;r<e.length;++r)n+=Math.exp(e[r]-t);let r=Math.log(n);return e.map(e=>e-t-r)}function s(e,t){let n=0;for(let r=0;r<e.length;++r)n+=e[r]*t[r];return n}function c(e,t){return s(e,t)/(l(e)*l(t))}function l(e){return Math.sqrt(e.reduce((e,t)=>e+t*t,0))}function u(e){if(e.length===0)throw Error(`Array must not be empty`);let t=e[0],n=0;for(let r=1;r<e.length;++r)e[r]<t&&(t=e[r],n=r);return[t,n]}function d(e){if(e.length===0)throw Error(`Array must not be empty`);let t=e[0],n=0;for(let r=1;r<e.length;++r)e[r]>t&&(t=e[r],n=r);return[t,n]}function f(e){return e>0&&(e&e-1)==0}class p{constructor(e){if(this.size=e|0,this.size<=1||!f(this.size))throw Error(`FFT size must be a power of two larger than 1`);this._csize=e<<1,this.table=new Float64Array(this.size*2);for(let e=0;e<this.table.length;e+=2){let t=Math.PI*e/this.size;this.table[e]=Math.cos(t),this.table[e+1]=-Math.sin(t)}let t=0;for(let e=1;this.size>e;e<<=1)++t;this._width=t%2==0?t-1:t,this._bitrev=new Int32Array(1<<this._width);for(let e=0;e<this._bitrev.length;++e){this._bitrev[e]=0;for(let t=0;t<this._width;t+=2){let n=this._width-t-2;this._bitrev[e]|=(e>>>t&3)<<n}}}createComplexArray(){return new Float64Array(this._csize)}fromComplexArray(e,t){let n=t||Array(e.length>>>1);for(let t=0;t<e.length;t+=2)n[t>>>1]=e[t];return n}toComplexArray(e,t){let n=t||this.createComplexArray();for(let t=0;t<n.length;t+=2)n[t]=e[t>>>1],n[t+1]=0;return n}transform(e,t){if(e===t)throw Error(`Input and output buffers must be different`);this._transform4(e,t,1)}realTransform(e,t){if(e===t)throw Error(`Input and output buffers must be different`);this._realTransform4(e,t,1)}inverseTransform(e,t){if(e===t)throw Error(`Input and output buffers must be different`);this._transform4(e,t,-1);for(let t=0;t<e.length;++t)e[t]/=this.size}_transform4(e,t,n){let r=this._csize,i=1<<this._width,a=r/i<<1,o,s,c=this._bitrev;if(a===4)for(o=0,s=0;o<r;o+=a,++s){let n=c[s];this._singleTransform2(t,e,o,n,i)}else for(o=0,s=0;o<r;o+=a,++s){let r=c[s];this._singleTransform4(t,e,o,r,i,n)}let l=this.table;for(i>>=2;i>=2;i>>=2){a=r/i<<1;let t=a>>>2;for(o=0;o<r;o+=a){let r=o+t-1;for(let a=o,s=0;a<r;a+=2,s+=i){let r=a,i=r+t,o=i+t,c=o+t,u=e[r],d=e[r+1],f=e[i],p=e[i+1],m=e[o],h=e[o+1],g=e[c],_=e[c+1],v=l[s],y=n*l[s+1],b=f*v-p*y,x=f*y+p*v,S=l[2*s],C=n*l[2*s+1],w=m*S-h*C,T=m*C+h*S,E=l[3*s],D=n*l[3*s+1],O=g*E-_*D,k=g*D+_*E,A=u+w,ee=d+T,te=u-w,ne=d-T,j=b+O,re=x+k,ie=n*(b-O),ae=n*(x-k);e[r]=A+j,e[r+1]=ee+re,e[i]=te+ae,e[i+1]=ne-ie,e[o]=A-j,e[o+1]=ee-re,e[c]=te-ae,e[c+1]=ne+ie}}}}_singleTransform2(e,t,n,r,i){let a=e[r],o=e[r+1],s=e[r+i],c=e[r+i+1];t[n]=a+s,t[n+1]=o+c,t[n+2]=a-s,t[n+3]=o-c}_singleTransform4(e,t,n,r,i,a){let o=i*2,s=i*3,c=e[r],l=e[r+1],u=e[r+i],d=e[r+i+1],f=e[r+o],p=e[r+o+1],m=e[r+s],h=e[r+s+1],g=c+f,_=l+p,v=c-f,y=l-p,b=u+m,x=d+h,S=a*(u-m),C=a*(d-h);t[n]=g+b,t[n+1]=_+x,t[n+2]=v+C,t[n+3]=y-S,t[n+4]=g-b,t[n+5]=_-x,t[n+6]=v-C,t[n+7]=y+S}_realTransform4(e,t,n){let r=this._csize,i=1<<this._width,a=r/i<<1,o,s,c=this._bitrev;if(a===4)for(o=0,s=0;o<r;o+=a,++s){let n=c[s];this._singleRealTransform2(t,e,o,n>>>1,i>>>1)}else for(o=0,s=0;o<r;o+=a,++s){let r=c[s];this._singleRealTransform4(t,e,o,r>>>1,i>>>1,n)}let l=this.table;for(i>>=2;i>=2;i>>=2){a=r/i<<1;let t=a>>>1,s=t>>>1,c=s>>>1;for(o=0;o<r;o+=a)for(let r=0,a=0;r<=c;r+=2,a+=i){let i=o+r,u=i+s,d=u+s,f=d+s,p=e[i],m=e[i+1],h=e[u],g=e[u+1],_=e[d],v=e[d+1],y=e[f],b=e[f+1],x=p,S=m,C=l[a],w=n*l[a+1],T=h*C-g*w,E=h*w+g*C,D=l[2*a],O=n*l[2*a+1],k=_*D-v*O,A=_*O+v*D,ee=l[3*a],te=n*l[3*a+1],ne=y*ee-b*te,j=y*te+b*ee,re=x+k,ie=S+A,ae=x-k,oe=S-A,se=T+ne,M=E+j,N=n*(T-ne),ce=n*(E-j);if(e[i]=re+se,e[i+1]=ie+M,e[u]=ae+ce,e[u+1]=oe-N,r===0){e[d]=re-se,e[d+1]=ie-M;continue}if(r===c)continue;let le=o+s-r,ue=o+t-r;e[le]=ae-n*ce,e[le+1]=-oe-n*N,e[ue]=re-n*se,e[ue+1]=-ie+n*M}}let u=r>>>1;for(let t=2;t<u;t+=2)e[r-t]=e[t],e[r-t+1]=-e[t+1]}_singleRealTransform2(e,t,n,r,i){let a=e[r],o=e[r+i];t[n]=a+o,t[n+1]=0,t[n+2]=a-o,t[n+3]=0}_singleRealTransform4(e,t,n,r,i,a){let o=i*2,s=i*3,c=e[r],l=e[r+i],u=e[r+o],d=e[r+s],f=c+u,p=c-u,m=l+d,h=a*(l-d);t[n]=f+m,t[n+1]=0,t[n+2]=p,t[n+3]=-h,t[n+4]=f-m,t[n+5]=0,t[n+6]=p,t[n+7]=h}}class m{constructor(e){let t=2*(e-1),n=2*(2*e-1),r=2**Math.ceil(Math.log2(n));this.bufferSize=r,this._a=t;let i=new Float64Array(n),a=new Float64Array(r);this._chirpBuffer=new Float64Array(r),this._buffer1=new Float64Array(r),this._buffer2=new Float64Array(r),this._outBuffer1=new Float64Array(r),this._outBuffer2=new Float64Array(r);let o=-2*Math.PI/e,s=Math.cos(o),c=Math.sin(o);for(let t=0;t<n>>1;++t){let n=(t+1-e)**2/2,r=Math.sqrt(s**2+c**2)**n,o=n*Math.atan2(c,s),l=2*t;i[l]=r*Math.cos(o),i[l+1]=r*Math.sin(o),a[l]=i[l],a[l+1]=-i[l+1]}this._slicedChirpBuffer=i.subarray(t,n),this._f=new p(r>>1),this._f.transform(this._chirpBuffer,a)}_transform(e,t,n){let r=this._buffer1,i=this._buffer2,a=this._outBuffer1,o=this._outBuffer2,s=this._chirpBuffer,c=this._slicedChirpBuffer,l=this._a;if(n)for(let e=0;e<c.length;e+=2){let n=e+1,i=t[e>>1];r[e]=i*c[e],r[n]=i*c[n]}else for(let e=0;e<c.length;e+=2){let n=e+1;r[e]=t[e]*c[e]-t[n]*c[n],r[n]=t[e]*c[n]+t[n]*c[e]}this._f.transform(a,r);for(let e=0;e<s.length;e+=2){let t=e+1;i[e]=a[e]*s[e]-a[t]*s[t],i[t]=a[e]*s[t]+a[t]*s[e]}this._f.inverseTransform(o,i);for(let t=0;t<o.length;t+=2){let n=o[t+l],r=o[t+l+1],i=c[t],a=c[t+1];e[t]=n*i-r*a,e[t+1]=n*a+r*i}}transform(e,t){this._transform(e,t,!1)}realTransform(e,t){this._transform(e,t,!0)}}class h{constructor(e){this.fft_length=e,this.isPowerOfTwo=f(e),this.isPowerOfTwo?(this.fft=new p(e),this.outputBufferSize=2*e):(this.fft=new m(e),this.outputBufferSize=this.fft.bufferSize)}realTransform(e,t){this.fft.realTransform(e,t)}transform(e,t){this.fft.transform(e,t)}}function g(e,t){if(t%2==0||t<=0)throw Error(`Window size must be a positive odd number`);let n=new e.constructor(e.length),r=new e.constructor(t),i=Math.floor(t/2);for(let t=0;t<e.length;++t){let a=0;for(let n=-i;n<=i;++n){let i=t+n;i<0?i=Math.abs(i):i>=e.length&&(i=2*(e.length-1)-i),r[a++]=e[i]}r.sort(),n[t]=r[i]}return n}function _(e,t){let n=10**t;return Math.round(e*n)/n}function v(e){let t=Math.round(e);return Math.abs(e)%1==.5?t%2==0?t:t-1:t}function y(e){let t=e.length,n=e[0].length,r=[t+1,n+1],i=Array.from({length:r[0]},()=>Array(r[1]).fill(1/0));i[0][0]=0;let a=Array.from({length:r[0]},()=>Array(r[1]).fill(-1));for(let t=1;t<r[1];++t)for(let n=1;n<r[0];++n){let r=i[n-1][t-1],o=i[n-1][t],s=i[n][t-1],c,l;r<o&&r<s?(c=r,l=0):o<r&&o<s?(c=o,l=1):(c=s,l=2),i[n][t]=e[n-1][t-1]+c,a[n][t]=l}for(let e=0;e<r[1];++e)a[0][e]=2;for(let e=0;e<r[0];++e)a[e][0]=1;let o=t,s=n,c=[],l=[];for(;o>0||s>0;)switch(c.push(o-1),l.push(s-1),a[o][s]){case 0:--o,--s;break;case 1:--o;break;case 2:--s;break;default:throw Error(`Internal error in dynamic time warping. Unexpected trace[${o}, ${s}]. Please file a bug report.`)}return c.reverse(),l.reverse(),[c,l]}}),"./src/utils/tensor.js":((e,t,n)=>{n.r(t),n.d(t,{DataTypeMap:()=>o,Tensor:()=>s,cat:()=>S,full:()=>k,full_like:()=>A,interpolate:()=>u,interpolate_4d:()=>d,layer_norm:()=>v,matmul:()=>f,mean:()=>E,mean_pooling:()=>_,ones:()=>ee,ones_like:()=>te,permute:()=>l,quantize_embeddings:()=>ae,rand:()=>re,randn:()=>ie,rfft:()=>p,slice:()=>g,stack:()=>C,std_mean:()=>T,topk:()=>m,zeros:()=>ne,zeros_like:()=>j});var r=n(`./src/utils/maths.js`),i=n(`./src/backends/onnx.js`),a=n(`./src/ops/registry.js`);let o=Object.freeze({float32:Float32Array,float16:typeof Float16Array<`u`?Float16Array:Uint16Array,float64:Float64Array,string:Array,int8:Int8Array,uint8:Uint8Array,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,int64:BigInt64Array,uint64:BigUint64Array,bool:Uint8Array,uint4:Uint8Array,int4:Int8Array});class s{get dims(){return this.ort_tensor.dims}set dims(e){this.ort_tensor.dims=e}get type(){return this.ort_tensor.type}get data(){return this.ort_tensor.data}get size(){return this.ort_tensor.size}get location(){return this.ort_tensor.location}ort_tensor;constructor(...e){return(0,i.isONNXTensor)(e[0])?this.ort_tensor=e[0]:this.ort_tensor=new i.Tensor(e[0],e[1],e[2]),new Proxy(this,{get:(e,t)=>{if(typeof t==`string`){let n=Number(t);if(Number.isInteger(n))return e._getitem(n)}return e[t]},set:(e,t,n)=>e[t]=n})}dispose(){this.ort_tensor.dispose()}*[Symbol.iterator](){let[e,...t]=this.dims;if(t.length>0){let n=t.reduce((e,t)=>e*t);for(let r=0;r<e;++r)yield this._subarray(r,n,t)}else yield*this.data}_getitem(e){let[t,...n]=this.dims;if(e=x(e,t),n.length>0){let t=n.reduce((e,t)=>e*t);return this._subarray(e,t,n)}else return new s(this.type,[this.data[e]],n)}indexOf(e){let t=this.data;for(let n=0;n<t.length;++n)if(t[n]==e)return n;return-1}_subarray(e,t,n){let r=e*t,i=(e+1)*t,a=`subarray`in this.data?this.data.subarray(r,i):this.data.slice(r,i);return new s(this.type,a,n)}item(){let e=this.data;if(e.length!==1)throw Error(`a Tensor with ${e.length} elements cannot be converted to Scalar`);return e[0]}tolist(){return c(this.data,this.dims)}sigmoid(){return this.clone().sigmoid_()}sigmoid_(){let e=this.data;for(let t=0;t<e.length;++t)e[t]=1/(1+Math.exp(-e[t]));return this}map(e){return this.clone().map_(e)}map_(e){let t=this.data;for(let n=0;n<t.length;++n)t[n]=e(t[n],n,t);return this}mul(e){return this.clone().mul_(e)}mul_(e){let t=this.data;for(let n=0;n<t.length;++n)t[n]*=e;return this}div(e){return this.clone().div_(e)}div_(e){let t=this.data;for(let n=0;n<t.length;++n)t[n]/=e;return this}add(e){return this.clone().add_(e)}add_(e){let t=this.data;for(let n=0;n<t.length;++n)t[n]+=e;return this}sub(e){return this.clone().sub_(e)}sub_(e){let t=this.data;for(let n=0;n<t.length;++n)t[n]-=e;return this}clone(){return new s(this.type,this.data.slice(),this.dims.slice())}slice(...e){let t=[],n=[];for(let r=0;r<this.dims.length;++r){let i=e[r];if(i==null)n.push([0,this.dims[r]]),t.push(this.dims[r]);else if(typeof i==`number`)i=x(i,this.dims[r],r),n.push([i,i+1]);else if(Array.isArray(i)&&i.length===2){let[e,a]=i;if(e=e===null?0:x(e,this.dims[r],r,!1),a=a===null?this.dims[r]:x(a,this.dims[r],r,!1),e>a)throw Error(`Invalid slice: ${i}`);let o=[Math.max(e,0),Math.min(a,this.dims[r])];n.push(o),t.push(o[1]-o[0])}else throw Error(`Invalid slice: ${i}`)}let r=n.map(([e,t])=>t-e),i=r.reduce((e,t)=>e*t),a=this.data,o=new a.constructor(i),c=this.stride(),l=!0;for(let e=1;e<r.length;++e)if(n[e][0]!==0||n[e][1]!==this.dims[e]){l=!1;break}if(l){let e=n[0][0]*c[0],t=n[0][1]*c[0];if(ArrayBuffer.isView(a))o.set(a.subarray(e,t));else if(Array.isArray(a)){let n=a.slice(e,t);for(let e=0;e<n.length;++e)o[e]=n[e]}else throw Error(`Unsupported data type for slicing`)}else for(let e=0;e<i;++e){let t=0;for(let i=r.length-1,a=e;i>=0;--i){let e=r[i];t+=(a%e+n[i][0])*c[i],a=Math.floor(a/e)}o[e]=a[t]}return new s(this.type,o,t)}permute(...e){return l(this,e)}transpose(...e){return this.permute(...e)}sum(e=null,t=!1){return this.norm(1,e,t)}norm(e=`fro`,t=null,n=!1){if(e===`fro`)e=2;else if(typeof e==`string`)throw Error(`Unsupported norm: ${e}`);let r=this.data,i=(t,n)=>t+n**e;if(t===null){let t=r.reduce(i,0)**(1/e);return new s(this.type,[t],[])}let[a,o,c]=w(i,this,t,n);if(e!==1)for(let t=0;t<o.length;++t)o[t]=o[t]**(1/e);return new s(a,o,c)}normalize_(e=2,t=1){t=x(t,this.dims.length);let n=this.norm(e,t,!0),r=this.data,i=n.data;for(let e=0;e<r.length;++e){let n=0;for(let r=this.dims.length-1,i=e,a=1;r>=0;--r){let e=this.dims[r];if(r!==t){let t=i%e;n+=t*a,a*=this.dims[r]}i=Math.floor(i/e)}r[e]/=i[n]}return this}normalize(e=2,t=1){return this.clone().normalize_(e,t)}stride(){return D(this.dims)}squeeze(e=null){return new s(this.type,this.data,y(this.dims,e))}squeeze_(e=null){return this.dims=y(this.dims,e),this}unsqueeze(e=null){return new s(this.type,this.data,b(this.dims,e))}unsqueeze_(e=null){return this.dims=b(this.dims,e),this}flatten_(e=0,t=-1){t=(t+this.dims.length)%this.dims.length;let n=this.dims.slice(0,e),r=this.dims.slice(e,t+1),i=this.dims.slice(t+1);return this.dims=[...n,r.reduce((e,t)=>e*t,1),...i],this}flatten(e=0,t=-1){return this.clone().flatten_(e,t)}view(...e){let t=-1;for(let n=0;n<e.length;++n)if(e[n]===-1){if(t!==-1)throw Error(`Only one dimension can be inferred`);t=n}let n=this.data;if(t!==-1){let r=e.reduce((e,n,r)=>r===t?e:e*n,1);e[t]=n.length/r}return new s(this.type,n,e)}neg_(){let e=this.data;for(let t=0;t<e.length;++t)e[t]=-e[t];return this}neg(){return this.clone().neg_()}gt(e){let t=new Uint8Array(this.data.length),n=this.data;for(let r=0;r<n.length;++r)t[r]=+(n[r]>e);return new s(`bool`,t,this.dims)}lt(e){let t=new Uint8Array(this.data.length),n=this.data;for(let r=0;r<n.length;++r)t[r]=+(n[r]<e);return new s(`bool`,t,this.dims)}clamp_(e,t){let n=this.data;for(let r=0;r<n.length;++r)n[r]=Math.min(Math.max(n[r],e),t);return this}clamp(e,t){return this.clone().clamp_(e,t)}round_(){let e=this.data;for(let t=0;t<e.length;++t)e[t]=Math.round(e[t]);return this}round(){return this.clone().round_()}mean(e=null,t=!1){return E(this,e,t)}min(e=null,t=!1){if(e===null){let e=(0,r.min)(this.data)[0];return new s(this.type,[e],[])}let[n,i,a]=w((e,t)=>Math.min(e,t),this,e,t,1/0);return new s(n,i,a)}max(e=null,t=!1){if(e===null){let e=(0,r.max)(this.data)[0];return new s(this.type,[e],[])}let[n,i,a]=w((e,t)=>Math.max(e,t),this,e,t,-1/0);return new s(n,i,a)}argmin(e=null,t=!1){if(e!==null)throw Error("`dim !== null` not yet implemented.");let n=(0,r.min)(this.data)[1];return new s(`int64`,[BigInt(n)],[])}argmax(e=null,t=!1){if(e!==null)throw Error("`dim !== null` not yet implemented.");let n=(0,r.max)(this.data)[1];return new s(`int64`,[BigInt(n)],[])}to(e){if(this.type===e)return this;if(!o.hasOwnProperty(e))throw Error(`Unsupported type: ${e}`);let t,n=[`int64`,`uint64`].includes(this.type),r=[`int64`,`uint64`].includes(e);return n&&!r?t=Number:!n&&r&&(t=[`float16`,`float32`,`float64`].includes(this.type)?e=>BigInt(Math.floor(e)):BigInt),new s(e,o[e].from(this.data,t),this.dims)}}function c(e,t){let n=e.length;if(n!==t.reduce((e,t)=>e*t))throw Error(`cannot reshape array of size ${n} into shape (${t})`);let r=e;for(let e=t.length-1;e>=0;e--)r=r.reduce((n,r)=>{let i=n[n.length-1];return i.length<t[e]?i.push(r):n.push([r]),n},[[]]);return r[0]}function l(e,t){let[n,i]=(0,r.permute_data)(e.data,e.dims,t);return new s(e.type,n,i)}function u(e,[t,n],i=`bilinear`,a=!1){let o=e.dims.at(-3)??1,c=e.dims.at(-2),l=e.dims.at(-1),u=(0,r.interpolate_data)(e.data,[o,c,l],[t,n],i,a);return new s(e.type,u,[o,t,n])}async function d(e,{size:t=null,mode:n=`bilinear`}={}){if(e.dims.length!==4)throw Error("`interpolate_4d` currently only supports 4D input.");if(!t)throw Error("`interpolate_4d` requires a `size` argument.");let r;if(t.length===2)r=[...e.dims.slice(0,2),...t];else if(t.length===3)r=[e.dims[0],...t];else if(t.length===4)r=t;else throw Error("`size` must be of length 2, 3, or 4.");let i;if(n===`nearest`)i=await a.TensorOpRegistry.nearest_interpolate_4d;else if(n===`bilinear`)i=await a.TensorOpRegistry.bilinear_interpolate_4d;else if(n===`bicubic`)i=await a.TensorOpRegistry.bicubic_interpolate_4d;else throw Error(`Unsupported mode: ${n}`);let o=new s(`int64`,new BigInt64Array(r.map(BigInt)),[r.length]);return await i({x:e,s:o})}async function f(e,t){return await(await a.TensorOpRegistry.matmul)({a:e,b:t})}async function p(e,t){return await(await a.TensorOpRegistry.rfft)({x:e,a:t})}async function m(e,t){let n=await a.TensorOpRegistry.top_k;return t=t==null?e.dims.at(-1):Math.min(t,e.dims.at(-1)),await n({x:e,k:new s(`int64`,[BigInt(t)],[1])})}let h=e=>new s(`int64`,e,[e.length]);async function g(e,t,n,r,i){return await(await a.TensorOpRegistry.slice)({x:e,s:h(t),e:h(n),a:h(r),t:h(i??Array(r.length).fill(1))})}function _(e,t){let n=e.data,r=t.data,i=[e.dims[0],e.dims[2]],a=new n.constructor(i[0]*i[1]),[o,c,l]=e.dims,u=0;for(let e=0;e<o;++e){let t=e*l*c;for(let i=0;i<l;++i){let o=0,s=0,d=e*c,f=t+i;for(let e=0;e<c;++e){let t=Number(r[d+e]);s+=t,o+=n[f+e*l]*t}let p=o/s;a[u++]=p}}return new s(e.type,a,i)}function v(e,t,{eps:n=1e-5}={}){if(e.dims.length!==2)throw Error("`layer_norm` currently only supports 2D input.");let[r,i]=e.dims;if(t.length!==1&&t[0]!==i)throw Error("`normalized_shape` must be a 1D array with shape `[input.dims[1]]`.");let[a,o]=T(e,1,0,!0),c=a.data,l=o.data,u=e.data,d=new u.constructor(u.length);for(let e=0;e<r;++e){let t=e*i;for(let r=0;r<i;++r){let i=t+r;d[i]=(u[i]-l[e])/(c[e]+n)}}return new s(e.type,d,e.dims)}function y(e,t){return e=e.slice(),t===null?e=e.filter(e=>e!==1):typeof t==`number`?e[t]===1&&e.splice(t,1):Array.isArray(t)&&(e=e.filter((e,n)=>e!==1||!t.includes(n))),e}function b(e,t){return t=x(t,e.length+1),e=e.slice(),e.splice(t,0,1),e}function x(e,t,n=null,r=!0){if(e<-t||e>=t){if(r)throw Error(`IndexError: index ${e} is out of bounds for dimension${n===null?``:` `+n} with size ${t}`);return e<-t?0:t}return e<0&&(e=(e%t+t)%t),e}function S(e,t=0){t=x(t,e[0].dims.length);let n=e[0].dims.slice();n[t]=e.reduce((e,n)=>e+n.dims[t],0);let r=n.reduce((e,t)=>e*t,1),i=new e[0].data.constructor(r),a=e[0].type;if(t===0){let t=0;for(let n of e){let e=n.data;i.set(e,t),t+=e.length}}else{let r=0;for(let a=0;a<e.length;++a){let{data:o,dims:s}=e[a];for(let e=0;e<o.length;++e){let a=0;for(let i=s.length-1,o=e,c=1;i>=0;--i){let e=s[i],l=o%e;i===t&&(l+=r),a+=l*c,c*=n[i],o=Math.floor(o/e)}i[a]=o[e]}r+=s[t]}}return new s(a,i,n)}function C(e,t=0){return S(e.map(e=>e.unsqueeze(t)),t)}function w(e,t,n=null,r=!1,i=null){let a=t.data,o=t.dims;n=x(n,o.length);let s=o.slice();s[n]=1;let c=new a.constructor(a.length/o[n]);i!==null&&c.fill(i);for(let t=0;t<a.length;++t){let r=0;for(let e=o.length-1,i=t,a=1;e>=0;--e){let t=o[e];if(e!==n){let n=i%t;r+=n*a,a*=s[e]}i=Math.floor(i/t)}c[r]=e(c[r],a[t],t,r)}return r||s.splice(n,1),[t.type,c,s]}function T(e,t=null,n=1,r=!1){let i=e.data,a=e.dims;if(t===null){let t=i.reduce((e,t)=>e+t,0)/i.length,r=Math.sqrt(i.reduce((e,n)=>e+(n-t)**2,0)/(i.length-n)),a=new s(e.type,[t],[]);return[new s(e.type,[r],[]),a]}t=x(t,a.length);let o=E(e,t,r),c=o.data,[l,u,d]=w((e,t,n,r)=>e+(t-c[r])**2,e,t,r);for(let e=0;e<u.length;++e)u[e]=Math.sqrt(u[e]/(a[t]-n));return[new s(l,u,d),o]}function E(e,t=null,n=!1){let r=e.dims,i=e.data;if(t===null){let t=i.reduce((e,t)=>e+t,0);return new s(e.type,[t/i.length],[])}t=x(t,r.length);let[a,o,c]=w((e,t)=>e+t,e,t,n);if(r[t]!==1)for(let e=0;e<o.length;++e)o[e]/=r[t];return new s(a,o,c)}function D(e){let t=Array(e.length);for(let n=e.length-1,r=1;n>=0;--n)t[n]=r,r*=e[n];return t}function O(e,t,n,r){return new s(n,new r(e.reduce((e,t)=>e*t,1)).fill(t),e)}function k(e,t){let n,r;if(typeof t==`number`)n=`float32`,r=Float32Array;else if(typeof t==`bigint`)n=`int64`,r=BigInt64Array;else if(typeof t==`boolean`)n=`bool`,r=Uint8Array;else throw Error(`Unsupported data type: ${typeof t}`);return O(e,t,n,r)}function A(e,t){return k(e.dims,t)}function ee(e){return O(e,1n,`int64`,BigInt64Array)}function te(e){return ee(e.dims)}function ne(e){return O(e,0n,`int64`,BigInt64Array)}function j(e){return ne(e.dims)}function re(e){let t=e.reduce((e,t)=>e*t,1);return new s(`float32`,Float32Array.from({length:t},()=>Math.random()),e)}function ie(e){let t=e.reduce((e,t)=>e*t,1);function n(){let e=1-Math.random(),t=1-Math.random();return Math.sqrt(-2*Math.log(e))*Math.cos(2*Math.PI*t)}return new s(`float32`,Float32Array.from({length:t},()=>n()),e)}function ae(e,t){if(e.dims.length!==2)throw Error(`The tensor must have 2 dimensions`);if(e.dims.at(-1)%8!=0)throw Error(`The last dimension of the tensor must be a multiple of 8`);if(![`binary`,`ubinary`].includes(t))throw Error(`The precision must be either 'binary' or 'ubinary'`);let n=t===`binary`,r=n?`int8`:`uint8`,i=n?Int8Array:Uint8Array,a=e.data,o=new i(a.length/8);for(let e=0;e<a.length;++e){let t=+(a[e]>0),r=Math.floor(e/8),i=e%8;o[r]|=t<<7-i,n&&i===0&&(o[r]-=128)}return new s(r,o,[e.dims[0],e.dims[1]/8])}}),"./src/utils/video.js":((e,t,n)=>{n.r(t),n.d(t,{RawVideo:()=>o,RawVideoFrame:()=>a,load_video:()=>s});var r=n(`./src/utils/image.js`),i=n(`./src/env.js`);class a{constructor(e,t){this.image=e,this.timestamp=t}}class o{constructor(e,t){e.length>0&&e[0]instanceof r.RawImage&&(e=e.map((n,r)=>new a(n,(r+1)/(e.length+1)*t))),this.frames=e,this.duration=t}get width(){return this.frames[0].image.width}get height(){return this.frames[0].image.height}get fps(){return this.frames.length/this.duration}}async function s(e,{num_frames:t=null,fps:n=null}={}){if(!i.apis.IS_BROWSER_ENV)throw Error("`load_video` is currently only supported in browser environments.");if(t==null&&n==null)throw Error(`Either num_frames or fps must be provided.`);let s=[],c=document.createElement(`video`);if(c.crossOrigin=`anonymous`,c.muted=!0,typeof e==`string`)c.src=e;else if(e instanceof Blob)c.src=URL.createObjectURL(e);else if(e instanceof HTMLVideoElement)c.src=e.src;else throw Error(`Invalid URL or video element provided.`);if(await new Promise(e=>c.onloadedmetadata=e),c.seekable.start(0)===c.seekable.end(0)){let e=await(await fetch(c.src)).blob();c.src=URL.createObjectURL(e),await new Promise(e=>c.onloadedmetadata=e)}let l=c.duration,u,d;t==null?(d=1/n,u=Math.floor(l/d)):(u=t,d=t===1?0:l/(t-1));let f=[];for(let e=0;e<u;++e)f.push(t===1?l/2:e*d);let p=document.createElement(`canvas`);p.width=c.videoWidth,p.height=c.videoHeight;let m=p.getContext(`2d`,{willReadFrequently:!0});for(let e of f){c.currentTime=e,await new Promise(e=>{c.onseeked=e}),m.drawImage(c,0,0,p.width,p.height);let t=m.getImageData(0,0,p.width,p.height),n=new a(new r.RawImage(t.data,p.width,p.height,4),e);s.push(n)}return c.remove(),new o(s,l)}})},rf={};function af(e){var t=rf[e];if(t!==void 0)return t.exports;var n=rf[e]={exports:{}};return nf[e](n,n.exports,af),n.exports}(()=>{var e=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,t;af.t=function(n,r){if(r&1&&(n=this(n)),r&8||typeof n==`object`&&n&&(r&4&&n.__esModule||r&16&&typeof n.then==`function`))return n;var i=Object.create(null);af.r(i);var a={};t||=[null,e({}),e([]),e(e)];for(var o=r&2&&n;typeof o==`object`&&!~t.indexOf(o);o=e(o))Object.getOwnPropertyNames(o).forEach(e=>a[e]=()=>n[e]);return a.default=()=>n,af.d(i,a),i}})(),af.d=(e,t)=>{for(var n in t)af.o(t,n)&&!af.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},af.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),af.r=e=>{typeof Symbol<`u`&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),Object.defineProperty(e,`__esModule`,{value:!0})};var $={};(()=>{af.r($),af.d($,{ASTFeatureExtractor:()=>d.ASTFeatureExtractor,ASTForAudioClassification:()=>n.ASTForAudioClassification,ASTModel:()=>n.ASTModel,ASTPreTrainedModel:()=>n.ASTPreTrainedModel,AlbertForMaskedLM:()=>n.AlbertForMaskedLM,AlbertForQuestionAnswering:()=>n.AlbertForQuestionAnswering,AlbertForSequenceClassification:()=>n.AlbertForSequenceClassification,AlbertModel:()=>n.AlbertModel,AlbertPreTrainedModel:()=>n.AlbertPreTrainedModel,AlbertTokenizer:()=>r.AlbertTokenizer,ArceeForCausalLM:()=>n.ArceeForCausalLM,ArceeModel:()=>n.ArceeModel,ArceePreTrainedModel:()=>n.ArceePreTrainedModel,AudioClassificationPipeline:()=>t.AudioClassificationPipeline,AutoConfig:()=>i.AutoConfig,AutoFeatureExtractor:()=>f.AutoFeatureExtractor,AutoImageProcessor:()=>h.AutoImageProcessor,AutoModel:()=>n.AutoModel,AutoModelForAudioClassification:()=>n.AutoModelForAudioClassification,AutoModelForAudioFrameClassification:()=>n.AutoModelForAudioFrameClassification,AutoModelForAudioTextToText:()=>n.AutoModelForAudioTextToText,AutoModelForCTC:()=>n.AutoModelForCTC,AutoModelForCausalLM:()=>n.AutoModelForCausalLM,AutoModelForDepthEstimation:()=>n.AutoModelForDepthEstimation,AutoModelForDocumentQuestionAnswering:()=>n.AutoModelForDocumentQuestionAnswering,AutoModelForImageClassification:()=>n.AutoModelForImageClassification,AutoModelForImageFeatureExtraction:()=>n.AutoModelForImageFeatureExtraction,AutoModelForImageMatting:()=>n.AutoModelForImageMatting,AutoModelForImageSegmentation:()=>n.AutoModelForImageSegmentation,AutoModelForImageTextToText:()=>n.AutoModelForImageTextToText,AutoModelForImageToImage:()=>n.AutoModelForImageToImage,AutoModelForMaskGeneration:()=>n.AutoModelForMaskGeneration,AutoModelForMaskedLM:()=>n.AutoModelForMaskedLM,AutoModelForNormalEstimation:()=>n.AutoModelForNormalEstimation,AutoModelForObjectDetection:()=>n.AutoModelForObjectDetection,AutoModelForPoseEstimation:()=>n.AutoModelForPoseEstimation,AutoModelForQuestionAnswering:()=>n.AutoModelForQuestionAnswering,AutoModelForSemanticSegmentation:()=>n.AutoModelForSemanticSegmentation,AutoModelForSeq2SeqLM:()=>n.AutoModelForSeq2SeqLM,AutoModelForSequenceClassification:()=>n.AutoModelForSequenceClassification,AutoModelForSpeechSeq2Seq:()=>n.AutoModelForSpeechSeq2Seq,AutoModelForTextToSpectrogram:()=>n.AutoModelForTextToSpectrogram,AutoModelForTextToWaveform:()=>n.AutoModelForTextToWaveform,AutoModelForTokenClassification:()=>n.AutoModelForTokenClassification,AutoModelForUniversalSegmentation:()=>n.AutoModelForUniversalSegmentation,AutoModelForVision2Seq:()=>n.AutoModelForVision2Seq,AutoModelForXVector:()=>n.AutoModelForXVector,AutoModelForZeroShotObjectDetection:()=>n.AutoModelForZeroShotObjectDetection,AutoProcessor:()=>v.AutoProcessor,AutoTokenizer:()=>r.AutoTokenizer,AutomaticSpeechRecognitionPipeline:()=>t.AutomaticSpeechRecognitionPipeline,BackgroundRemovalPipeline:()=>t.BackgroundRemovalPipeline,BartForConditionalGeneration:()=>n.BartForConditionalGeneration,BartForSequenceClassification:()=>n.BartForSequenceClassification,BartModel:()=>n.BartModel,BartPretrainedModel:()=>n.BartPretrainedModel,BartTokenizer:()=>r.BartTokenizer,BaseModelOutput:()=>n.BaseModelOutput,BaseStreamer:()=>y.BaseStreamer,BeitFeatureExtractor:()=>m.BeitFeatureExtractor,BeitForImageClassification:()=>n.BeitForImageClassification,BeitModel:()=>n.BeitModel,BeitPreTrainedModel:()=>n.BeitPreTrainedModel,BertForMaskedLM:()=>n.BertForMaskedLM,BertForQuestionAnswering:()=>n.BertForQuestionAnswering,BertForSequenceClassification:()=>n.BertForSequenceClassification,BertForTokenClassification:()=>n.BertForTokenClassification,BertModel:()=>n.BertModel,BertPreTrainedModel:()=>n.BertPreTrainedModel,BertTokenizer:()=>r.BertTokenizer,BitImageProcessor:()=>m.BitImageProcessor,BlenderbotForConditionalGeneration:()=>n.BlenderbotForConditionalGeneration,BlenderbotModel:()=>n.BlenderbotModel,BlenderbotPreTrainedModel:()=>n.BlenderbotPreTrainedModel,BlenderbotSmallForConditionalGeneration:()=>n.BlenderbotSmallForConditionalGeneration,BlenderbotSmallModel:()=>n.BlenderbotSmallModel,BlenderbotSmallPreTrainedModel:()=>n.BlenderbotSmallPreTrainedModel,BlenderbotSmallTokenizer:()=>r.BlenderbotSmallTokenizer,BlenderbotTokenizer:()=>r.BlenderbotTokenizer,BloomForCausalLM:()=>n.BloomForCausalLM,BloomModel:()=>n.BloomModel,BloomPreTrainedModel:()=>n.BloomPreTrainedModel,BloomTokenizer:()=>r.BloomTokenizer,CLIPFeatureExtractor:()=>m.CLIPFeatureExtractor,CLIPImageProcessor:()=>m.CLIPImageProcessor,CLIPModel:()=>n.CLIPModel,CLIPPreTrainedModel:()=>n.CLIPPreTrainedModel,CLIPSegForImageSegmentation:()=>n.CLIPSegForImageSegmentation,CLIPSegModel:()=>n.CLIPSegModel,CLIPSegPreTrainedModel:()=>n.CLIPSegPreTrainedModel,CLIPTextModel:()=>n.CLIPTextModel,CLIPTextModelWithProjection:()=>n.CLIPTextModelWithProjection,CLIPTokenizer:()=>r.CLIPTokenizer,CLIPVisionModel:()=>n.CLIPVisionModel,CLIPVisionModelWithProjection:()=>n.CLIPVisionModelWithProjection,CamembertForMaskedLM:()=>n.CamembertForMaskedLM,CamembertForQuestionAnswering:()=>n.CamembertForQuestionAnswering,CamembertForSequenceClassification:()=>n.CamembertForSequenceClassification,CamembertForTokenClassification:()=>n.CamembertForTokenClassification,CamembertModel:()=>n.CamembertModel,CamembertPreTrainedModel:()=>n.CamembertPreTrainedModel,CamembertTokenizer:()=>r.CamembertTokenizer,CausalLMOutput:()=>n.CausalLMOutput,CausalLMOutputWithPast:()=>n.CausalLMOutputWithPast,ChineseCLIPFeatureExtractor:()=>m.ChineseCLIPFeatureExtractor,ChineseCLIPModel:()=>n.ChineseCLIPModel,ChineseCLIPPreTrainedModel:()=>n.ChineseCLIPPreTrainedModel,ClapAudioModelWithProjection:()=>n.ClapAudioModelWithProjection,ClapFeatureExtractor:()=>d.ClapFeatureExtractor,ClapModel:()=>n.ClapModel,ClapPreTrainedModel:()=>n.ClapPreTrainedModel,ClapTextModelWithProjection:()=>n.ClapTextModelWithProjection,ClassifierFreeGuidanceLogitsProcessor:()=>x.ClassifierFreeGuidanceLogitsProcessor,CodeGenForCausalLM:()=>n.CodeGenForCausalLM,CodeGenModel:()=>n.CodeGenModel,CodeGenPreTrainedModel:()=>n.CodeGenPreTrainedModel,CodeGenTokenizer:()=>r.CodeGenTokenizer,CodeLlamaTokenizer:()=>r.CodeLlamaTokenizer,CohereForCausalLM:()=>n.CohereForCausalLM,CohereModel:()=>n.CohereModel,CoherePreTrainedModel:()=>n.CoherePreTrainedModel,CohereTokenizer:()=>r.CohereTokenizer,ConvBertForMaskedLM:()=>n.ConvBertForMaskedLM,ConvBertForQuestionAnswering:()=>n.ConvBertForQuestionAnswering,ConvBertForSequenceClassification:()=>n.ConvBertForSequenceClassification,ConvBertForTokenClassification:()=>n.ConvBertForTokenClassification,ConvBertModel:()=>n.ConvBertModel,ConvBertPreTrainedModel:()=>n.ConvBertPreTrainedModel,ConvBertTokenizer:()=>r.ConvBertTokenizer,ConvNextFeatureExtractor:()=>m.ConvNextFeatureExtractor,ConvNextForImageClassification:()=>n.ConvNextForImageClassification,ConvNextImageProcessor:()=>m.ConvNextImageProcessor,ConvNextModel:()=>n.ConvNextModel,ConvNextPreTrainedModel:()=>n.ConvNextPreTrainedModel,ConvNextV2ForImageClassification:()=>n.ConvNextV2ForImageClassification,ConvNextV2Model:()=>n.ConvNextV2Model,ConvNextV2PreTrainedModel:()=>n.ConvNextV2PreTrainedModel,DFineForObjectDetection:()=>n.DFineForObjectDetection,DFineModel:()=>n.DFineModel,DFinePreTrainedModel:()=>n.DFinePreTrainedModel,DINOv3ConvNextModel:()=>n.DINOv3ConvNextModel,DINOv3ConvNextPreTrainedModel:()=>n.DINOv3ConvNextPreTrainedModel,DINOv3ViTImageProcessor:()=>m.DINOv3ViTImageProcessor,DINOv3ViTModel:()=>n.DINOv3ViTModel,DINOv3ViTPreTrainedModel:()=>n.DINOv3ViTPreTrainedModel,DPTFeatureExtractor:()=>m.DPTFeatureExtractor,DPTForDepthEstimation:()=>n.DPTForDepthEstimation,DPTImageProcessor:()=>m.DPTImageProcessor,DPTModel:()=>n.DPTModel,DPTPreTrainedModel:()=>n.DPTPreTrainedModel,DacDecoderModel:()=>n.DacDecoderModel,DacDecoderOutput:()=>n.DacDecoderOutput,DacEncoderModel:()=>n.DacEncoderModel,DacEncoderOutput:()=>n.DacEncoderOutput,DacFeatureExtractor:()=>d.DacFeatureExtractor,DacModel:()=>n.DacModel,DacPreTrainedModel:()=>n.DacPreTrainedModel,DataTypeMap:()=>c.DataTypeMap,DebertaForMaskedLM:()=>n.DebertaForMaskedLM,DebertaForQuestionAnswering:()=>n.DebertaForQuestionAnswering,DebertaForSequenceClassification:()=>n.DebertaForSequenceClassification,DebertaForTokenClassification:()=>n.DebertaForTokenClassification,DebertaModel:()=>n.DebertaModel,DebertaPreTrainedModel:()=>n.DebertaPreTrainedModel,DebertaTokenizer:()=>r.DebertaTokenizer,DebertaV2ForMaskedLM:()=>n.DebertaV2ForMaskedLM,DebertaV2ForQuestionAnswering:()=>n.DebertaV2ForQuestionAnswering,DebertaV2ForSequenceClassification:()=>n.DebertaV2ForSequenceClassification,DebertaV2ForTokenClassification:()=>n.DebertaV2ForTokenClassification,DebertaV2Model:()=>n.DebertaV2Model,DebertaV2PreTrainedModel:()=>n.DebertaV2PreTrainedModel,DebertaV2Tokenizer:()=>r.DebertaV2Tokenizer,DecisionTransformerModel:()=>n.DecisionTransformerModel,DecisionTransformerPreTrainedModel:()=>n.DecisionTransformerPreTrainedModel,DeiTFeatureExtractor:()=>m.DeiTFeatureExtractor,DeiTForImageClassification:()=>n.DeiTForImageClassification,DeiTImageProcessor:()=>m.DeiTImageProcessor,DeiTModel:()=>n.DeiTModel,DeiTPreTrainedModel:()=>n.DeiTPreTrainedModel,DepthAnythingForDepthEstimation:()=>n.DepthAnythingForDepthEstimation,DepthAnythingPreTrainedModel:()=>n.DepthAnythingPreTrainedModel,DepthEstimationPipeline:()=>t.DepthEstimationPipeline,DepthProForDepthEstimation:()=>n.DepthProForDepthEstimation,DepthProPreTrainedModel:()=>n.DepthProPreTrainedModel,DetrFeatureExtractor:()=>m.DetrFeatureExtractor,DetrForObjectDetection:()=>n.DetrForObjectDetection,DetrForSegmentation:()=>n.DetrForSegmentation,DetrImageProcessor:()=>m.DetrImageProcessor,DetrModel:()=>n.DetrModel,DetrObjectDetectionOutput:()=>n.DetrObjectDetectionOutput,DetrPreTrainedModel:()=>n.DetrPreTrainedModel,DetrSegmentationOutput:()=>n.DetrSegmentationOutput,Dinov2ForImageClassification:()=>n.Dinov2ForImageClassification,Dinov2Model:()=>n.Dinov2Model,Dinov2PreTrainedModel:()=>n.Dinov2PreTrainedModel,Dinov2WithRegistersForImageClassification:()=>n.Dinov2WithRegistersForImageClassification,Dinov2WithRegistersModel:()=>n.Dinov2WithRegistersModel,Dinov2WithRegistersPreTrainedModel:()=>n.Dinov2WithRegistersPreTrainedModel,DistilBertForMaskedLM:()=>n.DistilBertForMaskedLM,DistilBertForQuestionAnswering:()=>n.DistilBertForQuestionAnswering,DistilBertForSequenceClassification:()=>n.DistilBertForSequenceClassification,DistilBertForTokenClassification:()=>n.DistilBertForTokenClassification,DistilBertModel:()=>n.DistilBertModel,DistilBertPreTrainedModel:()=>n.DistilBertPreTrainedModel,DistilBertTokenizer:()=>r.DistilBertTokenizer,DocumentQuestionAnsweringPipeline:()=>t.DocumentQuestionAnsweringPipeline,DonutFeatureExtractor:()=>m.DonutFeatureExtractor,DonutImageProcessor:()=>m.DonutImageProcessor,DonutSwinModel:()=>n.DonutSwinModel,DonutSwinPreTrainedModel:()=>n.DonutSwinPreTrainedModel,EdgeTamModel:()=>n.EdgeTamModel,EfficientNetForImageClassification:()=>n.EfficientNetForImageClassification,EfficientNetImageProcessor:()=>m.EfficientNetImageProcessor,EfficientNetModel:()=>n.EfficientNetModel,EfficientNetPreTrainedModel:()=>n.EfficientNetPreTrainedModel,ElectraForMaskedLM:()=>n.ElectraForMaskedLM,ElectraForQuestionAnswering:()=>n.ElectraForQuestionAnswering,ElectraForSequenceClassification:()=>n.ElectraForSequenceClassification,ElectraForTokenClassification:()=>n.ElectraForTokenClassification,ElectraModel:()=>n.ElectraModel,ElectraPreTrainedModel:()=>n.ElectraPreTrainedModel,ElectraTokenizer:()=>r.ElectraTokenizer,EncodecFeatureExtractor:()=>d.EncodecFeatureExtractor,EosTokenCriteria:()=>b.EosTokenCriteria,Ernie4_5ForCausalLM:()=>n.Ernie4_5ForCausalLM,Ernie4_5Model:()=>n.Ernie4_5Model,Ernie4_5PreTrainedModel:()=>n.Ernie4_5PreTrainedModel,EsmForMaskedLM:()=>n.EsmForMaskedLM,EsmForSequenceClassification:()=>n.EsmForSequenceClassification,EsmForTokenClassification:()=>n.EsmForTokenClassification,EsmModel:()=>n.EsmModel,EsmPreTrainedModel:()=>n.EsmPreTrainedModel,EsmTokenizer:()=>r.EsmTokenizer,ExaoneForCausalLM:()=>n.ExaoneForCausalLM,ExaoneModel:()=>n.ExaoneModel,ExaonePreTrainedModel:()=>n.ExaonePreTrainedModel,FFT:()=>l.FFT,FalconForCausalLM:()=>n.FalconForCausalLM,FalconModel:()=>n.FalconModel,FalconPreTrainedModel:()=>n.FalconPreTrainedModel,FalconTokenizer:()=>r.FalconTokenizer,FastViTForImageClassification:()=>n.FastViTForImageClassification,FastViTModel:()=>n.FastViTModel,FastViTPreTrainedModel:()=>n.FastViTPreTrainedModel,FeatureExtractionPipeline:()=>t.FeatureExtractionPipeline,FeatureExtractor:()=>u.FeatureExtractor,FillMaskPipeline:()=>t.FillMaskPipeline,Florence2ForConditionalGeneration:()=>n.Florence2ForConditionalGeneration,Florence2PreTrainedModel:()=>n.Florence2PreTrainedModel,Florence2Processor:()=>_.Florence2Processor,ForcedBOSTokenLogitsProcessor:()=>x.ForcedBOSTokenLogitsProcessor,ForcedEOSTokenLogitsProcessor:()=>x.ForcedEOSTokenLogitsProcessor,GLPNFeatureExtractor:()=>m.GLPNFeatureExtractor,GLPNForDepthEstimation:()=>n.GLPNForDepthEstimation,GLPNModel:()=>n.GLPNModel,GLPNPreTrainedModel:()=>n.GLPNPreTrainedModel,GPT2LMHeadModel:()=>n.GPT2LMHeadModel,GPT2Model:()=>n.GPT2Model,GPT2PreTrainedModel:()=>n.GPT2PreTrainedModel,GPT2Tokenizer:()=>r.GPT2Tokenizer,GPTBigCodeForCausalLM:()=>n.GPTBigCodeForCausalLM,GPTBigCodeModel:()=>n.GPTBigCodeModel,GPTBigCodePreTrainedModel:()=>n.GPTBigCodePreTrainedModel,GPTJForCausalLM:()=>n.GPTJForCausalLM,GPTJModel:()=>n.GPTJModel,GPTJPreTrainedModel:()=>n.GPTJPreTrainedModel,GPTNeoForCausalLM:()=>n.GPTNeoForCausalLM,GPTNeoModel:()=>n.GPTNeoModel,GPTNeoPreTrainedModel:()=>n.GPTNeoPreTrainedModel,GPTNeoXForCausalLM:()=>n.GPTNeoXForCausalLM,GPTNeoXModel:()=>n.GPTNeoXModel,GPTNeoXPreTrainedModel:()=>n.GPTNeoXPreTrainedModel,GPTNeoXTokenizer:()=>r.GPTNeoXTokenizer,Gemma2ForCausalLM:()=>n.Gemma2ForCausalLM,Gemma2Model:()=>n.Gemma2Model,Gemma2PreTrainedModel:()=>n.Gemma2PreTrainedModel,Gemma3ForCausalLM:()=>n.Gemma3ForCausalLM,Gemma3Model:()=>n.Gemma3Model,Gemma3PreTrainedModel:()=>n.Gemma3PreTrainedModel,Gemma3nAudioFeatureExtractor:()=>d.Gemma3nAudioFeatureExtractor,Gemma3nForConditionalGeneration:()=>n.Gemma3nForConditionalGeneration,Gemma3nPreTrainedModel:()=>n.Gemma3nPreTrainedModel,Gemma3nProcessor:()=>_.Gemma3nProcessor,GemmaForCausalLM:()=>n.GemmaForCausalLM,GemmaModel:()=>n.GemmaModel,GemmaPreTrainedModel:()=>n.GemmaPreTrainedModel,GemmaTokenizer:()=>r.GemmaTokenizer,GlmForCausalLM:()=>n.GlmForCausalLM,GlmModel:()=>n.GlmModel,GlmPreTrainedModel:()=>n.GlmPreTrainedModel,GraniteForCausalLM:()=>n.GraniteForCausalLM,GraniteModel:()=>n.GraniteModel,GraniteMoeHybridForCausalLM:()=>n.GraniteMoeHybridForCausalLM,GraniteMoeHybridModel:()=>n.GraniteMoeHybridModel,GraniteMoeHybridPreTrainedModel:()=>n.GraniteMoeHybridPreTrainedModel,GranitePreTrainedModel:()=>n.GranitePreTrainedModel,Grok1Tokenizer:()=>r.Grok1Tokenizer,GroundingDinoForObjectDetection:()=>n.GroundingDinoForObjectDetection,GroundingDinoImageProcessor:()=>m.GroundingDinoImageProcessor,GroundingDinoPreTrainedModel:()=>n.GroundingDinoPreTrainedModel,GroundingDinoProcessor:()=>_.GroundingDinoProcessor,GroupViTModel:()=>n.GroupViTModel,GroupViTPreTrainedModel:()=>n.GroupViTPreTrainedModel,HeliumForCausalLM:()=>n.HeliumForCausalLM,HeliumModel:()=>n.HeliumModel,HeliumPreTrainedModel:()=>n.HeliumPreTrainedModel,HerbertTokenizer:()=>r.HerbertTokenizer,HieraForImageClassification:()=>n.HieraForImageClassification,HieraModel:()=>n.HieraModel,HieraPreTrainedModel:()=>n.HieraPreTrainedModel,HubertForCTC:()=>n.HubertForCTC,HubertForSequenceClassification:()=>n.HubertForSequenceClassification,HubertModel:()=>n.HubertModel,HubertPreTrainedModel:()=>n.HubertPreTrainedModel,IJepaForImageClassification:()=>n.IJepaForImageClassification,IJepaModel:()=>n.IJepaModel,IJepaPreTrainedModel:()=>n.IJepaPreTrainedModel,Idefics3ForConditionalGeneration:()=>n.Idefics3ForConditionalGeneration,Idefics3ImageProcessor:()=>m.Idefics3ImageProcessor,Idefics3PreTrainedModel:()=>n.Idefics3PreTrainedModel,Idefics3Processor:()=>_.Idefics3Processor,ImageClassificationPipeline:()=>t.ImageClassificationPipeline,ImageFeatureExtractionPipeline:()=>t.ImageFeatureExtractionPipeline,ImageFeatureExtractor:()=>d.ImageFeatureExtractor,ImageMattingOutput:()=>n.ImageMattingOutput,ImageProcessor:()=>p.ImageProcessor,ImageSegmentationPipeline:()=>t.ImageSegmentationPipeline,ImageToImagePipeline:()=>t.ImageToImagePipeline,ImageToTextPipeline:()=>t.ImageToTextPipeline,InterruptableStoppingCriteria:()=>b.InterruptableStoppingCriteria,JAISLMHeadModel:()=>n.JAISLMHeadModel,JAISModel:()=>n.JAISModel,JAISPreTrainedModel:()=>n.JAISPreTrainedModel,JinaCLIPImageProcessor:()=>m.JinaCLIPImageProcessor,JinaCLIPModel:()=>n.JinaCLIPModel,JinaCLIPPreTrainedModel:()=>n.JinaCLIPPreTrainedModel,JinaCLIPProcessor:()=>_.JinaCLIPProcessor,JinaCLIPTextModel:()=>n.JinaCLIPTextModel,JinaCLIPVisionModel:()=>n.JinaCLIPVisionModel,Lfm2ForCausalLM:()=>n.Lfm2ForCausalLM,Lfm2Model:()=>n.Lfm2Model,Lfm2PreTrainedModel:()=>n.Lfm2PreTrainedModel,LiteWhisperForConditionalGeneration:()=>n.LiteWhisperForConditionalGeneration,Llama4ForCausalLM:()=>n.Llama4ForCausalLM,Llama4PreTrainedModel:()=>n.Llama4PreTrainedModel,LlamaForCausalLM:()=>n.LlamaForCausalLM,LlamaModel:()=>n.LlamaModel,LlamaPreTrainedModel:()=>n.LlamaPreTrainedModel,LlamaTokenizer:()=>r.LlamaTokenizer,LlavaForConditionalGeneration:()=>n.LlavaForConditionalGeneration,LlavaOnevisionForConditionalGeneration:()=>n.LlavaOnevisionForConditionalGeneration,LlavaOnevisionImageProcessor:()=>m.LlavaOnevisionImageProcessor,LlavaPreTrainedModel:()=>n.LlavaPreTrainedModel,LlavaProcessor:()=>_.LlavaProcessor,LlavaQwen2ForCausalLM:()=>n.LlavaQwen2ForCausalLM,LogitsProcessor:()=>x.LogitsProcessor,LogitsProcessorList:()=>x.LogitsProcessorList,LogitsWarper:()=>x.LogitsWarper,LongT5ForConditionalGeneration:()=>n.LongT5ForConditionalGeneration,LongT5Model:()=>n.LongT5Model,LongT5PreTrainedModel:()=>n.LongT5PreTrainedModel,M2M100ForConditionalGeneration:()=>n.M2M100ForConditionalGeneration,M2M100Model:()=>n.M2M100Model,M2M100PreTrainedModel:()=>n.M2M100PreTrainedModel,M2M100Tokenizer:()=>r.M2M100Tokenizer,MBart50Tokenizer:()=>r.MBart50Tokenizer,MBartForCausalLM:()=>n.MBartForCausalLM,MBartForConditionalGeneration:()=>n.MBartForConditionalGeneration,MBartForSequenceClassification:()=>n.MBartForSequenceClassification,MBartModel:()=>n.MBartModel,MBartPreTrainedModel:()=>n.MBartPreTrainedModel,MBartTokenizer:()=>r.MBartTokenizer,MPNetForMaskedLM:()=>n.MPNetForMaskedLM,MPNetForQuestionAnswering:()=>n.MPNetForQuestionAnswering,MPNetForSequenceClassification:()=>n.MPNetForSequenceClassification,MPNetForTokenClassification:()=>n.MPNetForTokenClassification,MPNetModel:()=>n.MPNetModel,MPNetPreTrainedModel:()=>n.MPNetPreTrainedModel,MPNetTokenizer:()=>r.MPNetTokenizer,MT5ForConditionalGeneration:()=>n.MT5ForConditionalGeneration,MT5Model:()=>n.MT5Model,MT5PreTrainedModel:()=>n.MT5PreTrainedModel,MarianMTModel:()=>n.MarianMTModel,MarianModel:()=>n.MarianModel,MarianPreTrainedModel:()=>n.MarianPreTrainedModel,MarianTokenizer:()=>r.MarianTokenizer,Mask2FormerImageProcessor:()=>m.Mask2FormerImageProcessor,MaskFormerFeatureExtractor:()=>m.MaskFormerFeatureExtractor,MaskFormerForInstanceSegmentation:()=>n.MaskFormerForInstanceSegmentation,MaskFormerImageProcessor:()=>m.MaskFormerImageProcessor,MaskFormerModel:()=>n.MaskFormerModel,MaskFormerPreTrainedModel:()=>n.MaskFormerPreTrainedModel,MaskedLMOutput:()=>n.MaskedLMOutput,MaxLengthCriteria:()=>b.MaxLengthCriteria,Metric3DForDepthEstimation:()=>n.Metric3DForDepthEstimation,Metric3DPreTrainedModel:()=>n.Metric3DPreTrainedModel,Metric3Dv2ForDepthEstimation:()=>n.Metric3Dv2ForDepthEstimation,Metric3Dv2PreTrainedModel:()=>n.Metric3Dv2PreTrainedModel,MgpstrForSceneTextRecognition:()=>n.MgpstrForSceneTextRecognition,MgpstrModelOutput:()=>n.MgpstrModelOutput,MgpstrPreTrainedModel:()=>n.MgpstrPreTrainedModel,MgpstrProcessor:()=>_.MgpstrProcessor,MgpstrTokenizer:()=>r.MgpstrTokenizer,MimiDecoderModel:()=>n.MimiDecoderModel,MimiDecoderOutput:()=>n.MimiDecoderOutput,MimiEncoderModel:()=>n.MimiEncoderModel,MimiEncoderOutput:()=>n.MimiEncoderOutput,MimiModel:()=>n.MimiModel,MimiPreTrainedModel:()=>n.MimiPreTrainedModel,MinLengthLogitsProcessor:()=>x.MinLengthLogitsProcessor,MinNewTokensLengthLogitsProcessor:()=>x.MinNewTokensLengthLogitsProcessor,Ministral3ForCausalLM:()=>n.Ministral3ForCausalLM,Ministral3Model:()=>n.Ministral3Model,Ministral3PreTrainedModel:()=>n.Ministral3PreTrainedModel,MinistralForCausalLM:()=>n.MinistralForCausalLM,MinistralModel:()=>n.MinistralModel,MinistralPreTrainedModel:()=>n.MinistralPreTrainedModel,Mistral3ForConditionalGeneration:()=>n.Mistral3ForConditionalGeneration,MistralForCausalLM:()=>n.MistralForCausalLM,MistralModel:()=>n.MistralModel,MistralPreTrainedModel:()=>n.MistralPreTrainedModel,MobileBertForMaskedLM:()=>n.MobileBertForMaskedLM,MobileBertForQuestionAnswering:()=>n.MobileBertForQuestionAnswering,MobileBertForSequenceClassification:()=>n.MobileBertForSequenceClassification,MobileBertModel:()=>n.MobileBertModel,MobileBertPreTrainedModel:()=>n.MobileBertPreTrainedModel,MobileBertTokenizer:()=>r.MobileBertTokenizer,MobileLLMForCausalLM:()=>n.MobileLLMForCausalLM,MobileLLMModel:()=>n.MobileLLMModel,MobileLLMPreTrainedModel:()=>n.MobileLLMPreTrainedModel,MobileNetV1FeatureExtractor:()=>m.MobileNetV1FeatureExtractor,MobileNetV1ForImageClassification:()=>n.MobileNetV1ForImageClassification,MobileNetV1ForSemanticSegmentation:()=>n.MobileNetV1ForSemanticSegmentation,MobileNetV1ImageProcessor:()=>m.MobileNetV1ImageProcessor,MobileNetV1Model:()=>n.MobileNetV1Model,MobileNetV1PreTrainedModel:()=>n.MobileNetV1PreTrainedModel,MobileNetV2FeatureExtractor:()=>m.MobileNetV2FeatureExtractor,MobileNetV2ForImageClassification:()=>n.MobileNetV2ForImageClassification,MobileNetV2ForSemanticSegmentation:()=>n.MobileNetV2ForSemanticSegmentation,MobileNetV2ImageProcessor:()=>m.MobileNetV2ImageProcessor,MobileNetV2Model:()=>n.MobileNetV2Model,MobileNetV2PreTrainedModel:()=>n.MobileNetV2PreTrainedModel,MobileNetV3FeatureExtractor:()=>m.MobileNetV3FeatureExtractor,MobileNetV3ForImageClassification:()=>n.MobileNetV3ForImageClassification,MobileNetV3ForSemanticSegmentation:()=>n.MobileNetV3ForSemanticSegmentation,MobileNetV3ImageProcessor:()=>m.MobileNetV3ImageProcessor,MobileNetV3Model:()=>n.MobileNetV3Model,MobileNetV3PreTrainedModel:()=>n.MobileNetV3PreTrainedModel,MobileNetV4FeatureExtractor:()=>m.MobileNetV4FeatureExtractor,MobileNetV4ForImageClassification:()=>n.MobileNetV4ForImageClassification,MobileNetV4ForSemanticSegmentation:()=>n.MobileNetV4ForSemanticSegmentation,MobileNetV4ImageProcessor:()=>m.MobileNetV4ImageProcessor,MobileNetV4Model:()=>n.MobileNetV4Model,MobileNetV4PreTrainedModel:()=>n.MobileNetV4PreTrainedModel,MobileViTFeatureExtractor:()=>m.MobileViTFeatureExtractor,MobileViTForImageClassification:()=>n.MobileViTForImageClassification,MobileViTImageProcessor:()=>m.MobileViTImageProcessor,MobileViTModel:()=>n.MobileViTModel,MobileViTPreTrainedModel:()=>n.MobileViTPreTrainedModel,MobileViTV2ForImageClassification:()=>n.MobileViTV2ForImageClassification,MobileViTV2Model:()=>n.MobileViTV2Model,MobileViTV2PreTrainedModel:()=>n.MobileViTV2PreTrainedModel,ModelOutput:()=>n.ModelOutput,ModernBertDecoderForCausalLM:()=>n.ModernBertDecoderForCausalLM,ModernBertDecoderModel:()=>n.ModernBertDecoderModel,ModernBertDecoderPreTrainedModel:()=>n.ModernBertDecoderPreTrainedModel,ModernBertForMaskedLM:()=>n.ModernBertForMaskedLM,ModernBertForSequenceClassification:()=>n.ModernBertForSequenceClassification,ModernBertForTokenClassification:()=>n.ModernBertForTokenClassification,ModernBertModel:()=>n.ModernBertModel,ModernBertPreTrainedModel:()=>n.ModernBertPreTrainedModel,Moondream1ForConditionalGeneration:()=>n.Moondream1ForConditionalGeneration,MoonshineFeatureExtractor:()=>d.MoonshineFeatureExtractor,MoonshineForConditionalGeneration:()=>n.MoonshineForConditionalGeneration,MoonshineModel:()=>n.MoonshineModel,MoonshinePreTrainedModel:()=>n.MoonshinePreTrainedModel,MoonshineProcessor:()=>_.MoonshineProcessor,MptForCausalLM:()=>n.MptForCausalLM,MptModel:()=>n.MptModel,MptPreTrainedModel:()=>n.MptPreTrainedModel,MultiModalityCausalLM:()=>n.MultiModalityCausalLM,MultiModalityPreTrainedModel:()=>n.MultiModalityPreTrainedModel,MusicgenForCausalLM:()=>n.MusicgenForCausalLM,MusicgenForConditionalGeneration:()=>n.MusicgenForConditionalGeneration,MusicgenModel:()=>n.MusicgenModel,MusicgenPreTrainedModel:()=>n.MusicgenPreTrainedModel,NanoChatForCausalLM:()=>n.NanoChatForCausalLM,NanoChatModel:()=>n.NanoChatModel,NanoChatPreTrainedModel:()=>n.NanoChatPreTrainedModel,NeoBertForMaskedLM:()=>n.NeoBertForMaskedLM,NeoBertForQuestionAnswering:()=>n.NeoBertForQuestionAnswering,NeoBertForSequenceClassification:()=>n.NeoBertForSequenceClassification,NeoBertForTokenClassification:()=>n.NeoBertForTokenClassification,NeoBertModel:()=>n.NeoBertModel,NeoBertPreTrainedModel:()=>n.NeoBertPreTrainedModel,NllbTokenizer:()=>r.NllbTokenizer,NoBadWordsLogitsProcessor:()=>x.NoBadWordsLogitsProcessor,NoRepeatNGramLogitsProcessor:()=>x.NoRepeatNGramLogitsProcessor,NomicBertModel:()=>n.NomicBertModel,NomicBertPreTrainedModel:()=>n.NomicBertPreTrainedModel,NougatImageProcessor:()=>m.NougatImageProcessor,NougatTokenizer:()=>r.NougatTokenizer,OPTForCausalLM:()=>n.OPTForCausalLM,OPTModel:()=>n.OPTModel,OPTPreTrainedModel:()=>n.OPTPreTrainedModel,ObjectDetectionPipeline:()=>t.ObjectDetectionPipeline,Olmo2ForCausalLM:()=>n.Olmo2ForCausalLM,Olmo2Model:()=>n.Olmo2Model,Olmo2PreTrainedModel:()=>n.Olmo2PreTrainedModel,OlmoForCausalLM:()=>n.OlmoForCausalLM,OlmoModel:()=>n.OlmoModel,OlmoPreTrainedModel:()=>n.OlmoPreTrainedModel,OpenELMForCausalLM:()=>n.OpenELMForCausalLM,OpenELMModel:()=>n.OpenELMModel,OpenELMPreTrainedModel:()=>n.OpenELMPreTrainedModel,OwlViTFeatureExtractor:()=>m.OwlViTFeatureExtractor,OwlViTForObjectDetection:()=>n.OwlViTForObjectDetection,OwlViTImageProcessor:()=>m.OwlViTImageProcessor,OwlViTModel:()=>n.OwlViTModel,OwlViTPreTrainedModel:()=>n.OwlViTPreTrainedModel,OwlViTProcessor:()=>_.OwlViTProcessor,Owlv2ForObjectDetection:()=>n.Owlv2ForObjectDetection,Owlv2ImageProcessor:()=>m.Owlv2ImageProcessor,Owlv2Model:()=>n.Owlv2Model,Owlv2PreTrainedModel:()=>n.Owlv2PreTrainedModel,PaliGemmaForConditionalGeneration:()=>n.PaliGemmaForConditionalGeneration,PaliGemmaPreTrainedModel:()=>n.PaliGemmaPreTrainedModel,PaliGemmaProcessor:()=>_.PaliGemmaProcessor,ParakeetFeatureExtractor:()=>d.ParakeetFeatureExtractor,ParakeetForCTC:()=>n.ParakeetForCTC,ParakeetPreTrainedModel:()=>n.ParakeetPreTrainedModel,PatchTSMixerForPrediction:()=>n.PatchTSMixerForPrediction,PatchTSMixerModel:()=>n.PatchTSMixerModel,PatchTSMixerPreTrainedModel:()=>n.PatchTSMixerPreTrainedModel,PatchTSTForPrediction:()=>n.PatchTSTForPrediction,PatchTSTModel:()=>n.PatchTSTModel,PatchTSTPreTrainedModel:()=>n.PatchTSTPreTrainedModel,Phi3ForCausalLM:()=>n.Phi3ForCausalLM,Phi3Model:()=>n.Phi3Model,Phi3PreTrainedModel:()=>n.Phi3PreTrainedModel,Phi3VForCausalLM:()=>n.Phi3VForCausalLM,Phi3VImageProcessor:()=>m.Phi3VImageProcessor,Phi3VPreTrainedModel:()=>n.Phi3VPreTrainedModel,Phi3VProcessor:()=>_.Phi3VProcessor,PhiForCausalLM:()=>n.PhiForCausalLM,PhiModel:()=>n.PhiModel,PhiPreTrainedModel:()=>n.PhiPreTrainedModel,Pipeline:()=>t.Pipeline,PixtralImageProcessor:()=>m.PixtralImageProcessor,PixtralProcessor:()=>_.PixtralProcessor,PreTrainedModel:()=>n.PreTrainedModel,PreTrainedTokenizer:()=>r.PreTrainedTokenizer,PretrainedConfig:()=>i.PretrainedConfig,PretrainedMixin:()=>n.PretrainedMixin,Processor:()=>g.Processor,PvtForImageClassification:()=>n.PvtForImageClassification,PvtImageProcessor:()=>m.PvtImageProcessor,PvtModel:()=>n.PvtModel,PvtPreTrainedModel:()=>n.PvtPreTrainedModel,PyAnnoteFeatureExtractor:()=>d.PyAnnoteFeatureExtractor,PyAnnoteForAudioFrameClassification:()=>n.PyAnnoteForAudioFrameClassification,PyAnnoteModel:()=>n.PyAnnoteModel,PyAnnotePreTrainedModel:()=>n.PyAnnotePreTrainedModel,PyAnnoteProcessor:()=>_.PyAnnoteProcessor,QuestionAnsweringModelOutput:()=>n.QuestionAnsweringModelOutput,QuestionAnsweringPipeline:()=>t.QuestionAnsweringPipeline,Qwen2ForCausalLM:()=>n.Qwen2ForCausalLM,Qwen2Model:()=>n.Qwen2Model,Qwen2PreTrainedModel:()=>n.Qwen2PreTrainedModel,Qwen2Tokenizer:()=>r.Qwen2Tokenizer,Qwen2VLForConditionalGeneration:()=>n.Qwen2VLForConditionalGeneration,Qwen2VLImageProcessor:()=>m.Qwen2VLImageProcessor,Qwen2VLPreTrainedModel:()=>n.Qwen2VLPreTrainedModel,Qwen2VLProcessor:()=>_.Qwen2VLProcessor,Qwen3ForCausalLM:()=>n.Qwen3ForCausalLM,Qwen3Model:()=>n.Qwen3Model,Qwen3PreTrainedModel:()=>n.Qwen3PreTrainedModel,RFDetrForObjectDetection:()=>n.RFDetrForObjectDetection,RFDetrModel:()=>n.RFDetrModel,RFDetrObjectDetectionOutput:()=>n.RFDetrObjectDetectionOutput,RFDetrPreTrainedModel:()=>n.RFDetrPreTrainedModel,RTDetrForObjectDetection:()=>n.RTDetrForObjectDetection,RTDetrImageProcessor:()=>m.RTDetrImageProcessor,RTDetrModel:()=>n.RTDetrModel,RTDetrObjectDetectionOutput:()=>n.RTDetrObjectDetectionOutput,RTDetrPreTrainedModel:()=>n.RTDetrPreTrainedModel,RTDetrV2ForObjectDetection:()=>n.RTDetrV2ForObjectDetection,RTDetrV2Model:()=>n.RTDetrV2Model,RTDetrV2ObjectDetectionOutput:()=>n.RTDetrV2ObjectDetectionOutput,RTDetrV2PreTrainedModel:()=>n.RTDetrV2PreTrainedModel,RawAudio:()=>a.RawAudio,RawImage:()=>o.RawImage,RawVideo:()=>s.RawVideo,RawVideoFrame:()=>s.RawVideoFrame,RepetitionPenaltyLogitsProcessor:()=>x.RepetitionPenaltyLogitsProcessor,ResNetForImageClassification:()=>n.ResNetForImageClassification,ResNetModel:()=>n.ResNetModel,ResNetPreTrainedModel:()=>n.ResNetPreTrainedModel,RoFormerForMaskedLM:()=>n.RoFormerForMaskedLM,RoFormerForQuestionAnswering:()=>n.RoFormerForQuestionAnswering,RoFormerForSequenceClassification:()=>n.RoFormerForSequenceClassification,RoFormerForTokenClassification:()=>n.RoFormerForTokenClassification,RoFormerModel:()=>n.RoFormerModel,RoFormerPreTrainedModel:()=>n.RoFormerPreTrainedModel,RoFormerTokenizer:()=>r.RoFormerTokenizer,RobertaForMaskedLM:()=>n.RobertaForMaskedLM,RobertaForQuestionAnswering:()=>n.RobertaForQuestionAnswering,RobertaForSequenceClassification:()=>n.RobertaForSequenceClassification,RobertaForTokenClassification:()=>n.RobertaForTokenClassification,RobertaModel:()=>n.RobertaModel,RobertaPreTrainedModel:()=>n.RobertaPreTrainedModel,RobertaTokenizer:()=>r.RobertaTokenizer,Sam2ImageProcessor:()=>m.Sam2ImageProcessor,Sam2ImageSegmentationOutput:()=>n.Sam2ImageSegmentationOutput,Sam2Model:()=>n.Sam2Model,Sam2PreTrainedModel:()=>n.Sam2PreTrainedModel,Sam2Processor:()=>_.Sam2Processor,Sam2VideoProcessor:()=>_.Sam2VideoProcessor,Sam3ImageProcessor:()=>m.Sam3ImageProcessor,Sam3TrackerModel:()=>n.Sam3TrackerModel,SamImageProcessor:()=>m.SamImageProcessor,SamImageSegmentationOutput:()=>n.SamImageSegmentationOutput,SamModel:()=>n.SamModel,SamPreTrainedModel:()=>n.SamPreTrainedModel,SamProcessor:()=>_.SamProcessor,SapiensForDepthEstimation:()=>n.SapiensForDepthEstimation,SapiensForNormalEstimation:()=>n.SapiensForNormalEstimation,SapiensForSemanticSegmentation:()=>n.SapiensForSemanticSegmentation,SapiensPreTrainedModel:()=>n.SapiensPreTrainedModel,SeamlessM4TFeatureExtractor:()=>d.SeamlessM4TFeatureExtractor,SegformerFeatureExtractor:()=>m.SegformerFeatureExtractor,SegformerForImageClassification:()=>n.SegformerForImageClassification,SegformerForSemanticSegmentation:()=>n.SegformerForSemanticSegmentation,SegformerImageProcessor:()=>m.SegformerImageProcessor,SegformerModel:()=>n.SegformerModel,SegformerPreTrainedModel:()=>n.SegformerPreTrainedModel,Seq2SeqLMOutput:()=>n.Seq2SeqLMOutput,SequenceClassifierOutput:()=>n.SequenceClassifierOutput,SiglipImageProcessor:()=>m.SiglipImageProcessor,SiglipModel:()=>n.SiglipModel,SiglipPreTrainedModel:()=>n.SiglipPreTrainedModel,SiglipTextModel:()=>n.SiglipTextModel,SiglipTokenizer:()=>r.SiglipTokenizer,SiglipVisionModel:()=>n.SiglipVisionModel,SmolLM3ForCausalLM:()=>n.SmolLM3ForCausalLM,SmolLM3Model:()=>n.SmolLM3Model,SmolLM3PreTrainedModel:()=>n.SmolLM3PreTrainedModel,SmolVLMForConditionalGeneration:()=>n.SmolVLMForConditionalGeneration,SmolVLMImageProcessor:()=>m.SmolVLMImageProcessor,SmolVLMProcessor:()=>_.SmolVLMProcessor,SnacDecoderModel:()=>n.SnacDecoderModel,SnacEncoderModel:()=>n.SnacEncoderModel,SnacFeatureExtractor:()=>d.SnacFeatureExtractor,SnacModel:()=>n.SnacModel,SnacPreTrainedModel:()=>n.SnacPreTrainedModel,SpeechT5FeatureExtractor:()=>d.SpeechT5FeatureExtractor,SpeechT5ForSpeechToText:()=>n.SpeechT5ForSpeechToText,SpeechT5ForTextToSpeech:()=>n.SpeechT5ForTextToSpeech,SpeechT5HifiGan:()=>n.SpeechT5HifiGan,SpeechT5Model:()=>n.SpeechT5Model,SpeechT5PreTrainedModel:()=>n.SpeechT5PreTrainedModel,SpeechT5Processor:()=>_.SpeechT5Processor,SpeechT5Tokenizer:()=>r.SpeechT5Tokenizer,SqueezeBertForMaskedLM:()=>n.SqueezeBertForMaskedLM,SqueezeBertForQuestionAnswering:()=>n.SqueezeBertForQuestionAnswering,SqueezeBertForSequenceClassification:()=>n.SqueezeBertForSequenceClassification,SqueezeBertModel:()=>n.SqueezeBertModel,SqueezeBertPreTrainedModel:()=>n.SqueezeBertPreTrainedModel,SqueezeBertTokenizer:()=>r.SqueezeBertTokenizer,StableLmForCausalLM:()=>n.StableLmForCausalLM,StableLmModel:()=>n.StableLmModel,StableLmPreTrainedModel:()=>n.StableLmPreTrainedModel,Starcoder2ForCausalLM:()=>n.Starcoder2ForCausalLM,Starcoder2Model:()=>n.Starcoder2Model,Starcoder2PreTrainedModel:()=>n.Starcoder2PreTrainedModel,StoppingCriteria:()=>b.StoppingCriteria,StoppingCriteriaList:()=>b.StoppingCriteriaList,StyleTextToSpeech2Model:()=>n.StyleTextToSpeech2Model,StyleTextToSpeech2PreTrainedModel:()=>n.StyleTextToSpeech2PreTrainedModel,SummarizationPipeline:()=>t.SummarizationPipeline,SupertonicForConditionalGeneration:()=>n.SupertonicForConditionalGeneration,SupertonicPreTrainedModel:()=>n.SupertonicPreTrainedModel,SuppressTokensAtBeginLogitsProcessor:()=>x.SuppressTokensAtBeginLogitsProcessor,Swin2SRForImageSuperResolution:()=>n.Swin2SRForImageSuperResolution,Swin2SRImageProcessor:()=>m.Swin2SRImageProcessor,Swin2SRModel:()=>n.Swin2SRModel,Swin2SRPreTrainedModel:()=>n.Swin2SRPreTrainedModel,SwinForImageClassification:()=>n.SwinForImageClassification,SwinForSemanticSegmentation:()=>n.SwinForSemanticSegmentation,SwinModel:()=>n.SwinModel,SwinPreTrainedModel:()=>n.SwinPreTrainedModel,T5ForConditionalGeneration:()=>n.T5ForConditionalGeneration,T5Model:()=>n.T5Model,T5PreTrainedModel:()=>n.T5PreTrainedModel,T5Tokenizer:()=>r.T5Tokenizer,TableTransformerForObjectDetection:()=>n.TableTransformerForObjectDetection,TableTransformerModel:()=>n.TableTransformerModel,TableTransformerObjectDetectionOutput:()=>n.TableTransformerObjectDetectionOutput,TableTransformerPreTrainedModel:()=>n.TableTransformerPreTrainedModel,TemperatureLogitsWarper:()=>x.TemperatureLogitsWarper,Tensor:()=>c.Tensor,Text2TextGenerationPipeline:()=>t.Text2TextGenerationPipeline,TextClassificationPipeline:()=>t.TextClassificationPipeline,TextGenerationPipeline:()=>t.TextGenerationPipeline,TextStreamer:()=>y.TextStreamer,TextToAudioPipeline:()=>t.TextToAudioPipeline,TokenClassificationPipeline:()=>t.TokenClassificationPipeline,TokenClassifierOutput:()=>n.TokenClassifierOutput,TokenizerModel:()=>r.TokenizerModel,TopKLogitsWarper:()=>x.TopKLogitsWarper,TopPLogitsWarper:()=>x.TopPLogitsWarper,TrOCRForCausalLM:()=>n.TrOCRForCausalLM,TrOCRPreTrainedModel:()=>n.TrOCRPreTrainedModel,TranslationPipeline:()=>t.TranslationPipeline,UltravoxModel:()=>n.UltravoxModel,UltravoxPreTrainedModel:()=>n.UltravoxPreTrainedModel,UltravoxProcessor:()=>_.UltravoxProcessor,UniSpeechForCTC:()=>n.UniSpeechForCTC,UniSpeechForSequenceClassification:()=>n.UniSpeechForSequenceClassification,UniSpeechModel:()=>n.UniSpeechModel,UniSpeechPreTrainedModel:()=>n.UniSpeechPreTrainedModel,UniSpeechSatForAudioFrameClassification:()=>n.UniSpeechSatForAudioFrameClassification,UniSpeechSatForCTC:()=>n.UniSpeechSatForCTC,UniSpeechSatForSequenceClassification:()=>n.UniSpeechSatForSequenceClassification,UniSpeechSatModel:()=>n.UniSpeechSatModel,UniSpeechSatPreTrainedModel:()=>n.UniSpeechSatPreTrainedModel,VLChatProcessor:()=>_.VLChatProcessor,VLMImageProcessor:()=>m.VLMImageProcessor,VaultGemmaForCausalLM:()=>n.VaultGemmaForCausalLM,VaultGemmaModel:()=>n.VaultGemmaModel,VaultGemmaPreTrainedModel:()=>n.VaultGemmaPreTrainedModel,ViTFeatureExtractor:()=>m.ViTFeatureExtractor,ViTForImageClassification:()=>n.ViTForImageClassification,ViTImageProcessor:()=>m.ViTImageProcessor,ViTMAEModel:()=>n.ViTMAEModel,ViTMAEPreTrainedModel:()=>n.ViTMAEPreTrainedModel,ViTMSNForImageClassification:()=>n.ViTMSNForImageClassification,ViTMSNModel:()=>n.ViTMSNModel,ViTMSNPreTrainedModel:()=>n.ViTMSNPreTrainedModel,ViTModel:()=>n.ViTModel,ViTPreTrainedModel:()=>n.ViTPreTrainedModel,VisionEncoderDecoderModel:()=>n.VisionEncoderDecoderModel,VitMatteForImageMatting:()=>n.VitMatteForImageMatting,VitMatteImageProcessor:()=>m.VitMatteImageProcessor,VitMattePreTrainedModel:()=>n.VitMattePreTrainedModel,VitPoseForPoseEstimation:()=>n.VitPoseForPoseEstimation,VitPoseImageProcessor:()=>m.VitPoseImageProcessor,VitPosePreTrainedModel:()=>n.VitPosePreTrainedModel,VitsModel:()=>n.VitsModel,VitsModelOutput:()=>n.VitsModelOutput,VitsPreTrainedModel:()=>n.VitsPreTrainedModel,VitsTokenizer:()=>r.VitsTokenizer,VoxtralForConditionalGeneration:()=>n.VoxtralForConditionalGeneration,VoxtralProcessor:()=>_.VoxtralProcessor,Wav2Vec2BertForCTC:()=>n.Wav2Vec2BertForCTC,Wav2Vec2BertForSequenceClassification:()=>n.Wav2Vec2BertForSequenceClassification,Wav2Vec2BertModel:()=>n.Wav2Vec2BertModel,Wav2Vec2BertPreTrainedModel:()=>n.Wav2Vec2BertPreTrainedModel,Wav2Vec2CTCTokenizer:()=>r.Wav2Vec2CTCTokenizer,Wav2Vec2FeatureExtractor:()=>d.Wav2Vec2FeatureExtractor,Wav2Vec2ForAudioFrameClassification:()=>n.Wav2Vec2ForAudioFrameClassification,Wav2Vec2ForCTC:()=>n.Wav2Vec2ForCTC,Wav2Vec2ForSequenceClassification:()=>n.Wav2Vec2ForSequenceClassification,Wav2Vec2Model:()=>n.Wav2Vec2Model,Wav2Vec2PreTrainedModel:()=>n.Wav2Vec2PreTrainedModel,Wav2Vec2Processor:()=>_.Wav2Vec2Processor,Wav2Vec2ProcessorWithLM:()=>_.Wav2Vec2ProcessorWithLM,WavLMForAudioFrameClassification:()=>n.WavLMForAudioFrameClassification,WavLMForCTC:()=>n.WavLMForCTC,WavLMForSequenceClassification:()=>n.WavLMForSequenceClassification,WavLMForXVector:()=>n.WavLMForXVector,WavLMModel:()=>n.WavLMModel,WavLMPreTrainedModel:()=>n.WavLMPreTrainedModel,WeSpeakerFeatureExtractor:()=>d.WeSpeakerFeatureExtractor,WeSpeakerResNetModel:()=>n.WeSpeakerResNetModel,WeSpeakerResNetPreTrainedModel:()=>n.WeSpeakerResNetPreTrainedModel,WhisperFeatureExtractor:()=>d.WhisperFeatureExtractor,WhisperForConditionalGeneration:()=>n.WhisperForConditionalGeneration,WhisperModel:()=>n.WhisperModel,WhisperPreTrainedModel:()=>n.WhisperPreTrainedModel,WhisperProcessor:()=>_.WhisperProcessor,WhisperTextStreamer:()=>y.WhisperTextStreamer,WhisperTimeStampLogitsProcessor:()=>x.WhisperTimeStampLogitsProcessor,WhisperTokenizer:()=>r.WhisperTokenizer,XLMForQuestionAnswering:()=>n.XLMForQuestionAnswering,XLMForSequenceClassification:()=>n.XLMForSequenceClassification,XLMForTokenClassification:()=>n.XLMForTokenClassification,XLMModel:()=>n.XLMModel,XLMPreTrainedModel:()=>n.XLMPreTrainedModel,XLMRobertaForMaskedLM:()=>n.XLMRobertaForMaskedLM,XLMRobertaForQuestionAnswering:()=>n.XLMRobertaForQuestionAnswering,XLMRobertaForSequenceClassification:()=>n.XLMRobertaForSequenceClassification,XLMRobertaForTokenClassification:()=>n.XLMRobertaForTokenClassification,XLMRobertaModel:()=>n.XLMRobertaModel,XLMRobertaPreTrainedModel:()=>n.XLMRobertaPreTrainedModel,XLMRobertaTokenizer:()=>r.XLMRobertaTokenizer,XLMTokenizer:()=>r.XLMTokenizer,XLMWithLMHeadModel:()=>n.XLMWithLMHeadModel,XVectorOutput:()=>n.XVectorOutput,YolosFeatureExtractor:()=>m.YolosFeatureExtractor,YolosForObjectDetection:()=>n.YolosForObjectDetection,YolosImageProcessor:()=>m.YolosImageProcessor,YolosModel:()=>n.YolosModel,YolosObjectDetectionOutput:()=>n.YolosObjectDetectionOutput,YolosPreTrainedModel:()=>n.YolosPreTrainedModel,ZeroShotAudioClassificationPipeline:()=>t.ZeroShotAudioClassificationPipeline,ZeroShotClassificationPipeline:()=>t.ZeroShotClassificationPipeline,ZeroShotImageClassificationPipeline:()=>t.ZeroShotImageClassificationPipeline,ZeroShotObjectDetectionPipeline:()=>t.ZeroShotObjectDetectionPipeline,bankers_round:()=>l.bankers_round,cat:()=>c.cat,cos_sim:()=>l.cos_sim,dot:()=>l.dot,dynamic_time_warping:()=>l.dynamic_time_warping,env:()=>e.env,full:()=>c.full,full_like:()=>c.full_like,getCacheShapes:()=>i.getCacheShapes,hamming:()=>a.hamming,hanning:()=>a.hanning,interpolate:()=>c.interpolate,interpolate_4d:()=>c.interpolate_4d,interpolate_data:()=>l.interpolate_data,is_chinese_char:()=>r.is_chinese_char,layer_norm:()=>c.layer_norm,load_image:()=>o.load_image,load_video:()=>s.load_video,log_softmax:()=>l.log_softmax,magnitude:()=>l.magnitude,matmul:()=>c.matmul,max:()=>l.max,mean:()=>c.mean,mean_pooling:()=>c.mean_pooling,medianFilter:()=>l.medianFilter,mel_filter_bank:()=>a.mel_filter_bank,min:()=>l.min,ones:()=>c.ones,ones_like:()=>c.ones_like,permute:()=>c.permute,permute_data:()=>l.permute_data,pipeline:()=>t.pipeline,quantize_embeddings:()=>c.quantize_embeddings,rand:()=>c.rand,randn:()=>c.randn,read_audio:()=>a.read_audio,rfft:()=>c.rfft,round:()=>l.round,slice:()=>c.slice,softmax:()=>l.softmax,spectrogram:()=>a.spectrogram,stack:()=>c.stack,std_mean:()=>c.std_mean,topk:()=>c.topk,window_function:()=>a.window_function,zeros:()=>c.zeros,zeros_like:()=>c.zeros_like});var e=af(`./src/env.js`),t=af(`./src/pipelines.js`),n=af(`./src/models.js`),r=af(`./src/tokenizers.js`),i=af(`./src/configs.js`),a=af(`./src/utils/audio.js`),o=af(`./src/utils/image.js`),s=af(`./src/utils/video.js`),c=af(`./src/utils/tensor.js`),l=af(`./src/utils/maths.js`),u=af(`./src/base/feature_extraction_utils.js`),d=af(`./src/models/feature_extractors.js`),f=af(`./src/models/auto/feature_extraction_auto.js`),p=af(`./src/base/image_processors_utils.js`),m=af(`./src/models/image_processors.js`),h=af(`./src/models/auto/image_processing_auto.js`),g=af(`./src/base/processing_utils.js`),_=af(`./src/models/processors.js`),v=af(`./src/models/auto/processing_auto.js`),y=af(`./src/generation/streamers.js`),b=af(`./src/generation/stopping_criteria.js`),x=af(`./src/generation/logits_process.js`)})(),$.ASTFeatureExtractor,$.ASTForAudioClassification,$.ASTModel,$.ASTPreTrainedModel,$.AlbertForMaskedLM,$.AlbertForQuestionAnswering,$.AlbertForSequenceClassification,$.AlbertModel,$.AlbertPreTrainedModel,$.AlbertTokenizer,$.ArceeForCausalLM,$.ArceeModel,$.ArceePreTrainedModel,$.AudioClassificationPipeline,$.AutoConfig,$.AutoFeatureExtractor,$.AutoImageProcessor,$.AutoModel,$.AutoModelForAudioClassification,$.AutoModelForAudioFrameClassification,$.AutoModelForAudioTextToText,$.AutoModelForCTC;var of=$.AutoModelForCausalLM;$.AutoModelForDepthEstimation,$.AutoModelForDocumentQuestionAnswering,$.AutoModelForImageClassification,$.AutoModelForImageFeatureExtraction,$.AutoModelForImageMatting,$.AutoModelForImageSegmentation,$.AutoModelForImageTextToText,$.AutoModelForImageToImage,$.AutoModelForMaskGeneration,$.AutoModelForMaskedLM,$.AutoModelForNormalEstimation,$.AutoModelForObjectDetection,$.AutoModelForPoseEstimation,$.AutoModelForQuestionAnswering,$.AutoModelForSemanticSegmentation,$.AutoModelForSeq2SeqLM,$.AutoModelForSequenceClassification,$.AutoModelForSpeechSeq2Seq,$.AutoModelForTextToSpectrogram,$.AutoModelForTextToWaveform,$.AutoModelForTokenClassification,$.AutoModelForUniversalSegmentation,$.AutoModelForVision2Seq,$.AutoModelForXVector,$.AutoModelForZeroShotObjectDetection;var sf=$.AutoProcessor;$.AutoTokenizer,$.AutomaticSpeechRecognitionPipeline,$.BackgroundRemovalPipeline,$.BartForConditionalGeneration,$.BartForSequenceClassification,$.BartModel,$.BartPretrainedModel,$.BartTokenizer,$.BaseModelOutput,$.BaseStreamer,$.BeitFeatureExtractor,$.BeitForImageClassification,$.BeitModel,$.BeitPreTrainedModel,$.BertForMaskedLM,$.BertForQuestionAnswering,$.BertForSequenceClassification,$.BertForTokenClassification,$.BertModel,$.BertPreTrainedModel,$.BertTokenizer,$.BitImageProcessor,$.BlenderbotForConditionalGeneration,$.BlenderbotModel,$.BlenderbotPreTrainedModel,$.BlenderbotSmallForConditionalGeneration,$.BlenderbotSmallModel,$.BlenderbotSmallPreTrainedModel,$.BlenderbotSmallTokenizer,$.BlenderbotTokenizer,$.BloomForCausalLM,$.BloomModel,$.BloomPreTrainedModel,$.BloomTokenizer,$.CLIPFeatureExtractor,$.CLIPImageProcessor,$.CLIPModel,$.CLIPPreTrainedModel,$.CLIPSegForImageSegmentation,$.CLIPSegModel,$.CLIPSegPreTrainedModel,$.CLIPTextModel,$.CLIPTextModelWithProjection,$.CLIPTokenizer,$.CLIPVisionModel,$.CLIPVisionModelWithProjection,$.CamembertForMaskedLM,$.CamembertForQuestionAnswering,$.CamembertForSequenceClassification,$.CamembertForTokenClassification,$.CamembertModel,$.CamembertPreTrainedModel,$.CamembertTokenizer,$.CausalLMOutput,$.CausalLMOutputWithPast,$.ChineseCLIPFeatureExtractor,$.ChineseCLIPModel,$.ChineseCLIPPreTrainedModel,$.ClapAudioModelWithProjection,$.ClapFeatureExtractor,$.ClapModel,$.ClapPreTrainedModel,$.ClapTextModelWithProjection,$.ClassifierFreeGuidanceLogitsProcessor,$.CodeGenForCausalLM,$.CodeGenModel,$.CodeGenPreTrainedModel,$.CodeGenTokenizer,$.CodeLlamaTokenizer,$.CohereForCausalLM,$.CohereModel,$.CoherePreTrainedModel,$.CohereTokenizer,$.ConvBertForMaskedLM,$.ConvBertForQuestionAnswering,$.ConvBertForSequenceClassification,$.ConvBertForTokenClassification,$.ConvBertModel,$.ConvBertPreTrainedModel,$.ConvBertTokenizer,$.ConvNextFeatureExtractor,$.ConvNextForImageClassification,$.ConvNextImageProcessor,$.ConvNextModel,$.ConvNextPreTrainedModel,$.ConvNextV2ForImageClassification,$.ConvNextV2Model,$.ConvNextV2PreTrainedModel,$.DFineForObjectDetection,$.DFineModel,$.DFinePreTrainedModel,$.DINOv3ConvNextModel,$.DINOv3ConvNextPreTrainedModel,$.DINOv3ViTImageProcessor,$.DINOv3ViTModel,$.DINOv3ViTPreTrainedModel,$.DPTFeatureExtractor,$.DPTForDepthEstimation,$.DPTImageProcessor,$.DPTModel,$.DPTPreTrainedModel,$.DacDecoderModel,$.DacDecoderOutput,$.DacEncoderModel,$.DacEncoderOutput,$.DacFeatureExtractor,$.DacModel,$.DacPreTrainedModel,$.DataTypeMap,$.DebertaForMaskedLM,$.DebertaForQuestionAnswering,$.DebertaForSequenceClassification,$.DebertaForTokenClassification,$.DebertaModel,$.DebertaPreTrainedModel,$.DebertaTokenizer,$.DebertaV2ForMaskedLM,$.DebertaV2ForQuestionAnswering,$.DebertaV2ForSequenceClassification,$.DebertaV2ForTokenClassification,$.DebertaV2Model,$.DebertaV2PreTrainedModel,$.DebertaV2Tokenizer,$.DecisionTransformerModel,$.DecisionTransformerPreTrainedModel,$.DeiTFeatureExtractor,$.DeiTForImageClassification,$.DeiTImageProcessor,$.DeiTModel,$.DeiTPreTrainedModel,$.DepthAnythingForDepthEstimation,$.DepthAnythingPreTrainedModel,$.DepthEstimationPipeline,$.DepthProForDepthEstimation,$.DepthProPreTrainedModel,$.DetrFeatureExtractor,$.DetrForObjectDetection,$.DetrForSegmentation,$.DetrImageProcessor,$.DetrModel,$.DetrObjectDetectionOutput,$.DetrPreTrainedModel,$.DetrSegmentationOutput,$.Dinov2ForImageClassification,$.Dinov2Model,$.Dinov2PreTrainedModel,$.Dinov2WithRegistersForImageClassification,$.Dinov2WithRegistersModel,$.Dinov2WithRegistersPreTrainedModel,$.DistilBertForMaskedLM,$.DistilBertForQuestionAnswering,$.DistilBertForSequenceClassification,$.DistilBertForTokenClassification,$.DistilBertModel,$.DistilBertPreTrainedModel,$.DistilBertTokenizer,$.DocumentQuestionAnsweringPipeline,$.DonutFeatureExtractor,$.DonutImageProcessor,$.DonutSwinModel,$.DonutSwinPreTrainedModel,$.EdgeTamModel,$.EfficientNetForImageClassification,$.EfficientNetImageProcessor,$.EfficientNetModel,$.EfficientNetPreTrainedModel,$.ElectraForMaskedLM,$.ElectraForQuestionAnswering,$.ElectraForSequenceClassification,$.ElectraForTokenClassification,$.ElectraModel,$.ElectraPreTrainedModel,$.ElectraTokenizer,$.EncodecFeatureExtractor,$.EosTokenCriteria,$.Ernie4_5ForCausalLM,$.Ernie4_5Model,$.Ernie4_5PreTrainedModel,$.EsmForMaskedLM,$.EsmForSequenceClassification,$.EsmForTokenClassification,$.EsmModel,$.EsmPreTrainedModel,$.EsmTokenizer,$.ExaoneForCausalLM,$.ExaoneModel,$.ExaonePreTrainedModel,$.FFT,$.FalconForCausalLM,$.FalconModel,$.FalconPreTrainedModel,$.FalconTokenizer,$.FastViTForImageClassification,$.FastViTModel,$.FastViTPreTrainedModel,$.FeatureExtractionPipeline,$.FeatureExtractor,$.FillMaskPipeline,$.Florence2ForConditionalGeneration,$.Florence2PreTrainedModel,$.Florence2Processor,$.ForcedBOSTokenLogitsProcessor,$.ForcedEOSTokenLogitsProcessor,$.GLPNFeatureExtractor,$.GLPNForDepthEstimation,$.GLPNModel,$.GLPNPreTrainedModel,$.GPT2LMHeadModel,$.GPT2Model,$.GPT2PreTrainedModel,$.GPT2Tokenizer,$.GPTBigCodeForCausalLM,$.GPTBigCodeModel,$.GPTBigCodePreTrainedModel,$.GPTJForCausalLM,$.GPTJModel,$.GPTJPreTrainedModel,$.GPTNeoForCausalLM,$.GPTNeoModel,$.GPTNeoPreTrainedModel,$.GPTNeoXForCausalLM,$.GPTNeoXModel,$.GPTNeoXPreTrainedModel,$.GPTNeoXTokenizer,$.Gemma2ForCausalLM,$.Gemma2Model,$.Gemma2PreTrainedModel,$.Gemma3ForCausalLM,$.Gemma3Model,$.Gemma3PreTrainedModel,$.Gemma3nAudioFeatureExtractor,$.Gemma3nForConditionalGeneration,$.Gemma3nPreTrainedModel,$.Gemma3nProcessor,$.GemmaForCausalLM,$.GemmaModel,$.GemmaPreTrainedModel,$.GemmaTokenizer,$.GlmForCausalLM,$.GlmModel,$.GlmPreTrainedModel,$.GraniteForCausalLM,$.GraniteModel,$.GraniteMoeHybridForCausalLM,$.GraniteMoeHybridModel,$.GraniteMoeHybridPreTrainedModel,$.GranitePreTrainedModel,$.Grok1Tokenizer,$.GroundingDinoForObjectDetection,$.GroundingDinoImageProcessor,$.GroundingDinoPreTrainedModel,$.GroundingDinoProcessor,$.GroupViTModel,$.GroupViTPreTrainedModel,$.HeliumForCausalLM,$.HeliumModel,$.HeliumPreTrainedModel,$.HerbertTokenizer,$.HieraForImageClassification,$.HieraModel,$.HieraPreTrainedModel,$.HubertForCTC,$.HubertForSequenceClassification,$.HubertModel,$.HubertPreTrainedModel,$.IJepaForImageClassification,$.IJepaModel,$.IJepaPreTrainedModel,$.Idefics3ForConditionalGeneration,$.Idefics3ImageProcessor,$.Idefics3PreTrainedModel,$.Idefics3Processor,$.ImageClassificationPipeline,$.ImageFeatureExtractionPipeline,$.ImageFeatureExtractor,$.ImageMattingOutput,$.ImageProcessor,$.ImageSegmentationPipeline,$.ImageToImagePipeline,$.ImageToTextPipeline,$.InterruptableStoppingCriteria,$.JAISLMHeadModel,$.JAISModel,$.JAISPreTrainedModel,$.JinaCLIPImageProcessor,$.JinaCLIPModel,$.JinaCLIPPreTrainedModel,$.JinaCLIPProcessor,$.JinaCLIPTextModel,$.JinaCLIPVisionModel,$.Lfm2ForCausalLM,$.Lfm2Model,$.Lfm2PreTrainedModel,$.LiteWhisperForConditionalGeneration,$.Llama4ForCausalLM,$.Llama4PreTrainedModel,$.LlamaForCausalLM,$.LlamaModel,$.LlamaPreTrainedModel,$.LlamaTokenizer,$.LlavaForConditionalGeneration,$.LlavaOnevisionForConditionalGeneration,$.LlavaOnevisionImageProcessor,$.LlavaPreTrainedModel,$.LlavaProcessor,$.LlavaQwen2ForCausalLM,$.LogitsProcessor,$.LogitsProcessorList,$.LogitsWarper,$.LongT5ForConditionalGeneration,$.LongT5Model,$.LongT5PreTrainedModel,$.M2M100ForConditionalGeneration,$.M2M100Model,$.M2M100PreTrainedModel,$.M2M100Tokenizer,$.MBart50Tokenizer,$.MBartForCausalLM,$.MBartForConditionalGeneration,$.MBartForSequenceClassification,$.MBartModel,$.MBartPreTrainedModel,$.MBartTokenizer,$.MPNetForMaskedLM,$.MPNetForQuestionAnswering,$.MPNetForSequenceClassification,$.MPNetForTokenClassification,$.MPNetModel,$.MPNetPreTrainedModel,$.MPNetTokenizer,$.MT5ForConditionalGeneration,$.MT5Model,$.MT5PreTrainedModel,$.MarianMTModel,$.MarianModel,$.MarianPreTrainedModel,$.MarianTokenizer,$.Mask2FormerImageProcessor,$.MaskFormerFeatureExtractor,$.MaskFormerForInstanceSegmentation,$.MaskFormerImageProcessor,$.MaskFormerModel,$.MaskFormerPreTrainedModel,$.MaskedLMOutput,$.MaxLengthCriteria,$.Metric3DForDepthEstimation,$.Metric3DPreTrainedModel,$.Metric3Dv2ForDepthEstimation,$.Metric3Dv2PreTrainedModel,$.MgpstrForSceneTextRecognition,$.MgpstrModelOutput,$.MgpstrPreTrainedModel,$.MgpstrProcessor,$.MgpstrTokenizer,$.MimiDecoderModel,$.MimiDecoderOutput,$.MimiEncoderModel,$.MimiEncoderOutput,$.MimiModel,$.MimiPreTrainedModel,$.MinLengthLogitsProcessor,$.MinNewTokensLengthLogitsProcessor,$.Ministral3ForCausalLM,$.Ministral3Model,$.Ministral3PreTrainedModel,$.MinistralForCausalLM,$.MinistralModel,$.MinistralPreTrainedModel,$.Mistral3ForConditionalGeneration,$.MistralForCausalLM,$.MistralModel,$.MistralPreTrainedModel,$.MobileBertForMaskedLM,$.MobileBertForQuestionAnswering,$.MobileBertForSequenceClassification,$.MobileBertModel,$.MobileBertPreTrainedModel,$.MobileBertTokenizer,$.MobileLLMForCausalLM,$.MobileLLMModel,$.MobileLLMPreTrainedModel,$.MobileNetV1FeatureExtractor,$.MobileNetV1ForImageClassification,$.MobileNetV1ForSemanticSegmentation,$.MobileNetV1ImageProcessor,$.MobileNetV1Model,$.MobileNetV1PreTrainedModel,$.MobileNetV2FeatureExtractor,$.MobileNetV2ForImageClassification,$.MobileNetV2ForSemanticSegmentation,$.MobileNetV2ImageProcessor,$.MobileNetV2Model,$.MobileNetV2PreTrainedModel,$.MobileNetV3FeatureExtractor,$.MobileNetV3ForImageClassification,$.MobileNetV3ForSemanticSegmentation,$.MobileNetV3ImageProcessor,$.MobileNetV3Model,$.MobileNetV3PreTrainedModel,$.MobileNetV4FeatureExtractor,$.MobileNetV4ForImageClassification,$.MobileNetV4ForSemanticSegmentation,$.MobileNetV4ImageProcessor,$.MobileNetV4Model,$.MobileNetV4PreTrainedModel,$.MobileViTFeatureExtractor,$.MobileViTForImageClassification,$.MobileViTImageProcessor,$.MobileViTModel,$.MobileViTPreTrainedModel,$.MobileViTV2ForImageClassification,$.MobileViTV2Model,$.MobileViTV2PreTrainedModel,$.ModelOutput,$.ModernBertDecoderForCausalLM,$.ModernBertDecoderModel,$.ModernBertDecoderPreTrainedModel,$.ModernBertForMaskedLM,$.ModernBertForSequenceClassification,$.ModernBertForTokenClassification,$.ModernBertModel,$.ModernBertPreTrainedModel,$.Moondream1ForConditionalGeneration,$.MoonshineFeatureExtractor,$.MoonshineForConditionalGeneration,$.MoonshineModel,$.MoonshinePreTrainedModel,$.MoonshineProcessor,$.MptForCausalLM,$.MptModel,$.MptPreTrainedModel,$.MultiModalityCausalLM,$.MultiModalityPreTrainedModel,$.MusicgenForCausalLM,$.MusicgenForConditionalGeneration,$.MusicgenModel,$.MusicgenPreTrainedModel,$.NanoChatForCausalLM,$.NanoChatModel,$.NanoChatPreTrainedModel,$.NeoBertForMaskedLM,$.NeoBertForQuestionAnswering,$.NeoBertForSequenceClassification,$.NeoBertForTokenClassification,$.NeoBertModel,$.NeoBertPreTrainedModel,$.NllbTokenizer,$.NoBadWordsLogitsProcessor,$.NoRepeatNGramLogitsProcessor,$.NomicBertModel,$.NomicBertPreTrainedModel,$.NougatImageProcessor,$.NougatTokenizer,$.OPTForCausalLM,$.OPTModel,$.OPTPreTrainedModel,$.ObjectDetectionPipeline,$.Olmo2ForCausalLM,$.Olmo2Model,$.Olmo2PreTrainedModel,$.OlmoForCausalLM,$.OlmoModel,$.OlmoPreTrainedModel,$.OpenELMForCausalLM,$.OpenELMModel,$.OpenELMPreTrainedModel,$.OwlViTFeatureExtractor,$.OwlViTForObjectDetection,$.OwlViTImageProcessor,$.OwlViTModel,$.OwlViTPreTrainedModel,$.OwlViTProcessor,$.Owlv2ForObjectDetection,$.Owlv2ImageProcessor,$.Owlv2Model,$.Owlv2PreTrainedModel,$.PaliGemmaForConditionalGeneration,$.PaliGemmaPreTrainedModel,$.PaliGemmaProcessor,$.ParakeetFeatureExtractor,$.ParakeetForCTC,$.ParakeetPreTrainedModel,$.PatchTSMixerForPrediction,$.PatchTSMixerModel,$.PatchTSMixerPreTrainedModel,$.PatchTSTForPrediction,$.PatchTSTModel,$.PatchTSTPreTrainedModel,$.Phi3ForCausalLM,$.Phi3Model,$.Phi3PreTrainedModel,$.Phi3VForCausalLM,$.Phi3VImageProcessor,$.Phi3VPreTrainedModel,$.Phi3VProcessor,$.PhiForCausalLM,$.PhiModel,$.PhiPreTrainedModel,$.Pipeline,$.PixtralImageProcessor,$.PixtralProcessor,$.PreTrainedModel,$.PreTrainedTokenizer,$.PretrainedConfig,$.PretrainedMixin,$.Processor,$.PvtForImageClassification,$.PvtImageProcessor,$.PvtModel,$.PvtPreTrainedModel,$.PyAnnoteFeatureExtractor,$.PyAnnoteForAudioFrameClassification,$.PyAnnoteModel,$.PyAnnotePreTrainedModel,$.PyAnnoteProcessor,$.QuestionAnsweringModelOutput,$.QuestionAnsweringPipeline,$.Qwen2ForCausalLM,$.Qwen2Model,$.Qwen2PreTrainedModel,$.Qwen2Tokenizer,$.Qwen2VLForConditionalGeneration,$.Qwen2VLImageProcessor,$.Qwen2VLPreTrainedModel,$.Qwen2VLProcessor,$.Qwen3ForCausalLM,$.Qwen3Model,$.Qwen3PreTrainedModel,$.RFDetrForObjectDetection,$.RFDetrModel,$.RFDetrObjectDetectionOutput,$.RFDetrPreTrainedModel,$.RTDetrForObjectDetection,$.RTDetrImageProcessor,$.RTDetrModel,$.RTDetrObjectDetectionOutput,$.RTDetrPreTrainedModel,$.RTDetrV2ForObjectDetection,$.RTDetrV2Model,$.RTDetrV2ObjectDetectionOutput,$.RTDetrV2PreTrainedModel,$.RawAudio,$.RawImage,$.RawVideo,$.RawVideoFrame,$.RepetitionPenaltyLogitsProcessor,$.ResNetForImageClassification,$.ResNetModel,$.ResNetPreTrainedModel,$.RoFormerForMaskedLM,$.RoFormerForQuestionAnswering,$.RoFormerForSequenceClassification,$.RoFormerForTokenClassification,$.RoFormerModel,$.RoFormerPreTrainedModel,$.RoFormerTokenizer,$.RobertaForMaskedLM,$.RobertaForQuestionAnswering,$.RobertaForSequenceClassification,$.RobertaForTokenClassification,$.RobertaModel,$.RobertaPreTrainedModel,$.RobertaTokenizer,$.Sam2ImageProcessor,$.Sam2ImageSegmentationOutput,$.Sam2Model,$.Sam2PreTrainedModel,$.Sam2Processor,$.Sam2VideoProcessor,$.Sam3ImageProcessor,$.Sam3TrackerModel,$.SamImageProcessor,$.SamImageSegmentationOutput,$.SamModel,$.SamPreTrainedModel,$.SamProcessor,$.SapiensForDepthEstimation,$.SapiensForNormalEstimation,$.SapiensForSemanticSegmentation,$.SapiensPreTrainedModel,$.SeamlessM4TFeatureExtractor,$.SegformerFeatureExtractor,$.SegformerForImageClassification,$.SegformerForSemanticSegmentation,$.SegformerImageProcessor,$.SegformerModel,$.SegformerPreTrainedModel,$.Seq2SeqLMOutput,$.SequenceClassifierOutput,$.SiglipImageProcessor,$.SiglipModel,$.SiglipPreTrainedModel,$.SiglipTextModel,$.SiglipTokenizer,$.SiglipVisionModel,$.SmolLM3ForCausalLM,$.SmolLM3Model,$.SmolLM3PreTrainedModel,$.SmolVLMForConditionalGeneration,$.SmolVLMImageProcessor,$.SmolVLMProcessor,$.SnacDecoderModel,$.SnacEncoderModel,$.SnacFeatureExtractor,$.SnacModel,$.SnacPreTrainedModel,$.SpeechT5FeatureExtractor,$.SpeechT5ForSpeechToText,$.SpeechT5ForTextToSpeech,$.SpeechT5HifiGan,$.SpeechT5Model,$.SpeechT5PreTrainedModel,$.SpeechT5Processor,$.SpeechT5Tokenizer,$.SqueezeBertForMaskedLM,$.SqueezeBertForQuestionAnswering,$.SqueezeBertForSequenceClassification,$.SqueezeBertModel,$.SqueezeBertPreTrainedModel,$.SqueezeBertTokenizer,$.StableLmForCausalLM,$.StableLmModel,$.StableLmPreTrainedModel,$.Starcoder2ForCausalLM,$.Starcoder2Model,$.Starcoder2PreTrainedModel,$.StoppingCriteria,$.StoppingCriteriaList,$.StyleTextToSpeech2Model,$.StyleTextToSpeech2PreTrainedModel,$.SummarizationPipeline,$.SupertonicForConditionalGeneration,$.SupertonicPreTrainedModel,$.SuppressTokensAtBeginLogitsProcessor,$.Swin2SRForImageSuperResolution,$.Swin2SRImageProcessor,$.Swin2SRModel,$.Swin2SRPreTrainedModel,$.SwinForImageClassification,$.SwinForSemanticSegmentation,$.SwinModel,$.SwinPreTrainedModel,$.T5ForConditionalGeneration,$.T5Model,$.T5PreTrainedModel,$.T5Tokenizer,$.TableTransformerForObjectDetection,$.TableTransformerModel,$.TableTransformerObjectDetectionOutput,$.TableTransformerPreTrainedModel,$.TemperatureLogitsWarper,$.Tensor,$.Text2TextGenerationPipeline,$.TextClassificationPipeline,$.TextGenerationPipeline;var cf=$.TextStreamer;$.TextToAudioPipeline,$.TokenClassificationPipeline,$.TokenClassifierOutput,$.TokenizerModel,$.TopKLogitsWarper,$.TopPLogitsWarper,$.TrOCRForCausalLM,$.TrOCRPreTrainedModel,$.TranslationPipeline,$.UltravoxModel,$.UltravoxPreTrainedModel,$.UltravoxProcessor,$.UniSpeechForCTC,$.UniSpeechForSequenceClassification,$.UniSpeechModel,$.UniSpeechPreTrainedModel,$.UniSpeechSatForAudioFrameClassification,$.UniSpeechSatForCTC,$.UniSpeechSatForSequenceClassification,$.UniSpeechSatModel,$.UniSpeechSatPreTrainedModel,$.VLChatProcessor,$.VLMImageProcessor,$.VaultGemmaForCausalLM,$.VaultGemmaModel,$.VaultGemmaPreTrainedModel,$.ViTFeatureExtractor,$.ViTForImageClassification,$.ViTImageProcessor,$.ViTMAEModel,$.ViTMAEPreTrainedModel,$.ViTMSNForImageClassification,$.ViTMSNModel,$.ViTMSNPreTrainedModel,$.ViTModel,$.ViTPreTrainedModel,$.VisionEncoderDecoderModel,$.VitMatteForImageMatting,$.VitMatteImageProcessor,$.VitMattePreTrainedModel,$.VitPoseForPoseEstimation,$.VitPoseImageProcessor,$.VitPosePreTrainedModel,$.VitsModel,$.VitsModelOutput,$.VitsPreTrainedModel,$.VitsTokenizer,$.VoxtralForConditionalGeneration,$.VoxtralProcessor,$.Wav2Vec2BertForCTC,$.Wav2Vec2BertForSequenceClassification,$.Wav2Vec2BertModel,$.Wav2Vec2BertPreTrainedModel,$.Wav2Vec2CTCTokenizer,$.Wav2Vec2FeatureExtractor,$.Wav2Vec2ForAudioFrameClassification,$.Wav2Vec2ForCTC,$.Wav2Vec2ForSequenceClassification,$.Wav2Vec2Model,$.Wav2Vec2PreTrainedModel,$.Wav2Vec2Processor,$.Wav2Vec2ProcessorWithLM,$.WavLMForAudioFrameClassification,$.WavLMForCTC,$.WavLMForSequenceClassification,$.WavLMForXVector,$.WavLMModel,$.WavLMPreTrainedModel,$.WeSpeakerFeatureExtractor,$.WeSpeakerResNetModel,$.WeSpeakerResNetPreTrainedModel,$.WhisperFeatureExtractor,$.WhisperForConditionalGeneration,$.WhisperModel,$.WhisperPreTrainedModel,$.WhisperProcessor,$.WhisperTextStreamer,$.WhisperTimeStampLogitsProcessor,$.WhisperTokenizer,$.XLMForQuestionAnswering,$.XLMForSequenceClassification,$.XLMForTokenClassification,$.XLMModel,$.XLMPreTrainedModel,$.XLMRobertaForMaskedLM,$.XLMRobertaForQuestionAnswering,$.XLMRobertaForSequenceClassification,$.XLMRobertaForTokenClassification,$.XLMRobertaModel,$.XLMRobertaPreTrainedModel,$.XLMRobertaTokenizer,$.XLMTokenizer,$.XLMWithLMHeadModel,$.XVectorOutput,$.YolosFeatureExtractor,$.YolosForObjectDetection,$.YolosImageProcessor,$.YolosModel,$.YolosObjectDetectionOutput,$.YolosPreTrainedModel,$.ZeroShotAudioClassificationPipeline,$.ZeroShotClassificationPipeline,$.ZeroShotImageClassificationPipeline,$.ZeroShotObjectDetectionPipeline,$.bankers_round,$.cat,$.cos_sim,$.dot,$.dynamic_time_warping;var lf=$.env;$.full,$.full_like,$.getCacheShapes,$.hamming,$.hanning,$.interpolate,$.interpolate_4d,$.interpolate_data,$.is_chinese_char,$.layer_norm,$.load_image,$.load_video,$.log_softmax,$.magnitude,$.matmul,$.max,$.mean,$.mean_pooling,$.medianFilter,$.mel_filter_bank,$.min,$.ones,$.ones_like,$.permute,$.permute_data,$.pipeline,$.quantize_embeddings,$.rand,$.randn,$.read_audio,$.rfft,$.round,$.slice,$.softmax,$.spectrogram,$.stack,$.std_mean,$.topk,$.window_function,$.zeros,$.zeros_like;export{of as AutoModelForCausalLM,sf as AutoProcessor,cf as TextStreamer,lf as env};