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,416 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
from dataclasses import dataclass, field
|
|
3
|
+
from typing import Dict, List, Optional, Tuple, Union
|
|
4
|
+
|
|
5
|
+
import mlx.core as mx
|
|
6
|
+
import mlx.nn as nn
|
|
7
|
+
|
|
8
|
+
from ..base import (
|
|
9
|
+
LanguageModelOutput,
|
|
10
|
+
create_attention_mask,
|
|
11
|
+
scaled_dot_product_attention,
|
|
12
|
+
)
|
|
13
|
+
from ..cache import KVCache
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass
|
|
17
|
+
class TextConfig:
|
|
18
|
+
model_type: str = "mllama"
|
|
19
|
+
vocab_size: int = 32000
|
|
20
|
+
hidden_size: int = 4096
|
|
21
|
+
intermediate_size: int = 14336
|
|
22
|
+
num_hidden_layers: int = 40
|
|
23
|
+
num_attention_heads: int = 32
|
|
24
|
+
num_key_value_heads: int = 8
|
|
25
|
+
hidden_act: str = "silu"
|
|
26
|
+
max_position_embeddings: int = 131072
|
|
27
|
+
initializer_range: float = 0.02
|
|
28
|
+
rms_norm_eps: float = 1e-6
|
|
29
|
+
tie_word_embeddings: bool = False
|
|
30
|
+
rope_theta: float = 10000.0
|
|
31
|
+
rope_traditional: bool = False
|
|
32
|
+
rope_scaling: Optional[Dict[str, Union[float, str]]] = None
|
|
33
|
+
cross_attention_layers: List[int] = field(
|
|
34
|
+
default_factory=lambda: [3, 8, 13, 18, 23, 28, 33, 38]
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
def __post_init__(self):
|
|
38
|
+
if self.num_key_value_heads is None:
|
|
39
|
+
self.num_key_value_heads = self.num_attention_heads
|
|
40
|
+
|
|
41
|
+
@classmethod
|
|
42
|
+
def from_dict(cls, params):
|
|
43
|
+
return cls(
|
|
44
|
+
**{
|
|
45
|
+
k: v
|
|
46
|
+
for k, v in params.items()
|
|
47
|
+
if k in inspect.signature(cls).parameters
|
|
48
|
+
}
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class MllamaTextCrossAttention(nn.Module):
|
|
53
|
+
def __init__(self, config: TextConfig, layer_idx: Optional[int] = None):
|
|
54
|
+
super().__init__()
|
|
55
|
+
self.config = config
|
|
56
|
+
self.hidden_size = config.hidden_size
|
|
57
|
+
self.num_heads = config.num_attention_heads
|
|
58
|
+
self.head_dim = self.hidden_size // self.num_heads
|
|
59
|
+
self.num_key_value_heads = config.num_key_value_heads
|
|
60
|
+
self.num_key_value_groups = self.num_heads // self.num_key_value_heads
|
|
61
|
+
self.layer_idx = layer_idx
|
|
62
|
+
self.scale = self.head_dim**-0.5
|
|
63
|
+
self.q_proj = nn.Linear(
|
|
64
|
+
self.hidden_size, self.num_heads * self.head_dim, bias=False
|
|
65
|
+
)
|
|
66
|
+
self.k_proj = nn.Linear(
|
|
67
|
+
self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False
|
|
68
|
+
)
|
|
69
|
+
self.v_proj = nn.Linear(
|
|
70
|
+
self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False
|
|
71
|
+
)
|
|
72
|
+
self.o_proj = nn.Linear(
|
|
73
|
+
self.num_heads * self.head_dim, self.hidden_size, bias=False
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
self.q_norm = nn.RMSNorm(self.head_dim, eps=config.rms_norm_eps)
|
|
77
|
+
self.k_norm = nn.RMSNorm(self.head_dim, eps=config.rms_norm_eps)
|
|
78
|
+
|
|
79
|
+
def __call__(
|
|
80
|
+
self,
|
|
81
|
+
hidden_states: mx.array,
|
|
82
|
+
cross_attention_states: Optional[mx.array] = None,
|
|
83
|
+
attention_mask: Optional[mx.array] = None,
|
|
84
|
+
cache: Optional[KVCache] = None,
|
|
85
|
+
) -> mx.array:
|
|
86
|
+
|
|
87
|
+
bsz, q_len, _ = hidden_states.shape
|
|
88
|
+
query = (
|
|
89
|
+
self.q_proj(hidden_states)
|
|
90
|
+
.reshape(bsz, q_len, self.num_heads, self.head_dim)
|
|
91
|
+
.transpose(0, 2, 1, 3)
|
|
92
|
+
)
|
|
93
|
+
query_states = self.q_norm(query)
|
|
94
|
+
|
|
95
|
+
if cross_attention_states is not None:
|
|
96
|
+
key_states = (
|
|
97
|
+
self.k_proj(cross_attention_states)
|
|
98
|
+
.reshape(bsz, -1, self.num_key_value_heads, self.head_dim)
|
|
99
|
+
.transpose(0, 2, 1, 3)
|
|
100
|
+
)
|
|
101
|
+
value_states = (
|
|
102
|
+
self.v_proj(cross_attention_states)
|
|
103
|
+
.reshape(bsz, -1, self.num_key_value_heads, self.head_dim)
|
|
104
|
+
.transpose(0, 2, 1, 3)
|
|
105
|
+
)
|
|
106
|
+
key_states = self.k_norm(key_states)
|
|
107
|
+
elif cache is not None and cache.offset > 0:
|
|
108
|
+
key_states, value_states = cache.fetch()
|
|
109
|
+
else:
|
|
110
|
+
key_states, value_states = mx.split(query, 2, axis=1)
|
|
111
|
+
key_states = self.k_norm(key_states)
|
|
112
|
+
|
|
113
|
+
attn_output = scaled_dot_product_attention(
|
|
114
|
+
query_states,
|
|
115
|
+
key_states,
|
|
116
|
+
value_states,
|
|
117
|
+
cache,
|
|
118
|
+
scale=self.scale,
|
|
119
|
+
mask=attention_mask, # add a dim for batch processing
|
|
120
|
+
)
|
|
121
|
+
attn_output = attn_output.transpose(0, 2, 1, 3).reshape(
|
|
122
|
+
bsz, q_len, self.hidden_size
|
|
123
|
+
)
|
|
124
|
+
return self.o_proj(attn_output)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class MllamaTextSelfAttention(nn.Module):
|
|
128
|
+
def __init__(self, config: TextConfig, layer_idx: int):
|
|
129
|
+
super().__init__()
|
|
130
|
+
self.config = config
|
|
131
|
+
self.hidden_size = config.hidden_size
|
|
132
|
+
self.num_heads = config.num_attention_heads
|
|
133
|
+
self.head_dim = self.hidden_size // self.num_heads
|
|
134
|
+
self.num_key_value_heads = config.num_key_value_heads
|
|
135
|
+
self.num_key_value_groups = self.num_heads // self.num_key_value_heads
|
|
136
|
+
self.scale = self.head_dim**-0.5
|
|
137
|
+
self.layer_idx = layer_idx
|
|
138
|
+
|
|
139
|
+
self.q_proj = nn.Linear(
|
|
140
|
+
self.hidden_size, self.num_heads * self.head_dim, bias=False
|
|
141
|
+
)
|
|
142
|
+
self.k_proj = nn.Linear(
|
|
143
|
+
self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False
|
|
144
|
+
)
|
|
145
|
+
self.v_proj = nn.Linear(
|
|
146
|
+
self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False
|
|
147
|
+
)
|
|
148
|
+
self.o_proj = nn.Linear(
|
|
149
|
+
self.num_heads * self.head_dim, self.hidden_size, bias=False
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
self.rope = nn.RoPE(
|
|
153
|
+
self.head_dim,
|
|
154
|
+
traditional=config.rope_traditional,
|
|
155
|
+
base=config.rope_theta,
|
|
156
|
+
scale=1,
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
def __call__(
|
|
160
|
+
self,
|
|
161
|
+
x: mx.array,
|
|
162
|
+
mask: Optional[mx.array] = None,
|
|
163
|
+
cache: Optional[KVCache] = None,
|
|
164
|
+
) -> mx.array:
|
|
165
|
+
bsz, q_len, _ = x.shape
|
|
166
|
+
query_states = (
|
|
167
|
+
self.q_proj(x).reshape(bsz, q_len, self.num_heads, -1).transpose(0, 2, 1, 3)
|
|
168
|
+
)
|
|
169
|
+
key_states = (
|
|
170
|
+
self.k_proj(x)
|
|
171
|
+
.reshape(bsz, q_len, self.num_key_value_heads, -1)
|
|
172
|
+
.transpose(0, 2, 1, 3)
|
|
173
|
+
)
|
|
174
|
+
value_states = (
|
|
175
|
+
self.v_proj(x)
|
|
176
|
+
.reshape(bsz, q_len, self.num_key_value_heads, -1)
|
|
177
|
+
.transpose(0, 2, 1, 3)
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
if cache is not None:
|
|
181
|
+
query_states = self.rope(query_states, offset=cache.offset)
|
|
182
|
+
key_states = self.rope(key_states, offset=cache.offset)
|
|
183
|
+
key_states, value_states = cache.update_and_fetch(key_states, value_states)
|
|
184
|
+
else:
|
|
185
|
+
query_states = self.rope(query_states)
|
|
186
|
+
key_states = self.rope(key_states)
|
|
187
|
+
|
|
188
|
+
attn_output = scaled_dot_product_attention(
|
|
189
|
+
query_states, key_states, value_states, cache, scale=self.scale, mask=mask
|
|
190
|
+
)
|
|
191
|
+
attn_output = attn_output.transpose(0, 2, 1, 3).reshape(
|
|
192
|
+
bsz, q_len, self.hidden_size
|
|
193
|
+
)
|
|
194
|
+
return self.o_proj(attn_output)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
class MllamaTextMLP(nn.Module):
|
|
198
|
+
def __init__(self, config: TextConfig):
|
|
199
|
+
super().__init__()
|
|
200
|
+
self.gate_proj = nn.Linear(
|
|
201
|
+
config.hidden_size, config.intermediate_size, bias=False
|
|
202
|
+
)
|
|
203
|
+
self.up_proj = nn.Linear(
|
|
204
|
+
config.hidden_size, config.intermediate_size, bias=False
|
|
205
|
+
)
|
|
206
|
+
self.down_proj = nn.Linear(
|
|
207
|
+
config.intermediate_size, config.hidden_size, bias=False
|
|
208
|
+
)
|
|
209
|
+
self.act_fn = lambda x: x * mx.sigmoid(x)
|
|
210
|
+
|
|
211
|
+
def __call__(self, x):
|
|
212
|
+
return self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
class MllamaSelfAttentionDecoderLayer(nn.Module):
|
|
216
|
+
def __init__(self, config: TextConfig, layer_idx: int):
|
|
217
|
+
super().__init__()
|
|
218
|
+
self.hidden_size = config.hidden_size
|
|
219
|
+
self.self_attn = MllamaTextSelfAttention(config, layer_idx=layer_idx)
|
|
220
|
+
self.mlp = MllamaTextMLP(config)
|
|
221
|
+
self.input_layernorm = nn.RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
|
222
|
+
self.post_attention_layernorm = nn.RMSNorm(
|
|
223
|
+
config.hidden_size, eps=config.rms_norm_eps
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
def __call__(
|
|
227
|
+
self,
|
|
228
|
+
hidden_states: mx.array,
|
|
229
|
+
mask: Optional[mx.array] = None,
|
|
230
|
+
cache: Optional[KVCache] = None,
|
|
231
|
+
) -> mx.array:
|
|
232
|
+
residual = hidden_states
|
|
233
|
+
hidden_states = self.input_layernorm(hidden_states)
|
|
234
|
+
hidden_states = self.self_attn(
|
|
235
|
+
x=hidden_states,
|
|
236
|
+
mask=mask,
|
|
237
|
+
cache=cache,
|
|
238
|
+
)
|
|
239
|
+
hidden_states = residual + hidden_states
|
|
240
|
+
|
|
241
|
+
residual = hidden_states
|
|
242
|
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
|
243
|
+
hidden_states = self.mlp(hidden_states)
|
|
244
|
+
hidden_states = residual + hidden_states
|
|
245
|
+
|
|
246
|
+
return hidden_states
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
class MllamaCrossAttentionDecoderLayer(nn.Module):
|
|
250
|
+
def __init__(self, config: TextConfig, layer_idx: int):
|
|
251
|
+
super().__init__()
|
|
252
|
+
self.hidden_size = config.hidden_size
|
|
253
|
+
self.cross_attn = MllamaTextCrossAttention(config, layer_idx=layer_idx)
|
|
254
|
+
self.mlp = MllamaTextMLP(config)
|
|
255
|
+
self.input_layernorm = nn.RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
|
256
|
+
self.post_attention_layernorm = nn.RMSNorm(
|
|
257
|
+
config.hidden_size, eps=config.rms_norm_eps
|
|
258
|
+
)
|
|
259
|
+
self.cross_attn_attn_gate = mx.zeros(1)
|
|
260
|
+
self.cross_attn_mlp_gate = mx.zeros(1)
|
|
261
|
+
|
|
262
|
+
def __call__(
|
|
263
|
+
self,
|
|
264
|
+
hidden_states: mx.array,
|
|
265
|
+
cross_attention_states: mx.array,
|
|
266
|
+
attention_mask: Optional[mx.array] = None,
|
|
267
|
+
full_text_row_masked_out_mask: Optional[mx.array] = None,
|
|
268
|
+
cache: Optional[KVCache] = None,
|
|
269
|
+
) -> mx.array:
|
|
270
|
+
residual = hidden_states
|
|
271
|
+
hidden_states = self.input_layernorm(hidden_states)
|
|
272
|
+
hidden_states = self.cross_attn(
|
|
273
|
+
hidden_states=hidden_states,
|
|
274
|
+
cross_attention_states=cross_attention_states,
|
|
275
|
+
attention_mask=attention_mask,
|
|
276
|
+
cache=cache,
|
|
277
|
+
)
|
|
278
|
+
hidden_states = residual + mx.tanh(self.cross_attn_attn_gate) * hidden_states
|
|
279
|
+
|
|
280
|
+
residual = hidden_states
|
|
281
|
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
|
282
|
+
hidden_states = self.mlp(hidden_states)
|
|
283
|
+
if full_text_row_masked_out_mask is not None:
|
|
284
|
+
hidden_states = full_text_row_masked_out_mask[:, 0] * hidden_states
|
|
285
|
+
hidden_states = residual + mx.tanh(self.cross_attn_mlp_gate) * hidden_states
|
|
286
|
+
|
|
287
|
+
return hidden_states
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
class MllamaTextModel(nn.Module):
|
|
291
|
+
def __init__(self, config: TextConfig):
|
|
292
|
+
super().__init__()
|
|
293
|
+
self.config = config
|
|
294
|
+
self.vocab_size = config.vocab_size
|
|
295
|
+
self.hidden_size = config.hidden_size
|
|
296
|
+
|
|
297
|
+
self.embed_tokens = nn.Embedding(config.vocab_size + 8, config.hidden_size)
|
|
298
|
+
self.layers = [
|
|
299
|
+
(
|
|
300
|
+
MllamaCrossAttentionDecoderLayer(config, layer_idx)
|
|
301
|
+
if layer_idx in config.cross_attention_layers
|
|
302
|
+
else MllamaSelfAttentionDecoderLayer(config, layer_idx)
|
|
303
|
+
)
|
|
304
|
+
for layer_idx in range(config.num_hidden_layers)
|
|
305
|
+
]
|
|
306
|
+
self.norm = nn.RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
|
307
|
+
|
|
308
|
+
def __call__(
|
|
309
|
+
self,
|
|
310
|
+
input_ids: Optional[mx.array] = None,
|
|
311
|
+
mask: Optional[mx.array] = None,
|
|
312
|
+
position_ids: Optional[mx.array] = None,
|
|
313
|
+
cross_attention_states: Optional[mx.array] = None,
|
|
314
|
+
cross_attention_mask: Optional[mx.array] = None,
|
|
315
|
+
full_text_row_masked_out_mask: Optional[mx.array] = None,
|
|
316
|
+
inputs_embeds: Optional[mx.array] = None,
|
|
317
|
+
cache: Optional[KVCache] = None,
|
|
318
|
+
) -> mx.array:
|
|
319
|
+
if input_ids is not None and inputs_embeds is not None:
|
|
320
|
+
raise ValueError(
|
|
321
|
+
"You cannot specify both input_ids and inputs_embeds at the same time"
|
|
322
|
+
)
|
|
323
|
+
elif input_ids is not None:
|
|
324
|
+
batch_size, seq_length = input_ids.shape
|
|
325
|
+
inputs_embeds = self.embed_tokens(input_ids)
|
|
326
|
+
elif inputs_embeds is not None:
|
|
327
|
+
batch_size, seq_length, _ = inputs_embeds.shape
|
|
328
|
+
else:
|
|
329
|
+
raise ValueError("You have to specify either input_ids or inputs_embeds")
|
|
330
|
+
|
|
331
|
+
if position_ids is None:
|
|
332
|
+
position_ids = mx.expand_dims(mx.arange(seq_length), 0)
|
|
333
|
+
position_ids = mx.repeat(position_ids, batch_size, axis=0)
|
|
334
|
+
|
|
335
|
+
hidden_states = inputs_embeds
|
|
336
|
+
|
|
337
|
+
if cache is None:
|
|
338
|
+
cache = [None] * len(self.layers)
|
|
339
|
+
|
|
340
|
+
if mask is None:
|
|
341
|
+
mask = create_attention_mask(hidden_states, cache)
|
|
342
|
+
|
|
343
|
+
for idx, (decoder_layer, c) in enumerate(zip(self.layers, cache)):
|
|
344
|
+
if idx in self.config.cross_attention_layers:
|
|
345
|
+
layer_outputs = decoder_layer(
|
|
346
|
+
hidden_states,
|
|
347
|
+
cross_attention_states=cross_attention_states,
|
|
348
|
+
attention_mask=cross_attention_mask,
|
|
349
|
+
full_text_row_masked_out_mask=full_text_row_masked_out_mask,
|
|
350
|
+
cache=c,
|
|
351
|
+
)
|
|
352
|
+
else:
|
|
353
|
+
layer_outputs = decoder_layer(
|
|
354
|
+
hidden_states,
|
|
355
|
+
mask=mask,
|
|
356
|
+
cache=c,
|
|
357
|
+
)
|
|
358
|
+
hidden_states = layer_outputs
|
|
359
|
+
|
|
360
|
+
hidden_states = self.norm(hidden_states)
|
|
361
|
+
|
|
362
|
+
return hidden_states
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
class LanguageModel(nn.Module):
|
|
366
|
+
def __init__(self, config: TextConfig):
|
|
367
|
+
super().__init__()
|
|
368
|
+
self.config = config
|
|
369
|
+
self.model = MllamaTextModel(config)
|
|
370
|
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
|
371
|
+
|
|
372
|
+
def __call__(
|
|
373
|
+
self,
|
|
374
|
+
input_ids: Optional[mx.array] = None,
|
|
375
|
+
mask: Optional[mx.array] = None,
|
|
376
|
+
cross_attention_states: Optional[mx.array] = None,
|
|
377
|
+
cross_attention_mask: Optional[mx.array] = None,
|
|
378
|
+
full_text_row_masked_out_mask: Optional[mx.array] = None,
|
|
379
|
+
inputs_embeds: Optional[mx.array] = None,
|
|
380
|
+
cache: Optional[KVCache] = None,
|
|
381
|
+
) -> Tuple[mx.array, Optional[mx.array]]:
|
|
382
|
+
|
|
383
|
+
hidden_states = self.model(
|
|
384
|
+
input_ids=input_ids,
|
|
385
|
+
mask=mask,
|
|
386
|
+
cross_attention_states=cross_attention_states,
|
|
387
|
+
cross_attention_mask=cross_attention_mask,
|
|
388
|
+
full_text_row_masked_out_mask=full_text_row_masked_out_mask,
|
|
389
|
+
inputs_embeds=inputs_embeds,
|
|
390
|
+
cache=cache,
|
|
391
|
+
)
|
|
392
|
+
|
|
393
|
+
logits = self.lm_head(hidden_states)
|
|
394
|
+
|
|
395
|
+
return LanguageModelOutput(
|
|
396
|
+
logits=logits, cross_attention_states=cross_attention_states
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
@staticmethod
|
|
400
|
+
def sanitize(weights):
|
|
401
|
+
# Remove unused precomputed rotary freqs
|
|
402
|
+
return {
|
|
403
|
+
k: v for k, v in weights.items() if "self_attn.rotary_emb.inv_freq" not in k
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
@property
|
|
407
|
+
def layers(self):
|
|
408
|
+
return self.model.layers
|
|
409
|
+
|
|
410
|
+
@property
|
|
411
|
+
def head_dim(self):
|
|
412
|
+
return self.config.hidden_size // self.config.num_attention_heads
|
|
413
|
+
|
|
414
|
+
@property
|
|
415
|
+
def n_kv_heads(self):
|
|
416
|
+
return self.config.num_key_value_heads
|
|
@@ -0,0 +1,172 @@
|
|
|
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, Tuple
|
|
7
|
+
|
|
8
|
+
import mlx.core as mx
|
|
9
|
+
import mlx.nn as nn
|
|
10
|
+
from huggingface_hub import snapshot_download
|
|
11
|
+
|
|
12
|
+
from ..cache import KVCache
|
|
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
|
+
ignore_index: int = -100
|
|
23
|
+
image_token_index: int = 128256
|
|
24
|
+
vision_feature_select_strategy: str = "default"
|
|
25
|
+
vision_feature_layer: int = -2
|
|
26
|
+
vocab_size: int = 32000
|
|
27
|
+
eos_token_id: Optional[List[int]] = None
|
|
28
|
+
|
|
29
|
+
@classmethod
|
|
30
|
+
def from_dict(cls, params):
|
|
31
|
+
return cls(
|
|
32
|
+
**{
|
|
33
|
+
k: v
|
|
34
|
+
for k, v in params.items()
|
|
35
|
+
if k in inspect.signature(cls).parameters
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Model(nn.Module):
|
|
41
|
+
def __init__(self, config: ModelConfig):
|
|
42
|
+
super().__init__()
|
|
43
|
+
self.config = config
|
|
44
|
+
self.vision_tower = VisionModel(config.vision_config)
|
|
45
|
+
self.language_model = LanguageModel(config.text_config)
|
|
46
|
+
self.multi_modal_projector = nn.Linear(
|
|
47
|
+
config.vision_config.vision_output_dim,
|
|
48
|
+
config.text_config.hidden_size,
|
|
49
|
+
bias=True,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def layers(self):
|
|
54
|
+
return self.language_model.model.layers
|
|
55
|
+
|
|
56
|
+
def __call__(
|
|
57
|
+
self,
|
|
58
|
+
input_ids: mx.array,
|
|
59
|
+
pixel_values: mx.array,
|
|
60
|
+
mask: mx.array,
|
|
61
|
+
cache: Optional[KVCache] = None,
|
|
62
|
+
**kwargs,
|
|
63
|
+
) -> Tuple[mx.array, Optional[mx.array]]:
|
|
64
|
+
|
|
65
|
+
aspect_ratio_ids = kwargs.pop("aspect_ratio_ids", None)
|
|
66
|
+
aspect_ratio_mask = kwargs.pop("aspect_ratio_mask", None)
|
|
67
|
+
cross_attention_mask = kwargs.pop("cross_attention_mask", None)
|
|
68
|
+
|
|
69
|
+
inputs_embeds = None
|
|
70
|
+
|
|
71
|
+
# Process vision input if provided
|
|
72
|
+
if pixel_values is not None:
|
|
73
|
+
if aspect_ratio_ids is None:
|
|
74
|
+
raise ValueError(
|
|
75
|
+
"`aspect_ratio_ids` must be provided if `pixel_values` is provided"
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
vision_outputs = self.vision_tower(
|
|
79
|
+
pixel_values=pixel_values,
|
|
80
|
+
aspect_ratio_ids=aspect_ratio_ids,
|
|
81
|
+
aspect_ratio_mask=aspect_ratio_mask,
|
|
82
|
+
)
|
|
83
|
+
cross_attention_states = vision_outputs[0]
|
|
84
|
+
|
|
85
|
+
cross_attention_states = self.multi_modal_projector(
|
|
86
|
+
cross_attention_states
|
|
87
|
+
).reshape(
|
|
88
|
+
-1,
|
|
89
|
+
cross_attention_states.shape[-2],
|
|
90
|
+
self.config.text_config.hidden_size,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
else:
|
|
94
|
+
cross_attention_states = None
|
|
95
|
+
|
|
96
|
+
# Prepare cross attention mask
|
|
97
|
+
if cross_attention_mask is not None:
|
|
98
|
+
cross_attention_mask, full_text_row_masked_out_mask = (
|
|
99
|
+
self._prepare_cross_attention_mask(
|
|
100
|
+
cross_attention_mask,
|
|
101
|
+
num_vision_tokens=(
|
|
102
|
+
self.config.vision_config.image_size
|
|
103
|
+
// self.config.vision_config.patch_size
|
|
104
|
+
)
|
|
105
|
+
** 2
|
|
106
|
+
+ 1,
|
|
107
|
+
)
|
|
108
|
+
)
|
|
109
|
+
else:
|
|
110
|
+
full_text_row_masked_out_mask = None
|
|
111
|
+
|
|
112
|
+
if cross_attention_mask is not None:
|
|
113
|
+
cache_position = mx.arange(input_ids.shape[1], dtype=mx.int32)
|
|
114
|
+
cross_attention_mask = cross_attention_mask[:, :, cache_position]
|
|
115
|
+
full_text_row_masked_out_mask = full_text_row_masked_out_mask[
|
|
116
|
+
:, :, cache_position
|
|
117
|
+
]
|
|
118
|
+
|
|
119
|
+
# Process language input
|
|
120
|
+
outputs = self.language_model(
|
|
121
|
+
input_ids=input_ids,
|
|
122
|
+
mask=mask,
|
|
123
|
+
cross_attention_states=cross_attention_states,
|
|
124
|
+
cross_attention_mask=cross_attention_mask,
|
|
125
|
+
full_text_row_masked_out_mask=full_text_row_masked_out_mask,
|
|
126
|
+
inputs_embeds=inputs_embeds,
|
|
127
|
+
cache=cache,
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
return outputs
|
|
131
|
+
|
|
132
|
+
def _prepare_cross_attention_mask(
|
|
133
|
+
self,
|
|
134
|
+
cross_attention_mask: mx.array,
|
|
135
|
+
num_vision_tokens: int,
|
|
136
|
+
) -> Tuple[mx.array, mx.array]:
|
|
137
|
+
batch_size, text_total_length, *_ = cross_attention_mask.shape
|
|
138
|
+
cross_attention_mask = mx.repeat(
|
|
139
|
+
cross_attention_mask, num_vision_tokens, axis=3
|
|
140
|
+
)
|
|
141
|
+
cross_attention_mask = cross_attention_mask.reshape(
|
|
142
|
+
batch_size, text_total_length, -1
|
|
143
|
+
)
|
|
144
|
+
cross_attention_mask = mx.expand_dims(cross_attention_mask, 1)
|
|
145
|
+
|
|
146
|
+
# Invert the mask
|
|
147
|
+
inverted_cross_attn_mask = 1.0 - cross_attention_mask
|
|
148
|
+
fill_array = mx.array(-1e9)
|
|
149
|
+
fill_array = mx.broadcast_to(fill_array, inverted_cross_attn_mask.shape)
|
|
150
|
+
cross_attention_mask = mx.where(
|
|
151
|
+
inverted_cross_attn_mask,
|
|
152
|
+
fill_array,
|
|
153
|
+
cross_attention_mask,
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
# Apply full-row bias
|
|
157
|
+
full_text_row_masked_out_mask = mx.any(
|
|
158
|
+
cross_attention_mask != -1e9,
|
|
159
|
+
axis=-1,
|
|
160
|
+
keepdims=True,
|
|
161
|
+
)
|
|
162
|
+
cross_attention_mask *= full_text_row_masked_out_mask
|
|
163
|
+
|
|
164
|
+
return cross_attention_mask, full_text_row_masked_out_mask
|
|
165
|
+
|
|
166
|
+
def sanitize(self, weights):
|
|
167
|
+
def transform_key(key):
|
|
168
|
+
if "vision_tower" not in key:
|
|
169
|
+
key = key.replace("vision_model", "vision_tower")
|
|
170
|
+
return key
|
|
171
|
+
|
|
172
|
+
return {transform_key(k): v for k, v in weights.items()}
|