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,472 @@
1
+ import glob
2
+ import inspect
3
+ import json
4
+ import math
5
+ from dataclasses import dataclass
6
+ from pathlib import Path
7
+ from typing import List, Optional, Tuple, Union
8
+
9
+ import mlx.core as mx
10
+ import mlx.nn as nn
11
+ import numpy as np
12
+ from huggingface_hub import snapshot_download
13
+ from PIL import Image
14
+ from transformers import AutoProcessor
15
+ from transformers.image_processing_utils import BaseImageProcessor, BatchFeature
16
+ from transformers.image_utils import to_numpy_array
17
+
18
+ from ..base import expand2square
19
+ from .language import LanguageModel, TextConfig
20
+ from .processing_deepsek_vl_v2 import DeepseekVLV2Processor
21
+ from .vision import VisionConfig, VisionModel
22
+
23
+ AutoProcessor.register("deepseek_vl_v2", DeepseekVLV2Processor)
24
+
25
+
26
+ @dataclass
27
+ class ProjectorConfig:
28
+ projector_type: str = "downsample_mlp_gelu"
29
+ input_dim: int = 1152
30
+ n_embed: int = 2048
31
+ depth: int = 2
32
+ mlp_ratio: int = 1
33
+ downsample_ratio: int = 2
34
+ token_pooling: bool = False
35
+
36
+ @classmethod
37
+ def from_dict(cls, params):
38
+ return cls(
39
+ **{
40
+ k: v
41
+ for k, v in params.items()
42
+ if k in inspect.signature(cls).parameters
43
+ }
44
+ )
45
+
46
+
47
+ @dataclass
48
+ class ModelConfig:
49
+ text_config: TextConfig
50
+ vision_config: VisionConfig
51
+ projector_config: ProjectorConfig
52
+ model_type: str
53
+ ignore_index: int = -100
54
+ image_token_index: int = 100015
55
+ vision_feature_select_strategy: str = "default"
56
+ select_layer: int = -1
57
+ pad_id: int = 100001
58
+ num_image_tokens: int = 576
59
+ vocab_size: int = 32000
60
+ tile_tag: str = "2D"
61
+ global_view_pos: str = "head"
62
+ eos_token_id: Optional[List[int]] = None
63
+
64
+ @classmethod
65
+ def from_dict(cls, params):
66
+ if "language_config" in params:
67
+ params["text_config"] = params["language_config"]
68
+ del params["language_config"]
69
+
70
+ return cls(
71
+ **{
72
+ k: v
73
+ for k, v in params.items()
74
+ if k in inspect.signature(cls).parameters
75
+ }
76
+ )
77
+
78
+
79
+ class MlpProjector(nn.Module):
80
+ def __init__(self, config: ProjectorConfig):
81
+ super().__init__()
82
+ self.config = config
83
+ if config.projector_config.projector_type == "identity":
84
+ modules = nn.Identity()
85
+ elif config.projector_config.projector_type == "linear":
86
+ modules = nn.Linear(
87
+ config.projector_config.input_dim, config.projector_config.n_embed
88
+ )
89
+ elif config.projector_config.projector_type == "mlp_gelu":
90
+ mlp_depth = config.projector_config.depth
91
+ modules = [
92
+ nn.Linear(
93
+ config.projector_config.input_dim, config.projector_config.n_embed
94
+ )
95
+ ]
96
+ for _ in range(1, mlp_depth):
97
+ modules.append(nn.GELU())
98
+ modules.append(
99
+ nn.Linear(
100
+ config.projector_config.n_embed, config.projector_config.n_embed
101
+ )
102
+ )
103
+ elif config.projector_config.projector_type == "downsample_mlp_gelu":
104
+ mlp_depth = config.projector_config.depth
105
+ mlp_ratio = config.projector_config.mlp_ratio
106
+ modules = [
107
+ nn.Linear(
108
+ config.projector_config.input_dim
109
+ * config.projector_config.downsample_ratio
110
+ * config.projector_config.downsample_ratio,
111
+ config.projector_config.n_embed * mlp_ratio,
112
+ )
113
+ ]
114
+ for _ in range(1, mlp_depth - 1):
115
+ modules.append(nn.GELU())
116
+ modules.append(
117
+ nn.Linear(
118
+ config.projector_config.n_embed * mlp_ratio,
119
+ config.projector_config.n_embed * mlp_ratio,
120
+ )
121
+ )
122
+ modules.append(nn.GELU())
123
+ modules.append(
124
+ nn.Linear(
125
+ config.projector_config.n_embed * mlp_ratio,
126
+ config.projector_config.n_embed,
127
+ )
128
+ )
129
+ else:
130
+ raise ValueError(
131
+ f"Unknown projector type: {config.projector_config.projector_type}"
132
+ )
133
+
134
+ if config.projector_config.token_pooling:
135
+ self.token_pooling_layer = nn.Linear(
136
+ config.projector_config.input_dim * 4, config.projector_config.input_dim
137
+ )
138
+ self.layers = modules
139
+
140
+ def __call__(self, x):
141
+ if self.config.projector_config.token_pooling:
142
+ batch_size, wxh, channels = x.shape
143
+ w = h = int(math.sqrt(wxh))
144
+ x = mx.reshape(x, (batch_size, w, h, channels))
145
+ x = mx.transpose(x, (0, 3, 1, 2)) # B, C, H, W
146
+
147
+ # Implement unfold operation manually since MLX doesn't have unfold
148
+ patches = []
149
+ for i in range(0, h - 1, 2):
150
+ for j in range(0, w - 1, 2):
151
+ patch = x[:, :, i : i + 2, j : j + 2]
152
+ patches.append(patch)
153
+
154
+ patches = mx.stack(patches, axis=2) # B, C, N_patches, 2, 2
155
+ batch_size, channels, n_patches, _, _ = patches.shape
156
+
157
+ # Reshape and concatenate
158
+ patches = mx.reshape(patches, (batch_size, channels, n_patches, -1))
159
+ patches = mx.transpose(patches, (0, 2, 1, 3))
160
+ patches = mx.reshape(patches, (batch_size, n_patches, channels * 4))
161
+ x = self.token_pooling_layer(patches)
162
+
163
+ elif self.config.projector_config.projector_type == "downsample_mlp_gelu":
164
+ bs, hw, input_dim = x.shape
165
+ h = w = int(math.sqrt(hw))
166
+
167
+ # Compute padding
168
+ pad = (
169
+ 0
170
+ if h % self.config.projector_config.downsample_ratio == 0
171
+ else self.config.projector_config.downsample_ratio
172
+ - h % self.config.projector_config.downsample_ratio
173
+ )
174
+
175
+ x = mx.reshape(x, (bs, h, w, input_dim))
176
+ if pad > 0:
177
+ x = mx.pad(x, [(0, 0), (0, pad), (0, pad), (0, 0)], constant_values=0)
178
+
179
+ x = mx.transpose(x, (0, 3, 1, 2)) # B, C, H, W
180
+
181
+ # Manual implementation of unfold for downsampling
182
+ h_pad, w_pad = x.shape[2], x.shape[3]
183
+ ds = self.config.projector_config.downsample_ratio
184
+ patches = []
185
+
186
+ for i in range(0, h_pad - ds + 1, ds):
187
+ for j in range(0, w_pad - ds + 1, ds):
188
+ patch = x[:, :, i : i + ds, j : j + ds]
189
+ patches.append(mx.reshape(patch, (bs, -1)))
190
+
191
+ x = mx.stack(patches, axis=1) # B, N_patches, C*ds*ds
192
+
193
+ for layer in self.layers:
194
+ x = layer(x)
195
+ return x
196
+
197
+
198
+ class Model(nn.Module):
199
+ def __init__(self, config: ModelConfig):
200
+ super().__init__()
201
+ self.config = config
202
+ self.vision = VisionModel(config.vision_config)
203
+ self.language_model = LanguageModel(config.text_config)
204
+ self.projector = MlpProjector(config)
205
+ self.vision_feature_layer = config.select_layer
206
+ self.vision_feature_select_strategy = config.vision_feature_select_strategy
207
+
208
+ self.tile_tag = config.tile_tag
209
+ self.global_view_pos = config.global_view_pos
210
+
211
+ # 用于format image token sequence的特殊token
212
+ embed_std = 1 / mx.sqrt(
213
+ mx.array(config.projector_config.n_embed, dtype=mx.float32)
214
+ )
215
+ if self.tile_tag == "2D":
216
+ # <|view_separator|>, <|\n|>
217
+ self.image_newline = mx.array(
218
+ mx.random.normal((config.projector_config.n_embed,)) * embed_std
219
+ )
220
+ # fix the typo: view_seperater
221
+ self.view_separator = mx.array(
222
+ mx.random.normal((config.projector_config.n_embed,)) * embed_std
223
+ )
224
+ elif self.tile_tag == "1D":
225
+ # <|tile_x|>, <|tile_global|>
226
+ candidate_resolutions = config.candidate_resolutions
227
+ if len(candidate_resolutions) == 0:
228
+ raise ValueError(
229
+ f"len(candidate_resolutions) should be larger than 0, but got {len(candidate_resolutions)}"
230
+ )
231
+ tile_variants_num = len(candidate_resolutions)
232
+ self.tile_indicators = mx.array(
233
+ mx.random.normal(
234
+ (tile_variants_num + 1, config.projector_config.n_embed)
235
+ )
236
+ * embed_std
237
+ )
238
+ else:
239
+ raise ValueError(
240
+ f"tile tag should be either 1D or 2D, but got {self.tile_tag}"
241
+ )
242
+
243
+ def process_image_features(
244
+ self,
245
+ input_embeds,
246
+ images_embeds,
247
+ images_spatial_crop,
248
+ images_seq_mask,
249
+ h,
250
+ w,
251
+ n_dim,
252
+ ):
253
+ tile_index = 0
254
+ all_batch_features = []
255
+
256
+ for idx in range(images_spatial_crop.shape[0]):
257
+ images_in_this_batch = []
258
+ for jdx in range(images_spatial_crop.shape[1]):
259
+ # Extract global & local features
260
+ num_width_tiles, num_height_tiles = images_spatial_crop[idx, jdx]
261
+ if num_width_tiles == 0 or num_height_tiles == 0:
262
+ break
263
+
264
+ num_tiles_in_image = (num_width_tiles * num_height_tiles).tolist()
265
+
266
+ # Get global features [hw, D]
267
+ global_features = images_embeds[tile_index]
268
+
269
+ # Get local features [num_height_tiles * num_width_tiles, hw, D]
270
+ local_features = images_embeds[
271
+ tile_index + 1 : tile_index + 1 + num_tiles_in_image
272
+ ]
273
+
274
+ tile_index += num_tiles_in_image + 1
275
+
276
+ # Format global and local features
277
+ if self.tile_tag == "2D":
278
+ # ----------------- global view add newline -----------------
279
+ # [hw, D] -> [h, w, D]
280
+ global_features = mx.reshape(global_features, (h, w, n_dim))
281
+
282
+ # [D] -> [h, 1, D]
283
+ new_lines_in_global = mx.expand_dims(self.image_newline, axis=0)
284
+ new_lines_in_global = mx.repeat(
285
+ new_lines_in_global, repeats=h, axis=0
286
+ )
287
+ new_lines_in_global = mx.expand_dims(new_lines_in_global, axis=1)
288
+
289
+ # cat([h, w, D], [h, 1, D], dim=1) -> [h, w + 1, D]
290
+ global_features = mx.concatenate(
291
+ [global_features, new_lines_in_global], axis=1
292
+ )
293
+
294
+ # [h, w + 1, D] -> [h * (w + 1), D]
295
+ global_features = mx.reshape(global_features, (-1, n_dim))
296
+
297
+ # ----------------- local view add newline -----------------
298
+ # Rearrange local features
299
+ # [num_height_tiles * num_width_tiles, h * w, D] -> [num_height_tiles * h, num_width_tiles * w, D]
300
+ local_features = mx.reshape(
301
+ local_features, (num_height_tiles, num_width_tiles, h, w, n_dim)
302
+ )
303
+ local_features = mx.transpose(local_features, (0, 2, 1, 3, 4))
304
+ local_features = mx.reshape(
305
+ local_features,
306
+ (num_height_tiles * h, num_width_tiles * w, n_dim),
307
+ )
308
+
309
+ # Create newlines for local features
310
+ # [D] -> [num_height_tiles * h, 1, D]
311
+ new_lines_in_local = mx.repeat(
312
+ mx.expand_dims(self.image_newline, axis=0),
313
+ repeats=num_height_tiles * h,
314
+ axis=0,
315
+ )
316
+ new_lines_in_local = mx.expand_dims(new_lines_in_local, axis=1)
317
+
318
+ # [num_height_tiles * h, num_width_tiles * w + 1, D]
319
+ local_features = mx.concatenate(
320
+ [local_features, new_lines_in_local], axis=1
321
+ )
322
+
323
+ # [(num_height_tiles * h) * (num_width_tiles * w + 1), D]
324
+ local_features = mx.reshape(local_features, (-1, n_dim))
325
+
326
+ # ----------------- merge global and local tiles -----------------
327
+ view_separator = mx.expand_dims(self.view_separator, axis=0)
328
+
329
+ if self.global_view_pos == "head":
330
+ global_local_features = mx.concatenate(
331
+ [global_features, view_separator, local_features], axis=0
332
+ )
333
+ else:
334
+ global_local_features = mx.concatenate(
335
+ [local_features, view_separator, global_features], axis=0
336
+ )
337
+
338
+ else:
339
+ # 1D processing (legacy path)
340
+ global_features = mx.concatenate(
341
+ [
342
+ mx.expand_dims(self.tile_indicators[0], axis=0),
343
+ global_features,
344
+ ],
345
+ axis=0,
346
+ )
347
+
348
+ local_indicators = mx.expand_dims(
349
+ self.tile_indicators[1 : num_tiles_in_image + 1], axis=1
350
+ )
351
+ local_features = mx.concatenate(
352
+ [local_indicators, local_features], axis=1
353
+ )
354
+ local_features = mx.reshape(local_features, (-1, n_dim))
355
+
356
+ if self.global_view_pos == "head":
357
+ global_local_features = mx.concatenate(
358
+ [global_features, local_features], axis=0
359
+ )
360
+ else:
361
+ global_local_features = mx.concatenate(
362
+ [local_features, global_features], axis=0
363
+ )
364
+
365
+ images_in_this_batch.append(global_local_features)
366
+
367
+ if images_in_this_batch:
368
+ images_in_this_batch = mx.concatenate(images_in_this_batch, axis=0)
369
+ # Find positions where images should be placed
370
+ image_indices = np.where(images_seq_mask[idx])[0].tolist()
371
+ # Directly assign the image features to those positions
372
+ input_embeds[idx, image_indices] = images_in_this_batch
373
+
374
+ return input_embeds
375
+
376
+ def get_input_embeddings(
377
+ self,
378
+ input_ids: Optional[mx.array] = None,
379
+ pixel_values: Optional[mx.array] = None,
380
+ images_spatial_crop: Optional[mx.array] = None,
381
+ image_seq_mask: Optional[mx.array] = None,
382
+ ):
383
+ if pixel_values is None:
384
+ return self.language_model.model.embed_tokens(input_ids)
385
+
386
+ bs = pixel_values.shape[0]
387
+ max_n_images = pixel_values.shape[1]
388
+
389
+ batch_num_tiles = [0 for _ in range(bs)]
390
+ total_tiles = []
391
+
392
+ # Total number of tiles in each batch
393
+ for idx in range(bs):
394
+ for jdx in range(max_n_images):
395
+ num_width_tiles, num_height_tiles = images_spatial_crop[idx][jdx]
396
+ if num_width_tiles == 0 or num_height_tiles == 0:
397
+ break
398
+ batch_num_tiles[idx] += (
399
+ 1 + num_width_tiles * num_height_tiles
400
+ ).tolist()
401
+
402
+ total_tiles.append(pixel_values[idx, : batch_num_tiles[idx]])
403
+
404
+ total_tiles = mx.concatenate(total_tiles, axis=0)
405
+
406
+ if total_tiles.shape[0] == 0:
407
+ return self.language_model.model.embed_tokens(input_ids)
408
+
409
+ # Get the input embeddings from the language model
410
+ input_embeds = self.language_model.model.embed_tokens(input_ids)
411
+
412
+ # Get the ouptut hidden states from the vision model
413
+ hidden_states, *_ = self.vision(
414
+ total_tiles.transpose(0, 2, 3, 1), output_hidden_states=True
415
+ )
416
+
417
+ # Pass image features through the multi-modal projector
418
+ image_features = self.projector(hidden_states)
419
+
420
+ _, hw, n_dim = image_features.shape
421
+ h = w = int(hw**0.5)
422
+
423
+ image_features = self.process_image_features(
424
+ input_embeds,
425
+ image_features,
426
+ images_spatial_crop,
427
+ image_seq_mask,
428
+ h,
429
+ w,
430
+ n_dim,
431
+ )
432
+
433
+ return image_features
434
+
435
+ @property
436
+ def layers(self):
437
+ return self.language_model.model.layers
438
+
439
+ def __call__(
440
+ self,
441
+ input_ids: mx.array,
442
+ pixel_values: Optional[mx.array] = None,
443
+ mask: Optional[mx.array] = None,
444
+ cache=None,
445
+ **kwargs,
446
+ ):
447
+
448
+ images_spatial_crop = kwargs.get("images_spatial_crop", None)
449
+ images_seq_mask = kwargs.get("images_seq_mask", None)
450
+ input_embeddings = self.get_input_embeddings(
451
+ input_ids, pixel_values, images_spatial_crop, images_seq_mask
452
+ )
453
+ logits = self.language_model(
454
+ input_ids, cache=cache, inputs_embeds=input_embeddings
455
+ )
456
+ return logits
457
+
458
+ @staticmethod
459
+ def sanitize(weights):
460
+ def transform_key(key):
461
+ if "language" in key and "language_model" not in key:
462
+ if ".model" in key:
463
+ key = key.replace("language.model", "language_model.model")
464
+ if ".lm_head" in key:
465
+ key = key.replace("language", "language_model")
466
+ if "vision" in key and "vision_tower" not in key:
467
+ key = key.replace("vision", "vision.vision_tower")
468
+ if "view_seperator" in key:
469
+ key = key.replace("view_seperator", "view_separator")
470
+ return key
471
+
472
+ return {transform_key(k): v for k, v in weights.items()}