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,738 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
import json
|
|
3
|
+
import math
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any, Optional, Tuple, Union
|
|
7
|
+
|
|
8
|
+
import mlx.core as mx
|
|
9
|
+
import mlx.nn as nn
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class BaseModelArgs:
|
|
14
|
+
@classmethod
|
|
15
|
+
def from_dict(cls, params):
|
|
16
|
+
return cls(
|
|
17
|
+
**{
|
|
18
|
+
k: v
|
|
19
|
+
for k, v in params.items()
|
|
20
|
+
if k in inspect.signature(cls).parameters
|
|
21
|
+
}
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass
|
|
26
|
+
class ModelConfig(BaseModelArgs):
|
|
27
|
+
model_type: str = "wav2vec2"
|
|
28
|
+
vocab_size: int = 32
|
|
29
|
+
hidden_size: int = 768
|
|
30
|
+
num_hidden_layers: int = 12
|
|
31
|
+
num_attention_heads: int = 12
|
|
32
|
+
intermediate_size: int = 3072
|
|
33
|
+
hidden_act: str = "gelu"
|
|
34
|
+
hidden_dropout: float = 0.1
|
|
35
|
+
activation_dropout: float = 0.1
|
|
36
|
+
attention_dropout: float = 0.1
|
|
37
|
+
feat_proj_dropout: float = 0.0
|
|
38
|
+
feat_quantizer_dropout: float = 0.0
|
|
39
|
+
final_dropout: float = 0.1
|
|
40
|
+
layerdrop: float = 0.1
|
|
41
|
+
initializer_range: float = 0.02
|
|
42
|
+
layer_norm_eps: float = 1e-5
|
|
43
|
+
feat_extract_norm: str = "group"
|
|
44
|
+
feat_extract_activation: str = "gelu"
|
|
45
|
+
conv_dim: Tuple[int, ...] = (512, 512, 512, 512, 512, 512, 512)
|
|
46
|
+
conv_stride: Tuple[int, ...] = (5, 2, 2, 2, 2, 2, 2)
|
|
47
|
+
conv_kernel: Tuple[int, ...] = (10, 3, 3, 3, 3, 2, 2)
|
|
48
|
+
conv_bias: bool = False
|
|
49
|
+
num_conv_pos_embeddings: int = 128
|
|
50
|
+
num_conv_pos_embedding_groups: int = 16
|
|
51
|
+
num_feat_extract_layers: int = 7
|
|
52
|
+
do_stable_layer_norm: bool = False
|
|
53
|
+
apply_spec_augment: bool = True
|
|
54
|
+
mask_time_prob: float = 0.05
|
|
55
|
+
mask_time_length: int = 10
|
|
56
|
+
mask_time_min_masks: int = 2
|
|
57
|
+
mask_feature_prob: float = 0.0
|
|
58
|
+
mask_feature_length: int = 10
|
|
59
|
+
mask_feature_min_masks: int = 0
|
|
60
|
+
num_codevectors_per_group: int = 320
|
|
61
|
+
num_codevector_groups: int = 2
|
|
62
|
+
contrastive_logits_temperature: float = 0.1
|
|
63
|
+
num_negatives: int = 100
|
|
64
|
+
codevector_dim: int = 256
|
|
65
|
+
proj_codevector_dim: int = 256
|
|
66
|
+
diversity_loss_weight: float = 0.1
|
|
67
|
+
ctc_loss_reduction: str = "sum"
|
|
68
|
+
ctc_zero_infinity: bool = False
|
|
69
|
+
pad_token_id: int = 0
|
|
70
|
+
bos_token_id: int = 1
|
|
71
|
+
eos_token_id: int = 2
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class Wav2Vec2NoLayerNormConvLayer(nn.Module):
|
|
75
|
+
def __init__(self, config, layer_id=0):
|
|
76
|
+
super().__init__()
|
|
77
|
+
self.in_conv_dim = config.conv_dim[layer_id - 1] if layer_id > 0 else 1
|
|
78
|
+
self.out_conv_dim = config.conv_dim[layer_id]
|
|
79
|
+
|
|
80
|
+
self.conv = nn.Conv1d(
|
|
81
|
+
self.in_conv_dim,
|
|
82
|
+
self.out_conv_dim,
|
|
83
|
+
kernel_size=config.conv_kernel[layer_id],
|
|
84
|
+
stride=config.conv_stride[layer_id],
|
|
85
|
+
bias=config.conv_bias,
|
|
86
|
+
)
|
|
87
|
+
self.activation = nn.GELU()
|
|
88
|
+
|
|
89
|
+
def __call__(self, hidden_states):
|
|
90
|
+
hidden_states = self.conv(hidden_states)
|
|
91
|
+
hidden_states = self.activation(hidden_states)
|
|
92
|
+
return hidden_states
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class Wav2Vec2LayerNormConvLayer(nn.Module):
|
|
96
|
+
def __init__(self, config, layer_id=0):
|
|
97
|
+
super().__init__()
|
|
98
|
+
self.in_conv_dim = config.conv_dim[layer_id - 1] if layer_id > 0 else 1
|
|
99
|
+
self.out_conv_dim = config.conv_dim[layer_id]
|
|
100
|
+
|
|
101
|
+
self.conv = nn.Conv1d(
|
|
102
|
+
self.in_conv_dim,
|
|
103
|
+
self.out_conv_dim,
|
|
104
|
+
kernel_size=config.conv_kernel[layer_id],
|
|
105
|
+
stride=config.conv_stride[layer_id],
|
|
106
|
+
bias=config.conv_bias,
|
|
107
|
+
)
|
|
108
|
+
self.layer_norm = nn.LayerNorm(self.out_conv_dim)
|
|
109
|
+
self.activation = nn.GELU()
|
|
110
|
+
|
|
111
|
+
def __call__(self, hidden_states):
|
|
112
|
+
hidden_states = self.conv(hidden_states.swapaxes(-2, -1))
|
|
113
|
+
|
|
114
|
+
hidden_states = self.layer_norm(hidden_states)
|
|
115
|
+
hidden_states = hidden_states.swapaxes(-2, -1)
|
|
116
|
+
|
|
117
|
+
hidden_states = self.activation(hidden_states)
|
|
118
|
+
return hidden_states
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class Wav2Vec2GroupNormConvLayer(nn.Module):
|
|
122
|
+
def __init__(self, config, layer_id=0):
|
|
123
|
+
super().__init__()
|
|
124
|
+
self.in_conv_dim = config.conv_dim[layer_id - 1] if layer_id > 0 else 1
|
|
125
|
+
self.out_conv_dim = config.conv_dim[layer_id]
|
|
126
|
+
|
|
127
|
+
self.conv = nn.Conv1d(
|
|
128
|
+
self.in_conv_dim,
|
|
129
|
+
self.out_conv_dim,
|
|
130
|
+
kernel_size=config.conv_kernel[layer_id],
|
|
131
|
+
stride=config.conv_stride[layer_id],
|
|
132
|
+
bias=config.conv_bias,
|
|
133
|
+
)
|
|
134
|
+
self.activation = nn.GELU()
|
|
135
|
+
|
|
136
|
+
self.layer_norm = nn.GroupNorm(
|
|
137
|
+
num_groups=self.out_conv_dim,
|
|
138
|
+
dims=self.out_conv_dim,
|
|
139
|
+
affine=True,
|
|
140
|
+
pytorch_compatible=True,
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
def __call__(self, hidden_states):
|
|
144
|
+
hidden_states = self.conv(hidden_states)
|
|
145
|
+
hidden_states = self.layer_norm(hidden_states)
|
|
146
|
+
hidden_states = self.activation(hidden_states)
|
|
147
|
+
return hidden_states
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def normalize_weight(x, except_dim=0):
|
|
151
|
+
if x.ndim != 3:
|
|
152
|
+
raise ValueError("Input tensor must have 3 dimensions")
|
|
153
|
+
|
|
154
|
+
axes = tuple(i for i in range(x.ndim) if i != except_dim)
|
|
155
|
+
return mx.sqrt(mx.sum(mx.power(x, 2), axis=axes, keepdims=True))
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class WNConv1d(nn.Module):
|
|
159
|
+
def __init__(
|
|
160
|
+
self,
|
|
161
|
+
in_channels: int,
|
|
162
|
+
out_channels: int,
|
|
163
|
+
kernel_size: int,
|
|
164
|
+
stride: int = 1,
|
|
165
|
+
padding: int = 0,
|
|
166
|
+
dilation: int = 1,
|
|
167
|
+
bias: bool = True,
|
|
168
|
+
groups: int = 1,
|
|
169
|
+
):
|
|
170
|
+
super().__init__()
|
|
171
|
+
|
|
172
|
+
if bias:
|
|
173
|
+
self.bias = mx.zeros((out_channels,))
|
|
174
|
+
|
|
175
|
+
self.kernel_size = kernel_size
|
|
176
|
+
self.padding = padding
|
|
177
|
+
self.dilation = dilation
|
|
178
|
+
self.stride = stride
|
|
179
|
+
self.groups = groups
|
|
180
|
+
|
|
181
|
+
scale = math.sqrt(1 / (in_channels * kernel_size))
|
|
182
|
+
weight_init = mx.random.uniform(
|
|
183
|
+
low=-scale,
|
|
184
|
+
high=scale,
|
|
185
|
+
shape=(out_channels, kernel_size, in_channels // groups),
|
|
186
|
+
)
|
|
187
|
+
self.weight_g = normalize_weight(weight_init, except_dim=1)
|
|
188
|
+
self.weight_v = weight_init / (self.weight_g + 1e-12)
|
|
189
|
+
|
|
190
|
+
def _extra_repr(self):
|
|
191
|
+
return (
|
|
192
|
+
f"in_channels={self.weight_v.shape[2]}, out_channels={self.weight_v.shape[0]}, "
|
|
193
|
+
f"kernel_size={self.kernel_size}, stride={self.stride}, "
|
|
194
|
+
f"padding={self.padding}, dilation={self.dilation}, "
|
|
195
|
+
f"bias={'bias' in self}"
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
def __call__(self, x):
|
|
199
|
+
weight = (
|
|
200
|
+
self.weight_g
|
|
201
|
+
* self.weight_v
|
|
202
|
+
/ normalize_weight(self.weight_v, except_dim=1)
|
|
203
|
+
)
|
|
204
|
+
y = mx.conv1d(x, weight, self.stride, self.padding, self.dilation, self.groups)
|
|
205
|
+
if "bias" in self:
|
|
206
|
+
y = y + self.bias
|
|
207
|
+
return y
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
class Wav2Vec2PositionalConvEmbedding(nn.Module):
|
|
211
|
+
def __init__(self, config):
|
|
212
|
+
super().__init__()
|
|
213
|
+
self.conv = WNConv1d(
|
|
214
|
+
config.hidden_size,
|
|
215
|
+
config.hidden_size,
|
|
216
|
+
kernel_size=config.num_conv_pos_embeddings,
|
|
217
|
+
padding=config.num_conv_pos_embeddings // 2,
|
|
218
|
+
groups=config.num_conv_pos_embedding_groups,
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
self.padding = Wav2Vec2SamePadLayer(config.num_conv_pos_embeddings)
|
|
222
|
+
self.activation = nn.GELU()
|
|
223
|
+
|
|
224
|
+
def __call__(self, hidden_states):
|
|
225
|
+
hidden_states = self.conv(hidden_states)
|
|
226
|
+
hidden_states = self.padding(hidden_states)
|
|
227
|
+
hidden_states = self.activation(hidden_states)
|
|
228
|
+
return hidden_states
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
class Wav2Vec2SamePadLayer(nn.Module):
|
|
232
|
+
def __init__(self, num_conv_pos_embeddings):
|
|
233
|
+
super().__init__()
|
|
234
|
+
self.num_pad_remove = 1 if num_conv_pos_embeddings % 2 == 0 else 0
|
|
235
|
+
|
|
236
|
+
def __call__(self, hidden_states):
|
|
237
|
+
if self.num_pad_remove > 0:
|
|
238
|
+
hidden_states = hidden_states[:, : -self.num_pad_remove, :]
|
|
239
|
+
return hidden_states
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
class Wav2Vec2FeatureEncoder(nn.Module):
|
|
243
|
+
def __init__(self, config):
|
|
244
|
+
super().__init__()
|
|
245
|
+
|
|
246
|
+
if config.feat_extract_norm == "group":
|
|
247
|
+
conv_layers = [Wav2Vec2GroupNormConvLayer(config, layer_id=0)] + [
|
|
248
|
+
Wav2Vec2NoLayerNormConvLayer(config, layer_id=i + 1)
|
|
249
|
+
for i in range(config.num_feat_extract_layers - 1)
|
|
250
|
+
]
|
|
251
|
+
elif config.feat_extract_norm == "layer":
|
|
252
|
+
conv_layers = [
|
|
253
|
+
Wav2Vec2LayerNormConvLayer(config, layer_id=i)
|
|
254
|
+
for i in range(config.num_feat_extract_layers)
|
|
255
|
+
]
|
|
256
|
+
else:
|
|
257
|
+
raise ValueError(
|
|
258
|
+
f"`config.feat_extract_norm` is {config.feat_extract_norm}, but has to be one of ['group', 'layer']"
|
|
259
|
+
)
|
|
260
|
+
self.conv_layers = conv_layers
|
|
261
|
+
|
|
262
|
+
def __call__(self, input_values):
|
|
263
|
+
hidden_states = input_values[:, None]
|
|
264
|
+
|
|
265
|
+
for conv_layer in self.conv_layers:
|
|
266
|
+
hidden_states = conv_layer(hidden_states)
|
|
267
|
+
|
|
268
|
+
return hidden_states
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
class Wav2Vec2FeatureProjection(nn.Module):
|
|
272
|
+
def __init__(self, config):
|
|
273
|
+
super().__init__()
|
|
274
|
+
self.layer_norm = nn.LayerNorm(config.conv_dim[-1], eps=config.layer_norm_eps)
|
|
275
|
+
self.projection = nn.Linear(config.conv_dim[-1], config.hidden_size)
|
|
276
|
+
self.dropout = nn.Dropout(config.feat_proj_dropout)
|
|
277
|
+
|
|
278
|
+
def __call__(self, hidden_states):
|
|
279
|
+
norm_hidden_states = self.layer_norm(hidden_states)
|
|
280
|
+
hidden_states = self.projection(norm_hidden_states)
|
|
281
|
+
hidden_states = self.dropout(hidden_states)
|
|
282
|
+
return hidden_states, norm_hidden_states
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
class Wav2Vec2Attention(nn.Module):
|
|
286
|
+
def __init__(
|
|
287
|
+
self,
|
|
288
|
+
embed_dim: int,
|
|
289
|
+
num_heads: int,
|
|
290
|
+
dropout: float = 0.0,
|
|
291
|
+
is_decoder: bool = False,
|
|
292
|
+
bias: bool = True,
|
|
293
|
+
is_causal: bool = False,
|
|
294
|
+
config: Optional[ModelConfig] = None,
|
|
295
|
+
):
|
|
296
|
+
super().__init__()
|
|
297
|
+
self.embed_dim = embed_dim
|
|
298
|
+
self.num_heads = num_heads
|
|
299
|
+
self.dropout = dropout
|
|
300
|
+
self.head_dim = embed_dim // num_heads
|
|
301
|
+
self.config = config
|
|
302
|
+
|
|
303
|
+
if (self.head_dim * num_heads) != self.embed_dim:
|
|
304
|
+
raise ValueError(
|
|
305
|
+
f"embed_dim must be divisible by num_heads (got `embed_dim`: {self.embed_dim} and `num_heads`: {num_heads})."
|
|
306
|
+
)
|
|
307
|
+
self.scaling = self.head_dim**-0.5
|
|
308
|
+
self.is_decoder = is_decoder
|
|
309
|
+
self.is_causal = is_causal
|
|
310
|
+
|
|
311
|
+
self.k_proj = nn.Linear(embed_dim, embed_dim, bias=bias)
|
|
312
|
+
self.v_proj = nn.Linear(embed_dim, embed_dim, bias=bias)
|
|
313
|
+
self.q_proj = nn.Linear(embed_dim, embed_dim, bias=bias)
|
|
314
|
+
self.out_proj = nn.Linear(embed_dim, embed_dim, bias=bias)
|
|
315
|
+
|
|
316
|
+
def _shape(self, tensor: mx.array, seq_len: int, bsz: int):
|
|
317
|
+
return tensor.reshape(bsz, seq_len, self.num_heads, self.head_dim).transpose(
|
|
318
|
+
0, 2, 1, 3
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
def __call__(
|
|
322
|
+
self,
|
|
323
|
+
hidden_states: mx.array,
|
|
324
|
+
key_value_states: Optional[Any] = None,
|
|
325
|
+
past_key_value: Optional[Tuple[Any]] = None,
|
|
326
|
+
attention_mask: Optional[Any] = None,
|
|
327
|
+
) -> Tuple[mx.array, Optional[mx.array], Optional[Tuple[mx.array]]]:
|
|
328
|
+
"""Input shape: Batch x Time x Channel"""
|
|
329
|
+
|
|
330
|
+
# if key_value_states are provided this layer is used as a cross-attention layer
|
|
331
|
+
# for the decoder
|
|
332
|
+
is_cross_attention = key_value_states is not None
|
|
333
|
+
|
|
334
|
+
bsz, tgt_len, _ = hidden_states.shape
|
|
335
|
+
|
|
336
|
+
# get query proj
|
|
337
|
+
query_states = self.q_proj(hidden_states) * self.scaling
|
|
338
|
+
# get key, value proj
|
|
339
|
+
# `past_key_value[0].shape[2] == key_value_states.shape[1]`
|
|
340
|
+
# is checking that the `sequence_length` of the `past_key_value` is the same as
|
|
341
|
+
# the provided `key_value_states` to support prefix tuning
|
|
342
|
+
if (
|
|
343
|
+
is_cross_attention
|
|
344
|
+
and past_key_value is not None
|
|
345
|
+
and past_key_value[0].shape[2] == key_value_states.shape[1]
|
|
346
|
+
):
|
|
347
|
+
# reuse k,v, cross_attentions
|
|
348
|
+
key_states = past_key_value[0]
|
|
349
|
+
value_states = past_key_value[1]
|
|
350
|
+
elif is_cross_attention:
|
|
351
|
+
# cross_attentions
|
|
352
|
+
key_states = self._shape(self.k_proj(key_value_states), -1, bsz)
|
|
353
|
+
value_states = self._shape(self.v_proj(key_value_states), -1, bsz)
|
|
354
|
+
elif past_key_value is not None:
|
|
355
|
+
# reuse k, v, self_attention
|
|
356
|
+
key_states = self._shape(self.k_proj(hidden_states), -1, bsz)
|
|
357
|
+
value_states = self._shape(self.v_proj(hidden_states), -1, bsz)
|
|
358
|
+
key_states = mx.concatenate([past_key_value[0], key_states], axis=2)
|
|
359
|
+
value_states = mx.concatenate([past_key_value[1], value_states], axis=2)
|
|
360
|
+
else:
|
|
361
|
+
# self_attention
|
|
362
|
+
key_states = self._shape(self.k_proj(hidden_states), -1, bsz)
|
|
363
|
+
value_states = self._shape(self.v_proj(hidden_states), -1, bsz)
|
|
364
|
+
|
|
365
|
+
if self.is_decoder:
|
|
366
|
+
past_key_value = (key_states, value_states)
|
|
367
|
+
|
|
368
|
+
query_states = self._shape(query_states, tgt_len, bsz)
|
|
369
|
+
|
|
370
|
+
attn_output = mx.fast.scaled_dot_product_attention(
|
|
371
|
+
q=query_states,
|
|
372
|
+
k=key_states,
|
|
373
|
+
v=value_states,
|
|
374
|
+
scale=1.0,
|
|
375
|
+
mask=attention_mask,
|
|
376
|
+
)
|
|
377
|
+
|
|
378
|
+
attn_output = attn_output.transpose(0, 2, 1, 3)
|
|
379
|
+
|
|
380
|
+
# Use the `embed_dim` from the config (stored in the class) rather than `hidden_state` because `attn_output` can be
|
|
381
|
+
# partitioned across GPUs when using tensor-parallelism.
|
|
382
|
+
attn_output = attn_output.reshape(bsz, tgt_len, self.embed_dim)
|
|
383
|
+
attn_output = self.out_proj(attn_output)
|
|
384
|
+
|
|
385
|
+
return attn_output, past_key_value
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
class Wav2Vec2FeedForward(nn.Module):
|
|
389
|
+
def __init__(self, config):
|
|
390
|
+
super().__init__()
|
|
391
|
+
self.intermediate_dropout = nn.Dropout(config.activation_dropout)
|
|
392
|
+
|
|
393
|
+
self.intermediate_dense = nn.Linear(
|
|
394
|
+
config.hidden_size, config.intermediate_size
|
|
395
|
+
)
|
|
396
|
+
|
|
397
|
+
self.intermediate_act_fn = nn.GELU()
|
|
398
|
+
|
|
399
|
+
self.output_dense = nn.Linear(config.intermediate_size, config.hidden_size)
|
|
400
|
+
self.output_dropout = nn.Dropout(config.hidden_dropout)
|
|
401
|
+
|
|
402
|
+
def __call__(self, hidden_states):
|
|
403
|
+
hidden_states = self.intermediate_dense(hidden_states)
|
|
404
|
+
hidden_states = self.intermediate_act_fn(hidden_states)
|
|
405
|
+
hidden_states = self.intermediate_dropout(hidden_states)
|
|
406
|
+
|
|
407
|
+
hidden_states = self.output_dense(hidden_states)
|
|
408
|
+
hidden_states = self.output_dropout(hidden_states)
|
|
409
|
+
return hidden_states
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
class Wav2Vec2EncoderLayer(nn.Module):
|
|
413
|
+
def __init__(self, config):
|
|
414
|
+
super().__init__()
|
|
415
|
+
self.attention = Wav2Vec2Attention(
|
|
416
|
+
embed_dim=config.hidden_size,
|
|
417
|
+
num_heads=config.num_attention_heads,
|
|
418
|
+
dropout=config.attention_dropout,
|
|
419
|
+
is_decoder=False,
|
|
420
|
+
)
|
|
421
|
+
|
|
422
|
+
self.dropout = nn.Dropout(config.hidden_dropout)
|
|
423
|
+
self.layer_norm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
|
424
|
+
self.feed_forward = Wav2Vec2FeedForward(config)
|
|
425
|
+
self.final_layer_norm = nn.LayerNorm(
|
|
426
|
+
config.hidden_size, eps=config.layer_norm_eps
|
|
427
|
+
)
|
|
428
|
+
|
|
429
|
+
def __call__(self, hidden_states, attention_mask=None):
|
|
430
|
+
attn_residual = hidden_states
|
|
431
|
+
hidden_states, _ = self.attention(hidden_states, attention_mask=attention_mask)
|
|
432
|
+
hidden_states = self.dropout(hidden_states)
|
|
433
|
+
hidden_states = attn_residual + hidden_states
|
|
434
|
+
|
|
435
|
+
hidden_states = self.layer_norm(hidden_states)
|
|
436
|
+
hidden_states = hidden_states + self.feed_forward(hidden_states)
|
|
437
|
+
hidden_states = self.final_layer_norm(hidden_states)
|
|
438
|
+
|
|
439
|
+
outputs = (hidden_states,)
|
|
440
|
+
|
|
441
|
+
return outputs
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
class Wav2Vec2EncoderLayerStableLayerNorm(nn.Module):
|
|
445
|
+
def __init__(self, config):
|
|
446
|
+
super().__init__()
|
|
447
|
+
self.attention = Wav2Vec2Attention(
|
|
448
|
+
embed_dim=config.hidden_size,
|
|
449
|
+
num_heads=config.num_attention_heads,
|
|
450
|
+
dropout=config.attention_dropout,
|
|
451
|
+
is_decoder=False,
|
|
452
|
+
)
|
|
453
|
+
self.dropout = nn.Dropout(config.hidden_dropout)
|
|
454
|
+
self.layer_norm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
|
455
|
+
self.feed_forward = Wav2Vec2FeedForward(config)
|
|
456
|
+
self.final_layer_norm = nn.LayerNorm(
|
|
457
|
+
config.hidden_size, eps=config.layer_norm_eps
|
|
458
|
+
)
|
|
459
|
+
|
|
460
|
+
def __call__(
|
|
461
|
+
self,
|
|
462
|
+
hidden_states: mx.array,
|
|
463
|
+
attention_mask: Optional[mx.array] = None,
|
|
464
|
+
):
|
|
465
|
+
attn_residual = hidden_states
|
|
466
|
+
hidden_states = self.layer_norm(hidden_states)
|
|
467
|
+
hidden_states, _ = self.attention(hidden_states, attention_mask=attention_mask)
|
|
468
|
+
hidden_states = self.dropout(hidden_states)
|
|
469
|
+
hidden_states = attn_residual + hidden_states
|
|
470
|
+
hidden_states = hidden_states + self.feed_forward(
|
|
471
|
+
self.final_layer_norm(hidden_states)
|
|
472
|
+
)
|
|
473
|
+
|
|
474
|
+
outputs = (hidden_states,)
|
|
475
|
+
|
|
476
|
+
return outputs
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
class Wav2Vec2Encoder(nn.Module):
|
|
480
|
+
def __init__(self, config):
|
|
481
|
+
super().__init__()
|
|
482
|
+
self.config = config
|
|
483
|
+
self.pos_conv_embed = Wav2Vec2PositionalConvEmbedding(config)
|
|
484
|
+
self.layer_norm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
|
485
|
+
self.dropout = nn.Dropout(config.hidden_dropout)
|
|
486
|
+
self.layers = [
|
|
487
|
+
Wav2Vec2EncoderLayer(config) for _ in range(config.num_hidden_layers)
|
|
488
|
+
]
|
|
489
|
+
|
|
490
|
+
def __call__(
|
|
491
|
+
self,
|
|
492
|
+
hidden_states: mx.array,
|
|
493
|
+
attention_mask: Optional[mx.array] = None,
|
|
494
|
+
output_hidden_states: bool = False,
|
|
495
|
+
return_dict: bool = True,
|
|
496
|
+
):
|
|
497
|
+
all_hidden_states = () if output_hidden_states else None
|
|
498
|
+
|
|
499
|
+
if attention_mask is not None:
|
|
500
|
+
# make sure padded tokens output 0
|
|
501
|
+
expand_attention_mask = attention_mask[..., None]
|
|
502
|
+
expand_attention_mask = mx.repeat(
|
|
503
|
+
expand_attention_mask, 1, 1, hidden_states.shape[2]
|
|
504
|
+
)
|
|
505
|
+
hidden_states[~expand_attention_mask] = 0
|
|
506
|
+
|
|
507
|
+
# extend attention_mask
|
|
508
|
+
attention_mask = 1.0 - attention_mask[:, None, None, :].astype(
|
|
509
|
+
hidden_states.dtype
|
|
510
|
+
)
|
|
511
|
+
attention_mask = attention_mask * mx.finfo(hidden_states.dtype).min
|
|
512
|
+
attention_mask = attention_mask.expand(
|
|
513
|
+
attention_mask.shape[0],
|
|
514
|
+
1,
|
|
515
|
+
attention_mask.shape[-1],
|
|
516
|
+
attention_mask.shape[-1],
|
|
517
|
+
)
|
|
518
|
+
|
|
519
|
+
position_embeddings = self.pos_conv_embed(hidden_states)
|
|
520
|
+
hidden_states = hidden_states + position_embeddings
|
|
521
|
+
hidden_states = self.layer_norm(hidden_states)
|
|
522
|
+
hidden_states = self.dropout(hidden_states)
|
|
523
|
+
|
|
524
|
+
for layer in self.layers:
|
|
525
|
+
if output_hidden_states:
|
|
526
|
+
all_hidden_states = all_hidden_states + (hidden_states,)
|
|
527
|
+
|
|
528
|
+
layer_outputs = layer(
|
|
529
|
+
hidden_states,
|
|
530
|
+
attention_mask=attention_mask,
|
|
531
|
+
)
|
|
532
|
+
hidden_states = layer_outputs[0]
|
|
533
|
+
|
|
534
|
+
if output_hidden_states:
|
|
535
|
+
all_hidden_states = all_hidden_states + (hidden_states,)
|
|
536
|
+
|
|
537
|
+
if not return_dict:
|
|
538
|
+
return tuple(v for v in [hidden_states, all_hidden_states] if v is not None)
|
|
539
|
+
return Wav2Vec2BaseModelOutput(
|
|
540
|
+
last_hidden_state=hidden_states,
|
|
541
|
+
hidden_states=all_hidden_states,
|
|
542
|
+
)
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
class Wav2Vec2EncoderStableLayerNorm(nn.Module):
|
|
546
|
+
def __init__(self, config):
|
|
547
|
+
super().__init__()
|
|
548
|
+
self.config = config
|
|
549
|
+
self.pos_conv_embed = Wav2Vec2PositionalConvEmbedding(config)
|
|
550
|
+
self.layer_norm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
|
551
|
+
self.dropout = nn.Dropout(config.hidden_dropout)
|
|
552
|
+
self.layers = [
|
|
553
|
+
Wav2Vec2EncoderLayerStableLayerNorm(config)
|
|
554
|
+
for _ in range(config.num_hidden_layers)
|
|
555
|
+
]
|
|
556
|
+
|
|
557
|
+
def __call__(
|
|
558
|
+
self,
|
|
559
|
+
hidden_states,
|
|
560
|
+
attention_mask=None,
|
|
561
|
+
output_hidden_states=False,
|
|
562
|
+
return_dict=True,
|
|
563
|
+
):
|
|
564
|
+
all_hidden_states = () if output_hidden_states else None
|
|
565
|
+
|
|
566
|
+
if attention_mask is not None:
|
|
567
|
+
# make sure padded tokens are not attended to
|
|
568
|
+
expand_attention_mask = attention_mask[..., None]
|
|
569
|
+
expand_attention_mask = mx.repeat(
|
|
570
|
+
expand_attention_mask, 1, 1, hidden_states.shape[2]
|
|
571
|
+
)
|
|
572
|
+
hidden_states = hidden_states * expand_attention_mask.astype(
|
|
573
|
+
hidden_states.dtype
|
|
574
|
+
)
|
|
575
|
+
|
|
576
|
+
# extend attention_mask
|
|
577
|
+
attention_mask = 1.0 - attention_mask[:, None, None, :].astype(
|
|
578
|
+
hidden_states.dtype
|
|
579
|
+
)
|
|
580
|
+
attention_mask = attention_mask * mx.finfo(hidden_states.dtype).min
|
|
581
|
+
attention_mask = attention_mask.expand(
|
|
582
|
+
attention_mask.shape[0],
|
|
583
|
+
1,
|
|
584
|
+
attention_mask.shape[-1],
|
|
585
|
+
attention_mask.shape[-1],
|
|
586
|
+
)
|
|
587
|
+
|
|
588
|
+
position_embeddings = self.pos_conv_embed(hidden_states)
|
|
589
|
+
hidden_states = hidden_states + position_embeddings
|
|
590
|
+
hidden_states = self.dropout(hidden_states)
|
|
591
|
+
|
|
592
|
+
for layer in self.layers:
|
|
593
|
+
if output_hidden_states:
|
|
594
|
+
all_hidden_states = all_hidden_states + (hidden_states,)
|
|
595
|
+
|
|
596
|
+
layer_outputs = layer(
|
|
597
|
+
hidden_states,
|
|
598
|
+
attention_mask=attention_mask,
|
|
599
|
+
)
|
|
600
|
+
hidden_states = layer_outputs[0]
|
|
601
|
+
|
|
602
|
+
hidden_states = self.layer_norm(hidden_states)
|
|
603
|
+
|
|
604
|
+
if output_hidden_states:
|
|
605
|
+
all_hidden_states = all_hidden_states + (hidden_states,)
|
|
606
|
+
|
|
607
|
+
if not return_dict:
|
|
608
|
+
return tuple(v for v in [hidden_states, all_hidden_states] if v is not None)
|
|
609
|
+
return Wav2Vec2BaseModelOutput(
|
|
610
|
+
last_hidden_state=hidden_states,
|
|
611
|
+
hidden_states=all_hidden_states,
|
|
612
|
+
)
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
@dataclass
|
|
616
|
+
class Wav2Vec2BaseModelOutput:
|
|
617
|
+
last_hidden_state: Optional[mx.array] = None
|
|
618
|
+
extract_features: Optional[mx.array] = None
|
|
619
|
+
hidden_states: Optional[Tuple[mx.array, ...]] = None
|
|
620
|
+
attentions: Optional[Tuple[mx.array, ...]] = None
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
class Wav2Vec2Model(nn.Module):
|
|
624
|
+
def __init__(self, config: ModelConfig):
|
|
625
|
+
super().__init__()
|
|
626
|
+
|
|
627
|
+
self.config = config
|
|
628
|
+
self.feature_extractor = Wav2Vec2FeatureEncoder(config)
|
|
629
|
+
self.feature_projection = Wav2Vec2FeatureProjection(config)
|
|
630
|
+
|
|
631
|
+
if config.do_stable_layer_norm:
|
|
632
|
+
self.encoder = Wav2Vec2EncoderStableLayerNorm(config)
|
|
633
|
+
else:
|
|
634
|
+
self.encoder = Wav2Vec2Encoder(config)
|
|
635
|
+
|
|
636
|
+
def _mask_hidden_states(
|
|
637
|
+
self,
|
|
638
|
+
hidden_states: mx.array,
|
|
639
|
+
mask_time_indices: Optional[mx.array] = None,
|
|
640
|
+
attention_mask: Optional[mx.array] = None,
|
|
641
|
+
):
|
|
642
|
+
# `config.apply_spec_augment` can set masking to False
|
|
643
|
+
if not getattr(self.config, "apply_spec_augment", True):
|
|
644
|
+
return hidden_states
|
|
645
|
+
|
|
646
|
+
return hidden_states
|
|
647
|
+
|
|
648
|
+
def __call__(
|
|
649
|
+
self,
|
|
650
|
+
input_values: Optional[mx.array],
|
|
651
|
+
attention_mask: Optional[mx.array] = None,
|
|
652
|
+
output_hidden_states: bool = True,
|
|
653
|
+
return_dict: bool = True,
|
|
654
|
+
) -> Union[Tuple, Wav2Vec2BaseModelOutput]:
|
|
655
|
+
extract_features = self.feature_extractor(input_values)
|
|
656
|
+
extract_features = extract_features.transpose(0, 2, 1)
|
|
657
|
+
|
|
658
|
+
if attention_mask is not None:
|
|
659
|
+
# compute reduced attention_mask corresponding to feature vectors
|
|
660
|
+
attention_mask = self._get_feature_vector_attention_mask(
|
|
661
|
+
extract_features.shape[1], attention_mask
|
|
662
|
+
)
|
|
663
|
+
|
|
664
|
+
hidden_states, extract_features = self.feature_projection(extract_features)
|
|
665
|
+
hidden_states = self._mask_hidden_states(
|
|
666
|
+
hidden_states,
|
|
667
|
+
attention_mask=attention_mask,
|
|
668
|
+
)
|
|
669
|
+
|
|
670
|
+
encoder_outputs = self.encoder(
|
|
671
|
+
hidden_states,
|
|
672
|
+
attention_mask=attention_mask,
|
|
673
|
+
output_hidden_states=output_hidden_states,
|
|
674
|
+
return_dict=return_dict,
|
|
675
|
+
)
|
|
676
|
+
hidden_states = encoder_outputs.last_hidden_state
|
|
677
|
+
|
|
678
|
+
if not return_dict:
|
|
679
|
+
return (hidden_states, extract_features) + encoder_outputs[1:]
|
|
680
|
+
|
|
681
|
+
return Wav2Vec2BaseModelOutput(
|
|
682
|
+
last_hidden_state=hidden_states,
|
|
683
|
+
extract_features=extract_features,
|
|
684
|
+
hidden_states=encoder_outputs.hidden_states,
|
|
685
|
+
attentions=encoder_outputs.attentions,
|
|
686
|
+
)
|
|
687
|
+
|
|
688
|
+
def sanitize(self, weights):
|
|
689
|
+
sanitized_weights = {}
|
|
690
|
+
for k, v in weights.items():
|
|
691
|
+
if k.startswith("wav2vec2."):
|
|
692
|
+
k = k.replace("wav2vec2.", "")
|
|
693
|
+
if k.endswith(".conv.weight"):
|
|
694
|
+
v = v.swapaxes(1, 2)
|
|
695
|
+
if k.endswith(".conv.weight_v") or k.endswith(".conv.weight_g"):
|
|
696
|
+
v = v.swapaxes(1, 2)
|
|
697
|
+
if k.endswith(".parametrizations.weight.original0"):
|
|
698
|
+
k = k.replace(".parametrizations.weight.original0", ".weight_g")
|
|
699
|
+
v = v.swapaxes(1, 2)
|
|
700
|
+
if k.endswith(".parametrizations.weight.original1"):
|
|
701
|
+
k = k.replace(".parametrizations.weight.original1", ".weight_v")
|
|
702
|
+
v = v.swapaxes(1, 2)
|
|
703
|
+
if (
|
|
704
|
+
"lm_head." in k
|
|
705
|
+
or k.startswith("quantizer.")
|
|
706
|
+
or k.startswith("project_")
|
|
707
|
+
or k == "masked_spec_embed"
|
|
708
|
+
):
|
|
709
|
+
continue
|
|
710
|
+
|
|
711
|
+
sanitized_weights[k] = v
|
|
712
|
+
return sanitized_weights
|
|
713
|
+
|
|
714
|
+
@classmethod
|
|
715
|
+
def from_pretrained(cls, model_path: str, **kwargs):
|
|
716
|
+
model_path = Path(model_path)
|
|
717
|
+
if not model_path.exists():
|
|
718
|
+
raise FileNotFoundError(f"Model directory not found: {model_path}")
|
|
719
|
+
|
|
720
|
+
config_path = model_path / "config.json"
|
|
721
|
+
if not config_path.exists():
|
|
722
|
+
raise FileNotFoundError(f"config.json not found in {model_path}")
|
|
723
|
+
|
|
724
|
+
model_path_safetensors = model_path / "model.safetensors"
|
|
725
|
+
if not model_path_safetensors.exists():
|
|
726
|
+
raise FileNotFoundError(f"model.safetensors not found in {model_path}")
|
|
727
|
+
|
|
728
|
+
with open(config_path, "r") as f:
|
|
729
|
+
config_dict = json.load(f)
|
|
730
|
+
config = ModelConfig.from_dict(config_dict)
|
|
731
|
+
model = Wav2Vec2Model(config)
|
|
732
|
+
|
|
733
|
+
weights = mx.load(model_path_safetensors.as_posix(), format="safetensors")
|
|
734
|
+
weights = model.sanitize(weights)
|
|
735
|
+
model.load_weights(list(weights.items()))
|
|
736
|
+
mx.eval(model.parameters())
|
|
737
|
+
|
|
738
|
+
return model
|