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
+ """
2
+ From https://github.com/deepseek-ai/DeepSeek-VL2
3
+ """
4
+
5
+ import math
6
+ from dataclasses import dataclass
7
+ from typing import Dict, List, Literal, Optional, Tuple
8
+
9
+ import mlx.core as mx
10
+ import mlx.nn as nn
11
+ import numpy as np
12
+ from PIL import Image, ImageOps
13
+ from transformers import LlamaTokenizerFast
14
+ from transformers.processing_utils import ProcessorMixin
15
+
16
+ from .conversation import get_conv_template
17
+
18
+
19
+ def select_best_resolution(image_size, candidate_resolutions):
20
+ # used for cropping
21
+ original_width, original_height = image_size
22
+ best_fit = None
23
+ max_effective_resolution = 0
24
+ min_wasted_resolution = float("inf")
25
+
26
+ for width, height in candidate_resolutions:
27
+ scale = min(width / original_width, height / original_height)
28
+ downscaled_width, downscaled_height = int(original_width * scale), int(
29
+ original_height * scale
30
+ )
31
+ effective_resolution = min(
32
+ downscaled_width * downscaled_height, original_width * original_height
33
+ )
34
+ wasted_resolution = (width * height) - effective_resolution
35
+
36
+ if effective_resolution > max_effective_resolution or (
37
+ effective_resolution == max_effective_resolution
38
+ and wasted_resolution < min_wasted_resolution
39
+ ):
40
+ max_effective_resolution = effective_resolution
41
+ min_wasted_resolution = wasted_resolution
42
+ best_fit = (width, height)
43
+
44
+ return best_fit
45
+
46
+
47
+ class DictOutput(object):
48
+ def keys(self):
49
+ return self.__dict__.keys()
50
+
51
+ def __getitem__(self, item):
52
+ if isinstance(item, int):
53
+ return list(self.__dict__.values())[item]
54
+ if item not in self.__dict__:
55
+ raise KeyError(item)
56
+ return self.__dict__[item]
57
+
58
+ def __setitem__(self, key, value):
59
+ self.__dict__[key] = value
60
+
61
+
62
+ @dataclass
63
+ class VLChatProcessorOutput(DictOutput):
64
+ sft_format: str
65
+ input_ids: mx.array
66
+ target_ids: mx.array
67
+ images: mx.array
68
+ images_seq_mask: mx.array
69
+ images_spatial_crop: mx.array
70
+ num_image_tokens: List[int]
71
+
72
+ def __len__(self):
73
+ return len(self.input_ids)
74
+
75
+
76
+ @dataclass
77
+ class BatchCollateOutput(DictOutput):
78
+ sft_format: List[str]
79
+ input_ids: mx.array
80
+ labels: mx.array
81
+ images: mx.array
82
+ attention_mask: mx.array
83
+ images_seq_mask: mx.array
84
+ images_spatial_crop: mx.array
85
+ seq_lens: List[int]
86
+
87
+
88
+ class ImageTransform:
89
+ def __init__(
90
+ self,
91
+ mean: Optional[Tuple[float, float, float]] = (0.5, 0.5, 0.5),
92
+ std: Optional[Tuple[float, float, float]] = (0.5, 0.5, 0.5),
93
+ normalize: bool = True,
94
+ ):
95
+ self.mean = mean
96
+ self.std = std
97
+ self.normalize = normalize
98
+
99
+ def __call__(self, pil_img: Image.Image):
100
+ # Convert PIL image to numpy array and normalize
101
+
102
+ img = mx.array(np.array(pil_img)) / 255.0
103
+
104
+ # Transpose from HWC to CHW format
105
+ img = mx.transpose(img, [2, 0, 1])
106
+
107
+ if self.normalize:
108
+ mean = mx.array(self.mean).reshape(-1, 1, 1)
109
+ std = mx.array(self.std).reshape(-1, 1, 1)
110
+ img = (img - mean) / std
111
+
112
+ return img
113
+
114
+
115
+ class DeepseekVLV2Processor(ProcessorMixin):
116
+ tokenizer_class = ("LlamaTokenizer", "LlamaTokenizerFast")
117
+ attributes = ["tokenizer"]
118
+
119
+ def __init__(
120
+ self,
121
+ tokenizer: LlamaTokenizerFast,
122
+ candidate_resolutions: Tuple[Tuple[int, int]],
123
+ patch_size: int,
124
+ downsample_ratio: int,
125
+ image_mean: Tuple[float, float, float] = (0.5, 0.5, 0.5),
126
+ image_std: Tuple[float, float, float] = (0.5, 0.5, 0.5),
127
+ normalize: bool = True,
128
+ image_token: str = "<image>",
129
+ pad_token: str = "<|▁pad▁|>",
130
+ add_special_token: bool = False,
131
+ sft_format: str = "deepseek",
132
+ mask_prompt: bool = True,
133
+ ignore_id: int = -100,
134
+ **kwargs,
135
+ ):
136
+ self.candidate_resolutions = candidate_resolutions
137
+ self.image_size = candidate_resolutions[0][0]
138
+ self.patch_size = patch_size
139
+ self.image_mean = image_mean
140
+ self.image_std = image_std
141
+ self.normalize = normalize
142
+ self.downsample_ratio = downsample_ratio
143
+
144
+ self.image_transform = ImageTransform(
145
+ mean=image_mean, std=image_std, normalize=normalize
146
+ )
147
+ self.tokenizer = tokenizer
148
+ self.tokenizer.padding_side = "left"
149
+
150
+ # Add special tokens
151
+ if tokenizer.pad_token is None:
152
+ self.tokenizer.add_special_tokens({"pad_token": pad_token})
153
+ print(
154
+ f"Add pad token = ['{pad_token}'] to the tokenizer\n"
155
+ f"{pad_token}:{tokenizer.encode(pad_token, add_special_tokens=False)[0]}"
156
+ )
157
+
158
+ image_token_id = self.tokenizer.vocab.get(image_token)
159
+ if image_token_id is None:
160
+ special_tokens = [image_token]
161
+ special_tokens_dict = {"additional_special_tokens": special_tokens}
162
+ self.tokenizer.add_special_tokens(special_tokens_dict)
163
+ self.image_token_id = self.tokenizer.vocab.get(image_token)
164
+ print(
165
+ f"Add image token = ['{image_token}'] to the tokenizer\n"
166
+ f"{image_token}:{tokenizer.encode(image_token, add_special_tokens=False)[0]}"
167
+ )
168
+
169
+ # Add grounding-related tokens
170
+ special_tokens = ["<|ref|>", "<|/ref|>", "<|det|>", "<|/det|>", "<|grounding|>"]
171
+ special_tokens_dict = {"additional_special_tokens": special_tokens}
172
+ self.tokenizer.add_special_tokens(special_tokens_dict)
173
+ print("Added grounding-related tokens")
174
+
175
+ # Add chat tokens
176
+ special_tokens = ["<|User|>", "<|Assistant|>"]
177
+ special_tokens_dict = {"additional_special_tokens": special_tokens}
178
+ self.tokenizer.add_special_tokens(special_tokens_dict)
179
+ print("Added chat tokens")
180
+
181
+ self.image_token = image_token
182
+ self.pad_token = pad_token
183
+ self.add_special_token = add_special_token
184
+ self.sft_format = sft_format
185
+ self.mask_prompt = mask_prompt
186
+ self.ignore_id = ignore_id
187
+
188
+ super().__init__(tokenizer, **kwargs)
189
+
190
+ @property
191
+ def bos_id(self):
192
+ return self.tokenizer.bos_token_id
193
+
194
+ @property
195
+ def eos_id(self):
196
+ return self.tokenizer.eos_token_id
197
+
198
+ @property
199
+ def pad_id(self):
200
+ return self.tokenizer.pad_token_id
201
+
202
+ def encode(self, text: str, bos: bool = True, eos: bool = False):
203
+ t = self.tokenizer.encode(text, add_special_tokens=False)
204
+
205
+ if bos:
206
+ t = [self.bos_id] + t
207
+ if eos:
208
+ t = t + [self.eos_id]
209
+
210
+ return t
211
+
212
+ def decode(self, t: List[int], **kwargs) -> str:
213
+ return self.tokenizer.decode(t, **kwargs)
214
+
215
+ def process_one(
216
+ self,
217
+ prompt: str = None,
218
+ conversations: List[Dict[str, str]] = None,
219
+ images: List[Image.Image] = None,
220
+ apply_sft_format: bool = False,
221
+ inference_mode: bool = True,
222
+ system_prompt: str = "",
223
+ **kwargs,
224
+ ):
225
+ assert (
226
+ prompt is None or conversations is None
227
+ ), "prompt and conversations cannot be used at the same time."
228
+
229
+ if apply_sft_format:
230
+ sft_format = self.format_prompts(
231
+ prompts=prompt, sft_format=self.sft_format, system_prompt=system_prompt
232
+ )
233
+ else:
234
+ sft_format = prompt
235
+ (
236
+ tokenized_str,
237
+ images_list,
238
+ images_seq_mask,
239
+ images_spatial_crop,
240
+ num_image_tokens,
241
+ ) = self.tokenize_with_images(
242
+ sft_format, images, bos=True, eos=True, cropping=len(images) <= 2
243
+ )
244
+ masked_tokenized_str = []
245
+ for token_index in tokenized_str:
246
+ if token_index != self.image_token_id:
247
+ masked_tokenized_str.append(token_index)
248
+ else:
249
+ masked_tokenized_str.append(self.ignore_id)
250
+
251
+ input_ids = mx.array(tokenized_str)
252
+ target_ids = mx.array(masked_tokenized_str)
253
+ images_seq_mask = mx.array(images_seq_mask)
254
+
255
+ # Set ignored indices
256
+ target_ids = mx.where(
257
+ (input_ids < 0) | (input_ids == self.image_token_id),
258
+ self.ignore_id,
259
+ target_ids,
260
+ )
261
+ input_ids = mx.where(input_ids < 0, self.pad_id, input_ids)
262
+
263
+ if inference_mode:
264
+ input_ids = input_ids[:-1]
265
+ target_ids = target_ids[:-1]
266
+ images_seq_mask = images_seq_mask[:-1]
267
+
268
+ if len(images_list) == 0:
269
+ images = mx.zeros((1, 3, self.image_size, self.image_size))
270
+ images_spatial_crop = mx.zeros((1, 2))
271
+ else:
272
+ images = mx.stack(images_list)
273
+ images_spatial_crop = mx.array(images_spatial_crop)
274
+
275
+ return VLChatProcessorOutput(
276
+ sft_format=sft_format,
277
+ input_ids=input_ids,
278
+ target_ids=target_ids,
279
+ images=images,
280
+ images_seq_mask=images_seq_mask,
281
+ images_spatial_crop=images_spatial_crop,
282
+ num_image_tokens=num_image_tokens,
283
+ )
284
+
285
+ def pad_sequence(self, sequences, padding_value):
286
+ # Get max length of sequences
287
+ max_len = max(len(seq) for seq in sequences)
288
+
289
+ # Pad each sequence to max length
290
+ padded_seqs = []
291
+ for seq in sequences:
292
+ pad_length = max_len - len(seq)
293
+ if pad_length > 0:
294
+ padding = mx.full((pad_length,), padding_value)
295
+ padded_seq = mx.concatenate([seq, padding])
296
+ else:
297
+ padded_seq = seq
298
+ padded_seqs.append(padded_seq)
299
+
300
+ return mx.stack(padded_seqs)
301
+
302
+ def tokenize_with_images(
303
+ self,
304
+ conversation: str,
305
+ images: List[Image.Image],
306
+ bos: bool = True,
307
+ eos: bool = True,
308
+ cropping: bool = True,
309
+ ):
310
+ """Tokenize text with <image> tags."""
311
+ assert conversation.count(self.image_token) == len(images)
312
+ text_splits = conversation.split(self.image_token)
313
+ images_list, images_seq_mask, images_spatial_crop = [], [], []
314
+ num_image_tokens = []
315
+ tokenized_str = []
316
+ for text_sep, image in zip(text_splits, images):
317
+ """encode text_sep"""
318
+ tokenized_sep = self.encode(text_sep, bos=False, eos=False)
319
+ tokenized_str += tokenized_sep
320
+ images_seq_mask += [False] * len(tokenized_sep)
321
+
322
+ """select best resolution for anyres"""
323
+ if cropping:
324
+ best_width, best_height = select_best_resolution(
325
+ image.size, self.candidate_resolutions
326
+ )
327
+ else:
328
+ best_width, best_height = self.image_size, self.image_size
329
+
330
+ """process the global view"""
331
+ global_view = ImageOps.pad(
332
+ image,
333
+ (self.image_size, self.image_size),
334
+ color=tuple(int(x * 255) for x in self.image_transform.mean),
335
+ )
336
+ images_list.append(self.image_transform(global_view))
337
+
338
+ """process the local views"""
339
+ local_view = ImageOps.pad(
340
+ image,
341
+ (best_width, best_height),
342
+ color=tuple(int(x * 255) for x in self.image_transform.mean),
343
+ )
344
+ for i in range(0, best_height, self.image_size):
345
+ for j in range(0, best_width, self.image_size):
346
+ images_list.append(
347
+ self.image_transform(
348
+ local_view.crop(
349
+ (j, i, j + self.image_size, i + self.image_size)
350
+ )
351
+ )
352
+ )
353
+
354
+ """record height / width crop num"""
355
+ num_width_tiles, num_height_tiles = (
356
+ best_width // self.image_size,
357
+ best_height // self.image_size,
358
+ )
359
+ images_spatial_crop.append([num_width_tiles, num_height_tiles])
360
+
361
+ """add image tokens"""
362
+ h = w = math.ceil(
363
+ (self.image_size // self.patch_size) / self.downsample_ratio
364
+ )
365
+ # global views tokens h * (w + 1), 1 is for line seperator
366
+ tokenized_image = [self.image_token_id] * h * (w + 1)
367
+ # add a seperator between global and local views
368
+ tokenized_image += [self.image_token_id]
369
+ # local views tokens, (num_height_tiles * h) * (num_width_tiles * w + 1)
370
+ tokenized_image += (
371
+ [self.image_token_id]
372
+ * (num_height_tiles * h)
373
+ * (num_width_tiles * w + 1)
374
+ )
375
+
376
+ tokenized_str += tokenized_image
377
+ images_seq_mask += [True] * len(tokenized_image)
378
+ num_image_tokens.append(len(tokenized_image))
379
+
380
+ """process the last text split"""
381
+ tokenized_sep = self.encode(text_splits[-1], bos=False, eos=False)
382
+ tokenized_str += tokenized_sep
383
+ images_seq_mask += [False] * len(tokenized_sep)
384
+
385
+ """add the bos and eos tokens"""
386
+ if bos:
387
+ tokenized_str = [self.bos_id] + tokenized_str
388
+ images_seq_mask = [False] + images_seq_mask
389
+ if eos:
390
+ tokenized_str = tokenized_str + [self.eos_id]
391
+ images_seq_mask = images_seq_mask + [False]
392
+
393
+ assert len(tokenized_str) == len(
394
+ images_seq_mask
395
+ ), f"tokenize_with_images func: tokenized_str's length {len(tokenized_str)} is not equal to imags_seq_mask's length {len(images_seq_mask)}"
396
+
397
+ return (
398
+ tokenized_str,
399
+ images_list,
400
+ images_seq_mask,
401
+ images_spatial_crop,
402
+ num_image_tokens,
403
+ )
404
+
405
+ def batchify(
406
+ self,
407
+ sample_list: List[VLChatProcessorOutput],
408
+ padding: Literal["left", "right"] = "left",
409
+ ) -> BatchCollateOutput:
410
+ batched_sft_format = [sample.sft_format for sample in sample_list]
411
+ batched_input_ids = [sample.input_ids for sample in sample_list]
412
+ batched_labels = [sample.target_ids for sample in sample_list]
413
+ batched_images_seq_mask = [sample.images_seq_mask for sample in sample_list]
414
+ seq_lens = [len(sample) for sample in sample_list]
415
+
416
+ # Padding
417
+ if padding == "left":
418
+ # MLX implementation of padding
419
+ max_len = max(len(ids) for ids in batched_input_ids)
420
+
421
+ def pad_left(sequence, pad_val):
422
+ pad_len = max_len - len(sequence)
423
+ if pad_len > 0:
424
+ padding = mx.full((pad_len,), pad_val)
425
+ return mx.concatenate([padding, sequence])
426
+ return sequence
427
+
428
+ batched_input_ids = mx.stack(
429
+ [pad_left(ids, self.pad_id) for ids in batched_input_ids]
430
+ )
431
+ batched_labels = mx.stack(
432
+ [pad_left(ids, self.ignore_id) for ids in batched_labels]
433
+ )
434
+ batched_images_seq_mask = mx.stack(
435
+ [pad_left(mask, False) for mask in batched_images_seq_mask]
436
+ )
437
+ batched_attention_mask = batched_input_ids != self.pad_id
438
+
439
+ else:
440
+ batched_input_ids = self.pad_sequence(batched_input_ids, self.pad_id)
441
+ batched_labels = self.pad_sequence(batched_labels, self.ignore_id)
442
+ batched_images_seq_mask = self.pad_sequence(batched_images_seq_mask, False)
443
+ batched_attention_mask = batched_input_ids != self.pad_id
444
+
445
+ # Padding images
446
+ max_n_patches = max(sample.images.shape[0] for sample in sample_list)
447
+ batched_images = []
448
+ for sample in sample_list:
449
+ images = sample.images
450
+ n_pads = max_n_patches - images.shape[0]
451
+ if n_pads > 0:
452
+ pad_shape = (n_pads,) + images.shape[1:]
453
+ pad_images = mx.zeros(pad_shape)
454
+ images = mx.concatenate([images, pad_images])
455
+ batched_images.append(images)
456
+ batched_images = mx.stack(batched_images)
457
+
458
+ # Padding spatial crop info
459
+ max_n_images = max(
460
+ sample.images_spatial_crop.shape[0] for sample in sample_list
461
+ )
462
+ batched_images_spatial_crop = []
463
+ for sample in sample_list:
464
+ spatial_crop = sample.images_spatial_crop
465
+ n_pads = max_n_images - spatial_crop.shape[0]
466
+ if n_pads > 0:
467
+ pad_spatial = mx.zeros((n_pads, 2))
468
+ spatial_crop = mx.concatenate([spatial_crop, pad_spatial])
469
+ batched_images_spatial_crop.append(spatial_crop)
470
+ batched_images_spatial_crop = mx.stack(batched_images_spatial_crop)
471
+
472
+ return {
473
+ "input_ids": batched_input_ids,
474
+ "attention_mask": batched_attention_mask,
475
+ "labels": batched_labels,
476
+ "images": batched_images,
477
+ "images_seq_mask": batched_images_seq_mask,
478
+ "images_spatial_crop": batched_images_spatial_crop,
479
+ "sft_format": batched_sft_format,
480
+ "seq_lens": seq_lens,
481
+ }
482
+
483
+ def __call__(
484
+ self,
485
+ *,
486
+ text: str = None,
487
+ images: List[Image.Image] = None,
488
+ apply_sft_format: bool = False,
489
+ force_batchify: bool = True,
490
+ inference_mode: bool = True,
491
+ system_prompt: str = "",
492
+ **kwargs,
493
+ ):
494
+ """
495
+
496
+ Args:
497
+ prompt (str): the formatted prompt;
498
+ conversations (List[Dict]): conversations with a list of messages;
499
+ images (List[ImageType]): the list of images;
500
+ apply_sft_format (bool): if prompt is not None, then apply the SFT format to prompt;
501
+ if conversations is not None, then it will always apply the SFT format to conversations;
502
+ force_batchify (bool): force batchify the inputs;
503
+ inference_mode (bool): if True, then remove the last eos token;
504
+ system_prompt (str): the system prompt;
505
+ **kwargs:
506
+
507
+ Returns:
508
+ outputs (BaseProcessorOutput): the output of the processor,
509
+ - input_ids (torch.LongTensor): [N + image tokens]
510
+ - images (torch.FloatTensor): [n_images, 3, H, W]
511
+ - image_id (int): the id of the image token
512
+ - num_image_tokens (List[int]): the number of image tokens
513
+ """
514
+
515
+ prepare = self.process_one(
516
+ prompt=text,
517
+ images=images,
518
+ apply_sft_format=apply_sft_format,
519
+ inference_mode=inference_mode,
520
+ system_prompt=system_prompt,
521
+ )
522
+
523
+ if force_batchify:
524
+ prepare = self.batchify([prepare])
525
+
526
+ return prepare