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,105 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
|
|
3
|
+
import mlx.core as mx
|
|
4
|
+
import numpy as np
|
|
5
|
+
import silentcipher
|
|
6
|
+
import soundfile as sf
|
|
7
|
+
from scipy import signal
|
|
8
|
+
|
|
9
|
+
# This watermark key is public, it is not secure.
|
|
10
|
+
# If using CSM 1B in another application, use a new private key and keep it secret.
|
|
11
|
+
CSM_1B_GH_WATERMARK = [212, 211, 146, 56, 201]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def cli_check_audio() -> None:
|
|
15
|
+
parser = argparse.ArgumentParser()
|
|
16
|
+
parser.add_argument("--audio_path", type=str, required=True)
|
|
17
|
+
args = parser.parse_args()
|
|
18
|
+
check_audio_from_file(args.audio_path)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def load_watermarker() -> silentcipher.server.Model:
|
|
22
|
+
model = silentcipher.get_model(
|
|
23
|
+
model_type="44.1k",
|
|
24
|
+
)
|
|
25
|
+
return model
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def resample_audio(audio: np.ndarray, orig_sr: int, target_sr: int) -> np.ndarray:
|
|
29
|
+
gcd = np.gcd(orig_sr, target_sr)
|
|
30
|
+
up = target_sr // gcd
|
|
31
|
+
down = orig_sr // gcd
|
|
32
|
+
resampled = signal.resample_poly(audio, up, down, padtype="edge")
|
|
33
|
+
return resampled
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def watermark(
|
|
37
|
+
watermarker: silentcipher.server.Model,
|
|
38
|
+
audio_array: mx.array,
|
|
39
|
+
sample_rate: int,
|
|
40
|
+
watermark_key: list[int],
|
|
41
|
+
) -> tuple[mx.array, int]:
|
|
42
|
+
audio_array = np.array(audio_array, dtype=np.float32)
|
|
43
|
+
|
|
44
|
+
if sample_rate != 44100:
|
|
45
|
+
audio_array_44khz = resample_audio(audio_array, sample_rate, 44100)
|
|
46
|
+
else:
|
|
47
|
+
audio_array_44khz = audio_array
|
|
48
|
+
|
|
49
|
+
encoded, *_ = watermarker.encode_wav(
|
|
50
|
+
audio_array_44khz, 44100, watermark_key, calc_sdr=False, message_sdr=36
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
if sample_rate != 44100:
|
|
54
|
+
encoded = resample_audio(encoded, 44100, sample_rate)
|
|
55
|
+
|
|
56
|
+
return encoded
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def verify(
|
|
60
|
+
watermarker: silentcipher.server.Model,
|
|
61
|
+
watermarked_audio: mx.array,
|
|
62
|
+
sample_rate: int,
|
|
63
|
+
watermark_key: list[int],
|
|
64
|
+
) -> bool:
|
|
65
|
+
if sample_rate != 44100:
|
|
66
|
+
watermarked_audio_44khz = resample_audio(watermarked_audio, sample_rate, 44100)
|
|
67
|
+
else:
|
|
68
|
+
watermarked_audio_44khz = watermarked_audio
|
|
69
|
+
|
|
70
|
+
result = watermarker.decode_wav(
|
|
71
|
+
watermarked_audio_44khz, 44100, phase_shift_decoding=True
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
is_watermarked = result["status"]
|
|
75
|
+
if is_watermarked:
|
|
76
|
+
is_csm_watermarked = result["messages"][0] == watermark_key
|
|
77
|
+
else:
|
|
78
|
+
is_csm_watermarked = False
|
|
79
|
+
|
|
80
|
+
return is_watermarked and is_csm_watermarked
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def check_audio_from_file(audio_path: str) -> None:
|
|
84
|
+
watermarker = load_watermarker()
|
|
85
|
+
audio_array, sample_rate = load_audio(audio_path)
|
|
86
|
+
is_watermarked = verify(watermarker, audio_array, sample_rate, CSM_1B_GH_WATERMARK)
|
|
87
|
+
outcome = "Watermarked" if is_watermarked else "Not watermarked"
|
|
88
|
+
print(f"{outcome}: {audio_path}")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def load_audio(audio_path: str) -> tuple[mx.array, int]:
|
|
92
|
+
audio_array_np, sample_rate = sf.read(audio_path, always_2d=True)
|
|
93
|
+
|
|
94
|
+
if audio_array_np.shape[1] > 1:
|
|
95
|
+
audio_array_np = audio_array_np.mean(axis=1)
|
|
96
|
+
else:
|
|
97
|
+
audio_array_np = audio_array_np.squeeze()
|
|
98
|
+
|
|
99
|
+
audio_array = mx.array(audio_array_np)
|
|
100
|
+
|
|
101
|
+
return audio_array, int(sample_rate)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
if __name__ == "__main__":
|
|
105
|
+
cli_check_audio()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .spark import Model, ModelConfig
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Any, Dict, Tuple, Union
|
|
3
|
+
|
|
4
|
+
import mlx.core as mx
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
from mlx_audio.stt.models.wav2vec.feature_extractor import Wav2Vec2FeatureExtractor
|
|
8
|
+
from mlx_audio.stt.models.wav2vec.wav2vec import Wav2Vec2Model
|
|
9
|
+
|
|
10
|
+
from .bicodec import BiCodec
|
|
11
|
+
from .utils.audio import load_audio
|
|
12
|
+
from .utils.file import load_config
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class BiCodecTokenizer:
|
|
16
|
+
"""BiCodec tokenizer for handling audio input and tokenization."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, model_dir: Path, **kwargs):
|
|
19
|
+
super().__init__()
|
|
20
|
+
"""
|
|
21
|
+
Args:
|
|
22
|
+
model_dir: Path to the model directory.
|
|
23
|
+
device: Device to run the model on (default is GPU if available).
|
|
24
|
+
"""
|
|
25
|
+
self.model_dir = model_dir
|
|
26
|
+
self.config = load_config(f"{model_dir}/audio_tokenizer_config.yaml")
|
|
27
|
+
self._initialize_model()
|
|
28
|
+
|
|
29
|
+
def _initialize_model(self):
|
|
30
|
+
"""Load and initialize the BiCodec model and Wav2Vec2 feature extractor."""
|
|
31
|
+
self.model = BiCodec.load_from_checkpoint(f"{self.model_dir}/BiCodec")
|
|
32
|
+
self.processor = Wav2Vec2FeatureExtractor.from_pretrained(
|
|
33
|
+
f"{self.model_dir}/wav2vec2-large-xlsr-53"
|
|
34
|
+
)
|
|
35
|
+
self.feature_extractor = Wav2Vec2Model.from_pretrained(
|
|
36
|
+
f"{self.model_dir}/wav2vec2-large-xlsr-53"
|
|
37
|
+
)
|
|
38
|
+
self.feature_extractor.config.output_hidden_states = True
|
|
39
|
+
|
|
40
|
+
def get_ref_clip(self, wav: np.ndarray) -> np.ndarray:
|
|
41
|
+
"""Get reference audio clip for speaker embedding."""
|
|
42
|
+
ref_segment_length = (
|
|
43
|
+
int(self.config["sample_rate"] * self.config["ref_segment_duration"])
|
|
44
|
+
// self.config["latent_hop_length"]
|
|
45
|
+
* self.config["latent_hop_length"]
|
|
46
|
+
)
|
|
47
|
+
wav_length = len(wav)
|
|
48
|
+
|
|
49
|
+
if ref_segment_length > wav_length:
|
|
50
|
+
# Repeat and truncate to handle insufficient length
|
|
51
|
+
wav = np.tile(wav, ref_segment_length // wav_length + 1)
|
|
52
|
+
|
|
53
|
+
return wav[:ref_segment_length]
|
|
54
|
+
|
|
55
|
+
def process_audio(
|
|
56
|
+
self, wav_path: Union[Path, mx.array]
|
|
57
|
+
) -> Tuple[np.ndarray, mx.array]:
|
|
58
|
+
"""load auido and get reference audio from wav path"""
|
|
59
|
+
if isinstance(wav_path, Path) or isinstance(wav_path, str):
|
|
60
|
+
wav = load_audio(
|
|
61
|
+
wav_path,
|
|
62
|
+
sampling_rate=self.config["sample_rate"],
|
|
63
|
+
volume_normalize=self.config["volume_normalize"],
|
|
64
|
+
)
|
|
65
|
+
elif isinstance(wav_path, mx.array):
|
|
66
|
+
wav = wav_path
|
|
67
|
+
else:
|
|
68
|
+
raise ValueError(f"Invalid input type: {type(wav_path)}")
|
|
69
|
+
|
|
70
|
+
wav_ref = self.get_ref_clip(wav)
|
|
71
|
+
|
|
72
|
+
return wav, wav_ref[None, ...]
|
|
73
|
+
|
|
74
|
+
def extract_wav2vec2_features(self, wavs: mx.array) -> mx.array:
|
|
75
|
+
"""extract wav2vec2 features"""
|
|
76
|
+
inputs = self.processor(
|
|
77
|
+
wavs,
|
|
78
|
+
sampling_rate=16000,
|
|
79
|
+
return_tensors="mx",
|
|
80
|
+
padding=True,
|
|
81
|
+
output_hidden_states=True,
|
|
82
|
+
)["input_values"]
|
|
83
|
+
feat = self.feature_extractor(inputs)
|
|
84
|
+
feats_mix = (
|
|
85
|
+
feat.hidden_states[11] + feat.hidden_states[14] + feat.hidden_states[16]
|
|
86
|
+
) / 3
|
|
87
|
+
|
|
88
|
+
return feats_mix
|
|
89
|
+
|
|
90
|
+
def tokenize_batch(self, batch: Dict[str, Any]) -> Tuple[mx.array, mx.array]:
|
|
91
|
+
"""tokenize the batch of audio
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
batch:
|
|
95
|
+
wavs (List[np.ndarray]): batch of audio
|
|
96
|
+
ref_wavs (mx.array): reference audio. shape: (batch_size, seq_len)
|
|
97
|
+
|
|
98
|
+
Returns:
|
|
99
|
+
semantic_tokens: semantic tokens. shape: (batch_size, seq_len, latent_dim)
|
|
100
|
+
global_tokens: global tokens. shape: (batch_size, seq_len, global_dim)
|
|
101
|
+
"""
|
|
102
|
+
feats = self.extract_wav2vec2_features(batch["wav"])
|
|
103
|
+
batch["feat"] = feats
|
|
104
|
+
|
|
105
|
+
semantic_tokens, global_tokens = self.model.tokenize(batch)
|
|
106
|
+
|
|
107
|
+
return global_tokens, semantic_tokens
|
|
108
|
+
|
|
109
|
+
def tokenize(self, audio_path: str) -> Tuple[mx.array, mx.array]:
|
|
110
|
+
"""tokenize the audio"""
|
|
111
|
+
wav, ref_wav = self.process_audio(audio_path)
|
|
112
|
+
feat = self.extract_wav2vec2_features(wav)
|
|
113
|
+
batch = {
|
|
114
|
+
"wav": wav[None, ...],
|
|
115
|
+
"ref_wav": ref_wav,
|
|
116
|
+
"feat": feat,
|
|
117
|
+
}
|
|
118
|
+
semantic_tokens, global_tokens = self.model.tokenize(batch)
|
|
119
|
+
|
|
120
|
+
return global_tokens, semantic_tokens
|
|
121
|
+
|
|
122
|
+
def detokenize(
|
|
123
|
+
self, global_tokens: mx.array, semantic_tokens: mx.array
|
|
124
|
+
) -> np.array:
|
|
125
|
+
"""detokenize the tokens to waveform
|
|
126
|
+
|
|
127
|
+
Args:
|
|
128
|
+
global_tokens: global tokens. shape: (batch_size, global_dim)
|
|
129
|
+
semantic_tokens: semantic tokens. shape: (batch_size, latent_dim)
|
|
130
|
+
|
|
131
|
+
Returns:
|
|
132
|
+
wav_rec: waveform. shape: (batch_size, seq_len) for batch or (seq_len,) for single
|
|
133
|
+
"""
|
|
134
|
+
global_tokens = mx.expand_dims(global_tokens, 1)
|
|
135
|
+
|
|
136
|
+
# convert to mlx array
|
|
137
|
+
wav_rec = self.model.detokenize(semantic_tokens, global_tokens)
|
|
138
|
+
return wav_rec.squeeze()
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Any, Dict, Optional
|
|
3
|
+
|
|
4
|
+
import mlx.core as mx
|
|
5
|
+
import mlx.nn as nn
|
|
6
|
+
import numpy as np
|
|
7
|
+
from omegaconf import DictConfig
|
|
8
|
+
from safetensors.torch import load_file
|
|
9
|
+
|
|
10
|
+
from mlx_audio.tts.models.spark.modules.encoder_decoder.feat_decoder import Decoder
|
|
11
|
+
from mlx_audio.tts.models.spark.modules.encoder_decoder.feat_encoder import Encoder
|
|
12
|
+
from mlx_audio.tts.models.spark.modules.encoder_decoder.wave_generator import (
|
|
13
|
+
WaveGenerator,
|
|
14
|
+
)
|
|
15
|
+
from mlx_audio.tts.models.spark.modules.residual import FactorizedVectorQuantize
|
|
16
|
+
from mlx_audio.tts.models.spark.modules.speaker.speaker_encoder import SpeakerEncoder
|
|
17
|
+
from mlx_audio.tts.models.spark.utils.file import load_config
|
|
18
|
+
from mlx_audio.tts.utils import get_model_path
|
|
19
|
+
from mlx_audio.utils import hanning, mel_filters, stft
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def mel_spectrogram(
|
|
23
|
+
audio: mx.array,
|
|
24
|
+
sample_rate: int = 16_000,
|
|
25
|
+
n_mels: int = 128,
|
|
26
|
+
n_fft: int = 1024,
|
|
27
|
+
f_min: int = 10,
|
|
28
|
+
f_max: Optional[int] = None,
|
|
29
|
+
hop_length: int = 320,
|
|
30
|
+
win_length: int = 640,
|
|
31
|
+
padding: int = 0,
|
|
32
|
+
):
|
|
33
|
+
if not isinstance(audio, mx.array):
|
|
34
|
+
audio = mx.array(audio)
|
|
35
|
+
if padding > 0:
|
|
36
|
+
audio = mx.pad(audio, (0, padding))
|
|
37
|
+
window = hanning(win_length + 1)[:-1]
|
|
38
|
+
freqs = stft(
|
|
39
|
+
audio, window=window, win_length=win_length, hop_length=hop_length, n_fft=n_fft
|
|
40
|
+
)
|
|
41
|
+
magnitudes = freqs.abs()
|
|
42
|
+
filters = mel_filters(
|
|
43
|
+
sample_rate=sample_rate,
|
|
44
|
+
n_fft=n_fft,
|
|
45
|
+
n_mels=n_mels,
|
|
46
|
+
f_min=f_min,
|
|
47
|
+
f_max=f_max,
|
|
48
|
+
norm="slaney",
|
|
49
|
+
mel_scale="slaney",
|
|
50
|
+
)
|
|
51
|
+
mel_spec = magnitudes @ filters.T
|
|
52
|
+
return mx.expand_dims(mel_spec, axis=0)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class BiCodec(nn.Module):
|
|
56
|
+
"""
|
|
57
|
+
BiCodec model for speech synthesis, incorporating a speaker encoder, feature encoder/decoder,
|
|
58
|
+
quantizer, and wave generator.
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
def __init__(
|
|
62
|
+
self,
|
|
63
|
+
mel_params: Dict[str, Any],
|
|
64
|
+
encoder: nn.Module,
|
|
65
|
+
decoder: nn.Module,
|
|
66
|
+
quantizer: nn.Module,
|
|
67
|
+
speaker_encoder: nn.Module,
|
|
68
|
+
prenet: nn.Module,
|
|
69
|
+
postnet: nn.Module,
|
|
70
|
+
**kwargs,
|
|
71
|
+
) -> None:
|
|
72
|
+
"""
|
|
73
|
+
Initializes the BiCodec model with the required components.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
mel_params (dict): Parameters for the mel-spectrogram transformer.
|
|
77
|
+
encoder (nn.Module): Encoder module.
|
|
78
|
+
decoder (nn.Module): Decoder module.
|
|
79
|
+
quantizer (nn.Module): Quantizer module.
|
|
80
|
+
speaker_encoder (nn.Module): Speaker encoder module.
|
|
81
|
+
prenet (nn.Module): Prenet network.
|
|
82
|
+
postnet (nn.Module): Postnet network.
|
|
83
|
+
"""
|
|
84
|
+
super().__init__()
|
|
85
|
+
self.encoder = encoder
|
|
86
|
+
self.decoder = decoder
|
|
87
|
+
self.quantizer = quantizer
|
|
88
|
+
self.speaker_encoder = speaker_encoder
|
|
89
|
+
self.prenet = prenet
|
|
90
|
+
self.postnet = postnet
|
|
91
|
+
self.mel_params = mel_params
|
|
92
|
+
|
|
93
|
+
@classmethod
|
|
94
|
+
def load_from_checkpoint(cls, model_dir: Path, **kwargs) -> "BiCodec":
|
|
95
|
+
"""
|
|
96
|
+
Loads the model from a checkpoint.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
model_dir (Path): Path to the model directory containing checkpoint and config.
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
BiCodec: The initialized BiCodec model.
|
|
103
|
+
"""
|
|
104
|
+
ckpt_path = f"{model_dir}/model.safetensors"
|
|
105
|
+
config = load_config(f"{model_dir}/config.yaml")["audio_tokenizer"]
|
|
106
|
+
mel_params = config["mel_params"]
|
|
107
|
+
|
|
108
|
+
encoder = Encoder(**config["encoder"])
|
|
109
|
+
quantizer = FactorizedVectorQuantize(**config["quantizer"])
|
|
110
|
+
prenet = Decoder(**config["prenet"])
|
|
111
|
+
postnet = Decoder(**config["postnet"])
|
|
112
|
+
decoder = WaveGenerator(**config["decoder"])
|
|
113
|
+
speaker_encoder = SpeakerEncoder(**config["speaker_encoder"])
|
|
114
|
+
|
|
115
|
+
model = cls(
|
|
116
|
+
mel_params=mel_params,
|
|
117
|
+
encoder=encoder,
|
|
118
|
+
decoder=decoder,
|
|
119
|
+
quantizer=quantizer,
|
|
120
|
+
speaker_encoder=speaker_encoder,
|
|
121
|
+
prenet=prenet,
|
|
122
|
+
postnet=postnet,
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
weights = load_file(ckpt_path)
|
|
126
|
+
|
|
127
|
+
# Convert PyTorch weights to MLX arrays and sanitize
|
|
128
|
+
weights = {
|
|
129
|
+
k: mx.array(v) for k, v in weights.items() if "num_batches_tracked" not in k
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
for module in [encoder, decoder, quantizer, speaker_encoder]:
|
|
133
|
+
if hasattr(module, "sanitize"):
|
|
134
|
+
weights = module.sanitize(weights)
|
|
135
|
+
|
|
136
|
+
model.load_weights(list(weights.items()), strict=True)
|
|
137
|
+
|
|
138
|
+
return model
|
|
139
|
+
|
|
140
|
+
def __call__(self, batch: Dict[str, Any]) -> Dict[str, Any]:
|
|
141
|
+
"""
|
|
142
|
+
Performs a forward pass through the model.
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
batch (dict): A dictionary containing features, reference waveform, and target waveform.
|
|
146
|
+
|
|
147
|
+
Returns:
|
|
148
|
+
dict: A dictionary containing the reconstruction, features, and other metrics.
|
|
149
|
+
"""
|
|
150
|
+
feat = batch["feat"]
|
|
151
|
+
ref_wav = batch["ref_wav"]
|
|
152
|
+
mel = self.get_mel_spectrogram(ref_wav)
|
|
153
|
+
z = self.encoder(feat.transpose(0, 2, 1))
|
|
154
|
+
vq_outputs = self.quantizer(z)
|
|
155
|
+
|
|
156
|
+
x_vector, d_vector = self.speaker_encoder(mel)
|
|
157
|
+
|
|
158
|
+
conditions = d_vector
|
|
159
|
+
with_speaker_loss = False
|
|
160
|
+
|
|
161
|
+
# Ensure conditions is an integer type for embedding lookup
|
|
162
|
+
# The error shows that the embedding layer expects integral indices
|
|
163
|
+
if isinstance(conditions, mx.array) and conditions.dtype == mx.float32:
|
|
164
|
+
# Convert to integer type if needed for the embedding layer
|
|
165
|
+
# or ensure it's properly formatted for the prenet
|
|
166
|
+
conditions = conditions.astype(mx.int32)
|
|
167
|
+
|
|
168
|
+
x = self.prenet(vq_outputs["z_q"], conditions)
|
|
169
|
+
pred_feat = self.postnet(x)
|
|
170
|
+
x = x + conditions[..., None]
|
|
171
|
+
wav_recon = self.decoder(x)
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
"vq_loss": vq_outputs["vq_loss"],
|
|
175
|
+
"perplexity": vq_outputs["perplexity"],
|
|
176
|
+
"cluster_size": vq_outputs["active_num"],
|
|
177
|
+
"recons": wav_recon,
|
|
178
|
+
"pred_feat": pred_feat,
|
|
179
|
+
"x_vector": x_vector,
|
|
180
|
+
"d_vector": d_vector,
|
|
181
|
+
"audios": batch["wav"][:, None],
|
|
182
|
+
"with_speaker_loss": with_speaker_loss,
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
def tokenize(self, batch: Dict[str, Any]):
|
|
186
|
+
"""
|
|
187
|
+
Tokenizes the input audio into semantic and global tokens.
|
|
188
|
+
|
|
189
|
+
Args:
|
|
190
|
+
batch (dict): The input audio features and reference waveform.
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
tuple: Semantic tokens and global tokens.
|
|
194
|
+
"""
|
|
195
|
+
feat = batch["feat"]
|
|
196
|
+
ref_wav = mx.array(batch["ref_wav"])
|
|
197
|
+
mel = self.get_mel_spectrogram(ref_wav)
|
|
198
|
+
z = self.encoder(feat.transpose(0, 2, 1))
|
|
199
|
+
semantic_tokens = self.quantizer.tokenize(z)
|
|
200
|
+
global_tokens = self.speaker_encoder.tokenize(mel)
|
|
201
|
+
|
|
202
|
+
return semantic_tokens, global_tokens
|
|
203
|
+
|
|
204
|
+
def detokenize(self, semantic_tokens, global_tokens):
|
|
205
|
+
"""
|
|
206
|
+
Detokenizes the semantic and global tokens into a waveform.
|
|
207
|
+
|
|
208
|
+
Args:
|
|
209
|
+
semantic_tokens (tensor): Semantic tokens.
|
|
210
|
+
global_tokens (tensor): Global tokens.
|
|
211
|
+
|
|
212
|
+
Returns:
|
|
213
|
+
tensor: Reconstructed waveform.
|
|
214
|
+
"""
|
|
215
|
+
|
|
216
|
+
z_q = self.quantizer.detokenize(semantic_tokens.transpose(0, 1)).transpose(
|
|
217
|
+
0, 2, 1
|
|
218
|
+
)
|
|
219
|
+
d_vector = self.speaker_encoder.detokenize(global_tokens)
|
|
220
|
+
x = self.prenet(z_q, d_vector)
|
|
221
|
+
x = x + d_vector[..., None]
|
|
222
|
+
wav_recon = self.decoder(x)
|
|
223
|
+
|
|
224
|
+
return wav_recon # Return MLX array directly
|
|
225
|
+
|
|
226
|
+
def get_mel_spectrogram(self, wav):
|
|
227
|
+
mels = []
|
|
228
|
+
for i in range(wav.shape[0]):
|
|
229
|
+
audio_sample = mx.squeeze(wav[i])
|
|
230
|
+
mel = mel_spectrogram(
|
|
231
|
+
audio=audio_sample,
|
|
232
|
+
sample_rate=self.mel_params["sample_rate"],
|
|
233
|
+
n_mels=self.mel_params["num_mels"],
|
|
234
|
+
n_fft=self.mel_params["n_fft"],
|
|
235
|
+
hop_length=self.mel_params["hop_length"],
|
|
236
|
+
win_length=self.mel_params["win_length"],
|
|
237
|
+
f_min=self.mel_params["mel_fmin"],
|
|
238
|
+
f_max=self.mel_params["mel_fmax"],
|
|
239
|
+
)
|
|
240
|
+
mels.append(mel)
|
|
241
|
+
return mx.concatenate(mels, axis=0)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
if __name__ == "__main__":
|
|
245
|
+
|
|
246
|
+
model_path = get_model_path("SparkAudio/Spark-TTS-0.5B")
|
|
247
|
+
|
|
248
|
+
model = BiCodec.load_from_checkpoint(model_path / "BiCodec")
|
|
249
|
+
model.eval()
|
|
250
|
+
|
|
251
|
+
# Generate random inputs for testing
|
|
252
|
+
duration = 0.96
|
|
253
|
+
x = mx.random.normal((20, 1, int(duration * 16000)), dtype=mx.float32)
|
|
254
|
+
feat = mx.random.normal((20, int(duration * 50), 1024), dtype=mx.float32)
|
|
255
|
+
inputs = {"feat": feat, "wav": x, "ref_wav": x}
|
|
256
|
+
|
|
257
|
+
# Forward pass
|
|
258
|
+
outputs = model(inputs)
|
|
259
|
+
semantic_tokens, global_tokens = model.tokenize(inputs)
|
|
260
|
+
|
|
261
|
+
wav_recon = model.detokenize(semantic_tokens, global_tokens)
|
|
262
|
+
|
|
263
|
+
print(outputs["recons"].shape)
|
|
264
|
+
print(wav_recon.shape)
|
|
265
|
+
|
|
266
|
+
if np.allclose(outputs["recons"], wav_recon):
|
|
267
|
+
print("Test successful")
|
|
268
|
+
else:
|
|
269
|
+
print("Test failed")
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import math
|
|
2
|
+
|
|
3
|
+
import mlx.core as mx
|
|
4
|
+
import mlx.nn as nn
|
|
5
|
+
|
|
6
|
+
from mlx_audio.codec.models.descript.nn.layers import WNConvTranspose1d
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SamplingBlock(nn.Module):
|
|
10
|
+
"""Sampling block for upsampling or downsampling"""
|
|
11
|
+
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
dim: int,
|
|
15
|
+
groups: int = 1,
|
|
16
|
+
upsample_scale: int = 1,
|
|
17
|
+
downsample_scale: int = 1,
|
|
18
|
+
) -> None:
|
|
19
|
+
"""
|
|
20
|
+
Args:
|
|
21
|
+
dim: input dimension
|
|
22
|
+
groups: number of groups
|
|
23
|
+
upsample_scale: upsampling scale
|
|
24
|
+
downsample_scale: downsampling scale
|
|
25
|
+
"""
|
|
26
|
+
super(SamplingBlock, self).__init__()
|
|
27
|
+
|
|
28
|
+
self.upsample_scale = upsample_scale
|
|
29
|
+
self.downsample_scale = downsample_scale
|
|
30
|
+
|
|
31
|
+
if self.upsample_scale > 1:
|
|
32
|
+
self.de_conv_upsampler = nn.Sequential(
|
|
33
|
+
nn.LeakyReLU(0.2),
|
|
34
|
+
WNConvTranspose1d(
|
|
35
|
+
dim,
|
|
36
|
+
dim,
|
|
37
|
+
kernel_size=upsample_scale * 2,
|
|
38
|
+
stride=upsample_scale,
|
|
39
|
+
padding=upsample_scale // 2 + upsample_scale % 2,
|
|
40
|
+
groups=groups,
|
|
41
|
+
),
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
if self.downsample_scale > 1:
|
|
45
|
+
self.conv_downsampler = nn.Sequential(
|
|
46
|
+
nn.LeakyReLU(0.2),
|
|
47
|
+
nn.Conv1d(
|
|
48
|
+
dim,
|
|
49
|
+
dim,
|
|
50
|
+
kernel_size=2 * downsample_scale,
|
|
51
|
+
stride=downsample_scale,
|
|
52
|
+
padding=downsample_scale // 2 + downsample_scale % 2,
|
|
53
|
+
groups=groups,
|
|
54
|
+
),
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
def repeat_upsampler(x, upsample_scale):
|
|
59
|
+
# MLX doesn't have repeat_interleave, so we need to implement it manually
|
|
60
|
+
batch_size, seq_len, channels = x.shape
|
|
61
|
+
# Create a new tensor with the expanded shape
|
|
62
|
+
output = mx.zeros((batch_size, seq_len * upsample_scale, channels))
|
|
63
|
+
# Fill the output tensor by repeating each element
|
|
64
|
+
for i in range(seq_len):
|
|
65
|
+
for j in range(upsample_scale):
|
|
66
|
+
output[:, i * upsample_scale + j, :] = x[:, i, :]
|
|
67
|
+
return output
|
|
68
|
+
|
|
69
|
+
@staticmethod
|
|
70
|
+
def skip_downsampler(x, downsample_scale):
|
|
71
|
+
return nn.AvgPool1d(kernel_size=downsample_scale, stride=downsample_scale)(x)
|
|
72
|
+
|
|
73
|
+
def __call__(self, x):
|
|
74
|
+
x = x.transpose(0, 2, 1)
|
|
75
|
+
if self.upsample_scale > 1:
|
|
76
|
+
repeat_res = self.repeat_upsampler(x, self.upsample_scale)
|
|
77
|
+
deconv_res = self.de_conv_upsampler(x)
|
|
78
|
+
upmerge_res = repeat_res + deconv_res
|
|
79
|
+
else:
|
|
80
|
+
upmerge_res = x
|
|
81
|
+
repeat_res = x
|
|
82
|
+
|
|
83
|
+
if self.downsample_scale > 1:
|
|
84
|
+
conv_res = self.conv_downsampler(upmerge_res)
|
|
85
|
+
skip2_res = self.skip_downsampler(upmerge_res, self.downsample_scale)
|
|
86
|
+
skip1_res = self.skip_downsampler(repeat_res, self.downsample_scale)
|
|
87
|
+
else:
|
|
88
|
+
conv_res = upmerge_res
|
|
89
|
+
skip2_res = upmerge_res
|
|
90
|
+
skip1_res = repeat_res
|
|
91
|
+
|
|
92
|
+
final_res = conv_res + skip1_res + skip2_res
|
|
93
|
+
|
|
94
|
+
return final_res.transpose(0, 2, 1)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# test
|
|
98
|
+
if __name__ == "__main__":
|
|
99
|
+
test_input = mx.random.randint(
|
|
100
|
+
0, 100, (8, 1024, 50)
|
|
101
|
+
) # Batch size = 8, 1024 channels, length = 50
|
|
102
|
+
model = SamplingBlock(1024, 1024, upsample_scale=2)
|
|
103
|
+
model_down = SamplingBlock(1024, 1024, downsample_scale=2)
|
|
104
|
+
output = model(test_input)
|
|
105
|
+
output_down = model_down(test_input)
|
|
106
|
+
print("shape after upsample * 2", output.shape) # torch.Size([8, 1024, 100])
|
|
107
|
+
print("shape after downsample * 2", output_down.shape) # torch.Size([8, 1024, 25])
|
|
108
|
+
if output.shape == (8, 1024, 100) and output_down.shape == (8, 1024, 25):
|
|
109
|
+
print("test successful")
|
|
110
|
+
else:
|
|
111
|
+
print("test failed")
|
|
File without changes
|