nexaai 1.0.19rc5__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 (221) 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-1.0.19rc5.dist-info → nexaai-1.0.19rc7.dist-info}/METADATA +1 -1
  219. {nexaai-1.0.19rc5.dist-info → nexaai-1.0.19rc7.dist-info}/RECORD +221 -21
  220. {nexaai-1.0.19rc5.dist-info → nexaai-1.0.19rc7.dist-info}/WHEEL +0 -0
  221. {nexaai-1.0.19rc5.dist-info → nexaai-1.0.19rc7.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,213 @@
1
+ import glob
2
+ import inspect
3
+ import json
4
+ from dataclasses import dataclass
5
+ from pathlib import Path
6
+ from typing import List, Optional
7
+
8
+ import mlx.core as mx
9
+ import mlx.nn as nn
10
+ import numpy as np
11
+ from huggingface_hub import snapshot_download
12
+
13
+ from .language import LanguageModel, RMSNorm, TextConfig
14
+ from .vision import VisionConfig, VisionModel
15
+
16
+
17
+ @dataclass
18
+ class ModelConfig:
19
+ text_config: TextConfig
20
+ vision_config: VisionConfig
21
+ model_type: str
22
+ vocab_size: int = 257152
23
+ ignore_index: int = -100
24
+ image_token_index: int = 262144
25
+ hidden_size: int = 2048
26
+ pad_token_id: int = 0
27
+ eos_token_id: Optional[List[int]] = None
28
+
29
+ @classmethod
30
+ def from_dict(cls, params):
31
+ return cls(
32
+ **{
33
+ k: v
34
+ for k, v in params.items()
35
+ if k in inspect.signature(cls).parameters
36
+ }
37
+ )
38
+
39
+
40
+ class Gemma3MultiModalProjector(nn.Module):
41
+ def __init__(self, config: ModelConfig):
42
+ super().__init__()
43
+ self.mm_input_projection_weight = mx.ones(
44
+ (config.vision_config.hidden_size, config.text_config.hidden_size)
45
+ )
46
+
47
+ self.mm_soft_emb_norm = RMSNorm(
48
+ config.vision_config.hidden_size, eps=config.vision_config.layer_norm_eps
49
+ )
50
+ self.patches_per_image = int(
51
+ config.vision_config.image_size // config.vision_config.patch_size
52
+ )
53
+ self.tokens_per_side = int(config.text_config.mm_tokens_per_image**0.5)
54
+ self.kernel_size = self.patches_per_image // self.tokens_per_side
55
+ self.avg_pool = nn.AvgPool2d(
56
+ kernel_size=self.kernel_size, stride=self.kernel_size
57
+ )
58
+
59
+ def __call__(self, x: mx.array) -> mx.array:
60
+ b, _, l = x.shape
61
+
62
+ reshaped_vision_outputs = x.transpose(0, 2, 1)
63
+ reshaped_vision_outputs = reshaped_vision_outputs.reshape(
64
+ b, l, self.patches_per_image, self.patches_per_image
65
+ )
66
+
67
+ # Transpose to place h, w in indices 1, 2
68
+ reshaped_vision_outputs = reshaped_vision_outputs.transpose(0, 2, 3, 1)
69
+ pooled_vision_outputs = self.avg_pool(reshaped_vision_outputs)
70
+ pooled_vision_outputs = pooled_vision_outputs.transpose(0, 3, 1, 2).flatten(2)
71
+ pooled_vision_outputs = pooled_vision_outputs.transpose(0, 2, 1)
72
+
73
+ normed_vision_outputs = self.mm_soft_emb_norm(pooled_vision_outputs)
74
+
75
+ projected_vision_outputs = mx.einsum(
76
+ "btm,md->btd", normed_vision_outputs, self.mm_input_projection_weight
77
+ )
78
+ return projected_vision_outputs.astype(x.dtype)
79
+
80
+
81
+ def masked_scatter(
82
+ final_embedding: mx.array,
83
+ image_mask_expanded: mx.array,
84
+ scaled_image_features: mx.array,
85
+ ):
86
+ # Reshape the tensors to 1D
87
+ final_embedding_shape = final_embedding.shape
88
+ scaled_image_features_flattened = mx.flatten(scaled_image_features)
89
+ final_embedding_flattened = mx.flatten(final_embedding)
90
+ image_mask_expanded_flattened = mx.flatten(image_mask_expanded)
91
+
92
+ # Scatter the scaled image features into the special image token positions
93
+ image_positions = mx.array(np.where(image_mask_expanded_flattened)[0], mx.uint32)
94
+ final_embedding_flattened[image_positions] = scaled_image_features_flattened
95
+
96
+ # Reshape back to the original shape
97
+ final_embedding = mx.reshape(final_embedding_flattened, final_embedding_shape)
98
+
99
+ return final_embedding
100
+
101
+
102
+ class Model(nn.Module):
103
+ def __init__(self, config: ModelConfig):
104
+ super().__init__()
105
+ self.model_type = config.model_type
106
+ self.config = config
107
+
108
+ self.vision_tower = VisionModel(config.vision_config)
109
+ self.language_model = LanguageModel(config.text_config)
110
+ self.multi_modal_projector = Gemma3MultiModalProjector(config)
111
+
112
+ def get_input_embeddings(
113
+ self,
114
+ input_ids: Optional[mx.array] = None,
115
+ pixel_values: Optional[mx.array] = None,
116
+ mask: Optional[mx.array] = None,
117
+ ):
118
+ if pixel_values is None:
119
+ return self.language_model.model.embed_tokens(input_ids), None
120
+
121
+ inputs_embeds = self.language_model.model.embed_tokens(input_ids)
122
+
123
+ hidden_state, _, _ = self.vision_tower(
124
+ pixel_values.transpose(0, 2, 3, 1).astype(inputs_embeds.dtype),
125
+ output_hidden_states=True,
126
+ )
127
+
128
+ image_features = self.multi_modal_projector(hidden_state)
129
+
130
+ final_inputs_embeds, final_attention_mask_4d = (
131
+ self.prepare_inputs_for_multimodal(
132
+ self.config.hidden_size,
133
+ self.config.pad_token_id,
134
+ self.config.image_token_index,
135
+ image_features,
136
+ inputs_embeds,
137
+ input_ids,
138
+ mask,
139
+ )
140
+ )
141
+ return final_inputs_embeds, final_attention_mask_4d
142
+
143
+ @staticmethod
144
+ def prepare_inputs_for_multimodal(
145
+ hidden_size,
146
+ pad_token_id,
147
+ image_token_index,
148
+ image_features,
149
+ inputs_embeds,
150
+ input_ids,
151
+ attention_mask,
152
+ ):
153
+ _, _, embed_dim = image_features.shape
154
+
155
+ batch_size, sequence_length = input_ids.shape
156
+ scaled_image_features = image_features / (hidden_size**0.5)
157
+ final_embedding = mx.zeros((batch_size, sequence_length, embed_dim))
158
+
159
+ pad_token_id = pad_token_id
160
+ pad_token_id = pad_token_id if pad_token_id is not None else 0
161
+ text_mask = (input_ids != image_token_index) & (input_ids != pad_token_id)
162
+ image_mask = input_ids == image_token_index
163
+ pad_mask = input_ids == pad_token_id
164
+
165
+ # expand masks to match embedding dimension
166
+ text_mask_expanded = mx.expand_dims(text_mask, -1)
167
+ text_mask_expanded = mx.repeat(text_mask_expanded, embed_dim, axis=-1)
168
+ pad_mask_expanded = mx.expand_dims(pad_mask, -1)
169
+ pad_mask_expanded = mx.repeat(pad_mask_expanded, embed_dim, axis=-1)
170
+ image_mask_expanded = mx.expand_dims(image_mask, -1)
171
+ image_mask_expanded = mx.repeat(image_mask_expanded, embed_dim, axis=-1)
172
+
173
+ # insert padding and text token embeddings
174
+ final_embedding = mx.where(text_mask_expanded, inputs_embeds, final_embedding)
175
+ final_embedding = mx.where(
176
+ pad_mask_expanded, mx.zeros_like(final_embedding), final_embedding
177
+ )
178
+
179
+ # insert image token embeddings
180
+ final_embedding = masked_scatter(
181
+ final_embedding, image_mask_expanded, scaled_image_features
182
+ )
183
+
184
+ attention_mask_expanded_1 = mx.expand_dims(attention_mask, 1)
185
+ attention_mask_expanded_2 = mx.expand_dims(attention_mask, 2)
186
+ final_attention_mask_4d = attention_mask_expanded_1 * attention_mask_expanded_2
187
+ final_attention_mask_4d = final_attention_mask_4d
188
+ final_attention_mask_4d = mx.expand_dims(final_attention_mask_4d, 1)
189
+ final_embedding = mx.array(final_embedding)
190
+ return final_embedding.astype(inputs_embeds.dtype), final_attention_mask_4d
191
+
192
+ @property
193
+ def layers(self):
194
+ return self.language_model.model.layers
195
+
196
+ def __call__(
197
+ self,
198
+ input_ids: mx.array,
199
+ pixel_values: mx.array,
200
+ mask: Optional[mx.array] = None,
201
+ cache: Optional[mx.array] = None,
202
+ **kwargs,
203
+ ):
204
+ input_embeddings, final_attention_mask_4d = self.get_input_embeddings(
205
+ input_ids, pixel_values, mask
206
+ )
207
+
208
+ logits = self.language_model(
209
+ inputs=input_ids,
210
+ cache=cache,
211
+ inputs_embeds=input_embeddings,
212
+ )
213
+ return logits
@@ -0,0 +1,315 @@
1
+ import inspect
2
+ from dataclasses import dataclass
3
+ from functools import partial
4
+ from typing import Any, Dict, List, Optional, Union
5
+
6
+ import mlx.core as mx
7
+ import mlx.nn as nn
8
+
9
+ from ..base import (
10
+ LanguageModelOutput,
11
+ create_attention_mask,
12
+ scaled_dot_product_attention,
13
+ )
14
+ from ..cache import KVCache, RotatingKVCache
15
+
16
+
17
+ @dataclass
18
+ class TextConfig:
19
+ model_type: str
20
+ hidden_size: int
21
+ num_hidden_layers: int
22
+ intermediate_size: int
23
+ num_attention_heads: int = 8
24
+ head_dim: int = 256
25
+ rms_norm_eps: float = 1.0e-6
26
+ vocab_size: int = 262208
27
+ num_key_value_heads: int = 4
28
+ rope_global_base_freq: float = 1_000_000.0
29
+ rope_local_base_freq: float = 10_000.0
30
+ rope_traditional: bool = False
31
+ query_pre_attn_scalar: float = 256
32
+ sliding_window: int = 1024
33
+ rope_scaling: Optional[Dict[str, Union[float, List[float]]]] = None
34
+ mm_tokens_per_image: int = 256
35
+ sliding_window_pattern: int = 6
36
+ max_position_embeddings: int = 4096
37
+
38
+ @classmethod
39
+ def from_dict(cls, params):
40
+ return cls(
41
+ **{
42
+ k: v
43
+ for k, v in params.items()
44
+ if k in inspect.signature(cls).parameters
45
+ }
46
+ )
47
+
48
+
49
+ class RMSNorm(nn.Module):
50
+ def __init__(self, dims: int, eps: float = 1e-5):
51
+ super().__init__()
52
+ self.weight = mx.ones((dims,))
53
+ self.eps = eps
54
+
55
+ def __call__(self, x):
56
+ return mx.fast.rms_norm(x, 1.0 + self.weight, self.eps)
57
+
58
+
59
+ class Attention(nn.Module):
60
+ def __init__(self, config: TextConfig, layer_idx: int):
61
+ super().__init__()
62
+
63
+ dim = config.hidden_size
64
+ self.n_heads = n_heads = config.num_attention_heads
65
+ self.n_kv_heads = n_kv_heads = config.num_key_value_heads
66
+ self.repeats = n_heads // n_kv_heads
67
+ self.head_dim = head_dim = config.head_dim
68
+ self.layer_idx = layer_idx
69
+
70
+ self.scale = config.query_pre_attn_scalar**-0.5
71
+
72
+ self.q_proj = nn.Linear(dim, n_heads * head_dim, bias=False)
73
+ self.k_proj = nn.Linear(dim, n_kv_heads * head_dim, bias=False)
74
+ self.v_proj = nn.Linear(dim, n_kv_heads * head_dim, bias=False)
75
+ self.o_proj = nn.Linear(n_heads * head_dim, dim, bias=False)
76
+
77
+ self.q_norm = RMSNorm(dims=head_dim, eps=config.rms_norm_eps)
78
+ self.k_norm = RMSNorm(dims=head_dim, eps=config.rms_norm_eps)
79
+ self.is_sliding = (layer_idx + 1) % config.sliding_window_pattern != 0
80
+
81
+ self.rope = nn.RoPE(
82
+ head_dim,
83
+ traditional=config.rope_traditional,
84
+ base=(
85
+ config.rope_local_base_freq
86
+ if self.is_sliding
87
+ else config.rope_global_base_freq
88
+ ),
89
+ )
90
+
91
+ def __call__(
92
+ self,
93
+ x: mx.array,
94
+ mask: Optional[mx.array] = None,
95
+ cache: Optional[Any] = None,
96
+ ) -> mx.array:
97
+ B, L, _ = x.shape
98
+ queries, keys, values = self.q_proj(x), self.k_proj(x), self.v_proj(x)
99
+ queries = queries.reshape(B, L, self.n_heads, -1).transpose(0, 2, 1, 3)
100
+
101
+ keys = keys.reshape(B, L, self.n_kv_heads, -1).transpose(0, 2, 1, 3)
102
+ values = values.reshape(B, L, self.n_kv_heads, -1).transpose(0, 2, 1, 3)
103
+
104
+ queries = self.q_norm(queries)
105
+ keys = self.k_norm(keys)
106
+
107
+ if cache is not None:
108
+ queries = self.rope(queries, offset=cache.offset)
109
+ keys = self.rope(keys, offset=cache.offset)
110
+ keys, values = cache.update_and_fetch(keys, values)
111
+ else:
112
+ queries = self.rope(queries)
113
+ keys = self.rope(keys)
114
+
115
+ # Sliding window
116
+ if mask is not None and isinstance(mask, mx.array):
117
+ if mask.shape[-1] != keys.shape[-2]:
118
+ mask = mask[..., -keys.shape[-2] :]
119
+
120
+ output = scaled_dot_product_attention(
121
+ queries, keys, values, cache, scale=self.scale, mask=mask
122
+ )
123
+ output = output.transpose(0, 2, 1, 3).reshape(B, L, -1)
124
+ return self.o_proj(output)
125
+
126
+
127
+ class MLP(nn.Module):
128
+ def __init__(self, dim, hidden_dim):
129
+ super().__init__()
130
+ self.gate_proj = nn.Linear(dim, hidden_dim, bias=False)
131
+ self.down_proj = nn.Linear(hidden_dim, dim, bias=False)
132
+ self.up_proj = nn.Linear(dim, hidden_dim, bias=False)
133
+
134
+ def __call__(self, x) -> mx.array:
135
+ # This should not be GELU approx, jax.nn.gelu
136
+ return self.down_proj(nn.gelu_approx(self.gate_proj(x)) * self.up_proj(x))
137
+
138
+
139
+ @partial(mx.compile, shapeless=True)
140
+ def clip_residual(x, y=None):
141
+ bound = mx.finfo(mx.float16).max
142
+ if y is None:
143
+ if x.dtype == mx.float16:
144
+ return mx.clip(x.astype(mx.float32), -bound, bound).astype(mx.float16)
145
+ else:
146
+ return x
147
+
148
+ if x.dtype != mx.float16:
149
+ return x + y
150
+
151
+ return mx.clip(x.astype(mx.float32) + y.astype(mx.float32), -bound, bound).astype(
152
+ mx.float16
153
+ )
154
+
155
+
156
+ class TransformerBlock(nn.Module):
157
+ def __init__(self, config: TextConfig, layer_idx: int):
158
+ super().__init__()
159
+ self.num_attention_heads = config.num_attention_heads
160
+ self.hidden_size = config.hidden_size
161
+ self.self_attn = Attention(config, layer_idx)
162
+ self.mlp = MLP(config.hidden_size, config.intermediate_size)
163
+ self.input_layernorm = RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
164
+ self.post_attention_layernorm = RMSNorm(
165
+ config.hidden_size, eps=config.rms_norm_eps
166
+ )
167
+ self.pre_feedforward_layernorm = RMSNorm(
168
+ config.hidden_size, eps=config.rms_norm_eps
169
+ )
170
+ self.post_feedforward_layernorm = RMSNorm(
171
+ config.hidden_size, eps=config.rms_norm_eps
172
+ )
173
+
174
+ def __call__(
175
+ self,
176
+ x: mx.array,
177
+ mask: Optional[mx.array] = None,
178
+ cache: Optional[Any] = None,
179
+ ) -> mx.array:
180
+
181
+ # Clip the input to avoid overflow in float16
182
+ # Float16 has a max value of 65504. When values exceed this limit, they become inf.
183
+ # Example: If x contains 70000.0 in float16, it becomes inf, causing gradient issues.
184
+ # We upcast to float32 for operations that might exceed the limit, then clip and
185
+ # convert back to float16 to maintain numerical stability.
186
+
187
+ # Clip input to avoid overflow in float16
188
+ x = clip_residual(x)
189
+
190
+ # Self-attention block
191
+ r = self.self_attn(self.input_layernorm(x), mask, cache)
192
+ h = self.post_attention_layernorm(r)
193
+
194
+ # Add residual connection with overflow protection for float16
195
+ h = clip_residual(x + h)
196
+
197
+ # MLP block
198
+ r = self.mlp(self.pre_feedforward_layernorm(h))
199
+ out = self.post_feedforward_layernorm(r)
200
+
201
+ # Add residual connection with overflow protection for float16
202
+ out = clip_residual(h + out)
203
+
204
+ return out
205
+
206
+
207
+ class Gemma3Model(nn.Module):
208
+ def __init__(self, config: TextConfig):
209
+ super().__init__()
210
+ self.config = config
211
+ self.vocab_size = config.vocab_size
212
+ self.num_hidden_layers = config.num_hidden_layers
213
+ assert self.vocab_size > 0
214
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size)
215
+ self.layers = [
216
+ TransformerBlock(config=config, layer_idx=layer_idx)
217
+ for layer_idx in range(config.num_hidden_layers)
218
+ ]
219
+ self.norm = RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
220
+
221
+ def __call__(
222
+ self,
223
+ inputs: mx.array,
224
+ inputs_embeds: mx.array = None,
225
+ mask: mx.array = None,
226
+ cache=None,
227
+ ):
228
+ if inputs_embeds is None:
229
+ h = self.embed_tokens(inputs)
230
+ else:
231
+ h = inputs_embeds
232
+
233
+ h *= mx.array(self.config.hidden_size**0.5, mx.bfloat16).astype(h.dtype)
234
+
235
+ if cache is None:
236
+ cache = [None] * len(self.layers)
237
+
238
+ if mask is None:
239
+ j = self.config.sliding_window_pattern
240
+ full_mask = create_attention_mask(h, cache[j - 1 : j])
241
+ sliding_window_mask = create_attention_mask(h, cache)
242
+
243
+ for i, (layer, c) in enumerate(zip(self.layers, cache)):
244
+ is_global = (
245
+ i % self.config.sliding_window_pattern
246
+ == self.config.sliding_window_pattern - 1
247
+ )
248
+
249
+ local_mask = mask
250
+ if mask is None and is_global:
251
+ local_mask = full_mask
252
+ elif mask is None:
253
+ local_mask = sliding_window_mask
254
+
255
+ h = layer(h, local_mask, c)
256
+
257
+ return self.norm(h)
258
+
259
+
260
+ class LanguageModel(nn.Module):
261
+ def __init__(self, config: TextConfig):
262
+ super().__init__()
263
+ self.config = config
264
+ self.model_type = config.model_type
265
+ self.model = Gemma3Model(config)
266
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
267
+
268
+ def __call__(
269
+ self,
270
+ inputs: mx.array,
271
+ inputs_embeds: Optional[mx.array] = None,
272
+ mask: Optional[mx.array] = None,
273
+ cache=None,
274
+ ):
275
+ out = self.model(inputs, inputs_embeds=inputs_embeds, mask=mask, cache=cache)
276
+ out = self.lm_head(out)
277
+ return LanguageModelOutput(logits=out)
278
+
279
+ def sanitize(self, weights):
280
+ if "lm_head.weight" not in weights:
281
+ weights["language_model.lm_head.weight"] = weights[
282
+ "language_model.model.embed_tokens.weight"
283
+ ]
284
+ return {
285
+ k: v for k, v in weights.items() if "self_attn.rotary_emb.inv_freq" not in k
286
+ }
287
+
288
+ @property
289
+ def layers(self):
290
+ return self.model.layers
291
+
292
+ @property
293
+ def head_dim(self):
294
+ return self.config.head_dim
295
+
296
+ @property
297
+ def n_kv_heads(self):
298
+ return self.config.num_key_value_heads
299
+
300
+ def make_cache(self):
301
+ caches = []
302
+ for i in range(self.config.num_hidden_layers):
303
+ if (
304
+ i % self.config.sliding_window_pattern
305
+ == self.config.sliding_window_pattern - 1
306
+ ):
307
+ caches.append(KVCache())
308
+ else:
309
+ caches.append(
310
+ RotatingKVCache(
311
+ max_size=self.config.sliding_window,
312
+ keep=0,
313
+ )
314
+ )
315
+ return caches