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,488 @@
1
+ import inspect
2
+ import math
3
+ from dataclasses import dataclass
4
+ from typing import Optional, Tuple
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 SimpleKVCache
15
+
16
+
17
+ @dataclass
18
+ class TextConfig:
19
+ d_model: int = 768
20
+ model_type: str = "florence2"
21
+ encoder_attention_heads: int = 8
22
+ decoder_attention_heads: int = 8
23
+ encoder_ffn_dim: int = 3072
24
+ decoder_ffn_dim: int = 3072
25
+ dropout: float = 0.1
26
+ attention_dropout: float = 0.0
27
+ activation_dropout: float = 0.0
28
+ activation_function: str = "gelu"
29
+ init_std: float = 0.02
30
+ encoder_layerdrop: float = 0.0
31
+ decoder_layerdrop: float = 0.0
32
+ scale_embedding: bool = False
33
+ use_cache: bool = True
34
+ max_position_embeddings: int = 1024
35
+ vocab_size: int = 51289
36
+ pad_token_id: int = 1
37
+ bos_token_id: int = 0
38
+ eos_token_id: int = 2
39
+ encoder_layers: int = 6
40
+ decoder_layers: int = 6
41
+
42
+ @classmethod
43
+ def from_dict(cls, params):
44
+ return cls(
45
+ **{
46
+ k: v
47
+ for k, v in params.items()
48
+ if k in inspect.signature(cls).parameters
49
+ }
50
+ )
51
+
52
+
53
+ class Florence2Attention(nn.Module):
54
+ def __init__(
55
+ self, config: TextConfig, is_decoder: bool = False, is_causal: bool = False
56
+ ):
57
+ super().__init__()
58
+ self.embed_dim = config.d_model
59
+ self.num_heads = (
60
+ config.decoder_attention_heads
61
+ if is_decoder
62
+ else config.encoder_attention_heads
63
+ )
64
+ self.is_decoder = is_decoder
65
+ self.is_causal = is_causal
66
+ self.head_dim = self.embed_dim // self.num_heads
67
+ self.scaling = self.head_dim**-0.5
68
+
69
+ self.k_proj = nn.Linear(self.embed_dim, self.embed_dim)
70
+ self.v_proj = nn.Linear(self.embed_dim, self.embed_dim)
71
+ self.q_proj = nn.Linear(self.embed_dim, self.embed_dim)
72
+ self.out_proj = nn.Linear(self.embed_dim, self.embed_dim)
73
+
74
+ def __call__(
75
+ self,
76
+ hidden_states,
77
+ key_value_states=None,
78
+ cache: Optional[SimpleKVCache] = None,
79
+ attention_mask=None,
80
+ layer_head_mask=None,
81
+ ):
82
+ batch_size, tgt_len, _ = hidden_states.shape
83
+
84
+ q = (
85
+ self.q_proj(hidden_states)
86
+ .reshape(batch_size, tgt_len, self.num_heads, self.head_dim)
87
+ .transpose(0, 2, 1, 3)
88
+ )
89
+
90
+ is_cross_attention = key_value_states is not None
91
+
92
+ batch_size, tgt_len, _ = hidden_states.shape
93
+ src_len = (
94
+ key_value_states.shape[1]
95
+ if key_value_states is not None
96
+ else hidden_states.shape[1]
97
+ )
98
+
99
+ if (
100
+ is_cross_attention
101
+ and cache.cache_length > 0
102
+ and cache.keys.shape[2] == key_value_states.shape[1]
103
+ ):
104
+ # k = cache[0]
105
+ # v = cache[1]
106
+ k = cache.keys
107
+ v = cache.values
108
+
109
+ elif is_cross_attention:
110
+ # Cross attention
111
+ k = (
112
+ self.k_proj(key_value_states)
113
+ .reshape(batch_size, src_len, self.num_heads, self.head_dim)
114
+ .transpose(0, 2, 1, 3)
115
+ )
116
+ v = (
117
+ self.v_proj(key_value_states)
118
+ .reshape(batch_size, src_len, self.num_heads, self.head_dim)
119
+ .transpose(0, 2, 1, 3)
120
+ )
121
+ elif cache is not None:
122
+ # reuse k, v, self_attention
123
+ k = (
124
+ self.k_proj(hidden_states)
125
+ .reshape(batch_size, src_len, self.num_heads, -1)
126
+ .transpose(0, 2, 1, 3)
127
+ )
128
+ v = (
129
+ self.v_proj(hidden_states)
130
+ .reshape(batch_size, src_len, self.num_heads, -1)
131
+ .transpose(0, 2, 1, 3)
132
+ )
133
+
134
+ k, v = cache.update_and_fetch(k, v)
135
+ else:
136
+ # Self attention
137
+ k = (
138
+ self.k_proj(hidden_states)
139
+ .reshape(batch_size, src_len, self.num_heads, self.head_dim)
140
+ .transpose(0, 2, 1, 3)
141
+ )
142
+ v = (
143
+ self.v_proj(hidden_states)
144
+ .reshape(batch_size, src_len, self.num_heads, self.head_dim)
145
+ .transpose(0, 2, 1, 3)
146
+ )
147
+
148
+ if self.is_decoder:
149
+ cache.update(k, v)
150
+
151
+ if self.is_causal and self.is_decoder:
152
+ causal_mask = create_attention_mask(hidden_states)
153
+ attention_mask = causal_mask
154
+
155
+ attn_output = (
156
+ scaled_dot_product_attention(
157
+ q, k, v, cache=cache, scale=self.scaling, mask=attention_mask
158
+ )
159
+ .transpose(0, 2, 1, 3)
160
+ .reshape(batch_size, tgt_len, -1)
161
+ )
162
+
163
+ attn_output = self.out_proj(attn_output)
164
+
165
+ return attn_output
166
+
167
+
168
+ class Florence2EncoderLayer(nn.Module):
169
+ def __init__(self, config: TextConfig):
170
+ super().__init__()
171
+ self.embed_dim = config.d_model
172
+ self.self_attn = Florence2Attention(config, is_decoder=False, is_causal=False)
173
+ self.self_attn_layer_norm = nn.LayerNorm(self.embed_dim)
174
+ self.activation_fn = nn.GELU()
175
+ self.fc1 = nn.Linear(self.embed_dim, config.encoder_ffn_dim)
176
+ self.fc2 = nn.Linear(config.encoder_ffn_dim, self.embed_dim)
177
+ self.final_layer_norm = nn.LayerNorm(self.embed_dim)
178
+
179
+ def __call__(self, hidden_states, attention_mask=None):
180
+ residual = hidden_states
181
+ hidden_states = self.self_attn(hidden_states, attention_mask=attention_mask)
182
+ hidden_states = residual + hidden_states
183
+ hidden_states = self.self_attn_layer_norm(hidden_states)
184
+
185
+ residual = hidden_states
186
+ hidden_states = self.activation_fn(self.fc1(hidden_states))
187
+ hidden_states = self.fc2(hidden_states)
188
+ hidden_states = residual + hidden_states
189
+ hidden_states = self.final_layer_norm(hidden_states)
190
+
191
+ return hidden_states
192
+
193
+
194
+ class Florence2DecoderLayer(nn.Module):
195
+ def __init__(self, config: TextConfig):
196
+ super().__init__()
197
+ self.embed_dim = config.d_model
198
+ self.self_attn = Florence2Attention(config, is_decoder=True, is_causal=True)
199
+ self.dropout = config.dropout
200
+ self.activation_fn = nn.GELU()
201
+ self.activation_dropout = config.activation_dropout
202
+
203
+ self.self_attn_layer_norm = nn.LayerNorm(self.embed_dim)
204
+ self.encoder_attn = Florence2Attention(config, is_decoder=True)
205
+ self.encoder_attn_layer_norm = nn.LayerNorm(self.embed_dim)
206
+ self.fc1 = nn.Linear(self.embed_dim, config.decoder_ffn_dim)
207
+ self.fc2 = nn.Linear(config.decoder_ffn_dim, self.embed_dim)
208
+ self.final_layer_norm = nn.LayerNorm(self.embed_dim)
209
+
210
+ def __call__(
211
+ self,
212
+ hidden_states,
213
+ encoder_hidden_states,
214
+ attention_mask=None,
215
+ encoder_attention_mask=None,
216
+ cache: Optional[Tuple[SimpleKVCache, SimpleKVCache]] = None,
217
+ ):
218
+ residual = hidden_states
219
+
220
+ # decoder uni-directional self-attention cached key/values tuple is at positions 1,2
221
+ self_attn_cache = cache[0] if cache[0] is not None else None
222
+
223
+ hidden_states = self.self_attn(
224
+ hidden_states, attention_mask=attention_mask, cache=self_attn_cache
225
+ )
226
+
227
+ hidden_states = residual + hidden_states
228
+ hidden_states = self.self_attn_layer_norm(hidden_states)
229
+
230
+ if encoder_hidden_states is not None:
231
+ residual = hidden_states
232
+
233
+ mask = create_attention_mask(hidden_states)
234
+
235
+ # cross_attn cached key/values tuple is at positions 3,4 of cache tuple
236
+ cross_attn_cache = cache[-1] if cache[-1] is not None else None
237
+
238
+ hidden_states = self.encoder_attn(
239
+ hidden_states,
240
+ key_value_states=encoder_hidden_states,
241
+ attention_mask=mask,
242
+ cache=cross_attn_cache,
243
+ )
244
+ hidden_states = residual + hidden_states
245
+ hidden_states = self.encoder_attn_layer_norm(hidden_states)
246
+
247
+ # Fully Connected
248
+ residual = hidden_states
249
+ hidden_states = self.activation_fn(self.fc1(hidden_states))
250
+ hidden_states = self.fc2(hidden_states)
251
+ hidden_states = residual + hidden_states
252
+ hidden_states = self.final_layer_norm(hidden_states)
253
+
254
+ return hidden_states
255
+
256
+
257
+ class Florence2Encoder(nn.Module):
258
+ def __init__(self, config: TextConfig):
259
+ super().__init__()
260
+ self.config = config
261
+ self.dropout = config.dropout
262
+ self.layerdrop = config.encoder_layerdrop
263
+
264
+ embed_dim = config.d_model
265
+ self.embed_scale = math.sqrt(embed_dim) if config.scale_embedding else 1.0
266
+ self.offset = 2
267
+ self.embed_positions = nn.Embedding(
268
+ config.max_position_embeddings + self.offset, embed_dim
269
+ )
270
+ self.layers = [
271
+ Florence2EncoderLayer(config) for _ in range(config.encoder_layers)
272
+ ]
273
+ self.layernorm_embedding = nn.LayerNorm(embed_dim)
274
+
275
+ def __call__(self, input_ids=None, inputs_embeds=None, attention_mask=None):
276
+
277
+ if inputs_embeds is None:
278
+ inputs_embeds = self.embed_tokens(input_ids)
279
+ input_shape = inputs_embeds.shape
280
+ else:
281
+ input_shape = inputs_embeds.shape
282
+
283
+ positions = mx.arange(input_shape[1])
284
+
285
+ if positions.ndim == 1:
286
+ positions = mx.expand_dims(positions, axis=0)
287
+
288
+ embed_pos = self.embed_positions(positions + self.offset)
289
+
290
+ hidden_states = inputs_embeds + embed_pos
291
+ hidden_states = self.layernorm_embedding(hidden_states)
292
+
293
+ for encoder_layer in self.layers:
294
+ # Add LayerDrop (see https://arxiv.org/abs/1909.11556 for description)
295
+ dropout_probability = mx.random.uniform()
296
+ if self.training and (dropout_probability < self.layerdrop):
297
+ continue
298
+ hidden_states = encoder_layer(hidden_states, attention_mask)
299
+
300
+ return hidden_states
301
+
302
+
303
+ class Florence2Decoder(nn.Module):
304
+ def __init__(self, config: TextConfig):
305
+ super().__init__()
306
+ self.config = config
307
+ self.dropout = config.dropout
308
+ self.layerdrop = config.decoder_layerdrop
309
+ self.padding_idx = config.pad_token_id
310
+ self.max_target_positions = config.max_position_embeddings
311
+ self.embed_scale = math.sqrt(config.d_model) if config.scale_embedding else 1.0
312
+ self.offset = 2
313
+ self.embed_positions = nn.Embedding(
314
+ config.max_position_embeddings + self.offset, config.d_model
315
+ )
316
+ self.layers = [
317
+ Florence2DecoderLayer(config) for _ in range(config.decoder_layers)
318
+ ]
319
+ self.layernorm_embedding = nn.LayerNorm(config.d_model)
320
+
321
+ def __call__(
322
+ self,
323
+ input_ids=None,
324
+ attention_mask=None,
325
+ encoder_hidden_states=None,
326
+ encoder_attention_mask=None,
327
+ head_mask=None,
328
+ cross_attn_head_mask=None,
329
+ inputs_embeds=None,
330
+ cache=None,
331
+ ):
332
+ if input_ids is not None and inputs_embeds is not None:
333
+ raise ValueError(
334
+ "You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time"
335
+ )
336
+ elif input_ids is not None:
337
+ inputs_embeds = self.embed_tokens(input_ids)
338
+ input_shape = inputs_embeds.shape # for 2d masks
339
+ positions = input_ids
340
+ elif inputs_embeds is not None:
341
+ input_shape = inputs_embeds.shape[:-1] # for 4d masks
342
+ positions = inputs_embeds[:, :, -1]
343
+ else:
344
+ raise ValueError(
345
+ "You have to specify either decoder_input_ids or decoder_inputs_embeds"
346
+ )
347
+
348
+ if positions.ndim == 1:
349
+ positions = mx.expand_dims(positions, axis=0)
350
+
351
+ cache_length = cache[0][0].keys.shape[2] if cache[0][0].cache_length > 0 else 0
352
+
353
+ bsz, seq_len = inputs_embeds.shape[:2]
354
+ positions = mx.arange(
355
+ cache_length,
356
+ cache_length + seq_len,
357
+ dtype=mx.int64,
358
+ )
359
+ positions = mx.expand_dims(positions, axis=0)
360
+
361
+ embed_pos = self.embed_positions(positions + self.offset)
362
+
363
+ hidden_states = inputs_embeds + embed_pos
364
+ hidden_states = self.layernorm_embedding(hidden_states)
365
+
366
+ for decoder_layer, c in zip(self.layers, cache):
367
+ # add LayerDrop (see https://arxiv.org/abs/1909.11556 for description)
368
+ dropout_probability = mx.random.uniform()
369
+ if self.training and (dropout_probability < self.layerdrop):
370
+ continue
371
+ hidden_states = decoder_layer(
372
+ hidden_states=hidden_states,
373
+ encoder_hidden_states=encoder_hidden_states,
374
+ attention_mask=attention_mask,
375
+ encoder_attention_mask=encoder_attention_mask,
376
+ cache=c,
377
+ )
378
+
379
+ return hidden_states
380
+
381
+
382
+ class Florence2LanguageModel(nn.Module):
383
+ def __init__(self, config: TextConfig):
384
+ super().__init__()
385
+ self.config = config
386
+ self.shared = nn.Embedding(config.vocab_size, config.d_model)
387
+ self.encoder = Florence2Encoder(config)
388
+ self.decoder = Florence2Decoder(config)
389
+ if config.scale_embedding:
390
+ self.embed_scale = math.sqrt(config.d_model)
391
+ else:
392
+ self.embed_scale = 1.0
393
+
394
+ def __call__(
395
+ self,
396
+ input_ids=None,
397
+ inputs_embeds=None,
398
+ decoder_input_ids=None,
399
+ decoder_inputs_embeds=None,
400
+ attention_mask=None,
401
+ decoder_attention_mask=None,
402
+ encoder_outputs=None,
403
+ cache=None,
404
+ ):
405
+ self.encoder.embed_tokens = self.shared
406
+ self.decoder.embed_tokens = self.shared
407
+
408
+ if decoder_input_ids is None and decoder_inputs_embeds is None:
409
+ if input_ids is None:
410
+ raise ValueError(
411
+ "If no `decoder_input_ids` or `decoder_inputs_embeds` are "
412
+ "passed, `input_ids` cannot be `None`. Please pass either "
413
+ "`input_ids` or `decoder_input_ids` or `decoder_inputs_embeds`."
414
+ )
415
+
416
+ decoder_input_ids = mx.zeros_like(input_ids)
417
+ decoder_input_ids[:, 1:] = input_ids[:, :-1]
418
+ decoder_input_ids[:, 0] = self.config.bos_token_id
419
+
420
+ if inputs_embeds is not None:
421
+ inputs_embeds = inputs_embeds * self.embed_scale
422
+
423
+ if cache is None:
424
+ cache = [(SimpleKVCache(), SimpleKVCache())] * len(self.decoder.layers)
425
+
426
+ if encoder_outputs is None:
427
+ encoder_outputs = self.encoder(
428
+ input_ids=input_ids,
429
+ inputs_embeds=inputs_embeds,
430
+ attention_mask=attention_mask,
431
+ )
432
+
433
+ decoder_outputs = self.decoder(
434
+ input_ids=decoder_input_ids,
435
+ attention_mask=decoder_attention_mask,
436
+ encoder_hidden_states=encoder_outputs,
437
+ encoder_attention_mask=attention_mask,
438
+ inputs_embeds=decoder_inputs_embeds,
439
+ cache=cache,
440
+ )
441
+ return decoder_outputs, encoder_outputs
442
+
443
+
444
+ class LanguageModel(nn.Module):
445
+ def __init__(self, config: TextConfig):
446
+ super().__init__()
447
+ self.config = config
448
+ self.model = Florence2LanguageModel(config)
449
+ self.lm_head = nn.Linear(config.d_model, config.vocab_size, bias=False)
450
+
451
+ def __call__(
452
+ self,
453
+ input_ids=None,
454
+ inputs_embeds=None,
455
+ decoder_input_ids=None,
456
+ decoder_inputs_embeds=None,
457
+ attention_mask=None,
458
+ decoder_attention_mask=None,
459
+ encoder_outputs=None,
460
+ cache=None,
461
+ ):
462
+ decoder_outputs, encoder_outputs = self.model(
463
+ input_ids,
464
+ inputs_embeds,
465
+ decoder_input_ids,
466
+ decoder_inputs_embeds,
467
+ attention_mask,
468
+ decoder_attention_mask,
469
+ encoder_outputs,
470
+ cache,
471
+ )
472
+ out = self.lm_head(decoder_outputs)
473
+ return LanguageModelOutput(logits=out, encoder_outputs=encoder_outputs)
474
+
475
+ @property
476
+ def layers(self):
477
+ return range(self.model.config.decoder_layers)
478
+
479
+ @property
480
+ def head_dim(self):
481
+ return self.config.d_model // self.config.decoder_attention_heads
482
+
483
+ @property
484
+ def n_kv_heads(self):
485
+ return self.config.decoder_attention_heads
486
+
487
+ def make_cache(self):
488
+ return [(SimpleKVCache(), SimpleKVCache()) for n in self.layers]