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,383 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import Optional, Tuple
|
|
4
|
+
|
|
5
|
+
import mlx.core as mx
|
|
6
|
+
import mlx.nn as nn
|
|
7
|
+
from einops.array_api import rearrange
|
|
8
|
+
from huggingface_hub import snapshot_download
|
|
9
|
+
|
|
10
|
+
from .model import MultiHeadAttention
|
|
11
|
+
from .utils import make_non_pad_mask, mask_to_bias
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass
|
|
15
|
+
class ModelConfig:
|
|
16
|
+
n_mels: int = 128
|
|
17
|
+
n_audio_ctx: int = 1500
|
|
18
|
+
n_audio_state: int = 1280
|
|
19
|
+
n_audio_head: int = 20
|
|
20
|
+
n_audio_layer: int = 6
|
|
21
|
+
n_codebook_size: int = 3**8
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def precompute_freqs_cis(
|
|
25
|
+
dim: int, end: int, theta: float = 10000.0, scaling: Optional[float] = None
|
|
26
|
+
) -> mx.array:
|
|
27
|
+
"""Precompute frequency tensor for rotary embeddings"""
|
|
28
|
+
freqs = 1.0 / (
|
|
29
|
+
theta ** (mx.arange(0, dim, 2)[: (dim // 2)].astype(mx.float32) / dim)
|
|
30
|
+
)
|
|
31
|
+
t = mx.arange(end)
|
|
32
|
+
if scaling is not None:
|
|
33
|
+
t = t * scaling
|
|
34
|
+
freqs = mx.outer(t, freqs).astype(mx.float32)
|
|
35
|
+
cos_freqs = mx.cos(freqs)
|
|
36
|
+
sin_freqs = mx.sin(freqs)
|
|
37
|
+
cos_freqs = mx.concatenate([cos_freqs, cos_freqs], axis=-1)
|
|
38
|
+
sin_freqs = mx.concatenate([sin_freqs, sin_freqs], axis=-1)
|
|
39
|
+
return cos_freqs, sin_freqs
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def apply_rotary_emb(
|
|
43
|
+
xq: mx.array,
|
|
44
|
+
xk: mx.array,
|
|
45
|
+
cos: mx.array,
|
|
46
|
+
sin: mx.array,
|
|
47
|
+
) -> Tuple[mx.array, mx.array]:
|
|
48
|
+
"""Apply rotary embeddings to query and key tensors"""
|
|
49
|
+
# Expand dimensions for broadcasting
|
|
50
|
+
cos = mx.expand_dims(mx.expand_dims(cos, axis=0), axis=2)
|
|
51
|
+
sin = mx.expand_dims(mx.expand_dims(sin, axis=0), axis=2)
|
|
52
|
+
|
|
53
|
+
D = xq.shape[-1]
|
|
54
|
+
# Split and rotate
|
|
55
|
+
xq_half_l, xq_half_r = xq[..., : D // 2], xq[..., D // 2 :]
|
|
56
|
+
xq_rotated = mx.concatenate([-xq_half_r, xq_half_l], axis=-1)
|
|
57
|
+
|
|
58
|
+
xk_half_l, xk_half_r = xk[..., : D // 2], xk[..., D // 2 :]
|
|
59
|
+
xk_rotated = mx.concatenate([-xk_half_r, xk_half_l], axis=-1)
|
|
60
|
+
|
|
61
|
+
# Apply rotation
|
|
62
|
+
xq_out = xq * cos + xq_rotated * sin
|
|
63
|
+
xk_out = xk * cos + xk_rotated * sin
|
|
64
|
+
|
|
65
|
+
return xq_out, xk_out
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class FSQCodebook(nn.Module):
|
|
69
|
+
"""Finite Scalar Quantization Codebook"""
|
|
70
|
+
|
|
71
|
+
def __init__(self, dim: int, level: int = 3):
|
|
72
|
+
super().__init__()
|
|
73
|
+
self.project_down = nn.Linear(dim, 8)
|
|
74
|
+
self.level = level
|
|
75
|
+
self.embed = None
|
|
76
|
+
|
|
77
|
+
def preprocess(self, x: mx.array) -> mx.array:
|
|
78
|
+
x = rearrange(x, "... d -> (...) d")
|
|
79
|
+
return x
|
|
80
|
+
|
|
81
|
+
def encode(self, x: mx.array) -> mx.array:
|
|
82
|
+
x_shape = x.shape
|
|
83
|
+
# pre-process
|
|
84
|
+
x = self.preprocess(x)
|
|
85
|
+
# quantize
|
|
86
|
+
h = self.project_down(x).astype(mx.float32)
|
|
87
|
+
h = mx.tanh(h)
|
|
88
|
+
h = h * 0.9990000128746033
|
|
89
|
+
h = mx.round(h) + 1
|
|
90
|
+
|
|
91
|
+
# Create powers for base conversion
|
|
92
|
+
powers = mx.power(self.level, mx.arange(2**self.level, dtype=h.dtype))
|
|
93
|
+
mu = mx.sum(h * mx.expand_dims(powers, axis=0), axis=-1)
|
|
94
|
+
ind = mu.reshape(x_shape[0], x_shape[1]).astype(mx.int32)
|
|
95
|
+
return ind
|
|
96
|
+
|
|
97
|
+
def decode(self, embed_ind: mx.array) -> mx.array:
|
|
98
|
+
raise NotImplementedError("There is no official up project component provided")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class FSQVectorQuantization(nn.Module):
|
|
102
|
+
"""Finite Scalar Quantization Vector Quantization"""
|
|
103
|
+
|
|
104
|
+
def __init__(
|
|
105
|
+
self,
|
|
106
|
+
dim: int,
|
|
107
|
+
codebook_size: int,
|
|
108
|
+
):
|
|
109
|
+
super().__init__()
|
|
110
|
+
assert 3**8 == codebook_size
|
|
111
|
+
self.fsq_codebook = FSQCodebook(dim=dim, level=3)
|
|
112
|
+
self.codebook_size = codebook_size
|
|
113
|
+
|
|
114
|
+
@property
|
|
115
|
+
def codebook(self):
|
|
116
|
+
return self.fsq_codebook.embed
|
|
117
|
+
|
|
118
|
+
def encode(self, x: mx.array) -> mx.array:
|
|
119
|
+
return self.fsq_codebook.encode(x)
|
|
120
|
+
|
|
121
|
+
def decode(self, embed_ind: mx.array) -> mx.array:
|
|
122
|
+
quantize = self.fsq_codebook.decode(embed_ind)
|
|
123
|
+
quantize = rearrange(quantize, "b n d -> b d n")
|
|
124
|
+
return quantize
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class FSMNMultiHeadAttention(MultiHeadAttention):
|
|
128
|
+
"""Multi-head attention with FSMN (Feedforward Sequential Memory Network)"""
|
|
129
|
+
|
|
130
|
+
def __init__(
|
|
131
|
+
self,
|
|
132
|
+
n_state: int,
|
|
133
|
+
n_head: int,
|
|
134
|
+
kernel_size: int = 31,
|
|
135
|
+
):
|
|
136
|
+
super().__init__(n_state, n_head)
|
|
137
|
+
|
|
138
|
+
self.fsmn_block = nn.Conv1d(
|
|
139
|
+
in_channels=n_state,
|
|
140
|
+
out_channels=n_state,
|
|
141
|
+
kernel_size=kernel_size,
|
|
142
|
+
stride=1,
|
|
143
|
+
padding=0,
|
|
144
|
+
groups=n_state,
|
|
145
|
+
bias=False,
|
|
146
|
+
)
|
|
147
|
+
self.left_padding = (kernel_size - 1) // 2
|
|
148
|
+
self.right_padding = kernel_size - 1 - self.left_padding
|
|
149
|
+
|
|
150
|
+
def forward_fsmn(
|
|
151
|
+
self, inputs: mx.array, mask: Optional[mx.array] = None
|
|
152
|
+
) -> mx.array:
|
|
153
|
+
b, t, n, d = inputs.shape
|
|
154
|
+
inputs = inputs.reshape(b, t, -1)
|
|
155
|
+
|
|
156
|
+
if mask is not None and mask.shape[2] > 0:
|
|
157
|
+
inputs = inputs * mask
|
|
158
|
+
|
|
159
|
+
pad_left = mx.zeros((b, self.left_padding, inputs.shape[2]), dtype=inputs.dtype)
|
|
160
|
+
pad_right = mx.zeros(
|
|
161
|
+
(b, self.right_padding, inputs.shape[2]), dtype=inputs.dtype
|
|
162
|
+
)
|
|
163
|
+
x_padded = mx.concatenate([pad_left, inputs, pad_right], axis=1)
|
|
164
|
+
x = self.fsmn_block(x_padded)
|
|
165
|
+
x = x + inputs
|
|
166
|
+
|
|
167
|
+
if mask is not None:
|
|
168
|
+
x = x * mask
|
|
169
|
+
|
|
170
|
+
return x
|
|
171
|
+
|
|
172
|
+
def qkv_attention(
|
|
173
|
+
self,
|
|
174
|
+
q: mx.array,
|
|
175
|
+
k: mx.array,
|
|
176
|
+
v: mx.array,
|
|
177
|
+
mask: Optional[mx.array] = None,
|
|
178
|
+
mask_pad: Optional[mx.array] = None,
|
|
179
|
+
freqs_cis: Optional[Tuple[mx.array, mx.array]] = None,
|
|
180
|
+
) -> Tuple[mx.array, mx.array | None, mx.array]:
|
|
181
|
+
B, T, D = q.shape
|
|
182
|
+
scale = (D // self.n_head) ** -0.25
|
|
183
|
+
|
|
184
|
+
q = q.reshape(B, T, self.n_head, -1)
|
|
185
|
+
k = k.reshape(B, T, self.n_head, -1)
|
|
186
|
+
v = v.reshape(B, T, self.n_head, -1)
|
|
187
|
+
|
|
188
|
+
if freqs_cis is not None:
|
|
189
|
+
cos, sin = freqs_cis
|
|
190
|
+
q, k = apply_rotary_emb(q, k, cos[:T], sin[:T])
|
|
191
|
+
|
|
192
|
+
fsm_memory = self.forward_fsmn(v, mask_pad)
|
|
193
|
+
|
|
194
|
+
q = q.transpose(0, 2, 1, 3) * scale
|
|
195
|
+
k = k.transpose(0, 2, 1, 3) * scale
|
|
196
|
+
v = v.transpose(0, 2, 1, 3)
|
|
197
|
+
|
|
198
|
+
output = mx.fast.scaled_dot_product_attention(q, k, v, scale=1, mask=mask)
|
|
199
|
+
output = output.transpose(0, 2, 1, 3).reshape(B, T, D)
|
|
200
|
+
|
|
201
|
+
return output, None, fsm_memory
|
|
202
|
+
|
|
203
|
+
def __call__(
|
|
204
|
+
self,
|
|
205
|
+
x: mx.array,
|
|
206
|
+
mask: Optional[mx.array] = None,
|
|
207
|
+
mask_pad: Optional[mx.array] = None,
|
|
208
|
+
freqs_cis: Optional[Tuple[mx.array, mx.array]] = None,
|
|
209
|
+
) -> Tuple[mx.array, mx.array | None]:
|
|
210
|
+
q = self.query(x)
|
|
211
|
+
k = self.key(x)
|
|
212
|
+
v = self.value(x)
|
|
213
|
+
|
|
214
|
+
wv, qk, fsm_memory = self.qkv_attention(q, k, v, mask, mask_pad, freqs_cis)
|
|
215
|
+
return self.out(wv) + fsm_memory, qk
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
class ResidualAttentionBlock(nn.Module):
|
|
219
|
+
"""Residual attention block with FSMN"""
|
|
220
|
+
|
|
221
|
+
def __init__(
|
|
222
|
+
self,
|
|
223
|
+
n_state: int,
|
|
224
|
+
n_head: int,
|
|
225
|
+
kernel_size: int = 31,
|
|
226
|
+
):
|
|
227
|
+
super().__init__()
|
|
228
|
+
|
|
229
|
+
self.attn = FSMNMultiHeadAttention(n_state, n_head, kernel_size)
|
|
230
|
+
self.attn_ln = nn.LayerNorm(n_state, eps=1e-6)
|
|
231
|
+
|
|
232
|
+
n_mlp = n_state * 4
|
|
233
|
+
self.mlp = nn.Sequential(
|
|
234
|
+
nn.Linear(n_state, n_mlp), nn.GELU(), nn.Linear(n_mlp, n_state)
|
|
235
|
+
)
|
|
236
|
+
self.mlp_ln = nn.LayerNorm(n_state)
|
|
237
|
+
|
|
238
|
+
def __call__(
|
|
239
|
+
self,
|
|
240
|
+
x: mx.array,
|
|
241
|
+
mask: Optional[mx.array] = None,
|
|
242
|
+
mask_pad: Optional[mx.array] = None,
|
|
243
|
+
freqs_cis: Optional[Tuple[mx.array, mx.array]] = None,
|
|
244
|
+
) -> mx.array:
|
|
245
|
+
x = (
|
|
246
|
+
x
|
|
247
|
+
+ self.attn(
|
|
248
|
+
self.attn_ln(x), mask=mask, mask_pad=mask_pad, freqs_cis=freqs_cis
|
|
249
|
+
)[0]
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
x = x + self.mlp(self.mlp_ln(x))
|
|
253
|
+
return x
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
class AudioEncoderV2(nn.Module):
|
|
257
|
+
def __init__(
|
|
258
|
+
self,
|
|
259
|
+
n_mels: int,
|
|
260
|
+
n_state: int,
|
|
261
|
+
n_head: int,
|
|
262
|
+
n_layer: int,
|
|
263
|
+
stride: int,
|
|
264
|
+
):
|
|
265
|
+
super().__init__()
|
|
266
|
+
self.stride = stride
|
|
267
|
+
|
|
268
|
+
self.conv1 = nn.Conv1d(
|
|
269
|
+
in_channels=n_mels,
|
|
270
|
+
out_channels=n_state,
|
|
271
|
+
kernel_size=3,
|
|
272
|
+
stride=stride,
|
|
273
|
+
padding=1,
|
|
274
|
+
)
|
|
275
|
+
self.conv2 = nn.Conv1d(
|
|
276
|
+
in_channels=n_state,
|
|
277
|
+
out_channels=n_state,
|
|
278
|
+
kernel_size=3,
|
|
279
|
+
stride=2,
|
|
280
|
+
padding=1,
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
self._freqs_cis = precompute_freqs_cis(64, 1024 * 2)
|
|
284
|
+
|
|
285
|
+
self.blocks = [ResidualAttentionBlock(n_state, n_head) for _ in range(n_layer)]
|
|
286
|
+
|
|
287
|
+
def __call__(self, x: mx.array, x_len: mx.array) -> Tuple[mx.array, mx.array]:
|
|
288
|
+
"""
|
|
289
|
+
x : mx.array, shape = (batch_size, n_mels, T)
|
|
290
|
+
the mel spectrogram of the audio
|
|
291
|
+
x_len: mx.array, shape = (batch_size,)
|
|
292
|
+
length of each audio in x
|
|
293
|
+
"""
|
|
294
|
+
mask = make_non_pad_mask(x_len)
|
|
295
|
+
mask = mx.expand_dims(mask, axis=1) # (B, 1, T)
|
|
296
|
+
|
|
297
|
+
x = x.transpose(0, 2, 1) # (B, T, n_mels)
|
|
298
|
+
mask_transposed = mask.transpose(0, 2, 1) # (B, T, 1)
|
|
299
|
+
|
|
300
|
+
x = self.conv1(x * mask_transposed)
|
|
301
|
+
x = nn.gelu(x)
|
|
302
|
+
x_len = (x_len + 2 - 1 * (3 - 1) - 1) // self.stride + 1
|
|
303
|
+
|
|
304
|
+
mask = make_non_pad_mask(x_len)
|
|
305
|
+
mask_transposed = mx.expand_dims(mask, axis=-1) # (B, T, 1)
|
|
306
|
+
|
|
307
|
+
x = self.conv2(x * mask_transposed)
|
|
308
|
+
x = nn.gelu(x)
|
|
309
|
+
x_len = (x_len + 2 - 1 * (3 - 1) - 1) // 2 + 1
|
|
310
|
+
|
|
311
|
+
mask = make_non_pad_mask(x_len)
|
|
312
|
+
mask_pad = mx.expand_dims(mask, axis=-1) # (B, T, 1)
|
|
313
|
+
mask = mask_to_bias(mask, x.dtype)
|
|
314
|
+
mask = mx.expand_dims(mask, axis=1) # (B, 1, T)
|
|
315
|
+
|
|
316
|
+
for block in self.blocks:
|
|
317
|
+
x = block(x, mask, mask_pad, self._freqs_cis)
|
|
318
|
+
|
|
319
|
+
return x, x_len
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
class S3TokenizerV2(nn.Module):
|
|
323
|
+
"""S3 tokenizer v2 implementation.
|
|
324
|
+
Args:
|
|
325
|
+
config (ModelConfig): Config
|
|
326
|
+
"""
|
|
327
|
+
|
|
328
|
+
def __init__(self, name: str, config: ModelConfig = ModelConfig()):
|
|
329
|
+
super().__init__()
|
|
330
|
+
if "v1" not in name:
|
|
331
|
+
assert "v2" in name
|
|
332
|
+
config.n_codebook_size = 3**8
|
|
333
|
+
self.config = config
|
|
334
|
+
self.encoder = AudioEncoderV2(
|
|
335
|
+
self.config.n_mels,
|
|
336
|
+
self.config.n_audio_state,
|
|
337
|
+
self.config.n_audio_head,
|
|
338
|
+
self.config.n_audio_layer,
|
|
339
|
+
2,
|
|
340
|
+
)
|
|
341
|
+
self.quantizer = FSQVectorQuantization(
|
|
342
|
+
self.config.n_audio_state,
|
|
343
|
+
self.config.n_codebook_size,
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
def __call__(self, mel: mx.array, mel_len: mx.array) -> Tuple[mx.array, mx.array]:
|
|
347
|
+
return self.quantize(mel, mel_len)
|
|
348
|
+
|
|
349
|
+
def quantize(self, mel: mx.array, mel_len: mx.array) -> Tuple[mx.array, mx.array]:
|
|
350
|
+
hidden, code_len = self.encoder(mel, mel_len)
|
|
351
|
+
code = self.quantizer.encode(hidden)
|
|
352
|
+
return code, code_len
|
|
353
|
+
|
|
354
|
+
@classmethod
|
|
355
|
+
def from_pretrained(
|
|
356
|
+
cls,
|
|
357
|
+
name: str = "speech_tokenizer_v2_25hz",
|
|
358
|
+
repo_id: str = "mlx-community/CosyVoice2-0.5B-S3Tokenizer",
|
|
359
|
+
) -> "S3TokenizerV2":
|
|
360
|
+
path = fetch_from_hub(repo_id)
|
|
361
|
+
if path is None:
|
|
362
|
+
raise ValueError(f"Could not find model {path}")
|
|
363
|
+
|
|
364
|
+
model = S3TokenizerV2(name)
|
|
365
|
+
model_path = path / f"{name}.safetensors"
|
|
366
|
+
weights = mx.load(model_path.as_posix(), format="safetensors")
|
|
367
|
+
model.load_weights(list(weights.items()))
|
|
368
|
+
mx.eval(model.parameters())
|
|
369
|
+
|
|
370
|
+
return model
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
# fetch model from hub
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
def fetch_from_hub(hf_repo: str) -> Path:
|
|
377
|
+
model_path = Path(
|
|
378
|
+
snapshot_download(
|
|
379
|
+
repo_id=hf_repo,
|
|
380
|
+
allow_patterns=["*.safetensors", "*.json"],
|
|
381
|
+
)
|
|
382
|
+
)
|
|
383
|
+
return model_path
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
import mlx.core as mx
|
|
4
|
+
|
|
5
|
+
from mlx_audio.utils import hanning, mel_filters, stft
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def log_mel_spectrogram(
|
|
9
|
+
audio: mx.array,
|
|
10
|
+
sample_rate: int = 16_000,
|
|
11
|
+
n_mels: int = 128,
|
|
12
|
+
n_fft: int = 400,
|
|
13
|
+
hop_length: int = 160,
|
|
14
|
+
padding: int = 0,
|
|
15
|
+
):
|
|
16
|
+
if not isinstance(audio, mx.array):
|
|
17
|
+
audio = mx.array(audio)
|
|
18
|
+
|
|
19
|
+
if padding > 0:
|
|
20
|
+
audio = mx.pad(audio, (0, padding))
|
|
21
|
+
|
|
22
|
+
window = hanning(n_fft + 1)[:-1]
|
|
23
|
+
freqs = stft(
|
|
24
|
+
audio,
|
|
25
|
+
window=window,
|
|
26
|
+
n_fft=n_fft,
|
|
27
|
+
hop_length=hop_length,
|
|
28
|
+
win_length=n_fft,
|
|
29
|
+
).swapaxes(0, 1)
|
|
30
|
+
magnitudes = freqs.abs() ** 2
|
|
31
|
+
filters = mel_filters(
|
|
32
|
+
sample_rate=sample_rate,
|
|
33
|
+
n_fft=n_fft,
|
|
34
|
+
n_mels=n_mels,
|
|
35
|
+
norm="slaney",
|
|
36
|
+
mel_scale="slaney",
|
|
37
|
+
)
|
|
38
|
+
mel_spec = filters @ magnitudes
|
|
39
|
+
log_spec = mx.maximum(mel_spec, 1e-10).log10()
|
|
40
|
+
log_spec = mx.maximum(log_spec, log_spec.max() - 8.0)
|
|
41
|
+
log_spec = (log_spec + 4.0) / 4.0
|
|
42
|
+
return log_spec
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def make_non_pad_mask(lengths: mx.array, max_len: int = 0) -> mx.array:
|
|
46
|
+
"""Make mask tensor containing indices of non-padded part.
|
|
47
|
+
|
|
48
|
+
The sequences in a batch may have different lengths. To enable
|
|
49
|
+
batch computing, padding is need to make all sequence in same
|
|
50
|
+
size. To avoid the padding part pass value to context dependent
|
|
51
|
+
block such as attention or convolution, this padding part is
|
|
52
|
+
masked.
|
|
53
|
+
|
|
54
|
+
1 for non-padded part and 0 for padded part.
|
|
55
|
+
|
|
56
|
+
Parameters
|
|
57
|
+
----------
|
|
58
|
+
lengths (mx.array): Batch of lengths (B,).
|
|
59
|
+
max_len (int): Maximum length. If 0, use the maximum length in batch.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
-------
|
|
63
|
+
mx.array: Mask tensor containing indices of padded part (B, max_T).
|
|
64
|
+
|
|
65
|
+
Examples:
|
|
66
|
+
>>> import mlx.core as mx
|
|
67
|
+
>>> lengths = mx.array([5, 3, 2])
|
|
68
|
+
>>> masks = make_non_pad_mask(lengths)
|
|
69
|
+
masks = [[1, 1, 1, 1, 1],
|
|
70
|
+
[1, 1, 1, 0, 0],
|
|
71
|
+
[1, 1, 0, 0, 0]]
|
|
72
|
+
"""
|
|
73
|
+
batch_size = lengths.shape[0]
|
|
74
|
+
max_len = max_len if max_len > 0 else int(mx.max(lengths).item())
|
|
75
|
+
seq_range = mx.arange(0, max_len, dtype=mx.int32)
|
|
76
|
+
seq_range_expand = mx.expand_dims(seq_range, axis=0) # (1, max_len)
|
|
77
|
+
seq_range_expand = mx.broadcast_to(seq_range_expand, (batch_size, max_len))
|
|
78
|
+
seq_length_expand = mx.expand_dims(lengths, axis=-1) # (B, 1)
|
|
79
|
+
mask = seq_range_expand >= seq_length_expand
|
|
80
|
+
return mx.logical_not(mask)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def mask_to_bias(mask: mx.array, dtype: mx.Dtype = mx.float32) -> mx.array:
|
|
84
|
+
assert mask.dtype == mx.bool_, "Input mask must be boolean type"
|
|
85
|
+
assert dtype in [
|
|
86
|
+
mx.float32,
|
|
87
|
+
mx.bfloat16,
|
|
88
|
+
mx.float16,
|
|
89
|
+
], "dtype must be a floating point type"
|
|
90
|
+
mask = mask.astype(dtype)
|
|
91
|
+
mask = (1.0 - mask) * -1.0e10
|
|
92
|
+
return mask
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def padding(data: List[mx.array]) -> tuple[mx.array, mx.array]:
|
|
96
|
+
"""Padding the data into batch data
|
|
97
|
+
|
|
98
|
+
Parameters
|
|
99
|
+
----------
|
|
100
|
+
data: List[mx.array], shape of each array (128, T)
|
|
101
|
+
|
|
102
|
+
Returns:
|
|
103
|
+
-------
|
|
104
|
+
Tuple of (padded_feats, feats_lengths)
|
|
105
|
+
- padded_feats: shape (B, 128, max_T)
|
|
106
|
+
- feats_lengths: shape (B,)
|
|
107
|
+
"""
|
|
108
|
+
assert isinstance(data, list), "Input must be a list of arrays"
|
|
109
|
+
|
|
110
|
+
feats_lengths = mx.array([s.shape[1] for s in data], dtype=mx.int32)
|
|
111
|
+
|
|
112
|
+
max_len = max(s.shape[1] for s in data)
|
|
113
|
+
batch_size = len(data)
|
|
114
|
+
n_mels = data[0].shape[0]
|
|
115
|
+
|
|
116
|
+
padded_feats = mx.zeros((batch_size, n_mels, max_len), dtype=data[0].dtype)
|
|
117
|
+
|
|
118
|
+
for i, feat in enumerate(data):
|
|
119
|
+
seq_len = feat.shape[1]
|
|
120
|
+
padded_feats[i, :, :seq_len] = feat
|
|
121
|
+
|
|
122
|
+
return padded_feats, feats_lengths
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .snac import SNAC
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import mlx.core as mx
|
|
2
|
+
import mlx.nn as nn
|
|
3
|
+
from einops.array_api import rearrange
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class LocalMHA(nn.Module):
|
|
7
|
+
def __init__(self, dim=1024, window_size=32, dim_head=64, use_rotary_pos_emb=True):
|
|
8
|
+
super().__init__()
|
|
9
|
+
self.norm = nn.LayerNorm(dim)
|
|
10
|
+
self.heads = dim // dim_head
|
|
11
|
+
self.window_size = window_size
|
|
12
|
+
self.to_qkv = nn.Linear(dim, dim * 3, bias=False)
|
|
13
|
+
if use_rotary_pos_emb:
|
|
14
|
+
self.rel_pos = SinusoidalEmbeddings(dim_head, scale_base=window_size // 2)
|
|
15
|
+
else:
|
|
16
|
+
self.rel_pos = None
|
|
17
|
+
self.to_out = nn.Linear(dim, dim, bias=False)
|
|
18
|
+
|
|
19
|
+
def __call__(self, x):
|
|
20
|
+
B, C, T = x.shape
|
|
21
|
+
residual = x
|
|
22
|
+
x = self.norm(x.moveaxis(1, 2))
|
|
23
|
+
windows = T // self.window_size
|
|
24
|
+
|
|
25
|
+
qkv = self.to_qkv(x)
|
|
26
|
+
q, k, v = mx.split(qkv, 3, axis=-1)
|
|
27
|
+
|
|
28
|
+
q = rearrange(q, "b (w n) (h d) -> b h w n d", w=windows, h=self.heads)
|
|
29
|
+
k = rearrange(k, "b (w n) (h d) -> b h w n d", w=windows, h=self.heads)
|
|
30
|
+
v = rearrange(v, "b (w n) (h d) -> b h w n d", w=windows, h=self.heads)
|
|
31
|
+
|
|
32
|
+
if self.rel_pos is not None:
|
|
33
|
+
pos_emb, scale = self.rel_pos(k)
|
|
34
|
+
q, k = apply_rotary_pos_emb(q, k, pos_emb, scale)
|
|
35
|
+
|
|
36
|
+
scale = mx.sqrt(mx.array(q.shape[-1], dtype=mx.float32))
|
|
37
|
+
scores = mx.matmul(q, k.transpose(0, 1, 2, 4, 3)) / scale
|
|
38
|
+
attn_weights = mx.softmax(scores, axis=-1)
|
|
39
|
+
out = mx.matmul(attn_weights, v)
|
|
40
|
+
|
|
41
|
+
out = rearrange(out, "b h w n d -> b (w n) (h d)")
|
|
42
|
+
out = self.to_out(out)
|
|
43
|
+
return out.moveaxis(1, 2) + residual
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class SinusoidalEmbeddings(nn.Module):
|
|
47
|
+
def __init__(self, dim, scale_base=None, use_xpos=False):
|
|
48
|
+
super().__init__()
|
|
49
|
+
inv_freq = 1.0 / (10000 ** (mx.arange(0, dim, 2, dtype=mx.float32) / dim))
|
|
50
|
+
self.inv_freq = inv_freq
|
|
51
|
+
|
|
52
|
+
# xpos related
|
|
53
|
+
self.use_xpos = use_xpos
|
|
54
|
+
self.scale_base = scale_base
|
|
55
|
+
assert not (
|
|
56
|
+
use_xpos and scale_base is None
|
|
57
|
+
), "scale base must be defined if using xpos"
|
|
58
|
+
|
|
59
|
+
if use_xpos:
|
|
60
|
+
scale = (mx.arange(0, dim, 2, dtype=mx.float32) + 0.4 * dim) / (1.4 * dim)
|
|
61
|
+
self.scale = scale
|
|
62
|
+
|
|
63
|
+
def __call__(self, x):
|
|
64
|
+
seq_len = x.shape[-2]
|
|
65
|
+
t = mx.arange(seq_len, dtype=self.inv_freq.dtype)
|
|
66
|
+
freqs = mx.einsum("i,j->ij", t, self.inv_freq)
|
|
67
|
+
freqs = mx.concatenate([freqs, freqs], axis=-1)
|
|
68
|
+
|
|
69
|
+
if not self.use_xpos:
|
|
70
|
+
return freqs, mx.ones((1,))
|
|
71
|
+
|
|
72
|
+
power = (t - (seq_len // 2)) / self.scale_base
|
|
73
|
+
power_reshaped = rearrange(power, "n -> n 1")
|
|
74
|
+
scale = mx.power(self.scale, power_reshaped)
|
|
75
|
+
scale = mx.concatenate([scale, scale], axis=-1)
|
|
76
|
+
|
|
77
|
+
return freqs, scale
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def rotate_half(x):
|
|
81
|
+
x = rearrange(x, "b ... (r d) -> b ... r d", r=2)
|
|
82
|
+
x1, x2 = mx.split(x, 2, axis=-2)
|
|
83
|
+
return mx.concatenate([-x2, x1], axis=-1)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def apply_rotary_pos_emb(q, k, freqs, scale=1):
|
|
87
|
+
q_len = q.shape[-2]
|
|
88
|
+
q_freqs = freqs[..., -q_len:, :]
|
|
89
|
+
inv_scale = mx.power(scale, -1)
|
|
90
|
+
|
|
91
|
+
if scale.ndim == 2:
|
|
92
|
+
scale = scale[-q_len:, :]
|
|
93
|
+
|
|
94
|
+
q = (q * mx.cos(q_freqs) * scale) + (rotate_half(q) * mx.sin(q_freqs) * scale)
|
|
95
|
+
k = (k * mx.cos(freqs) * inv_scale) + (rotate_half(k) * mx.sin(freqs) * inv_scale)
|
|
96
|
+
|
|
97
|
+
return q, k
|