__init__.pyi 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431
  1. # auto-generated file
  2. import ggml.ffi as ffi
  3. import numpy as np
  4. class lib:
  5. @property
  6. def GGML_BACKEND_CPU(self) -> int: ...
  7. @property
  8. def GGML_BACKEND_GPU(self) -> int: ...
  9. @property
  10. def GGML_BACKEND_GPU_SPLIT(self) -> int: ...
  11. @property
  12. def GGML_FTYPE_ALL_F32(self) -> int: ...
  13. @property
  14. def GGML_FTYPE_MOSTLY_F16(self) -> int: ...
  15. @property
  16. def GGML_FTYPE_MOSTLY_Q2_K(self) -> int: ...
  17. @property
  18. def GGML_FTYPE_MOSTLY_Q3_K(self) -> int: ...
  19. @property
  20. def GGML_FTYPE_MOSTLY_Q4_0(self) -> int: ...
  21. @property
  22. def GGML_FTYPE_MOSTLY_Q4_1(self) -> int: ...
  23. @property
  24. def GGML_FTYPE_MOSTLY_Q4_1_SOME_F16(self) -> int: ...
  25. @property
  26. def GGML_FTYPE_MOSTLY_Q4_K(self) -> int: ...
  27. @property
  28. def GGML_FTYPE_MOSTLY_Q5_0(self) -> int: ...
  29. @property
  30. def GGML_FTYPE_MOSTLY_Q5_1(self) -> int: ...
  31. @property
  32. def GGML_FTYPE_MOSTLY_Q5_K(self) -> int: ...
  33. @property
  34. def GGML_FTYPE_MOSTLY_Q6_K(self) -> int: ...
  35. @property
  36. def GGML_FTYPE_MOSTLY_Q8_0(self) -> int: ...
  37. @property
  38. def GGML_FTYPE_UNKNOWN(self) -> int: ...
  39. @property
  40. def GGML_LINESEARCH_BACKTRACKING_ARMIJO(self) -> int: ...
  41. @property
  42. def GGML_LINESEARCH_BACKTRACKING_STRONG_WOLFE(self) -> int: ...
  43. @property
  44. def GGML_LINESEARCH_BACKTRACKING_WOLFE(self) -> int: ...
  45. @property
  46. def GGML_LINESEARCH_DEFAULT(self) -> int: ...
  47. @property
  48. def GGML_LINESEARCH_FAIL(self) -> int: ...
  49. @property
  50. def GGML_LINESEARCH_INVALID_PARAMETERS(self) -> int: ...
  51. @property
  52. def GGML_LINESEARCH_MAXIMUM_ITERATIONS(self) -> int: ...
  53. @property
  54. def GGML_LINESEARCH_MAXIMUM_STEP(self) -> int: ...
  55. @property
  56. def GGML_LINESEARCH_MINIMUM_STEP(self) -> int: ...
  57. @property
  58. def GGML_OBJECT_GRAPH(self) -> int: ...
  59. @property
  60. def GGML_OBJECT_TENSOR(self) -> int: ...
  61. @property
  62. def GGML_OBJECT_WORK_BUFFER(self) -> int: ...
  63. @property
  64. def GGML_OPT_ADAM(self) -> int: ...
  65. @property
  66. def GGML_OPT_DID_NOT_CONVERGE(self) -> int: ...
  67. @property
  68. def GGML_OPT_FAIL(self) -> int: ...
  69. @property
  70. def GGML_OPT_INVALID_WOLFE(self) -> int: ...
  71. @property
  72. def GGML_OPT_LBFGS(self) -> int: ...
  73. @property
  74. def GGML_OPT_NO_CONTEXT(self) -> int: ...
  75. @property
  76. def GGML_OPT_OK(self) -> int: ...
  77. @property
  78. def GGML_OP_ACC(self) -> int: ...
  79. @property
  80. def GGML_OP_ADD(self) -> int: ...
  81. @property
  82. def GGML_OP_ADD1(self) -> int: ...
  83. @property
  84. def GGML_OP_ALIBI(self) -> int: ...
  85. @property
  86. def GGML_OP_ARGMAX(self) -> int: ...
  87. @property
  88. def GGML_OP_CLAMP(self) -> int: ...
  89. @property
  90. def GGML_OP_CONT(self) -> int: ...
  91. @property
  92. def GGML_OP_CONV_1D(self) -> int: ...
  93. @property
  94. def GGML_OP_CONV_2D(self) -> int: ...
  95. @property
  96. def GGML_OP_COUNT(self) -> int: ...
  97. @property
  98. def GGML_OP_CPY(self) -> int: ...
  99. @property
  100. def GGML_OP_CROSS_ENTROPY_LOSS(self) -> int: ...
  101. @property
  102. def GGML_OP_CROSS_ENTROPY_LOSS_BACK(self) -> int: ...
  103. @property
  104. def GGML_OP_DIAG(self) -> int: ...
  105. @property
  106. def GGML_OP_DIAG_MASK_INF(self) -> int: ...
  107. @property
  108. def GGML_OP_DIAG_MASK_ZERO(self) -> int: ...
  109. @property
  110. def GGML_OP_DIV(self) -> int: ...
  111. @property
  112. def GGML_OP_DUP(self) -> int: ...
  113. @property
  114. def GGML_OP_FLASH_ATTN(self) -> int: ...
  115. @property
  116. def GGML_OP_FLASH_ATTN_BACK(self) -> int: ...
  117. @property
  118. def GGML_OP_FLASH_FF(self) -> int: ...
  119. @property
  120. def GGML_OP_GET_ROWS(self) -> int: ...
  121. @property
  122. def GGML_OP_GET_ROWS_BACK(self) -> int: ...
  123. @property
  124. def GGML_OP_LOG(self) -> int: ...
  125. @property
  126. def GGML_OP_MAP_BINARY(self) -> int: ...
  127. @property
  128. def GGML_OP_MAP_CUSTOM1(self) -> int: ...
  129. @property
  130. def GGML_OP_MAP_CUSTOM1_F32(self) -> int: ...
  131. @property
  132. def GGML_OP_MAP_CUSTOM2(self) -> int: ...
  133. @property
  134. def GGML_OP_MAP_CUSTOM2_F32(self) -> int: ...
  135. @property
  136. def GGML_OP_MAP_CUSTOM3(self) -> int: ...
  137. @property
  138. def GGML_OP_MAP_CUSTOM3_F32(self) -> int: ...
  139. @property
  140. def GGML_OP_MAP_UNARY(self) -> int: ...
  141. @property
  142. def GGML_OP_MEAN(self) -> int: ...
  143. @property
  144. def GGML_OP_MUL(self) -> int: ...
  145. @property
  146. def GGML_OP_MUL_MAT(self) -> int: ...
  147. @property
  148. def GGML_OP_NONE(self) -> int: ...
  149. @property
  150. def GGML_OP_NORM(self) -> int: ...
  151. @property
  152. def GGML_OP_OUT_PROD(self) -> int: ...
  153. @property
  154. def GGML_OP_PERMUTE(self) -> int: ...
  155. @property
  156. def GGML_OP_POOL_1D(self) -> int: ...
  157. @property
  158. def GGML_OP_POOL_2D(self) -> int: ...
  159. @property
  160. def GGML_OP_POOL_AVG(self) -> int: ...
  161. @property
  162. def GGML_OP_POOL_COUNT(self) -> int: ...
  163. @property
  164. def GGML_OP_POOL_MAX(self) -> int: ...
  165. @property
  166. def GGML_OP_REPEAT(self) -> int: ...
  167. @property
  168. def GGML_OP_REPEAT_BACK(self) -> int: ...
  169. @property
  170. def GGML_OP_RESHAPE(self) -> int: ...
  171. @property
  172. def GGML_OP_RMS_NORM(self) -> int: ...
  173. @property
  174. def GGML_OP_RMS_NORM_BACK(self) -> int: ...
  175. @property
  176. def GGML_OP_ROPE(self) -> int: ...
  177. @property
  178. def GGML_OP_ROPE_BACK(self) -> int: ...
  179. @property
  180. def GGML_OP_SCALE(self) -> int: ...
  181. @property
  182. def GGML_OP_SET(self) -> int: ...
  183. @property
  184. def GGML_OP_SILU_BACK(self) -> int: ...
  185. @property
  186. def GGML_OP_SOFT_MAX(self) -> int: ...
  187. @property
  188. def GGML_OP_SOFT_MAX_BACK(self) -> int: ...
  189. @property
  190. def GGML_OP_SQR(self) -> int: ...
  191. @property
  192. def GGML_OP_SQRT(self) -> int: ...
  193. @property
  194. def GGML_OP_SUB(self) -> int: ...
  195. @property
  196. def GGML_OP_SUM(self) -> int: ...
  197. @property
  198. def GGML_OP_SUM_ROWS(self) -> int: ...
  199. @property
  200. def GGML_OP_TRANSPOSE(self) -> int: ...
  201. @property
  202. def GGML_OP_UNARY(self) -> int: ...
  203. @property
  204. def GGML_OP_VIEW(self) -> int: ...
  205. @property
  206. def GGML_OP_WIN_PART(self) -> int: ...
  207. @property
  208. def GGML_OP_WIN_UNPART(self) -> int: ...
  209. @property
  210. def GGML_TASK_COMPUTE(self) -> int: ...
  211. @property
  212. def GGML_TASK_FINALIZE(self) -> int: ...
  213. @property
  214. def GGML_TASK_INIT(self) -> int: ...
  215. @property
  216. def GGML_TYPE_COUNT(self) -> int: ...
  217. @property
  218. def GGML_TYPE_F16(self) -> int: ...
  219. @property
  220. def GGML_TYPE_F32(self) -> int: ...
  221. @property
  222. def GGML_TYPE_I16(self) -> int: ...
  223. @property
  224. def GGML_TYPE_I32(self) -> int: ...
  225. @property
  226. def GGML_TYPE_I8(self) -> int: ...
  227. @property
  228. def GGML_TYPE_Q2_K(self) -> int: ...
  229. @property
  230. def GGML_TYPE_Q3_K(self) -> int: ...
  231. @property
  232. def GGML_TYPE_Q4_0(self) -> int: ...
  233. @property
  234. def GGML_TYPE_Q4_1(self) -> int: ...
  235. @property
  236. def GGML_TYPE_Q4_K(self) -> int: ...
  237. @property
  238. def GGML_TYPE_Q5_0(self) -> int: ...
  239. @property
  240. def GGML_TYPE_Q5_1(self) -> int: ...
  241. @property
  242. def GGML_TYPE_Q5_K(self) -> int: ...
  243. @property
  244. def GGML_TYPE_Q6_K(self) -> int: ...
  245. @property
  246. def GGML_TYPE_Q8_0(self) -> int: ...
  247. @property
  248. def GGML_TYPE_Q8_1(self) -> int: ...
  249. @property
  250. def GGML_TYPE_Q8_K(self) -> int: ...
  251. @property
  252. def GGML_UNARY_OP_ABS(self) -> int: ...
  253. @property
  254. def GGML_UNARY_OP_ELU(self) -> int: ...
  255. @property
  256. def GGML_UNARY_OP_GELU(self) -> int: ...
  257. @property
  258. def GGML_UNARY_OP_GELU_QUICK(self) -> int: ...
  259. @property
  260. def GGML_UNARY_OP_NEG(self) -> int: ...
  261. @property
  262. def GGML_UNARY_OP_RELU(self) -> int: ...
  263. @property
  264. def GGML_UNARY_OP_SGN(self) -> int: ...
  265. @property
  266. def GGML_UNARY_OP_SILU(self) -> int: ...
  267. @property
  268. def GGML_UNARY_OP_STEP(self) -> int: ...
  269. @property
  270. def GGML_UNARY_OP_TANH(self) -> int: ...
  271. @property
  272. def GGUF_TYPE_ARRAY(self) -> int: ...
  273. @property
  274. def GGUF_TYPE_BOOL(self) -> int: ...
  275. @property
  276. def GGUF_TYPE_COUNT(self) -> int: ...
  277. @property
  278. def GGUF_TYPE_FLOAT32(self) -> int: ...
  279. @property
  280. def GGUF_TYPE_INT16(self) -> int: ...
  281. @property
  282. def GGUF_TYPE_INT32(self) -> int: ...
  283. @property
  284. def GGUF_TYPE_INT8(self) -> int: ...
  285. @property
  286. def GGUF_TYPE_STRING(self) -> int: ...
  287. @property
  288. def GGUF_TYPE_UINT16(self) -> int: ...
  289. @property
  290. def GGUF_TYPE_UINT32(self) -> int: ...
  291. @property
  292. def GGUF_TYPE_UINT8(self) -> int: ...
  293. def abort_callback(data: ffi.CData) -> bool:
  294. """
  295. abort ggml_graph_compute when true
  296. bool (*abort_callback)(void * data);
  297. """
  298. ...
  299. def dequantize_row_q2_K(x: ffi.CData, y: ffi.CData, k: int) -> None:
  300. """
  301. Dequantization
  302. void dequantize_row_q2_K(const block_q2_K * restrict x, float * restrict y, int k);
  303. """
  304. ...
  305. def dequantize_row_q3_K(x: ffi.CData, y: ffi.CData, k: int) -> None:
  306. """void dequantize_row_q3_K(const block_q3_K * restrict x, float * restrict y, int k);"""
  307. ...
  308. def dequantize_row_q4_K(x: ffi.CData, y: ffi.CData, k: int) -> None:
  309. """void dequantize_row_q4_K(const block_q4_K * restrict x, float * restrict y, int k);"""
  310. ...
  311. def dequantize_row_q5_K(x: ffi.CData, y: ffi.CData, k: int) -> None:
  312. """void dequantize_row_q5_K(const block_q5_K * restrict x, float * restrict y, int k);"""
  313. ...
  314. def dequantize_row_q6_K(x: ffi.CData, y: ffi.CData, k: int) -> None:
  315. """void dequantize_row_q6_K(const block_q6_K * restrict x, float * restrict y, int k);"""
  316. ...
  317. def dequantize_row_q8_K(x: ffi.CData, y: ffi.CData, k: int) -> None:
  318. """void dequantize_row_q8_K(const block_q8_K * restrict x, float * restrict y, int k);"""
  319. ...
  320. def ggml_abs(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  321. """
  322. GGML_API struct ggml_tensor * ggml_abs(
  323. struct ggml_context * ctx,
  324. struct ggml_tensor * a);
  325. """
  326. ...
  327. def ggml_abs_inplace(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  328. """
  329. GGML_API struct ggml_tensor * ggml_abs_inplace(
  330. struct ggml_context * ctx,
  331. struct ggml_tensor * a);
  332. """
  333. ...
  334. def ggml_acc(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, nb1: int, nb2: int, nb3: int, offset: int) -> ffi.CData:
  335. """
  336. GGML_API struct ggml_tensor * ggml_acc(
  337. struct ggml_context * ctx,
  338. struct ggml_tensor * a,
  339. struct ggml_tensor * b,
  340. size_t nb1,
  341. size_t nb2,
  342. size_t nb3,
  343. size_t offset);
  344. """
  345. ...
  346. def ggml_acc_inplace(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, nb1: int, nb2: int, nb3: int, offset: int) -> ffi.CData:
  347. """
  348. GGML_API struct ggml_tensor * ggml_acc_inplace(
  349. struct ggml_context * ctx,
  350. struct ggml_tensor * a,
  351. struct ggml_tensor * b,
  352. size_t nb1,
  353. size_t nb2,
  354. size_t nb3,
  355. size_t offset);
  356. """
  357. ...
  358. def ggml_add(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  359. """
  360. GGML_API struct ggml_tensor * ggml_add(
  361. struct ggml_context * ctx,
  362. struct ggml_tensor * a,
  363. struct ggml_tensor * b);
  364. """
  365. ...
  366. def ggml_add1(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  367. """
  368. GGML_API struct ggml_tensor * ggml_add1(
  369. struct ggml_context * ctx,
  370. struct ggml_tensor * a,
  371. struct ggml_tensor * b);
  372. """
  373. ...
  374. def ggml_add1_inplace(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  375. """
  376. GGML_API struct ggml_tensor * ggml_add1_inplace(
  377. struct ggml_context * ctx,
  378. struct ggml_tensor * a,
  379. struct ggml_tensor * b);
  380. """
  381. ...
  382. def ggml_add_inplace(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  383. """
  384. GGML_API struct ggml_tensor * ggml_add_inplace(
  385. struct ggml_context * ctx,
  386. struct ggml_tensor * a,
  387. struct ggml_tensor * b);
  388. """
  389. ...
  390. def ggml_alibi(ctx: ffi.CData, a: ffi.CData, n_past: int, n_head: int, bias_max: float) -> ffi.CData:
  391. """
  392. alibi position embedding
  393. in-place, returns view(a)
  394. struct ggml_tensor * ggml_alibi(
  395. struct ggml_context * ctx,
  396. struct ggml_tensor * a,
  397. int n_past,
  398. int n_head,
  399. float bias_max);
  400. """
  401. ...
  402. def ggml_allocr_alloc(alloc: ffi.CData, tensor: ffi.CData) -> None:
  403. """GGML_API void ggml_allocr_alloc(struct ggml_allocr * alloc, struct ggml_tensor * tensor);"""
  404. ...
  405. def ggml_allocr_alloc_graph(alloc: ffi.CData, graph: ffi.CData) -> int:
  406. """GGML_API size_t ggml_allocr_alloc_graph(struct ggml_allocr * alloc, struct ggml_cgraph * graph);"""
  407. ...
  408. def ggml_allocr_free(alloc: ffi.CData) -> None:
  409. """GGML_API void ggml_allocr_free(struct ggml_allocr * alloc);"""
  410. ...
  411. def ggml_allocr_is_measure(alloc: ffi.CData) -> bool:
  412. """GGML_API bool ggml_allocr_is_measure(struct ggml_allocr * alloc);"""
  413. ...
  414. def ggml_allocr_new(data: ffi.CData, size: int, alignment: int) -> ffi.CData:
  415. """GGML_API struct ggml_allocr * ggml_allocr_new(void * data, size_t size, size_t alignment);"""
  416. ...
  417. def ggml_allocr_new_measure(alignment: int) -> ffi.CData:
  418. """GGML_API struct ggml_allocr * ggml_allocr_new_measure(size_t alignment);"""
  419. ...
  420. def ggml_allocr_reset(alloc: ffi.CData) -> None:
  421. """GGML_API void ggml_allocr_reset(struct ggml_allocr * alloc);"""
  422. ...
  423. def ggml_allocr_set_parse_seq(alloc: ffi.CData, list: ffi.CData, n: int) -> None:
  424. """
  425. tell the allocator to parse nodes following the order described in the list
  426. you should call this if your graph are optimized to execute out-of-order
  427. GGML_API void ggml_allocr_set_parse_seq(struct ggml_allocr * alloc, int * list, int n);
  428. """
  429. ...
  430. def ggml_are_same_shape(t0: ffi.CData, t1: ffi.CData) -> bool:
  431. """ GGML_API bool ggml_are_same_shape(const struct ggml_tensor * t0, const struct ggml_tensor * t1);"""
  432. ...
  433. def ggml_argmax(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  434. """
  435. argmax along rows
  436. GGML_API struct ggml_tensor * ggml_argmax(
  437. struct ggml_context * ctx,
  438. struct ggml_tensor * a);
  439. """
  440. ...
  441. def ggml_blck_size(type: int) -> int:
  442. """ GGML_API int ggml_blck_size (enum ggml_type type);"""
  443. ...
  444. def ggml_build_backward(ctx: ffi.CData, gf: ffi.CData, keep: bool) -> ffi.CData:
  445. """ GGML_API struct ggml_cgraph ggml_build_backward(struct ggml_context * ctx, struct ggml_cgraph * gf, bool keep);"""
  446. ...
  447. def ggml_build_forward(tensor: ffi.CData) -> ffi.CData:
  448. """ GGML_API struct ggml_cgraph ggml_build_forward (struct ggml_tensor * tensor);"""
  449. ...
  450. def ggml_build_forward_ctx(ctx: ffi.CData, tensor: ffi.CData) -> ffi.CData:
  451. """ GGML_API struct ggml_cgraph * ggml_build_forward_ctx(struct ggml_context * ctx, struct ggml_tensor * tensor);"""
  452. ...
  453. def ggml_build_forward_expand(cgraph: ffi.CData, tensor: ffi.CData) -> None:
  454. """ GGML_API void ggml_build_forward_expand(struct ggml_cgraph * cgraph, struct ggml_tensor * tensor);"""
  455. ...
  456. def ggml_cl_can_mul_mat(src0: ffi.CData, src1: ffi.CData, dst: ffi.CData) -> bool:
  457. """bool ggml_cl_can_mul_mat(const struct ggml_tensor * src0, const struct ggml_tensor * src1, struct ggml_tensor * dst);"""
  458. ...
  459. def ggml_cl_free_data(tensor: ffi.CData) -> None:
  460. """void ggml_cl_free_data(const struct ggml_tensor* tensor);"""
  461. ...
  462. def ggml_cl_host_free(ptr: ffi.CData) -> None:
  463. """void ggml_cl_host_free(void * ptr);"""
  464. ...
  465. def ggml_cl_host_malloc(size: int) -> ffi.CData:
  466. """void * ggml_cl_host_malloc(size_t size);"""
  467. ...
  468. def ggml_cl_init() -> None:
  469. """void ggml_cl_init(void);"""
  470. ...
  471. def ggml_cl_mul(src0: ffi.CData, src1: ffi.CData, dst: ffi.CData) -> None:
  472. """void ggml_cl_mul(const struct ggml_tensor * src0, const struct ggml_tensor * src1, struct ggml_tensor * dst);"""
  473. ...
  474. def ggml_cl_mul_mat(src0: ffi.CData, src1: ffi.CData, dst: ffi.CData, wdata: ffi.CData, wsize: int) -> None:
  475. """void ggml_cl_mul_mat(const struct ggml_tensor * src0, const struct ggml_tensor * src1, struct ggml_tensor * dst, void * wdata, size_t wsize);"""
  476. ...
  477. def ggml_cl_mul_mat_get_wsize(src0: ffi.CData, src1: ffi.CData, dst: ffi.CData) -> int:
  478. """size_t ggml_cl_mul_mat_get_wsize(const struct ggml_tensor * src0, const struct ggml_tensor * src1, struct ggml_tensor * dst);"""
  479. ...
  480. def ggml_cl_transform_tensor(data: ffi.CData, tensor: ffi.CData) -> None:
  481. """void ggml_cl_transform_tensor(void * data, struct ggml_tensor * tensor);"""
  482. ...
  483. def ggml_clamp(ctx: ffi.CData, a: ffi.CData, min: float, max: float) -> ffi.CData:
  484. """
  485. clamp
  486. in-place, returns view(a)
  487. struct ggml_tensor * ggml_clamp(
  488. struct ggml_context * ctx,
  489. struct ggml_tensor * a,
  490. float min,
  491. float max);
  492. """
  493. ...
  494. def ggml_cont(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  495. """
  496. make contiguous
  497. GGML_API struct ggml_tensor * ggml_cont(
  498. struct ggml_context * ctx,
  499. struct ggml_tensor * a);
  500. """
  501. ...
  502. def ggml_cont_inplace(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  503. """
  504. make contiguous, in-place
  505. GGML_API struct ggml_tensor * ggml_cont_inplace(
  506. struct ggml_context * ctx,
  507. struct ggml_tensor * a);
  508. """
  509. ...
  510. def ggml_conv_1d(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, s0: int, p0: int, d0: int) -> ffi.CData:
  511. """
  512. GGML_API struct ggml_tensor * ggml_conv_1d(
  513. struct ggml_context * ctx,
  514. struct ggml_tensor * a,
  515. struct ggml_tensor * b,
  516. int s0, // stride
  517. int p0, // padding
  518. int d0); // dilation
  519. """
  520. ...
  521. def ggml_conv_1d_ph(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, s: int, d: int) -> ffi.CData:
  522. """
  523. conv_1d with padding = half
  524. alias for ggml_conv_1d(a, b, s, a->ne[0]/2, d)
  525. GGML_API struct ggml_tensor * ggml_conv_1d_ph(
  526. struct ggml_context * ctx,
  527. struct ggml_tensor * a,
  528. struct ggml_tensor * b,
  529. int s,
  530. int d);
  531. """
  532. ...
  533. def ggml_conv_2d(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, s0: int, s1: int, p0: int, p1: int, d0: int, d1: int) -> ffi.CData:
  534. """
  535. GGML_API struct ggml_tensor * ggml_conv_2d(
  536. struct ggml_context * ctx,
  537. struct ggml_tensor * a,
  538. struct ggml_tensor * b,
  539. int s0,
  540. int s1,
  541. int p0,
  542. int p1,
  543. int d0,
  544. int d1);
  545. """
  546. ...
  547. def ggml_cpu_has_arm_fma() -> int:
  548. """ GGML_API int ggml_cpu_has_arm_fma (void);"""
  549. ...
  550. def ggml_cpu_has_avx() -> int:
  551. """ GGML_API int ggml_cpu_has_avx (void);"""
  552. ...
  553. def ggml_cpu_has_avx2() -> int:
  554. """ GGML_API int ggml_cpu_has_avx2 (void);"""
  555. ...
  556. def ggml_cpu_has_avx512() -> int:
  557. """ GGML_API int ggml_cpu_has_avx512 (void);"""
  558. ...
  559. def ggml_cpu_has_avx512_vbmi() -> int:
  560. """ GGML_API int ggml_cpu_has_avx512_vbmi(void);"""
  561. ...
  562. def ggml_cpu_has_avx512_vnni() -> int:
  563. """ GGML_API int ggml_cpu_has_avx512_vnni(void);"""
  564. ...
  565. def ggml_cpu_has_blas() -> int:
  566. """ GGML_API int ggml_cpu_has_blas (void);"""
  567. ...
  568. def ggml_cpu_has_clblast() -> int:
  569. """ GGML_API int ggml_cpu_has_clblast (void);"""
  570. ...
  571. def ggml_cpu_has_cublas() -> int:
  572. """ GGML_API int ggml_cpu_has_cublas (void);"""
  573. ...
  574. def ggml_cpu_has_f16c() -> int:
  575. """ GGML_API int ggml_cpu_has_f16c (void);"""
  576. ...
  577. def ggml_cpu_has_fma() -> int:
  578. """ GGML_API int ggml_cpu_has_fma (void);"""
  579. ...
  580. def ggml_cpu_has_fp16_va() -> int:
  581. """ GGML_API int ggml_cpu_has_fp16_va (void);"""
  582. ...
  583. def ggml_cpu_has_gpublas() -> int:
  584. """ GGML_API int ggml_cpu_has_gpublas (void);"""
  585. ...
  586. def ggml_cpu_has_neon() -> int:
  587. """ GGML_API int ggml_cpu_has_neon (void);"""
  588. ...
  589. def ggml_cpu_has_sse3() -> int:
  590. """ GGML_API int ggml_cpu_has_sse3 (void);"""
  591. ...
  592. def ggml_cpu_has_vsx() -> int:
  593. """ GGML_API int ggml_cpu_has_vsx (void);"""
  594. ...
  595. def ggml_cpu_has_wasm_simd() -> int:
  596. """ GGML_API int ggml_cpu_has_wasm_simd (void);"""
  597. ...
  598. def ggml_cpy(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  599. """
  600. a -> b, return view(b)
  601. GGML_API struct ggml_tensor * ggml_cpy(
  602. struct ggml_context * ctx,
  603. struct ggml_tensor * a,
  604. struct ggml_tensor * b);
  605. """
  606. ...
  607. def ggml_cpy_inplace(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  608. """
  609. a -> b, in-place, return view(b)
  610. GGML_API struct ggml_tensor * ggml_cpy_inplace(
  611. struct ggml_context * ctx,
  612. struct ggml_tensor * a,
  613. struct ggml_tensor * b);
  614. """
  615. ...
  616. def ggml_cross_entropy_loss(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  617. """
  618. GGML_API struct ggml_tensor * ggml_cross_entropy_loss(
  619. struct ggml_context * ctx,
  620. struct ggml_tensor * a,
  621. struct ggml_tensor * b);
  622. """
  623. ...
  624. def ggml_cross_entropy_loss_back(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, c: ffi.CData) -> ffi.CData:
  625. """
  626. GGML_API struct ggml_tensor * ggml_cross_entropy_loss_back(
  627. struct ggml_context * ctx,
  628. struct ggml_tensor * a,
  629. struct ggml_tensor * b,
  630. struct ggml_tensor * c);
  631. """
  632. ...
  633. def ggml_cuda_assign_buffers(tensor: ffi.CData) -> None:
  634. """GGML_API void ggml_cuda_assign_buffers(struct ggml_tensor * tensor);"""
  635. ...
  636. def ggml_cuda_assign_buffers_force_inplace(tensor: ffi.CData) -> None:
  637. """GGML_API void ggml_cuda_assign_buffers_force_inplace(struct ggml_tensor * tensor);"""
  638. ...
  639. def ggml_cuda_assign_buffers_no_scratch(tensor: ffi.CData) -> None:
  640. """GGML_API void ggml_cuda_assign_buffers_no_scratch(struct ggml_tensor * tensor);"""
  641. ...
  642. def ggml_cuda_can_mul_mat(src0: ffi.CData, src1: ffi.CData, dst: ffi.CData) -> bool:
  643. """GGML_API bool ggml_cuda_can_mul_mat(const struct ggml_tensor * src0, const struct ggml_tensor * src1, struct ggml_tensor * dst);"""
  644. ...
  645. def ggml_cuda_compute_forward(params: ffi.CData, tensor: ffi.CData) -> bool:
  646. """GGML_API bool ggml_cuda_compute_forward(struct ggml_compute_params * params, struct ggml_tensor * tensor);"""
  647. ...
  648. def ggml_cuda_free_data(tensor: ffi.CData) -> None:
  649. """GGML_API void ggml_cuda_free_data(struct ggml_tensor * tensor);"""
  650. ...
  651. def ggml_cuda_free_scratch() -> None:
  652. """GGML_API void ggml_cuda_free_scratch(void);"""
  653. ...
  654. def ggml_cuda_get_device_count() -> int:
  655. """GGML_API int ggml_cuda_get_device_count(void);"""
  656. ...
  657. def ggml_cuda_get_device_description(device: int, description: ffi.CData, description_size: int) -> None:
  658. """GGML_API void ggml_cuda_get_device_description(int device, char * description, size_t description_size);"""
  659. ...
  660. def ggml_cuda_host_free(ptr: ffi.CData) -> None:
  661. """GGML_API void ggml_cuda_host_free(void * ptr);"""
  662. ...
  663. def ggml_cuda_host_malloc(size: int) -> ffi.CData:
  664. """GGML_API void * ggml_cuda_host_malloc(size_t size);"""
  665. ...
  666. def ggml_cuda_set_main_device(main_device: int) -> None:
  667. """GGML_API void ggml_cuda_set_main_device(int main_device);"""
  668. ...
  669. def ggml_cuda_set_mul_mat_q(mul_mat_q: bool) -> None:
  670. """GGML_API void ggml_cuda_set_mul_mat_q(bool mul_mat_q);"""
  671. ...
  672. def ggml_cuda_set_scratch_size(scratch_size: int) -> None:
  673. """GGML_API void ggml_cuda_set_scratch_size(size_t scratch_size);"""
  674. ...
  675. def ggml_cuda_set_tensor_split(tensor_split: ffi.CData) -> None:
  676. """GGML_API void ggml_cuda_set_tensor_split(const float * tensor_split);"""
  677. ...
  678. def ggml_cuda_transform_tensor(data: ffi.CData, tensor: ffi.CData) -> None:
  679. """GGML_API void ggml_cuda_transform_tensor(void * data, struct ggml_tensor * tensor);"""
  680. ...
  681. def ggml_cycles() -> int:
  682. """ GGML_API int64_t ggml_cycles(void);"""
  683. ...
  684. def ggml_cycles_per_ms() -> int:
  685. """ GGML_API int64_t ggml_cycles_per_ms(void);"""
  686. ...
  687. def ggml_diag(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  688. """
  689. GGML_API struct ggml_tensor * ggml_diag(
  690. struct ggml_context * ctx,
  691. struct ggml_tensor * a);
  692. """
  693. ...
  694. def ggml_diag_mask_inf(ctx: ffi.CData, a: ffi.CData, n_past: int) -> ffi.CData:
  695. """
  696. set elements above the diagonal to -INF
  697. GGML_API struct ggml_tensor * ggml_diag_mask_inf(
  698. struct ggml_context * ctx,
  699. struct ggml_tensor * a,
  700. int n_past);
  701. """
  702. ...
  703. def ggml_diag_mask_inf_inplace(ctx: ffi.CData, a: ffi.CData, n_past: int) -> ffi.CData:
  704. """
  705. in-place, returns view(a)
  706. GGML_API struct ggml_tensor * ggml_diag_mask_inf_inplace(
  707. struct ggml_context * ctx,
  708. struct ggml_tensor * a,
  709. int n_past);
  710. """
  711. ...
  712. def ggml_diag_mask_zero(ctx: ffi.CData, a: ffi.CData, n_past: int) -> ffi.CData:
  713. """
  714. set elements above the diagonal to 0
  715. GGML_API struct ggml_tensor * ggml_diag_mask_zero(
  716. struct ggml_context * ctx,
  717. struct ggml_tensor * a,
  718. int n_past);
  719. """
  720. ...
  721. def ggml_diag_mask_zero_inplace(ctx: ffi.CData, a: ffi.CData, n_past: int) -> ffi.CData:
  722. """
  723. in-place, returns view(a)
  724. GGML_API struct ggml_tensor * ggml_diag_mask_zero_inplace(
  725. struct ggml_context * ctx,
  726. struct ggml_tensor * a,
  727. int n_past);
  728. """
  729. ...
  730. def ggml_div(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  731. """
  732. GGML_API struct ggml_tensor * ggml_div(
  733. struct ggml_context * ctx,
  734. struct ggml_tensor * a,
  735. struct ggml_tensor * b);
  736. """
  737. ...
  738. def ggml_div_inplace(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  739. """
  740. GGML_API struct ggml_tensor * ggml_div_inplace(
  741. struct ggml_context * ctx,
  742. struct ggml_tensor * a,
  743. struct ggml_tensor * b);
  744. """
  745. ...
  746. def ggml_dup(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  747. """
  748. GGML_API struct ggml_tensor * ggml_dup(
  749. struct ggml_context * ctx,
  750. struct ggml_tensor * a);
  751. """
  752. ...
  753. def ggml_dup_inplace(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  754. """
  755. in-place, returns view(a)
  756. GGML_API struct ggml_tensor * ggml_dup_inplace(
  757. struct ggml_context * ctx,
  758. struct ggml_tensor * a);
  759. """
  760. ...
  761. def ggml_dup_tensor(ctx: ffi.CData, src: ffi.CData) -> ffi.CData:
  762. """ GGML_API struct ggml_tensor * ggml_dup_tensor (struct ggml_context * ctx, const struct ggml_tensor * src);"""
  763. ...
  764. def ggml_element_size(tensor: ffi.CData) -> int:
  765. """ GGML_API size_t ggml_element_size(const struct ggml_tensor * tensor);"""
  766. ...
  767. def ggml_elu(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  768. """
  769. GGML_API struct ggml_tensor * ggml_elu(
  770. struct ggml_context * ctx,
  771. struct ggml_tensor * a);
  772. """
  773. ...
  774. def ggml_elu_inplace(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  775. """
  776. GGML_API struct ggml_tensor * ggml_elu_inplace(
  777. struct ggml_context * ctx,
  778. struct ggml_tensor * a);
  779. """
  780. ...
  781. def ggml_flash_attn(ctx: ffi.CData, q: ffi.CData, k: ffi.CData, v: ffi.CData, masked: bool) -> ffi.CData:
  782. """
  783. GGML_API struct ggml_tensor * ggml_flash_attn(
  784. struct ggml_context * ctx,
  785. struct ggml_tensor * q,
  786. struct ggml_tensor * k,
  787. struct ggml_tensor * v,
  788. bool masked);
  789. """
  790. ...
  791. def ggml_flash_attn_back(ctx: ffi.CData, q: ffi.CData, k: ffi.CData, v: ffi.CData, d: ffi.CData, masked: bool) -> ffi.CData:
  792. """
  793. GGML_API struct ggml_tensor * ggml_flash_attn_back(
  794. struct ggml_context * ctx,
  795. struct ggml_tensor * q,
  796. struct ggml_tensor * k,
  797. struct ggml_tensor * v,
  798. struct ggml_tensor * d,
  799. bool masked);
  800. """
  801. ...
  802. def ggml_flash_ff(ctx: ffi.CData, a: ffi.CData, b0: ffi.CData, b1: ffi.CData, c0: ffi.CData, c1: ffi.CData) -> ffi.CData:
  803. """
  804. GGML_API struct ggml_tensor * ggml_flash_ff(
  805. struct ggml_context * ctx,
  806. struct ggml_tensor * a,
  807. struct ggml_tensor * b0,
  808. struct ggml_tensor * b1,
  809. struct ggml_tensor * c0,
  810. struct ggml_tensor * c1);
  811. """
  812. ...
  813. def ggml_format_name(tensor: ffi.CData, fmt: ffi.CData, *args2) -> ffi.CData:
  814. """ GGML_API struct ggml_tensor * ggml_format_name( struct ggml_tensor * tensor, const char * fmt, ...);"""
  815. ...
  816. def ggml_fp16_to_fp32(x: np.float16) -> float:
  817. """
  818. convert FP16 <-> FP32
  819. GGML_API float ggml_fp16_to_fp32(ggml_fp16_t x);
  820. """
  821. ...
  822. def ggml_fp16_to_fp32_row(x: ffi.CData, y: ffi.CData, n: int) -> None:
  823. """ GGML_API void ggml_fp16_to_fp32_row(const ggml_fp16_t * x, float * y, int n);"""
  824. ...
  825. def ggml_fp32_to_fp16(x: float) -> np.float16:
  826. """ GGML_API ggml_fp16_t ggml_fp32_to_fp16(float x);"""
  827. ...
  828. def ggml_fp32_to_fp16_row(x: ffi.CData, y: ffi.CData, n: int) -> None:
  829. """ GGML_API void ggml_fp32_to_fp16_row(const float * x, ggml_fp16_t * y, int n);"""
  830. ...
  831. def ggml_free(ctx: ffi.CData) -> None:
  832. """ GGML_API void ggml_free(struct ggml_context * ctx);"""
  833. ...
  834. def ggml_ftype_to_ggml_type(ftype: int) -> int:
  835. """
  836. TODO: temporary until model loading of ggml examples is refactored
  837. GGML_API enum ggml_type ggml_ftype_to_ggml_type(enum ggml_ftype ftype);
  838. """
  839. ...
  840. def ggml_gelu(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  841. """
  842. TODO: double-check this computation is correct
  843. GGML_API struct ggml_tensor * ggml_gelu(
  844. struct ggml_context * ctx,
  845. struct ggml_tensor * a);
  846. """
  847. ...
  848. def ggml_gelu_inplace(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  849. """
  850. GGML_API struct ggml_tensor * ggml_gelu_inplace(
  851. struct ggml_context * ctx,
  852. struct ggml_tensor * a);
  853. """
  854. ...
  855. def ggml_gelu_quick(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  856. """
  857. GGML_API struct ggml_tensor * ggml_gelu_quick(
  858. struct ggml_context * ctx,
  859. struct ggml_tensor * a);
  860. """
  861. ...
  862. def ggml_gelu_quick_inplace(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  863. """
  864. GGML_API struct ggml_tensor * ggml_gelu_quick_inplace(
  865. struct ggml_context * ctx,
  866. struct ggml_tensor * a);
  867. """
  868. ...
  869. def ggml_get_data(tensor: ffi.CData) -> ffi.CData:
  870. """ GGML_API void * ggml_get_data (const struct ggml_tensor * tensor);"""
  871. ...
  872. def ggml_get_data_f32(tensor: ffi.CData) -> ffi.CData:
  873. """ GGML_API float * ggml_get_data_f32(const struct ggml_tensor * tensor);"""
  874. ...
  875. def ggml_get_f32_1d(tensor: ffi.CData, i: int) -> float:
  876. """ GGML_API float ggml_get_f32_1d(const struct ggml_tensor * tensor, int i);"""
  877. ...
  878. def ggml_get_i32_1d(tensor: ffi.CData, i: int) -> int:
  879. """ GGML_API int32_t ggml_get_i32_1d(const struct ggml_tensor * tensor, int i);"""
  880. ...
  881. def ggml_get_max_tensor_size(ctx: ffi.CData) -> int:
  882. """ GGML_API size_t ggml_get_max_tensor_size(const struct ggml_context * ctx);"""
  883. ...
  884. def ggml_get_mem_buffer(ctx: ffi.CData) -> ffi.CData:
  885. """ GGML_API void * ggml_get_mem_buffer (const struct ggml_context * ctx);"""
  886. ...
  887. def ggml_get_mem_size(ctx: ffi.CData) -> int:
  888. """ GGML_API size_t ggml_get_mem_size (const struct ggml_context * ctx);"""
  889. ...
  890. def ggml_get_name(tensor: ffi.CData) -> ffi.CData:
  891. """ GGML_API const char * ggml_get_name (const struct ggml_tensor * tensor);"""
  892. ...
  893. def ggml_get_no_alloc(ctx: ffi.CData) -> bool:
  894. """ GGML_API bool ggml_get_no_alloc(struct ggml_context * ctx);"""
  895. ...
  896. def ggml_get_rows(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  897. """
  898. GGML_API struct ggml_tensor * ggml_get_rows(
  899. struct ggml_context * ctx,
  900. struct ggml_tensor * a,
  901. struct ggml_tensor * b);
  902. """
  903. ...
  904. def ggml_get_rows_back(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, c: ffi.CData) -> ffi.CData:
  905. """
  906. GGML_API struct ggml_tensor * ggml_get_rows_back(
  907. struct ggml_context * ctx,
  908. struct ggml_tensor * a,
  909. struct ggml_tensor * b,
  910. struct ggml_tensor * c);
  911. """
  912. ...
  913. def ggml_get_tensor(ctx: ffi.CData, name: ffi.CData) -> ffi.CData:
  914. """ GGML_API struct ggml_tensor * ggml_get_tensor(struct ggml_context * ctx, const char * name);"""
  915. ...
  916. def ggml_get_unary_op(tensor: ffi.CData) -> int:
  917. """ GGML_API enum ggml_unary_op ggml_get_unary_op(const struct ggml_tensor * tensor);"""
  918. ...
  919. def ggml_graph_compute(cgraph: ffi.CData, cplan: ffi.CData) -> int:
  920. """ GGML_API int ggml_graph_compute(struct ggml_cgraph * cgraph, struct ggml_cplan * cplan);"""
  921. ...
  922. def ggml_graph_compute_with_ctx(ctx: ffi.CData, cgraph: ffi.CData, n_threads: int) -> None:
  923. """
  924. same as ggml_graph_compute() but the work data is allocated as a part of the context
  925. note: the drawback of this API is that you must have ensured that the context has enough memory for the work data
  926. GGML_API void ggml_graph_compute_with_ctx(struct ggml_context * ctx, struct ggml_cgraph * cgraph, int n_threads);
  927. """
  928. ...
  929. def ggml_graph_dump_dot(gb: ffi.CData, gf: ffi.CData, filename: ffi.CData) -> None:
  930. """
  931. dump the graph into a file using the dot format
  932. GGML_API void ggml_graph_dump_dot(const struct ggml_cgraph * gb, const struct ggml_cgraph * gf, const char * filename);
  933. """
  934. ...
  935. def ggml_graph_export(cgraph: ffi.CData, fname: ffi.CData) -> None:
  936. """ GGML_API void ggml_graph_export(const struct ggml_cgraph * cgraph, const char * fname);"""
  937. ...
  938. def ggml_graph_get_tensor(cgraph: ffi.CData, name: ffi.CData) -> ffi.CData:
  939. """ GGML_API struct ggml_tensor * ggml_graph_get_tensor(struct ggml_cgraph * cgraph, const char * name);"""
  940. ...
  941. def ggml_graph_import(fname: ffi.CData, ctx_data: ffi.CData, ctx_eval: ffi.CData) -> ffi.CData:
  942. """ GGML_API struct ggml_cgraph ggml_graph_import(const char * fname, struct ggml_context ** ctx_data, struct ggml_context ** ctx_eval);"""
  943. ...
  944. def ggml_graph_overhead() -> int:
  945. """ GGML_API size_t ggml_graph_overhead(void);"""
  946. ...
  947. def ggml_graph_plan(cgraph: ffi.CData, n_threads: int) -> ffi.CData:
  948. """
  949. ggml_graph_plan() has to be called before ggml_graph_compute()
  950. when plan.work_size > 0, caller must allocate memory for plan.work_data
  951. GGML_API struct ggml_cplan ggml_graph_plan (struct ggml_cgraph * cgraph, int n_threads /*= GGML_DEFAULT_N_THREADS*/);
  952. """
  953. ...
  954. def ggml_graph_print(cgraph: ffi.CData) -> None:
  955. """
  956. print info and performance information for the graph
  957. GGML_API void ggml_graph_print(const struct ggml_cgraph * cgraph);
  958. """
  959. ...
  960. def ggml_graph_reset(cgraph: ffi.CData) -> None:
  961. """ GGML_API void ggml_graph_reset (struct ggml_cgraph * cgraph);"""
  962. ...
  963. def ggml_init(params: ffi.CData) -> ffi.CData:
  964. """ GGML_API struct ggml_context * ggml_init(struct ggml_init_params params);"""
  965. ...
  966. def ggml_init_cublas() -> None:
  967. """GGML_API void ggml_init_cublas(void);"""
  968. ...
  969. def ggml_internal_get_type_traits(type: int) -> ffi.CData:
  970. """ ggml_type_traits_t ggml_internal_get_type_traits(enum ggml_type type);"""
  971. ...
  972. def ggml_is_contiguous(tensor: ffi.CData) -> bool:
  973. """ GGML_API bool ggml_is_contiguous(const struct ggml_tensor * tensor);"""
  974. ...
  975. def ggml_is_numa() -> bool:
  976. """ GGML_API bool ggml_is_numa(void); // true if init detected that system has >1 NUMA node"""
  977. ...
  978. def ggml_is_permuted(tensor: ffi.CData) -> bool:
  979. """ GGML_API bool ggml_is_permuted (const struct ggml_tensor * tensor);"""
  980. ...
  981. def ggml_is_quantized(type: int) -> bool:
  982. """ GGML_API bool ggml_is_quantized(enum ggml_type type);"""
  983. ...
  984. def ggml_is_transposed(tensor: ffi.CData) -> bool:
  985. """ GGML_API bool ggml_is_transposed(const struct ggml_tensor * tensor);"""
  986. ...
  987. def ggml_log(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  988. """
  989. GGML_API struct ggml_tensor * ggml_log(
  990. struct ggml_context * ctx,
  991. struct ggml_tensor * a);
  992. """
  993. ...
  994. def ggml_log_inplace(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  995. """
  996. GGML_API struct ggml_tensor * ggml_log_inplace(
  997. struct ggml_context * ctx,
  998. struct ggml_tensor * a);
  999. """
  1000. ...
  1001. def ggml_map_binary_f32(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, fun: ffi.CData) -> ffi.CData:
  1002. """
  1003. GGML_DEPRECATED(GGML_API struct ggml_tensor * ggml_map_binary_f32(
  1004. struct ggml_context * ctx,
  1005. struct ggml_tensor * a,
  1006. struct ggml_tensor * b,
  1007. ggml_binary_op_f32_t fun),
  1008. "use ggml_map_custom2 instead");
  1009. """
  1010. ...
  1011. def ggml_map_binary_inplace_f32(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, fun: ffi.CData) -> ffi.CData:
  1012. """
  1013. GGML_DEPRECATED(GGML_API struct ggml_tensor * ggml_map_binary_inplace_f32(
  1014. struct ggml_context * ctx,
  1015. struct ggml_tensor * a,
  1016. struct ggml_tensor * b,
  1017. ggml_binary_op_f32_t fun),
  1018. "use ggml_map_custom2_inplace instead");
  1019. """
  1020. ...
  1021. def ggml_map_custom1(ctx: ffi.CData, a: ffi.CData, fun: ffi.CData, n_tasks: int, userdata: ffi.CData) -> ffi.CData:
  1022. """
  1023. GGML_API struct ggml_tensor * ggml_map_custom1(
  1024. struct ggml_context * ctx,
  1025. struct ggml_tensor * a,
  1026. ggml_custom1_op_t fun,
  1027. int n_tasks,
  1028. void * userdata);
  1029. """
  1030. ...
  1031. def ggml_map_custom1_f32(ctx: ffi.CData, a: ffi.CData, fun: ffi.CData) -> ffi.CData:
  1032. """
  1033. GGML_DEPRECATED(GGML_API struct ggml_tensor * ggml_map_custom1_f32(
  1034. struct ggml_context * ctx,
  1035. struct ggml_tensor * a,
  1036. ggml_custom1_op_f32_t fun),
  1037. "use ggml_map_custom1 instead");
  1038. """
  1039. ...
  1040. def ggml_map_custom1_inplace(ctx: ffi.CData, a: ffi.CData, fun: ffi.CData, n_tasks: int, userdata: ffi.CData) -> ffi.CData:
  1041. """
  1042. GGML_API struct ggml_tensor * ggml_map_custom1_inplace(
  1043. struct ggml_context * ctx,
  1044. struct ggml_tensor * a,
  1045. ggml_custom1_op_t fun,
  1046. int n_tasks,
  1047. void * userdata);
  1048. """
  1049. ...
  1050. def ggml_map_custom1_inplace_f32(ctx: ffi.CData, a: ffi.CData, fun: ffi.CData) -> ffi.CData:
  1051. """
  1052. GGML_DEPRECATED(GGML_API struct ggml_tensor * ggml_map_custom1_inplace_f32(
  1053. struct ggml_context * ctx,
  1054. struct ggml_tensor * a,
  1055. ggml_custom1_op_f32_t fun),
  1056. "use ggml_map_custom1_inplace instead");
  1057. """
  1058. ...
  1059. def ggml_map_custom2(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, fun: ffi.CData, n_tasks: int, userdata: ffi.CData) -> ffi.CData:
  1060. """
  1061. GGML_API struct ggml_tensor * ggml_map_custom2(
  1062. struct ggml_context * ctx,
  1063. struct ggml_tensor * a,
  1064. struct ggml_tensor * b,
  1065. ggml_custom2_op_t fun,
  1066. int n_tasks,
  1067. void * userdata);
  1068. """
  1069. ...
  1070. def ggml_map_custom2_f32(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, fun: ffi.CData) -> ffi.CData:
  1071. """
  1072. GGML_DEPRECATED(GGML_API struct ggml_tensor * ggml_map_custom2_f32(
  1073. struct ggml_context * ctx,
  1074. struct ggml_tensor * a,
  1075. struct ggml_tensor * b,
  1076. ggml_custom2_op_f32_t fun),
  1077. "use ggml_map_custom2 instead");
  1078. """
  1079. ...
  1080. def ggml_map_custom2_inplace(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, fun: ffi.CData, n_tasks: int, userdata: ffi.CData) -> ffi.CData:
  1081. """
  1082. GGML_API struct ggml_tensor * ggml_map_custom2_inplace(
  1083. struct ggml_context * ctx,
  1084. struct ggml_tensor * a,
  1085. struct ggml_tensor * b,
  1086. ggml_custom2_op_t fun,
  1087. int n_tasks,
  1088. void * userdata);
  1089. """
  1090. ...
  1091. def ggml_map_custom2_inplace_f32(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, fun: ffi.CData) -> ffi.CData:
  1092. """
  1093. GGML_DEPRECATED(GGML_API struct ggml_tensor * ggml_map_custom2_inplace_f32(
  1094. struct ggml_context * ctx,
  1095. struct ggml_tensor * a,
  1096. struct ggml_tensor * b,
  1097. ggml_custom2_op_f32_t fun),
  1098. "use ggml_map_custom2_inplace instead");
  1099. """
  1100. ...
  1101. def ggml_map_custom3(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, c: ffi.CData, fun: ffi.CData, n_tasks: int, userdata: ffi.CData) -> ffi.CData:
  1102. """
  1103. GGML_API struct ggml_tensor * ggml_map_custom3(
  1104. struct ggml_context * ctx,
  1105. struct ggml_tensor * a,
  1106. struct ggml_tensor * b,
  1107. struct ggml_tensor * c,
  1108. ggml_custom3_op_t fun,
  1109. int n_tasks,
  1110. void * userdata);
  1111. """
  1112. ...
  1113. def ggml_map_custom3_f32(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, c: ffi.CData, fun: ffi.CData) -> ffi.CData:
  1114. """
  1115. GGML_DEPRECATED(GGML_API struct ggml_tensor * ggml_map_custom3_f32(
  1116. struct ggml_context * ctx,
  1117. struct ggml_tensor * a,
  1118. struct ggml_tensor * b,
  1119. struct ggml_tensor * c,
  1120. ggml_custom3_op_f32_t fun),
  1121. "use ggml_map_custom3 instead");
  1122. """
  1123. ...
  1124. def ggml_map_custom3_inplace(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, c: ffi.CData, fun: ffi.CData, n_tasks: int, userdata: ffi.CData) -> ffi.CData:
  1125. """
  1126. GGML_API struct ggml_tensor * ggml_map_custom3_inplace(
  1127. struct ggml_context * ctx,
  1128. struct ggml_tensor * a,
  1129. struct ggml_tensor * b,
  1130. struct ggml_tensor * c,
  1131. ggml_custom3_op_t fun,
  1132. int n_tasks,
  1133. void * userdata);
  1134. """
  1135. ...
  1136. def ggml_map_custom3_inplace_f32(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, c: ffi.CData, fun: ffi.CData) -> ffi.CData:
  1137. """
  1138. GGML_DEPRECATED(GGML_API struct ggml_tensor * ggml_map_custom3_inplace_f32(
  1139. struct ggml_context * ctx,
  1140. struct ggml_tensor * a,
  1141. struct ggml_tensor * b,
  1142. struct ggml_tensor * c,
  1143. ggml_custom3_op_f32_t fun),
  1144. "use ggml_map_custom3_inplace instead");
  1145. """
  1146. ...
  1147. def ggml_map_unary_f32(ctx: ffi.CData, a: ffi.CData, fun: ffi.CData) -> ffi.CData:
  1148. """
  1149. GGML_DEPRECATED(GGML_API struct ggml_tensor * ggml_map_unary_f32(
  1150. struct ggml_context * ctx,
  1151. struct ggml_tensor * a,
  1152. ggml_unary_op_f32_t fun),
  1153. "use ggml_map_custom1 instead");
  1154. """
  1155. ...
  1156. def ggml_map_unary_inplace_f32(ctx: ffi.CData, a: ffi.CData, fun: ffi.CData) -> ffi.CData:
  1157. """
  1158. GGML_DEPRECATED(GGML_API struct ggml_tensor * ggml_map_unary_inplace_f32(
  1159. struct ggml_context * ctx,
  1160. struct ggml_tensor * a,
  1161. ggml_unary_op_f32_t fun),
  1162. "use ggml_map_custom1_inplace instead");
  1163. """
  1164. ...
  1165. def ggml_mean(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1166. """
  1167. mean along rows
  1168. GGML_API struct ggml_tensor * ggml_mean(
  1169. struct ggml_context * ctx,
  1170. struct ggml_tensor * a);
  1171. """
  1172. ...
  1173. def ggml_metal_add_buffer(ctx: ffi.CData, name: ffi.CData, data: ffi.CData, size: int, max_size: int) -> bool:
  1174. """
  1175. creates a mapping between a host memory buffer and a device memory buffer
  1176. - make sure to map all buffers used in the graph before calling ggml_metal_graph_compute
  1177. - the mapping is used during computation to determine the arguments of the compute kernels
  1178. - you don't need to keep the host memory buffer allocated as it is never accessed by Metal
  1179. - max_size specifies the maximum size of a tensor and is used to create shared views such
  1180. that it is guaranteed that the tensor will fit in at least one of the views
  1181. bool ggml_metal_add_buffer(
  1182. struct ggml_metal_context * ctx,
  1183. const char * name,
  1184. void * data,
  1185. size_t size,
  1186. size_t max_size);
  1187. """
  1188. ...
  1189. def ggml_metal_free(ctx: ffi.CData) -> None:
  1190. """void ggml_metal_free(struct ggml_metal_context * ctx);"""
  1191. ...
  1192. def ggml_metal_get_concur_list(ctx: ffi.CData) -> ffi.CData:
  1193. """
  1194. output the concur_list for ggml_alloc
  1195. int * ggml_metal_get_concur_list(struct ggml_metal_context * ctx);
  1196. """
  1197. ...
  1198. def ggml_metal_get_tensor(ctx: ffi.CData, t: ffi.CData) -> None:
  1199. """
  1200. get data from the device into host memory
  1201. void ggml_metal_get_tensor(struct ggml_metal_context * ctx, struct ggml_tensor * t);
  1202. """
  1203. ...
  1204. def ggml_metal_graph_compute(ctx: ffi.CData, gf: ffi.CData) -> None:
  1205. """
  1206. same as ggml_graph_compute but uses Metal
  1207. creates gf->n_threads command buffers in parallel
  1208. void ggml_metal_graph_compute(struct ggml_metal_context * ctx, struct ggml_cgraph * gf);
  1209. """
  1210. ...
  1211. def ggml_metal_graph_find_concurrency(ctx: ffi.CData, gf: ffi.CData, check_mem: bool) -> None:
  1212. """
  1213. try to find operations that can be run concurrently in the graph
  1214. you should run it again if the topology of your graph changes
  1215. void ggml_metal_graph_find_concurrency(struct ggml_metal_context * ctx, struct ggml_cgraph * gf, bool check_mem);
  1216. """
  1217. ...
  1218. def ggml_metal_host_free(data: ffi.CData) -> None:
  1219. """void ggml_metal_host_free (void * data);"""
  1220. ...
  1221. def ggml_metal_host_malloc(n: int) -> ffi.CData:
  1222. """void * ggml_metal_host_malloc(size_t n);"""
  1223. ...
  1224. def ggml_metal_if_optimized(ctx: ffi.CData) -> int:
  1225. """
  1226. if the graph has been optimized for concurrently dispatch, return length of the concur_list if optimized
  1227. int ggml_metal_if_optimized(struct ggml_metal_context * ctx);
  1228. """
  1229. ...
  1230. def ggml_metal_init(n_cb: int) -> ffi.CData:
  1231. """
  1232. number of command buffers to use
  1233. struct ggml_metal_context * ggml_metal_init(int n_cb);
  1234. """
  1235. ...
  1236. def ggml_metal_set_n_cb(ctx: ffi.CData, n_cb: int) -> None:
  1237. """
  1238. set the number of command buffers to use
  1239. void ggml_metal_set_n_cb(struct ggml_metal_context * ctx, int n_cb);
  1240. """
  1241. ...
  1242. def ggml_metal_set_tensor(ctx: ffi.CData, t: ffi.CData) -> None:
  1243. """
  1244. set data from host memory into the device
  1245. void ggml_metal_set_tensor(struct ggml_metal_context * ctx, struct ggml_tensor * t);
  1246. """
  1247. ...
  1248. def ggml_mpi_backend_free() -> None:
  1249. """void ggml_mpi_backend_free(void);"""
  1250. ...
  1251. def ggml_mpi_backend_init() -> None:
  1252. """void ggml_mpi_backend_init(void);"""
  1253. ...
  1254. def ggml_mpi_eval_init(ctx_mpi: ffi.CData, n_tokens: ffi.CData, n_past: ffi.CData, n_threads: ffi.CData) -> None:
  1255. """
  1256. void ggml_mpi_eval_init(
  1257. struct ggml_mpi_context * ctx_mpi,
  1258. int * n_tokens,
  1259. int * n_past,
  1260. int * n_threads);
  1261. """
  1262. ...
  1263. def ggml_mpi_free(ctx: ffi.CData) -> None:
  1264. """void ggml_mpi_free(struct ggml_mpi_context * ctx);"""
  1265. ...
  1266. def ggml_mpi_graph_compute_post(ctx_mpi: ffi.CData, gf: ffi.CData, n_layers: int) -> None:
  1267. """
  1268. void ggml_mpi_graph_compute_post(
  1269. struct ggml_mpi_context * ctx_mpi,
  1270. struct ggml_cgraph * gf,
  1271. int n_layers);
  1272. """
  1273. ...
  1274. def ggml_mpi_graph_compute_pre(ctx_mpi: ffi.CData, gf: ffi.CData, n_layers: int) -> None:
  1275. """
  1276. void ggml_mpi_graph_compute_pre(
  1277. struct ggml_mpi_context * ctx_mpi,
  1278. struct ggml_cgraph * gf,
  1279. int n_layers);
  1280. """
  1281. ...
  1282. def ggml_mpi_init() -> ffi.CData:
  1283. """struct ggml_mpi_context * ggml_mpi_init(void);"""
  1284. ...
  1285. def ggml_mpi_rank(ctx: ffi.CData) -> int:
  1286. """int ggml_mpi_rank(struct ggml_mpi_context * ctx);"""
  1287. ...
  1288. def ggml_mul(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  1289. """
  1290. GGML_API struct ggml_tensor * ggml_mul(
  1291. struct ggml_context * ctx,
  1292. struct ggml_tensor * a,
  1293. struct ggml_tensor * b);
  1294. """
  1295. ...
  1296. def ggml_mul_inplace(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  1297. """
  1298. GGML_API struct ggml_tensor * ggml_mul_inplace(
  1299. struct ggml_context * ctx,
  1300. struct ggml_tensor * a,
  1301. struct ggml_tensor * b);
  1302. """
  1303. ...
  1304. def ggml_mul_mat(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  1305. """
  1306. A: n columns, m rows
  1307. B: n columns, p rows (i.e. we transpose it internally)
  1308. result is m columns, p rows
  1309. GGML_API struct ggml_tensor * ggml_mul_mat(
  1310. struct ggml_context * ctx,
  1311. struct ggml_tensor * a,
  1312. struct ggml_tensor * b);
  1313. """
  1314. ...
  1315. def ggml_nbytes(tensor: ffi.CData) -> int:
  1316. """ GGML_API size_t ggml_nbytes (const struct ggml_tensor * tensor);"""
  1317. ...
  1318. def ggml_nbytes_pad(tensor: ffi.CData) -> int:
  1319. """ GGML_API size_t ggml_nbytes_pad (const struct ggml_tensor * tensor); // same as ggml_nbytes() but padded to GGML_MEM_ALIGN"""
  1320. ...
  1321. def ggml_nbytes_split(tensor: ffi.CData, nrows_split: int) -> int:
  1322. """ GGML_API size_t ggml_nbytes_split(const struct ggml_tensor * tensor, int nrows_split);"""
  1323. ...
  1324. def ggml_neg(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1325. """
  1326. GGML_API struct ggml_tensor * ggml_neg(
  1327. struct ggml_context * ctx,
  1328. struct ggml_tensor * a);
  1329. """
  1330. ...
  1331. def ggml_neg_inplace(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1332. """
  1333. GGML_API struct ggml_tensor * ggml_neg_inplace(
  1334. struct ggml_context * ctx,
  1335. struct ggml_tensor * a);
  1336. """
  1337. ...
  1338. def ggml_nelements(tensor: ffi.CData) -> int:
  1339. """ GGML_API int64_t ggml_nelements (const struct ggml_tensor * tensor);"""
  1340. ...
  1341. def ggml_new_f32(ctx: ffi.CData, value: float) -> ffi.CData:
  1342. """ GGML_API struct ggml_tensor * ggml_new_f32(struct ggml_context * ctx, float value);"""
  1343. ...
  1344. def ggml_new_graph(ctx: ffi.CData) -> ffi.CData:
  1345. """
  1346. graph allocation in a context
  1347. GGML_API struct ggml_cgraph * ggml_new_graph (struct ggml_context * ctx);
  1348. """
  1349. ...
  1350. def ggml_new_i32(ctx: ffi.CData, value: int) -> ffi.CData:
  1351. """ GGML_API struct ggml_tensor * ggml_new_i32(struct ggml_context * ctx, int32_t value);"""
  1352. ...
  1353. def ggml_new_tensor(ctx: ffi.CData, type: int, n_dims: int, ne: ffi.CData) -> ffi.CData:
  1354. """
  1355. GGML_API struct ggml_tensor * ggml_new_tensor(
  1356. struct ggml_context * ctx,
  1357. enum ggml_type type,
  1358. int n_dims,
  1359. const int64_t *ne);
  1360. """
  1361. ...
  1362. def ggml_new_tensor_1d(ctx: ffi.CData, type: int, ne0: int) -> ffi.CData:
  1363. """
  1364. GGML_API struct ggml_tensor * ggml_new_tensor_1d(
  1365. struct ggml_context * ctx,
  1366. enum ggml_type type,
  1367. int64_t ne0);
  1368. """
  1369. ...
  1370. def ggml_new_tensor_2d(ctx: ffi.CData, type: int, ne0: int, ne1: int) -> ffi.CData:
  1371. """
  1372. GGML_API struct ggml_tensor * ggml_new_tensor_2d(
  1373. struct ggml_context * ctx,
  1374. enum ggml_type type,
  1375. int64_t ne0,
  1376. int64_t ne1);
  1377. """
  1378. ...
  1379. def ggml_new_tensor_3d(ctx: ffi.CData, type: int, ne0: int, ne1: int, ne2: int) -> ffi.CData:
  1380. """
  1381. GGML_API struct ggml_tensor * ggml_new_tensor_3d(
  1382. struct ggml_context * ctx,
  1383. enum ggml_type type,
  1384. int64_t ne0,
  1385. int64_t ne1,
  1386. int64_t ne2);
  1387. """
  1388. ...
  1389. def ggml_new_tensor_4d(ctx: ffi.CData, type: int, ne0: int, ne1: int, ne2: int, ne3: int) -> ffi.CData:
  1390. """
  1391. GGML_API struct ggml_tensor * ggml_new_tensor_4d(
  1392. struct ggml_context * ctx,
  1393. enum ggml_type type,
  1394. int64_t ne0,
  1395. int64_t ne1,
  1396. int64_t ne2,
  1397. int64_t ne3);
  1398. """
  1399. ...
  1400. def ggml_norm(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1401. """
  1402. normalize along rows
  1403. TODO: eps is hardcoded to 1e-5 for now
  1404. GGML_API struct ggml_tensor * ggml_norm(
  1405. struct ggml_context * ctx,
  1406. struct ggml_tensor * a);
  1407. """
  1408. ...
  1409. def ggml_norm_inplace(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1410. """
  1411. GGML_API struct ggml_tensor * ggml_norm_inplace(
  1412. struct ggml_context * ctx,
  1413. struct ggml_tensor * a);
  1414. """
  1415. ...
  1416. def ggml_nrows(tensor: ffi.CData) -> int:
  1417. """ GGML_API int64_t ggml_nrows (const struct ggml_tensor * tensor);"""
  1418. ...
  1419. def ggml_numa_init() -> None:
  1420. """ GGML_API void ggml_numa_init(void); // call once for better performance on NUMA systems"""
  1421. ...
  1422. def ggml_op_name(op: int) -> ffi.CData:
  1423. """ GGML_API const char * ggml_op_name (enum ggml_op op);"""
  1424. ...
  1425. def ggml_op_symbol(op: int) -> ffi.CData:
  1426. """ GGML_API const char * ggml_op_symbol(enum ggml_op op);"""
  1427. ...
  1428. def ggml_opt(ctx: ffi.CData, params: ffi.CData, f: ffi.CData) -> int:
  1429. """
  1430. optimize the function defined by the tensor f
  1431. GGML_API enum ggml_opt_result ggml_opt(
  1432. struct ggml_context * ctx,
  1433. struct ggml_opt_params params,
  1434. struct ggml_tensor * f);
  1435. """
  1436. ...
  1437. def ggml_opt_default_params(type: int) -> ffi.CData:
  1438. """ GGML_API struct ggml_opt_params ggml_opt_default_params(enum ggml_opt_type type);"""
  1439. ...
  1440. def ggml_opt_init(ctx: ffi.CData, opt: ffi.CData, params: ffi.CData, nx: int) -> None:
  1441. """
  1442. initialize optimizer context
  1443. GGML_API void ggml_opt_init(
  1444. struct ggml_context * ctx,
  1445. struct ggml_opt_context * opt,
  1446. struct ggml_opt_params params,
  1447. int64_t nx);
  1448. """
  1449. ...
  1450. def ggml_opt_resume(ctx: ffi.CData, opt: ffi.CData, f: ffi.CData) -> int:
  1451. """
  1452. continue optimizing the function defined by the tensor f
  1453. GGML_API enum ggml_opt_result ggml_opt_resume(
  1454. struct ggml_context * ctx,
  1455. struct ggml_opt_context * opt,
  1456. struct ggml_tensor * f);
  1457. """
  1458. ...
  1459. def ggml_opt_resume_g(ctx: ffi.CData, opt: ffi.CData, f: ffi.CData, gf: ffi.CData, gb: ffi.CData) -> int:
  1460. """
  1461. continue optimizing the function defined by the tensor f
  1462. GGML_API enum ggml_opt_result ggml_opt_resume_g(
  1463. struct ggml_context * ctx,
  1464. struct ggml_opt_context * opt,
  1465. struct ggml_tensor * f,
  1466. struct ggml_cgraph * gf,
  1467. struct ggml_cgraph * gb);
  1468. """
  1469. ...
  1470. def ggml_out_prod(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  1471. """
  1472. A: m columns, n rows,
  1473. B: p columns, n rows,
  1474. result is m columns, p rows
  1475. GGML_API struct ggml_tensor * ggml_out_prod(
  1476. struct ggml_context * ctx,
  1477. struct ggml_tensor * a,
  1478. struct ggml_tensor * b);
  1479. """
  1480. ...
  1481. def ggml_permute(ctx: ffi.CData, a: ffi.CData, axis0: int, axis1: int, axis2: int, axis3: int) -> ffi.CData:
  1482. """
  1483. GGML_API struct ggml_tensor * ggml_permute(
  1484. struct ggml_context * ctx,
  1485. struct ggml_tensor * a,
  1486. int axis0,
  1487. int axis1,
  1488. int axis2,
  1489. int axis3);
  1490. """
  1491. ...
  1492. def ggml_pool_1d(ctx: ffi.CData, a: ffi.CData, op: int, k0: int, s0: int, p0: int) -> ffi.CData:
  1493. """
  1494. GGML_API struct ggml_tensor * ggml_pool_1d(
  1495. struct ggml_context * ctx,
  1496. struct ggml_tensor * a,
  1497. enum ggml_op_pool op,
  1498. int k0, // kernel size
  1499. int s0, // stride
  1500. int p0); // padding
  1501. """
  1502. ...
  1503. def ggml_pool_2d(ctx: ffi.CData, a: ffi.CData, op: int, k0: int, k1: int, s0: int, s1: int, p0: int, p1: int) -> ffi.CData:
  1504. """
  1505. GGML_API struct ggml_tensor * ggml_pool_2d(
  1506. struct ggml_context * ctx,
  1507. struct ggml_tensor * a,
  1508. enum ggml_op_pool op,
  1509. int k0,
  1510. int k1,
  1511. int s0,
  1512. int s1,
  1513. int p0,
  1514. int p1);
  1515. """
  1516. ...
  1517. def ggml_print_object(obj: ffi.CData) -> None:
  1518. """ GGML_API void ggml_print_object (const struct ggml_object * obj);"""
  1519. ...
  1520. def ggml_print_objects(ctx: ffi.CData) -> None:
  1521. """ GGML_API void ggml_print_objects(const struct ggml_context * ctx);"""
  1522. ...
  1523. def ggml_quantize_chunk(type: int, src: ffi.CData, dst: ffi.CData, start: int, n: int, hist: ffi.CData) -> int:
  1524. """ GGML_API size_t ggml_quantize_chunk(enum ggml_type type, const float * src, void * dst, int start, int n, int64_t * hist);"""
  1525. ...
  1526. def ggml_quantize_q2_K(src: ffi.CData, dst: ffi.CData, n: int, k: int, hist: ffi.CData) -> int:
  1527. """
  1528. Quantization with histogram collection
  1529. size_t ggml_quantize_q2_K(const float * src, void * dst, int n, int k, int64_t * hist);
  1530. """
  1531. ...
  1532. def ggml_quantize_q3_K(src: ffi.CData, dst: ffi.CData, n: int, k: int, hist: ffi.CData) -> int:
  1533. """size_t ggml_quantize_q3_K(const float * src, void * dst, int n, int k, int64_t * hist);"""
  1534. ...
  1535. def ggml_quantize_q4_0(src: ffi.CData, dst: ffi.CData, n: int, k: int, hist: ffi.CData) -> int:
  1536. """ GGML_API size_t ggml_quantize_q4_0(const float * src, void * dst, int n, int k, int64_t * hist);"""
  1537. ...
  1538. def ggml_quantize_q4_1(src: ffi.CData, dst: ffi.CData, n: int, k: int, hist: ffi.CData) -> int:
  1539. """ GGML_API size_t ggml_quantize_q4_1(const float * src, void * dst, int n, int k, int64_t * hist);"""
  1540. ...
  1541. def ggml_quantize_q4_K(src: ffi.CData, dst: ffi.CData, n: int, k: int, hist: ffi.CData) -> int:
  1542. """size_t ggml_quantize_q4_K(const float * src, void * dst, int n, int k, int64_t * hist);"""
  1543. ...
  1544. def ggml_quantize_q5_0(src: ffi.CData, dst: ffi.CData, n: int, k: int, hist: ffi.CData) -> int:
  1545. """ GGML_API size_t ggml_quantize_q5_0(const float * src, void * dst, int n, int k, int64_t * hist);"""
  1546. ...
  1547. def ggml_quantize_q5_1(src: ffi.CData, dst: ffi.CData, n: int, k: int, hist: ffi.CData) -> int:
  1548. """ GGML_API size_t ggml_quantize_q5_1(const float * src, void * dst, int n, int k, int64_t * hist);"""
  1549. ...
  1550. def ggml_quantize_q5_K(src: ffi.CData, dst: ffi.CData, n: int, k: int, hist: ffi.CData) -> int:
  1551. """size_t ggml_quantize_q5_K(const float * src, void * dst, int n, int k, int64_t * hist);"""
  1552. ...
  1553. def ggml_quantize_q6_K(src: ffi.CData, dst: ffi.CData, n: int, k: int, hist: ffi.CData) -> int:
  1554. """size_t ggml_quantize_q6_K(const float * src, void * dst, int n, int k, int64_t * hist);"""
  1555. ...
  1556. def ggml_quantize_q8_0(src: ffi.CData, dst: ffi.CData, n: int, k: int, hist: ffi.CData) -> int:
  1557. """ GGML_API size_t ggml_quantize_q8_0(const float * src, void * dst, int n, int k, int64_t * hist);"""
  1558. ...
  1559. def ggml_relu(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1560. """
  1561. GGML_API struct ggml_tensor * ggml_relu(
  1562. struct ggml_context * ctx,
  1563. struct ggml_tensor * a);
  1564. """
  1565. ...
  1566. def ggml_relu_inplace(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1567. """
  1568. GGML_API struct ggml_tensor * ggml_relu_inplace(
  1569. struct ggml_context * ctx,
  1570. struct ggml_tensor * a);
  1571. """
  1572. ...
  1573. def ggml_repeat(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  1574. """
  1575. if a is the same shape as b, and a is not parameter, return a
  1576. otherwise, return a new tensor: repeat(a) to fit in b
  1577. GGML_API struct ggml_tensor * ggml_repeat(
  1578. struct ggml_context * ctx,
  1579. struct ggml_tensor * a,
  1580. struct ggml_tensor * b);
  1581. """
  1582. ...
  1583. def ggml_repeat_back(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  1584. """
  1585. GGML_API struct ggml_tensor * ggml_repeat_back(
  1586. struct ggml_context * ctx,
  1587. struct ggml_tensor * a,
  1588. struct ggml_tensor * b);
  1589. """
  1590. ...
  1591. def ggml_reshape(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  1592. """
  1593. return view(a), b specifies the new shape
  1594. TODO: when we start computing gradient, make a copy instead of view
  1595. GGML_API struct ggml_tensor * ggml_reshape(
  1596. struct ggml_context * ctx,
  1597. struct ggml_tensor * a,
  1598. struct ggml_tensor * b);
  1599. """
  1600. ...
  1601. def ggml_reshape_1d(ctx: ffi.CData, a: ffi.CData, ne0: int) -> ffi.CData:
  1602. """
  1603. return view(a)
  1604. TODO: when we start computing gradient, make a copy instead of view
  1605. GGML_API struct ggml_tensor * ggml_reshape_1d(
  1606. struct ggml_context * ctx,
  1607. struct ggml_tensor * a,
  1608. int64_t ne0);
  1609. """
  1610. ...
  1611. def ggml_reshape_2d(ctx: ffi.CData, a: ffi.CData, ne0: int, ne1: int) -> ffi.CData:
  1612. """
  1613. GGML_API struct ggml_tensor * ggml_reshape_2d(
  1614. struct ggml_context * ctx,
  1615. struct ggml_tensor * a,
  1616. int64_t ne0,
  1617. int64_t ne1);
  1618. """
  1619. ...
  1620. def ggml_reshape_3d(ctx: ffi.CData, a: ffi.CData, ne0: int, ne1: int, ne2: int) -> ffi.CData:
  1621. """
  1622. return view(a)
  1623. TODO: when we start computing gradient, make a copy instead of view
  1624. GGML_API struct ggml_tensor * ggml_reshape_3d(
  1625. struct ggml_context * ctx,
  1626. struct ggml_tensor * a,
  1627. int64_t ne0,
  1628. int64_t ne1,
  1629. int64_t ne2);
  1630. """
  1631. ...
  1632. def ggml_reshape_4d(ctx: ffi.CData, a: ffi.CData, ne0: int, ne1: int, ne2: int, ne3: int) -> ffi.CData:
  1633. """
  1634. GGML_API struct ggml_tensor * ggml_reshape_4d(
  1635. struct ggml_context * ctx,
  1636. struct ggml_tensor * a,
  1637. int64_t ne0,
  1638. int64_t ne1,
  1639. int64_t ne2,
  1640. int64_t ne3);
  1641. """
  1642. ...
  1643. def ggml_rms_norm(ctx: ffi.CData, a: ffi.CData, eps: float) -> ffi.CData:
  1644. """
  1645. GGML_API struct ggml_tensor * ggml_rms_norm(
  1646. struct ggml_context * ctx,
  1647. struct ggml_tensor * a,
  1648. float eps);
  1649. """
  1650. ...
  1651. def ggml_rms_norm_back(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  1652. """
  1653. a - x
  1654. b - dy
  1655. TODO: update with configurable eps
  1656. GGML_API struct ggml_tensor * ggml_rms_norm_back(
  1657. struct ggml_context * ctx,
  1658. struct ggml_tensor * a,
  1659. struct ggml_tensor * b);
  1660. """
  1661. ...
  1662. def ggml_rms_norm_inplace(ctx: ffi.CData, a: ffi.CData, eps: float) -> ffi.CData:
  1663. """
  1664. GGML_API struct ggml_tensor * ggml_rms_norm_inplace(
  1665. struct ggml_context * ctx,
  1666. struct ggml_tensor * a,
  1667. float eps);
  1668. """
  1669. ...
  1670. def ggml_rope(ctx: ffi.CData, a: ffi.CData, n_past: int, n_dims: int, mode: int, n_ctx: int) -> ffi.CData:
  1671. """
  1672. rotary position embedding
  1673. if mode & 1 == 1, skip n_past elements
  1674. if mode & 2 == 1, GPT-NeoX style
  1675. if mode & 4 == 1, ChatGLM style
  1676. TODO: avoid creating a new tensor every time
  1677. GGML_API struct ggml_tensor * ggml_rope(
  1678. struct ggml_context * ctx,
  1679. struct ggml_tensor * a,
  1680. int n_past,
  1681. int n_dims,
  1682. int mode,
  1683. int n_ctx);
  1684. """
  1685. ...
  1686. def ggml_rope_back(ctx: ffi.CData, a: ffi.CData, n_past: int, n_dims: int, mode: int, n_ctx: int) -> ffi.CData:
  1687. """
  1688. rotary position embedding backward, i.e compute dx from dy
  1689. a - dy
  1690. GGML_API struct ggml_tensor * ggml_rope_back(
  1691. struct ggml_context * ctx,
  1692. struct ggml_tensor * a,
  1693. int n_past,
  1694. int n_dims,
  1695. int mode,
  1696. int n_ctx);
  1697. """
  1698. ...
  1699. def ggml_rope_custom(ctx: ffi.CData, a: ffi.CData, n_past: int, n_dims: int, mode: int, n_ctx: int, freq_base: float, freq_scale: float) -> ffi.CData:
  1700. """
  1701. custom RoPE
  1702. GGML_API struct ggml_tensor * ggml_rope_custom(
  1703. struct ggml_context * ctx,
  1704. struct ggml_tensor * a,
  1705. int n_past,
  1706. int n_dims,
  1707. int mode,
  1708. int n_ctx,
  1709. float freq_base,
  1710. float freq_scale);
  1711. """
  1712. ...
  1713. def ggml_rope_custom_inplace(ctx: ffi.CData, a: ffi.CData, n_past: int, n_dims: int, mode: int, n_ctx: int, freq_base: float, freq_scale: float) -> ffi.CData:
  1714. """
  1715. in-place, returns view(a)
  1716. GGML_API struct ggml_tensor * ggml_rope_custom_inplace(
  1717. struct ggml_context * ctx,
  1718. struct ggml_tensor * a,
  1719. int n_past,
  1720. int n_dims,
  1721. int mode,
  1722. int n_ctx,
  1723. float freq_base,
  1724. float freq_scale);
  1725. """
  1726. ...
  1727. def ggml_rope_inplace(ctx: ffi.CData, a: ffi.CData, n_past: int, n_dims: int, mode: int, n_ctx: int) -> ffi.CData:
  1728. """
  1729. in-place, returns view(a)
  1730. GGML_API struct ggml_tensor * ggml_rope_inplace(
  1731. struct ggml_context * ctx,
  1732. struct ggml_tensor * a,
  1733. int n_past,
  1734. int n_dims,
  1735. int mode,
  1736. int n_ctx);
  1737. """
  1738. ...
  1739. def ggml_scale(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  1740. """
  1741. GGML_API struct ggml_tensor * ggml_scale(
  1742. struct ggml_context * ctx,
  1743. struct ggml_tensor * a,
  1744. struct ggml_tensor * b);
  1745. """
  1746. ...
  1747. def ggml_scale_inplace(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  1748. """
  1749. in-place, returns view(a)
  1750. GGML_API struct ggml_tensor * ggml_scale_inplace(
  1751. struct ggml_context * ctx,
  1752. struct ggml_tensor * a,
  1753. struct ggml_tensor * b);
  1754. """
  1755. ...
  1756. def ggml_set(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, nb1: int, nb2: int, nb3: int, offset: int) -> ffi.CData:
  1757. """
  1758. b -> view(a,offset,nb1,nb2,3), return modified a
  1759. GGML_API struct ggml_tensor * ggml_set(
  1760. struct ggml_context * ctx,
  1761. struct ggml_tensor * a,
  1762. struct ggml_tensor * b,
  1763. size_t nb1,
  1764. size_t nb2,
  1765. size_t nb3,
  1766. size_t offset);
  1767. """
  1768. ...
  1769. def ggml_set_1d(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, offset: int) -> ffi.CData:
  1770. """
  1771. GGML_API struct ggml_tensor * ggml_set_1d(
  1772. struct ggml_context * ctx,
  1773. struct ggml_tensor * a,
  1774. struct ggml_tensor * b,
  1775. size_t offset);
  1776. """
  1777. ...
  1778. def ggml_set_1d_inplace(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, offset: int) -> ffi.CData:
  1779. """
  1780. GGML_API struct ggml_tensor * ggml_set_1d_inplace(
  1781. struct ggml_context * ctx,
  1782. struct ggml_tensor * a,
  1783. struct ggml_tensor * b,
  1784. size_t offset);
  1785. """
  1786. ...
  1787. def ggml_set_2d(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, nb1: int, offset: int) -> ffi.CData:
  1788. """
  1789. b -> view(a,offset,nb1,nb2,3), return modified a
  1790. GGML_API struct ggml_tensor * ggml_set_2d(
  1791. struct ggml_context * ctx,
  1792. struct ggml_tensor * a,
  1793. struct ggml_tensor * b,
  1794. size_t nb1,
  1795. size_t offset);
  1796. """
  1797. ...
  1798. def ggml_set_2d_inplace(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, nb1: int, offset: int) -> ffi.CData:
  1799. """
  1800. b -> view(a,offset,nb1,nb2,3), return view(a)
  1801. GGML_API struct ggml_tensor * ggml_set_2d_inplace(
  1802. struct ggml_context * ctx,
  1803. struct ggml_tensor * a,
  1804. struct ggml_tensor * b,
  1805. size_t nb1,
  1806. size_t offset);
  1807. """
  1808. ...
  1809. def ggml_set_f32(tensor: ffi.CData, value: float) -> ffi.CData:
  1810. """ GGML_API struct ggml_tensor * ggml_set_f32 (struct ggml_tensor * tensor, float value);"""
  1811. ...
  1812. def ggml_set_f32_1d(tensor: ffi.CData, i: int, value: float) -> None:
  1813. """ GGML_API void ggml_set_f32_1d(const struct ggml_tensor * tensor, int i, float value);"""
  1814. ...
  1815. def ggml_set_i32(tensor: ffi.CData, value: int) -> ffi.CData:
  1816. """ GGML_API struct ggml_tensor * ggml_set_i32 (struct ggml_tensor * tensor, int32_t value);"""
  1817. ...
  1818. def ggml_set_i32_1d(tensor: ffi.CData, i: int, value: int) -> None:
  1819. """ GGML_API void ggml_set_i32_1d(const struct ggml_tensor * tensor, int i, int32_t value);"""
  1820. ...
  1821. def ggml_set_inplace(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, nb1: int, nb2: int, nb3: int, offset: int) -> ffi.CData:
  1822. """
  1823. b -> view(a,offset,nb1,nb2,3), return view(a)
  1824. GGML_API struct ggml_tensor * ggml_set_inplace(
  1825. struct ggml_context * ctx,
  1826. struct ggml_tensor * a,
  1827. struct ggml_tensor * b,
  1828. size_t nb1,
  1829. size_t nb2,
  1830. size_t nb3,
  1831. size_t offset);
  1832. """
  1833. ...
  1834. def ggml_set_name(tensor: ffi.CData, name: ffi.CData) -> ffi.CData:
  1835. """ GGML_API struct ggml_tensor * ggml_set_name ( struct ggml_tensor * tensor, const char * name);"""
  1836. ...
  1837. def ggml_set_no_alloc(ctx: ffi.CData, no_alloc: bool) -> None:
  1838. """ GGML_API void ggml_set_no_alloc(struct ggml_context * ctx, bool no_alloc);"""
  1839. ...
  1840. def ggml_set_param(ctx: ffi.CData, tensor: ffi.CData) -> None:
  1841. """
  1842. GGML_API void ggml_set_param(
  1843. struct ggml_context * ctx,
  1844. struct ggml_tensor * tensor);
  1845. """
  1846. ...
  1847. def ggml_set_scratch(ctx: ffi.CData, scratch: ffi.CData) -> int:
  1848. """ GGML_API size_t ggml_set_scratch (struct ggml_context * ctx, struct ggml_scratch scratch);"""
  1849. ...
  1850. def ggml_set_zero(tensor: ffi.CData) -> ffi.CData:
  1851. """ GGML_API struct ggml_tensor * ggml_set_zero(struct ggml_tensor * tensor);"""
  1852. ...
  1853. def ggml_sgn(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1854. """
  1855. GGML_API struct ggml_tensor * ggml_sgn(
  1856. struct ggml_context * ctx,
  1857. struct ggml_tensor * a);
  1858. """
  1859. ...
  1860. def ggml_sgn_inplace(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1861. """
  1862. GGML_API struct ggml_tensor * ggml_sgn_inplace(
  1863. struct ggml_context * ctx,
  1864. struct ggml_tensor * a);
  1865. """
  1866. ...
  1867. def ggml_silu(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1868. """
  1869. GGML_API struct ggml_tensor * ggml_silu(
  1870. struct ggml_context * ctx,
  1871. struct ggml_tensor * a);
  1872. """
  1873. ...
  1874. def ggml_silu_back(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  1875. """
  1876. a - x
  1877. b - dy
  1878. GGML_API struct ggml_tensor * ggml_silu_back(
  1879. struct ggml_context * ctx,
  1880. struct ggml_tensor * a,
  1881. struct ggml_tensor * b);
  1882. """
  1883. ...
  1884. def ggml_silu_inplace(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1885. """
  1886. GGML_API struct ggml_tensor * ggml_silu_inplace(
  1887. struct ggml_context * ctx,
  1888. struct ggml_tensor * a);
  1889. """
  1890. ...
  1891. def ggml_soft_max(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1892. """
  1893. GGML_API struct ggml_tensor * ggml_soft_max(
  1894. struct ggml_context * ctx,
  1895. struct ggml_tensor * a);
  1896. """
  1897. ...
  1898. def ggml_soft_max_back(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  1899. """
  1900. GGML_API struct ggml_tensor * ggml_soft_max_back(
  1901. struct ggml_context * ctx,
  1902. struct ggml_tensor * a,
  1903. struct ggml_tensor * b);
  1904. """
  1905. ...
  1906. def ggml_soft_max_back_inplace(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  1907. """
  1908. in-place, returns view(a)
  1909. GGML_API struct ggml_tensor * ggml_soft_max_back_inplace(
  1910. struct ggml_context * ctx,
  1911. struct ggml_tensor * a,
  1912. struct ggml_tensor * b);
  1913. """
  1914. ...
  1915. def ggml_soft_max_inplace(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1916. """
  1917. in-place, returns view(a)
  1918. GGML_API struct ggml_tensor * ggml_soft_max_inplace(
  1919. struct ggml_context * ctx,
  1920. struct ggml_tensor * a);
  1921. """
  1922. ...
  1923. def ggml_sqr(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1924. """
  1925. GGML_API struct ggml_tensor * ggml_sqr(
  1926. struct ggml_context * ctx,
  1927. struct ggml_tensor * a);
  1928. """
  1929. ...
  1930. def ggml_sqr_inplace(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1931. """
  1932. GGML_API struct ggml_tensor * ggml_sqr_inplace(
  1933. struct ggml_context * ctx,
  1934. struct ggml_tensor * a);
  1935. """
  1936. ...
  1937. def ggml_sqrt(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1938. """
  1939. GGML_API struct ggml_tensor * ggml_sqrt(
  1940. struct ggml_context * ctx,
  1941. struct ggml_tensor * a);
  1942. """
  1943. ...
  1944. def ggml_sqrt_inplace(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1945. """
  1946. GGML_API struct ggml_tensor * ggml_sqrt_inplace(
  1947. struct ggml_context * ctx,
  1948. struct ggml_tensor * a);
  1949. """
  1950. ...
  1951. def ggml_step(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1952. """
  1953. GGML_API struct ggml_tensor * ggml_step(
  1954. struct ggml_context * ctx,
  1955. struct ggml_tensor * a);
  1956. """
  1957. ...
  1958. def ggml_step_inplace(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1959. """
  1960. GGML_API struct ggml_tensor * ggml_step_inplace(
  1961. struct ggml_context * ctx,
  1962. struct ggml_tensor * a);
  1963. """
  1964. ...
  1965. def ggml_sub(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  1966. """
  1967. GGML_API struct ggml_tensor * ggml_sub(
  1968. struct ggml_context * ctx,
  1969. struct ggml_tensor * a,
  1970. struct ggml_tensor * b);
  1971. """
  1972. ...
  1973. def ggml_sub_inplace(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
  1974. """
  1975. GGML_API struct ggml_tensor * ggml_sub_inplace(
  1976. struct ggml_context * ctx,
  1977. struct ggml_tensor * a,
  1978. struct ggml_tensor * b);
  1979. """
  1980. ...
  1981. def ggml_sum(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1982. """
  1983. return scalar
  1984. GGML_API struct ggml_tensor * ggml_sum(
  1985. struct ggml_context * ctx,
  1986. struct ggml_tensor * a);
  1987. """
  1988. ...
  1989. def ggml_sum_rows(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1990. """
  1991. sums along rows, with input shape [a,b,c,d] return shape [1,b,c,d]
  1992. GGML_API struct ggml_tensor * ggml_sum_rows(
  1993. struct ggml_context * ctx,
  1994. struct ggml_tensor * a);
  1995. """
  1996. ...
  1997. def ggml_tanh(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  1998. """
  1999. GGML_API struct ggml_tensor * ggml_tanh(
  2000. struct ggml_context * ctx,
  2001. struct ggml_tensor * a);
  2002. """
  2003. ...
  2004. def ggml_tanh_inplace(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  2005. """
  2006. GGML_API struct ggml_tensor * ggml_tanh_inplace(
  2007. struct ggml_context * ctx,
  2008. struct ggml_tensor * a);
  2009. """
  2010. ...
  2011. def ggml_tensor_overhead() -> int:
  2012. """
  2013. use this to compute the memory overhead of a tensor
  2014. GGML_API size_t ggml_tensor_overhead(void);
  2015. """
  2016. ...
  2017. def ggml_time_init() -> None:
  2018. """ GGML_API void ggml_time_init(void); // call this once at the beginning of the program"""
  2019. ...
  2020. def ggml_time_ms() -> int:
  2021. """ GGML_API int64_t ggml_time_ms(void);"""
  2022. ...
  2023. def ggml_time_us() -> int:
  2024. """ GGML_API int64_t ggml_time_us(void);"""
  2025. ...
  2026. def ggml_transpose(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
  2027. """
  2028. alias for ggml_permute(ctx, a, 1, 0, 2, 3)
  2029. GGML_API struct ggml_tensor * ggml_transpose(
  2030. struct ggml_context * ctx,
  2031. struct ggml_tensor * a);
  2032. """
  2033. ...
  2034. def ggml_type_name(type: int) -> ffi.CData:
  2035. """ GGML_API const char * ggml_type_name(enum ggml_type type);"""
  2036. ...
  2037. def ggml_type_size(type: int) -> int:
  2038. """ GGML_API size_t ggml_type_size (enum ggml_type type); // size in bytes for all elements in a block"""
  2039. ...
  2040. def ggml_type_sizef(type: int) -> float:
  2041. """ GGML_API float ggml_type_sizef(enum ggml_type type); // ggml_type_size()/ggml_blck_size() as float"""
  2042. ...
  2043. def ggml_unary(ctx: ffi.CData, a: ffi.CData, op: int) -> ffi.CData:
  2044. """
  2045. GGML_API struct ggml_tensor * ggml_unary(
  2046. struct ggml_context * ctx,
  2047. struct ggml_tensor * a,
  2048. enum ggml_unary_op op);
  2049. """
  2050. ...
  2051. def ggml_unary_inplace(ctx: ffi.CData, a: ffi.CData, op: int) -> ffi.CData:
  2052. """
  2053. GGML_API struct ggml_tensor * ggml_unary_inplace(
  2054. struct ggml_context * ctx,
  2055. struct ggml_tensor * a,
  2056. enum ggml_unary_op op);
  2057. """
  2058. ...
  2059. def ggml_used_mem(ctx: ffi.CData) -> int:
  2060. """ GGML_API size_t ggml_used_mem(const struct ggml_context * ctx);"""
  2061. ...
  2062. def ggml_vec_dot_q2_K_q8_K(n: int, s: ffi.CData, vx: ffi.CData, vy: ffi.CData) -> None:
  2063. """
  2064. Dot product
  2065. void ggml_vec_dot_q2_K_q8_K(int n, float * restrict s, const void * restrict vx, const void * restrict vy);
  2066. """
  2067. ...
  2068. def ggml_vec_dot_q3_K_q8_K(n: int, s: ffi.CData, vx: ffi.CData, vy: ffi.CData) -> None:
  2069. """void ggml_vec_dot_q3_K_q8_K(int n, float * restrict s, const void * restrict vx, const void * restrict vy);"""
  2070. ...
  2071. def ggml_vec_dot_q4_K_q8_K(n: int, s: ffi.CData, vx: ffi.CData, vy: ffi.CData) -> None:
  2072. """void ggml_vec_dot_q4_K_q8_K(int n, float * restrict s, const void * restrict vx, const void * restrict vy);"""
  2073. ...
  2074. def ggml_vec_dot_q5_K_q8_K(n: int, s: ffi.CData, vx: ffi.CData, vy: ffi.CData) -> None:
  2075. """void ggml_vec_dot_q5_K_q8_K(int n, float * restrict s, const void * restrict vx, const void * restrict vy);"""
  2076. ...
  2077. def ggml_vec_dot_q6_K_q8_K(n: int, s: ffi.CData, vx: ffi.CData, vy: ffi.CData) -> None:
  2078. """void ggml_vec_dot_q6_K_q8_K(int n, float * restrict s, const void * restrict vx, const void * restrict vy);"""
  2079. ...
  2080. def ggml_view_1d(ctx: ffi.CData, a: ffi.CData, ne0: int, offset: int) -> ffi.CData:
  2081. """
  2082. offset in bytes
  2083. GGML_API struct ggml_tensor * ggml_view_1d(
  2084. struct ggml_context * ctx,
  2085. struct ggml_tensor * a,
  2086. int64_t ne0,
  2087. size_t offset);
  2088. """
  2089. ...
  2090. def ggml_view_2d(ctx: ffi.CData, a: ffi.CData, ne0: int, ne1: int, nb1: int, offset: int) -> ffi.CData:
  2091. """
  2092. GGML_API struct ggml_tensor * ggml_view_2d(
  2093. struct ggml_context * ctx,
  2094. struct ggml_tensor * a,
  2095. int64_t ne0,
  2096. int64_t ne1,
  2097. size_t nb1, // row stride in bytes
  2098. size_t offset);
  2099. """
  2100. ...
  2101. def ggml_view_3d(ctx: ffi.CData, a: ffi.CData, ne0: int, ne1: int, ne2: int, nb1: int, nb2: int, offset: int) -> ffi.CData:
  2102. """
  2103. GGML_API struct ggml_tensor * ggml_view_3d(
  2104. struct ggml_context * ctx,
  2105. struct ggml_tensor * a,
  2106. int64_t ne0,
  2107. int64_t ne1,
  2108. int64_t ne2,
  2109. size_t nb1, // row stride in bytes
  2110. size_t nb2, // slice stride in bytes
  2111. size_t offset);
  2112. """
  2113. ...
  2114. def ggml_view_4d(ctx: ffi.CData, a: ffi.CData, ne0: int, ne1: int, ne2: int, ne3: int, nb1: int, nb2: int, nb3: int, offset: int) -> ffi.CData:
  2115. """
  2116. GGML_API struct ggml_tensor * ggml_view_4d(
  2117. struct ggml_context * ctx,
  2118. struct ggml_tensor * a,
  2119. int64_t ne0,
  2120. int64_t ne1,
  2121. int64_t ne2,
  2122. int64_t ne3,
  2123. size_t nb1, // row stride in bytes
  2124. size_t nb2, // slice stride in bytes
  2125. size_t nb3,
  2126. size_t offset);
  2127. """
  2128. ...
  2129. def ggml_view_tensor(ctx: ffi.CData, src: ffi.CData) -> ffi.CData:
  2130. """ GGML_API struct ggml_tensor * ggml_view_tensor(struct ggml_context * ctx, const struct ggml_tensor * src);"""
  2131. ...
  2132. def ggml_win_part(ctx: ffi.CData, a: ffi.CData, w: int) -> ffi.CData:
  2133. """
  2134. partition into non-overlapping windows with padding if needed
  2135. example:
  2136. a: 768 64 64 1
  2137. w: 14
  2138. res: 768 14 14 25
  2139. used in sam
  2140. GGML_API struct ggml_tensor * ggml_win_part(
  2141. struct ggml_context * ctx,
  2142. struct ggml_tensor * a,
  2143. int w);
  2144. """
  2145. ...
  2146. def ggml_win_unpart(ctx: ffi.CData, a: ffi.CData, w0: int, h0: int, w: int) -> ffi.CData:
  2147. """
  2148. reverse of ggml_win_part
  2149. used in sam
  2150. GGML_API struct ggml_tensor * ggml_win_unpart(
  2151. struct ggml_context * ctx,
  2152. struct ggml_tensor * a,
  2153. int w0,
  2154. int h0,
  2155. int w);
  2156. """
  2157. ...
  2158. def gguf_add_tensor(ctx: ffi.CData, tensor: ffi.CData) -> None:
  2159. """
  2160. manage tensor info
  2161. GGML_API void gguf_add_tensor(struct gguf_context * ctx, const struct ggml_tensor * tensor);
  2162. """
  2163. ...
  2164. def gguf_find_key(ctx: ffi.CData, key: ffi.CData) -> int:
  2165. """ GGML_API int gguf_find_key(struct gguf_context * ctx, const char * key);"""
  2166. ...
  2167. def gguf_find_tensor(ctx: ffi.CData, name: ffi.CData) -> int:
  2168. """ GGML_API int gguf_find_tensor (struct gguf_context * ctx, const char * name);"""
  2169. ...
  2170. def gguf_free(ctx: ffi.CData) -> None:
  2171. """ GGML_API void gguf_free(struct gguf_context * ctx);"""
  2172. ...
  2173. def gguf_get_alignment(ctx: ffi.CData) -> int:
  2174. """ GGML_API size_t gguf_get_alignment (struct gguf_context * ctx);"""
  2175. ...
  2176. def gguf_get_arr_data(ctx: ffi.CData, i: int) -> ffi.CData:
  2177. """ GGML_API const void * gguf_get_arr_data(struct gguf_context * ctx, int i);"""
  2178. ...
  2179. def gguf_get_arr_n(ctx: ffi.CData, i: int) -> int:
  2180. """ GGML_API int gguf_get_arr_n (struct gguf_context * ctx, int i);"""
  2181. ...
  2182. def gguf_get_arr_str(ctx: ffi.CData, key_id: int, i: int) -> ffi.CData:
  2183. """ GGML_API const char * gguf_get_arr_str (struct gguf_context * ctx, int key_id, int i);"""
  2184. ...
  2185. def gguf_get_arr_type(ctx: ffi.CData, i: int) -> int:
  2186. """ GGML_API enum gguf_type gguf_get_arr_type(struct gguf_context * ctx, int i);"""
  2187. ...
  2188. def gguf_get_data(ctx: ffi.CData) -> ffi.CData:
  2189. """ GGML_API void * gguf_get_data (struct gguf_context * ctx);"""
  2190. ...
  2191. def gguf_get_data_offset(ctx: ffi.CData) -> int:
  2192. """ GGML_API size_t gguf_get_data_offset(struct gguf_context * ctx);"""
  2193. ...
  2194. def gguf_get_key(ctx: ffi.CData, i: int) -> ffi.CData:
  2195. """ GGML_API const char * gguf_get_key (struct gguf_context * ctx, int i);"""
  2196. ...
  2197. def gguf_get_kv_type(ctx: ffi.CData, i: int) -> int:
  2198. """ GGML_API enum gguf_type gguf_get_kv_type (struct gguf_context * ctx, int i);"""
  2199. ...
  2200. def gguf_get_meta_data(ctx: ffi.CData, data: ffi.CData) -> None:
  2201. """ GGML_API void gguf_get_meta_data(struct gguf_context * ctx, void * data);"""
  2202. ...
  2203. def gguf_get_meta_size(ctx: ffi.CData) -> int:
  2204. """
  2205. get the size in bytes of the meta data (header, kv pairs, tensor info) including padding
  2206. GGML_API size_t gguf_get_meta_size(struct gguf_context * ctx);
  2207. """
  2208. ...
  2209. def gguf_get_n_kv(ctx: ffi.CData) -> int:
  2210. """ GGML_API int gguf_get_n_kv(struct gguf_context * ctx);"""
  2211. ...
  2212. def gguf_get_n_tensors(ctx: ffi.CData) -> int:
  2213. """ GGML_API int gguf_get_n_tensors (struct gguf_context * ctx);"""
  2214. ...
  2215. def gguf_get_tensor_name(ctx: ffi.CData, i: int) -> ffi.CData:
  2216. """ GGML_API char * gguf_get_tensor_name (struct gguf_context * ctx, int i);"""
  2217. ...
  2218. def gguf_get_tensor_offset(ctx: ffi.CData, i: int) -> int:
  2219. """ GGML_API size_t gguf_get_tensor_offset(struct gguf_context * ctx, int i);"""
  2220. ...
  2221. def gguf_get_val_bool(ctx: ffi.CData, i: int) -> bool:
  2222. """ GGML_API bool gguf_get_val_bool(struct gguf_context * ctx, int i);"""
  2223. ...
  2224. def gguf_get_val_f32(ctx: ffi.CData, i: int) -> float:
  2225. """ GGML_API float gguf_get_val_f32 (struct gguf_context * ctx, int i);"""
  2226. ...
  2227. def gguf_get_val_i16(ctx: ffi.CData, i: int) -> int:
  2228. """ GGML_API int16_t gguf_get_val_i16 (struct gguf_context * ctx, int i);"""
  2229. ...
  2230. def gguf_get_val_i32(ctx: ffi.CData, i: int) -> int:
  2231. """ GGML_API int32_t gguf_get_val_i32 (struct gguf_context * ctx, int i);"""
  2232. ...
  2233. def gguf_get_val_i8(ctx: ffi.CData, i: int) -> int:
  2234. """ GGML_API int8_t gguf_get_val_i8 (struct gguf_context * ctx, int i);"""
  2235. ...
  2236. def gguf_get_val_str(ctx: ffi.CData, i: int) -> ffi.CData:
  2237. """ GGML_API const char * gguf_get_val_str (struct gguf_context * ctx, int i);"""
  2238. ...
  2239. def gguf_get_val_u16(ctx: ffi.CData, i: int) -> int:
  2240. """ GGML_API uint16_t gguf_get_val_u16 (struct gguf_context * ctx, int i);"""
  2241. ...
  2242. def gguf_get_val_u32(ctx: ffi.CData, i: int) -> int:
  2243. """ GGML_API uint32_t gguf_get_val_u32 (struct gguf_context * ctx, int i);"""
  2244. ...
  2245. def gguf_get_val_u8(ctx: ffi.CData, i: int) -> int:
  2246. """
  2247. results are undefined if the wrong type is used for the key
  2248. GGML_API uint8_t gguf_get_val_u8 (struct gguf_context * ctx, int i);
  2249. """
  2250. ...
  2251. def gguf_get_version(ctx: ffi.CData) -> int:
  2252. """ GGML_API int gguf_get_version (struct gguf_context * ctx);"""
  2253. ...
  2254. def gguf_init_empty() -> ffi.CData:
  2255. """ GGML_API struct gguf_context * gguf_init_empty(void);"""
  2256. ...
  2257. def gguf_init_from_file(fname: ffi.CData, params: ffi.CData) -> ffi.CData:
  2258. """ GGML_API struct gguf_context * gguf_init_from_file(const char * fname, struct gguf_init_params params);"""
  2259. ...
  2260. def gguf_set_arr_data(ctx: ffi.CData, key: ffi.CData, type: int, data: ffi.CData, n: int) -> None:
  2261. """ GGML_API void gguf_set_arr_data(struct gguf_context * ctx, const char * key, enum gguf_type type, const void * data, int n);"""
  2262. ...
  2263. def gguf_set_arr_str(ctx: ffi.CData, key: ffi.CData, data: ffi.CData, n: int) -> None:
  2264. """ GGML_API void gguf_set_arr_str (struct gguf_context * ctx, const char * key, const char ** data, int n);"""
  2265. ...
  2266. def gguf_set_kv(ctx: ffi.CData, src: ffi.CData) -> None:
  2267. """
  2268. set or add KV pairs from another context
  2269. GGML_API void gguf_set_kv(struct gguf_context * ctx, struct gguf_context * src);
  2270. """
  2271. ...
  2272. def gguf_set_tensor_data(ctx: ffi.CData, name: ffi.CData, data: ffi.CData, size: int) -> None:
  2273. """ GGML_API void gguf_set_tensor_data(struct gguf_context * ctx, const char * name, const void * data, size_t size);"""
  2274. ...
  2275. def gguf_set_tensor_type(ctx: ffi.CData, name: ffi.CData, type: int) -> None:
  2276. """ GGML_API void gguf_set_tensor_type(struct gguf_context * ctx, const char * name, enum ggml_type type);"""
  2277. ...
  2278. def gguf_set_val_bool(ctx: ffi.CData, key: ffi.CData, val: bool) -> None:
  2279. """ GGML_API void gguf_set_val_bool(struct gguf_context * ctx, const char * key, bool val);"""
  2280. ...
  2281. def gguf_set_val_f32(ctx: ffi.CData, key: ffi.CData, val: float) -> None:
  2282. """ GGML_API void gguf_set_val_f32 (struct gguf_context * ctx, const char * key, float val);"""
  2283. ...
  2284. def gguf_set_val_i16(ctx: ffi.CData, key: ffi.CData, val: int) -> None:
  2285. """ GGML_API void gguf_set_val_i16 (struct gguf_context * ctx, const char * key, int16_t val);"""
  2286. ...
  2287. def gguf_set_val_i32(ctx: ffi.CData, key: ffi.CData, val: int) -> None:
  2288. """ GGML_API void gguf_set_val_i32 (struct gguf_context * ctx, const char * key, int32_t val);"""
  2289. ...
  2290. def gguf_set_val_i8(ctx: ffi.CData, key: ffi.CData, val: int) -> None:
  2291. """ GGML_API void gguf_set_val_i8 (struct gguf_context * ctx, const char * key, int8_t val);"""
  2292. ...
  2293. def gguf_set_val_str(ctx: ffi.CData, key: ffi.CData, val: ffi.CData) -> None:
  2294. """ GGML_API void gguf_set_val_str (struct gguf_context * ctx, const char * key, const char * val);"""
  2295. ...
  2296. def gguf_set_val_u16(ctx: ffi.CData, key: ffi.CData, val: int) -> None:
  2297. """ GGML_API void gguf_set_val_u16 (struct gguf_context * ctx, const char * key, uint16_t val);"""
  2298. ...
  2299. def gguf_set_val_u32(ctx: ffi.CData, key: ffi.CData, val: int) -> None:
  2300. """ GGML_API void gguf_set_val_u32 (struct gguf_context * ctx, const char * key, uint32_t val);"""
  2301. ...
  2302. def gguf_set_val_u8(ctx: ffi.CData, key: ffi.CData, val: int) -> None:
  2303. """
  2304. overrides existing values or adds a new one
  2305. GGML_API void gguf_set_val_u8 (struct gguf_context * ctx, const char * key, uint8_t val);
  2306. """
  2307. ...
  2308. def gguf_type_name(type: int) -> ffi.CData:
  2309. """ GGML_API const char * gguf_type_name(enum gguf_type type);"""
  2310. ...
  2311. def gguf_write_to_file(ctx: ffi.CData, fname: ffi.CData, only_meta: bool) -> None:
  2312. """
  2313. write the entire context to a binary file
  2314. GGML_API void gguf_write_to_file(struct gguf_context * ctx, const char * fname, bool only_meta);
  2315. """
  2316. ...
  2317. def quantize_row_q2_K(x: ffi.CData, y: ffi.CData, k: int) -> None:
  2318. """void quantize_row_q2_K(const float * restrict x, void * restrict y, int k);"""
  2319. ...
  2320. def quantize_row_q2_K_reference(x: ffi.CData, y: ffi.CData, k: int) -> None:
  2321. """
  2322. Quantization
  2323. void quantize_row_q2_K_reference(const float * restrict x, block_q2_K * restrict y, int k);
  2324. """
  2325. ...
  2326. def quantize_row_q3_K(x: ffi.CData, y: ffi.CData, k: int) -> None:
  2327. """void quantize_row_q3_K(const float * restrict x, void * restrict y, int k);"""
  2328. ...
  2329. def quantize_row_q3_K_reference(x: ffi.CData, y: ffi.CData, k: int) -> None:
  2330. """void quantize_row_q3_K_reference(const float * restrict x, block_q3_K * restrict y, int k);"""
  2331. ...
  2332. def quantize_row_q4_K(x: ffi.CData, y: ffi.CData, k: int) -> None:
  2333. """void quantize_row_q4_K(const float * restrict x, void * restrict y, int k);"""
  2334. ...
  2335. def quantize_row_q4_K_reference(x: ffi.CData, y: ffi.CData, k: int) -> None:
  2336. """void quantize_row_q4_K_reference(const float * restrict x, block_q4_K * restrict y, int k);"""
  2337. ...
  2338. def quantize_row_q5_K(x: ffi.CData, y: ffi.CData, k: int) -> None:
  2339. """void quantize_row_q5_K(const float * restrict x, void * restrict y, int k);"""
  2340. ...
  2341. def quantize_row_q5_K_reference(x: ffi.CData, y: ffi.CData, k: int) -> None:
  2342. """void quantize_row_q5_K_reference(const float * restrict x, block_q5_K * restrict y, int k);"""
  2343. ...
  2344. def quantize_row_q6_K(x: ffi.CData, y: ffi.CData, k: int) -> None:
  2345. """void quantize_row_q6_K(const float * restrict x, void * restrict y, int k);"""
  2346. ...
  2347. def quantize_row_q6_K_reference(x: ffi.CData, y: ffi.CData, k: int) -> None:
  2348. """void quantize_row_q6_K_reference(const float * restrict x, block_q6_K * restrict y, int k);"""
  2349. ...
  2350. def quantize_row_q8_K(x: ffi.CData, y: ffi.CData, k: int) -> None:
  2351. """void quantize_row_q8_K(const float * restrict x, void * restrict y, int k);"""
  2352. ...
  2353. def quantize_row_q8_K_reference(x: ffi.CData, y: ffi.CData, k: int) -> None:
  2354. """void quantize_row_q8_K_reference(const float * restrict x, block_q8_K * restrict y, int k);"""
  2355. ...