nexaai 1.0.19rc7__cp310-cp310-macosx_14_0_universal2.whl → 1.0.19rc8__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 (196) 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-1.0.19rc7.dist-info → nexaai-1.0.19rc8.dist-info}/METADATA +1 -1
  5. {nexaai-1.0.19rc7.dist-info → nexaai-1.0.19rc8.dist-info}/RECORD +7 -196
  6. nexaai/binds/nexa_mlx/py-lib/asr/__init__.py +0 -12
  7. nexaai/binds/nexa_mlx/py-lib/asr/interface.py +0 -122
  8. nexaai/binds/nexa_mlx/py-lib/common/__init__.py +0 -0
  9. nexaai/binds/nexa_mlx/py-lib/common/utils.py +0 -25
  10. nexaai/binds/nexa_mlx/py-lib/cv/__init__.py +0 -0
  11. nexaai/binds/nexa_mlx/py-lib/cv/generate.py +0 -195
  12. nexaai/binds/nexa_mlx/py-lib/cv/interface.py +0 -151
  13. nexaai/binds/nexa_mlx/py-lib/cv/main.py +0 -81
  14. nexaai/binds/nexa_mlx/py-lib/cv/modeling/pp_ocr_v4.py +0 -1736
  15. nexaai/binds/nexa_mlx/py-lib/embedding/__init__.py +0 -0
  16. nexaai/binds/nexa_mlx/py-lib/embedding/generate.py +0 -333
  17. nexaai/binds/nexa_mlx/py-lib/embedding/interface.py +0 -617
  18. nexaai/binds/nexa_mlx/py-lib/embedding/main.py +0 -173
  19. nexaai/binds/nexa_mlx/py-lib/embedding/modeling/__init__.py +0 -0
  20. nexaai/binds/nexa_mlx/py-lib/embedding/modeling/nexa_jina_v2.py +0 -399
  21. nexaai/binds/nexa_mlx/py-lib/image_gen/__init__.py +0 -1
  22. nexaai/binds/nexa_mlx/py-lib/image_gen/generate_sd.py +0 -244
  23. nexaai/binds/nexa_mlx/py-lib/image_gen/interface.py +0 -82
  24. nexaai/binds/nexa_mlx/py-lib/image_gen/main.py +0 -281
  25. nexaai/binds/nexa_mlx/py-lib/image_gen/stable_diffusion/__init__.py +0 -306
  26. nexaai/binds/nexa_mlx/py-lib/image_gen/stable_diffusion/clip.py +0 -116
  27. nexaai/binds/nexa_mlx/py-lib/image_gen/stable_diffusion/config.py +0 -65
  28. nexaai/binds/nexa_mlx/py-lib/image_gen/stable_diffusion/model_io.py +0 -386
  29. nexaai/binds/nexa_mlx/py-lib/image_gen/stable_diffusion/sampler.py +0 -105
  30. nexaai/binds/nexa_mlx/py-lib/image_gen/stable_diffusion/tokenizer.py +0 -100
  31. nexaai/binds/nexa_mlx/py-lib/image_gen/stable_diffusion/unet.py +0 -460
  32. nexaai/binds/nexa_mlx/py-lib/image_gen/stable_diffusion/vae.py +0 -274
  33. nexaai/binds/nexa_mlx/py-lib/llm/__init__.py +0 -0
  34. nexaai/binds/nexa_mlx/py-lib/llm/generate.py +0 -149
  35. nexaai/binds/nexa_mlx/py-lib/llm/interface.py +0 -764
  36. nexaai/binds/nexa_mlx/py-lib/llm/main.py +0 -68
  37. nexaai/binds/nexa_mlx/py-lib/rerank/__init__.py +0 -0
  38. nexaai/binds/nexa_mlx/py-lib/rerank/generate.py +0 -174
  39. nexaai/binds/nexa_mlx/py-lib/rerank/interface.py +0 -287
  40. nexaai/binds/nexa_mlx/py-lib/rerank/main.py +0 -127
  41. nexaai/binds/nexa_mlx/py-lib/rerank/modeling/__init__.py +0 -0
  42. nexaai/binds/nexa_mlx/py-lib/rerank/modeling/nexa_jina_rerank.py +0 -330
  43. nexaai/binds/nexa_mlx/py-lib/sd/__init__.py +0 -1
  44. nexaai/binds/nexa_mlx/py-lib/sd/interface.py +0 -362
  45. nexaai/binds/nexa_mlx/py-lib/sd/main.py +0 -286
  46. nexaai/binds/nexa_mlx/py-lib/sd/modeling/__init__.py +0 -306
  47. nexaai/binds/nexa_mlx/py-lib/sd/modeling/clip.py +0 -116
  48. nexaai/binds/nexa_mlx/py-lib/sd/modeling/config.py +0 -65
  49. nexaai/binds/nexa_mlx/py-lib/sd/modeling/model_io.py +0 -385
  50. nexaai/binds/nexa_mlx/py-lib/sd/modeling/sampler.py +0 -105
  51. nexaai/binds/nexa_mlx/py-lib/sd/modeling/tokenizer.py +0 -100
  52. nexaai/binds/nexa_mlx/py-lib/sd/modeling/unet.py +0 -460
  53. nexaai/binds/nexa_mlx/py-lib/sd/modeling/vae.py +0 -274
  54. nexaai/binds/nexa_mlx/py-lib/tts/__init__.py +0 -12
  55. nexaai/binds/nexa_mlx/py-lib/tts/interface.py +0 -276
  56. nexaai/binds/nexa_mlx/py-lib/vlm/__init__.py +0 -3
  57. nexaai/binds/nexa_mlx/py-lib/vlm/generate.py +0 -572
  58. nexaai/binds/nexa_mlx/py-lib/vlm/generate_qwen3_vl.py +0 -294
  59. nexaai/binds/nexa_mlx/py-lib/vlm/generate_qwen3_vl_moe.py +0 -276
  60. nexaai/binds/nexa_mlx/py-lib/vlm/interface.py +0 -504
  61. nexaai/binds/nexa_mlx/py-lib/vlm/main.py +0 -320
  62. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/__init__.py +0 -0
  63. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/convert.py +0 -68
  64. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/__init__.py +0 -0
  65. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/aya_vision/__init__.py +0 -8
  66. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/aya_vision/aya_vision.py +0 -193
  67. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/aya_vision/interpolate.py +0 -186
  68. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/aya_vision/language.py +0 -233
  69. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/aya_vision/vision.py +0 -503
  70. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/base.py +0 -202
  71. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/cache.py +0 -230
  72. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/deepseek_vl_v2/__init__.py +0 -10
  73. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/deepseek_vl_v2/conversation.py +0 -264
  74. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/deepseek_vl_v2/deepseek_vl_v2.py +0 -472
  75. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/deepseek_vl_v2/language.py +0 -591
  76. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/deepseek_vl_v2/processing_deepsek_vl_v2.py +0 -526
  77. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/deepseek_vl_v2/vision.py +0 -356
  78. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/florence2/__init__.py +0 -8
  79. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/florence2/florence2.py +0 -366
  80. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/florence2/language.py +0 -488
  81. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/florence2/vision.py +0 -591
  82. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3/__init__.py +0 -8
  83. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3/gemma3.py +0 -213
  84. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3/language.py +0 -315
  85. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3/vision.py +0 -238
  86. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3n/__init__.py +0 -2
  87. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3n/audio.py +0 -1038
  88. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3n/config.py +0 -139
  89. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3n/gemma3n.py +0 -322
  90. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3n/language.py +0 -629
  91. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/gemma3n/vision.py +0 -1022
  92. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/idefics2/__init__.py +0 -9
  93. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/idefics2/idefics2.py +0 -294
  94. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/idefics2/language.py +0 -191
  95. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/idefics2/vision.py +0 -267
  96. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/idefics3/__init__.py +0 -8
  97. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/idefics3/idefics3.py +0 -175
  98. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/idefics3/language.py +0 -192
  99. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/idefics3/vision.py +0 -233
  100. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/internvl_chat/__init__.py +0 -9
  101. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/internvl_chat/internvl_chat.py +0 -140
  102. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/internvl_chat/language.py +0 -220
  103. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/internvl_chat/processor.py +0 -393
  104. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/internvl_chat/vision.py +0 -293
  105. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/kernels.py +0 -307
  106. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/kimi_vl/__init__.py +0 -8
  107. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/kimi_vl/kimi_vl.py +0 -143
  108. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/kimi_vl/language.py +0 -509
  109. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/kimi_vl/vision.py +0 -522
  110. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llama4/__init__.py +0 -8
  111. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llama4/language.py +0 -386
  112. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llama4/llama4.py +0 -138
  113. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llama4/vision.py +0 -560
  114. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava/__init__.py +0 -8
  115. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava/language.py +0 -240
  116. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava/llava.py +0 -153
  117. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava/vision.py +0 -259
  118. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava_bunny/__init__.py +0 -9
  119. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava_bunny/language.py +0 -236
  120. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava_bunny/llava_bunny.py +0 -256
  121. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava_bunny/vision.py +0 -303
  122. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava_next/__init__.py +0 -8
  123. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava_next/language.py +0 -230
  124. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava_next/llava_next.py +0 -160
  125. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/llava_next/vision.py +0 -243
  126. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/mistral3/__init__.py +0 -8
  127. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/mistral3/mistral3.py +0 -283
  128. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/mllama/__init__.py +0 -8
  129. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/mllama/language.py +0 -416
  130. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/mllama/mllama.py +0 -172
  131. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/mllama/vision.py +0 -499
  132. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/molmo/__init__.py +0 -8
  133. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/molmo/language.py +0 -243
  134. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/molmo/molmo.py +0 -133
  135. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/molmo/vision.py +0 -465
  136. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/multi_modality/__init__.py +0 -10
  137. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/multi_modality/language.py +0 -230
  138. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/multi_modality/multi_modality.py +0 -385
  139. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/multi_modality/sam.py +0 -557
  140. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/multi_modality/vision.py +0 -526
  141. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/paligemma/__init__.py +0 -8
  142. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/paligemma/language.py +0 -282
  143. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/paligemma/paligemma.py +0 -160
  144. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/paligemma/vision.py +0 -242
  145. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/phi3_v/__init__.py +0 -8
  146. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/phi3_v/language.py +0 -21
  147. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/phi3_v/phi3_v.py +0 -243
  148. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/phi3_v/su_rope.py +0 -71
  149. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/phi3_v/vision.py +0 -324
  150. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/pixtral/__init__.py +0 -8
  151. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/pixtral/language.py +0 -229
  152. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/pixtral/pixtral.py +0 -161
  153. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/pixtral/vision.py +0 -320
  154. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_5_vl/__init__.py +0 -2
  155. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_5_vl/config.py +0 -108
  156. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_5_vl/language.py +0 -490
  157. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_5_vl/qwen2_5_vl.py +0 -168
  158. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_5_vl/vision.py +0 -414
  159. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_vl/__init__.py +0 -2
  160. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_vl/config.py +0 -104
  161. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_vl/language.py +0 -490
  162. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_vl/qwen2_vl.py +0 -167
  163. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen2_vl/vision.py +0 -312
  164. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3_vl/llm_common/__init__.py +0 -0
  165. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3_vl/llm_common/base.py +0 -117
  166. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3_vl/llm_common/cache.py +0 -531
  167. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3_vl/llm_common/generate.py +0 -701
  168. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3_vl/llm_common/rope_utils.py +0 -255
  169. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3_vl/llm_common/sample_utils.py +0 -303
  170. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3_vl/llm_common/tokenizer_utils.py +0 -407
  171. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3_vl/processor.py +0 -476
  172. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3_vl/qwen3vl.py +0 -1223
  173. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/llm_common/__init__.py +0 -0
  174. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/llm_common/base.py +0 -117
  175. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/llm_common/cache.py +0 -531
  176. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/llm_common/generate.py +0 -701
  177. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/llm_common/rope_utils.py +0 -255
  178. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/llm_common/sample_utils.py +0 -303
  179. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/llm_common/tokenizer_utils.py +0 -407
  180. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/processor.py +0 -476
  181. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/qwen3vl_moe.py +0 -1309
  182. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/qwen3vl_moe/switch_layers.py +0 -210
  183. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/smolvlm/__init__.py +0 -8
  184. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/models/smolvlm/smolvlm.py +0 -62
  185. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/processing_qwen2_5_vl.py +0 -209
  186. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/processing_qwen2_vl.py +0 -215
  187. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/prompt_utils.py +0 -474
  188. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/sample_utils.py +0 -39
  189. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/tokenizer_utils.py +0 -344
  190. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/trainer/__init__.py +0 -9
  191. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/trainer/lora.py +0 -70
  192. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/trainer/trainer.py +0 -296
  193. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/trainer/utils.py +0 -160
  194. nexaai/binds/nexa_mlx/py-lib/vlm/modeling/utils.py +0 -928
  195. {nexaai-1.0.19rc7.dist-info → nexaai-1.0.19rc8.dist-info}/WHEEL +0 -0
  196. {nexaai-1.0.19rc7.dist-info → nexaai-1.0.19rc8.dist-info}/top_level.txt +0 -0
@@ -1,320 +0,0 @@
1
- from .interface import VLM
2
- from ml import GenerationConfig, SamplerConfig, ChatMessage
3
- import re
4
- import os
5
- import codecs
6
- import argparse
7
-
8
- def parse_media_from_input(user_input):
9
- """Parse quoted media files from user input and return prompt and media paths"""
10
- # Find all quoted strings (both single and double quotes)
11
- quoted_pattern = r'["\']([^"\']*)["\']'
12
- quoted_matches = re.findall(quoted_pattern, user_input)
13
-
14
- # Remove quoted strings from the input to get the actual prompt
15
- prompt = re.sub(quoted_pattern, '', user_input).strip()
16
-
17
- # Separate image and audio files based on extensions
18
- image_extensions = {'.png', '.jpg', '.jpeg', '.gif', '.bmp', '.tiff', '.webp'}
19
- audio_extensions = {'.mp3', '.wav', '.flac', '.aac', '.ogg', '.m4a'}
20
-
21
- image_paths = []
22
- audio_paths = []
23
-
24
- for quoted_file in quoted_matches:
25
- if quoted_file: # Skip empty quotes
26
- # Expand user path if it starts with ~
27
- if quoted_file.startswith('~'):
28
- quoted_file = os.path.expanduser(quoted_file)
29
-
30
- # Check if file exists
31
- if not os.path.exists(quoted_file):
32
- print(f"Warning: File '{quoted_file}' not found")
33
- continue
34
-
35
- file_ext = os.path.splitext(quoted_file.lower())[1]
36
- if file_ext in image_extensions:
37
- image_paths.append(quoted_file)
38
- elif file_ext in audio_extensions:
39
- audio_paths.append(quoted_file)
40
-
41
- return prompt, image_paths if image_paths else None, audio_paths if audio_paths else None
42
-
43
- def parse_arguments():
44
- """Parse command line arguments for the VLM main function."""
45
- parser = argparse.ArgumentParser(
46
- description="Interactive VLM (Vision-Language Model) conversation interface."
47
- )
48
- parser.add_argument(
49
- "--model_path",
50
- type=str,
51
- default="mlx-community/gemma-3-4b-it-8bit",
52
- help="The path to the local model directory or Hugging Face repo."
53
- )
54
- parser.add_argument(
55
- "--model_name",
56
- type=str,
57
- default="",
58
- help="Specific model name/type (e.g., 'qwen3vl', 'qwen3vl-moe', 'gemma3'). If empty, auto-detect from model_path."
59
- )
60
- parser.add_argument(
61
- "--context_length",
62
- type=int,
63
- default=2048,
64
- help="Context length for the model (default: 2048)."
65
- )
66
- parser.add_argument(
67
- "--temperature",
68
- type=float,
69
- default=0.7,
70
- help="Sampling temperature (default: 0.7)."
71
- )
72
- parser.add_argument(
73
- "--top_p",
74
- type=float,
75
- default=0.9,
76
- help="Top-p sampling parameter (default: 0.9)."
77
- )
78
- parser.add_argument(
79
- "--max_tokens",
80
- type=int,
81
- default=512,
82
- help="Maximum tokens to generate (default: 512)."
83
- )
84
- return parser.parse_args()
85
-
86
- def main():
87
- """Main function for interactive VLM conversation."""
88
- args = parse_arguments()
89
-
90
- # Auto-detect model name if not provided
91
- model_name = args.model_name
92
-
93
- # TODO: avoid such hardcoded model name detection
94
- if not model_name:
95
- if "qwen3vl-30B" in args.model_path.lower():
96
- model_name = "qwen3vl-moe"
97
- elif "qwen3" in args.model_path.lower():
98
- model_name = "qwen3vl"
99
- elif "gemma" in args.model_path.lower():
100
- model_name = "gemma3"
101
- else:
102
- model_name = ""
103
-
104
- # Load the VLM instance
105
- vlm = VLM(
106
- model_name=model_name,
107
- model_path=args.model_path,
108
- mmproj_path=None, # Not needed for this model
109
- context_length=args.context_length,
110
- device=None
111
- )
112
-
113
- # Configure sampler
114
- sampler_config = SamplerConfig(
115
- temperature=args.temperature,
116
- top_p=args.top_p
117
- )
118
- vlm.set_sampler(sampler_config)
119
-
120
- # Chat history using ChatMessage objects
121
- chat = []
122
-
123
- print("VLM Multi-round conversation started. Type 'quit' or 'exit' to end.")
124
- print("Include images/audios in quotes, e.g.: 'describe \"image1.jpg\" \"image2.png\"'")
125
- print("You can also use single quotes: 'describe '/path/to/image.jpg''")
126
- print("=" * 50)
127
-
128
- def on_token(text_chunk):
129
- """Token callback for streaming"""
130
- print(text_chunk, end="", flush=True)
131
- return True
132
-
133
- while True:
134
- # Get user input
135
- user_input = input("\nUser: ").strip()
136
-
137
- # Check for exit commands
138
- if user_input.lower() in ["quit", "exit", "q"]:
139
- print("Goodbye!")
140
- break
141
-
142
- if not user_input:
143
- continue
144
-
145
- # Parse media files and prompt from user input
146
- prompt_text, image_paths, audio_paths = parse_media_from_input(user_input)
147
-
148
- # If no text prompt after parsing, use the original input
149
- if not prompt_text.strip():
150
- prompt_text = user_input
151
- image_paths = None
152
- audio_paths = None
153
-
154
- # Add user message to chat history using ChatMessage
155
- chat.append(ChatMessage(role="user", content=prompt_text))
156
-
157
- # Calculate number of images and audios for chat template
158
- num_images = len(image_paths) if image_paths else 0
159
- num_audios = len(audio_paths) if audio_paths else 0
160
-
161
- # Apply chat template with image/audio token insertion
162
- try:
163
- formatted_prompt = vlm.apply_chat_template_with_media(chat, num_images=num_images, num_audios=num_audios)
164
- except (NotImplementedError, AttributeError):
165
- # Fallback to manual formatting if chat template is not implemented
166
- formatted_prompt = ""
167
- for msg in chat:
168
- formatted_prompt += f"{msg.role}: {msg.content}\n"
169
- formatted_prompt += "Assistant: "
170
-
171
- # Generation config with media paths
172
- generation_config = GenerationConfig(
173
- max_tokens=args.max_tokens,
174
- sampler_config=sampler_config,
175
- image_paths=image_paths,
176
- audio_paths=audio_paths
177
- )
178
-
179
- # Generate response
180
- print("Assistant: ", end="", flush=True)
181
-
182
- try:
183
- # Use streaming generation with callback
184
- response_text = ""
185
-
186
- def token_callback(text_chunk):
187
- nonlocal response_text
188
- print(text_chunk, end="", flush=True)
189
- response_text += text_chunk
190
- return True
191
-
192
- # Use generate_stream method for streaming generation
193
- response = vlm.generate_stream(
194
- prompt=formatted_prompt,
195
- config=generation_config,
196
- on_token=token_callback
197
- )
198
-
199
- print() # New line after streaming
200
-
201
- # Add assistant response to chat history using ChatMessage
202
- chat.append(ChatMessage(role="assistant", content=response_text))
203
-
204
- except Exception as e:
205
- print(f"Error generating response: {e}")
206
- print()
207
-
208
- # Clean up
209
- vlm.destroy()
210
-
211
- def test_vlm_generate_stream(model_path, model_name):
212
- # Specify the checkpoint
213
- context_length = 2048
214
-
215
- # Load the corresponding model and VLM instance
216
- vlm = VLM(
217
- model_name=model_name,
218
- model_path=model_path,
219
- mmproj_path=None, # Not needed for this model
220
- context_length=context_length,
221
- device=None
222
- )
223
-
224
- # Configure sampler
225
- sampler_config = SamplerConfig(
226
- temperature=0.7,
227
- top_p=0.9
228
- )
229
- vlm.set_sampler(sampler_config)
230
-
231
- # Chat history using ChatMessage objects (following ml.py API)
232
- chat = []
233
-
234
- print("Multi-round VLM conversation started. Type 'quit' or 'exit' to end.")
235
- print("Include images/audios in quotes, e.g.: 'describe \"image1.jpg\" \"image2.png\"'")
236
- print("You can also use single quotes: 'describe '/path/to/image.jpg''")
237
- print("=" * 50)
238
-
239
- def on_token(text_chunk, user_data):
240
- """Token callback for streaming"""
241
- print(text_chunk, end="", flush=True)
242
- if user_data is not None:
243
- user_data["response"] += text_chunk
244
- return True
245
-
246
- while True:
247
- # Get user input
248
- user_input = input("\nUser: ").strip()
249
-
250
- # Check for exit commands
251
- if user_input.lower() in ["quit", "exit", "q"]:
252
- print("Goodbye!")
253
- break
254
-
255
- if not user_input:
256
- continue
257
-
258
- # Parse media files and prompt from user input
259
- prompt_text, image_paths, audio_paths = parse_media_from_input(user_input)
260
-
261
- # If no text prompt after parsing, use the original input
262
- if not prompt_text.strip():
263
- prompt_text = user_input
264
- image_paths = None
265
- audio_paths = None
266
-
267
- # Add user message to chat history using ChatMessage (following ml.py API)
268
- chat.append(ChatMessage(role="user", content=prompt_text))
269
-
270
- # Calculate number of images and audios for chat template
271
- num_images = len(image_paths) if image_paths else 0
272
- num_audios = len(audio_paths) if audio_paths else 0
273
-
274
- # Apply chat template with image/audio token insertion
275
- try:
276
- formatted_prompt = vlm.apply_chat_template_with_media(chat, num_images=num_images, num_audios=num_audios)
277
- except (NotImplementedError, AttributeError):
278
- # Fallback to manual formatting if chat template is not implemented
279
- formatted_prompt = ""
280
- for msg in chat:
281
- formatted_prompt += f"{msg.role}: {msg.content}\n"
282
- formatted_prompt += "Assistant: "
283
-
284
- # Generation config with media paths
285
- generation_config = GenerationConfig(
286
- max_tokens=512,
287
- sampler_config=sampler_config,
288
- image_paths=image_paths,
289
- audio_paths=audio_paths
290
- )
291
-
292
- # Generate response
293
- print("Assistant: ", end="", flush=True)
294
-
295
- try:
296
- # Use streaming generation with callback - single method handles all cases
297
- user_data = {"response": ""}
298
-
299
- # Always use the unified generate_stream method
300
- response = vlm.generate_stream(
301
- prompt=formatted_prompt,
302
- config=generation_config,
303
- on_token=on_token,
304
- user_data=user_data
305
- )
306
-
307
- print() # New line after streaming
308
-
309
- # Add assistant response to chat history using ChatMessage
310
- chat.append(ChatMessage(role="assistant", content=user_data["response"]))
311
-
312
- except Exception as e:
313
- print(f"Error generating response: {e}")
314
- print()
315
-
316
- # Clean up
317
- vlm.destroy()
318
-
319
- if __name__ == "__main__":
320
- main()
File without changes
@@ -1,68 +0,0 @@
1
- # Copyright © 2023-2024 Apple Inc.
2
-
3
- import argparse
4
-
5
- from .utils import MODEL_CONVERSION_DTYPES, convert
6
-
7
-
8
- def configure_parser() -> argparse.ArgumentParser:
9
- """
10
- Configures and returns the argument parser for the script.
11
-
12
- Returns:
13
- argparse.ArgumentParser: Configured argument parser.
14
- """
15
- parser = argparse.ArgumentParser(
16
- description="Convert Hugging Face model to MLX format"
17
- )
18
-
19
- parser.add_argument("--hf-path", type=str, help="Path to the Hugging Face model.")
20
- parser.add_argument(
21
- "--mlx-path", type=str, default="mlx_model", help="Path to save the MLX model."
22
- )
23
- parser.add_argument(
24
- "-q", "--quantize", help="Generate a quantized model.", action="store_true"
25
- )
26
- parser.add_argument(
27
- "--q-group-size", help="Group size for quantization.", type=int, default=64
28
- )
29
- parser.add_argument(
30
- "--q-bits", help="Bits per weight for quantization.", type=int, default=4
31
- )
32
- parser.add_argument(
33
- "--dtype",
34
- help="Type to save the parameter. Defaults to config.json's `torch_dtype` or the current model weights dtype",
35
- type=str,
36
- choices=MODEL_CONVERSION_DTYPES,
37
- default=None,
38
- )
39
- parser.add_argument(
40
- "--upload-repo",
41
- help="The Hugging Face repo to upload the model to.",
42
- type=str,
43
- default=None,
44
- )
45
- parser.add_argument(
46
- "-d",
47
- "--dequantize",
48
- help="Dequantize a quantized model.",
49
- action="store_true",
50
- default=False,
51
- )
52
- parser.add_argument(
53
- "--skip-vision",
54
- help="Skip vision module quantization.",
55
- action="store_true",
56
- default=False,
57
- )
58
- return parser
59
-
60
-
61
- def main():
62
- parser = configure_parser()
63
- args = parser.parse_args()
64
- convert(**vars(args))
65
-
66
-
67
- if __name__ == "__main__":
68
- main()
@@ -1,8 +0,0 @@
1
- from .aya_vision import (
2
- LanguageModel,
3
- Model,
4
- ModelConfig,
5
- TextConfig,
6
- VisionConfig,
7
- VisionModel,
8
- )
@@ -1,193 +0,0 @@
1
- import glob
2
- import inspect
3
- import json
4
- from dataclasses import dataclass
5
- from pathlib import Path
6
- from typing import List, Optional
7
-
8
- import mlx.core as mx
9
- import mlx.nn as nn
10
- import numpy as np
11
- from mlx_lm.utils import snapshot_download
12
-
13
- from .language import LanguageModel, TextConfig
14
- from .vision import VisionConfig, VisionModel
15
-
16
-
17
- @dataclass
18
- class ModelConfig:
19
- text_config: TextConfig
20
- vision_config: VisionConfig
21
- model_type: str
22
- image_token_index: int = 255036
23
- max_splits_per_img: int = 12
24
- downsample_factor: int = 2
25
- alignment_intermediate_size: int = 28672
26
- adapter_layer_norm_eps: float = 1e-06
27
- vision_feature_layer: int = -1
28
- vision_feature_select_strategy: str = "full"
29
- eos_token_id: Optional[List[int]] = None
30
-
31
- @classmethod
32
- def from_dict(cls, params):
33
- return cls(
34
- **{
35
- k: v
36
- for k, v in params.items()
37
- if k in inspect.signature(cls).parameters
38
- }
39
- )
40
-
41
-
42
- class AyaVisionMultiModalProjector(nn.Module):
43
- def __init__(self, config: ModelConfig):
44
- super().__init__()
45
- self.config = config
46
- self.downsample_factor = config.downsample_factor
47
- self.alignment_intermediate_size = getattr(
48
- config, "alignment_intermediate_size", config.text_config.hidden_size
49
- )
50
- self.layernorm = nn.LayerNorm(
51
- config.vision_config.hidden_size * (config.downsample_factor**2),
52
- eps=config.adapter_layer_norm_eps,
53
- )
54
-
55
- self.linear_1 = nn.Linear(
56
- config.vision_config.hidden_size * (config.downsample_factor**2),
57
- self.alignment_intermediate_size,
58
- bias=True,
59
- )
60
-
61
- self.act = nn.SiLU() # SwiGLU uses SiLU activation
62
-
63
- # For SwiGLU, project down to half size since we split intermediate dim
64
- self.linear_2 = nn.Linear(
65
- self.alignment_intermediate_size // 2,
66
- config.text_config.hidden_size,
67
- bias=True,
68
- )
69
-
70
- def __call__(self, image_features):
71
- image_features = self.pixel_shuffle(image_features)
72
- image_features = self.layernorm(image_features)
73
- hidden_states = self.linear_1(image_features)
74
-
75
- # Split along last dimension and apply SwiGLU
76
- x, gate = mx.split(hidden_states, 2, axis=-1)
77
- hidden_states = self.act(gate) * x
78
-
79
- hidden_states = self.linear_2(hidden_states)
80
- return hidden_states
81
-
82
- def pixel_shuffle(self, image_features): # B, S, D
83
- batch_size, seq_length, feature_dim = image_features.shape
84
- height = width = int(seq_length**0.5)
85
- image_features = image_features.reshape(
86
- image_features.shape[0], width, height, -1
87
- )
88
- channels = image_features.shape[-1]
89
- image_features = image_features.reshape(
90
- batch_size,
91
- width,
92
- int(height / self.downsample_factor),
93
- int(channels * self.downsample_factor),
94
- )
95
- image_features = image_features.transpose(0, 2, 1, 3)
96
- image_features = image_features.reshape(
97
- batch_size,
98
- int(height / self.downsample_factor),
99
- int(width / self.downsample_factor),
100
- -1,
101
- )
102
- image_features = image_features.transpose(0, 2, 1, 3)
103
- return image_features
104
-
105
-
106
- class Model(nn.Module):
107
- def __init__(self, config: ModelConfig):
108
- super().__init__()
109
- self.config = config
110
- self.vision_tower = VisionModel(config.vision_config)
111
- self.language_model = LanguageModel(config.text_config)
112
- self.multi_modal_projector = AyaVisionMultiModalProjector(config)
113
- self.vision_feature_layer = config.vision_feature_layer
114
- self.vision_feature_select_strategy = config.vision_feature_select_strategy
115
-
116
- def get_input_embeddings(
117
- self,
118
- input_ids: Optional[mx.array] = None,
119
- pixel_values: Optional[mx.array] = None,
120
- **kwargs,
121
- ):
122
- if pixel_values is None:
123
- return self.language_model.model.embed_tokens(input_ids)
124
-
125
- # Get the input embeddings from the language model
126
- inputs_embeds = self.language_model.model.embed_tokens(input_ids)
127
-
128
- spatial_shapes = kwargs.get("spatial_shapes", None)
129
- # Get the ouptut hidden states from the vision model
130
- *_, hidden_states = self.vision_tower(
131
- pixel_values.transpose(0, 2, 3, 1),
132
- spatial_shapes=spatial_shapes,
133
- output_hidden_states=True,
134
- )
135
-
136
- # Select the hidden states from the desired layer
137
- selected_image_feature = hidden_states[self.vision_feature_layer]
138
-
139
- if self.vision_feature_select_strategy == "default":
140
- selected_image_feature = selected_image_feature[:, 1:]
141
- elif self.vision_feature_select_strategy == "full":
142
- selected_image_feature = selected_image_feature
143
- else:
144
- raise ValueError(
145
- "Unexpected feature selection strategy: "
146
- f"{self.vision_feature_select_strategy}"
147
- )
148
-
149
- # Pass image features through the multi-modal projector
150
- image_features = self.multi_modal_projector(selected_image_feature)
151
-
152
- # Insert special image tokens in the input_ids
153
- final_inputs_embeds = self._merge_input_ids_with_image_features(
154
- image_features, inputs_embeds, input_ids
155
- )
156
- return final_inputs_embeds
157
-
158
- def _merge_input_ids_with_image_features(
159
- self, image_features, inputs_embeds, input_ids
160
- ):
161
- image_token_index = self.config.image_token_index
162
-
163
- # Positions of <image> tokens in input_ids, assuming batch size is 1
164
- image_positions = np.where(input_ids[0] == image_token_index)[0].tolist()
165
- num_images, _, _, vision_hidden_size = image_features.shape
166
-
167
- reshaped_image_hidden_states = image_features.reshape(-1, vision_hidden_size)
168
-
169
- # cast to the dtype of the input_embeds to support quantized models
170
- reshaped_image_hidden_states = reshaped_image_hidden_states.astype(
171
- inputs_embeds.dtype
172
- )
173
- inputs_embeds[:, image_positions, :] = reshaped_image_hidden_states
174
- return inputs_embeds
175
-
176
- @property
177
- def layers(self):
178
- return self.language_model.model.layers
179
-
180
- def __call__(
181
- self,
182
- input_ids: mx.array,
183
- pixel_values: mx.array,
184
- mask: mx.array,
185
- cache=None,
186
- **kwargs,
187
- ):
188
-
189
- input_embddings = self.get_input_embeddings(input_ids, pixel_values, **kwargs)
190
- logits = self.language_model(
191
- input_ids, cache=cache, inputs_embeds=input_embddings
192
- )
193
- return logits