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,180 @@
|
|
|
1
|
+
import math
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
import mlx.core as mx
|
|
5
|
+
import mlx.nn as nn
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class MultiHeadAttention(nn.Module):
|
|
9
|
+
def __init__(
|
|
10
|
+
self,
|
|
11
|
+
n_head: int,
|
|
12
|
+
n_feat: int,
|
|
13
|
+
bias=True,
|
|
14
|
+
head_dim: Optional[int] = None,
|
|
15
|
+
):
|
|
16
|
+
super().__init__()
|
|
17
|
+
|
|
18
|
+
self.n_head = n_head
|
|
19
|
+
self.head_dim = n_feat // n_head if not head_dim else head_dim
|
|
20
|
+
self.scale = self.head_dim**-0.5
|
|
21
|
+
|
|
22
|
+
self.linear_q = nn.Linear(n_feat, self.head_dim * self.n_head, bias=bias)
|
|
23
|
+
self.linear_k = nn.Linear(n_feat, self.head_dim * self.n_head, bias=bias)
|
|
24
|
+
self.linear_v = nn.Linear(n_feat, self.head_dim * self.n_head, bias=bias)
|
|
25
|
+
self.linear_out = nn.Linear(self.head_dim * self.n_head, n_feat, bias=bias)
|
|
26
|
+
|
|
27
|
+
def __call__(
|
|
28
|
+
self,
|
|
29
|
+
q: mx.array,
|
|
30
|
+
k: mx.array,
|
|
31
|
+
v: mx.array,
|
|
32
|
+
pos_emb: mx.array | None = None,
|
|
33
|
+
mask: mx.array | None = None,
|
|
34
|
+
cache=None,
|
|
35
|
+
) -> mx.array:
|
|
36
|
+
q, k, v = self.linear_q(q), self.linear_k(k), self.linear_v(v)
|
|
37
|
+
|
|
38
|
+
batch, q_seq, _ = q.shape
|
|
39
|
+
_, k_seq, _ = k.shape
|
|
40
|
+
|
|
41
|
+
q = q.reshape(batch, q_seq, self.n_head, self.head_dim).transpose(0, 2, 1, 3)
|
|
42
|
+
k = k.reshape(batch, k_seq, self.n_head, self.head_dim).transpose(0, 2, 1, 3)
|
|
43
|
+
v = v.reshape(batch, k_seq, self.n_head, self.head_dim).transpose(0, 2, 1, 3)
|
|
44
|
+
|
|
45
|
+
if cache:
|
|
46
|
+
k, v = cache.update_and_fetch(k, v)
|
|
47
|
+
|
|
48
|
+
o = mx.fast.scaled_dot_product_attention(q, k, v, scale=self.scale, mask=mask)
|
|
49
|
+
o = o.transpose(0, 2, 1, 3).reshape(batch, q_seq, -1)
|
|
50
|
+
|
|
51
|
+
return self.linear_out(o)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class RelPositionMultiHeadAttention(MultiHeadAttention):
|
|
55
|
+
def __init__(
|
|
56
|
+
self,
|
|
57
|
+
n_head: int,
|
|
58
|
+
n_feat: int,
|
|
59
|
+
bias: bool = True,
|
|
60
|
+
head_dim: Optional[int] = None,
|
|
61
|
+
pos_bias_u: mx.array | None = None,
|
|
62
|
+
pos_bias_v: mx.array | None = None,
|
|
63
|
+
):
|
|
64
|
+
super().__init__(n_head=n_head, n_feat=n_feat, bias=bias, head_dim=head_dim)
|
|
65
|
+
|
|
66
|
+
self.linear_pos = nn.Linear(n_feat, n_feat, bias=False)
|
|
67
|
+
|
|
68
|
+
if pos_bias_u is None:
|
|
69
|
+
self._pos_bias_u_init = mx.zeros((self.n_head, self.head_dim))
|
|
70
|
+
else:
|
|
71
|
+
self._pos_bias_u_init = pos_bias_u
|
|
72
|
+
|
|
73
|
+
if pos_bias_v is None:
|
|
74
|
+
self._pos_bias_v_init = mx.zeros((self.n_head, self.head_dim))
|
|
75
|
+
else:
|
|
76
|
+
self._pos_bias_v_init = pos_bias_v
|
|
77
|
+
|
|
78
|
+
self.pos_bias_u = self._pos_bias_u_init
|
|
79
|
+
self.pos_bias_v = self._pos_bias_v_init
|
|
80
|
+
|
|
81
|
+
def __call__(
|
|
82
|
+
self,
|
|
83
|
+
q: mx.array,
|
|
84
|
+
k: mx.array,
|
|
85
|
+
v: mx.array,
|
|
86
|
+
pos_emb: mx.array | None = None,
|
|
87
|
+
mask: mx.array | None = None,
|
|
88
|
+
cache=None,
|
|
89
|
+
) -> mx.array:
|
|
90
|
+
if pos_emb is None:
|
|
91
|
+
raise ValueError("pos_emb is necessary!")
|
|
92
|
+
|
|
93
|
+
q, k, v = self.linear_q(q), self.linear_k(k), self.linear_v(v)
|
|
94
|
+
|
|
95
|
+
p = self.linear_pos(pos_emb) # p stands for position
|
|
96
|
+
|
|
97
|
+
batch, q_seq, _ = q.shape
|
|
98
|
+
_, k_seq, _ = k.shape
|
|
99
|
+
_, pos_len, _ = p.shape
|
|
100
|
+
|
|
101
|
+
q = q.reshape(batch, q_seq, self.n_head, self.head_dim)
|
|
102
|
+
q_u = (q + self.pos_bias_u).transpose(0, 2, 1, 3)
|
|
103
|
+
q_v = (q + self.pos_bias_v).transpose(0, 2, 1, 3)
|
|
104
|
+
|
|
105
|
+
k = k.reshape(batch, k_seq, self.n_head, self.head_dim).transpose(0, 2, 1, 3)
|
|
106
|
+
v = v.reshape(batch, k_seq, self.n_head, self.head_dim).transpose(0, 2, 1, 3)
|
|
107
|
+
p = p.reshape(batch, pos_len, self.n_head, self.head_dim).transpose(0, 2, 1, 3)
|
|
108
|
+
|
|
109
|
+
if cache is not None:
|
|
110
|
+
k, v = cache.update_and_fetch(k, v)
|
|
111
|
+
|
|
112
|
+
matrix_bd = mx.matmul(q_v, p.swapaxes(-2, -1))
|
|
113
|
+
matrix_bd = matrix_bd * self.scale
|
|
114
|
+
|
|
115
|
+
if mask is not None:
|
|
116
|
+
mask = mx.expand_dims(mask, 0)
|
|
117
|
+
matrix_bd[mask] = -mx.inf
|
|
118
|
+
|
|
119
|
+
o = mx.fast.scaled_dot_product_attention(
|
|
120
|
+
q_u, k, v, scale=self.scale, mask=matrix_bd
|
|
121
|
+
)
|
|
122
|
+
o = o.transpose(0, 2, 1, 3).reshape(batch, q_seq, -1)
|
|
123
|
+
|
|
124
|
+
return self.linear_out(o)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class RelPositionalEncoding(nn.Module):
|
|
128
|
+
def __init__(
|
|
129
|
+
self,
|
|
130
|
+
d_model: int,
|
|
131
|
+
max_len: int = 5000,
|
|
132
|
+
scale_input: bool = True,
|
|
133
|
+
):
|
|
134
|
+
assert d_model % 2 == 0 and max_len > 0
|
|
135
|
+
super().__init__()
|
|
136
|
+
|
|
137
|
+
self.d_model = d_model
|
|
138
|
+
self.max_len = max_len
|
|
139
|
+
self.scale = math.sqrt(self.d_model) if scale_input else 1.0
|
|
140
|
+
self.calculate_pe()
|
|
141
|
+
|
|
142
|
+
def calculate_pe(self):
|
|
143
|
+
positions = mx.arange(0, self.max_len, 1, dtype=mx.int32)
|
|
144
|
+
positions = mx.expand_dims(positions, axis=1).astype(mx.float32)
|
|
145
|
+
|
|
146
|
+
div_term = mx.exp(
|
|
147
|
+
mx.arange(0, self.d_model, 2, dtype=mx.float32)
|
|
148
|
+
* -(math.log(10000.0) / self.d_model)
|
|
149
|
+
)
|
|
150
|
+
pe = mx.zeros((self.max_len, self.d_model), dtype=mx.float32)
|
|
151
|
+
|
|
152
|
+
pe[:, 0::2] = mx.sin(positions * div_term)
|
|
153
|
+
pe[:, 1::2] = mx.cos(positions * div_term)
|
|
154
|
+
|
|
155
|
+
self._pe = mx.expand_dims(pe, axis=0).astype(mx.float32)
|
|
156
|
+
|
|
157
|
+
mx.eval(self._pe)
|
|
158
|
+
|
|
159
|
+
def __call__(self, x: mx.array, offset: int = 0) -> tuple[mx.array, mx.array]:
|
|
160
|
+
input_len = x.shape[1] + offset
|
|
161
|
+
|
|
162
|
+
if input_len > self.max_len:
|
|
163
|
+
self.max_len = input_len + 1
|
|
164
|
+
self.calculate_pe()
|
|
165
|
+
|
|
166
|
+
x = x * self.scale
|
|
167
|
+
|
|
168
|
+
pos_emb = self._pe[:, offset : offset + x.shape[1]].astype(x.dtype)
|
|
169
|
+
|
|
170
|
+
return x, pos_emb
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class LearnedPositionEncoding(nn.Module):
|
|
174
|
+
def __init__(self, seq_len: int, model_dim: int):
|
|
175
|
+
super().__init__()
|
|
176
|
+
|
|
177
|
+
self.emb = nn.Embedding(seq_len, model_dim)
|
|
178
|
+
|
|
179
|
+
def __call__(self, x: mx.array, offset: int = 0):
|
|
180
|
+
return self.emb(mx.arange(offset, offset + x.shape[1]))
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
import mlx.core as mx
|
|
4
|
+
import mlx.nn as nn
|
|
5
|
+
from mlx.utils import tree_flatten
|
|
6
|
+
|
|
7
|
+
from mlx_audio.codec.models.bigvgan.bigvgan import BigVGAN, BigVGANConfig
|
|
8
|
+
from mlx_audio.codec.models.bigvgan.conv import WNConv1d
|
|
9
|
+
from mlx_audio.tts.models.indextts.ecapa_tdnn.ecapa_tdnn import ECPATDNN, ECPATDNNArgs
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class BigVGANConditioningConfig(BigVGANConfig):
|
|
14
|
+
gpt_dim: int = 1
|
|
15
|
+
speaker_embedding_dim: int = 1
|
|
16
|
+
cond_d_vector_in_each_upsampling_layer: bool = True
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class BigVGANConditioning(BigVGAN):
|
|
20
|
+
def __init__(self, config: BigVGANConditioningConfig):
|
|
21
|
+
super().__init__(config)
|
|
22
|
+
|
|
23
|
+
self.conv_pre = WNConv1d(
|
|
24
|
+
config.gpt_dim, config.upsample_initial_channel, 7, 1, 3
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
self.cond_in_each_up_layer = config.cond_d_vector_in_each_upsampling_layer
|
|
28
|
+
|
|
29
|
+
self.speaker_encoder = ECPATDNN(
|
|
30
|
+
ECPATDNNArgs(config.num_mels, lin_neurons=config.speaker_embedding_dim)
|
|
31
|
+
)
|
|
32
|
+
self.cond_layer = nn.Conv1d(
|
|
33
|
+
config.speaker_embedding_dim, config.upsample_initial_channel, 1
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
if config.cond_d_vector_in_each_upsampling_layer:
|
|
37
|
+
self.conds = [
|
|
38
|
+
nn.Conv1d(
|
|
39
|
+
config.speaker_embedding_dim,
|
|
40
|
+
config.upsample_initial_channel // (2 ** (i + 1)),
|
|
41
|
+
1,
|
|
42
|
+
)
|
|
43
|
+
for i in range(len(self.ups))
|
|
44
|
+
]
|
|
45
|
+
else:
|
|
46
|
+
self.conds = []
|
|
47
|
+
|
|
48
|
+
def __call__(
|
|
49
|
+
self, x: mx.array, mel_refer: mx.array
|
|
50
|
+
) -> mx.array: # (batch, num_mels, seq)
|
|
51
|
+
x = x.transpose(0, 2, 1)
|
|
52
|
+
mel_refer = mel_refer.transpose(0, 2, 1)
|
|
53
|
+
|
|
54
|
+
speaker_embedding = self.speaker_encoder(mel_refer)
|
|
55
|
+
|
|
56
|
+
x = self.conv_pre(x)
|
|
57
|
+
x += self.cond_layer(speaker_embedding)
|
|
58
|
+
|
|
59
|
+
for step in range(self.num_upsamples):
|
|
60
|
+
for idx in range(len(self.ups[step])):
|
|
61
|
+
x = self.ups[step][idx](x)
|
|
62
|
+
|
|
63
|
+
if self.cond_in_each_up_layer:
|
|
64
|
+
x += self.conds[step](speaker_embedding)
|
|
65
|
+
|
|
66
|
+
xs = self.resblocks[step * self.num_kernels](x)
|
|
67
|
+
for idx in range(1, self.num_kernels):
|
|
68
|
+
xs += self.resblocks[step * self.num_kernels + idx](x)
|
|
69
|
+
|
|
70
|
+
x = xs / self.num_kernels
|
|
71
|
+
|
|
72
|
+
x = self.activation_post(x)
|
|
73
|
+
x = self.conv_post(x)
|
|
74
|
+
|
|
75
|
+
if self.use_tanh_at_final:
|
|
76
|
+
x = mx.tanh(x)
|
|
77
|
+
else:
|
|
78
|
+
x = mx.clip(x, -1.0, 1.0)
|
|
79
|
+
|
|
80
|
+
return x.transpose(0, 2, 1)
|
|
81
|
+
|
|
82
|
+
def sanitize(self, weights: dict[str, mx.array]):
|
|
83
|
+
new_weights = {}
|
|
84
|
+
|
|
85
|
+
curr_weights = dict(tree_flatten(self.parameters()))
|
|
86
|
+
|
|
87
|
+
for key, value in weights.items():
|
|
88
|
+
if "num_batches_tracked" in key:
|
|
89
|
+
continue
|
|
90
|
+
|
|
91
|
+
key = (
|
|
92
|
+
key.replace("norm.norm", "norm")
|
|
93
|
+
.replace("conv.conv", "conv")
|
|
94
|
+
.replace("conv1.conv", "conv1")
|
|
95
|
+
.replace("conv2.conv", "conv2")
|
|
96
|
+
.replace("fc.conv", "fc")
|
|
97
|
+
.replace("asp_bn.norm", "asp_bn")
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
if (
|
|
101
|
+
"conv" in key
|
|
102
|
+
or "cond_layer" in key
|
|
103
|
+
or "lowpass.filter" in key
|
|
104
|
+
or "upsample.filter" in key
|
|
105
|
+
or "conds" in key
|
|
106
|
+
or "fc" in key
|
|
107
|
+
):
|
|
108
|
+
if value.ndim == 3:
|
|
109
|
+
if value.shape != curr_weights[key].shape:
|
|
110
|
+
value = value.transpose(0, 2, 1)
|
|
111
|
+
elif value.ndim == 4:
|
|
112
|
+
if value.shape != curr_weights[key].shape:
|
|
113
|
+
value = value.transpose(0, 2, 3, 1)
|
|
114
|
+
|
|
115
|
+
if "ups." in key:
|
|
116
|
+
if value.ndim == 3:
|
|
117
|
+
if value.shape != curr_weights[key].shape:
|
|
118
|
+
value = value.transpose(1, 2, 0)
|
|
119
|
+
|
|
120
|
+
new_weights[key] = value
|
|
121
|
+
|
|
122
|
+
del curr_weights
|
|
123
|
+
|
|
124
|
+
return new_weights
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
import mlx.core as mx
|
|
5
|
+
import mlx.nn as nn
|
|
6
|
+
|
|
7
|
+
from mlx_audio.tts.models.indextts.attention import (
|
|
8
|
+
MultiHeadAttention,
|
|
9
|
+
RelPositionalEncoding,
|
|
10
|
+
RelPositionMultiHeadAttention,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass
|
|
15
|
+
class ConformerArgs:
|
|
16
|
+
input_size: int = 100
|
|
17
|
+
output_size: int = 256
|
|
18
|
+
num_blocks: int = 6
|
|
19
|
+
linear_units: int = 2048
|
|
20
|
+
attention_heads: int = 4
|
|
21
|
+
pos_enc_layer_type: str = "rel_pos"
|
|
22
|
+
input_layer: str = "conv2d"
|
|
23
|
+
cnn_module_kernel: int = 15
|
|
24
|
+
pos_emb_max_len: int = 2048
|
|
25
|
+
causal_downsampling: bool = False
|
|
26
|
+
use_bias: bool = True
|
|
27
|
+
xscaling: bool = True
|
|
28
|
+
macaron_style: bool = False
|
|
29
|
+
pos_bias_u: mx.array | None = None
|
|
30
|
+
pos_bias_v: mx.array | None = None
|
|
31
|
+
perceiver_mult: int = 2
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class FeedForward(nn.Module):
|
|
35
|
+
def __init__(self, dim: int, d_ff: int, use_bias: bool = True):
|
|
36
|
+
super().__init__()
|
|
37
|
+
self.w_1 = nn.Linear(dim, d_ff, bias=use_bias)
|
|
38
|
+
self.activation = nn.SiLU()
|
|
39
|
+
self.w_2 = nn.Linear(d_ff, dim, bias=use_bias)
|
|
40
|
+
|
|
41
|
+
def __call__(self, x: mx.array) -> mx.array:
|
|
42
|
+
return self.w_2(self.activation(self.w_1(x)))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class Convolution(nn.Module):
|
|
46
|
+
def __init__(self, args: ConformerArgs):
|
|
47
|
+
assert (args.cnn_module_kernel - 1) % 2 == 0
|
|
48
|
+
super().__init__()
|
|
49
|
+
|
|
50
|
+
self.pointwise_conv1 = nn.Conv1d(
|
|
51
|
+
args.output_size,
|
|
52
|
+
args.output_size * 2,
|
|
53
|
+
kernel_size=1,
|
|
54
|
+
stride=1,
|
|
55
|
+
padding=0,
|
|
56
|
+
bias=args.use_bias,
|
|
57
|
+
)
|
|
58
|
+
self.depthwise_conv = nn.Conv1d(
|
|
59
|
+
args.output_size,
|
|
60
|
+
args.output_size,
|
|
61
|
+
kernel_size=args.cnn_module_kernel,
|
|
62
|
+
stride=1,
|
|
63
|
+
padding=(args.cnn_module_kernel - 1) // 2,
|
|
64
|
+
groups=args.output_size,
|
|
65
|
+
bias=args.use_bias,
|
|
66
|
+
)
|
|
67
|
+
self.norm = nn.LayerNorm(args.output_size)
|
|
68
|
+
self.activation = nn.SiLU()
|
|
69
|
+
self.pointwise_conv2 = nn.Conv1d(
|
|
70
|
+
args.output_size,
|
|
71
|
+
args.output_size,
|
|
72
|
+
kernel_size=1,
|
|
73
|
+
stride=1,
|
|
74
|
+
padding=0,
|
|
75
|
+
bias=args.use_bias,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
def __call__(self, x: mx.array) -> mx.array:
|
|
79
|
+
x = self.pointwise_conv1(x)
|
|
80
|
+
x = nn.glu(x, axis=2)
|
|
81
|
+
|
|
82
|
+
x = self.depthwise_conv(x)
|
|
83
|
+
x = self.norm(x)
|
|
84
|
+
x = self.activation(x)
|
|
85
|
+
x = self.pointwise_conv2(x)
|
|
86
|
+
|
|
87
|
+
return x
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class ConformerBlock(nn.Module):
|
|
91
|
+
def __init__(self, args: ConformerArgs):
|
|
92
|
+
super().__init__()
|
|
93
|
+
self.macaron_style = args.macaron_style
|
|
94
|
+
self.ff_scale = 0.5 if self.macaron_style else 1
|
|
95
|
+
if args.macaron_style:
|
|
96
|
+
self.norm_ff_macaron = nn.LayerNorm(args.output_size)
|
|
97
|
+
self.feed_forward_macaron = FeedForward(
|
|
98
|
+
args.output_size, args.linear_units, args.use_bias
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
self.norm_mha = nn.LayerNorm(args.output_size)
|
|
102
|
+
self.self_attn = (
|
|
103
|
+
RelPositionMultiHeadAttention(
|
|
104
|
+
args.attention_heads,
|
|
105
|
+
args.output_size,
|
|
106
|
+
bias=args.use_bias,
|
|
107
|
+
pos_bias_u=args.pos_bias_u,
|
|
108
|
+
pos_bias_v=args.pos_bias_v,
|
|
109
|
+
)
|
|
110
|
+
if args.pos_enc_layer_type == "rel_pos"
|
|
111
|
+
else MultiHeadAttention(
|
|
112
|
+
args.attention_heads,
|
|
113
|
+
args.output_size,
|
|
114
|
+
bias=True,
|
|
115
|
+
)
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
self.norm_conv = nn.LayerNorm(args.output_size)
|
|
119
|
+
self.conv_module = Convolution(args)
|
|
120
|
+
|
|
121
|
+
self.norm_ff = nn.LayerNorm(args.output_size)
|
|
122
|
+
self.feed_forward = FeedForward(
|
|
123
|
+
args.output_size, args.linear_units, args.use_bias
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
self.norm_final = nn.LayerNorm(args.output_size)
|
|
127
|
+
|
|
128
|
+
def __call__(
|
|
129
|
+
self,
|
|
130
|
+
x: mx.array,
|
|
131
|
+
pos_emb: mx.array | None = None,
|
|
132
|
+
mask: mx.array | None = None,
|
|
133
|
+
cache=None,
|
|
134
|
+
) -> mx.array:
|
|
135
|
+
if self.macaron_style:
|
|
136
|
+
x += self.ff_scale * self.feed_forward_macaron(self.norm_ff_macaron(x))
|
|
137
|
+
|
|
138
|
+
x_norm = self.norm_mha(x)
|
|
139
|
+
x += self.self_attn(
|
|
140
|
+
x_norm, x_norm, x_norm, mask=mask, pos_emb=pos_emb, cache=cache
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
x += self.conv_module(self.norm_conv(x))
|
|
144
|
+
x += self.ff_scale * self.feed_forward(self.norm_ff(x))
|
|
145
|
+
|
|
146
|
+
return self.norm_final(x)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class Conv2dSubsampling(nn.Module):
|
|
150
|
+
CONV_LAYERS = {
|
|
151
|
+
"conv2d2": [(3, 2)],
|
|
152
|
+
"conv2d3": [(5, 3)],
|
|
153
|
+
"conv2d4": [(3, 2), (3, 2)],
|
|
154
|
+
"conv2d6": [(3, 2), (5, 3)],
|
|
155
|
+
"conv2d8": [(3, 2), (3, 2), (3, 2)],
|
|
156
|
+
}
|
|
157
|
+
CONV_MASKS = {
|
|
158
|
+
"conv2d2": [slice(2, None, 2)],
|
|
159
|
+
"conv2d3": [slice(None, -2, 3)],
|
|
160
|
+
"conv2d4": [slice(2, None, 2), slice(2, None, 2)],
|
|
161
|
+
"conv2d6": [slice(2, None, 2), slice(4, None, 3)],
|
|
162
|
+
"conv2d8": [slice(2, None, 2), slice(2, None, 2), slice(2, None, 2)],
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
def __init__(self, args: ConformerArgs):
|
|
166
|
+
super().__init__()
|
|
167
|
+
conv_layers = self.CONV_LAYERS[args.input_layer]
|
|
168
|
+
|
|
169
|
+
self.mask_patterns = self.CONV_MASKS[args.input_layer]
|
|
170
|
+
self.conv = []
|
|
171
|
+
self.subsampling_rate = 0
|
|
172
|
+
|
|
173
|
+
in_channels = 1
|
|
174
|
+
out_freq = args.input_size
|
|
175
|
+
for kernel_size, stride in conv_layers:
|
|
176
|
+
self.conv.append(
|
|
177
|
+
nn.Conv2d(
|
|
178
|
+
in_channels,
|
|
179
|
+
args.output_size,
|
|
180
|
+
kernel_size=kernel_size,
|
|
181
|
+
stride=stride,
|
|
182
|
+
)
|
|
183
|
+
)
|
|
184
|
+
self.conv.append(nn.ReLU())
|
|
185
|
+
|
|
186
|
+
in_channels = args.output_size
|
|
187
|
+
out_freq = (out_freq - kernel_size + stride) // stride
|
|
188
|
+
self.subsampling_rate *= stride
|
|
189
|
+
|
|
190
|
+
self.out = [nn.Linear(args.output_size * out_freq, args.output_size)]
|
|
191
|
+
|
|
192
|
+
def __call__(self, x: mx.array, mask: Optional[mx.array] = None):
|
|
193
|
+
x = x[:, :, :, None]
|
|
194
|
+
|
|
195
|
+
for layer in self.conv:
|
|
196
|
+
x = layer(x)
|
|
197
|
+
|
|
198
|
+
x = x.swapaxes(2, 3).reshape(*x.shape[:2], -1)
|
|
199
|
+
|
|
200
|
+
for layer in self.out:
|
|
201
|
+
x = layer(x)
|
|
202
|
+
|
|
203
|
+
if mask is not None:
|
|
204
|
+
for pattern in self.mask_patterns:
|
|
205
|
+
mask = mask[pattern]
|
|
206
|
+
|
|
207
|
+
return x, mask
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
class Conformer(nn.Module):
|
|
211
|
+
def __init__(self, args: ConformerArgs):
|
|
212
|
+
super().__init__()
|
|
213
|
+
|
|
214
|
+
if args.pos_enc_layer_type == "rel_pos":
|
|
215
|
+
self.pos_enc = RelPositionalEncoding(
|
|
216
|
+
d_model=args.output_size,
|
|
217
|
+
max_len=args.pos_emb_max_len,
|
|
218
|
+
scale_input=args.xscaling,
|
|
219
|
+
)
|
|
220
|
+
else:
|
|
221
|
+
self.pos_enc = None
|
|
222
|
+
|
|
223
|
+
self.embed = Conv2dSubsampling(args)
|
|
224
|
+
self.encoders = [ConformerBlock(args) for _ in range(args.num_blocks)]
|
|
225
|
+
self.after_norm = nn.LayerNorm(args.output_size, eps=1e-5)
|
|
226
|
+
|
|
227
|
+
def __call__(
|
|
228
|
+
self, x: mx.array, mask: Optional[mx.array] = None, cache=None
|
|
229
|
+
) -> mx.array:
|
|
230
|
+
x, mask = self.embed(x, mask)
|
|
231
|
+
|
|
232
|
+
if cache is None:
|
|
233
|
+
cache = [None] * len(self.encoders)
|
|
234
|
+
|
|
235
|
+
pos_emb = None
|
|
236
|
+
if self.pos_enc is not None:
|
|
237
|
+
x, pos_emb = self.pos_enc(
|
|
238
|
+
x,
|
|
239
|
+
offset=cache[0].offset if cache[0] is not None else 0, # type: ignore
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
for layer, c in zip(self.encoders, cache):
|
|
243
|
+
x = layer(x, pos_emb=pos_emb, cache=c, mask=mask)
|
|
244
|
+
|
|
245
|
+
x = self.after_norm(x)
|
|
246
|
+
|
|
247
|
+
return x
|
|
File without changes
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
import mlx.core as mx
|
|
4
|
+
import mlx.nn as nn
|
|
5
|
+
|
|
6
|
+
from mlx_audio.tts.models.indextts.ecapa_tdnn.tdnn import TDNN
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AttentiveStatisticsPooling(nn.Module):
|
|
10
|
+
def __init__(
|
|
11
|
+
self, channels: int, attention_channels: int, global_context: bool = True
|
|
12
|
+
):
|
|
13
|
+
super().__init__()
|
|
14
|
+
|
|
15
|
+
self.eps = 1e-12
|
|
16
|
+
self.global_context = global_context
|
|
17
|
+
|
|
18
|
+
self.tdnn = TDNN(
|
|
19
|
+
channels * 3 if global_context else channels, attention_channels, 1
|
|
20
|
+
)
|
|
21
|
+
self.tanh = nn.Tanh()
|
|
22
|
+
self.conv = nn.Conv1d(attention_channels, channels, 1)
|
|
23
|
+
|
|
24
|
+
def __call__(self, x: mx.array, mask: Optional[mx.array] = None): # NLC
|
|
25
|
+
N, L, C = x.shape
|
|
26
|
+
|
|
27
|
+
if mask is not None:
|
|
28
|
+
mask = mask[:, :, None]
|
|
29
|
+
else:
|
|
30
|
+
mask = mx.ones((N, L, 1))
|
|
31
|
+
|
|
32
|
+
if self.global_context:
|
|
33
|
+
global_mean = (x * mask).sum(1, keepdims=True) / (
|
|
34
|
+
mask.sum(1, keepdims=True) + self.eps
|
|
35
|
+
)
|
|
36
|
+
global_std = mx.sqrt(
|
|
37
|
+
((x - global_mean) ** 2 * mask).sum(1, keepdims=True)
|
|
38
|
+
/ (mask.sum(1, keepdims=True) + self.eps)
|
|
39
|
+
+ self.eps
|
|
40
|
+
)
|
|
41
|
+
attn = mx.concat(
|
|
42
|
+
[
|
|
43
|
+
x,
|
|
44
|
+
mx.repeat(global_mean, L, axis=1),
|
|
45
|
+
mx.repeat(global_std, L, axis=1),
|
|
46
|
+
],
|
|
47
|
+
axis=2,
|
|
48
|
+
)
|
|
49
|
+
else:
|
|
50
|
+
attn = x
|
|
51
|
+
|
|
52
|
+
attn = self.conv(self.tanh(self.tdnn(attn)))
|
|
53
|
+
|
|
54
|
+
attn = mx.softmax(mx.where(mask == 0, -mx.inf, attn), axis=1)
|
|
55
|
+
|
|
56
|
+
mean = (x * attn).sum(1, keepdims=True)
|
|
57
|
+
std = mx.sqrt(((x - mean) ** 2 * attn).sum(1, keepdims=True) + self.eps)
|
|
58
|
+
|
|
59
|
+
return mx.concat([mean, std], axis=2)
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
from dataclasses import dataclass, field
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
import mlx.core as mx
|
|
5
|
+
import mlx.nn as nn
|
|
6
|
+
|
|
7
|
+
from mlx_audio.tts.models.indextts.ecapa_tdnn.asp import AttentiveStatisticsPooling
|
|
8
|
+
from mlx_audio.tts.models.indextts.ecapa_tdnn.se_res2net import SeRes2Net
|
|
9
|
+
from mlx_audio.tts.models.indextts.ecapa_tdnn.tdnn import TDNN
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class ECPATDNNArgs:
|
|
14
|
+
input_size: int
|
|
15
|
+
lin_neurons: int = 192
|
|
16
|
+
channels: list[int] = field(default_factory=lambda: [512, 512, 512, 512, 1536])
|
|
17
|
+
kernel_sizes: list[int] = field(default_factory=lambda: [5, 3, 3, 3, 1])
|
|
18
|
+
dilations: list[int] = field(default_factory=lambda: [1, 2, 3, 4, 1])
|
|
19
|
+
attention_channels: int = 128
|
|
20
|
+
res2net_scale: int = 8
|
|
21
|
+
se_channels: int = 128
|
|
22
|
+
global_context: bool = True
|
|
23
|
+
groups: list[int] = field(default_factory=lambda: [1, 1, 1, 1, 1])
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ECPATDNN(nn.Module):
|
|
27
|
+
def __init__(self, args: ECPATDNNArgs):
|
|
28
|
+
super().__init__()
|
|
29
|
+
assert len(args.channels) == len(args.kernel_sizes) and len(
|
|
30
|
+
args.channels
|
|
31
|
+
) == len(args.dilations)
|
|
32
|
+
|
|
33
|
+
self.args = args
|
|
34
|
+
|
|
35
|
+
self.blocks = [
|
|
36
|
+
TDNN(
|
|
37
|
+
args.input_size,
|
|
38
|
+
args.channels[0],
|
|
39
|
+
args.kernel_sizes[0],
|
|
40
|
+
dilation=args.dilations[0],
|
|
41
|
+
groups=args.groups[0],
|
|
42
|
+
)
|
|
43
|
+
] + [
|
|
44
|
+
SeRes2Net(
|
|
45
|
+
args.channels[i - 1],
|
|
46
|
+
args.channels[i],
|
|
47
|
+
scale=args.res2net_scale,
|
|
48
|
+
attention_channels=args.se_channels,
|
|
49
|
+
kernel_size=args.kernel_sizes[i],
|
|
50
|
+
dilation=args.dilations[i],
|
|
51
|
+
groups=args.groups[i],
|
|
52
|
+
)
|
|
53
|
+
for i in range(1, len(args.channels) - 1)
|
|
54
|
+
]
|
|
55
|
+
self.mfa = TDNN(
|
|
56
|
+
args.channels[-2] * (len(args.channels) - 2),
|
|
57
|
+
args.channels[-1],
|
|
58
|
+
args.kernel_sizes[-1],
|
|
59
|
+
dilation=args.dilations[-1],
|
|
60
|
+
groups=args.groups[-1],
|
|
61
|
+
)
|
|
62
|
+
self.asp = AttentiveStatisticsPooling(
|
|
63
|
+
args.channels[-1],
|
|
64
|
+
attention_channels=args.attention_channels,
|
|
65
|
+
global_context=args.global_context,
|
|
66
|
+
)
|
|
67
|
+
self.asp_bn = nn.BatchNorm(args.channels[-1] * 2)
|
|
68
|
+
self.fc = nn.Conv1d(
|
|
69
|
+
in_channels=args.channels[-1] * 2,
|
|
70
|
+
out_channels=args.lin_neurons,
|
|
71
|
+
kernel_size=1,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
def __call__(self, x: mx.array, mask: Optional[mx.array] = None): #
|
|
75
|
+
xl = []
|
|
76
|
+
for layer in self.blocks:
|
|
77
|
+
if isinstance(layer, SeRes2Net):
|
|
78
|
+
x = layer(x, mask=mask)
|
|
79
|
+
xl.append(mx.array(x))
|
|
80
|
+
else:
|
|
81
|
+
x = layer(x)
|
|
82
|
+
|
|
83
|
+
x = mx.concat(xl, axis=2)
|
|
84
|
+
x = self.mfa(x)
|
|
85
|
+
|
|
86
|
+
x = self.asp(x, mask=mask)
|
|
87
|
+
x = self.asp_bn(x)
|
|
88
|
+
|
|
89
|
+
x = self.fc(x)
|
|
90
|
+
|
|
91
|
+
return x
|