nexaai 1.0.19rc5__cp310-cp310-macosx_14_0_universal2.whl → 1.0.19rc7__cp310-cp310-macosx_14_0_universal2.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of nexaai might be problematic. Click here for more details.

Files changed (221) hide show
  1. nexaai/_stub.cpython-310-darwin.so +0 -0
  2. nexaai/_version.py +1 -1
  3. nexaai/binds/libnexa_bridge.dylib +0 -0
  4. nexaai/binds/nexa_llama_cpp/libggml-base.dylib +0 -0
  5. nexaai/binds/nexa_llama_cpp/libggml-cpu.so +0 -0
  6. nexaai/binds/nexa_llama_cpp/libggml-metal.so +0 -0
  7. nexaai/binds/nexa_llama_cpp/libggml.dylib +0 -0
  8. nexaai/binds/nexa_llama_cpp/libllama.dylib +0 -0
  9. nexaai/binds/nexa_llama_cpp/libmtmd.dylib +0 -0
  10. nexaai/binds/nexa_llama_cpp/libnexa_plugin.dylib +0 -0
  11. nexaai/binds/nexa_mlx/libnexa_plugin.dylib +0 -0
  12. nexaai/binds/nexa_mlx/py-lib/asr/__init__.py +12 -0
  13. nexaai/binds/nexa_mlx/py-lib/asr/interface.py +122 -0
  14. nexaai/binds/nexa_mlx/py-lib/common/__init__.py +0 -0
  15. nexaai/binds/nexa_mlx/py-lib/common/utils.py +25 -0
  16. nexaai/binds/nexa_mlx/py-lib/cv/__init__.py +0 -0
  17. nexaai/binds/nexa_mlx/py-lib/cv/generate.py +195 -0
  18. nexaai/binds/nexa_mlx/py-lib/cv/interface.py +151 -0
  19. nexaai/binds/nexa_mlx/py-lib/cv/main.py +81 -0
  20. nexaai/binds/nexa_mlx/py-lib/cv/modeling/pp_ocr_v4.py +1736 -0
  21. nexaai/binds/nexa_mlx/py-lib/embedding/__init__.py +0 -0
  22. nexaai/binds/nexa_mlx/py-lib/embedding/generate.py +333 -0
  23. nexaai/binds/nexa_mlx/py-lib/embedding/interface.py +617 -0
  24. nexaai/binds/nexa_mlx/py-lib/embedding/main.py +173 -0
  25. nexaai/binds/nexa_mlx/py-lib/embedding/modeling/__init__.py +0 -0
  26. nexaai/binds/nexa_mlx/py-lib/embedding/modeling/nexa_jina_v2.py +399 -0
  27. nexaai/binds/nexa_mlx/py-lib/image_gen/__init__.py +1 -0
  28. nexaai/binds/nexa_mlx/py-lib/image_gen/generate_sd.py +244 -0
  29. nexaai/binds/nexa_mlx/py-lib/image_gen/interface.py +82 -0
  30. nexaai/binds/nexa_mlx/py-lib/image_gen/main.py +281 -0
  31. nexaai/binds/nexa_mlx/py-lib/image_gen/stable_diffusion/__init__.py +306 -0
  32. nexaai/binds/nexa_mlx/py-lib/image_gen/stable_diffusion/clip.py +116 -0
  33. nexaai/binds/nexa_mlx/py-lib/image_gen/stable_diffusion/config.py +65 -0
  34. nexaai/binds/nexa_mlx/py-lib/image_gen/stable_diffusion/model_io.py +386 -0
  35. nexaai/binds/nexa_mlx/py-lib/image_gen/stable_diffusion/sampler.py +105 -0
  36. nexaai/binds/nexa_mlx/py-lib/image_gen/stable_diffusion/tokenizer.py +100 -0
  37. nexaai/binds/nexa_mlx/py-lib/image_gen/stable_diffusion/unet.py +460 -0
  38. nexaai/binds/nexa_mlx/py-lib/image_gen/stable_diffusion/vae.py +274 -0
  39. nexaai/binds/nexa_mlx/py-lib/llm/__init__.py +0 -0
  40. nexaai/binds/nexa_mlx/py-lib/llm/generate.py +149 -0
  41. nexaai/binds/nexa_mlx/py-lib/llm/interface.py +764 -0
  42. nexaai/binds/nexa_mlx/py-lib/llm/main.py +68 -0
  43. nexaai/binds/nexa_mlx/py-lib/rerank/__init__.py +0 -0
  44. nexaai/binds/nexa_mlx/py-lib/rerank/generate.py +174 -0
  45. nexaai/binds/nexa_mlx/py-lib/rerank/interface.py +287 -0
  46. nexaai/binds/nexa_mlx/py-lib/rerank/main.py +127 -0
  47. nexaai/binds/nexa_mlx/py-lib/rerank/modeling/__init__.py +0 -0
  48. nexaai/binds/nexa_mlx/py-lib/rerank/modeling/nexa_jina_rerank.py +330 -0
  49. nexaai/binds/nexa_mlx/py-lib/sd/__init__.py +1 -0
  50. nexaai/binds/nexa_mlx/py-lib/sd/interface.py +362 -0
  51. nexaai/binds/nexa_mlx/py-lib/sd/main.py +286 -0
  52. nexaai/binds/nexa_mlx/py-lib/sd/modeling/__init__.py +306 -0
  53. nexaai/binds/nexa_mlx/py-lib/sd/modeling/clip.py +116 -0
  54. nexaai/binds/nexa_mlx/py-lib/sd/modeling/config.py +65 -0
  55. nexaai/binds/nexa_mlx/py-lib/sd/modeling/model_io.py +385 -0
  56. nexaai/binds/nexa_mlx/py-lib/sd/modeling/sampler.py +105 -0
  57. nexaai/binds/nexa_mlx/py-lib/sd/modeling/tokenizer.py +100 -0
  58. nexaai/binds/nexa_mlx/py-lib/sd/modeling/unet.py +460 -0
  59. nexaai/binds/nexa_mlx/py-lib/sd/modeling/vae.py +274 -0
  60. nexaai/binds/nexa_mlx/py-lib/tts/__init__.py +12 -0
  61. nexaai/binds/nexa_mlx/py-lib/tts/interface.py +276 -0
  62. nexaai/binds/nexa_mlx/py-lib/vlm/__init__.py +3 -0
  63. nexaai/binds/nexa_mlx/py-lib/vlm/generate.py +572 -0
  64. nexaai/binds/nexa_mlx/py-lib/vlm/generate_qwen3_vl.py +294 -0
  65. nexaai/binds/nexa_mlx/py-lib/vlm/generate_qwen3_vl_moe.py +276 -0
  66. nexaai/binds/nexa_mlx/py-lib/vlm/interface.py +504 -0
  67. nexaai/binds/nexa_mlx/py-lib/vlm/main.py +320 -0
  68. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/__init__.py +0 -0
  69. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/convert.py +68 -0
  70. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/__init__.py +0 -0
  71. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/aya_vision/__init__.py +8 -0
  72. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/aya_vision/aya_vision.py +193 -0
  73. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/aya_vision/interpolate.py +186 -0
  74. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/aya_vision/language.py +233 -0
  75. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/aya_vision/vision.py +503 -0
  76. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/base.py +202 -0
  77. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/cache.py +230 -0
  78. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/deepseek_vl_v2/__init__.py +10 -0
  79. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/deepseek_vl_v2/conversation.py +264 -0
  80. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/deepseek_vl_v2/deepseek_vl_v2.py +472 -0
  81. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/deepseek_vl_v2/language.py +591 -0
  82. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/deepseek_vl_v2/processing_deepsek_vl_v2.py +526 -0
  83. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/deepseek_vl_v2/vision.py +356 -0
  84. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/florence2/__init__.py +8 -0
  85. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/florence2/florence2.py +366 -0
  86. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/florence2/language.py +488 -0
  87. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/florence2/vision.py +591 -0
  88. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3/__init__.py +8 -0
  89. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3/gemma3.py +213 -0
  90. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3/language.py +315 -0
  91. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3/vision.py +238 -0
  92. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3n/__init__.py +2 -0
  93. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3n/audio.py +1038 -0
  94. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3n/config.py +139 -0
  95. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3n/gemma3n.py +322 -0
  96. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3n/language.py +629 -0
  97. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3n/vision.py +1022 -0
  98. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/idefics2/__init__.py +9 -0
  99. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/idefics2/idefics2.py +294 -0
  100. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/idefics2/language.py +191 -0
  101. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/idefics2/vision.py +267 -0
  102. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/idefics3/__init__.py +8 -0
  103. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/idefics3/idefics3.py +175 -0
  104. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/idefics3/language.py +192 -0
  105. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/idefics3/vision.py +233 -0
  106. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/internvl_chat/__init__.py +9 -0
  107. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/internvl_chat/internvl_chat.py +140 -0
  108. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/internvl_chat/language.py +220 -0
  109. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/internvl_chat/processor.py +393 -0
  110. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/internvl_chat/vision.py +293 -0
  111. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/kernels.py +307 -0
  112. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/kimi_vl/__init__.py +8 -0
  113. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/kimi_vl/kimi_vl.py +143 -0
  114. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/kimi_vl/language.py +509 -0
  115. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/kimi_vl/vision.py +522 -0
  116. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llama4/__init__.py +8 -0
  117. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llama4/language.py +386 -0
  118. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llama4/llama4.py +138 -0
  119. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llama4/vision.py +560 -0
  120. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava/__init__.py +8 -0
  121. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava/language.py +240 -0
  122. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava/llava.py +153 -0
  123. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava/vision.py +259 -0
  124. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava_bunny/__init__.py +9 -0
  125. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava_bunny/language.py +236 -0
  126. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava_bunny/llava_bunny.py +256 -0
  127. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava_bunny/vision.py +303 -0
  128. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava_next/__init__.py +8 -0
  129. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava_next/language.py +230 -0
  130. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava_next/llava_next.py +160 -0
  131. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava_next/vision.py +243 -0
  132. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/mistral3/__init__.py +8 -0
  133. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/mistral3/mistral3.py +283 -0
  134. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/mllama/__init__.py +8 -0
  135. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/mllama/language.py +416 -0
  136. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/mllama/mllama.py +172 -0
  137. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/mllama/vision.py +499 -0
  138. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/molmo/__init__.py +8 -0
  139. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/molmo/language.py +243 -0
  140. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/molmo/molmo.py +133 -0
  141. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/molmo/vision.py +465 -0
  142. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/multi_modality/__init__.py +10 -0
  143. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/multi_modality/language.py +230 -0
  144. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/multi_modality/multi_modality.py +385 -0
  145. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/multi_modality/sam.py +557 -0
  146. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/multi_modality/vision.py +526 -0
  147. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/paligemma/__init__.py +8 -0
  148. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/paligemma/language.py +282 -0
  149. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/paligemma/paligemma.py +160 -0
  150. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/paligemma/vision.py +242 -0
  151. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/phi3_v/__init__.py +8 -0
  152. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/phi3_v/language.py +21 -0
  153. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/phi3_v/phi3_v.py +243 -0
  154. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/phi3_v/su_rope.py +71 -0
  155. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/phi3_v/vision.py +324 -0
  156. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/pixtral/__init__.py +8 -0
  157. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/pixtral/language.py +229 -0
  158. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/pixtral/pixtral.py +161 -0
  159. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/pixtral/vision.py +320 -0
  160. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_5_vl/__init__.py +2 -0
  161. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_5_vl/config.py +108 -0
  162. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_5_vl/language.py +490 -0
  163. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_5_vl/qwen2_5_vl.py +168 -0
  164. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_5_vl/vision.py +414 -0
  165. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_vl/__init__.py +2 -0
  166. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_vl/config.py +104 -0
  167. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_vl/language.py +490 -0
  168. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_vl/qwen2_vl.py +167 -0
  169. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_vl/vision.py +312 -0
  170. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3_vl/llm_common/__init__.py +0 -0
  171. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3_vl/llm_common/base.py +117 -0
  172. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3_vl/llm_common/cache.py +531 -0
  173. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3_vl/llm_common/generate.py +701 -0
  174. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3_vl/llm_common/rope_utils.py +255 -0
  175. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3_vl/llm_common/sample_utils.py +303 -0
  176. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3_vl/llm_common/tokenizer_utils.py +407 -0
  177. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3_vl/processor.py +476 -0
  178. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3_vl/qwen3vl.py +1223 -0
  179. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/llm_common/__init__.py +0 -0
  180. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/llm_common/base.py +117 -0
  181. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/llm_common/cache.py +531 -0
  182. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/llm_common/generate.py +701 -0
  183. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/llm_common/rope_utils.py +255 -0
  184. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/llm_common/sample_utils.py +303 -0
  185. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/llm_common/tokenizer_utils.py +407 -0
  186. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/processor.py +476 -0
  187. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/qwen3vl_moe.py +1309 -0
  188. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/switch_layers.py +210 -0
  189. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/smolvlm/__init__.py +8 -0
  190. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/smolvlm/smolvlm.py +62 -0
  191. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/processing_qwen2_5_vl.py +209 -0
  192. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/processing_qwen2_vl.py +215 -0
  193. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/prompt_utils.py +474 -0
  194. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/sample_utils.py +39 -0
  195. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/tokenizer_utils.py +344 -0
  196. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/trainer/__init__.py +9 -0
  197. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/trainer/lora.py +70 -0
  198. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/trainer/trainer.py +296 -0
  199. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/trainer/utils.py +160 -0
  200. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/utils.py +928 -0
  201. nexaai/binds/nexa_nexaml/libggml-base.dylib +0 -0
  202. nexaai/binds/nexa_nexaml/libggml-cpu.so +0 -0
  203. nexaai/binds/nexa_nexaml/libggml-metal.so +0 -0
  204. nexaai/binds/nexa_nexaml/libggml.dylib +0 -0
  205. nexaai/mlx_backend/vlm/generate_qwen3_vl_moe.py +276 -0
  206. nexaai/mlx_backend/vlm/interface.py +21 -4
  207. nexaai/mlx_backend/vlm/main.py +6 -2
  208. nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/__init__.py +0 -0
  209. nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/base.py +117 -0
  210. nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/cache.py +531 -0
  211. nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/generate.py +701 -0
  212. nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/rope_utils.py +255 -0
  213. nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/sample_utils.py +303 -0
  214. nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/tokenizer_utils.py +407 -0
  215. nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/processor.py +476 -0
  216. nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/qwen3vl_moe.py +1309 -0
  217. nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/switch_layers.py +210 -0
  218. {nexaai-1.0.19rc5.dist-info → nexaai-1.0.19rc7.dist-info}/METADATA +1 -1
  219. {nexaai-1.0.19rc5.dist-info → nexaai-1.0.19rc7.dist-info}/RECORD +221 -21
  220. {nexaai-1.0.19rc5.dist-info → nexaai-1.0.19rc7.dist-info}/WHEEL +0 -0
  221. {nexaai-1.0.19rc5.dist-info → nexaai-1.0.19rc7.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,416 @@
1
+ import inspect
2
+ from dataclasses import dataclass, field
3
+ from typing import Dict, List, Optional, Tuple, Union
4
+
5
+ import mlx.core as mx
6
+ import mlx.nn as nn
7
+
8
+ from ..base import (
9
+ LanguageModelOutput,
10
+ create_attention_mask,
11
+ scaled_dot_product_attention,
12
+ )
13
+ from ..cache import KVCache
14
+
15
+
16
+ @dataclass
17
+ class TextConfig:
18
+ model_type: str = "mllama"
19
+ vocab_size: int = 32000
20
+ hidden_size: int = 4096
21
+ intermediate_size: int = 14336
22
+ num_hidden_layers: int = 40
23
+ num_attention_heads: int = 32
24
+ num_key_value_heads: int = 8
25
+ hidden_act: str = "silu"
26
+ max_position_embeddings: int = 131072
27
+ initializer_range: float = 0.02
28
+ rms_norm_eps: float = 1e-6
29
+ tie_word_embeddings: bool = False
30
+ rope_theta: float = 10000.0
31
+ rope_traditional: bool = False
32
+ rope_scaling: Optional[Dict[str, Union[float, str]]] = None
33
+ cross_attention_layers: List[int] = field(
34
+ default_factory=lambda: [3, 8, 13, 18, 23, 28, 33, 38]
35
+ )
36
+
37
+ def __post_init__(self):
38
+ if self.num_key_value_heads is None:
39
+ self.num_key_value_heads = self.num_attention_heads
40
+
41
+ @classmethod
42
+ def from_dict(cls, params):
43
+ return cls(
44
+ **{
45
+ k: v
46
+ for k, v in params.items()
47
+ if k in inspect.signature(cls).parameters
48
+ }
49
+ )
50
+
51
+
52
+ class MllamaTextCrossAttention(nn.Module):
53
+ def __init__(self, config: TextConfig, layer_idx: Optional[int] = None):
54
+ super().__init__()
55
+ self.config = config
56
+ self.hidden_size = config.hidden_size
57
+ self.num_heads = config.num_attention_heads
58
+ self.head_dim = self.hidden_size // self.num_heads
59
+ self.num_key_value_heads = config.num_key_value_heads
60
+ self.num_key_value_groups = self.num_heads // self.num_key_value_heads
61
+ self.layer_idx = layer_idx
62
+ self.scale = self.head_dim**-0.5
63
+ self.q_proj = nn.Linear(
64
+ self.hidden_size, self.num_heads * self.head_dim, bias=False
65
+ )
66
+ self.k_proj = nn.Linear(
67
+ self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False
68
+ )
69
+ self.v_proj = nn.Linear(
70
+ self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False
71
+ )
72
+ self.o_proj = nn.Linear(
73
+ self.num_heads * self.head_dim, self.hidden_size, bias=False
74
+ )
75
+
76
+ self.q_norm = nn.RMSNorm(self.head_dim, eps=config.rms_norm_eps)
77
+ self.k_norm = nn.RMSNorm(self.head_dim, eps=config.rms_norm_eps)
78
+
79
+ def __call__(
80
+ self,
81
+ hidden_states: mx.array,
82
+ cross_attention_states: Optional[mx.array] = None,
83
+ attention_mask: Optional[mx.array] = None,
84
+ cache: Optional[KVCache] = None,
85
+ ) -> mx.array:
86
+
87
+ bsz, q_len, _ = hidden_states.shape
88
+ query = (
89
+ self.q_proj(hidden_states)
90
+ .reshape(bsz, q_len, self.num_heads, self.head_dim)
91
+ .transpose(0, 2, 1, 3)
92
+ )
93
+ query_states = self.q_norm(query)
94
+
95
+ if cross_attention_states is not None:
96
+ key_states = (
97
+ self.k_proj(cross_attention_states)
98
+ .reshape(bsz, -1, self.num_key_value_heads, self.head_dim)
99
+ .transpose(0, 2, 1, 3)
100
+ )
101
+ value_states = (
102
+ self.v_proj(cross_attention_states)
103
+ .reshape(bsz, -1, self.num_key_value_heads, self.head_dim)
104
+ .transpose(0, 2, 1, 3)
105
+ )
106
+ key_states = self.k_norm(key_states)
107
+ elif cache is not None and cache.offset > 0:
108
+ key_states, value_states = cache.fetch()
109
+ else:
110
+ key_states, value_states = mx.split(query, 2, axis=1)
111
+ key_states = self.k_norm(key_states)
112
+
113
+ attn_output = scaled_dot_product_attention(
114
+ query_states,
115
+ key_states,
116
+ value_states,
117
+ cache,
118
+ scale=self.scale,
119
+ mask=attention_mask, # add a dim for batch processing
120
+ )
121
+ attn_output = attn_output.transpose(0, 2, 1, 3).reshape(
122
+ bsz, q_len, self.hidden_size
123
+ )
124
+ return self.o_proj(attn_output)
125
+
126
+
127
+ class MllamaTextSelfAttention(nn.Module):
128
+ def __init__(self, config: TextConfig, layer_idx: int):
129
+ super().__init__()
130
+ self.config = config
131
+ self.hidden_size = config.hidden_size
132
+ self.num_heads = config.num_attention_heads
133
+ self.head_dim = self.hidden_size // self.num_heads
134
+ self.num_key_value_heads = config.num_key_value_heads
135
+ self.num_key_value_groups = self.num_heads // self.num_key_value_heads
136
+ self.scale = self.head_dim**-0.5
137
+ self.layer_idx = layer_idx
138
+
139
+ self.q_proj = nn.Linear(
140
+ self.hidden_size, self.num_heads * self.head_dim, bias=False
141
+ )
142
+ self.k_proj = nn.Linear(
143
+ self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False
144
+ )
145
+ self.v_proj = nn.Linear(
146
+ self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False
147
+ )
148
+ self.o_proj = nn.Linear(
149
+ self.num_heads * self.head_dim, self.hidden_size, bias=False
150
+ )
151
+
152
+ self.rope = nn.RoPE(
153
+ self.head_dim,
154
+ traditional=config.rope_traditional,
155
+ base=config.rope_theta,
156
+ scale=1,
157
+ )
158
+
159
+ def __call__(
160
+ self,
161
+ x: mx.array,
162
+ mask: Optional[mx.array] = None,
163
+ cache: Optional[KVCache] = None,
164
+ ) -> mx.array:
165
+ bsz, q_len, _ = x.shape
166
+ query_states = (
167
+ self.q_proj(x).reshape(bsz, q_len, self.num_heads, -1).transpose(0, 2, 1, 3)
168
+ )
169
+ key_states = (
170
+ self.k_proj(x)
171
+ .reshape(bsz, q_len, self.num_key_value_heads, -1)
172
+ .transpose(0, 2, 1, 3)
173
+ )
174
+ value_states = (
175
+ self.v_proj(x)
176
+ .reshape(bsz, q_len, self.num_key_value_heads, -1)
177
+ .transpose(0, 2, 1, 3)
178
+ )
179
+
180
+ if cache is not None:
181
+ query_states = self.rope(query_states, offset=cache.offset)
182
+ key_states = self.rope(key_states, offset=cache.offset)
183
+ key_states, value_states = cache.update_and_fetch(key_states, value_states)
184
+ else:
185
+ query_states = self.rope(query_states)
186
+ key_states = self.rope(key_states)
187
+
188
+ attn_output = scaled_dot_product_attention(
189
+ query_states, key_states, value_states, cache, scale=self.scale, mask=mask
190
+ )
191
+ attn_output = attn_output.transpose(0, 2, 1, 3).reshape(
192
+ bsz, q_len, self.hidden_size
193
+ )
194
+ return self.o_proj(attn_output)
195
+
196
+
197
+ class MllamaTextMLP(nn.Module):
198
+ def __init__(self, config: TextConfig):
199
+ super().__init__()
200
+ self.gate_proj = nn.Linear(
201
+ config.hidden_size, config.intermediate_size, bias=False
202
+ )
203
+ self.up_proj = nn.Linear(
204
+ config.hidden_size, config.intermediate_size, bias=False
205
+ )
206
+ self.down_proj = nn.Linear(
207
+ config.intermediate_size, config.hidden_size, bias=False
208
+ )
209
+ self.act_fn = lambda x: x * mx.sigmoid(x)
210
+
211
+ def __call__(self, x):
212
+ return self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
213
+
214
+
215
+ class MllamaSelfAttentionDecoderLayer(nn.Module):
216
+ def __init__(self, config: TextConfig, layer_idx: int):
217
+ super().__init__()
218
+ self.hidden_size = config.hidden_size
219
+ self.self_attn = MllamaTextSelfAttention(config, layer_idx=layer_idx)
220
+ self.mlp = MllamaTextMLP(config)
221
+ self.input_layernorm = nn.RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
222
+ self.post_attention_layernorm = nn.RMSNorm(
223
+ config.hidden_size, eps=config.rms_norm_eps
224
+ )
225
+
226
+ def __call__(
227
+ self,
228
+ hidden_states: mx.array,
229
+ mask: Optional[mx.array] = None,
230
+ cache: Optional[KVCache] = None,
231
+ ) -> mx.array:
232
+ residual = hidden_states
233
+ hidden_states = self.input_layernorm(hidden_states)
234
+ hidden_states = self.self_attn(
235
+ x=hidden_states,
236
+ mask=mask,
237
+ cache=cache,
238
+ )
239
+ hidden_states = residual + hidden_states
240
+
241
+ residual = hidden_states
242
+ hidden_states = self.post_attention_layernorm(hidden_states)
243
+ hidden_states = self.mlp(hidden_states)
244
+ hidden_states = residual + hidden_states
245
+
246
+ return hidden_states
247
+
248
+
249
+ class MllamaCrossAttentionDecoderLayer(nn.Module):
250
+ def __init__(self, config: TextConfig, layer_idx: int):
251
+ super().__init__()
252
+ self.hidden_size = config.hidden_size
253
+ self.cross_attn = MllamaTextCrossAttention(config, layer_idx=layer_idx)
254
+ self.mlp = MllamaTextMLP(config)
255
+ self.input_layernorm = nn.RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
256
+ self.post_attention_layernorm = nn.RMSNorm(
257
+ config.hidden_size, eps=config.rms_norm_eps
258
+ )
259
+ self.cross_attn_attn_gate = mx.zeros(1)
260
+ self.cross_attn_mlp_gate = mx.zeros(1)
261
+
262
+ def __call__(
263
+ self,
264
+ hidden_states: mx.array,
265
+ cross_attention_states: mx.array,
266
+ attention_mask: Optional[mx.array] = None,
267
+ full_text_row_masked_out_mask: Optional[mx.array] = None,
268
+ cache: Optional[KVCache] = None,
269
+ ) -> mx.array:
270
+ residual = hidden_states
271
+ hidden_states = self.input_layernorm(hidden_states)
272
+ hidden_states = self.cross_attn(
273
+ hidden_states=hidden_states,
274
+ cross_attention_states=cross_attention_states,
275
+ attention_mask=attention_mask,
276
+ cache=cache,
277
+ )
278
+ hidden_states = residual + mx.tanh(self.cross_attn_attn_gate) * hidden_states
279
+
280
+ residual = hidden_states
281
+ hidden_states = self.post_attention_layernorm(hidden_states)
282
+ hidden_states = self.mlp(hidden_states)
283
+ if full_text_row_masked_out_mask is not None:
284
+ hidden_states = full_text_row_masked_out_mask[:, 0] * hidden_states
285
+ hidden_states = residual + mx.tanh(self.cross_attn_mlp_gate) * hidden_states
286
+
287
+ return hidden_states
288
+
289
+
290
+ class MllamaTextModel(nn.Module):
291
+ def __init__(self, config: TextConfig):
292
+ super().__init__()
293
+ self.config = config
294
+ self.vocab_size = config.vocab_size
295
+ self.hidden_size = config.hidden_size
296
+
297
+ self.embed_tokens = nn.Embedding(config.vocab_size + 8, config.hidden_size)
298
+ self.layers = [
299
+ (
300
+ MllamaCrossAttentionDecoderLayer(config, layer_idx)
301
+ if layer_idx in config.cross_attention_layers
302
+ else MllamaSelfAttentionDecoderLayer(config, layer_idx)
303
+ )
304
+ for layer_idx in range(config.num_hidden_layers)
305
+ ]
306
+ self.norm = nn.RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
307
+
308
+ def __call__(
309
+ self,
310
+ input_ids: Optional[mx.array] = None,
311
+ mask: Optional[mx.array] = None,
312
+ position_ids: Optional[mx.array] = None,
313
+ cross_attention_states: Optional[mx.array] = None,
314
+ cross_attention_mask: Optional[mx.array] = None,
315
+ full_text_row_masked_out_mask: Optional[mx.array] = None,
316
+ inputs_embeds: Optional[mx.array] = None,
317
+ cache: Optional[KVCache] = None,
318
+ ) -> mx.array:
319
+ if input_ids is not None and inputs_embeds is not None:
320
+ raise ValueError(
321
+ "You cannot specify both input_ids and inputs_embeds at the same time"
322
+ )
323
+ elif input_ids is not None:
324
+ batch_size, seq_length = input_ids.shape
325
+ inputs_embeds = self.embed_tokens(input_ids)
326
+ elif inputs_embeds is not None:
327
+ batch_size, seq_length, _ = inputs_embeds.shape
328
+ else:
329
+ raise ValueError("You have to specify either input_ids or inputs_embeds")
330
+
331
+ if position_ids is None:
332
+ position_ids = mx.expand_dims(mx.arange(seq_length), 0)
333
+ position_ids = mx.repeat(position_ids, batch_size, axis=0)
334
+
335
+ hidden_states = inputs_embeds
336
+
337
+ if cache is None:
338
+ cache = [None] * len(self.layers)
339
+
340
+ if mask is None:
341
+ mask = create_attention_mask(hidden_states, cache)
342
+
343
+ for idx, (decoder_layer, c) in enumerate(zip(self.layers, cache)):
344
+ if idx in self.config.cross_attention_layers:
345
+ layer_outputs = decoder_layer(
346
+ hidden_states,
347
+ cross_attention_states=cross_attention_states,
348
+ attention_mask=cross_attention_mask,
349
+ full_text_row_masked_out_mask=full_text_row_masked_out_mask,
350
+ cache=c,
351
+ )
352
+ else:
353
+ layer_outputs = decoder_layer(
354
+ hidden_states,
355
+ mask=mask,
356
+ cache=c,
357
+ )
358
+ hidden_states = layer_outputs
359
+
360
+ hidden_states = self.norm(hidden_states)
361
+
362
+ return hidden_states
363
+
364
+
365
+ class LanguageModel(nn.Module):
366
+ def __init__(self, config: TextConfig):
367
+ super().__init__()
368
+ self.config = config
369
+ self.model = MllamaTextModel(config)
370
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
371
+
372
+ def __call__(
373
+ self,
374
+ input_ids: Optional[mx.array] = None,
375
+ mask: Optional[mx.array] = None,
376
+ cross_attention_states: Optional[mx.array] = None,
377
+ cross_attention_mask: Optional[mx.array] = None,
378
+ full_text_row_masked_out_mask: Optional[mx.array] = None,
379
+ inputs_embeds: Optional[mx.array] = None,
380
+ cache: Optional[KVCache] = None,
381
+ ) -> Tuple[mx.array, Optional[mx.array]]:
382
+
383
+ hidden_states = self.model(
384
+ input_ids=input_ids,
385
+ mask=mask,
386
+ cross_attention_states=cross_attention_states,
387
+ cross_attention_mask=cross_attention_mask,
388
+ full_text_row_masked_out_mask=full_text_row_masked_out_mask,
389
+ inputs_embeds=inputs_embeds,
390
+ cache=cache,
391
+ )
392
+
393
+ logits = self.lm_head(hidden_states)
394
+
395
+ return LanguageModelOutput(
396
+ logits=logits, cross_attention_states=cross_attention_states
397
+ )
398
+
399
+ @staticmethod
400
+ def sanitize(weights):
401
+ # Remove unused precomputed rotary freqs
402
+ return {
403
+ k: v for k, v in weights.items() if "self_attn.rotary_emb.inv_freq" not in k
404
+ }
405
+
406
+ @property
407
+ def layers(self):
408
+ return self.model.layers
409
+
410
+ @property
411
+ def head_dim(self):
412
+ return self.config.hidden_size // self.config.num_attention_heads
413
+
414
+ @property
415
+ def n_kv_heads(self):
416
+ return self.config.num_key_value_heads
@@ -0,0 +1,172 @@
1
+ import glob
2
+ import inspect
3
+ import json
4
+ from dataclasses import dataclass
5
+ from pathlib import Path
6
+ from typing import List, Optional, Tuple
7
+
8
+ import mlx.core as mx
9
+ import mlx.nn as nn
10
+ from huggingface_hub import snapshot_download
11
+
12
+ from ..cache import KVCache
13
+ from .language import LanguageModel, TextConfig
14
+ from .vision import VisionConfig, VisionModel
15
+
16
+
17
+ @dataclass
18
+ class ModelConfig:
19
+ text_config: TextConfig
20
+ vision_config: VisionConfig
21
+ model_type: str
22
+ ignore_index: int = -100
23
+ image_token_index: int = 128256
24
+ vision_feature_select_strategy: str = "default"
25
+ vision_feature_layer: int = -2
26
+ vocab_size: int = 32000
27
+ eos_token_id: Optional[List[int]] = None
28
+
29
+ @classmethod
30
+ def from_dict(cls, params):
31
+ return cls(
32
+ **{
33
+ k: v
34
+ for k, v in params.items()
35
+ if k in inspect.signature(cls).parameters
36
+ }
37
+ )
38
+
39
+
40
+ class Model(nn.Module):
41
+ def __init__(self, config: ModelConfig):
42
+ super().__init__()
43
+ self.config = config
44
+ self.vision_tower = VisionModel(config.vision_config)
45
+ self.language_model = LanguageModel(config.text_config)
46
+ self.multi_modal_projector = nn.Linear(
47
+ config.vision_config.vision_output_dim,
48
+ config.text_config.hidden_size,
49
+ bias=True,
50
+ )
51
+
52
+ @property
53
+ def layers(self):
54
+ return self.language_model.model.layers
55
+
56
+ def __call__(
57
+ self,
58
+ input_ids: mx.array,
59
+ pixel_values: mx.array,
60
+ mask: mx.array,
61
+ cache: Optional[KVCache] = None,
62
+ **kwargs,
63
+ ) -> Tuple[mx.array, Optional[mx.array]]:
64
+
65
+ aspect_ratio_ids = kwargs.pop("aspect_ratio_ids", None)
66
+ aspect_ratio_mask = kwargs.pop("aspect_ratio_mask", None)
67
+ cross_attention_mask = kwargs.pop("cross_attention_mask", None)
68
+
69
+ inputs_embeds = None
70
+
71
+ # Process vision input if provided
72
+ if pixel_values is not None:
73
+ if aspect_ratio_ids is None:
74
+ raise ValueError(
75
+ "`aspect_ratio_ids` must be provided if `pixel_values` is provided"
76
+ )
77
+
78
+ vision_outputs = self.vision_tower(
79
+ pixel_values=pixel_values,
80
+ aspect_ratio_ids=aspect_ratio_ids,
81
+ aspect_ratio_mask=aspect_ratio_mask,
82
+ )
83
+ cross_attention_states = vision_outputs[0]
84
+
85
+ cross_attention_states = self.multi_modal_projector(
86
+ cross_attention_states
87
+ ).reshape(
88
+ -1,
89
+ cross_attention_states.shape[-2],
90
+ self.config.text_config.hidden_size,
91
+ )
92
+
93
+ else:
94
+ cross_attention_states = None
95
+
96
+ # Prepare cross attention mask
97
+ if cross_attention_mask is not None:
98
+ cross_attention_mask, full_text_row_masked_out_mask = (
99
+ self._prepare_cross_attention_mask(
100
+ cross_attention_mask,
101
+ num_vision_tokens=(
102
+ self.config.vision_config.image_size
103
+ // self.config.vision_config.patch_size
104
+ )
105
+ ** 2
106
+ + 1,
107
+ )
108
+ )
109
+ else:
110
+ full_text_row_masked_out_mask = None
111
+
112
+ if cross_attention_mask is not None:
113
+ cache_position = mx.arange(input_ids.shape[1], dtype=mx.int32)
114
+ cross_attention_mask = cross_attention_mask[:, :, cache_position]
115
+ full_text_row_masked_out_mask = full_text_row_masked_out_mask[
116
+ :, :, cache_position
117
+ ]
118
+
119
+ # Process language input
120
+ outputs = self.language_model(
121
+ input_ids=input_ids,
122
+ mask=mask,
123
+ cross_attention_states=cross_attention_states,
124
+ cross_attention_mask=cross_attention_mask,
125
+ full_text_row_masked_out_mask=full_text_row_masked_out_mask,
126
+ inputs_embeds=inputs_embeds,
127
+ cache=cache,
128
+ )
129
+
130
+ return outputs
131
+
132
+ def _prepare_cross_attention_mask(
133
+ self,
134
+ cross_attention_mask: mx.array,
135
+ num_vision_tokens: int,
136
+ ) -> Tuple[mx.array, mx.array]:
137
+ batch_size, text_total_length, *_ = cross_attention_mask.shape
138
+ cross_attention_mask = mx.repeat(
139
+ cross_attention_mask, num_vision_tokens, axis=3
140
+ )
141
+ cross_attention_mask = cross_attention_mask.reshape(
142
+ batch_size, text_total_length, -1
143
+ )
144
+ cross_attention_mask = mx.expand_dims(cross_attention_mask, 1)
145
+
146
+ # Invert the mask
147
+ inverted_cross_attn_mask = 1.0 - cross_attention_mask
148
+ fill_array = mx.array(-1e9)
149
+ fill_array = mx.broadcast_to(fill_array, inverted_cross_attn_mask.shape)
150
+ cross_attention_mask = mx.where(
151
+ inverted_cross_attn_mask,
152
+ fill_array,
153
+ cross_attention_mask,
154
+ )
155
+
156
+ # Apply full-row bias
157
+ full_text_row_masked_out_mask = mx.any(
158
+ cross_attention_mask != -1e9,
159
+ axis=-1,
160
+ keepdims=True,
161
+ )
162
+ cross_attention_mask *= full_text_row_masked_out_mask
163
+
164
+ return cross_attention_mask, full_text_row_masked_out_mask
165
+
166
+ def sanitize(self, weights):
167
+ def transform_key(key):
168
+ if "vision_tower" not in key:
169
+ key = key.replace("vision_model", "vision_tower")
170
+ return key
171
+
172
+ return {transform_key(k): v for k, v in weights.items()}