nexaai 1.0.19rc6__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 (224) 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/utils/manifest_utils.py +222 -15
  219. nexaai/utils/model_manager.py +83 -7
  220. nexaai/utils/model_types.py +2 -0
  221. {nexaai-1.0.19rc6.dist-info → nexaai-1.0.19rc7.dist-info}/METADATA +1 -1
  222. {nexaai-1.0.19rc6.dist-info → nexaai-1.0.19rc7.dist-info}/RECORD +224 -24
  223. {nexaai-1.0.19rc6.dist-info → nexaai-1.0.19rc7.dist-info}/WHEEL +0 -0
  224. {nexaai-1.0.19rc6.dist-info → nexaai-1.0.19rc7.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,526 @@
1
+ import copy
2
+ import inspect
3
+ from dataclasses import dataclass
4
+ from functools import partial
5
+ from math import sqrt
6
+ from typing import Dict, Optional, Union
7
+
8
+ import cv2
9
+ import mlx.core as mx
10
+ import mlx.nn as nn
11
+ import numpy as np
12
+
13
+ from .sam import SAMEncoder
14
+
15
+
16
+ @dataclass
17
+ class VisionConfig:
18
+ model_type: str
19
+ num_hidden_layers: int = 24
20
+ hidden_size: int = 1024
21
+ intermediate_size: int = 4096
22
+ num_attention_heads: int = 16
23
+ image_size: int = 384
24
+ patch_size: int = 16
25
+ num_channels: int = 3
26
+ layer_norm_eps: float = 1e-5
27
+ cls: str = None
28
+ params: dict = None
29
+
30
+ def __post_init__(self):
31
+ if "high_res_cfg" in self.params:
32
+ self.image_size = self.params["high_res_cfg"]["image_size"]
33
+
34
+ @classmethod
35
+ def from_dict(cls, params):
36
+ return cls(
37
+ **{
38
+ k: v
39
+ for k, v in params.items()
40
+ if k in inspect.signature(cls).parameters
41
+ }
42
+ )
43
+
44
+
45
+ @dataclass
46
+ class MLPConfig:
47
+ hidden_size: int
48
+ intermediate_size: int
49
+
50
+
51
+ def check_array_shape(arr):
52
+ shape = arr.shape
53
+
54
+ # Check if the shape has 4 dimensions
55
+ if len(shape) != 4:
56
+ return False
57
+
58
+ out_channels, kH, KW, _ = shape
59
+
60
+ # Check if out_channels is the largest, and kH and KW are the same
61
+ if (out_channels >= kH) and (out_channels >= KW) and (kH == KW):
62
+ return True
63
+ else:
64
+ return False
65
+
66
+
67
+ class AttentionPoolLatent(nn.Module):
68
+ """Attention pooling w/ latent query"""
69
+
70
+ def __init__(
71
+ self,
72
+ in_features: int,
73
+ out_features: int = None,
74
+ embed_dim: int = None,
75
+ num_heads: int = 8,
76
+ mlp_ratio: float = 4.0,
77
+ qkv_bias: bool = True,
78
+ qk_norm: bool = False,
79
+ latent_len: int = 1,
80
+ latent_dim: int = None,
81
+ pos_embed: str = "",
82
+ pool_type: str = "token",
83
+ norm_layer: Optional[nn.Module] = None,
84
+ drop: float = 0.0,
85
+ ):
86
+ super().__init__()
87
+
88
+ embed_dim = embed_dim or in_features
89
+ out_features = out_features or in_features
90
+ assert embed_dim % num_heads == 0
91
+ self.num_heads = num_heads
92
+ self.head_dim = embed_dim // num_heads
93
+ self.scale = self.head_dim**-0.5
94
+ self.pool = pool_type
95
+
96
+ self.latent_dim = latent_dim or embed_dim
97
+ self.latent_len = latent_len
98
+ self.latent = mx.zeros((self.latent_len, embed_dim))[None, :]
99
+
100
+ self.q = nn.Linear(embed_dim, embed_dim, bias=qkv_bias)
101
+ self.kv = nn.Linear(embed_dim, embed_dim * 2, bias=qkv_bias)
102
+ self.q_norm = norm_layer(self.head_dim) if qk_norm else nn.Identity()
103
+ self.k_norm = norm_layer(self.head_dim) if qk_norm else nn.Identity()
104
+ self.proj = nn.Linear(embed_dim, embed_dim)
105
+ self.proj_drop = nn.Dropout(drop)
106
+
107
+ if pos_embed == "abs":
108
+ spatial_len = self.feat_size
109
+ self.pos_embed = mx.zeros((spatial_len, in_features))
110
+ else:
111
+ self.pos_embed = None
112
+
113
+ self.norm = nn.LayerNorm(out_features)
114
+ config = MLPConfig(
115
+ hidden_size=embed_dim, intermediate_size=int(embed_dim * mlp_ratio)
116
+ )
117
+ self.mlp = MLP(config)
118
+
119
+ def __call__(self, x: mx.array):
120
+ B, N, C = x.shape
121
+
122
+ if self.pos_embed is not None:
123
+ x = x + self.pos_embed.unsqueeze(0).to(x.dtype)
124
+
125
+ q_latent = mx.array(self.latent)
126
+
127
+ q = (
128
+ self.q(q_latent)
129
+ .reshape(B, self.latent_len, self.num_heads, self.head_dim)
130
+ .transpose(0, 2, 1, 3)
131
+ )
132
+
133
+ kv = (
134
+ self.kv(x)
135
+ .reshape(B, N, 2, self.num_heads, self.head_dim)
136
+ .transpose(2, 0, 3, 1, 4)
137
+ )
138
+ k, v = mx.split(kv, 2, axis=0)
139
+
140
+ q, k = self.q_norm(q), self.k_norm(k)
141
+
142
+ x = mx.fast.scaled_dot_product_attention(
143
+ q, k[0], v[0], scale=(1.0 / sqrt(q.shape[-1])), mask=None
144
+ )
145
+
146
+ x = x.transpose(0, 2, 1, 3).reshape(B, self.latent_len, C)
147
+ x = self.proj(x)
148
+ x = self.proj_drop(x)
149
+
150
+ x = x + self.mlp(self.norm(x))
151
+
152
+ # optional pool if latent seq_len > 1 and pooled output is desired
153
+ if self.pool == "token":
154
+ x = x[:, 0]
155
+ elif self.pool == "avg":
156
+ x = x.mean(1)
157
+ return x
158
+
159
+
160
+ class Attention(nn.Module):
161
+ def __init__(
162
+ self,
163
+ dims: int,
164
+ num_heads: int,
165
+ qkv_bias: bool = False,
166
+ ):
167
+ super().__init__()
168
+
169
+ if (dims % num_heads) != 0:
170
+ raise ValueError(
171
+ "The input feature dimensions should be divisible by the "
172
+ f"number of heads ({dims} % {num_heads}) != 0"
173
+ )
174
+
175
+ self.num_heads = num_heads = num_heads
176
+ head_dim = dims // num_heads
177
+ self.scale = head_dim**-0.5
178
+
179
+ self.qkv = nn.Linear(dims, dims * 3, bias=qkv_bias)
180
+ self.proj = nn.Linear(dims, dims, bias=True)
181
+
182
+ def __call__(self, x, mask=None):
183
+ qkv = self.qkv(x)
184
+ queries, keys, values = mx.split(qkv, 3, axis=-1)
185
+
186
+ num_heads = self.num_heads
187
+ B, L, D = queries.shape
188
+ _, S, _ = keys.shape
189
+ queries = queries.reshape(B, L, num_heads, -1).transpose(0, 2, 1, 3)
190
+ keys = keys.reshape(B, S, num_heads, -1).transpose(0, 2, 1, 3)
191
+ values = values.reshape(B, S, num_heads, -1).transpose(0, 2, 1, 3)
192
+
193
+ output = mx.fast.scaled_dot_product_attention(
194
+ queries, keys, values, scale=self.scale, mask=mask
195
+ )
196
+ output = output.transpose(0, 2, 1, 3).reshape(B, L, -1)
197
+
198
+ return self.proj(output)
199
+
200
+
201
+ class FastGELUActivation(nn.Module):
202
+ """
203
+ Applies GELU approximation that is slower than QuickGELU but more accurate. See: https://github.com/hendrycks/GELUs
204
+ """
205
+
206
+ def __call__(self, input: mx.array) -> mx.array:
207
+ return (
208
+ 0.5
209
+ * input
210
+ * (1.0 + mx.tanh(np.sqrt(2 / np.pi) * (input + 0.044715 * (input**3))))
211
+ ).astype(input.dtype)
212
+
213
+
214
+ class MLP(nn.Module):
215
+ def __init__(self, config: Union[VisionConfig, Dict], bias: bool = True):
216
+ super().__init__()
217
+ self.activation_fn = FastGELUActivation()
218
+ self.fc1 = nn.Linear(config.hidden_size, config.intermediate_size, bias=bias)
219
+ self.fc2 = nn.Linear(config.intermediate_size, config.hidden_size, bias=bias)
220
+
221
+ def __call__(self, x: mx.array) -> mx.array:
222
+ x = self.activation_fn(self.fc1(x))
223
+ x = self.fc2(x)
224
+ return x
225
+
226
+
227
+ class EncoderLayer(nn.Module):
228
+ def __init__(self, config: VisionConfig):
229
+ super().__init__()
230
+ self.embed_dim = config.hidden_size
231
+ self.attn = Attention(
232
+ config.hidden_size, config.num_attention_heads, qkv_bias=True
233
+ )
234
+ self.norm1 = nn.LayerNorm(self.embed_dim, eps=config.layer_norm_eps)
235
+ self.mlp = MLP(config)
236
+ self.norm2 = nn.LayerNorm(self.embed_dim, eps=config.layer_norm_eps)
237
+
238
+ def __call__(self, x: mx.array, mask: Optional[mx.array] = None) -> mx.array:
239
+ y = self.norm1(x)
240
+ y = self.attn(y, mask)
241
+ x = x + y
242
+ y = self.norm2(x)
243
+ y = self.mlp(y)
244
+ return x + y
245
+
246
+
247
+ class VisionEmbeddings(nn.Module):
248
+ def __init__(self, config: VisionConfig, norm_layer: bool = False):
249
+ super().__init__()
250
+ self.config = config
251
+ self.embed_dim = config.hidden_size
252
+ self.image_size = config.image_size
253
+ self.patch_size = config.patch_size
254
+
255
+ self.proj = nn.Conv2d(
256
+ in_channels=config.num_channels,
257
+ out_channels=self.embed_dim,
258
+ kernel_size=self.patch_size,
259
+ stride=self.patch_size,
260
+ )
261
+
262
+ self.num_patches = (self.image_size // self.patch_size) ** 2
263
+ self.num_positions = self.num_patches
264
+
265
+ self.norm = (
266
+ nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
267
+ if norm_layer
268
+ else nn.Identity()
269
+ )
270
+
271
+ def __call__(self, x: mx.array) -> mx.array:
272
+ patch_embeddings = self.proj(x)
273
+ patch_embeddings = mx.flatten(patch_embeddings, start_axis=1, end_axis=2)
274
+ return self.norm(patch_embeddings)
275
+
276
+
277
+ class SigLipVisionModel(nn.Module):
278
+ def __init__(
279
+ self,
280
+ config: VisionConfig,
281
+ ignore_head: bool,
282
+ pre_norm: bool = False,
283
+ no_embed_class: bool = True,
284
+ ):
285
+ super().__init__()
286
+ self.num_prefix_tokens = 1
287
+ self.no_embed_class = False
288
+ self.dynamic_img_size = False
289
+ self.ignore_head = ignore_head
290
+ self.cls_token = None
291
+ self.reg_token = None
292
+ self.patch_embed = VisionEmbeddings(config)
293
+ self.norm_pre = nn.LayerNorm(config.hidden_size) if pre_norm else nn.Identity()
294
+ self.blocks = [EncoderLayer(config) for _ in range(config.num_hidden_layers)]
295
+ self.norm = nn.LayerNorm(config.hidden_size)
296
+ num_patches = self.patch_embed.num_patches
297
+ embed_len = (
298
+ num_patches if no_embed_class else num_patches + self.num_prefix_tokens
299
+ )
300
+ self.pos_embed = mx.random.normal((embed_len, config.hidden_size))[None, :]
301
+
302
+ norm_layer = partial(nn.LayerNorm, eps=1e-5)
303
+ self.attn_pool = AttentionPoolLatent(
304
+ config.hidden_size,
305
+ num_heads=config.num_attention_heads,
306
+ norm_layer=norm_layer,
307
+ )
308
+
309
+ def __call__(
310
+ self,
311
+ x: mx.array,
312
+ output_hidden_states: Optional[bool] = None,
313
+ ) -> mx.array:
314
+ x = self.patch_embed(x)
315
+ x += self.pos_embed
316
+ x = self.norm_pre(x)
317
+
318
+ encoder_states = (x,) if output_hidden_states else None
319
+ for l in self.blocks:
320
+ x = l(x, mask=None)
321
+ if output_hidden_states:
322
+ encoder_states = encoder_states + (x,)
323
+
324
+ pooler_output = self.norm(x)
325
+
326
+ if not self.ignore_head:
327
+ pooler_output = self.attn_pool(pooler_output)
328
+ return pooler_output, x, encoder_states
329
+
330
+
331
+ class HybridVisionModel(nn.Module):
332
+ def __init__(self, config: VisionConfig, resolution: str, ignore_head: bool = True):
333
+ super().__init__()
334
+
335
+ self.model_type = config.model_type
336
+ self.resolution = resolution
337
+ if self.model_type != "vision":
338
+ raise ValueError(f"Unsupported model type: {self.model_type}")
339
+
340
+ if resolution == "high":
341
+ self.vision_tower = SAMEncoder()
342
+ else:
343
+ self.vision_tower = SigLipVisionModel(config, ignore_head)
344
+
345
+ def __call__(self, x: mx.array) -> mx.array:
346
+ if self.resolution == "high":
347
+ return self.vision_tower(x)
348
+ else:
349
+ return self.vision_tower(x)[0]
350
+
351
+
352
+ # def resize_image(image, size, antialias=True):
353
+ # """
354
+ # Resize an image using scipy.ndimage.zoom with an option for bicubic interpolation.
355
+
356
+ # Args:
357
+ # image (numpy.ndarray): The input image array.
358
+ # size (tuple): The target size as (width, height).
359
+ # antialias (bool): True to use bicubic interpolation, False to use nearest neighbor.
360
+
361
+ # Returns:
362
+ # numpy.ndarray: The resized image array.
363
+ # """
364
+ # # Ensure the image is an array and remove singleton dimensions
365
+ # image = np.array(image[0])
366
+
367
+ # # Calculate zoom factors for the spatial dimensions
368
+ # # Note: size is expected as (width, height) but image.shape gives (height, width)
369
+ # current_height, current_width = image.shape[:2]
370
+ # width_factor = size[0] / current_width
371
+ # height_factor = size[1] / current_height
372
+ # zoom_factors = (height_factor, width_factor) # Apply zoom to height and width
373
+
374
+ # # Choose the interpolation order: 3 for bicubic, 0 for nearest
375
+ # order = 3 if antialias else 0
376
+
377
+ # # Apply zoom to the image. Handle both grayscale and color images.
378
+ # if image.ndim == 2: # Grayscale image
379
+ # resized_image = zoom(image, zoom_factors, order=order)
380
+ # elif image.ndim == 3: # Color image
381
+ # # Apply zoom separately for each channel
382
+ # resized_channels = [
383
+ # zoom(image[:, :, i], zoom_factors, order=order)
384
+ # for i in range(image.shape[2])
385
+ # ]
386
+ # resized_image = np.stack(resized_channels, axis=2)
387
+
388
+ # return resized_image
389
+
390
+
391
+ # TODO: Match the output of scipy.ndimage.zoom
392
+ def resize_image(image, size, antialias=True):
393
+ """
394
+ Resize an image with OpenCV.
395
+
396
+ Args:
397
+ image (numpy.ndarray): The input image array. Supports H × W or H × W × C.
398
+ If you pass in a batch (N × H × W × C) just slice the
399
+ element you want, e.g. image[0].
400
+ size (tuple): Target size as (width, height) — exactly the same order that
401
+ cv2.resize expects.
402
+ antialias (bool):
403
+ * True → high‑quality interpolation (bicubic for upscaling, area for downscaling)
404
+ * False → nearest‑neighbor (fast, blocky)
405
+
406
+ Returns:
407
+ numpy.ndarray: The resized image array.
408
+ """
409
+ img = np.ascontiguousarray(np.asarray(image))
410
+ if img.ndim == 4 and img.shape[0] == 1: # squeeze stray batch dim
411
+ img = img[0]
412
+ h0, w0 = img.shape[:2]
413
+
414
+ # --- work out dsize vs fx/fy ---------------------------------------------
415
+ dsize = None
416
+ fx = fy = 0.0
417
+ if isinstance(size, (int, float)): # uniform scale
418
+ fx = fy = float(size)
419
+ elif isinstance(size, (tuple, list)) and len(size) == 2:
420
+ a, b = size
421
+ # Heuristic: treat "small" floats as scale factors
422
+ if all(isinstance(x, (int, float)) and x < 10 for x in (a, b)):
423
+ fx, fy = float(a), float(b) # scale factors
424
+ else:
425
+ dsize = (int(a), int(b)) # absolute pixels
426
+ else:
427
+ raise ValueError("target must be scalar or a 2‑tuple")
428
+
429
+ # Guard against zeros after int‑casting
430
+ if dsize:
431
+ if dsize[0] <= 0 or dsize[1] <= 0:
432
+ raise ValueError(f"dsize became {dsize}")
433
+ else:
434
+ if fx <= 0 or fy <= 0:
435
+ raise ValueError(f"fx,fy became {(fx, fy)}")
436
+
437
+ # --- choose interpolation -------------------------------------------------
438
+ if antialias:
439
+ # Use Lanczos interpolation for potentially better detail preservation
440
+ interp = cv2.INTER_LANCZOS4
441
+ else:
442
+ interp = cv2.INTER_NEAREST
443
+
444
+ # --- call OpenCV ----------------------------------------------------------
445
+ return mx.array(cv2.resize(img, dsize=dsize, fx=fx, fy=fy, interpolation=interp))
446
+
447
+
448
+ class VisionModel(nn.Module):
449
+ def __init__(self, config: VisionConfig, ignore_head: bool = True):
450
+ super().__init__()
451
+
452
+ self.model_type = config.model_type
453
+ self.config = config
454
+ if self.model_type != "vision":
455
+ raise ValueError(f"Unsupported model type: {self.model_type}")
456
+
457
+ if config.cls == "HybridVisionTower":
458
+ self.high_layer_norm = nn.LayerNorm(
459
+ config.params["high_res_cfg"]["output_dim"]
460
+ )
461
+ self.low_layer_norm = nn.LayerNorm(
462
+ config.params["low_res_cfg"]["output_dim"]
463
+ )
464
+
465
+ high_res_cfg = copy.deepcopy(config)
466
+ high_res_cfg.image_size = config.params["high_res_cfg"]["image_size"]
467
+ self.vision_tower_high = HybridVisionModel(
468
+ high_res_cfg, "high", ignore_head
469
+ )
470
+
471
+ low_res_cfg = copy.deepcopy(config)
472
+ low_res_cfg.image_size = config.params["low_res_cfg"]["image_size"]
473
+
474
+ self.vision_tower_low = HybridVisionModel(low_res_cfg, "low", ignore_head)
475
+ self.low_res_size = config.params["low_res_cfg"]["image_size"]
476
+ self.resize = lambda image: resize_image(
477
+ image, (self.low_res_size, self.low_res_size), antialias=True
478
+ )
479
+
480
+ else:
481
+ self.vision_tower = SigLipVisionModel(config, ignore_head)
482
+
483
+ def __call__(
484
+ self, x: mx.array, output_hidden_states: Optional[bool] = None
485
+ ) -> mx.array:
486
+ if self.config.cls == "HybridVisionTower":
487
+ high_images = x
488
+ low_images = mx.array(self.resize(np.array(x)))[None, :]
489
+
490
+ high_res = self.vision_tower_high(high_images)
491
+ low_res = self.vision_tower_low(low_images)
492
+
493
+ return (high_res, low_res)
494
+ else:
495
+ return self.vision_tower(x, output_hidden_states)
496
+
497
+ def sanitize(self, weights):
498
+ sanitized_weights = {}
499
+ weight_keys = {
500
+ "neck.0.weight",
501
+ "neck.2.weight",
502
+ "neck_hd.0.weight",
503
+ "neck_hd.2.weight",
504
+ "downsamples.0.weight",
505
+ "downsamples.1.weight",
506
+ "patch_embed.proj.weight",
507
+ }
508
+ for k, v in weights.items():
509
+ if "position_ids" in k:
510
+ # Remove unused position_ids
511
+ continue
512
+
513
+ elif ".".join(k.split(".")[-3:]) in weight_keys:
514
+ # PyTorch conv2d weight tensors have shape:
515
+ # [out_channels, in_channels, kH, KW]
516
+ # MLX conv2d expects the weight be of shape:
517
+ # [out_channels, kH, KW, in_channels]
518
+ if check_array_shape(v):
519
+ sanitized_weights[k] = v
520
+ else:
521
+ sanitized_weights[k] = v.transpose(0, 2, 3, 1)
522
+
523
+ else:
524
+ sanitized_weights[k] = v
525
+
526
+ return sanitized_weights
@@ -0,0 +1,8 @@
1
+ from .paligemma import (
2
+ LanguageModel,
3
+ Model,
4
+ ModelConfig,
5
+ TextConfig,
6
+ VisionConfig,
7
+ VisionModel,
8
+ )