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,236 @@
1
+ import inspect
2
+ from dataclasses import dataclass
3
+ from typing import Dict, Optional, Tuple, Union
4
+
5
+ import mlx.core as mx
6
+ import mlx.nn as nn
7
+
8
+ from ..base import (
9
+ LanguageModelOutput,
10
+ create_attention_mask,
11
+ scaled_dot_product_attention,
12
+ )
13
+ from ..cache import KVCache
14
+
15
+
16
+ @dataclass
17
+ class TextConfig:
18
+ model_type: str
19
+ hidden_size: int
20
+ num_hidden_layers: int
21
+ intermediate_size: int
22
+ num_attention_heads: int
23
+ rms_norm_eps: float
24
+ vocab_size: int
25
+ attention_bias: bool = True
26
+ num_key_value_heads: int = None
27
+ rope_theta: float = 1000000
28
+ rope_traditional: bool = False
29
+ rope_scaling: Optional[Dict[str, Union[float, str]]] = None
30
+ max_position_embeddings: int = 4096
31
+ tie_word_embeddings: bool = True
32
+
33
+ @classmethod
34
+ def from_dict(cls, params):
35
+ return cls(
36
+ **{
37
+ k: v
38
+ for k, v in params.items()
39
+ if k in inspect.signature(cls).parameters
40
+ }
41
+ )
42
+
43
+ def __post_init__(self):
44
+ if self.num_key_value_heads is None:
45
+ self.num_key_value_heads = self.num_attention_heads
46
+
47
+ if self.rope_scaling:
48
+ required_keys = {"factor", "type"}
49
+ if not all(key in self.rope_scaling for key in required_keys):
50
+ raise ValueError(f"rope_scaling must contain keys {required_keys}")
51
+
52
+ if self.rope_scaling["type"] != "linear":
53
+ raise ValueError("rope_scaling 'type' currently only supports 'linear'")
54
+
55
+
56
+ class Attention(nn.Module):
57
+ def __init__(self, config: TextConfig):
58
+ super().__init__()
59
+
60
+ dim = config.hidden_size
61
+ self.n_heads = n_heads = config.num_attention_heads
62
+ self.n_kv_heads = n_kv_heads = config.num_key_value_heads
63
+
64
+ head_dim = config.hidden_size // n_heads
65
+ self.scale = head_dim**-0.5
66
+
67
+ if hasattr(config, "attention_bias"):
68
+ attention_bias = config.attention_bias
69
+ else:
70
+ attention_bias = False
71
+
72
+ self.q_proj = nn.Linear(dim, n_heads * head_dim, bias=attention_bias)
73
+ self.k_proj = nn.Linear(dim, n_kv_heads * head_dim, bias=attention_bias)
74
+ self.v_proj = nn.Linear(dim, n_kv_heads * head_dim, bias=attention_bias)
75
+ self.o_proj = nn.Linear(n_heads * head_dim, dim, bias=False)
76
+
77
+ rope_scale = (
78
+ 1 / config.rope_scaling["factor"]
79
+ if config.rope_scaling is not None
80
+ and config.rope_scaling["type"] == "linear"
81
+ else 1
82
+ )
83
+ self.rope = nn.RoPE(
84
+ head_dim,
85
+ traditional=config.rope_traditional,
86
+ base=config.rope_theta,
87
+ scale=rope_scale,
88
+ )
89
+
90
+ def __call__(
91
+ self,
92
+ x: mx.array,
93
+ mask: Optional[mx.array] = None,
94
+ cache: Optional[Tuple[mx.array, mx.array]] = None,
95
+ ) -> mx.array:
96
+ B, L, D = x.shape
97
+
98
+ queries, keys, values = self.q_proj(x), self.k_proj(x), self.v_proj(x)
99
+
100
+ # Prepare the queries, keys and values for the attention computation
101
+ queries = queries.reshape(B, L, self.n_heads, -1).transpose(0, 2, 1, 3)
102
+ keys = keys.reshape(B, L, self.n_kv_heads, -1).transpose(0, 2, 1, 3)
103
+ values = values.reshape(B, L, self.n_kv_heads, -1).transpose(0, 2, 1, 3)
104
+
105
+ if cache is not None:
106
+ queries = self.rope(queries, offset=cache.offset)
107
+ keys = self.rope(keys, offset=cache.offset)
108
+ keys, values = cache.update_and_fetch(keys, values)
109
+ else:
110
+ queries = self.rope(queries)
111
+ keys = self.rope(keys)
112
+
113
+ output = scaled_dot_product_attention(
114
+ queries, keys, values, cache, scale=self.scale, mask=mask
115
+ )
116
+ output = output.transpose(0, 2, 1, 3).reshape(B, L, -1)
117
+ return self.o_proj(output)
118
+
119
+
120
+ class MLP(nn.Module):
121
+ def __init__(self, dim, hidden_dim):
122
+ super().__init__()
123
+ self.gate_proj = nn.Linear(dim, hidden_dim, bias=False)
124
+ self.down_proj = nn.Linear(hidden_dim, dim, bias=False)
125
+ self.up_proj = nn.Linear(dim, hidden_dim, bias=False)
126
+
127
+ def __call__(self, x) -> mx.array:
128
+ return self.down_proj(nn.silu(self.gate_proj(x)) * self.up_proj(x))
129
+
130
+
131
+ class TransformerBlock(nn.Module):
132
+ def __init__(self, config: TextConfig):
133
+ super().__init__()
134
+ self.num_attention_heads = config.num_attention_heads
135
+ self.hidden_size = config.hidden_size
136
+ self.self_attn = Attention(config)
137
+ self.mlp = MLP(config.hidden_size, config.intermediate_size)
138
+ self.input_layernorm = nn.RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
139
+ self.post_attention_layernorm = nn.RMSNorm(
140
+ config.hidden_size, eps=config.rms_norm_eps
141
+ )
142
+ self.config = config
143
+
144
+ def __call__(
145
+ self,
146
+ x: mx.array,
147
+ mask: Optional[mx.array] = None,
148
+ cache=None,
149
+ ) -> mx.array:
150
+ r = self.self_attn(self.input_layernorm(x), mask, cache)
151
+ h = x + r
152
+ r = self.mlp(self.post_attention_layernorm(h))
153
+ out = h + r
154
+ return out
155
+
156
+
157
+ class Qwen2Model(nn.Module):
158
+ def __init__(self, config: TextConfig):
159
+ super().__init__()
160
+ self.config = config
161
+ self.vocab_size = config.vocab_size
162
+ self.num_hidden_layers = config.num_hidden_layers
163
+ assert self.vocab_size > 0
164
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size)
165
+ self.layers = [
166
+ TransformerBlock(config=config) for _ in range(config.num_hidden_layers)
167
+ ]
168
+ self.norm = nn.RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
169
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
170
+
171
+ def __call__(
172
+ self,
173
+ inputs: mx.array,
174
+ inputs_embeds: Optional[mx.array] = None,
175
+ mask: Optional[mx.array] = None,
176
+ cache=None,
177
+ ):
178
+ # for passing merged input embeddings
179
+ if inputs_embeds is None:
180
+ h = self.embed_tokens(inputs)
181
+ else:
182
+ h = inputs_embeds
183
+
184
+ if cache is None:
185
+ cache = [None] * len(self.layers)
186
+
187
+ if mask is None:
188
+ mask = create_attention_mask(h, cache)
189
+
190
+ for layer, c in zip(self.layers, cache):
191
+ h = layer(h, mask, c)
192
+
193
+ return self.lm_head(self.norm(h))
194
+
195
+
196
+ class LanguageModel(nn.Module):
197
+ def __init__(self, config: TextConfig):
198
+ super().__init__()
199
+ self.config = config
200
+ self.model_type = config.model_type
201
+ self.model = Qwen2Model(config)
202
+
203
+ def __call__(
204
+ self,
205
+ inputs: mx.array,
206
+ inputs_embeds: Optional[mx.array] = None,
207
+ mask: Optional[mx.array] = None,
208
+ cache=None,
209
+ ):
210
+ out = self.model(inputs, mask=mask, cache=cache, inputs_embeds=inputs_embeds)
211
+ return LanguageModelOutput(logits=out)
212
+
213
+ def sanitize(self, weights):
214
+ if (
215
+ self.config.tie_word_embeddings
216
+ and "language_model.model.lm_head.weight" not in weights
217
+ ):
218
+ weights["language_model.model.lm_head.weight"] = weights[
219
+ "language_model.model.embed_tokens.weight"
220
+ ]
221
+
222
+ return {
223
+ k: v for k, v in weights.items() if "self_attn.rotary_emb.inv_freq" not in k
224
+ }
225
+
226
+ @property
227
+ def layers(self):
228
+ return self.model.layers
229
+
230
+ @property
231
+ def head_dim(self):
232
+ return self.config.hidden_size // self.config.num_attention_heads
233
+
234
+ @property
235
+ def n_kv_heads(self):
236
+ return self.config.num_key_value_heads
@@ -0,0 +1,256 @@
1
+ import glob
2
+ import inspect
3
+ import json
4
+ import re
5
+ from dataclasses import dataclass
6
+ from functools import partial, reduce
7
+ from pathlib import Path
8
+ from typing import Dict, List, Optional, Tuple
9
+
10
+ import mlx.core as mx
11
+ import mlx.nn as nn
12
+ import numpy as np
13
+ from huggingface_hub import snapshot_download
14
+ from PIL import Image
15
+ from transformers import AutoConfig
16
+ from transformers.image_transforms import (
17
+ convert_to_rgb,
18
+ normalize,
19
+ rescale,
20
+ resize,
21
+ to_channel_dimension_format,
22
+ )
23
+ from transformers.image_utils import to_numpy_array
24
+
25
+ from ..base import BaseImageProcessor
26
+ from .language import LanguageModel, TextConfig
27
+ from .vision import VisionConfig, VisionModel
28
+
29
+
30
+ @dataclass
31
+ class ModelConfig:
32
+ text_config: TextConfig
33
+ vision_config: VisionConfig
34
+ model_type: str
35
+ auto_map: dict
36
+ hidden_size: int
37
+ mm_hidden_size: int
38
+ mm_projector_type: str = "mlp2x_gelu"
39
+ ignore_index: int = -100
40
+ image_token_index: int = -200
41
+ vocab_size: int = 151936
42
+ eos_token_id: Optional[List[int]] = None
43
+
44
+ @classmethod
45
+ def from_dict(cls, params):
46
+ if not params.get("text_config", {}):
47
+ # Copy text config parameters from root level
48
+ excluded_keys = {"vision_config"}
49
+ params["text_config"] = dict(
50
+ filter(lambda x: x[0] not in excluded_keys, params.items())
51
+ )
52
+ if not params.get("vision_config", {}).get("model_type", {}):
53
+ # Set default model type
54
+ params["vision_config"]["model_type"] = "siglip_vision_model"
55
+
56
+ return cls(
57
+ **{
58
+ k: v
59
+ for k, v in params.items()
60
+ if k in inspect.signature(cls).parameters
61
+ }
62
+ )
63
+
64
+
65
+ class ImageProcessor(BaseImageProcessor):
66
+ def preprocess(self, images):
67
+ if isinstance(images, Image.Image):
68
+ images = [images]
69
+ else:
70
+ assert isinstance(images, list)
71
+
72
+ transforms = [
73
+ convert_to_rgb,
74
+ to_numpy_array,
75
+ partial(
76
+ resize,
77
+ size=self.size,
78
+ resample=self.resample,
79
+ data_format=self.data_format,
80
+ ),
81
+ partial(rescale, scale=self.rescale_factor, data_format=self.data_format),
82
+ partial(
83
+ normalize,
84
+ mean=self.image_mean,
85
+ std=self.image_std,
86
+ data_format=self.data_format,
87
+ ),
88
+ partial(
89
+ to_channel_dimension_format,
90
+ channel_dim=self.data_format,
91
+ input_channel_dim=self.data_format,
92
+ ),
93
+ ]
94
+
95
+ images = reduce(lambda x, f: [*map(f, x)], transforms, images)
96
+
97
+ return images
98
+
99
+
100
+ class LlavaMultiModalProjector(nn.Module):
101
+ def __init__(self, config: ModelConfig):
102
+ super().__init__()
103
+ self.linear_1 = nn.Linear(
104
+ config.vision_config.hidden_size, config.text_config.hidden_size, bias=True
105
+ )
106
+ self.gelu = nn.GELU()
107
+ self.linear_2 = nn.Linear(
108
+ config.text_config.hidden_size, config.text_config.hidden_size, bias=True
109
+ )
110
+
111
+ def __call__(self, x: mx.array) -> mx.array:
112
+ x = self.linear_1(x)
113
+ x = self.gelu(x)
114
+ x = self.linear_2(x)
115
+ return x
116
+
117
+
118
+ class SigLipVisionTower(nn.Module):
119
+ def __init__(self, config: VisionConfig):
120
+ super().__init__()
121
+ self.vision_tower = VisionModel(config)
122
+
123
+ def __call__(
124
+ self, x: mx.array, output_hidden_states: Optional[bool] = None
125
+ ) -> mx.array:
126
+ return self.vision_tower(x, output_hidden_states)
127
+
128
+
129
+ class Model(nn.Module):
130
+ def __init__(self, config: ModelConfig):
131
+ super().__init__()
132
+ self.model_type = config.model_type
133
+ self.config = config
134
+
135
+ self.vision_tower = SigLipVisionTower(config.vision_config)
136
+ self.language_model = LanguageModel(config.text_config)
137
+ self.mm_projector = LlavaMultiModalProjector(config)
138
+
139
+ def get_input_embeddings(
140
+ self,
141
+ input_ids: Optional[mx.array] = None,
142
+ pixel_values: Optional[mx.array] = None,
143
+ ):
144
+ if pixel_values is None:
145
+ return self.language_model.model.embed_tokens(input_ids)
146
+
147
+ inputs_embeds = self.language_model.model.embed_tokens(input_ids)
148
+
149
+ *_, hidden_state = self.vision_tower(
150
+ pixel_values.transpose(0, 2, 3, 1), output_hidden_states=True
151
+ )
152
+
153
+ image_features = hidden_state[-1].astype(pixel_values.dtype)
154
+ assert image_features.shape[-2] == 729
155
+
156
+ image_features = self.mm_projector(image_features)
157
+
158
+ final_inputs_embeds = self._prepare_inputs_for_multimodal(
159
+ image_features, inputs_embeds, input_ids
160
+ )
161
+ return final_inputs_embeds
162
+
163
+ def _prepare_inputs_for_multimodal(self, image_features, inputs_embeds, input_ids):
164
+ image_token_index = self.config.image_token_index
165
+ num_images, num_image_patches, embed_dim = image_features.shape
166
+
167
+ batch_size, seq_length, embed_dim = inputs_embeds.shape
168
+ num_images, num_image_patches, _ = image_features.shape
169
+
170
+ # Positions of <image> tokens in input_ids for each batch
171
+ image_positions = mx.argmax(input_ids == image_token_index, axis=1)
172
+
173
+ final_embeddings = []
174
+ for b in range(batch_size):
175
+ text_segments = []
176
+ start_idx = 0
177
+ position = int(image_positions[b].item())
178
+
179
+ text_segments.append(inputs_embeds[b : b + 1, start_idx:position])
180
+ text_segments.append(image_features[b : b + 1])
181
+ text_segments.append(inputs_embeds[b : b + 1, position + 1 :])
182
+
183
+ batch_embeddings = mx.concatenate(text_segments, axis=1)
184
+ final_embeddings.append(batch_embeddings)
185
+
186
+ # Create a final embedding of shape
187
+ # (batch_size, num_image_patches + sequence_len, embed_dim)
188
+ return mx.concatenate(final_embeddings, axis=0)
189
+
190
+ @property
191
+ def layers(self):
192
+ return self.language_model.model.layers
193
+
194
+ def __call__(
195
+ self,
196
+ input_ids: mx.array,
197
+ pixel_values: mx.array,
198
+ mask: Optional[mx.array] = None,
199
+ cache: Optional[Tuple[mx.array, mx.array]] = None,
200
+ **kwargs,
201
+ ):
202
+ input_embeddings = self.get_input_embeddings(input_ids, pixel_values)
203
+ logits = self.language_model(
204
+ inputs=input_ids,
205
+ cache=cache,
206
+ inputs_embeds=input_embeddings,
207
+ mask=None, # TODO: add mask
208
+ )
209
+ return logits
210
+
211
+ def sanitize(self, weights):
212
+ weights = {
213
+ (
214
+ f"{k.split('.', 1)[1]}"
215
+ if re.match(r"^model\.vision_tower", k)
216
+ else (
217
+ f"mm_projector.linear_1.{k.split('.')[-1]}"
218
+ if re.match(r"^model\.mm_projector\.0", k)
219
+ else (
220
+ f"mm_projector.linear_2.{k.split('.')[-1]}"
221
+ if re.match(r"^model\.mm_projector\.2", k)
222
+ else (
223
+ f"language_model.model.{k}"
224
+ if re.match(r"^lm_head", k)
225
+ else (
226
+ f"language_model.{k}"
227
+ if re.match(r"^model\.(embed_tokens|norm|layers)", k)
228
+ else k
229
+ )
230
+ )
231
+ )
232
+ )
233
+ ): v
234
+ for k, v in weights.items()
235
+ }
236
+
237
+ weights = {
238
+ (
239
+ f"vision_tower.vision_tower.vision_model.head.attention.in_proj.bias"
240
+ if re.match(
241
+ r"^vision_tower\.vision_tower\.vision_model\.head\.attention\.in_proj_bias",
242
+ k,
243
+ )
244
+ else (
245
+ f"vision_tower.vision_tower.vision_model.head.attention.in_proj.weight"
246
+ if re.match(
247
+ r"^vision_tower\.vision_tower\.vision_model\.head\.attention\.in_proj_weight",
248
+ k,
249
+ )
250
+ else k
251
+ )
252
+ ): v
253
+ for k, v in weights.items()
254
+ }
255
+
256
+ return weights