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,591 @@
1
+ import inspect
2
+ import math
3
+ from collections import OrderedDict
4
+ from dataclasses import dataclass, field
5
+ from typing import List, Optional, Tuple, Union
6
+
7
+ import mlx.core as mx
8
+ import mlx.nn as nn
9
+
10
+
11
+ @dataclass
12
+ class VisionConfig:
13
+ """Configuration class for Florence2 Vision model (DaViT)."""
14
+
15
+ model_type: str = "davit"
16
+ in_chans: int = 3
17
+ num_classes: int = 1000
18
+ depths: List[int] = field(default_factory=lambda: [1, 1, 9, 1])
19
+ dim_embed: List[int] = field(default_factory=lambda: [128, 256, 512, 1024])
20
+ num_heads: List[int] = field(default_factory=lambda: [4, 8, 16, 32])
21
+ num_groups: List[int] = field(default_factory=lambda: [4, 8, 16, 32])
22
+ window_size: int = 12
23
+ mlp_ratio: float = 4.0
24
+ drop_path_rate: float = 0.1
25
+ patch_size: List[int] = field(default_factory=lambda: [7, 3, 3, 3])
26
+ patch_stride: List[int] = field(default_factory=lambda: [4, 2, 2, 2])
27
+ patch_padding: List[int] = field(default_factory=lambda: [3, 1, 1, 1])
28
+ patch_prenorm: List[bool] = field(
29
+ default_factory=lambda: [False, False, False, False]
30
+ )
31
+ qkv_bias: bool = True
32
+ conv_at_attn: bool = True
33
+ conv_at_ffn: bool = True
34
+ hidden_size: int = 768
35
+ image_size: Tuple[int, int] = (768, 768)
36
+
37
+ @classmethod
38
+ def from_dict(cls, params):
39
+ return cls(
40
+ **{
41
+ k: v
42
+ for k, v in params.items()
43
+ if k in inspect.signature(cls).parameters
44
+ }
45
+ )
46
+
47
+
48
+ def check_array_shape(arr):
49
+ shape = arr.shape
50
+
51
+ # Check if the shape has 4 dimensions
52
+ if len(shape) != 4:
53
+ return False
54
+
55
+ out_channels, kH, KW, _ = shape
56
+
57
+ # Check if out_channels is the largest, and kH and KW are the same
58
+ if (out_channels >= kH) and (out_channels >= KW) and (kH == KW):
59
+ return True
60
+ else:
61
+ return False
62
+
63
+
64
+ class MlpFC(nn.Module):
65
+ """MLP FC module"""
66
+
67
+ def __init__(
68
+ self,
69
+ in_features: int,
70
+ hidden_features: Optional[int] = None,
71
+ out_features: Optional[int] = None,
72
+ ):
73
+ super().__init__()
74
+ self.fc1 = nn.Linear(in_features, hidden_features)
75
+ self.fc2 = nn.Linear(hidden_features, out_features)
76
+ self.gelu = nn.GELU()
77
+
78
+ def __call__(self, x):
79
+ return self.fc2(self.gelu(self.fc1(x)))
80
+
81
+
82
+ class Mlp(nn.Module):
83
+ """MLP module"""
84
+
85
+ def __init__(
86
+ self,
87
+ in_features: int,
88
+ hidden_features: Optional[int] = None,
89
+ out_features: Optional[int] = None,
90
+ ):
91
+ super().__init__()
92
+ out_features = out_features or in_features
93
+ hidden_features = hidden_features or in_features
94
+
95
+ self.net = MlpFC(in_features, hidden_features, out_features)
96
+
97
+ def __call__(self, x, size):
98
+ return self.net(x), size
99
+
100
+
101
+ class DepthWiseConv2d(nn.Module):
102
+ """Depthwise Convolution"""
103
+
104
+ def __init__(
105
+ self,
106
+ dim_in: int,
107
+ kernel_size: int,
108
+ padding: int,
109
+ stride: int,
110
+ bias: bool = True,
111
+ ):
112
+ super().__init__()
113
+
114
+ self.dw = nn.Conv2d(
115
+ dim_in,
116
+ dim_in,
117
+ kernel_size=kernel_size,
118
+ padding=padding,
119
+ stride=stride,
120
+ bias=bias,
121
+ groups=dim_in,
122
+ )
123
+
124
+ def __call__(self, x, size):
125
+ B, N, C = x.shape
126
+ H, W = size
127
+ assert N == H * W
128
+
129
+ x = self.dw(x.reshape(B, H, W, C))
130
+
131
+ x = x.transpose(0, 3, 1, 2)
132
+
133
+ size = (x.shape[-2], x.shape[-1])
134
+ x = x.flatten(2).transpose(0, 2, 1)
135
+ return x, size
136
+
137
+
138
+ class ConvEmbed(nn.Module):
139
+ """Image to Patch Embedding"""
140
+
141
+ def __init__(
142
+ self,
143
+ patch_size: int = 7,
144
+ in_chans: int = 3,
145
+ embed_dim: int = 64,
146
+ stride: int = 4,
147
+ padding: int = 2,
148
+ norm_layer: Optional[nn.Module] = None,
149
+ pre_norm: bool = True,
150
+ ):
151
+ super().__init__()
152
+ self.proj = nn.Conv2d(
153
+ in_chans, embed_dim, kernel_size=patch_size, stride=stride, padding=padding
154
+ )
155
+
156
+ if norm_layer and pre_norm:
157
+ self.norm = norm_layer(in_chans)
158
+ elif norm_layer:
159
+ self.norm = norm_layer(embed_dim)
160
+ else:
161
+ self.norm = None
162
+
163
+ self.pre_norm = pre_norm
164
+
165
+ def __call__(self, x, size):
166
+ H, W = size
167
+ if len(x.shape) == 3:
168
+
169
+ if self.norm and self.pre_norm:
170
+ x = self.norm(x)
171
+
172
+ x = x.reshape(-1, H, W, x.shape[-1])
173
+ else:
174
+ x = x.transpose(0, 2, 3, 1)
175
+
176
+ x = self.proj(x)
177
+
178
+ B, H, W, C = x.shape
179
+
180
+ x = x.reshape(B, H * W, C)
181
+
182
+ if self.norm and not self.pre_norm:
183
+ x = self.norm(x)
184
+
185
+ return x, (H, W)
186
+
187
+
188
+ class ChannelAttention(nn.Module):
189
+ """Channel Attention module"""
190
+
191
+ def __init__(self, dim: int, groups: int = 8, qkv_bias: bool = True):
192
+ super().__init__()
193
+ self.groups = groups
194
+ self.qkv = nn.Linear(dim, dim * 3, bias=qkv_bias)
195
+ self.proj = nn.Linear(dim, dim)
196
+
197
+ def __call__(self, x, size):
198
+ B, N, C = x.shape
199
+
200
+ qkv = self.qkv(x).reshape(B, N, 3, self.groups, C // self.groups)
201
+ qkv = qkv.transpose(2, 0, 3, 1, 4)
202
+ q, k, v = qkv[0], qkv[1], qkv[2] # Each has shape (B, groups, N, C//groups)
203
+
204
+ q = q * (float(N) ** -0.5)
205
+
206
+ # For multi-head attention, we need to keep the groups dimension
207
+ attention = mx.matmul(q.transpose(0, 1, 3, 2), k) # (B, groups, N, N)
208
+ attention = mx.softmax(attention, axis=-1)
209
+
210
+ x = mx.matmul(attention, v.transpose(0, 1, 3, 2)).transpose(
211
+ 0, 1, 3, 2
212
+ ) # (B, groups, N, C//groups)
213
+ x = x.transpose(0, 2, 1, 3).reshape(B, N, C)
214
+ x = self.proj(x)
215
+
216
+ return x, size
217
+
218
+
219
+ def window_partition(x: mx.array, window_size: int):
220
+ """Partition into non-overlapping windows"""
221
+ B, H, W, C = x.shape
222
+ x = mx.reshape(
223
+ x, (B, H // window_size, window_size, W // window_size, window_size, C)
224
+ )
225
+ windows = mx.reshape(
226
+ mx.transpose(x, (0, 1, 3, 2, 4, 5)), (-1, window_size, window_size, C)
227
+ )
228
+ return windows
229
+
230
+
231
+ def window_reverse(
232
+ windows: mx.array, batch_size: int, window_size: int, H: int, W: int
233
+ ):
234
+ """Merge windows back to feature map"""
235
+ B = batch_size
236
+ x = mx.reshape(
237
+ windows, (B, H // window_size, W // window_size, window_size, window_size, -1)
238
+ )
239
+ x = mx.reshape(mx.transpose(x, (0, 1, 3, 2, 4, 5)), (B, H, W, -1))
240
+ return x
241
+
242
+
243
+ class WindowAttention(nn.Module):
244
+ """Window based multi-head self attention module"""
245
+
246
+ def __init__(
247
+ self, dim: int, num_heads: int, window_size: int, qkv_bias: bool = True
248
+ ):
249
+ super().__init__()
250
+ self.dim = dim
251
+ self.window_size = window_size
252
+ self.num_heads = num_heads
253
+ head_dim = dim // num_heads
254
+ self.scale = float(head_dim) ** -0.5
255
+
256
+ self.qkv = nn.Linear(dim, dim * 3, bias=qkv_bias)
257
+ self.proj = nn.Linear(dim, dim)
258
+
259
+ def __call__(self, x, size):
260
+ H, W = size
261
+ B, L, C = x.shape
262
+
263
+ assert L == H * W, f"input feature has wrong size {L} == {H * W}"
264
+
265
+ x = mx.reshape(x, (B, H, W, C))
266
+
267
+ # Calculate padding
268
+ pad_l = pad_t = 0
269
+ pad_r = (self.window_size - W % self.window_size) % self.window_size
270
+ pad_b = (self.window_size - H % self.window_size) % self.window_size
271
+
272
+ # MLX padding
273
+ x = mx.pad(x, [(0, 0), (pad_t, pad_b), (pad_l, pad_r), (0, 0)])
274
+
275
+ _, Hp, Wp, _ = x.shape
276
+
277
+ # Window partition
278
+ x = window_partition(x, self.window_size)
279
+ x = mx.reshape(x, (-1, self.window_size * self.window_size, C))
280
+
281
+ # Multi-head self attention
282
+ B_, N, C = x.shape
283
+ qkv = mx.reshape(self.qkv(x), (B_, N, 3, self.num_heads, C // self.num_heads))
284
+ qkv = mx.transpose(qkv, (2, 0, 3, 1, 4))
285
+ q, k, v = qkv[0], qkv[1], qkv[2]
286
+
287
+ # Scaled dot-product attention
288
+ q = q * self.scale
289
+ attn = mx.matmul(q, mx.transpose(k, (0, 1, 3, 2)))
290
+ attn = mx.softmax(attn, axis=-1)
291
+
292
+ x = mx.reshape(mx.transpose(mx.matmul(attn, v), (0, 2, 1, 3)), (B_, N, C))
293
+ x = self.proj(x)
294
+
295
+ # Merge windows
296
+ x = mx.reshape(x, (-1, self.window_size, self.window_size, C))
297
+ x = window_reverse(x, B, self.window_size, Hp, Wp)
298
+
299
+ if pad_r > 0 or pad_b > 0:
300
+ x = x[:, :H, :W, :]
301
+
302
+ x = mx.reshape(x, (B, H * W, C))
303
+ return x, size
304
+
305
+
306
+ class PreNorm(nn.Module):
307
+ """Pre-normalization module"""
308
+
309
+ def __init__(self, norm, fn, drop_path=None):
310
+ super().__init__()
311
+ self.norm = norm
312
+ self.fn = fn
313
+ self.drop_path = drop_path
314
+
315
+ def __call__(self, x, size):
316
+ shortcut = x
317
+ if self.norm is not None:
318
+ x = self.norm(x)
319
+ x, size = self.fn(x, size)
320
+
321
+ if self.drop_path is not None:
322
+ x = self.drop_path(x)
323
+
324
+ x = shortcut + x
325
+ return x, size
326
+
327
+
328
+ class DropPath(nn.Module):
329
+ """Drop paths (Stochastic Depth) per sample."""
330
+
331
+ def __init__(self, drop_prob: float = 0.0):
332
+ super().__init__()
333
+ self.drop_prob = drop_prob
334
+
335
+ def __call__(self, x):
336
+ if self.drop_prob == 0.0 or not self.training:
337
+ return x
338
+
339
+ keep_prob = 1 - self.drop_prob
340
+ shape = (x.shape[0],) + (1,) * (x.ndim - 1)
341
+ random_tensor = keep_prob + mx.random.uniform(shape)
342
+ random_tensor = mx.floor(random_tensor)
343
+ output = x * random_tensor / keep_prob
344
+ return output
345
+
346
+
347
+ class SpatialBlock(nn.Module):
348
+ """Spatial attention block"""
349
+
350
+ def __init__(
351
+ self,
352
+ dim: int,
353
+ num_heads: int,
354
+ window_size: int,
355
+ mlp_ratio: float = 4.0,
356
+ qkv_bias: bool = True,
357
+ drop_path_rate: float = 0.0,
358
+ conv_at_attn: bool = True,
359
+ conv_at_ffn: bool = True,
360
+ ):
361
+ super().__init__()
362
+
363
+ drop_path = DropPath(drop_path_rate) if drop_path_rate > 0.0 else None
364
+
365
+ self.conv1 = (
366
+ PreNorm(None, DepthWiseConv2d(dim, 3, 1, 1), None) if conv_at_attn else None
367
+ )
368
+
369
+ self.window_attn = PreNorm(
370
+ nn.LayerNorm(dim),
371
+ WindowAttention(dim, num_heads, window_size, qkv_bias=qkv_bias),
372
+ drop_path,
373
+ )
374
+
375
+ self.conv2 = (
376
+ PreNorm(None, DepthWiseConv2d(dim, 3, 1, 1), None) if conv_at_ffn else None
377
+ )
378
+
379
+ self.ffn = PreNorm(
380
+ nn.LayerNorm(dim),
381
+ Mlp(
382
+ in_features=dim, hidden_features=int(dim * mlp_ratio), out_features=dim
383
+ ),
384
+ drop_path,
385
+ )
386
+
387
+ def __call__(self, x, size):
388
+ if self.conv1 is not None:
389
+ x, size = self.conv1(x, size)
390
+ x, size = self.window_attn(x, size)
391
+
392
+ if self.conv2 is not None:
393
+ x, size = self.conv2(x, size)
394
+ x, size = self.ffn(x, size)
395
+ return x, size
396
+
397
+
398
+ class ChannelBlock(nn.Module):
399
+ """Channel attention block"""
400
+
401
+ def __init__(
402
+ self,
403
+ dim: int,
404
+ groups: int,
405
+ mlp_ratio: float = 4.0,
406
+ qkv_bias: bool = True,
407
+ drop_path_rate: float = 0.0,
408
+ conv_at_attn: bool = True,
409
+ conv_at_ffn: bool = True,
410
+ ):
411
+ super().__init__()
412
+
413
+ drop_path = DropPath(drop_path_rate) if drop_path_rate > 0.0 else None
414
+
415
+ self.conv1 = (
416
+ PreNorm(None, DepthWiseConv2d(dim, 3, 1, 1), None) if conv_at_attn else None
417
+ )
418
+
419
+ self.channel_attn = PreNorm(
420
+ nn.LayerNorm(dim),
421
+ ChannelAttention(dim, groups=groups, qkv_bias=qkv_bias),
422
+ drop_path,
423
+ )
424
+
425
+ self.conv2 = (
426
+ PreNorm(None, DepthWiseConv2d(dim, 3, 1, 1), None) if conv_at_ffn else None
427
+ )
428
+
429
+ self.ffn = PreNorm(
430
+ nn.LayerNorm(dim),
431
+ Mlp(
432
+ in_features=dim, hidden_features=int(dim * mlp_ratio), out_features=dim
433
+ ),
434
+ drop_path,
435
+ )
436
+
437
+ def __call__(self, x, size):
438
+ if self.conv1 is not None:
439
+ x, size = self.conv1(x, size)
440
+ x, size = self.channel_attn(x, size)
441
+
442
+ if self.conv2 is not None:
443
+ x, size = self.conv2(x, size)
444
+ x, size = self.ffn(x, size)
445
+
446
+ return x, size
447
+
448
+
449
+ class Block(nn.Module):
450
+ def __init__(
451
+ self,
452
+ dim: int,
453
+ num_heads: int,
454
+ num_groups: int,
455
+ window_size: int,
456
+ mlp_ratio: float = 4.0,
457
+ qkv_bias: bool = True,
458
+ drop_path_rate: Tuple[float, float] = (0.0, 0.0),
459
+ conv_at_attn: bool = True,
460
+ conv_at_ffn: bool = True,
461
+ ):
462
+ super().__init__()
463
+ self.spatial_block = SpatialBlock(
464
+ dim,
465
+ num_heads,
466
+ window_size,
467
+ drop_path_rate=drop_path_rate[0],
468
+ qkv_bias=qkv_bias,
469
+ mlp_ratio=mlp_ratio,
470
+ conv_at_attn=conv_at_attn,
471
+ conv_at_ffn=conv_at_ffn,
472
+ )
473
+ self.channel_block = ChannelBlock(
474
+ dim,
475
+ num_groups,
476
+ drop_path_rate=drop_path_rate[1],
477
+ qkv_bias=qkv_bias,
478
+ mlp_ratio=mlp_ratio,
479
+ conv_at_attn=conv_at_attn,
480
+ conv_at_ffn=conv_at_ffn,
481
+ )
482
+
483
+ def __call__(self, x, size):
484
+ x, size = self.spatial_block(x, size)
485
+ x, size = self.channel_block(x, size)
486
+ return x, size
487
+
488
+
489
+ class VisionModel(nn.Module):
490
+ """DaViT: Dual Attention Vision Transformer"""
491
+
492
+ def __init__(self, config: VisionConfig):
493
+ super().__init__()
494
+
495
+ self.num_classes = config.num_classes
496
+ self.model_type = config.model_type
497
+ self.dim_embed = config.dim_embed
498
+ self.num_heads = config.num_heads
499
+ self.num_groups = config.num_groups
500
+ self.num_stages = len(self.dim_embed)
501
+ assert self.num_stages == len(self.num_heads) == len(self.num_groups)
502
+
503
+ if self.model_type not in ["davit", ""]:
504
+ raise ValueError(
505
+ f"Model type {self.model_type} not supported. Currently only 'davit' is supported"
506
+ )
507
+
508
+ # Convert PyTorch's linspace to MLX equivalent
509
+ total_blocks = sum(config.depths) * 2
510
+ dpr = [
511
+ i * config.drop_path_rate / (total_blocks - 1) for i in range(total_blocks)
512
+ ]
513
+
514
+ depth_offset = 0
515
+ self.convs = []
516
+ self.blocks = []
517
+
518
+ for i in range(self.num_stages):
519
+
520
+ conv_embed = ConvEmbed(
521
+ patch_size=config.patch_size[i],
522
+ stride=config.patch_stride[i],
523
+ padding=config.patch_padding[i],
524
+ in_chans=config.in_chans if i == 0 else self.dim_embed[i - 1],
525
+ embed_dim=self.dim_embed[i],
526
+ norm_layer=nn.LayerNorm,
527
+ pre_norm=config.patch_prenorm[i],
528
+ )
529
+ self.convs.append(conv_embed)
530
+
531
+ block = []
532
+ for j in range(config.depths[i]):
533
+ block.append(
534
+ Block(
535
+ self.dim_embed[i],
536
+ config.num_heads[i],
537
+ config.num_groups[i],
538
+ config.window_size,
539
+ config.mlp_ratio,
540
+ config.qkv_bias,
541
+ (dpr[depth_offset + j * 2], dpr[depth_offset + j * 2 + 1]),
542
+ config.conv_at_attn,
543
+ config.conv_at_ffn,
544
+ )
545
+ )
546
+
547
+ self.blocks.append(block)
548
+
549
+ depth_offset += config.depths[i] * 2
550
+
551
+ def __call__(self, x):
552
+ input_size = x.shape[2:]
553
+
554
+ # Process through stages
555
+ for conv, blks in zip(self.convs, self.blocks):
556
+ x, input_size = conv(x, input_size)
557
+ for blk in blks:
558
+ x, input_size = blk(x, input_size)
559
+
560
+ return x
561
+
562
+ @staticmethod
563
+ def sanitize(weights):
564
+ sanitized_weights = {}
565
+ for k, v in weights.items():
566
+ if "position_ids" in k:
567
+ # Remove unused position_ids
568
+ continue
569
+ elif "convs" in k:
570
+ if "proj.weight" in k:
571
+ # PyTorch conv2d weight tensors have shape:
572
+ # [out_channels, in_channels, kH, KW]
573
+ # MLX conv2d expects the weight be of shape:
574
+ # [out_channels, kH, KW, in_channels]
575
+ if check_array_shape(v):
576
+ sanitized_weights[k] = v
577
+ else:
578
+ sanitized_weights[k] = v.transpose(0, 2, 3, 1)
579
+ else:
580
+ sanitized_weights[k] = v
581
+ elif "blocks" in k:
582
+ if "dw.weight" in k:
583
+ sanitized_weights[k] = (
584
+ v.transpose(0, 2, 3, 1) if v.shape[1] < v.shape[-1] else v
585
+ )
586
+ else:
587
+ sanitized_weights[k] = v
588
+ else:
589
+ sanitized_weights[k] = v
590
+
591
+ return sanitized_weights
@@ -0,0 +1,8 @@
1
+ from .gemma3 import (
2
+ LanguageModel,
3
+ Model,
4
+ ModelConfig,
5
+ TextConfig,
6
+ VisionConfig,
7
+ VisionModel,
8
+ )