nexaai 1.0.29__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.
- nexaai/__init__.py +99 -0
- nexaai/_stub.cpython-310-darwin.so +0 -0
- nexaai/_version.py +4 -0
- nexaai/asr.py +68 -0
- nexaai/asr_impl/__init__.py +0 -0
- nexaai/asr_impl/mlx_asr_impl.py +93 -0
- nexaai/asr_impl/pybind_asr_impl.py +127 -0
- nexaai/base.py +39 -0
- nexaai/binds/__init__.py +7 -0
- nexaai/binds/asr_bind.cpython-310-darwin.so +0 -0
- nexaai/binds/common_bind.cpython-310-darwin.so +0 -0
- nexaai/binds/cpu_gpu/libggml-base.dylib +0 -0
- nexaai/binds/cpu_gpu/libggml-cpu.so +0 -0
- nexaai/binds/cpu_gpu/libggml-metal.so +0 -0
- nexaai/binds/cpu_gpu/libggml.dylib +0 -0
- nexaai/binds/cpu_gpu/libmtmd.dylib +0 -0
- nexaai/binds/cpu_gpu/libnexa_cpu_gpu.dylib +0 -0
- nexaai/binds/cpu_gpu/libnexa_plugin.dylib +0 -0
- nexaai/binds/cv_bind.cpython-310-darwin.so +0 -0
- nexaai/binds/diarize_bind.cpython-310-darwin.so +0 -0
- nexaai/binds/embedder_bind.cpython-310-darwin.so +0 -0
- nexaai/binds/libnexa_bridge.dylib +0 -0
- nexaai/binds/llm_bind.cpython-310-darwin.so +0 -0
- nexaai/binds/metal/libnexa_plugin.dylib +0 -0
- nexaai/binds/metal/py-lib/ml.py +888 -0
- nexaai/binds/metal/py-lib/mlx_audio/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/__init__.py +5 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/bigvgan/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/bigvgan/activation.py +51 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/bigvgan/amp.py +96 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/bigvgan/bigvgan.py +149 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/bigvgan/conv.py +114 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/bigvgan/resample.py +177 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/descript/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/descript/base.py +228 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/descript/dac.py +285 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/descript/nn/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/descript/nn/layers.py +129 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/descript/nn/quantize.py +149 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/encodec/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/encodec/encodec.py +777 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/mimi/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/mimi/mimi.py +286 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/mimi/modules/__init__.py +20 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/mimi/modules/conv.py +398 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/mimi/modules/kv_cache.py +199 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/mimi/modules/quantization.py +179 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/mimi/modules/seanet.py +314 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/mimi/modules/transformer.py +256 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/s3/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/s3/model.py +260 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/s3/model_v2.py +383 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/s3/utils.py +122 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/snac/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/snac/attention.py +97 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/snac/layers.py +306 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/snac/snac.py +154 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/snac/vq.py +135 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/vocos/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/vocos/mel.py +33 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/vocos/vocos.py +359 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/tests/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/tests/test_bigvgan.py +54 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/tests/test_descript.py +109 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/tests/test_encodec.py +58 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/tests/test_mimi.py +22 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/tests/test_s3.py +25 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/tests/test_snac.py +40 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/tests/test_vocos.py +93 -0
- nexaai/binds/metal/py-lib/mlx_audio/server.py +525 -0
- nexaai/binds/metal/py-lib/mlx_audio/sts/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/sts/tests/test_voice_pipeline.py +156 -0
- nexaai/binds/metal/py-lib/mlx_audio/sts/voice_pipeline.py +327 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/generate.py +174 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/parakeet/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/parakeet/alignment.py +248 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/parakeet/attention.py +187 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/parakeet/audio.py +76 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/parakeet/conformer.py +331 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/parakeet/ctc.py +34 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/parakeet/parakeet.py +604 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/parakeet/rnnt.py +157 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/parakeet/tokenizer.py +2 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/wav2vec/feature_extractor.py +757 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/wav2vec/wav2vec.py +738 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/whisper/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/whisper/audio.py +82 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/whisper/decoding.py +742 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/whisper/timing.py +329 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/whisper/tokenizer.py +398 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/whisper/whisper.py +862 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/whisper/writers.py +268 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/tests/test_models.py +381 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/utils.py +195 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/audio_player.py +120 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/convert.py +71 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/generate.py +449 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/bark/__init__.py +4 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/bark/bark.py +528 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/bark/isftnet.py +12 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/bark/pipeline.py +442 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/base.py +84 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/dia/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/dia/audio.py +287 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/dia/config.py +256 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/dia/dia.py +592 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/dia/layers.py +870 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/__init__.py +3 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/attention.py +180 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/bigvgan.py +124 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/conformer.py +247 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/ecapa_tdnn/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/ecapa_tdnn/asp.py +59 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/ecapa_tdnn/ecapa_tdnn.py +91 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/ecapa_tdnn/se_res2net.py +132 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/ecapa_tdnn/tdnn.py +42 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/gpt2.py +38 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/indextts.py +412 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/mel.py +37 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/normalize.py +294 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/perceiver.py +62 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/interpolate.py +108 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/kokoro/__init__.py +4 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/kokoro/istftnet.py +979 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/kokoro/kokoro.py +331 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/kokoro/modules.py +659 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/kokoro/pipeline.py +453 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/kokoro/voice.py +113 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/llama/__init__.py +3 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/llama/llama.py +324 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/outetts/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/outetts/audio_processor.py +351 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/outetts/dac_interface.py +162 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/outetts/outetts.py +255 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/outetts/prompt_processor.py +181 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/outetts/tokens.py +36 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/sesame/__init__.py +3 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/sesame/attention.py +195 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/sesame/sesame.py +633 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/sesame/watermarking.py +105 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/audio_tokenizer.py +138 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/bicodec.py +269 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/blocks/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/blocks/sampler.py +111 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/encoder_decoder/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/encoder_decoder/feat_decoder.py +120 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/encoder_decoder/feat_encoder.py +136 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/encoder_decoder/wave_generator.py +113 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/finite_scalar_quantization.py +238 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/residual.py +209 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/residual_fsq.py +309 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/speaker/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/speaker/ecapa_tdnn.py +283 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/speaker/perceiver_encoder.py +326 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/speaker/pooling_layers.py +297 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/speaker/speaker_encoder.py +155 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/spark.py +382 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/utils/audio.py +220 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/utils/file.py +221 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/utils/token_parser.py +181 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/tests/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/tests/test_base.py +66 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/tests/test_convert.py +173 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/tests/test_interpolate.py +88 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/tests/test_models.py +974 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/utils.py +337 -0
- nexaai/binds/metal/py-lib/mlx_audio/utils.py +237 -0
- nexaai/binds/metal/py-lib/mlx_audio/version.py +1 -0
- nexaai/binds/metal/py-lib/profiling.py +239 -0
- nexaai/binds/nexaml/libfftw3.3.dylib +0 -0
- nexaai/binds/nexaml/libfftw3f.3.dylib +0 -0
- nexaai/binds/nexaml/libggml-base.dylib +0 -0
- nexaai/binds/nexaml/libggml-cpu.so +0 -0
- nexaai/binds/nexaml/libggml-metal.so +0 -0
- nexaai/binds/nexaml/libggml.dylib +0 -0
- nexaai/binds/nexaml/libmp3lame.0.dylib +0 -0
- nexaai/binds/nexaml/libmpg123.0.dylib +0 -0
- nexaai/binds/nexaml/libnexa-mm-process.dylib +0 -0
- nexaai/binds/nexaml/libnexa-sampling.dylib +0 -0
- nexaai/binds/nexaml/libnexa_plugin.dylib +0 -0
- nexaai/binds/nexaml/libnexaproc.dylib +0 -0
- nexaai/binds/nexaml/libomp.dylib +0 -0
- nexaai/binds/nexaml/libqwen3-vl.dylib +0 -0
- nexaai/binds/nexaml/libqwen3vl-vision.dylib +0 -0
- nexaai/binds/rerank_bind.cpython-310-darwin.so +0 -0
- nexaai/binds/vlm_bind.cpython-310-darwin.so +0 -0
- nexaai/common.py +106 -0
- nexaai/cv.py +95 -0
- nexaai/cv_impl/__init__.py +0 -0
- nexaai/cv_impl/mlx_cv_impl.py +91 -0
- nexaai/cv_impl/pybind_cv_impl.py +124 -0
- nexaai/diarize.py +80 -0
- nexaai/diarize_impl/__init__.py +1 -0
- nexaai/diarize_impl/pybind_diarize_impl.py +125 -0
- nexaai/embedder.py +73 -0
- nexaai/embedder_impl/__init__.py +0 -0
- nexaai/embedder_impl/mlx_embedder_impl.py +118 -0
- nexaai/embedder_impl/pybind_embedder_impl.py +96 -0
- nexaai/image_gen.py +141 -0
- nexaai/image_gen_impl/__init__.py +0 -0
- nexaai/image_gen_impl/mlx_image_gen_impl.py +292 -0
- nexaai/image_gen_impl/pybind_image_gen_impl.py +85 -0
- nexaai/llm.py +98 -0
- nexaai/llm_impl/__init__.py +0 -0
- nexaai/llm_impl/mlx_llm_impl.py +271 -0
- nexaai/llm_impl/pybind_llm_impl.py +238 -0
- nexaai/log.py +92 -0
- nexaai/mlx_backend/asr/__init__.py +12 -0
- nexaai/mlx_backend/asr/interface.py +122 -0
- nexaai/mlx_backend/common/__init__.py +0 -0
- nexaai/mlx_backend/common/utils.py +25 -0
- nexaai/mlx_backend/cv/__init__.py +0 -0
- nexaai/mlx_backend/cv/generate.py +195 -0
- nexaai/mlx_backend/cv/interface.py +162 -0
- nexaai/mlx_backend/cv/main.py +81 -0
- nexaai/mlx_backend/cv/modeling/pp_ocr_v4.py +1736 -0
- nexaai/mlx_backend/embedding/__init__.py +0 -0
- nexaai/mlx_backend/embedding/generate.py +333 -0
- nexaai/mlx_backend/embedding/interface.py +617 -0
- nexaai/mlx_backend/embedding/main.py +173 -0
- nexaai/mlx_backend/embedding/modeling/__init__.py +0 -0
- nexaai/mlx_backend/embedding/modeling/nexa_jina_v2.py +399 -0
- nexaai/mlx_backend/image_gen/__init__.py +1 -0
- nexaai/mlx_backend/image_gen/generate_sd.py +244 -0
- nexaai/mlx_backend/image_gen/interface.py +82 -0
- nexaai/mlx_backend/image_gen/main.py +281 -0
- nexaai/mlx_backend/image_gen/stable_diffusion/__init__.py +306 -0
- nexaai/mlx_backend/image_gen/stable_diffusion/clip.py +116 -0
- nexaai/mlx_backend/image_gen/stable_diffusion/config.py +65 -0
- nexaai/mlx_backend/image_gen/stable_diffusion/model_io.py +386 -0
- nexaai/mlx_backend/image_gen/stable_diffusion/sampler.py +105 -0
- nexaai/mlx_backend/image_gen/stable_diffusion/tokenizer.py +100 -0
- nexaai/mlx_backend/image_gen/stable_diffusion/unet.py +460 -0
- nexaai/mlx_backend/image_gen/stable_diffusion/vae.py +274 -0
- nexaai/mlx_backend/llm/__init__.py +0 -0
- nexaai/mlx_backend/llm/generate.py +149 -0
- nexaai/mlx_backend/llm/interface.py +764 -0
- nexaai/mlx_backend/llm/main.py +68 -0
- nexaai/mlx_backend/ml.py +888 -0
- nexaai/mlx_backend/mlx_audio/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/codec/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/codec/models/__init__.py +5 -0
- nexaai/mlx_backend/mlx_audio/codec/models/bigvgan/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/codec/models/bigvgan/activation.py +51 -0
- nexaai/mlx_backend/mlx_audio/codec/models/bigvgan/amp.py +96 -0
- nexaai/mlx_backend/mlx_audio/codec/models/bigvgan/bigvgan.py +149 -0
- nexaai/mlx_backend/mlx_audio/codec/models/bigvgan/conv.py +114 -0
- nexaai/mlx_backend/mlx_audio/codec/models/bigvgan/resample.py +177 -0
- nexaai/mlx_backend/mlx_audio/codec/models/descript/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/codec/models/descript/base.py +228 -0
- nexaai/mlx_backend/mlx_audio/codec/models/descript/dac.py +285 -0
- nexaai/mlx_backend/mlx_audio/codec/models/descript/nn/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/codec/models/descript/nn/layers.py +129 -0
- nexaai/mlx_backend/mlx_audio/codec/models/descript/nn/quantize.py +149 -0
- nexaai/mlx_backend/mlx_audio/codec/models/encodec/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/codec/models/encodec/encodec.py +777 -0
- nexaai/mlx_backend/mlx_audio/codec/models/mimi/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/codec/models/mimi/mimi.py +286 -0
- nexaai/mlx_backend/mlx_audio/codec/models/mimi/modules/__init__.py +20 -0
- nexaai/mlx_backend/mlx_audio/codec/models/mimi/modules/conv.py +398 -0
- nexaai/mlx_backend/mlx_audio/codec/models/mimi/modules/kv_cache.py +199 -0
- nexaai/mlx_backend/mlx_audio/codec/models/mimi/modules/quantization.py +179 -0
- nexaai/mlx_backend/mlx_audio/codec/models/mimi/modules/seanet.py +314 -0
- nexaai/mlx_backend/mlx_audio/codec/models/mimi/modules/transformer.py +256 -0
- nexaai/mlx_backend/mlx_audio/codec/models/s3/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/codec/models/s3/model.py +260 -0
- nexaai/mlx_backend/mlx_audio/codec/models/s3/model_v2.py +383 -0
- nexaai/mlx_backend/mlx_audio/codec/models/s3/utils.py +122 -0
- nexaai/mlx_backend/mlx_audio/codec/models/snac/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/codec/models/snac/attention.py +97 -0
- nexaai/mlx_backend/mlx_audio/codec/models/snac/layers.py +306 -0
- nexaai/mlx_backend/mlx_audio/codec/models/snac/snac.py +154 -0
- nexaai/mlx_backend/mlx_audio/codec/models/snac/vq.py +135 -0
- nexaai/mlx_backend/mlx_audio/codec/models/vocos/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/codec/models/vocos/mel.py +33 -0
- nexaai/mlx_backend/mlx_audio/codec/models/vocos/vocos.py +359 -0
- nexaai/mlx_backend/mlx_audio/codec/tests/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/codec/tests/test_bigvgan.py +54 -0
- nexaai/mlx_backend/mlx_audio/codec/tests/test_descript.py +109 -0
- nexaai/mlx_backend/mlx_audio/codec/tests/test_encodec.py +58 -0
- nexaai/mlx_backend/mlx_audio/codec/tests/test_mimi.py +22 -0
- nexaai/mlx_backend/mlx_audio/codec/tests/test_s3.py +25 -0
- nexaai/mlx_backend/mlx_audio/codec/tests/test_snac.py +40 -0
- nexaai/mlx_backend/mlx_audio/codec/tests/test_vocos.py +93 -0
- nexaai/mlx_backend/mlx_audio/server.py +525 -0
- nexaai/mlx_backend/mlx_audio/sts/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/sts/tests/test_voice_pipeline.py +156 -0
- nexaai/mlx_backend/mlx_audio/sts/voice_pipeline.py +327 -0
- nexaai/mlx_backend/mlx_audio/stt/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/stt/generate.py +174 -0
- nexaai/mlx_backend/mlx_audio/stt/models/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/stt/models/parakeet/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/stt/models/parakeet/alignment.py +248 -0
- nexaai/mlx_backend/mlx_audio/stt/models/parakeet/attention.py +187 -0
- nexaai/mlx_backend/mlx_audio/stt/models/parakeet/audio.py +76 -0
- nexaai/mlx_backend/mlx_audio/stt/models/parakeet/conformer.py +331 -0
- nexaai/mlx_backend/mlx_audio/stt/models/parakeet/ctc.py +34 -0
- nexaai/mlx_backend/mlx_audio/stt/models/parakeet/parakeet.py +604 -0
- nexaai/mlx_backend/mlx_audio/stt/models/parakeet/rnnt.py +157 -0
- nexaai/mlx_backend/mlx_audio/stt/models/parakeet/tokenizer.py +2 -0
- nexaai/mlx_backend/mlx_audio/stt/models/wav2vec/feature_extractor.py +757 -0
- nexaai/mlx_backend/mlx_audio/stt/models/wav2vec/wav2vec.py +738 -0
- nexaai/mlx_backend/mlx_audio/stt/models/whisper/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/stt/models/whisper/audio.py +82 -0
- nexaai/mlx_backend/mlx_audio/stt/models/whisper/decoding.py +742 -0
- nexaai/mlx_backend/mlx_audio/stt/models/whisper/timing.py +329 -0
- nexaai/mlx_backend/mlx_audio/stt/models/whisper/tokenizer.py +398 -0
- nexaai/mlx_backend/mlx_audio/stt/models/whisper/whisper.py +862 -0
- nexaai/mlx_backend/mlx_audio/stt/models/whisper/writers.py +268 -0
- nexaai/mlx_backend/mlx_audio/stt/tests/test_models.py +381 -0
- nexaai/mlx_backend/mlx_audio/stt/utils.py +195 -0
- nexaai/mlx_backend/mlx_audio/tts/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/tts/audio_player.py +120 -0
- nexaai/mlx_backend/mlx_audio/tts/convert.py +71 -0
- nexaai/mlx_backend/mlx_audio/tts/generate.py +449 -0
- nexaai/mlx_backend/mlx_audio/tts/models/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/tts/models/bark/__init__.py +4 -0
- nexaai/mlx_backend/mlx_audio/tts/models/bark/bark.py +528 -0
- nexaai/mlx_backend/mlx_audio/tts/models/bark/isftnet.py +12 -0
- nexaai/mlx_backend/mlx_audio/tts/models/bark/pipeline.py +442 -0
- nexaai/mlx_backend/mlx_audio/tts/models/base.py +84 -0
- nexaai/mlx_backend/mlx_audio/tts/models/dia/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/tts/models/dia/audio.py +287 -0
- nexaai/mlx_backend/mlx_audio/tts/models/dia/config.py +256 -0
- nexaai/mlx_backend/mlx_audio/tts/models/dia/dia.py +592 -0
- nexaai/mlx_backend/mlx_audio/tts/models/dia/layers.py +870 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/__init__.py +3 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/attention.py +180 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/bigvgan.py +124 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/conformer.py +247 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/ecapa_tdnn/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/ecapa_tdnn/asp.py +59 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/ecapa_tdnn/ecapa_tdnn.py +91 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/ecapa_tdnn/se_res2net.py +132 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/ecapa_tdnn/tdnn.py +42 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/gpt2.py +38 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/indextts.py +412 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/mel.py +37 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/normalize.py +294 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/perceiver.py +62 -0
- nexaai/mlx_backend/mlx_audio/tts/models/interpolate.py +108 -0
- nexaai/mlx_backend/mlx_audio/tts/models/kokoro/__init__.py +4 -0
- nexaai/mlx_backend/mlx_audio/tts/models/kokoro/istftnet.py +979 -0
- nexaai/mlx_backend/mlx_audio/tts/models/kokoro/kokoro.py +331 -0
- nexaai/mlx_backend/mlx_audio/tts/models/kokoro/modules.py +659 -0
- nexaai/mlx_backend/mlx_audio/tts/models/kokoro/pipeline.py +453 -0
- nexaai/mlx_backend/mlx_audio/tts/models/kokoro/voice.py +113 -0
- nexaai/mlx_backend/mlx_audio/tts/models/llama/__init__.py +3 -0
- nexaai/mlx_backend/mlx_audio/tts/models/llama/llama.py +324 -0
- nexaai/mlx_backend/mlx_audio/tts/models/outetts/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/tts/models/outetts/audio_processor.py +351 -0
- nexaai/mlx_backend/mlx_audio/tts/models/outetts/dac_interface.py +162 -0
- nexaai/mlx_backend/mlx_audio/tts/models/outetts/default_speaker.json +461 -0
- nexaai/mlx_backend/mlx_audio/tts/models/outetts/outetts.py +255 -0
- nexaai/mlx_backend/mlx_audio/tts/models/outetts/prompt_processor.py +181 -0
- nexaai/mlx_backend/mlx_audio/tts/models/outetts/tokens.py +36 -0
- nexaai/mlx_backend/mlx_audio/tts/models/sesame/__init__.py +3 -0
- nexaai/mlx_backend/mlx_audio/tts/models/sesame/attention.py +195 -0
- nexaai/mlx_backend/mlx_audio/tts/models/sesame/sesame.py +633 -0
- nexaai/mlx_backend/mlx_audio/tts/models/sesame/watermarking.py +105 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/audio_tokenizer.py +138 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/bicodec.py +269 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/blocks/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/blocks/sampler.py +111 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/encoder_decoder/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/encoder_decoder/feat_decoder.py +120 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/encoder_decoder/feat_encoder.py +136 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/encoder_decoder/wave_generator.py +113 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/finite_scalar_quantization.py +238 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/residual.py +209 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/residual_fsq.py +309 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/speaker/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/speaker/ecapa_tdnn.py +283 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/speaker/perceiver_encoder.py +326 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/speaker/pooling_layers.py +297 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/speaker/speaker_encoder.py +155 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/spark.py +382 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/utils/audio.py +220 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/utils/file.py +221 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/utils/token_parser.py +181 -0
- nexaai/mlx_backend/mlx_audio/tts/tests/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/tts/tests/test_base.py +66 -0
- nexaai/mlx_backend/mlx_audio/tts/tests/test_convert.py +173 -0
- nexaai/mlx_backend/mlx_audio/tts/tests/test_interpolate.py +88 -0
- nexaai/mlx_backend/mlx_audio/tts/tests/test_models.py +974 -0
- nexaai/mlx_backend/mlx_audio/tts/utils.py +337 -0
- nexaai/mlx_backend/mlx_audio/utils.py +237 -0
- nexaai/mlx_backend/mlx_audio/version.py +1 -0
- nexaai/mlx_backend/profiling.py +239 -0
- nexaai/mlx_backend/rerank/__init__.py +0 -0
- nexaai/mlx_backend/rerank/generate.py +174 -0
- nexaai/mlx_backend/rerank/interface.py +287 -0
- nexaai/mlx_backend/rerank/main.py +127 -0
- nexaai/mlx_backend/rerank/modeling/__init__.py +0 -0
- nexaai/mlx_backend/rerank/modeling/nexa_jina_rerank.py +330 -0
- nexaai/mlx_backend/sd/__init__.py +1 -0
- nexaai/mlx_backend/sd/interface.py +362 -0
- nexaai/mlx_backend/sd/main.py +286 -0
- nexaai/mlx_backend/sd/modeling/__init__.py +306 -0
- nexaai/mlx_backend/sd/modeling/clip.py +116 -0
- nexaai/mlx_backend/sd/modeling/config.py +65 -0
- nexaai/mlx_backend/sd/modeling/model_io.py +385 -0
- nexaai/mlx_backend/sd/modeling/sampler.py +105 -0
- nexaai/mlx_backend/sd/modeling/tokenizer.py +100 -0
- nexaai/mlx_backend/sd/modeling/unet.py +460 -0
- nexaai/mlx_backend/sd/modeling/vae.py +274 -0
- nexaai/mlx_backend/tts/__init__.py +12 -0
- nexaai/mlx_backend/tts/interface.py +276 -0
- nexaai/mlx_backend/vlm/__init__.py +3 -0
- nexaai/mlx_backend/vlm/generate.py +572 -0
- nexaai/mlx_backend/vlm/generate_qwen3_vl.py +374 -0
- nexaai/mlx_backend/vlm/generate_qwen3_vl_moe.py +259 -0
- nexaai/mlx_backend/vlm/interface.py +559 -0
- nexaai/mlx_backend/vlm/main.py +365 -0
- nexaai/mlx_backend/vlm/modeling/__init__.py +0 -0
- nexaai/mlx_backend/vlm/modeling/convert.py +68 -0
- nexaai/mlx_backend/vlm/modeling/models/__init__.py +0 -0
- nexaai/mlx_backend/vlm/modeling/models/aya_vision/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/aya_vision/aya_vision.py +193 -0
- nexaai/mlx_backend/vlm/modeling/models/aya_vision/interpolate.py +186 -0
- nexaai/mlx_backend/vlm/modeling/models/aya_vision/language.py +233 -0
- nexaai/mlx_backend/vlm/modeling/models/aya_vision/vision.py +503 -0
- nexaai/mlx_backend/vlm/modeling/models/base.py +202 -0
- nexaai/mlx_backend/vlm/modeling/models/cache.py +230 -0
- nexaai/mlx_backend/vlm/modeling/models/deepseek_vl_v2/__init__.py +10 -0
- nexaai/mlx_backend/vlm/modeling/models/deepseek_vl_v2/conversation.py +264 -0
- nexaai/mlx_backend/vlm/modeling/models/deepseek_vl_v2/deepseek_vl_v2.py +472 -0
- nexaai/mlx_backend/vlm/modeling/models/deepseek_vl_v2/language.py +591 -0
- nexaai/mlx_backend/vlm/modeling/models/deepseek_vl_v2/processing_deepsek_vl_v2.py +526 -0
- nexaai/mlx_backend/vlm/modeling/models/deepseek_vl_v2/vision.py +356 -0
- nexaai/mlx_backend/vlm/modeling/models/florence2/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/florence2/florence2.py +366 -0
- nexaai/mlx_backend/vlm/modeling/models/florence2/language.py +488 -0
- nexaai/mlx_backend/vlm/modeling/models/florence2/vision.py +591 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3/gemma3.py +213 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3/language.py +315 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3/vision.py +238 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3n/__init__.py +2 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3n/audio.py +1038 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3n/config.py +139 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3n/gemma3n.py +322 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3n/language.py +629 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3n/vision.py +1022 -0
- nexaai/mlx_backend/vlm/modeling/models/idefics2/__init__.py +9 -0
- nexaai/mlx_backend/vlm/modeling/models/idefics2/idefics2.py +294 -0
- nexaai/mlx_backend/vlm/modeling/models/idefics2/language.py +191 -0
- nexaai/mlx_backend/vlm/modeling/models/idefics2/vision.py +267 -0
- nexaai/mlx_backend/vlm/modeling/models/idefics3/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/idefics3/idefics3.py +175 -0
- nexaai/mlx_backend/vlm/modeling/models/idefics3/language.py +192 -0
- nexaai/mlx_backend/vlm/modeling/models/idefics3/vision.py +233 -0
- nexaai/mlx_backend/vlm/modeling/models/internvl_chat/__init__.py +9 -0
- nexaai/mlx_backend/vlm/modeling/models/internvl_chat/internvl_chat.py +140 -0
- nexaai/mlx_backend/vlm/modeling/models/internvl_chat/language.py +220 -0
- nexaai/mlx_backend/vlm/modeling/models/internvl_chat/processor.py +393 -0
- nexaai/mlx_backend/vlm/modeling/models/internvl_chat/vision.py +293 -0
- nexaai/mlx_backend/vlm/modeling/models/kernels.py +307 -0
- nexaai/mlx_backend/vlm/modeling/models/kimi_vl/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/kimi_vl/kimi_vl.py +143 -0
- nexaai/mlx_backend/vlm/modeling/models/kimi_vl/language.py +509 -0
- nexaai/mlx_backend/vlm/modeling/models/kimi_vl/vision.py +522 -0
- nexaai/mlx_backend/vlm/modeling/models/llama4/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/llama4/language.py +386 -0
- nexaai/mlx_backend/vlm/modeling/models/llama4/llama4.py +138 -0
- nexaai/mlx_backend/vlm/modeling/models/llama4/vision.py +560 -0
- nexaai/mlx_backend/vlm/modeling/models/llava/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/llava/language.py +240 -0
- nexaai/mlx_backend/vlm/modeling/models/llava/llava.py +153 -0
- nexaai/mlx_backend/vlm/modeling/models/llava/vision.py +259 -0
- nexaai/mlx_backend/vlm/modeling/models/llava_bunny/__init__.py +9 -0
- nexaai/mlx_backend/vlm/modeling/models/llava_bunny/language.py +236 -0
- nexaai/mlx_backend/vlm/modeling/models/llava_bunny/llava_bunny.py +256 -0
- nexaai/mlx_backend/vlm/modeling/models/llava_bunny/vision.py +303 -0
- nexaai/mlx_backend/vlm/modeling/models/llava_next/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/llava_next/language.py +230 -0
- nexaai/mlx_backend/vlm/modeling/models/llava_next/llava_next.py +160 -0
- nexaai/mlx_backend/vlm/modeling/models/llava_next/vision.py +243 -0
- nexaai/mlx_backend/vlm/modeling/models/mistral3/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/mistral3/mistral3.py +283 -0
- nexaai/mlx_backend/vlm/modeling/models/mllama/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/mllama/language.py +416 -0
- nexaai/mlx_backend/vlm/modeling/models/mllama/mllama.py +172 -0
- nexaai/mlx_backend/vlm/modeling/models/mllama/vision.py +499 -0
- nexaai/mlx_backend/vlm/modeling/models/molmo/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/molmo/language.py +243 -0
- nexaai/mlx_backend/vlm/modeling/models/molmo/molmo.py +133 -0
- nexaai/mlx_backend/vlm/modeling/models/molmo/vision.py +465 -0
- nexaai/mlx_backend/vlm/modeling/models/multi_modality/__init__.py +10 -0
- nexaai/mlx_backend/vlm/modeling/models/multi_modality/language.py +230 -0
- nexaai/mlx_backend/vlm/modeling/models/multi_modality/multi_modality.py +385 -0
- nexaai/mlx_backend/vlm/modeling/models/multi_modality/sam.py +557 -0
- nexaai/mlx_backend/vlm/modeling/models/multi_modality/vision.py +526 -0
- nexaai/mlx_backend/vlm/modeling/models/paligemma/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/paligemma/language.py +282 -0
- nexaai/mlx_backend/vlm/modeling/models/paligemma/paligemma.py +160 -0
- nexaai/mlx_backend/vlm/modeling/models/paligemma/vision.py +242 -0
- nexaai/mlx_backend/vlm/modeling/models/phi3_v/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/phi3_v/language.py +21 -0
- nexaai/mlx_backend/vlm/modeling/models/phi3_v/phi3_v.py +243 -0
- nexaai/mlx_backend/vlm/modeling/models/phi3_v/su_rope.py +71 -0
- nexaai/mlx_backend/vlm/modeling/models/phi3_v/vision.py +324 -0
- nexaai/mlx_backend/vlm/modeling/models/pixtral/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/pixtral/language.py +229 -0
- nexaai/mlx_backend/vlm/modeling/models/pixtral/pixtral.py +161 -0
- nexaai/mlx_backend/vlm/modeling/models/pixtral/vision.py +320 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_5_vl/__init__.py +2 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_5_vl/config.py +108 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_5_vl/language.py +490 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_5_vl/qwen2_5_vl.py +168 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_5_vl/vision.py +414 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_vl/__init__.py +2 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_vl/config.py +104 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_vl/language.py +490 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_vl/qwen2_vl.py +167 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_vl/vision.py +312 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3_vl/llm_common/__init__.py +0 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3_vl/llm_common/base.py +117 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3_vl/llm_common/cache.py +531 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3_vl/llm_common/generate.py +701 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3_vl/llm_common/rope_utils.py +255 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3_vl/llm_common/sample_utils.py +303 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3_vl/llm_common/tokenizer_utils.py +407 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3_vl/processor.py +476 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3_vl/qwen3vl.py +1262 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/__init__.py +0 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/base.py +117 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/cache.py +531 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/generate.py +701 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/rope_utils.py +255 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/sample_utils.py +303 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/tokenizer_utils.py +407 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/processor.py +476 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/qwen3vl_moe.py +1308 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/switch_layers.py +210 -0
- nexaai/mlx_backend/vlm/modeling/models/smolvlm/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/smolvlm/smolvlm.py +62 -0
- nexaai/mlx_backend/vlm/modeling/processing_qwen2_5_vl.py +209 -0
- nexaai/mlx_backend/vlm/modeling/processing_qwen2_vl.py +215 -0
- nexaai/mlx_backend/vlm/modeling/prompt_utils.py +474 -0
- nexaai/mlx_backend/vlm/modeling/sample_utils.py +39 -0
- nexaai/mlx_backend/vlm/modeling/tokenizer_utils.py +344 -0
- nexaai/mlx_backend/vlm/modeling/trainer/__init__.py +9 -0
- nexaai/mlx_backend/vlm/modeling/trainer/lora.py +70 -0
- nexaai/mlx_backend/vlm/modeling/trainer/trainer.py +296 -0
- nexaai/mlx_backend/vlm/modeling/trainer/utils.py +160 -0
- nexaai/mlx_backend/vlm/modeling/utils.py +928 -0
- nexaai/rerank.py +57 -0
- nexaai/rerank_impl/__init__.py +0 -0
- nexaai/rerank_impl/mlx_rerank_impl.py +94 -0
- nexaai/rerank_impl/pybind_rerank_impl.py +136 -0
- nexaai/runtime.py +68 -0
- nexaai/runtime_error.py +24 -0
- nexaai/tts.py +75 -0
- nexaai/tts_impl/__init__.py +0 -0
- nexaai/tts_impl/mlx_tts_impl.py +94 -0
- nexaai/tts_impl/pybind_tts_impl.py +43 -0
- nexaai/utils/decode.py +18 -0
- nexaai/utils/manifest_utils.py +531 -0
- nexaai/utils/model_manager.py +1745 -0
- nexaai/utils/model_types.py +49 -0
- nexaai/utils/progress_tracker.py +389 -0
- nexaai/utils/quantization_utils.py +245 -0
- nexaai/vlm.py +130 -0
- nexaai/vlm_impl/__init__.py +0 -0
- nexaai/vlm_impl/mlx_vlm_impl.py +259 -0
- nexaai/vlm_impl/pybind_vlm_impl.py +275 -0
- nexaai-1.0.29.dist-info/METADATA +35 -0
- nexaai-1.0.29.dist-info/RECORD +580 -0
- nexaai-1.0.29.dist-info/WHEEL +5 -0
- nexaai-1.0.29.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
"""
|
|
2
|
+
From https://github.com/deepseek-ai/DeepSeek-VL2
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Dict, List, Literal, Optional, Tuple
|
|
8
|
+
|
|
9
|
+
import mlx.core as mx
|
|
10
|
+
import mlx.nn as nn
|
|
11
|
+
import numpy as np
|
|
12
|
+
from PIL import Image, ImageOps
|
|
13
|
+
from transformers import LlamaTokenizerFast
|
|
14
|
+
from transformers.processing_utils import ProcessorMixin
|
|
15
|
+
|
|
16
|
+
from .conversation import get_conv_template
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def select_best_resolution(image_size, candidate_resolutions):
|
|
20
|
+
# used for cropping
|
|
21
|
+
original_width, original_height = image_size
|
|
22
|
+
best_fit = None
|
|
23
|
+
max_effective_resolution = 0
|
|
24
|
+
min_wasted_resolution = float("inf")
|
|
25
|
+
|
|
26
|
+
for width, height in candidate_resolutions:
|
|
27
|
+
scale = min(width / original_width, height / original_height)
|
|
28
|
+
downscaled_width, downscaled_height = int(original_width * scale), int(
|
|
29
|
+
original_height * scale
|
|
30
|
+
)
|
|
31
|
+
effective_resolution = min(
|
|
32
|
+
downscaled_width * downscaled_height, original_width * original_height
|
|
33
|
+
)
|
|
34
|
+
wasted_resolution = (width * height) - effective_resolution
|
|
35
|
+
|
|
36
|
+
if effective_resolution > max_effective_resolution or (
|
|
37
|
+
effective_resolution == max_effective_resolution
|
|
38
|
+
and wasted_resolution < min_wasted_resolution
|
|
39
|
+
):
|
|
40
|
+
max_effective_resolution = effective_resolution
|
|
41
|
+
min_wasted_resolution = wasted_resolution
|
|
42
|
+
best_fit = (width, height)
|
|
43
|
+
|
|
44
|
+
return best_fit
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class DictOutput(object):
|
|
48
|
+
def keys(self):
|
|
49
|
+
return self.__dict__.keys()
|
|
50
|
+
|
|
51
|
+
def __getitem__(self, item):
|
|
52
|
+
if isinstance(item, int):
|
|
53
|
+
return list(self.__dict__.values())[item]
|
|
54
|
+
if item not in self.__dict__:
|
|
55
|
+
raise KeyError(item)
|
|
56
|
+
return self.__dict__[item]
|
|
57
|
+
|
|
58
|
+
def __setitem__(self, key, value):
|
|
59
|
+
self.__dict__[key] = value
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@dataclass
|
|
63
|
+
class VLChatProcessorOutput(DictOutput):
|
|
64
|
+
sft_format: str
|
|
65
|
+
input_ids: mx.array
|
|
66
|
+
target_ids: mx.array
|
|
67
|
+
images: mx.array
|
|
68
|
+
images_seq_mask: mx.array
|
|
69
|
+
images_spatial_crop: mx.array
|
|
70
|
+
num_image_tokens: List[int]
|
|
71
|
+
|
|
72
|
+
def __len__(self):
|
|
73
|
+
return len(self.input_ids)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@dataclass
|
|
77
|
+
class BatchCollateOutput(DictOutput):
|
|
78
|
+
sft_format: List[str]
|
|
79
|
+
input_ids: mx.array
|
|
80
|
+
labels: mx.array
|
|
81
|
+
images: mx.array
|
|
82
|
+
attention_mask: mx.array
|
|
83
|
+
images_seq_mask: mx.array
|
|
84
|
+
images_spatial_crop: mx.array
|
|
85
|
+
seq_lens: List[int]
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class ImageTransform:
|
|
89
|
+
def __init__(
|
|
90
|
+
self,
|
|
91
|
+
mean: Optional[Tuple[float, float, float]] = (0.5, 0.5, 0.5),
|
|
92
|
+
std: Optional[Tuple[float, float, float]] = (0.5, 0.5, 0.5),
|
|
93
|
+
normalize: bool = True,
|
|
94
|
+
):
|
|
95
|
+
self.mean = mean
|
|
96
|
+
self.std = std
|
|
97
|
+
self.normalize = normalize
|
|
98
|
+
|
|
99
|
+
def __call__(self, pil_img: Image.Image):
|
|
100
|
+
# Convert PIL image to numpy array and normalize
|
|
101
|
+
|
|
102
|
+
img = mx.array(np.array(pil_img)) / 255.0
|
|
103
|
+
|
|
104
|
+
# Transpose from HWC to CHW format
|
|
105
|
+
img = mx.transpose(img, [2, 0, 1])
|
|
106
|
+
|
|
107
|
+
if self.normalize:
|
|
108
|
+
mean = mx.array(self.mean).reshape(-1, 1, 1)
|
|
109
|
+
std = mx.array(self.std).reshape(-1, 1, 1)
|
|
110
|
+
img = (img - mean) / std
|
|
111
|
+
|
|
112
|
+
return img
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class DeepseekVLV2Processor(ProcessorMixin):
|
|
116
|
+
tokenizer_class = ("LlamaTokenizer", "LlamaTokenizerFast")
|
|
117
|
+
attributes = ["tokenizer"]
|
|
118
|
+
|
|
119
|
+
def __init__(
|
|
120
|
+
self,
|
|
121
|
+
tokenizer: LlamaTokenizerFast,
|
|
122
|
+
candidate_resolutions: Tuple[Tuple[int, int]],
|
|
123
|
+
patch_size: int,
|
|
124
|
+
downsample_ratio: int,
|
|
125
|
+
image_mean: Tuple[float, float, float] = (0.5, 0.5, 0.5),
|
|
126
|
+
image_std: Tuple[float, float, float] = (0.5, 0.5, 0.5),
|
|
127
|
+
normalize: bool = True,
|
|
128
|
+
image_token: str = "<image>",
|
|
129
|
+
pad_token: str = "<|▁pad▁|>",
|
|
130
|
+
add_special_token: bool = False,
|
|
131
|
+
sft_format: str = "deepseek",
|
|
132
|
+
mask_prompt: bool = True,
|
|
133
|
+
ignore_id: int = -100,
|
|
134
|
+
**kwargs,
|
|
135
|
+
):
|
|
136
|
+
self.candidate_resolutions = candidate_resolutions
|
|
137
|
+
self.image_size = candidate_resolutions[0][0]
|
|
138
|
+
self.patch_size = patch_size
|
|
139
|
+
self.image_mean = image_mean
|
|
140
|
+
self.image_std = image_std
|
|
141
|
+
self.normalize = normalize
|
|
142
|
+
self.downsample_ratio = downsample_ratio
|
|
143
|
+
|
|
144
|
+
self.image_transform = ImageTransform(
|
|
145
|
+
mean=image_mean, std=image_std, normalize=normalize
|
|
146
|
+
)
|
|
147
|
+
self.tokenizer = tokenizer
|
|
148
|
+
self.tokenizer.padding_side = "left"
|
|
149
|
+
|
|
150
|
+
# Add special tokens
|
|
151
|
+
if tokenizer.pad_token is None:
|
|
152
|
+
self.tokenizer.add_special_tokens({"pad_token": pad_token})
|
|
153
|
+
print(
|
|
154
|
+
f"Add pad token = ['{pad_token}'] to the tokenizer\n"
|
|
155
|
+
f"{pad_token}:{tokenizer.encode(pad_token, add_special_tokens=False)[0]}"
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
image_token_id = self.tokenizer.vocab.get(image_token)
|
|
159
|
+
if image_token_id is None:
|
|
160
|
+
special_tokens = [image_token]
|
|
161
|
+
special_tokens_dict = {"additional_special_tokens": special_tokens}
|
|
162
|
+
self.tokenizer.add_special_tokens(special_tokens_dict)
|
|
163
|
+
self.image_token_id = self.tokenizer.vocab.get(image_token)
|
|
164
|
+
print(
|
|
165
|
+
f"Add image token = ['{image_token}'] to the tokenizer\n"
|
|
166
|
+
f"{image_token}:{tokenizer.encode(image_token, add_special_tokens=False)[0]}"
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
# Add grounding-related tokens
|
|
170
|
+
special_tokens = ["<|ref|>", "<|/ref|>", "<|det|>", "<|/det|>", "<|grounding|>"]
|
|
171
|
+
special_tokens_dict = {"additional_special_tokens": special_tokens}
|
|
172
|
+
self.tokenizer.add_special_tokens(special_tokens_dict)
|
|
173
|
+
print("Added grounding-related tokens")
|
|
174
|
+
|
|
175
|
+
# Add chat tokens
|
|
176
|
+
special_tokens = ["<|User|>", "<|Assistant|>"]
|
|
177
|
+
special_tokens_dict = {"additional_special_tokens": special_tokens}
|
|
178
|
+
self.tokenizer.add_special_tokens(special_tokens_dict)
|
|
179
|
+
print("Added chat tokens")
|
|
180
|
+
|
|
181
|
+
self.image_token = image_token
|
|
182
|
+
self.pad_token = pad_token
|
|
183
|
+
self.add_special_token = add_special_token
|
|
184
|
+
self.sft_format = sft_format
|
|
185
|
+
self.mask_prompt = mask_prompt
|
|
186
|
+
self.ignore_id = ignore_id
|
|
187
|
+
|
|
188
|
+
super().__init__(tokenizer, **kwargs)
|
|
189
|
+
|
|
190
|
+
@property
|
|
191
|
+
def bos_id(self):
|
|
192
|
+
return self.tokenizer.bos_token_id
|
|
193
|
+
|
|
194
|
+
@property
|
|
195
|
+
def eos_id(self):
|
|
196
|
+
return self.tokenizer.eos_token_id
|
|
197
|
+
|
|
198
|
+
@property
|
|
199
|
+
def pad_id(self):
|
|
200
|
+
return self.tokenizer.pad_token_id
|
|
201
|
+
|
|
202
|
+
def encode(self, text: str, bos: bool = True, eos: bool = False):
|
|
203
|
+
t = self.tokenizer.encode(text, add_special_tokens=False)
|
|
204
|
+
|
|
205
|
+
if bos:
|
|
206
|
+
t = [self.bos_id] + t
|
|
207
|
+
if eos:
|
|
208
|
+
t = t + [self.eos_id]
|
|
209
|
+
|
|
210
|
+
return t
|
|
211
|
+
|
|
212
|
+
def decode(self, t: List[int], **kwargs) -> str:
|
|
213
|
+
return self.tokenizer.decode(t, **kwargs)
|
|
214
|
+
|
|
215
|
+
def process_one(
|
|
216
|
+
self,
|
|
217
|
+
prompt: str = None,
|
|
218
|
+
conversations: List[Dict[str, str]] = None,
|
|
219
|
+
images: List[Image.Image] = None,
|
|
220
|
+
apply_sft_format: bool = False,
|
|
221
|
+
inference_mode: bool = True,
|
|
222
|
+
system_prompt: str = "",
|
|
223
|
+
**kwargs,
|
|
224
|
+
):
|
|
225
|
+
assert (
|
|
226
|
+
prompt is None or conversations is None
|
|
227
|
+
), "prompt and conversations cannot be used at the same time."
|
|
228
|
+
|
|
229
|
+
if apply_sft_format:
|
|
230
|
+
sft_format = self.format_prompts(
|
|
231
|
+
prompts=prompt, sft_format=self.sft_format, system_prompt=system_prompt
|
|
232
|
+
)
|
|
233
|
+
else:
|
|
234
|
+
sft_format = prompt
|
|
235
|
+
(
|
|
236
|
+
tokenized_str,
|
|
237
|
+
images_list,
|
|
238
|
+
images_seq_mask,
|
|
239
|
+
images_spatial_crop,
|
|
240
|
+
num_image_tokens,
|
|
241
|
+
) = self.tokenize_with_images(
|
|
242
|
+
sft_format, images, bos=True, eos=True, cropping=len(images) <= 2
|
|
243
|
+
)
|
|
244
|
+
masked_tokenized_str = []
|
|
245
|
+
for token_index in tokenized_str:
|
|
246
|
+
if token_index != self.image_token_id:
|
|
247
|
+
masked_tokenized_str.append(token_index)
|
|
248
|
+
else:
|
|
249
|
+
masked_tokenized_str.append(self.ignore_id)
|
|
250
|
+
|
|
251
|
+
input_ids = mx.array(tokenized_str)
|
|
252
|
+
target_ids = mx.array(masked_tokenized_str)
|
|
253
|
+
images_seq_mask = mx.array(images_seq_mask)
|
|
254
|
+
|
|
255
|
+
# Set ignored indices
|
|
256
|
+
target_ids = mx.where(
|
|
257
|
+
(input_ids < 0) | (input_ids == self.image_token_id),
|
|
258
|
+
self.ignore_id,
|
|
259
|
+
target_ids,
|
|
260
|
+
)
|
|
261
|
+
input_ids = mx.where(input_ids < 0, self.pad_id, input_ids)
|
|
262
|
+
|
|
263
|
+
if inference_mode:
|
|
264
|
+
input_ids = input_ids[:-1]
|
|
265
|
+
target_ids = target_ids[:-1]
|
|
266
|
+
images_seq_mask = images_seq_mask[:-1]
|
|
267
|
+
|
|
268
|
+
if len(images_list) == 0:
|
|
269
|
+
images = mx.zeros((1, 3, self.image_size, self.image_size))
|
|
270
|
+
images_spatial_crop = mx.zeros((1, 2))
|
|
271
|
+
else:
|
|
272
|
+
images = mx.stack(images_list)
|
|
273
|
+
images_spatial_crop = mx.array(images_spatial_crop)
|
|
274
|
+
|
|
275
|
+
return VLChatProcessorOutput(
|
|
276
|
+
sft_format=sft_format,
|
|
277
|
+
input_ids=input_ids,
|
|
278
|
+
target_ids=target_ids,
|
|
279
|
+
images=images,
|
|
280
|
+
images_seq_mask=images_seq_mask,
|
|
281
|
+
images_spatial_crop=images_spatial_crop,
|
|
282
|
+
num_image_tokens=num_image_tokens,
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
def pad_sequence(self, sequences, padding_value):
|
|
286
|
+
# Get max length of sequences
|
|
287
|
+
max_len = max(len(seq) for seq in sequences)
|
|
288
|
+
|
|
289
|
+
# Pad each sequence to max length
|
|
290
|
+
padded_seqs = []
|
|
291
|
+
for seq in sequences:
|
|
292
|
+
pad_length = max_len - len(seq)
|
|
293
|
+
if pad_length > 0:
|
|
294
|
+
padding = mx.full((pad_length,), padding_value)
|
|
295
|
+
padded_seq = mx.concatenate([seq, padding])
|
|
296
|
+
else:
|
|
297
|
+
padded_seq = seq
|
|
298
|
+
padded_seqs.append(padded_seq)
|
|
299
|
+
|
|
300
|
+
return mx.stack(padded_seqs)
|
|
301
|
+
|
|
302
|
+
def tokenize_with_images(
|
|
303
|
+
self,
|
|
304
|
+
conversation: str,
|
|
305
|
+
images: List[Image.Image],
|
|
306
|
+
bos: bool = True,
|
|
307
|
+
eos: bool = True,
|
|
308
|
+
cropping: bool = True,
|
|
309
|
+
):
|
|
310
|
+
"""Tokenize text with <image> tags."""
|
|
311
|
+
assert conversation.count(self.image_token) == len(images)
|
|
312
|
+
text_splits = conversation.split(self.image_token)
|
|
313
|
+
images_list, images_seq_mask, images_spatial_crop = [], [], []
|
|
314
|
+
num_image_tokens = []
|
|
315
|
+
tokenized_str = []
|
|
316
|
+
for text_sep, image in zip(text_splits, images):
|
|
317
|
+
"""encode text_sep"""
|
|
318
|
+
tokenized_sep = self.encode(text_sep, bos=False, eos=False)
|
|
319
|
+
tokenized_str += tokenized_sep
|
|
320
|
+
images_seq_mask += [False] * len(tokenized_sep)
|
|
321
|
+
|
|
322
|
+
"""select best resolution for anyres"""
|
|
323
|
+
if cropping:
|
|
324
|
+
best_width, best_height = select_best_resolution(
|
|
325
|
+
image.size, self.candidate_resolutions
|
|
326
|
+
)
|
|
327
|
+
else:
|
|
328
|
+
best_width, best_height = self.image_size, self.image_size
|
|
329
|
+
|
|
330
|
+
"""process the global view"""
|
|
331
|
+
global_view = ImageOps.pad(
|
|
332
|
+
image,
|
|
333
|
+
(self.image_size, self.image_size),
|
|
334
|
+
color=tuple(int(x * 255) for x in self.image_transform.mean),
|
|
335
|
+
)
|
|
336
|
+
images_list.append(self.image_transform(global_view))
|
|
337
|
+
|
|
338
|
+
"""process the local views"""
|
|
339
|
+
local_view = ImageOps.pad(
|
|
340
|
+
image,
|
|
341
|
+
(best_width, best_height),
|
|
342
|
+
color=tuple(int(x * 255) for x in self.image_transform.mean),
|
|
343
|
+
)
|
|
344
|
+
for i in range(0, best_height, self.image_size):
|
|
345
|
+
for j in range(0, best_width, self.image_size):
|
|
346
|
+
images_list.append(
|
|
347
|
+
self.image_transform(
|
|
348
|
+
local_view.crop(
|
|
349
|
+
(j, i, j + self.image_size, i + self.image_size)
|
|
350
|
+
)
|
|
351
|
+
)
|
|
352
|
+
)
|
|
353
|
+
|
|
354
|
+
"""record height / width crop num"""
|
|
355
|
+
num_width_tiles, num_height_tiles = (
|
|
356
|
+
best_width // self.image_size,
|
|
357
|
+
best_height // self.image_size,
|
|
358
|
+
)
|
|
359
|
+
images_spatial_crop.append([num_width_tiles, num_height_tiles])
|
|
360
|
+
|
|
361
|
+
"""add image tokens"""
|
|
362
|
+
h = w = math.ceil(
|
|
363
|
+
(self.image_size // self.patch_size) / self.downsample_ratio
|
|
364
|
+
)
|
|
365
|
+
# global views tokens h * (w + 1), 1 is for line seperator
|
|
366
|
+
tokenized_image = [self.image_token_id] * h * (w + 1)
|
|
367
|
+
# add a seperator between global and local views
|
|
368
|
+
tokenized_image += [self.image_token_id]
|
|
369
|
+
# local views tokens, (num_height_tiles * h) * (num_width_tiles * w + 1)
|
|
370
|
+
tokenized_image += (
|
|
371
|
+
[self.image_token_id]
|
|
372
|
+
* (num_height_tiles * h)
|
|
373
|
+
* (num_width_tiles * w + 1)
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
tokenized_str += tokenized_image
|
|
377
|
+
images_seq_mask += [True] * len(tokenized_image)
|
|
378
|
+
num_image_tokens.append(len(tokenized_image))
|
|
379
|
+
|
|
380
|
+
"""process the last text split"""
|
|
381
|
+
tokenized_sep = self.encode(text_splits[-1], bos=False, eos=False)
|
|
382
|
+
tokenized_str += tokenized_sep
|
|
383
|
+
images_seq_mask += [False] * len(tokenized_sep)
|
|
384
|
+
|
|
385
|
+
"""add the bos and eos tokens"""
|
|
386
|
+
if bos:
|
|
387
|
+
tokenized_str = [self.bos_id] + tokenized_str
|
|
388
|
+
images_seq_mask = [False] + images_seq_mask
|
|
389
|
+
if eos:
|
|
390
|
+
tokenized_str = tokenized_str + [self.eos_id]
|
|
391
|
+
images_seq_mask = images_seq_mask + [False]
|
|
392
|
+
|
|
393
|
+
assert len(tokenized_str) == len(
|
|
394
|
+
images_seq_mask
|
|
395
|
+
), f"tokenize_with_images func: tokenized_str's length {len(tokenized_str)} is not equal to imags_seq_mask's length {len(images_seq_mask)}"
|
|
396
|
+
|
|
397
|
+
return (
|
|
398
|
+
tokenized_str,
|
|
399
|
+
images_list,
|
|
400
|
+
images_seq_mask,
|
|
401
|
+
images_spatial_crop,
|
|
402
|
+
num_image_tokens,
|
|
403
|
+
)
|
|
404
|
+
|
|
405
|
+
def batchify(
|
|
406
|
+
self,
|
|
407
|
+
sample_list: List[VLChatProcessorOutput],
|
|
408
|
+
padding: Literal["left", "right"] = "left",
|
|
409
|
+
) -> BatchCollateOutput:
|
|
410
|
+
batched_sft_format = [sample.sft_format for sample in sample_list]
|
|
411
|
+
batched_input_ids = [sample.input_ids for sample in sample_list]
|
|
412
|
+
batched_labels = [sample.target_ids for sample in sample_list]
|
|
413
|
+
batched_images_seq_mask = [sample.images_seq_mask for sample in sample_list]
|
|
414
|
+
seq_lens = [len(sample) for sample in sample_list]
|
|
415
|
+
|
|
416
|
+
# Padding
|
|
417
|
+
if padding == "left":
|
|
418
|
+
# MLX implementation of padding
|
|
419
|
+
max_len = max(len(ids) for ids in batched_input_ids)
|
|
420
|
+
|
|
421
|
+
def pad_left(sequence, pad_val):
|
|
422
|
+
pad_len = max_len - len(sequence)
|
|
423
|
+
if pad_len > 0:
|
|
424
|
+
padding = mx.full((pad_len,), pad_val)
|
|
425
|
+
return mx.concatenate([padding, sequence])
|
|
426
|
+
return sequence
|
|
427
|
+
|
|
428
|
+
batched_input_ids = mx.stack(
|
|
429
|
+
[pad_left(ids, self.pad_id) for ids in batched_input_ids]
|
|
430
|
+
)
|
|
431
|
+
batched_labels = mx.stack(
|
|
432
|
+
[pad_left(ids, self.ignore_id) for ids in batched_labels]
|
|
433
|
+
)
|
|
434
|
+
batched_images_seq_mask = mx.stack(
|
|
435
|
+
[pad_left(mask, False) for mask in batched_images_seq_mask]
|
|
436
|
+
)
|
|
437
|
+
batched_attention_mask = batched_input_ids != self.pad_id
|
|
438
|
+
|
|
439
|
+
else:
|
|
440
|
+
batched_input_ids = self.pad_sequence(batched_input_ids, self.pad_id)
|
|
441
|
+
batched_labels = self.pad_sequence(batched_labels, self.ignore_id)
|
|
442
|
+
batched_images_seq_mask = self.pad_sequence(batched_images_seq_mask, False)
|
|
443
|
+
batched_attention_mask = batched_input_ids != self.pad_id
|
|
444
|
+
|
|
445
|
+
# Padding images
|
|
446
|
+
max_n_patches = max(sample.images.shape[0] for sample in sample_list)
|
|
447
|
+
batched_images = []
|
|
448
|
+
for sample in sample_list:
|
|
449
|
+
images = sample.images
|
|
450
|
+
n_pads = max_n_patches - images.shape[0]
|
|
451
|
+
if n_pads > 0:
|
|
452
|
+
pad_shape = (n_pads,) + images.shape[1:]
|
|
453
|
+
pad_images = mx.zeros(pad_shape)
|
|
454
|
+
images = mx.concatenate([images, pad_images])
|
|
455
|
+
batched_images.append(images)
|
|
456
|
+
batched_images = mx.stack(batched_images)
|
|
457
|
+
|
|
458
|
+
# Padding spatial crop info
|
|
459
|
+
max_n_images = max(
|
|
460
|
+
sample.images_spatial_crop.shape[0] for sample in sample_list
|
|
461
|
+
)
|
|
462
|
+
batched_images_spatial_crop = []
|
|
463
|
+
for sample in sample_list:
|
|
464
|
+
spatial_crop = sample.images_spatial_crop
|
|
465
|
+
n_pads = max_n_images - spatial_crop.shape[0]
|
|
466
|
+
if n_pads > 0:
|
|
467
|
+
pad_spatial = mx.zeros((n_pads, 2))
|
|
468
|
+
spatial_crop = mx.concatenate([spatial_crop, pad_spatial])
|
|
469
|
+
batched_images_spatial_crop.append(spatial_crop)
|
|
470
|
+
batched_images_spatial_crop = mx.stack(batched_images_spatial_crop)
|
|
471
|
+
|
|
472
|
+
return {
|
|
473
|
+
"input_ids": batched_input_ids,
|
|
474
|
+
"attention_mask": batched_attention_mask,
|
|
475
|
+
"labels": batched_labels,
|
|
476
|
+
"images": batched_images,
|
|
477
|
+
"images_seq_mask": batched_images_seq_mask,
|
|
478
|
+
"images_spatial_crop": batched_images_spatial_crop,
|
|
479
|
+
"sft_format": batched_sft_format,
|
|
480
|
+
"seq_lens": seq_lens,
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
def __call__(
|
|
484
|
+
self,
|
|
485
|
+
*,
|
|
486
|
+
text: str = None,
|
|
487
|
+
images: List[Image.Image] = None,
|
|
488
|
+
apply_sft_format: bool = False,
|
|
489
|
+
force_batchify: bool = True,
|
|
490
|
+
inference_mode: bool = True,
|
|
491
|
+
system_prompt: str = "",
|
|
492
|
+
**kwargs,
|
|
493
|
+
):
|
|
494
|
+
"""
|
|
495
|
+
|
|
496
|
+
Args:
|
|
497
|
+
prompt (str): the formatted prompt;
|
|
498
|
+
conversations (List[Dict]): conversations with a list of messages;
|
|
499
|
+
images (List[ImageType]): the list of images;
|
|
500
|
+
apply_sft_format (bool): if prompt is not None, then apply the SFT format to prompt;
|
|
501
|
+
if conversations is not None, then it will always apply the SFT format to conversations;
|
|
502
|
+
force_batchify (bool): force batchify the inputs;
|
|
503
|
+
inference_mode (bool): if True, then remove the last eos token;
|
|
504
|
+
system_prompt (str): the system prompt;
|
|
505
|
+
**kwargs:
|
|
506
|
+
|
|
507
|
+
Returns:
|
|
508
|
+
outputs (BaseProcessorOutput): the output of the processor,
|
|
509
|
+
- input_ids (torch.LongTensor): [N + image tokens]
|
|
510
|
+
- images (torch.FloatTensor): [n_images, 3, H, W]
|
|
511
|
+
- image_id (int): the id of the image token
|
|
512
|
+
- num_image_tokens (List[int]): the number of image tokens
|
|
513
|
+
"""
|
|
514
|
+
|
|
515
|
+
prepare = self.process_one(
|
|
516
|
+
prompt=text,
|
|
517
|
+
images=images,
|
|
518
|
+
apply_sft_format=apply_sft_format,
|
|
519
|
+
inference_mode=inference_mode,
|
|
520
|
+
system_prompt=system_prompt,
|
|
521
|
+
)
|
|
522
|
+
|
|
523
|
+
if force_batchify:
|
|
524
|
+
prepare = self.batchify([prepare])
|
|
525
|
+
|
|
526
|
+
return prepare
|