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,39 @@
1
+ import mlx.core as mx
2
+
3
+
4
+ def top_p_sampling(logits: mx.array, top_p: float, temperature: float) -> mx.array:
5
+ """
6
+ Apply top-p (nucleus) sampling to logits.
7
+
8
+ Args:
9
+ logits: The logits from the model's output.
10
+ top_p: The cumulative probability threshold for top-p filtering.
11
+ temperature: Temperature parameter for softmax distribution reshaping.
12
+ Returns:
13
+ token selected based on the top-p criterion.
14
+ """
15
+ if (
16
+ logits.dtype == mx.bfloat16
17
+ ): # workaround for unable to load kernel contiguous_scan_inclusive_sum_bfloat16_bfloat16
18
+ logits = logits.astype(mx.float32)
19
+
20
+ # referenced implementation from https://github.com/huggingface/transformers/blob/main/src/transformers/generation/logits_process.py#L449-L460
21
+ probs = mx.softmax(logits / temperature, axis=-1)
22
+
23
+ # sort probs in ascending order
24
+ sorted_indices = mx.argsort(probs, axis=-1)
25
+ sorted_probs = probs[..., sorted_indices.squeeze(0)]
26
+
27
+ cumulative_probs = mx.cumsum(sorted_probs, axis=-1)
28
+
29
+ # select tokens with cumulative probs below threshold
30
+ top_probs = mx.where(
31
+ cumulative_probs > 1 - top_p,
32
+ sorted_probs,
33
+ mx.zeros_like(sorted_probs),
34
+ )
35
+
36
+ sorted_token = mx.random.categorical(mx.log(top_probs))
37
+ token = sorted_indices.squeeze(0)[sorted_token]
38
+
39
+ return token
@@ -0,0 +1,344 @@
1
+ import json
2
+ from functools import partial
3
+ from json import JSONDecodeError
4
+ from typing import List
5
+
6
+ from transformers import AutoTokenizer
7
+
8
+ REPLACEMENT_CHAR = "\ufffd"
9
+
10
+
11
+ def _remove_space(x):
12
+ if x and x[0] == " ":
13
+ return x[1:]
14
+ return x
15
+
16
+
17
+ class StreamingDetokenizer:
18
+ """The streaming detokenizer interface so that we can detokenize one token at a time.
19
+
20
+ Example usage is as follows:
21
+
22
+ detokenizer = ...
23
+
24
+ # Reset the tokenizer state
25
+ detokenizer.reset()
26
+
27
+ for token in generate(...):
28
+ detokenizer.add_token(token.item())
29
+
30
+ # Contains the whole text so far. Some tokens may not be included
31
+ # since it contains whole words usually.
32
+ detokenizer.text
33
+
34
+ # Contains the printable segment (usually a word) since the last
35
+ # time it was accessed
36
+ detokenizer.last_segment
37
+
38
+ # Contains all the tokens added so far
39
+ detokenizer.tokens
40
+
41
+ # Make sure that we detokenize any remaining tokens
42
+ detokenizer.finalize()
43
+
44
+ # Now detokenizer.text should match tokenizer.decode(detokenizer.tokens)
45
+ """
46
+
47
+ __slots__ = ("text", "tokens", "offset")
48
+
49
+ def reset(self):
50
+ raise NotImplementedError()
51
+
52
+ def add_token(self, token, skip_special_token_ids: List[int] = []):
53
+ raise NotImplementedError()
54
+
55
+ def finalize(self):
56
+ raise NotImplementedError()
57
+
58
+ @property
59
+ def last_segment(self):
60
+ """Return the last segment of readable text since last time this property was accessed."""
61
+ text = self.text
62
+ if text and text[-1] != REPLACEMENT_CHAR:
63
+ segment = text[self.offset :]
64
+ self.offset = len(text)
65
+ return segment
66
+ return ""
67
+
68
+
69
+ class NaiveStreamingDetokenizer(StreamingDetokenizer):
70
+ """NaiveStreamingDetokenizer relies on the underlying tokenizer
71
+ implementation and should work with every tokenizer.
72
+
73
+ Its complexity is O(T^2) where T is the longest line since it will
74
+ repeatedly detokenize the same tokens until a new line is generated.
75
+ """
76
+
77
+ def __init__(self, tokenizer):
78
+ self._tokenizer = tokenizer
79
+ self._tokenizer.decode([0])
80
+ self.reset()
81
+
82
+ def reset(self):
83
+ self.offset = 0
84
+ self._tokens = []
85
+ self._text = ""
86
+ self._current_tokens = []
87
+ self._current_text = ""
88
+
89
+ def add_token(self, token, skip_special_token_ids: List[int] = []):
90
+ if token in skip_special_token_ids:
91
+ return
92
+ self._current_tokens.append(token)
93
+
94
+ def finalize(self):
95
+ self._tokens.extend(self._current_tokens)
96
+ self._text += self._tokenizer.decode(self._current_tokens)
97
+ self._current_tokens = []
98
+ self._current_text = ""
99
+
100
+ @property
101
+ def text(self):
102
+ if self._current_tokens:
103
+ self._current_text = self._tokenizer.decode(self._current_tokens)
104
+ if self._current_text and self._current_text[-1] == "\n":
105
+ self._tokens.extend(self._current_tokens)
106
+ self._text += self._current_text
107
+ self._current_tokens.clear()
108
+ self._current_text = ""
109
+ return self._text + self._current_text
110
+
111
+ @property
112
+ def tokens(self):
113
+ return self._tokens
114
+
115
+
116
+ class SPMStreamingDetokenizer(StreamingDetokenizer):
117
+ """A streaming detokenizer for SPM models.
118
+
119
+ It adds tokens to the text if the next token starts with the special SPM
120
+ underscore which results in linear complexity.
121
+ """
122
+
123
+ def __init__(self, tokenizer, trim_space=True):
124
+ self.trim_space = trim_space
125
+
126
+ # Extract the tokens in a list from id to text
127
+ self.tokenmap = [None] * len(tokenizer.vocab)
128
+ for value, tokenid in tokenizer.vocab.items():
129
+ self.tokenmap[tokenid] = value
130
+
131
+ # Replace bytes with their value
132
+ for i in range(len(self.tokenmap)):
133
+ if self.tokenmap[i].startswith("<0x"):
134
+ self.tokenmap[i] = chr(int(self.tokenmap[i][3:5], 16))
135
+
136
+ self.reset()
137
+
138
+ def reset(self):
139
+ self.offset = 0
140
+ self._unflushed = ""
141
+ self.text = ""
142
+ self.tokens = []
143
+
144
+ def add_token(self, token, skip_special_token_ids: List[int] = []):
145
+ if token in skip_special_token_ids:
146
+ return
147
+ v = self.tokenmap[token]
148
+ if v[0] == "\u2581":
149
+ if self.text or not self.trim_space:
150
+ self.text += self._unflushed.replace("\u2581", " ")
151
+ else:
152
+ self.text = _remove_space(self._unflushed.replace("\u2581", " "))
153
+ self._unflushed = v
154
+ else:
155
+ self._unflushed += v
156
+
157
+ def finalize(self):
158
+ if self.text or not self.trim_space:
159
+ self.text += self._unflushed.replace("\u2581", " ")
160
+ else:
161
+ self.text = _remove_space(self._unflushed.replace("\u2581", " "))
162
+ self._unflushed = ""
163
+
164
+
165
+ class BPEStreamingDetokenizer(StreamingDetokenizer):
166
+ """A streaming detokenizer for OpenAI style BPE models.
167
+
168
+ It adds tokens to the text if the next token starts with a space similar to
169
+ the SPM detokenizer.
170
+ """
171
+
172
+ _byte_decoder = None
173
+
174
+ def __init__(self, tokenizer, trim_space=False):
175
+ self.trim_space = trim_space
176
+
177
+ # Extract the tokens in a list from id to text
178
+ self.tokenmap = [None] * len(tokenizer.vocab)
179
+ for value, tokenid in tokenizer.vocab.items():
180
+ self.tokenmap[tokenid] = value
181
+
182
+ self.reset()
183
+
184
+ # Make the BPE byte decoder from
185
+ # https://github.com/openai/gpt-2/blob/master/src/encoder.py
186
+ self.make_byte_decoder()
187
+
188
+ def reset(self):
189
+ self.offset = 0
190
+ self._unflushed = ""
191
+ self.text = ""
192
+ self.tokens = []
193
+
194
+ def add_token(self, token, skip_special_token_ids: List[int] = []):
195
+ if token in skip_special_token_ids:
196
+ return
197
+ v = self.tokenmap[token]
198
+ # if the token starts with space
199
+ if self._byte_decoder[v[0]] == 32:
200
+ current_text = bytearray(
201
+ self._byte_decoder[c] for c in self._unflushed
202
+ ).decode("utf-8")
203
+ if self.text or not self.trim_space:
204
+ self.text += current_text
205
+ else:
206
+ self.text += _remove_space(current_text)
207
+ self._unflushed = v
208
+ else:
209
+ self._unflushed += v
210
+
211
+ def finalize(self):
212
+ current_text = bytearray(self._byte_decoder[c] for c in self._unflushed).decode(
213
+ "utf-8"
214
+ )
215
+ if self.text or not self.trim_space:
216
+ self.text += current_text
217
+ else:
218
+ self.text += _remove_space(current_text)
219
+ self._unflushed = ""
220
+
221
+ @classmethod
222
+ def make_byte_decoder(cls):
223
+ """See https://github.com/openai/gpt-2/blob/master/src/encoder.py for the rationale."""
224
+ if cls._byte_decoder is not None:
225
+ return
226
+
227
+ char_to_bytes = {}
228
+ limits = [
229
+ 0,
230
+ ord("!"),
231
+ ord("~") + 1,
232
+ ord("¡"),
233
+ ord("¬") + 1,
234
+ ord("®"),
235
+ ord("ÿ") + 1,
236
+ ]
237
+ n = 0
238
+ for i, (start, stop) in enumerate(zip(limits, limits[1:])):
239
+ if i % 2 == 0:
240
+ for b in range(start, stop):
241
+ char_to_bytes[chr(2**8 + n)] = b
242
+ n += 1
243
+ else:
244
+ for b in range(start, stop):
245
+ char_to_bytes[chr(b)] = b
246
+ cls._byte_decoder = char_to_bytes
247
+
248
+
249
+ class TokenizerWrapper:
250
+ """A wrapper that combines an HF tokenizer and a detokenizer.
251
+
252
+ Accessing any attribute other than the ``detokenizer`` is forwarded to the
253
+ huggingface tokenizer.
254
+ """
255
+
256
+ def __init__(self, tokenizer, detokenizer_class=NaiveStreamingDetokenizer):
257
+ self._tokenizer = tokenizer
258
+ self._detokenizer = detokenizer_class(tokenizer)
259
+
260
+ def __getattr__(self, attr):
261
+ if attr == "detokenizer":
262
+ return self._detokenizer
263
+ else:
264
+ return getattr(self._tokenizer, attr)
265
+
266
+
267
+ def _match(a, b):
268
+ if type(a) != type(b):
269
+ return False
270
+ if isinstance(a, dict):
271
+ return len(a) == len(b) and all(k in b and _match(a[k], b[k]) for k in a)
272
+ if isinstance(a, list):
273
+ return len(a) == len(b) and all(_match(ai, bi) for ai, bi in zip(a, b))
274
+
275
+ return a == b
276
+
277
+
278
+ def _is_spm_decoder(decoder):
279
+ _target_description = {
280
+ "type": "Sequence",
281
+ "decoders": [
282
+ {"type": "Replace", "pattern": {"String": "▁"}, "content": " "},
283
+ {"type": "ByteFallback"},
284
+ {"type": "Fuse"},
285
+ {"type": "Strip", "content": " ", "start": 1, "stop": 0},
286
+ ],
287
+ }
288
+ return _match(_target_description, decoder)
289
+
290
+
291
+ def _is_spm_decoder_no_space(decoder):
292
+ _target_description = {
293
+ "type": "Sequence",
294
+ "decoders": [
295
+ {"type": "Replace", "pattern": {"String": "▁"}, "content": " "},
296
+ {"type": "ByteFallback"},
297
+ {"type": "Fuse"},
298
+ ],
299
+ }
300
+ return _match(_target_description, decoder)
301
+
302
+
303
+ def _is_bpe_decoder(decoder):
304
+ _target_description = {
305
+ "type": "ByteLevel",
306
+ "add_prefix_space": False,
307
+ "trim_offsets": False,
308
+ "use_regex": False,
309
+ }
310
+
311
+ return _match(_target_description, decoder)
312
+
313
+
314
+ def load_tokenizer(model_path, return_tokenizer=True, tokenizer_config_extra={}):
315
+ """Load a huggingface tokenizer and try to infer the type of streaming
316
+ detokenizer to use.
317
+
318
+ Note, to use a fast streaming tokenizer, pass a local file path rather than
319
+ a Hugging Face repo ID.
320
+ """
321
+ detokenizer_class = NaiveStreamingDetokenizer
322
+
323
+ tokenizer_file = model_path / "tokenizer.json"
324
+ if tokenizer_file.exists():
325
+ with open(tokenizer_file, "r") as f:
326
+ try:
327
+ tokenizer_content = json.load(f)
328
+ except JSONDecodeError as e:
329
+ raise JSONDecodeError("Failed to parse tokenizer.json", e.doc, e.pos)
330
+ if "decoder" in tokenizer_content:
331
+ if _is_spm_decoder(tokenizer_content["decoder"]):
332
+ detokenizer_class = SPMStreamingDetokenizer
333
+ elif _is_spm_decoder_no_space(tokenizer_content["decoder"]):
334
+ detokenizer_class = partial(SPMStreamingDetokenizer, trim_space=False)
335
+ elif _is_bpe_decoder(tokenizer_content["decoder"]):
336
+ detokenizer_class = BPEStreamingDetokenizer
337
+
338
+ if return_tokenizer:
339
+ return TokenizerWrapper(
340
+ AutoTokenizer.from_pretrained(model_path, **tokenizer_config_extra),
341
+ detokenizer_class,
342
+ )
343
+ else:
344
+ return detokenizer_class
@@ -0,0 +1,9 @@
1
+ from .lora import LoRaLayer, replace_lora_with_linear
2
+ from .trainer import Dataset, Trainer, save_adapter
3
+ from .utils import (
4
+ apply_lora_layers,
5
+ count_parameters,
6
+ find_all_linear_names,
7
+ get_peft_model,
8
+ print_trainable_parameters,
9
+ )
@@ -0,0 +1,70 @@
1
+ import math
2
+ from typing import Union
3
+
4
+ import mlx.core as mx
5
+ import mlx.nn as nn
6
+
7
+
8
+ class LoRaLayer(nn.Module):
9
+ def __init__(
10
+ self,
11
+ linear: Union[nn.Linear, nn.QuantizedLinear],
12
+ rank: int,
13
+ alpha: float = 0.1,
14
+ dropout: float = 0.0,
15
+ ):
16
+ super().__init__()
17
+
18
+ self.original_layer = linear
19
+
20
+ self.dropout = nn.Dropout(p=dropout)
21
+
22
+ output_dims, input_dims = linear.weight.shape
23
+ if isinstance(linear, nn.QuantizedLinear):
24
+ input_dims *= 32 // linear.bits
25
+
26
+ std_dev = 1 / math.sqrt(rank)
27
+
28
+ self.A = mx.random.uniform(
29
+ low=-std_dev,
30
+ high=std_dev,
31
+ shape=(input_dims, rank),
32
+ )
33
+ self.B = mx.zeros((rank, output_dims))
34
+ self.alpha = alpha
35
+
36
+ def __call__(self, x):
37
+ y = self.original_layer(x)
38
+ lora_update = (self.dropout(x) @ self.A) @ self.B
39
+ return y + (self.alpha * lora_update).astype(x.dtype)
40
+
41
+
42
+ def replace_lora_with_linear(model):
43
+ for i, layer in enumerate(model.layers):
44
+ if isinstance(layer, LoRaLayer):
45
+ # Compute the final merged weight
46
+ lora_update = layer.alpha * (layer.A @ layer.B)
47
+ updated_weight = layer.original_layer.weight + lora_update
48
+ use_bias = layer.original_layer.bias is not None
49
+
50
+ updated_bias = layer.original_layer.bias
51
+
52
+ # Create a new Linear layer with the updated parameters
53
+ new_linear_layer = nn.Linear(
54
+ updated_weight.size(1), updated_weight.size(0), bias=use_bias
55
+ )
56
+
57
+ new_linear_layer.weight = updated_weight
58
+
59
+ if use_bias:
60
+ new_linear_layer.bias = updated_bias
61
+
62
+ if isinstance(layer.original_layer, nn.QuantizedLinear):
63
+ new_linear_layer = nn.QuantizedLinear.from_linear(
64
+ new_linear_layer,
65
+ new_linear_layer.group_size,
66
+ new_linear_layer.bits,
67
+ )
68
+
69
+ # Replace the LoRaLayer with the new Linear layer in the model
70
+ model.layers[i] = new_linear_layer