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,248 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
@dataclass
|
|
5
|
+
class AlignedToken:
|
|
6
|
+
id: int
|
|
7
|
+
text: str
|
|
8
|
+
start: float
|
|
9
|
+
duration: float
|
|
10
|
+
end: float = 0.0 # temporary
|
|
11
|
+
|
|
12
|
+
def __post_init__(self) -> None:
|
|
13
|
+
self.end = self.start + self.duration
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass
|
|
17
|
+
class AlignedSentence:
|
|
18
|
+
text: str
|
|
19
|
+
tokens: list[AlignedToken]
|
|
20
|
+
start: float = 0.0 # temporary
|
|
21
|
+
end: float = 0.0 # temporary
|
|
22
|
+
duration: float = 0.0 # temporary
|
|
23
|
+
|
|
24
|
+
def __post_init__(self) -> None:
|
|
25
|
+
self.tokens = list(sorted(self.tokens, key=lambda x: x.start))
|
|
26
|
+
self.start = self.tokens[0].start
|
|
27
|
+
self.end = self.tokens[-1].end
|
|
28
|
+
self.duration = self.end - self.start
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass
|
|
32
|
+
class AlignedResult:
|
|
33
|
+
text: str
|
|
34
|
+
sentences: list[AlignedSentence]
|
|
35
|
+
|
|
36
|
+
def __post_init__(self) -> None:
|
|
37
|
+
self.text = self.text.strip()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def tokens_to_sentences(tokens: list[AlignedToken]) -> list[AlignedSentence]:
|
|
41
|
+
sentences = []
|
|
42
|
+
current_tokens = []
|
|
43
|
+
|
|
44
|
+
for idx, token in enumerate(tokens):
|
|
45
|
+
current_tokens.append(token)
|
|
46
|
+
|
|
47
|
+
# hacky, will fix
|
|
48
|
+
if (
|
|
49
|
+
"!" in token.text
|
|
50
|
+
or "?" in token.text
|
|
51
|
+
or "。" in token.text
|
|
52
|
+
or "?" in token.text
|
|
53
|
+
or "!" in token.text
|
|
54
|
+
or (
|
|
55
|
+
"." in token.text
|
|
56
|
+
and (idx == len(tokens) - 1 or " " in tokens[idx + 1].text)
|
|
57
|
+
)
|
|
58
|
+
): # type: ignore
|
|
59
|
+
sentence_text = "".join(t.text for t in current_tokens)
|
|
60
|
+
sentence = AlignedSentence(text=sentence_text, tokens=current_tokens)
|
|
61
|
+
sentences.append(sentence)
|
|
62
|
+
|
|
63
|
+
current_tokens = []
|
|
64
|
+
|
|
65
|
+
if current_tokens:
|
|
66
|
+
sentence_text = "".join(t.text for t in current_tokens)
|
|
67
|
+
sentence = AlignedSentence(text=sentence_text, tokens=current_tokens)
|
|
68
|
+
sentences.append(sentence)
|
|
69
|
+
|
|
70
|
+
return sentences
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def sentences_to_result(sentences: list[AlignedSentence]) -> AlignedResult:
|
|
74
|
+
return AlignedResult("".join(sentence.text for sentence in sentences), sentences)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def merge_longest_contiguous(
|
|
78
|
+
a: list[AlignedToken],
|
|
79
|
+
b: list[AlignedToken],
|
|
80
|
+
*,
|
|
81
|
+
overlap_duration: float,
|
|
82
|
+
):
|
|
83
|
+
if not a or not b:
|
|
84
|
+
return b if not a else a
|
|
85
|
+
|
|
86
|
+
a_end_time = a[-1].end
|
|
87
|
+
b_start_time = b[0].start
|
|
88
|
+
|
|
89
|
+
if a_end_time <= b_start_time:
|
|
90
|
+
return a + b
|
|
91
|
+
|
|
92
|
+
overlap_a = [token for token in a if token.end > b_start_time - overlap_duration]
|
|
93
|
+
overlap_b = [token for token in b if token.start < a_end_time + overlap_duration]
|
|
94
|
+
|
|
95
|
+
enough_pairs = len(overlap_a) // 2
|
|
96
|
+
|
|
97
|
+
if len(overlap_a) < 2 or len(overlap_b) < 2:
|
|
98
|
+
cutoff_time = (a_end_time + b_start_time) / 2
|
|
99
|
+
return [t for t in a if t.end <= cutoff_time] + [
|
|
100
|
+
t for t in b if t.start >= cutoff_time
|
|
101
|
+
]
|
|
102
|
+
|
|
103
|
+
best_contiguous = []
|
|
104
|
+
for i in range(len(overlap_a)):
|
|
105
|
+
for j in range(len(overlap_b)):
|
|
106
|
+
if (
|
|
107
|
+
overlap_a[i].id == overlap_b[j].id
|
|
108
|
+
and abs(overlap_a[i].start - overlap_b[j].start) < overlap_duration / 2
|
|
109
|
+
):
|
|
110
|
+
current = []
|
|
111
|
+
k, l_ = i, j
|
|
112
|
+
while (
|
|
113
|
+
k < len(overlap_a)
|
|
114
|
+
and l_ < len(overlap_b)
|
|
115
|
+
and overlap_a[k].id == overlap_b[l_].id
|
|
116
|
+
and abs(overlap_a[k].start - overlap_b[l_].start)
|
|
117
|
+
< overlap_duration / 2
|
|
118
|
+
):
|
|
119
|
+
current.append((k, l_))
|
|
120
|
+
k += 1
|
|
121
|
+
l_ += 1
|
|
122
|
+
|
|
123
|
+
if len(current) > len(best_contiguous):
|
|
124
|
+
best_contiguous = current
|
|
125
|
+
|
|
126
|
+
if len(best_contiguous) >= enough_pairs:
|
|
127
|
+
a_start_idx = len(a) - len(overlap_a)
|
|
128
|
+
lcs_indices_a = [a_start_idx + pair[0] for pair in best_contiguous]
|
|
129
|
+
lcs_indices_b = [pair[1] for pair in best_contiguous]
|
|
130
|
+
|
|
131
|
+
result = []
|
|
132
|
+
result.extend(a[: lcs_indices_a[0]])
|
|
133
|
+
|
|
134
|
+
for i in range(len(best_contiguous)):
|
|
135
|
+
idx_a = lcs_indices_a[i]
|
|
136
|
+
idx_b = lcs_indices_b[i]
|
|
137
|
+
|
|
138
|
+
result.append(a[idx_a])
|
|
139
|
+
|
|
140
|
+
if i < len(best_contiguous) - 1:
|
|
141
|
+
next_idx_a = lcs_indices_a[i + 1]
|
|
142
|
+
next_idx_b = lcs_indices_b[i + 1]
|
|
143
|
+
|
|
144
|
+
gap_tokens_a = a[idx_a + 1 : next_idx_a]
|
|
145
|
+
gap_tokens_b = b[idx_b + 1 : next_idx_b]
|
|
146
|
+
|
|
147
|
+
if len(gap_tokens_b) > len(gap_tokens_a):
|
|
148
|
+
result.extend(gap_tokens_b)
|
|
149
|
+
else:
|
|
150
|
+
result.extend(gap_tokens_a)
|
|
151
|
+
|
|
152
|
+
result.extend(b[lcs_indices_b[-1] + 1 :])
|
|
153
|
+
return result
|
|
154
|
+
else:
|
|
155
|
+
raise RuntimeError(f"No pairs exceeding {enough_pairs}")
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def merge_longest_common_subsequence(
|
|
159
|
+
a: list[AlignedToken],
|
|
160
|
+
b: list[AlignedToken],
|
|
161
|
+
*,
|
|
162
|
+
overlap_duration: float,
|
|
163
|
+
):
|
|
164
|
+
if not a or not b:
|
|
165
|
+
return b if not a else a
|
|
166
|
+
|
|
167
|
+
a_end_time = a[-1].end
|
|
168
|
+
b_start_time = b[0].start
|
|
169
|
+
|
|
170
|
+
if a_end_time <= b_start_time:
|
|
171
|
+
return a + b
|
|
172
|
+
|
|
173
|
+
overlap_a = [token for token in a if token.end > b_start_time - overlap_duration]
|
|
174
|
+
overlap_b = [token for token in b if token.start < a_end_time + overlap_duration]
|
|
175
|
+
|
|
176
|
+
if len(overlap_a) < 2 or len(overlap_b) < 2:
|
|
177
|
+
cutoff_time = (a_end_time + b_start_time) / 2
|
|
178
|
+
return [t for t in a if t.end <= cutoff_time] + [
|
|
179
|
+
t for t in b if t.start >= cutoff_time
|
|
180
|
+
]
|
|
181
|
+
|
|
182
|
+
dp = [[0 for _ in range(len(overlap_b) + 1)] for _ in range(len(overlap_a) + 1)]
|
|
183
|
+
|
|
184
|
+
for i in range(1, len(overlap_a) + 1):
|
|
185
|
+
for j in range(1, len(overlap_b) + 1):
|
|
186
|
+
if (
|
|
187
|
+
overlap_a[i - 1].id == overlap_b[j - 1].id
|
|
188
|
+
and abs(overlap_a[i - 1].start - overlap_b[j - 1].start)
|
|
189
|
+
< overlap_duration / 2
|
|
190
|
+
):
|
|
191
|
+
dp[i][j] = dp[i - 1][j - 1] + 1
|
|
192
|
+
else:
|
|
193
|
+
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
|
|
194
|
+
|
|
195
|
+
lcs_pairs = []
|
|
196
|
+
i, j = len(overlap_a), len(overlap_b)
|
|
197
|
+
|
|
198
|
+
while i > 0 and j > 0:
|
|
199
|
+
if (
|
|
200
|
+
overlap_a[i - 1].id == overlap_b[j - 1].id
|
|
201
|
+
and abs(overlap_a[i - 1].start - overlap_b[j - 1].start)
|
|
202
|
+
< overlap_duration / 2
|
|
203
|
+
):
|
|
204
|
+
lcs_pairs.append((i - 1, j - 1))
|
|
205
|
+
i -= 1
|
|
206
|
+
j -= 1
|
|
207
|
+
elif dp[i - 1][j] > dp[i][j - 1]:
|
|
208
|
+
i -= 1
|
|
209
|
+
else:
|
|
210
|
+
j -= 1
|
|
211
|
+
|
|
212
|
+
lcs_pairs.reverse()
|
|
213
|
+
|
|
214
|
+
if not lcs_pairs:
|
|
215
|
+
cutoff_time = (a_end_time + b_start_time) / 2
|
|
216
|
+
return [t for t in a if t.end <= cutoff_time] + [
|
|
217
|
+
t for t in b if t.start >= cutoff_time
|
|
218
|
+
]
|
|
219
|
+
|
|
220
|
+
a_start_idx = len(a) - len(overlap_a)
|
|
221
|
+
lcs_indices_a = [a_start_idx + pair[0] for pair in lcs_pairs]
|
|
222
|
+
lcs_indices_b = [pair[1] for pair in lcs_pairs]
|
|
223
|
+
|
|
224
|
+
result = []
|
|
225
|
+
|
|
226
|
+
result.extend(a[: lcs_indices_a[0]])
|
|
227
|
+
|
|
228
|
+
for i in range(len(lcs_pairs)):
|
|
229
|
+
idx_a = lcs_indices_a[i]
|
|
230
|
+
idx_b = lcs_indices_b[i]
|
|
231
|
+
|
|
232
|
+
result.append(a[idx_a])
|
|
233
|
+
|
|
234
|
+
if i < len(lcs_pairs) - 1:
|
|
235
|
+
next_idx_a = lcs_indices_a[i + 1]
|
|
236
|
+
next_idx_b = lcs_indices_b[i + 1]
|
|
237
|
+
|
|
238
|
+
gap_tokens_a = a[idx_a + 1 : next_idx_a]
|
|
239
|
+
gap_tokens_b = b[idx_b + 1 : next_idx_b]
|
|
240
|
+
|
|
241
|
+
if len(gap_tokens_b) > len(gap_tokens_a):
|
|
242
|
+
result.extend(gap_tokens_b)
|
|
243
|
+
else:
|
|
244
|
+
result.extend(gap_tokens_a)
|
|
245
|
+
|
|
246
|
+
result.extend(b[lcs_indices_b[-1] + 1 :])
|
|
247
|
+
|
|
248
|
+
return result
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import math
|
|
2
|
+
|
|
3
|
+
import mlx.core as mx
|
|
4
|
+
import mlx.nn as nn
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class MultiHeadAttention(nn.Module):
|
|
8
|
+
def __init__(
|
|
9
|
+
self,
|
|
10
|
+
n_head: int,
|
|
11
|
+
n_feat: int,
|
|
12
|
+
bias=True,
|
|
13
|
+
):
|
|
14
|
+
super().__init__()
|
|
15
|
+
|
|
16
|
+
self.n_head = n_head
|
|
17
|
+
self.head_dim = n_feat // n_head
|
|
18
|
+
self.scale = self.head_dim**-0.5
|
|
19
|
+
|
|
20
|
+
self.linear_q = nn.Linear(n_feat, n_feat, bias=bias)
|
|
21
|
+
self.linear_k = nn.Linear(n_feat, n_feat, bias=bias)
|
|
22
|
+
self.linear_v = nn.Linear(n_feat, n_feat, bias=bias)
|
|
23
|
+
self.linear_out = nn.Linear(n_feat, n_feat, bias=bias)
|
|
24
|
+
|
|
25
|
+
def __call__(
|
|
26
|
+
self,
|
|
27
|
+
q: mx.array,
|
|
28
|
+
k: mx.array,
|
|
29
|
+
v: mx.array,
|
|
30
|
+
pos_emb: mx.array | None = None,
|
|
31
|
+
mask: mx.array | None = None,
|
|
32
|
+
cache=None,
|
|
33
|
+
) -> mx.array:
|
|
34
|
+
q, k, v = self.linear_q(q), self.linear_k(k), self.linear_v(v)
|
|
35
|
+
|
|
36
|
+
batch, q_seq, _ = q.shape
|
|
37
|
+
_, k_seq, _ = k.shape
|
|
38
|
+
|
|
39
|
+
q = q.reshape(batch, q_seq, self.n_head, self.head_dim).transpose(0, 2, 1, 3)
|
|
40
|
+
k = k.reshape(batch, k_seq, self.n_head, self.head_dim).transpose(0, 2, 1, 3)
|
|
41
|
+
v = v.reshape(batch, k_seq, self.n_head, self.head_dim).transpose(0, 2, 1, 3)
|
|
42
|
+
|
|
43
|
+
if cache:
|
|
44
|
+
k, v = cache.update_and_fetch(k, v)
|
|
45
|
+
|
|
46
|
+
o = mx.fast.scaled_dot_product_attention(q, k, v, scale=self.scale, mask=mask)
|
|
47
|
+
o = o.transpose(0, 2, 1, 3).reshape(batch, q_seq, self.n_feat)
|
|
48
|
+
|
|
49
|
+
return self.linear_out(o)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class RelPositionMultiHeadAttention(MultiHeadAttention):
|
|
53
|
+
def __init__(
|
|
54
|
+
self,
|
|
55
|
+
n_head: int,
|
|
56
|
+
n_feat: int,
|
|
57
|
+
bias: bool = True,
|
|
58
|
+
pos_bias_u: mx.array | None = None,
|
|
59
|
+
pos_bias_v: mx.array | None = None,
|
|
60
|
+
):
|
|
61
|
+
super().__init__(
|
|
62
|
+
n_head=n_head,
|
|
63
|
+
n_feat=n_feat,
|
|
64
|
+
bias=bias,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
self.linear_pos = nn.Linear(n_feat, n_feat, bias=False)
|
|
68
|
+
|
|
69
|
+
if pos_bias_u is None:
|
|
70
|
+
self._pos_bias_u_init = mx.zeros((self.n_head, self.head_dim))
|
|
71
|
+
else:
|
|
72
|
+
self._pos_bias_u_init = pos_bias_u
|
|
73
|
+
|
|
74
|
+
if pos_bias_v is None:
|
|
75
|
+
self._pos_bias_v_init = mx.zeros((self.n_head, self.head_dim))
|
|
76
|
+
else:
|
|
77
|
+
self._pos_bias_v_init = pos_bias_v
|
|
78
|
+
|
|
79
|
+
self.pos_bias_u = self._pos_bias_u_init
|
|
80
|
+
self.pos_bias_v = self._pos_bias_v_init
|
|
81
|
+
|
|
82
|
+
def rel_shift(self, x: mx.array) -> mx.array:
|
|
83
|
+
B, H, Tq, pos_len = x.shape
|
|
84
|
+
padding = [(0, 0)] * (x.ndim - 1) + [(1, 0)]
|
|
85
|
+
|
|
86
|
+
x = mx.pad(x, padding)
|
|
87
|
+
x = x.reshape(B, H, pos_len + 1, Tq)
|
|
88
|
+
x = x[:, :, 1:, :]
|
|
89
|
+
x = x.reshape(B, H, Tq, pos_len)
|
|
90
|
+
|
|
91
|
+
return x
|
|
92
|
+
|
|
93
|
+
def __call__(
|
|
94
|
+
self,
|
|
95
|
+
q: mx.array,
|
|
96
|
+
k: mx.array,
|
|
97
|
+
v: mx.array,
|
|
98
|
+
pos_emb: mx.array | None = None,
|
|
99
|
+
mask: mx.array | None = None,
|
|
100
|
+
cache=None,
|
|
101
|
+
) -> mx.array:
|
|
102
|
+
if pos_emb is None:
|
|
103
|
+
raise ValueError("pos_emb is necessary!")
|
|
104
|
+
|
|
105
|
+
q, k, v = self.linear_q(q), self.linear_k(k), self.linear_v(v)
|
|
106
|
+
|
|
107
|
+
p = self.linear_pos(pos_emb) # p stands for position
|
|
108
|
+
|
|
109
|
+
batch, q_seq, _ = q.shape
|
|
110
|
+
_, k_seq, _ = k.shape
|
|
111
|
+
_, pos_len, _ = p.shape
|
|
112
|
+
|
|
113
|
+
q = q.reshape(batch, q_seq, self.n_head, self.head_dim)
|
|
114
|
+
q_u = (q + self.pos_bias_u).transpose(0, 2, 1, 3)
|
|
115
|
+
q_v = (q + self.pos_bias_v).transpose(0, 2, 1, 3)
|
|
116
|
+
|
|
117
|
+
k = k.reshape(batch, k_seq, self.n_head, self.head_dim).transpose(0, 2, 1, 3)
|
|
118
|
+
v = v.reshape(batch, k_seq, self.n_head, self.head_dim).transpose(0, 2, 1, 3)
|
|
119
|
+
p = p.reshape(batch, pos_len, self.n_head, self.head_dim).transpose(0, 2, 1, 3)
|
|
120
|
+
|
|
121
|
+
if cache is not None:
|
|
122
|
+
k, v = cache.update_and_fetch(k, v)
|
|
123
|
+
|
|
124
|
+
matrix_bd = mx.matmul(q_v, p.swapaxes(-2, -1))
|
|
125
|
+
matrix_bd = self.rel_shift(matrix_bd)
|
|
126
|
+
matrix_bd = matrix_bd[:, :, :, : k.shape[-2]] * self.scale
|
|
127
|
+
|
|
128
|
+
if mask is not None:
|
|
129
|
+
mask = mx.expand_dims(mask, 0)
|
|
130
|
+
matrix_bd[mask] = -mx.inf
|
|
131
|
+
|
|
132
|
+
o = mx.fast.scaled_dot_product_attention(
|
|
133
|
+
q_u, k, v, scale=self.scale, mask=matrix_bd
|
|
134
|
+
)
|
|
135
|
+
o = o.transpose(0, 2, 1, 3).reshape(batch, q_seq, -1)
|
|
136
|
+
|
|
137
|
+
return self.linear_out(o)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class RelPositionalEncoding(nn.Module):
|
|
141
|
+
def __init__(
|
|
142
|
+
self,
|
|
143
|
+
d_model: int,
|
|
144
|
+
max_len: int = 5000,
|
|
145
|
+
scale_input: bool = True,
|
|
146
|
+
):
|
|
147
|
+
assert d_model % 2 == 0 and max_len > 0
|
|
148
|
+
super().__init__()
|
|
149
|
+
|
|
150
|
+
self.d_model = d_model
|
|
151
|
+
self.max_len = max_len
|
|
152
|
+
self.scale = math.sqrt(self.d_model) if scale_input else 1.0
|
|
153
|
+
self.calculate_pe()
|
|
154
|
+
|
|
155
|
+
def calculate_pe(self):
|
|
156
|
+
positions = mx.arange(self.max_len - 1, -self.max_len, -1, dtype=mx.int32)
|
|
157
|
+
positions = mx.expand_dims(positions, axis=1).astype(mx.float32)
|
|
158
|
+
|
|
159
|
+
div_term = mx.exp(
|
|
160
|
+
mx.arange(0, self.d_model, 2, dtype=mx.float32)
|
|
161
|
+
* -(math.log(10000.0) / self.d_model)
|
|
162
|
+
)
|
|
163
|
+
pe = mx.zeros((2 * self.max_len - 1, self.d_model), dtype=mx.float32)
|
|
164
|
+
|
|
165
|
+
pe[:, 0::2] = mx.sin(positions * div_term)
|
|
166
|
+
pe[:, 1::2] = mx.cos(positions * div_term)
|
|
167
|
+
|
|
168
|
+
self._pe = mx.expand_dims(pe, axis=0).astype(mx.float32)
|
|
169
|
+
|
|
170
|
+
mx.eval(self._pe)
|
|
171
|
+
|
|
172
|
+
def __call__(self, x: mx.array, offset: int = 0) -> tuple[mx.array, mx.array]:
|
|
173
|
+
input_len = x.shape[1] + offset
|
|
174
|
+
|
|
175
|
+
if input_len > self.max_len:
|
|
176
|
+
self.max_len = input_len + 1
|
|
177
|
+
self.calculate_pe()
|
|
178
|
+
|
|
179
|
+
x = x * self.scale
|
|
180
|
+
|
|
181
|
+
buffer_len = self._pe.shape[1]
|
|
182
|
+
start_idx = buffer_len // 2 - (input_len - 1)
|
|
183
|
+
end_idx = buffer_len // 2 + (input_len - 1) + 1
|
|
184
|
+
|
|
185
|
+
pos_emb = self._pe[:, start_idx:end_idx].astype(x.dtype)
|
|
186
|
+
|
|
187
|
+
return x, pos_emb
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
import mlx.core as mx
|
|
4
|
+
|
|
5
|
+
from mlx_audio.utils import (
|
|
6
|
+
STR_TO_WINDOW_FN,
|
|
7
|
+
bartlett,
|
|
8
|
+
blackman,
|
|
9
|
+
hamming,
|
|
10
|
+
hanning,
|
|
11
|
+
mel_filters,
|
|
12
|
+
stft,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass
|
|
17
|
+
class PreprocessArgs:
|
|
18
|
+
sample_rate: int
|
|
19
|
+
normalize: str
|
|
20
|
+
window_size: float
|
|
21
|
+
window_stride: float
|
|
22
|
+
window: str
|
|
23
|
+
features: int
|
|
24
|
+
n_fft: int
|
|
25
|
+
dither: float
|
|
26
|
+
pad_to: int = 0
|
|
27
|
+
pad_value: float = 0
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def win_length(self) -> int:
|
|
31
|
+
return int(self.window_size * self.sample_rate)
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def hop_length(self) -> int:
|
|
35
|
+
return int(self.window_stride * self.sample_rate)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def log_mel_spectrogram(x: mx.array, args: PreprocessArgs) -> mx.array:
|
|
39
|
+
original_dtype = x.dtype
|
|
40
|
+
|
|
41
|
+
if args.pad_to > 0:
|
|
42
|
+
if x.shape[-1] < args.pad_to:
|
|
43
|
+
pad_length = args.pad_to - x.shape[-1]
|
|
44
|
+
x = mx.pad(x, ((0, pad_length),), constant_values=args.pad_value)
|
|
45
|
+
|
|
46
|
+
window_fn = STR_TO_WINDOW_FN.get(args.window, None)
|
|
47
|
+
window = window_fn(args.win_length) if window_fn else hanning(args.win_length)
|
|
48
|
+
|
|
49
|
+
# Ensure input is long enough for STFT (minimum n_fft samples required)
|
|
50
|
+
min_length = args.n_fft
|
|
51
|
+
if x.shape[-1] < min_length:
|
|
52
|
+
pad_length = min_length - x.shape[-1]
|
|
53
|
+
x = mx.pad(x, ((0, pad_length),), constant_values=args.pad_value)
|
|
54
|
+
|
|
55
|
+
x = stft(x, args.n_fft, args.hop_length, args.win_length, window)
|
|
56
|
+
x = mx.square(mx.abs(x)).astype(original_dtype)
|
|
57
|
+
filters = mel_filters(
|
|
58
|
+
args.sample_rate, args.n_fft, args.features, norm=args.normalize, mel_scale=None
|
|
59
|
+
)
|
|
60
|
+
x = filters.astype(x.dtype) @ x.T
|
|
61
|
+
|
|
62
|
+
x = mx.log(x + 1e-5)
|
|
63
|
+
|
|
64
|
+
if args.normalize == "per_feature":
|
|
65
|
+
mean = mx.mean(x, axis=1, keepdims=True)
|
|
66
|
+
std = mx.std(x, axis=1, keepdims=True)
|
|
67
|
+
normalized_mel = (x - mean) / (std + 1e-5)
|
|
68
|
+
else:
|
|
69
|
+
mean = mx.mean(x)
|
|
70
|
+
std = mx.std(x)
|
|
71
|
+
normalized_mel = (x - mean) / (std + 1e-5)
|
|
72
|
+
|
|
73
|
+
normalized_mel = normalized_mel.T
|
|
74
|
+
normalized_mel = mx.expand_dims(normalized_mel, axis=0)
|
|
75
|
+
|
|
76
|
+
return normalized_mel.astype(original_dtype)
|