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,306 @@
|
|
|
1
|
+
import math
|
|
2
|
+
|
|
3
|
+
import mlx.core as mx
|
|
4
|
+
import mlx.nn as nn
|
|
5
|
+
|
|
6
|
+
from .attention import LocalMHA
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def normalize_weight(x, except_dim=0):
|
|
10
|
+
if x.ndim != 3:
|
|
11
|
+
raise ValueError("Input tensor must have 3 dimensions")
|
|
12
|
+
|
|
13
|
+
axes = tuple(i for i in range(x.ndim) if i != except_dim)
|
|
14
|
+
return mx.sqrt(mx.sum(mx.power(x, 2), axis=axes, keepdims=True))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class WNConv1d(nn.Module):
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
in_channels: int,
|
|
21
|
+
out_channels: int,
|
|
22
|
+
kernel_size: int,
|
|
23
|
+
stride: int = 1,
|
|
24
|
+
padding: int = 0,
|
|
25
|
+
dilation: int = 1,
|
|
26
|
+
groups: int = 1,
|
|
27
|
+
bias: bool = True,
|
|
28
|
+
):
|
|
29
|
+
super().__init__()
|
|
30
|
+
|
|
31
|
+
if bias:
|
|
32
|
+
self.bias = mx.zeros((out_channels,))
|
|
33
|
+
|
|
34
|
+
self.kernel_size = kernel_size
|
|
35
|
+
self.padding = padding
|
|
36
|
+
self.dilation = dilation
|
|
37
|
+
self.stride = stride
|
|
38
|
+
self.groups = groups
|
|
39
|
+
|
|
40
|
+
scale = math.sqrt(1 / (in_channels * kernel_size))
|
|
41
|
+
weight_init = mx.random.uniform(
|
|
42
|
+
low=-scale,
|
|
43
|
+
high=scale,
|
|
44
|
+
shape=(out_channels, kernel_size, in_channels // groups),
|
|
45
|
+
)
|
|
46
|
+
self.weight_g = normalize_weight(weight_init)
|
|
47
|
+
self.weight_v = weight_init / (self.weight_g + 1e-12)
|
|
48
|
+
|
|
49
|
+
def _extra_repr(self):
|
|
50
|
+
return (
|
|
51
|
+
f"kernel_size={self.kernel_size}, stride={self.stride}, "
|
|
52
|
+
f"padding={self.padding}, dilation={self.dilation}, "
|
|
53
|
+
f"groups={self.groups}, bias={'bias' in self}"
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
def __call__(self, x):
|
|
57
|
+
weight = self.weight_g * self.weight_v / normalize_weight(self.weight_v)
|
|
58
|
+
y = mx.conv1d(x, weight, self.stride, self.padding, self.dilation, self.groups)
|
|
59
|
+
if hasattr(self, "bias"):
|
|
60
|
+
y = y + self.bias
|
|
61
|
+
return y
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class WNConvTranspose1d(nn.Module):
|
|
65
|
+
def __init__(
|
|
66
|
+
self,
|
|
67
|
+
in_channels: int,
|
|
68
|
+
out_channels: int,
|
|
69
|
+
kernel_size: int,
|
|
70
|
+
stride: int = 1,
|
|
71
|
+
padding: int = 0,
|
|
72
|
+
dilation: int = 1,
|
|
73
|
+
output_padding: int = 0,
|
|
74
|
+
groups: int = 1,
|
|
75
|
+
bias: bool = True,
|
|
76
|
+
):
|
|
77
|
+
super().__init__()
|
|
78
|
+
|
|
79
|
+
self.bias = mx.zeros((out_channels,)) if bias else None
|
|
80
|
+
|
|
81
|
+
self.kernel_size = kernel_size
|
|
82
|
+
self.padding = padding
|
|
83
|
+
self.dilation = dilation
|
|
84
|
+
self.stride = stride
|
|
85
|
+
self.output_padding = output_padding
|
|
86
|
+
self.groups = groups
|
|
87
|
+
|
|
88
|
+
scale = math.sqrt(1 / (in_channels * kernel_size))
|
|
89
|
+
weight_init = mx.random.uniform(
|
|
90
|
+
low=-scale,
|
|
91
|
+
high=scale,
|
|
92
|
+
shape=(in_channels, kernel_size, out_channels // groups),
|
|
93
|
+
)
|
|
94
|
+
self.weight_g = normalize_weight(weight_init, except_dim=0)
|
|
95
|
+
self.weight_v = weight_init / (self.weight_g + 1e-12)
|
|
96
|
+
|
|
97
|
+
def _extra_repr(self):
|
|
98
|
+
return (
|
|
99
|
+
f"kernel_size={self.kernel_size}, stride={self.stride}, "
|
|
100
|
+
f"padding={self.padding}, dilation={self.dilation}, "
|
|
101
|
+
f"output_padding={self.output_padding}, "
|
|
102
|
+
f"groups={self.groups}, bias={self.bias is not None}"
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
def __call__(self, x):
|
|
106
|
+
weight = (
|
|
107
|
+
self.weight_g
|
|
108
|
+
* self.weight_v
|
|
109
|
+
/ normalize_weight(self.weight_v, except_dim=0)
|
|
110
|
+
)
|
|
111
|
+
y = mx.conv_transpose1d(
|
|
112
|
+
x,
|
|
113
|
+
weight.swapaxes(0, 2), # mlx uses (out_channels, kernel_size, in_channels)
|
|
114
|
+
self.stride,
|
|
115
|
+
self.padding,
|
|
116
|
+
self.dilation,
|
|
117
|
+
self.groups,
|
|
118
|
+
)
|
|
119
|
+
if self.bias is not None:
|
|
120
|
+
y = y + self.bias
|
|
121
|
+
return y
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def snake(x, alpha):
|
|
125
|
+
shape = x.shape
|
|
126
|
+
x = x.reshape(shape[0], shape[1], -1)
|
|
127
|
+
recip = mx.reciprocal(alpha + 1e-9)
|
|
128
|
+
x = x + recip * mx.power(mx.sin(alpha * x), 2)
|
|
129
|
+
x = x.reshape(shape)
|
|
130
|
+
return x
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
class Encoder(nn.Module):
|
|
134
|
+
def __init__(
|
|
135
|
+
self,
|
|
136
|
+
d_model=64,
|
|
137
|
+
strides=[3, 3, 7, 7],
|
|
138
|
+
depthwise=False,
|
|
139
|
+
attn_window_size=32,
|
|
140
|
+
):
|
|
141
|
+
super().__init__()
|
|
142
|
+
layers = [WNConv1d(1, d_model, kernel_size=7, padding=3)]
|
|
143
|
+
for stride in strides:
|
|
144
|
+
d_model *= 2
|
|
145
|
+
groups = d_model // 2 if depthwise else 1
|
|
146
|
+
layers += [EncoderBlock(output_dim=d_model, stride=stride, groups=groups)]
|
|
147
|
+
if attn_window_size is not None:
|
|
148
|
+
layers += [LocalMHA(dim=d_model, window_size=attn_window_size)]
|
|
149
|
+
groups = d_model if depthwise else 1
|
|
150
|
+
layers += [
|
|
151
|
+
WNConv1d(d_model, d_model, kernel_size=7, padding=3, groups=groups),
|
|
152
|
+
]
|
|
153
|
+
self.block = nn.Sequential(*layers)
|
|
154
|
+
|
|
155
|
+
def __call__(self, x):
|
|
156
|
+
return self.block(x).moveaxis(1, 2)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class Decoder(nn.Module):
|
|
160
|
+
def __init__(
|
|
161
|
+
self,
|
|
162
|
+
input_channel,
|
|
163
|
+
channels,
|
|
164
|
+
rates,
|
|
165
|
+
noise=False,
|
|
166
|
+
depthwise=False,
|
|
167
|
+
attn_window_size=32,
|
|
168
|
+
d_out=1,
|
|
169
|
+
):
|
|
170
|
+
super().__init__()
|
|
171
|
+
if depthwise:
|
|
172
|
+
layers = [
|
|
173
|
+
WNConv1d(
|
|
174
|
+
input_channel,
|
|
175
|
+
input_channel,
|
|
176
|
+
kernel_size=7,
|
|
177
|
+
padding=3,
|
|
178
|
+
groups=input_channel,
|
|
179
|
+
),
|
|
180
|
+
WNConv1d(input_channel, channels, kernel_size=1),
|
|
181
|
+
]
|
|
182
|
+
else:
|
|
183
|
+
layers = [WNConv1d(input_channel, channels, kernel_size=7, padding=3)]
|
|
184
|
+
|
|
185
|
+
if attn_window_size is not None:
|
|
186
|
+
layers += [LocalMHA(dim=channels, window_size=attn_window_size)]
|
|
187
|
+
|
|
188
|
+
for i, stride in enumerate(rates):
|
|
189
|
+
input_dim = channels // (2**i)
|
|
190
|
+
output_dim = channels // (2 ** (i + 1))
|
|
191
|
+
groups = output_dim if depthwise else 1
|
|
192
|
+
layers.append(
|
|
193
|
+
DecoderBlock(input_dim, output_dim, stride, noise, groups=groups)
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
layers += [
|
|
197
|
+
Snake1d(output_dim),
|
|
198
|
+
WNConv1d(output_dim, d_out, kernel_size=7, padding=3),
|
|
199
|
+
nn.Tanh(),
|
|
200
|
+
]
|
|
201
|
+
self.model = nn.Sequential(*layers)
|
|
202
|
+
|
|
203
|
+
def __call__(self, x):
|
|
204
|
+
x = self.model(x)
|
|
205
|
+
return x
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class ResidualUnit(nn.Module):
|
|
209
|
+
def __init__(self, dim=16, dilation=1, kernel=7, groups=1):
|
|
210
|
+
super().__init__()
|
|
211
|
+
pad = ((kernel - 1) * dilation) // 2
|
|
212
|
+
self.block = nn.Sequential(
|
|
213
|
+
Snake1d(dim),
|
|
214
|
+
WNConv1d(
|
|
215
|
+
dim,
|
|
216
|
+
dim,
|
|
217
|
+
kernel_size=kernel,
|
|
218
|
+
dilation=dilation,
|
|
219
|
+
padding=pad,
|
|
220
|
+
groups=groups,
|
|
221
|
+
),
|
|
222
|
+
Snake1d(dim),
|
|
223
|
+
WNConv1d(dim, dim, kernel_size=1),
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
def __call__(self, x):
|
|
227
|
+
y = self.block(x)
|
|
228
|
+
pad = (x.shape[-1] - y.shape[-1]) // 2
|
|
229
|
+
if pad > 0:
|
|
230
|
+
x = x[..., pad:-pad]
|
|
231
|
+
return x + y
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
class EncoderBlock(nn.Module):
|
|
235
|
+
def __init__(self, output_dim=16, input_dim=None, stride=1, groups=1):
|
|
236
|
+
super().__init__()
|
|
237
|
+
input_dim = input_dim or output_dim // 2
|
|
238
|
+
self.block = nn.Sequential(
|
|
239
|
+
ResidualUnit(input_dim, dilation=1, groups=groups),
|
|
240
|
+
ResidualUnit(input_dim, dilation=3, groups=groups),
|
|
241
|
+
ResidualUnit(input_dim, dilation=9, groups=groups),
|
|
242
|
+
Snake1d(input_dim),
|
|
243
|
+
WNConv1d(
|
|
244
|
+
input_dim,
|
|
245
|
+
output_dim,
|
|
246
|
+
kernel_size=2 * stride,
|
|
247
|
+
stride=stride,
|
|
248
|
+
padding=math.ceil(stride / 2),
|
|
249
|
+
),
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
def __call__(self, x):
|
|
253
|
+
return self.block(x)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
class NoiseBlock(nn.Module):
|
|
257
|
+
def __init__(self, dim):
|
|
258
|
+
super().__init__()
|
|
259
|
+
self.linear = WNConv1d(dim, dim, kernel_size=1, bias=False)
|
|
260
|
+
|
|
261
|
+
def __call__(self, x):
|
|
262
|
+
B, C, T = x.shape
|
|
263
|
+
noise = mx.random.normal((B, 1, T))
|
|
264
|
+
h = self.linear(x)
|
|
265
|
+
n = noise * h
|
|
266
|
+
x = x + n
|
|
267
|
+
return x
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
class DecoderBlock(nn.Module):
|
|
271
|
+
def __init__(self, input_dim=16, output_dim=8, stride=1, noise=False, groups=1):
|
|
272
|
+
super().__init__()
|
|
273
|
+
|
|
274
|
+
layers = [
|
|
275
|
+
Snake1d(input_dim),
|
|
276
|
+
WNConvTranspose1d(
|
|
277
|
+
input_dim,
|
|
278
|
+
output_dim,
|
|
279
|
+
kernel_size=2 * stride,
|
|
280
|
+
stride=stride,
|
|
281
|
+
padding=math.ceil(stride / 2),
|
|
282
|
+
output_padding=stride % 2,
|
|
283
|
+
),
|
|
284
|
+
]
|
|
285
|
+
if noise:
|
|
286
|
+
layers.append(NoiseBlock(output_dim))
|
|
287
|
+
layers.extend(
|
|
288
|
+
[
|
|
289
|
+
ResidualUnit(output_dim, dilation=1, groups=groups),
|
|
290
|
+
ResidualUnit(output_dim, dilation=3, groups=groups),
|
|
291
|
+
ResidualUnit(output_dim, dilation=9, groups=groups),
|
|
292
|
+
]
|
|
293
|
+
)
|
|
294
|
+
self.block = nn.Sequential(*layers)
|
|
295
|
+
|
|
296
|
+
def __call__(self, x):
|
|
297
|
+
return self.block(x)
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
class Snake1d(nn.Module):
|
|
301
|
+
def __init__(self, channels):
|
|
302
|
+
super().__init__()
|
|
303
|
+
self.alpha = mx.ones((1, channels, 1))
|
|
304
|
+
|
|
305
|
+
def __call__(self, x):
|
|
306
|
+
return snake(x, self.alpha.swapaxes(1, 2))
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import math
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import List, Tuple
|
|
5
|
+
|
|
6
|
+
import mlx.core as mx
|
|
7
|
+
import mlx.nn as nn
|
|
8
|
+
import numpy as np
|
|
9
|
+
from huggingface_hub import snapshot_download
|
|
10
|
+
|
|
11
|
+
from .layers import Decoder, Encoder
|
|
12
|
+
from .vq import ResidualVectorQuantize
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class SNAC(nn.Module):
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
sampling_rate=44100,
|
|
19
|
+
encoder_dim=64,
|
|
20
|
+
encoder_rates=[3, 3, 7, 7],
|
|
21
|
+
latent_dim=None,
|
|
22
|
+
decoder_dim=1536,
|
|
23
|
+
decoder_rates=[7, 7, 3, 3],
|
|
24
|
+
attn_window_size=32,
|
|
25
|
+
codebook_size=4096,
|
|
26
|
+
codebook_dim=8,
|
|
27
|
+
vq_strides=[8, 4, 2, 1],
|
|
28
|
+
noise=True,
|
|
29
|
+
depthwise=True,
|
|
30
|
+
):
|
|
31
|
+
super().__init__()
|
|
32
|
+
self.sampling_rate = sampling_rate
|
|
33
|
+
self.encoder_dim = encoder_dim
|
|
34
|
+
self.encoder_rates = encoder_rates
|
|
35
|
+
self.decoder_dim = decoder_dim
|
|
36
|
+
self.decoder_rates = decoder_rates
|
|
37
|
+
if latent_dim is None:
|
|
38
|
+
latent_dim = encoder_dim * (2 ** len(encoder_rates))
|
|
39
|
+
self.latent_dim = latent_dim
|
|
40
|
+
self.hop_length = np.prod(encoder_rates)
|
|
41
|
+
self.encoder = Encoder(
|
|
42
|
+
encoder_dim,
|
|
43
|
+
encoder_rates,
|
|
44
|
+
depthwise=depthwise,
|
|
45
|
+
attn_window_size=attn_window_size,
|
|
46
|
+
)
|
|
47
|
+
self.n_codebooks = len(vq_strides)
|
|
48
|
+
self.codebook_size = codebook_size
|
|
49
|
+
self.codebook_dim = codebook_dim
|
|
50
|
+
self.vq_strides = vq_strides
|
|
51
|
+
self.attn_window_size = attn_window_size
|
|
52
|
+
self.quantizer = ResidualVectorQuantize(
|
|
53
|
+
input_dim=latent_dim,
|
|
54
|
+
codebook_size=codebook_size,
|
|
55
|
+
codebook_dim=codebook_dim,
|
|
56
|
+
vq_strides=vq_strides,
|
|
57
|
+
)
|
|
58
|
+
self.decoder = Decoder(
|
|
59
|
+
latent_dim,
|
|
60
|
+
decoder_dim,
|
|
61
|
+
decoder_rates,
|
|
62
|
+
noise,
|
|
63
|
+
depthwise=depthwise,
|
|
64
|
+
attn_window_size=attn_window_size,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
def preprocess(self, audio_data):
|
|
68
|
+
length = audio_data.shape[-1]
|
|
69
|
+
|
|
70
|
+
def lcm(a, b):
|
|
71
|
+
return abs(a * b) // math.gcd(a, b)
|
|
72
|
+
|
|
73
|
+
lcm_value = self.vq_strides[0]
|
|
74
|
+
for i in range(1, len(self.vq_strides)):
|
|
75
|
+
lcm_value = lcm(lcm_value, self.vq_strides[i])
|
|
76
|
+
|
|
77
|
+
if self.attn_window_size:
|
|
78
|
+
lcm_value = lcm(lcm_value, self.attn_window_size)
|
|
79
|
+
|
|
80
|
+
pad_to = self.hop_length * lcm_value
|
|
81
|
+
right_pad = math.ceil(length / pad_to) * pad_to - length
|
|
82
|
+
|
|
83
|
+
# Pad the audio data
|
|
84
|
+
audio_data = mx.pad(audio_data, [(0, 0), (0, 0), (0, right_pad)])
|
|
85
|
+
return audio_data
|
|
86
|
+
|
|
87
|
+
def __call__(self, audio_data: mx.array) -> Tuple[mx.array, List[mx.array]]:
|
|
88
|
+
length = audio_data.shape[-1]
|
|
89
|
+
audio_data = self.preprocess(audio_data)
|
|
90
|
+
z = self.encoder(audio_data.moveaxis(1, 2))
|
|
91
|
+
z_q, codes = self.quantizer(z)
|
|
92
|
+
audio_hat = self.decoder(z_q)
|
|
93
|
+
return audio_hat[..., :length], codes
|
|
94
|
+
|
|
95
|
+
def encode(self, audio_data: mx.array) -> List[mx.array]:
|
|
96
|
+
audio_data = self.preprocess(audio_data)
|
|
97
|
+
z = self.encoder(audio_data.moveaxis(1, 2))
|
|
98
|
+
_, codes = self.quantizer(z)
|
|
99
|
+
return codes
|
|
100
|
+
|
|
101
|
+
def decode(self, codes: List[mx.array]) -> mx.array:
|
|
102
|
+
z_q = self.quantizer.from_codes(codes)
|
|
103
|
+
audio_hat = self.decoder(z_q.moveaxis(1, 2))
|
|
104
|
+
return audio_hat
|
|
105
|
+
|
|
106
|
+
def _extra_repr(self):
|
|
107
|
+
return (
|
|
108
|
+
f"sampling_rate={self.sampling_rate}, "
|
|
109
|
+
f"encoder_dim={self.encoder_dim}, "
|
|
110
|
+
f"encoder_rates={self.encoder_rates}, "
|
|
111
|
+
f"latent_dim={self.latent_dim}, "
|
|
112
|
+
f"decoder_dim={self.decoder_dim}, "
|
|
113
|
+
f"decoder_rates={self.decoder_rates}, "
|
|
114
|
+
f"codebook_size={self.codebook_size}, "
|
|
115
|
+
f"codebook_dim={self.codebook_dim}, "
|
|
116
|
+
f"vq_strides={self.vq_strides}"
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
@classmethod
|
|
120
|
+
def from_config(cls, config_path):
|
|
121
|
+
with open(config_path, "r") as f:
|
|
122
|
+
config = json.load(f)
|
|
123
|
+
model = cls(**config)
|
|
124
|
+
return model
|
|
125
|
+
|
|
126
|
+
@classmethod
|
|
127
|
+
def from_pretrained(cls, repo_id, **kwargs):
|
|
128
|
+
path = fetch_from_hub(repo_id)
|
|
129
|
+
|
|
130
|
+
if path is None:
|
|
131
|
+
raise ValueError(f"Could not find model {path}")
|
|
132
|
+
|
|
133
|
+
model_path = path / "model.safetensors"
|
|
134
|
+
config_path = path / "config.json"
|
|
135
|
+
snac = cls.from_config(config_path)
|
|
136
|
+
|
|
137
|
+
weights = mx.load(model_path.as_posix(), format="safetensors")
|
|
138
|
+
snac.load_weights(list(weights.items()))
|
|
139
|
+
mx.eval(snac.parameters())
|
|
140
|
+
|
|
141
|
+
return snac
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# fetch model from hub
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def fetch_from_hub(hf_repo: str) -> Path:
|
|
148
|
+
model_path = Path(
|
|
149
|
+
snapshot_download(
|
|
150
|
+
repo_id=hf_repo,
|
|
151
|
+
allow_patterns=["*.safetensors", "*.json"],
|
|
152
|
+
)
|
|
153
|
+
)
|
|
154
|
+
return model_path
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
import mlx.core as mx
|
|
4
|
+
import mlx.nn as nn
|
|
5
|
+
from einops.array_api import rearrange
|
|
6
|
+
|
|
7
|
+
from .layers import WNConv1d
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class VectorQuantize(nn.Module):
|
|
11
|
+
def __init__(
|
|
12
|
+
self, input_dim: int, codebook_size: int, codebook_dim: int, stride: int = 1
|
|
13
|
+
):
|
|
14
|
+
super().__init__()
|
|
15
|
+
self.codebook_size = codebook_size
|
|
16
|
+
self.codebook_dim = codebook_dim
|
|
17
|
+
self.stride = stride
|
|
18
|
+
|
|
19
|
+
self.in_proj = WNConv1d(input_dim, codebook_dim, kernel_size=1)
|
|
20
|
+
self.out_proj = WNConv1d(codebook_dim, input_dim, kernel_size=1)
|
|
21
|
+
self.codebook = nn.Embedding(codebook_size, codebook_dim)
|
|
22
|
+
|
|
23
|
+
def __call__(self, z):
|
|
24
|
+
z = z.moveaxis(1, 2)
|
|
25
|
+
|
|
26
|
+
if self.stride > 1:
|
|
27
|
+
kernel_size = self.stride
|
|
28
|
+
stride = self.stride
|
|
29
|
+
kernel = mx.ones((z.shape[2], kernel_size, 1)) / kernel_size
|
|
30
|
+
z = mx.conv1d(z, kernel, stride=stride, padding=0, groups=z.shape[2])
|
|
31
|
+
|
|
32
|
+
# Factorized codes - Project input into low-dimensional space
|
|
33
|
+
z_e = self.in_proj(z).moveaxis(1, 2) # z_e : (B x D x T)
|
|
34
|
+
z_q, indices = self.decode_latents(z_e)
|
|
35
|
+
|
|
36
|
+
# Straight-through estimator: z_e + stop_gradient(z_q - z_e)
|
|
37
|
+
z_q = z_e + (z_q - z_e)
|
|
38
|
+
|
|
39
|
+
z_q = self.out_proj(z_q.moveaxis(1, 2)).moveaxis(1, 2)
|
|
40
|
+
|
|
41
|
+
if self.stride > 1:
|
|
42
|
+
# Implement repeat_interleave
|
|
43
|
+
shape = list(z_q.shape)
|
|
44
|
+
shape[-1] *= self.stride
|
|
45
|
+
# Create a new tensor with the expanded shape
|
|
46
|
+
expanded = mx.zeros(shape)
|
|
47
|
+
|
|
48
|
+
# Fill the expanded tensor with repeated values
|
|
49
|
+
for i in range(self.stride):
|
|
50
|
+
expanded[..., i :: self.stride] = z_q
|
|
51
|
+
|
|
52
|
+
z_q = expanded
|
|
53
|
+
|
|
54
|
+
return z_q, indices
|
|
55
|
+
|
|
56
|
+
def embed_code(self, embed_id):
|
|
57
|
+
return self.codebook.weight[embed_id]
|
|
58
|
+
|
|
59
|
+
def decode_code(self, embed_id):
|
|
60
|
+
return self.embed_code(embed_id).moveaxis(1, 2)
|
|
61
|
+
|
|
62
|
+
def decode_latents(self, latents):
|
|
63
|
+
encodings = rearrange(latents, "b d t -> (b t) d")
|
|
64
|
+
codebook = self.codebook.weight # codebook: (N x D)
|
|
65
|
+
|
|
66
|
+
encodings = normalize(encodings)
|
|
67
|
+
codebook = normalize(codebook)
|
|
68
|
+
|
|
69
|
+
dist = (
|
|
70
|
+
mx.power(encodings, 2).sum(1, keepdims=True)
|
|
71
|
+
- 2 * encodings @ codebook.T
|
|
72
|
+
+ mx.power(codebook, 2).sum(1, keepdims=True).T
|
|
73
|
+
)
|
|
74
|
+
min_dist = (-dist).argmax(1)
|
|
75
|
+
indices = rearrange(min_dist, "(b t) -> b t", b=latents.shape[0])
|
|
76
|
+
z_q = self.decode_code(indices)
|
|
77
|
+
return z_q, indices
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class ResidualVectorQuantize(nn.Module):
|
|
81
|
+
def __init__(
|
|
82
|
+
self,
|
|
83
|
+
input_dim: int = 512,
|
|
84
|
+
codebook_size: int = 1024,
|
|
85
|
+
codebook_dim: int = 8,
|
|
86
|
+
vq_strides: List[int] = [1, 1, 1, 1],
|
|
87
|
+
):
|
|
88
|
+
super().__init__()
|
|
89
|
+
self.n_codebooks = len(vq_strides)
|
|
90
|
+
self.codebook_dim = codebook_dim
|
|
91
|
+
self.codebook_size = codebook_size
|
|
92
|
+
self.quantizers = [
|
|
93
|
+
VectorQuantize(input_dim, codebook_size, codebook_dim, stride)
|
|
94
|
+
for stride in vq_strides
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
def __call__(self, z):
|
|
98
|
+
z_q = 0
|
|
99
|
+
residual = z
|
|
100
|
+
codes = []
|
|
101
|
+
for i, quantizer in enumerate(self.quantizers):
|
|
102
|
+
z_q_i, indices_i = quantizer(residual)
|
|
103
|
+
z_q = z_q + z_q_i
|
|
104
|
+
residual = residual - z_q_i
|
|
105
|
+
codes.append(indices_i)
|
|
106
|
+
|
|
107
|
+
return z_q, codes
|
|
108
|
+
|
|
109
|
+
def from_codes(self, codes: List[mx.array]) -> mx.array:
|
|
110
|
+
z_q = 0.0
|
|
111
|
+
for i in range(self.n_codebooks):
|
|
112
|
+
z_p_i = self.quantizers[i].decode_code(codes[i])
|
|
113
|
+
z_q_i = self.quantizers[i].out_proj(z_p_i.moveaxis(1, 2)).moveaxis(1, 2)
|
|
114
|
+
|
|
115
|
+
# Handle repeat_interleave for stride > 1
|
|
116
|
+
if self.quantizers[i].stride > 1:
|
|
117
|
+
stride = self.quantizers[i].stride
|
|
118
|
+
shape = list(z_q_i.shape)
|
|
119
|
+
shape[-1] *= stride
|
|
120
|
+
expanded = mx.zeros(shape)
|
|
121
|
+
|
|
122
|
+
for j in range(stride):
|
|
123
|
+
expanded[..., j::stride] = z_q_i
|
|
124
|
+
|
|
125
|
+
z_q_i = expanded
|
|
126
|
+
|
|
127
|
+
z_q += z_q_i
|
|
128
|
+
|
|
129
|
+
return z_q
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def normalize(x, p=2.0, dim=1, eps=1e-12):
|
|
133
|
+
"""L2 normalization function"""
|
|
134
|
+
norm = mx.power(mx.sum(mx.power(mx.abs(x), p), axis=dim, keepdims=True), 1 / p)
|
|
135
|
+
return x / mx.maximum(norm, eps)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .vocos import Vocos
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
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 = 24_000,
|
|
11
|
+
n_mels: int = 100,
|
|
12
|
+
n_fft: int = 1024,
|
|
13
|
+
hop_length: int = 256,
|
|
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
|
+
freqs = stft(audio, window=hanning(n_fft), n_fft=n_fft, win_length=hop_length)
|
|
23
|
+
magnitudes = freqs[:-1, :].abs()
|
|
24
|
+
filters = mel_filters(
|
|
25
|
+
sample_rate=sample_rate,
|
|
26
|
+
n_fft=n_fft,
|
|
27
|
+
n_mels=n_mels,
|
|
28
|
+
norm=None,
|
|
29
|
+
mel_scale="htk",
|
|
30
|
+
)
|
|
31
|
+
mel_spec = magnitudes @ filters.T
|
|
32
|
+
log_spec = mx.maximum(mel_spec, 1e-5).log()
|
|
33
|
+
return mx.expand_dims(log_spec, axis=0)
|