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,228 @@
|
|
|
1
|
+
import math
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Union
|
|
5
|
+
|
|
6
|
+
import mlx.core as mx
|
|
7
|
+
import mlx.nn as nn
|
|
8
|
+
import numpy as np
|
|
9
|
+
import soundfile as sf
|
|
10
|
+
from einops.array_api import rearrange
|
|
11
|
+
|
|
12
|
+
SUPPORTED_VERSIONS = ["1.0.0"]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass
|
|
16
|
+
class DACFile:
|
|
17
|
+
codes: mx.array
|
|
18
|
+
|
|
19
|
+
# Metadata
|
|
20
|
+
chunk_length: int
|
|
21
|
+
original_length: int
|
|
22
|
+
input_db: float
|
|
23
|
+
channels: int
|
|
24
|
+
sample_rate: int
|
|
25
|
+
padding: bool
|
|
26
|
+
dac_version: str
|
|
27
|
+
|
|
28
|
+
def save(self, path):
|
|
29
|
+
artifacts = {
|
|
30
|
+
"codes": np.array(self.codes).astype(np.uint16),
|
|
31
|
+
"metadata": {
|
|
32
|
+
"input_db": self.input_db,
|
|
33
|
+
"original_length": self.original_length,
|
|
34
|
+
"sample_rate": self.sample_rate,
|
|
35
|
+
"chunk_length": self.chunk_length,
|
|
36
|
+
"channels": self.channels,
|
|
37
|
+
"padding": self.padding,
|
|
38
|
+
"dac_version": SUPPORTED_VERSIONS[-1],
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
path = Path(path).with_suffix(".dac")
|
|
42
|
+
with open(path, "wb") as f:
|
|
43
|
+
np.save(f, artifacts)
|
|
44
|
+
return path
|
|
45
|
+
|
|
46
|
+
@classmethod
|
|
47
|
+
def load(cls, path):
|
|
48
|
+
artifacts = np.load(path, allow_pickle=True)[()]
|
|
49
|
+
codes = mx.array(artifacts["codes"], dtype=mx.int32)
|
|
50
|
+
if artifacts["metadata"].get("dac_version", None) not in SUPPORTED_VERSIONS:
|
|
51
|
+
raise RuntimeError(
|
|
52
|
+
f"Given file {path} can't be loaded with this version of descript-audio-codec."
|
|
53
|
+
)
|
|
54
|
+
return cls(codes=codes, **artifacts["metadata"])
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class CodecMixin:
|
|
58
|
+
@property
|
|
59
|
+
def padding(self):
|
|
60
|
+
if not hasattr(self, "_padding"):
|
|
61
|
+
self._padding = True
|
|
62
|
+
return self._padding
|
|
63
|
+
|
|
64
|
+
@padding.setter
|
|
65
|
+
def padding(self, value):
|
|
66
|
+
assert isinstance(value, bool)
|
|
67
|
+
|
|
68
|
+
layers = [
|
|
69
|
+
layer
|
|
70
|
+
for layer in self.modules()
|
|
71
|
+
if isinstance(layer, (nn.Conv1d, nn.ConvTranspose1d))
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
for layer in layers:
|
|
75
|
+
if value:
|
|
76
|
+
if hasattr(layer, "original_padding"):
|
|
77
|
+
layer.padding = layer.original_padding
|
|
78
|
+
else:
|
|
79
|
+
layer.original_padding = layer.padding
|
|
80
|
+
layer.padding = tuple(0 for _ in range(len(layer.padding)))
|
|
81
|
+
|
|
82
|
+
self._padding = value
|
|
83
|
+
|
|
84
|
+
def get_delay(self):
|
|
85
|
+
l_out = self.get_output_length(0)
|
|
86
|
+
L = l_out
|
|
87
|
+
|
|
88
|
+
layers = []
|
|
89
|
+
for layer in self.modules():
|
|
90
|
+
if isinstance(layer, (nn.Conv1d, nn.ConvTranspose1d)):
|
|
91
|
+
layers.append(layer)
|
|
92
|
+
|
|
93
|
+
for layer in reversed(layers):
|
|
94
|
+
d = layer.dilation
|
|
95
|
+
k = layer.weight.shape[1]
|
|
96
|
+
s = layer.stride
|
|
97
|
+
|
|
98
|
+
if isinstance(layer, nn.ConvTranspose1d):
|
|
99
|
+
L = ((L - d * (k - 1) - 1) / s) + 1
|
|
100
|
+
elif isinstance(layer, nn.Conv1d):
|
|
101
|
+
L = (L - 1) * s + d * (k - 1) + 1
|
|
102
|
+
|
|
103
|
+
L = math.ceil(L)
|
|
104
|
+
|
|
105
|
+
l_in = L
|
|
106
|
+
|
|
107
|
+
return (l_in - l_out) // 2
|
|
108
|
+
|
|
109
|
+
def get_output_length(self, input_length):
|
|
110
|
+
L = input_length
|
|
111
|
+
for layer in self.modules():
|
|
112
|
+
if isinstance(layer, (nn.Conv1d, nn.ConvTranspose1d)):
|
|
113
|
+
d = layer.dilation
|
|
114
|
+
k = layer.weight.shape[1]
|
|
115
|
+
s = layer.stride
|
|
116
|
+
|
|
117
|
+
if isinstance(layer, nn.Conv1d):
|
|
118
|
+
L = ((L - d * (k - 1) - 1) / s) + 1
|
|
119
|
+
elif isinstance(layer, nn.ConvTranspose1d):
|
|
120
|
+
L = (L - 1) * s + d * (k - 1) + 1
|
|
121
|
+
|
|
122
|
+
L = math.floor(L)
|
|
123
|
+
return L
|
|
124
|
+
|
|
125
|
+
def compress(
|
|
126
|
+
self,
|
|
127
|
+
audio_path: Union[str, Path],
|
|
128
|
+
win_duration: float = 1.0,
|
|
129
|
+
normalize_db: float = -16,
|
|
130
|
+
n_quantizers: int = None,
|
|
131
|
+
) -> DACFile:
|
|
132
|
+
audio_signal, original_sr = sf.read(audio_path)
|
|
133
|
+
signal_duration = audio_signal.shape[-1] / original_sr
|
|
134
|
+
|
|
135
|
+
original_padding = self.padding
|
|
136
|
+
if original_sr != self.sample_rate:
|
|
137
|
+
raise ValueError(
|
|
138
|
+
f"Sample rate of the audio signal ({original_sr}) does not match the sample rate of the model ({self.sample_rate})."
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
audio_data = mx.array(audio_signal)
|
|
142
|
+
|
|
143
|
+
rms = mx.sqrt(mx.mean(mx.power(audio_data, 2), axis=-1) + 1e-12)
|
|
144
|
+
input_db = 20 * mx.log10(rms / 1.0 + 1e-12)
|
|
145
|
+
|
|
146
|
+
if normalize_db is not None:
|
|
147
|
+
audio_data = audio_data * mx.power(10, (normalize_db - input_db) / 20)
|
|
148
|
+
|
|
149
|
+
audio_data = rearrange(audio_data, "n -> 1 1 n")
|
|
150
|
+
nb, nac, nt = audio_data.shape
|
|
151
|
+
audio_data = rearrange(audio_data, "nb nac nt -> (nb nac) 1 nt")
|
|
152
|
+
|
|
153
|
+
win_duration = signal_duration if win_duration is None else win_duration
|
|
154
|
+
|
|
155
|
+
if signal_duration <= win_duration:
|
|
156
|
+
self.padding = True
|
|
157
|
+
n_samples = nt
|
|
158
|
+
hop = nt
|
|
159
|
+
else:
|
|
160
|
+
self.padding = False
|
|
161
|
+
audio_data = mx.pad(audio_data, [(0, 0), (0, 0), (self.delay, self.delay)])
|
|
162
|
+
|
|
163
|
+
n_samples = int(win_duration * self.sample_rate)
|
|
164
|
+
n_samples = int(math.ceil(n_samples / self.hop_length) * self.hop_length)
|
|
165
|
+
hop = self.get_output_length(n_samples)
|
|
166
|
+
|
|
167
|
+
codes = []
|
|
168
|
+
for i in range(0, nt, hop):
|
|
169
|
+
x = audio_data[..., i : i + n_samples]
|
|
170
|
+
x = mx.pad(x, [(0, 0), (0, 0), (0, max(0, n_samples - x.shape[-1]))])
|
|
171
|
+
|
|
172
|
+
x = self.preprocess(x, self.sample_rate)
|
|
173
|
+
_, c, _, _, _ = self.encode(x, n_quantizers)
|
|
174
|
+
codes.append(c)
|
|
175
|
+
chunk_length = c.shape[-1]
|
|
176
|
+
|
|
177
|
+
codes = mx.concatenate(codes, axis=-1)
|
|
178
|
+
|
|
179
|
+
dac_file = DACFile(
|
|
180
|
+
codes=codes,
|
|
181
|
+
chunk_length=chunk_length,
|
|
182
|
+
original_length=signal_duration,
|
|
183
|
+
input_db=input_db,
|
|
184
|
+
channels=nac,
|
|
185
|
+
sample_rate=original_sr,
|
|
186
|
+
padding=self.padding,
|
|
187
|
+
dac_version=SUPPORTED_VERSIONS[-1],
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
if n_quantizers is not None:
|
|
191
|
+
codes = codes[:, :n_quantizers, :]
|
|
192
|
+
|
|
193
|
+
self.padding = original_padding
|
|
194
|
+
return dac_file
|
|
195
|
+
|
|
196
|
+
def decompress(self, obj: Union[str, Path, DACFile]) -> mx.array:
|
|
197
|
+
if isinstance(obj, (str, Path)):
|
|
198
|
+
obj = DACFile.load(obj)
|
|
199
|
+
|
|
200
|
+
if self.sample_rate != obj.sample_rate:
|
|
201
|
+
raise ValueError(
|
|
202
|
+
f"Sample rate of the audio signal ({obj.sample_rate}) does not match the sample rate of the model ({self.sample_rate})."
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
original_padding = self.padding
|
|
206
|
+
self.padding = obj.padding
|
|
207
|
+
|
|
208
|
+
codes = obj.codes
|
|
209
|
+
chunk_length = obj.chunk_length
|
|
210
|
+
recons = []
|
|
211
|
+
|
|
212
|
+
for i in range(0, codes.shape[-1], chunk_length):
|
|
213
|
+
c = codes[..., i : i + chunk_length]
|
|
214
|
+
z = self.quantizer.from_codes(c)[0]
|
|
215
|
+
r = self.decode(z)
|
|
216
|
+
recons.append(r)
|
|
217
|
+
|
|
218
|
+
recons = mx.concatenate(recons, axis=1)
|
|
219
|
+
recons = rearrange(recons, "1 n 1 -> 1 n")
|
|
220
|
+
|
|
221
|
+
target_db = obj.input_db
|
|
222
|
+
normalize_db = -16
|
|
223
|
+
|
|
224
|
+
if normalize_db is not None:
|
|
225
|
+
recons = recons * mx.power(10, (target_db - normalize_db) / 20)
|
|
226
|
+
|
|
227
|
+
self.padding = original_padding
|
|
228
|
+
return recons
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import math
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import List, Literal, Union
|
|
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 .base import CodecMixin
|
|
12
|
+
from .nn.layers import Snake1d, WNConv1d, WNConvTranspose1d
|
|
13
|
+
from .nn.quantize import ResidualVectorQuantize
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ResidualUnit(nn.Module):
|
|
17
|
+
def __init__(self, dim: int = 16, dilation: int = 1):
|
|
18
|
+
super().__init__()
|
|
19
|
+
pad = ((7 - 1) * dilation) // 2
|
|
20
|
+
|
|
21
|
+
self.block = nn.Sequential(
|
|
22
|
+
Snake1d(dim),
|
|
23
|
+
WNConv1d(dim, dim, kernel_size=7, dilation=dilation, padding=pad),
|
|
24
|
+
Snake1d(dim),
|
|
25
|
+
WNConv1d(dim, dim, kernel_size=1),
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
def __call__(self, x):
|
|
29
|
+
y = self.block(x)
|
|
30
|
+
pad = (x.shape[-1] - y.shape[-1]) // 2
|
|
31
|
+
if pad > 0:
|
|
32
|
+
x = x[..., pad:-pad]
|
|
33
|
+
return x + y
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class EncoderBlock(nn.Module):
|
|
37
|
+
def __init__(self, dim: int = 16, stride: int = 1):
|
|
38
|
+
super().__init__()
|
|
39
|
+
self.block = nn.Sequential(
|
|
40
|
+
ResidualUnit(dim // 2, dilation=1),
|
|
41
|
+
ResidualUnit(dim // 2, dilation=3),
|
|
42
|
+
ResidualUnit(dim // 2, dilation=9),
|
|
43
|
+
Snake1d(dim // 2),
|
|
44
|
+
WNConv1d(
|
|
45
|
+
dim // 2,
|
|
46
|
+
dim,
|
|
47
|
+
kernel_size=2 * stride,
|
|
48
|
+
stride=stride,
|
|
49
|
+
padding=math.ceil(stride / 2),
|
|
50
|
+
),
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
def __call__(self, x):
|
|
54
|
+
return self.block(x)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class Encoder(nn.Module):
|
|
58
|
+
def __init__(
|
|
59
|
+
self,
|
|
60
|
+
d_model: int = 64,
|
|
61
|
+
strides: list = [2, 4, 8, 8],
|
|
62
|
+
d_latent: int = 64,
|
|
63
|
+
):
|
|
64
|
+
super().__init__()
|
|
65
|
+
self.block = [WNConv1d(1, d_model, kernel_size=7, padding=3)]
|
|
66
|
+
|
|
67
|
+
for stride in strides:
|
|
68
|
+
d_model *= 2
|
|
69
|
+
self.block += [EncoderBlock(d_model, stride=stride)]
|
|
70
|
+
|
|
71
|
+
self.block += [
|
|
72
|
+
Snake1d(d_model),
|
|
73
|
+
WNConv1d(d_model, d_latent, kernel_size=3, padding=1),
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
self.block = nn.Sequential(*self.block)
|
|
77
|
+
self.enc_dim = d_model
|
|
78
|
+
|
|
79
|
+
def __call__(self, x):
|
|
80
|
+
return self.block(x).moveaxis(1, 2)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class DecoderBlock(nn.Module):
|
|
84
|
+
def __init__(self, input_dim: int = 16, output_dim: int = 8, stride: int = 1):
|
|
85
|
+
super().__init__()
|
|
86
|
+
self.block = nn.Sequential(
|
|
87
|
+
Snake1d(input_dim),
|
|
88
|
+
WNConvTranspose1d(
|
|
89
|
+
input_dim,
|
|
90
|
+
output_dim,
|
|
91
|
+
kernel_size=2 * stride,
|
|
92
|
+
stride=stride,
|
|
93
|
+
padding=math.ceil(stride / 2),
|
|
94
|
+
),
|
|
95
|
+
ResidualUnit(output_dim, dilation=1),
|
|
96
|
+
ResidualUnit(output_dim, dilation=3),
|
|
97
|
+
ResidualUnit(output_dim, dilation=9),
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
def __call__(self, x):
|
|
101
|
+
return self.block(x)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class Decoder(nn.Module):
|
|
105
|
+
def __init__(
|
|
106
|
+
self,
|
|
107
|
+
input_channel,
|
|
108
|
+
channels,
|
|
109
|
+
rates,
|
|
110
|
+
d_out: int = 1,
|
|
111
|
+
):
|
|
112
|
+
super().__init__()
|
|
113
|
+
layers = [WNConv1d(input_channel, channels, kernel_size=7, padding=3)]
|
|
114
|
+
|
|
115
|
+
for i, stride in enumerate(rates):
|
|
116
|
+
input_dim = channels // 2**i
|
|
117
|
+
output_dim = channels // 2 ** (i + 1)
|
|
118
|
+
layers += [DecoderBlock(input_dim, output_dim, stride)]
|
|
119
|
+
|
|
120
|
+
layers += [
|
|
121
|
+
Snake1d(output_dim),
|
|
122
|
+
WNConv1d(output_dim, d_out, kernel_size=7, padding=3),
|
|
123
|
+
nn.Tanh(),
|
|
124
|
+
]
|
|
125
|
+
|
|
126
|
+
self.model = nn.Sequential(*layers)
|
|
127
|
+
|
|
128
|
+
def __call__(self, x):
|
|
129
|
+
return self.model(x)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
class DAC(nn.Module, CodecMixin):
|
|
133
|
+
def __init__(
|
|
134
|
+
self,
|
|
135
|
+
encoder_dim: int = 64,
|
|
136
|
+
encoder_rates: List[int] = [2, 4, 5, 8],
|
|
137
|
+
latent_dim: int = None,
|
|
138
|
+
decoder_dim: int = 1536,
|
|
139
|
+
decoder_rates: List[int] = [8, 5, 4, 2],
|
|
140
|
+
n_codebooks: int = 32,
|
|
141
|
+
codebook_size: int = 1024,
|
|
142
|
+
codebook_dim: Union[int, list] = 8,
|
|
143
|
+
sample_rate: int = 44100,
|
|
144
|
+
**kwargs,
|
|
145
|
+
):
|
|
146
|
+
super().__init__()
|
|
147
|
+
|
|
148
|
+
self.encoder_dim = encoder_dim
|
|
149
|
+
self.encoder_rates = encoder_rates
|
|
150
|
+
self.decoder_dim = decoder_dim
|
|
151
|
+
self.decoder_rates = decoder_rates
|
|
152
|
+
self.sample_rate = sample_rate
|
|
153
|
+
|
|
154
|
+
if latent_dim is None:
|
|
155
|
+
latent_dim = encoder_dim * (2 ** len(encoder_rates))
|
|
156
|
+
|
|
157
|
+
self.latent_dim = latent_dim
|
|
158
|
+
|
|
159
|
+
self.hop_length = np.prod(encoder_rates)
|
|
160
|
+
self.encoder = Encoder(encoder_dim, encoder_rates, latent_dim)
|
|
161
|
+
|
|
162
|
+
self.n_codebooks = n_codebooks
|
|
163
|
+
self.codebook_size = codebook_size
|
|
164
|
+
self.codebook_dim = codebook_dim
|
|
165
|
+
self.quantizer = ResidualVectorQuantize(
|
|
166
|
+
input_dim=latent_dim,
|
|
167
|
+
n_codebooks=n_codebooks,
|
|
168
|
+
codebook_size=codebook_size,
|
|
169
|
+
codebook_dim=codebook_dim,
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
self.decoder = Decoder(
|
|
173
|
+
latent_dim,
|
|
174
|
+
decoder_dim,
|
|
175
|
+
decoder_rates,
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
self.sample_rate = sample_rate
|
|
179
|
+
|
|
180
|
+
self.delay = self.get_delay()
|
|
181
|
+
|
|
182
|
+
def preprocess(self, audio_data, sample_rate):
|
|
183
|
+
if sample_rate is None:
|
|
184
|
+
sample_rate = self.sample_rate
|
|
185
|
+
assert sample_rate == self.sample_rate
|
|
186
|
+
|
|
187
|
+
length = audio_data.shape[-1]
|
|
188
|
+
right_pad = math.ceil(length / self.hop_length) * self.hop_length - length
|
|
189
|
+
audio_data = mx.pad(audio_data, [(0, 0), (0, 0), (0, right_pad)])
|
|
190
|
+
|
|
191
|
+
return audio_data
|
|
192
|
+
|
|
193
|
+
def encode(
|
|
194
|
+
self,
|
|
195
|
+
audio_data: mx.array,
|
|
196
|
+
n_quantizers: int = None,
|
|
197
|
+
):
|
|
198
|
+
z = self.encoder(audio_data.moveaxis(1, 2))
|
|
199
|
+
z, codes, latents, commitment_loss, codebook_loss = self.quantizer(
|
|
200
|
+
z, n_quantizers
|
|
201
|
+
)
|
|
202
|
+
return z, codes, latents, commitment_loss, codebook_loss
|
|
203
|
+
|
|
204
|
+
def decode(self, z: mx.array):
|
|
205
|
+
return self.decoder(z.moveaxis(1, 2))
|
|
206
|
+
|
|
207
|
+
def _extra_repr(self):
|
|
208
|
+
return (
|
|
209
|
+
f"encoder_dim={self.encoder_dim}, "
|
|
210
|
+
f"encoder_rates={self.encoder_rates}, "
|
|
211
|
+
f"latent_dim={self.latent_dim}, "
|
|
212
|
+
f"decoder_dim={self.decoder_dim}, "
|
|
213
|
+
f"decoder_rates={self.decoder_rates}, "
|
|
214
|
+
f"n_codebooks={self.n_codebooks}, "
|
|
215
|
+
f"codebook_size={self.codebook_size}, "
|
|
216
|
+
f"codebook_dim={self.codebook_dim}"
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
def __call__(
|
|
220
|
+
self,
|
|
221
|
+
audio_data: mx.array,
|
|
222
|
+
sample_rate: int = None,
|
|
223
|
+
n_quantizers: int = None,
|
|
224
|
+
use_rvq: bool = True,
|
|
225
|
+
return_loss: bool = False,
|
|
226
|
+
):
|
|
227
|
+
length = audio_data.shape[-1]
|
|
228
|
+
audio_data = self.preprocess(audio_data, sample_rate)
|
|
229
|
+
|
|
230
|
+
if use_rvq:
|
|
231
|
+
z, codes, latents, commitment_loss, codebook_loss = self.encode(
|
|
232
|
+
audio_data, n_quantizers
|
|
233
|
+
)
|
|
234
|
+
else:
|
|
235
|
+
z = self.encoder(audio_data.moveaxis(1, 2))
|
|
236
|
+
|
|
237
|
+
x = self.decode(z)
|
|
238
|
+
|
|
239
|
+
if return_loss:
|
|
240
|
+
return mx.losses.mse(x, audio_data)
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
"audio": x[..., :length],
|
|
244
|
+
"z": z,
|
|
245
|
+
"codes": codes,
|
|
246
|
+
"latents": latents,
|
|
247
|
+
"vq/commitment_loss": commitment_loss,
|
|
248
|
+
"vq/codebook_loss": codebook_loss,
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
@classmethod
|
|
252
|
+
def from_pretrained(
|
|
253
|
+
cls,
|
|
254
|
+
repo_id: str,
|
|
255
|
+
) -> "DAC":
|
|
256
|
+
path = fetch_from_hub(repo_id)
|
|
257
|
+
if path is None:
|
|
258
|
+
raise ValueError(f"Could not find model {path}")
|
|
259
|
+
|
|
260
|
+
model_path = path / "model.safetensors"
|
|
261
|
+
config_path = path / "config.json"
|
|
262
|
+
|
|
263
|
+
with open(config_path) as f:
|
|
264
|
+
config = json.load(f)
|
|
265
|
+
|
|
266
|
+
dac = DAC(**config)
|
|
267
|
+
|
|
268
|
+
weights = mx.load(model_path.as_posix(), format="safetensors")
|
|
269
|
+
dac.load_weights(list(weights.items()))
|
|
270
|
+
mx.eval(dac.parameters())
|
|
271
|
+
|
|
272
|
+
return dac
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
# fetch model from hub
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def fetch_from_hub(hf_repo: str) -> Path:
|
|
279
|
+
model_path = Path(
|
|
280
|
+
snapshot_download(
|
|
281
|
+
repo_id=hf_repo,
|
|
282
|
+
allow_patterns=["*.safetensors", "*.json"],
|
|
283
|
+
)
|
|
284
|
+
)
|
|
285
|
+
return model_path
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from . import layers, quantize
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import math
|
|
2
|
+
|
|
3
|
+
import mlx.core as mx
|
|
4
|
+
import mlx.nn as nn
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def normalize_weight(x, except_dim=0):
|
|
8
|
+
if x.ndim != 3:
|
|
9
|
+
raise ValueError("Input tensor must have 3 dimensions")
|
|
10
|
+
|
|
11
|
+
axes = tuple(i for i in range(x.ndim) if i != except_dim)
|
|
12
|
+
return mx.sqrt(mx.sum(mx.power(x, 2), axis=axes, keepdims=True))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class WNConv1d(nn.Module):
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
in_channels: int,
|
|
19
|
+
out_channels: int,
|
|
20
|
+
kernel_size: int,
|
|
21
|
+
stride: int = 1,
|
|
22
|
+
padding: int = 0,
|
|
23
|
+
dilation: int = 1,
|
|
24
|
+
bias: bool = True,
|
|
25
|
+
groups: int = 1,
|
|
26
|
+
):
|
|
27
|
+
super().__init__()
|
|
28
|
+
|
|
29
|
+
if bias:
|
|
30
|
+
self.bias = mx.zeros((out_channels,))
|
|
31
|
+
|
|
32
|
+
self.kernel_size = kernel_size
|
|
33
|
+
self.padding = padding
|
|
34
|
+
self.dilation = dilation
|
|
35
|
+
self.stride = stride
|
|
36
|
+
self.groups = groups
|
|
37
|
+
|
|
38
|
+
scale = math.sqrt(1 / (in_channels * kernel_size))
|
|
39
|
+
weight_init = mx.random.uniform(
|
|
40
|
+
low=-scale,
|
|
41
|
+
high=scale,
|
|
42
|
+
shape=(out_channels, kernel_size, in_channels),
|
|
43
|
+
)
|
|
44
|
+
self.weight_g = normalize_weight(weight_init)
|
|
45
|
+
self.weight_v = weight_init / (self.weight_g + 1e-12)
|
|
46
|
+
|
|
47
|
+
def _extra_repr(self):
|
|
48
|
+
return (
|
|
49
|
+
f"in_channels={self.weight_v.shape[2]}, out_channels={self.weight_v.shape[0]}, "
|
|
50
|
+
f"kernel_size={self.kernel_size}, stride={self.stride}, "
|
|
51
|
+
f"padding={self.padding}, dilation={self.dilation}, "
|
|
52
|
+
f"bias={'bias' in self}"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
def __call__(self, x):
|
|
56
|
+
weight = self.weight_g * self.weight_v / normalize_weight(self.weight_v)
|
|
57
|
+
y = mx.conv1d(x, weight, self.stride, self.padding, self.dilation, self.groups)
|
|
58
|
+
if "bias" in self:
|
|
59
|
+
y = y + self.bias
|
|
60
|
+
return y
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class WNConvTranspose1d(nn.Module):
|
|
64
|
+
def __init__(
|
|
65
|
+
self,
|
|
66
|
+
in_channels: int,
|
|
67
|
+
out_channels: int,
|
|
68
|
+
kernel_size: int,
|
|
69
|
+
stride: int = 1,
|
|
70
|
+
padding: int = 0,
|
|
71
|
+
dilation: int = 1,
|
|
72
|
+
groups: int = 1,
|
|
73
|
+
bias: bool = True,
|
|
74
|
+
):
|
|
75
|
+
super().__init__()
|
|
76
|
+
|
|
77
|
+
self.bias = mx.zeros((out_channels,)) if bias else None
|
|
78
|
+
|
|
79
|
+
self.kernel_size = kernel_size
|
|
80
|
+
self.padding = padding
|
|
81
|
+
self.dilation = dilation
|
|
82
|
+
self.stride = stride
|
|
83
|
+
self.groups = groups
|
|
84
|
+
|
|
85
|
+
scale = math.sqrt(1 / (in_channels * kernel_size))
|
|
86
|
+
weight_init = mx.random.uniform(
|
|
87
|
+
low=-scale,
|
|
88
|
+
high=scale,
|
|
89
|
+
shape=(out_channels, kernel_size, in_channels // groups),
|
|
90
|
+
)
|
|
91
|
+
self.weight_g = normalize_weight(weight_init, except_dim=2)
|
|
92
|
+
self.weight_v = weight_init / (self.weight_g + 1e-12)
|
|
93
|
+
|
|
94
|
+
def _extra_repr(self):
|
|
95
|
+
return (
|
|
96
|
+
f"in_channels={self.weight_v.shape[2] * self.groups}, out_channels={self.weight_v.shape[0]}, "
|
|
97
|
+
f"kernel_size={self.kernel_size}, stride={self.stride}, "
|
|
98
|
+
f"padding={self.padding}, dilation={self.dilation}, "
|
|
99
|
+
f"groups={self.groups}, bias={'bias' in self}"
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
def __call__(self, x):
|
|
103
|
+
weight = (
|
|
104
|
+
self.weight_g
|
|
105
|
+
* self.weight_v
|
|
106
|
+
/ normalize_weight(self.weight_v, except_dim=2)
|
|
107
|
+
)
|
|
108
|
+
y = mx.conv_transpose1d(
|
|
109
|
+
x, weight, self.stride, self.padding, self.dilation, self.groups
|
|
110
|
+
)
|
|
111
|
+
if self.bias is not None:
|
|
112
|
+
y = y + self.bias
|
|
113
|
+
return y
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def snake(x, alpha):
|
|
117
|
+
recip = mx.reciprocal(alpha + 1e-9)
|
|
118
|
+
x = x + recip * mx.power(mx.sin(alpha * x), 2)
|
|
119
|
+
return x
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class Snake1d(nn.Module):
|
|
123
|
+
def __init__(self, channels):
|
|
124
|
+
super().__init__()
|
|
125
|
+
self.alpha = mx.ones((1, 1, channels))
|
|
126
|
+
|
|
127
|
+
def __call__(self, x):
|
|
128
|
+
x = snake(x, self.alpha)
|
|
129
|
+
return x
|