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,407 @@
1
+ import json
2
+ from functools import partial
3
+ from json import JSONDecodeError
4
+ from typing import List
5
+
6
+ from transformers import AutoTokenizer, PreTrainedTokenizerFast
7
+
8
+
9
+ class StreamingDetokenizer:
10
+ """The streaming detokenizer interface so that we can detokenize one token at a time.
11
+
12
+ Example usage is as follows:
13
+
14
+ detokenizer = ...
15
+
16
+ # Reset the tokenizer state
17
+ detokenizer.reset()
18
+
19
+ for token in generate(...):
20
+ detokenizer.add_token(token.item())
21
+
22
+ # Contains the whole text so far. Some tokens may not be included
23
+ # since it contains whole words usually.
24
+ detokenizer.text
25
+
26
+ # Contains the printable segment (usually a word) since the last
27
+ # time it was accessed
28
+ detokenizer.last_segment
29
+
30
+ # Contains all the tokens added so far
31
+ detokenizer.tokens
32
+
33
+ # Make sure that we detokenize any remaining tokens
34
+ detokenizer.finalize()
35
+
36
+ # Now detokenizer.text should match tokenizer.decode(detokenizer.tokens)
37
+ """
38
+
39
+ __slots__ = ("text", "tokens", "offset")
40
+
41
+ def reset(self):
42
+ raise NotImplementedError()
43
+
44
+ def add_token(self, token):
45
+ raise NotImplementedError()
46
+
47
+ def finalize(self):
48
+ raise NotImplementedError()
49
+
50
+ @property
51
+ def last_segment(self):
52
+ """Return the last segment of readable text since last time this property was accessed."""
53
+ text = self.text
54
+ segment = text[self.offset :]
55
+ self.offset = len(text)
56
+ return segment
57
+
58
+
59
+ class NaiveStreamingDetokenizer(StreamingDetokenizer):
60
+ """NaiveStreamingDetokenizer relies on the underlying tokenizer
61
+ implementation and should work with every tokenizer.
62
+
63
+ Its complexity is O(T^2) where T is the longest line since it will
64
+ repeatedly detokenize the same tokens until a new line is generated.
65
+ """
66
+
67
+ def __init__(self, tokenizer):
68
+ self._tokenizer = tokenizer
69
+ self._tokenizer.decode([0])
70
+ self.reset()
71
+
72
+ def reset(self):
73
+ self.offset = 0
74
+ self.tokens = []
75
+ self._text = ""
76
+ self._current_tokens = []
77
+ self._current_text = ""
78
+
79
+ def add_token(self, token):
80
+ self._current_tokens.append(token)
81
+ self.tokens.append(token)
82
+
83
+ def finalize(self):
84
+ self._text += self._tokenizer.decode(self._current_tokens)
85
+ self._current_tokens = []
86
+ self._current_text = ""
87
+
88
+ @property
89
+ def text(self):
90
+ if self._current_tokens:
91
+ self._current_text = self._tokenizer.decode(self._current_tokens)
92
+ if self._tokenizer.clean_up_tokenization_spaces and self._current_text[-1] == " ":
93
+ self._current_text = self._current_text[:-1]
94
+ if self._current_text and self._current_text[-1] == "\n":
95
+ self._text += self._current_text
96
+ self._current_tokens.clear()
97
+ self._current_text = ""
98
+ return self._text + self._current_text
99
+
100
+
101
+ class SPMStreamingDetokenizer(StreamingDetokenizer):
102
+ """A streaming detokenizer for SPM models.
103
+
104
+ It adds tokens to the text if the next token starts with the special SPM
105
+ underscore which results in linear complexity.
106
+ """
107
+
108
+ def __init__(self, tokenizer, trim_space=True):
109
+ self.trim_space = trim_space
110
+ self._sep = "\u2581".encode()
111
+
112
+ # Extract the tokens in a list from id to text
113
+ self.tokenmap = [""] * (max(tokenizer.vocab.values()) + 1)
114
+ for value, tokenid in tokenizer.vocab.items():
115
+ if value.startswith("<0x"):
116
+ # Replace bytes with their value
117
+ self.tokenmap[tokenid] = bytes([int(value[3:5], 16)])
118
+ else:
119
+ self.tokenmap[tokenid] = value.encode()
120
+
121
+ self.reset()
122
+
123
+ def reset(self):
124
+ self.offset = 0
125
+ self._unflushed = b""
126
+ self.text = ""
127
+ self.tokens = []
128
+
129
+ def _try_flush(self, force=False):
130
+ text = self._unflushed.replace(self._sep, b" ").decode("utf-8", "replace")
131
+ if not force and text.endswith("\ufffd"):
132
+ return
133
+ if not self.text and self.trim_space and text and text[0] == " ":
134
+ text = text[1:]
135
+ self.text += text
136
+ self._unflushed = b""
137
+
138
+ def add_token(self, token):
139
+ self.tokens.append(token)
140
+ v = self.tokenmap[token]
141
+ self._unflushed += v
142
+ self._try_flush()
143
+
144
+ def finalize(self):
145
+ self._try_flush(force=True)
146
+ self._unflushed = b""
147
+
148
+
149
+ class BPEStreamingDetokenizer(StreamingDetokenizer):
150
+ """A streaming detokenizer for OpenAI style BPE models.
151
+
152
+ It adds tokens to the text if the next token starts with a space similar to
153
+ the SPM detokenizer.
154
+ """
155
+
156
+ _byte_decoder = None
157
+ _space_matches = (".", "?", "!", ",", "n't", "'m", "'s", "'ve", "'re")
158
+
159
+ def __init__(self, tokenizer):
160
+ self.clean_spaces = tokenizer.clean_up_tokenization_spaces
161
+
162
+ # Extract the tokens in a list from id to text
163
+ self.tokenmap = [None] * len(tokenizer.vocab)
164
+ for value, tokenid in tokenizer.vocab.items():
165
+ self.tokenmap[tokenid] = value
166
+
167
+ self.reset()
168
+
169
+ # Make the BPE byte decoder from
170
+ # https://github.com/openai/gpt-2/blob/master/src/encoder.py
171
+ self.make_byte_decoder()
172
+
173
+ def reset(self):
174
+ self.offset = 0
175
+ self._unflushed = ""
176
+ self.text = ""
177
+ self.tokens = []
178
+
179
+ def _decode_bytes(self, seq):
180
+ barr = bytearray()
181
+ for c in seq:
182
+ res = self._byte_decoder.get(c, False)
183
+ if res:
184
+ barr.append(res)
185
+ else:
186
+ barr.extend(bytes(c, "utf-8"))
187
+ return barr.decode("utf-8", "replace")
188
+
189
+ def _maybe_trim_space(self, current_text):
190
+ if len(current_text) == 0:
191
+ return current_text
192
+ elif current_text[0] != " ":
193
+ return current_text
194
+ elif not self.text:
195
+ return current_text[1:]
196
+ elif self.clean_spaces and current_text[1:].startswith(self._space_matches):
197
+ return current_text[1:]
198
+ return current_text
199
+
200
+ def add_token(self, token):
201
+ self.tokens.append(token)
202
+ v = self.tokenmap[token]
203
+ self._unflushed += v
204
+ text = self._decode_bytes(self._unflushed)
205
+
206
+ # For multi-byte utf-8 wait until they are complete
207
+ # For single spaces wait until the next token to clean it if needed
208
+ if not text.endswith("\ufffd") and not (len(v) == 1 and self._byte_decoder[v[0]] == 32):
209
+ self.text += self._maybe_trim_space(text)
210
+ self._unflushed = ""
211
+
212
+ def finalize(self):
213
+ current_text = bytearray(self._byte_decoder[c] for c in self._unflushed).decode(
214
+ "utf-8",
215
+ "replace",
216
+ )
217
+ self.text += self._maybe_trim_space(current_text)
218
+ self._unflushed = ""
219
+
220
+ @classmethod
221
+ def make_byte_decoder(cls):
222
+ """See https://github.com/openai/gpt-2/blob/master/src/encoder.py for the rationale."""
223
+ if cls._byte_decoder is not None:
224
+ return
225
+
226
+ char_to_bytes = {}
227
+ limits = [
228
+ 0,
229
+ ord("!"),
230
+ ord("~") + 1,
231
+ ord("¡"),
232
+ ord("¬") + 1,
233
+ ord("®"),
234
+ ord("ÿ") + 1,
235
+ ]
236
+ n = 0
237
+ for i, (start, stop) in enumerate(zip(limits, limits[1:])):
238
+ if i % 2 == 0:
239
+ for b in range(start, stop):
240
+ char_to_bytes[chr(2**8 + n)] = b
241
+ n += 1
242
+ else:
243
+ for b in range(start, stop):
244
+ char_to_bytes[chr(b)] = b
245
+ cls._byte_decoder = char_to_bytes
246
+
247
+
248
+ class TokenizerWrapper:
249
+ """A wrapper that combines an HF tokenizer and a detokenizer.
250
+
251
+ Accessing any attribute other than the ``detokenizer`` is forwarded to the
252
+ huggingface tokenizer.
253
+ """
254
+
255
+ def __init__(self, tokenizer, detokenizer_class=NaiveStreamingDetokenizer, eos_token_ids=None):
256
+ self._tokenizer = tokenizer
257
+ self._detokenizer = detokenizer_class(tokenizer)
258
+ self._eos_token_ids = (
259
+ set(eos_token_ids) if eos_token_ids is not None else {tokenizer.eos_token_id}
260
+ )
261
+
262
+ def add_eos_token(self, token: str):
263
+ token_id = None
264
+ try:
265
+ token_id = int(token)
266
+ except ValueError:
267
+ token_id = self._tokenizer.convert_tokens_to_ids(token)
268
+
269
+ if token_id is None:
270
+ raise ValueError(f"'{token}' is not a token for this tokenizer")
271
+
272
+ self._eos_token_ids.add(token_id)
273
+
274
+ def __getattr__(self, attr):
275
+ if attr == "detokenizer":
276
+ return self._detokenizer
277
+ elif attr == "eos_token_ids":
278
+ return self._eos_token_ids
279
+ elif attr.startswith("_"):
280
+ return self.__getattribute__(attr)
281
+ else:
282
+ return getattr(self._tokenizer, attr)
283
+
284
+ def __setattr__(self, attr, value):
285
+ if attr in {"detokenizer", "eos_token_ids"}:
286
+ if attr == "detokenizer":
287
+ raise AttributeError("Cannot set the detokenizer.")
288
+ elif attr == "eos_token_ids":
289
+ self._eos_token_ids = set(value) if value is not None else set()
290
+ elif attr.startswith("_"):
291
+ super().__setattr__(attr, value)
292
+ else:
293
+ setattr(self._tokenizer, attr, value)
294
+
295
+
296
+ class NewlineTokenizer(PreTrainedTokenizerFast):
297
+ """A tokenizer that replaces newlines with <n> and <n> with new line."""
298
+
299
+ def __init__(self, *args, **kwargs):
300
+ super().__init__(*args, **kwargs)
301
+
302
+ def _preprocess_text(self, text):
303
+ return text.replace("\n", "<n>")
304
+
305
+ def _postprocess_text(self, text):
306
+ return text.replace("<n>", "\n")
307
+
308
+ def encode(self, text, **kwargs):
309
+ return super().encode(self._preprocess_text(text), **kwargs)
310
+
311
+ def encode_batch(self, texts, **kwargs):
312
+ return super().encode_batch([self._preprocess_text(t) for t in texts], **kwargs)
313
+
314
+ def decode(self, *args, **kwargs):
315
+ return self._postprocess_text(super().decode(*args, **kwargs))
316
+
317
+ def batch_decode(self, *args, **kwargs):
318
+ decoded = super().batch_decode(*args, **kwargs)
319
+ return [self._postprocess_text(d) for d in decoded]
320
+
321
+
322
+ AutoTokenizer.register("NewlineTokenizer", fast_tokenizer_class=NewlineTokenizer)
323
+
324
+
325
+ def _match(a, b):
326
+ if type(a) != type(b):
327
+ return False
328
+ if isinstance(a, dict):
329
+ return len(a) == len(b) and all(k in b and _match(a[k], b[k]) for k in a)
330
+ if isinstance(a, list):
331
+ return len(a) == len(b) and all(_match(ai, bi) for ai, bi in zip(a, b))
332
+
333
+ return a == b
334
+
335
+
336
+ def _is_spm_decoder(decoder):
337
+ _target_description = {
338
+ "type": "Sequence",
339
+ "decoders": [
340
+ {"type": "Replace", "pattern": {"String": "▁"}, "content": " "},
341
+ {"type": "ByteFallback"},
342
+ {"type": "Fuse"},
343
+ {"type": "Strip", "content": " ", "start": 1, "stop": 0},
344
+ ],
345
+ }
346
+ return _match(_target_description, decoder)
347
+
348
+
349
+ def _is_spm_decoder_no_space(decoder):
350
+ _target_description = {
351
+ "type": "Sequence",
352
+ "decoders": [
353
+ {"type": "Replace", "pattern": {"String": "▁"}, "content": " "},
354
+ {"type": "ByteFallback"},
355
+ {"type": "Fuse"},
356
+ ],
357
+ }
358
+ return _match(_target_description, decoder)
359
+
360
+
361
+ def _is_bpe_decoder(decoder):
362
+ return isinstance(decoder, dict) and decoder.get("type", None) == "ByteLevel"
363
+
364
+
365
+ def load_tokenizer(
366
+ model_path, tokenizer_config_extra={}, return_tokenizer=True, eos_token_ids=None
367
+ ):
368
+ """Load a huggingface tokenizer and try to infer the type of streaming
369
+ detokenizer to use.
370
+
371
+ Note, to use a fast streaming tokenizer, pass a local file path rather than
372
+ a Hugging Face repo ID.
373
+ """
374
+ detokenizer_class = NaiveStreamingDetokenizer
375
+
376
+ tokenizer_file = model_path / "tokenizer.json"
377
+ if tokenizer_file.exists():
378
+ with open(tokenizer_file, "r", encoding="utf-8") as fid:
379
+ try:
380
+ tokenizer_content = json.load(fid)
381
+ except JSONDecodeError as e:
382
+ raise JSONDecodeError("Failed to parse tokenizer.json", e.doc, e.pos)
383
+
384
+ if "decoder" in tokenizer_content:
385
+ if _is_spm_decoder(tokenizer_content["decoder"]):
386
+ detokenizer_class = SPMStreamingDetokenizer
387
+ elif _is_spm_decoder_no_space(tokenizer_content["decoder"]):
388
+ detokenizer_class = partial(SPMStreamingDetokenizer, trim_space=False)
389
+ elif _is_bpe_decoder(tokenizer_content["decoder"]):
390
+ detokenizer_class = BPEStreamingDetokenizer
391
+
392
+ if isinstance(eos_token_ids, int):
393
+ eos_token_ids = [eos_token_ids]
394
+
395
+ if return_tokenizer:
396
+ return TokenizerWrapper(
397
+ AutoTokenizer.from_pretrained(model_path, **tokenizer_config_extra),
398
+ detokenizer_class,
399
+ eos_token_ids=eos_token_ids,
400
+ )
401
+ else:
402
+ return detokenizer_class
403
+
404
+
405
+ def no_bos_or_eos(sequence: List, bos: int, eos: int) -> List:
406
+ removed_bos = sequence if sequence[0] != bos else sequence[1:]
407
+ return removed_bos[:-1] if removed_bos[-1] == eos else removed_bos