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,442 @@
|
|
|
1
|
+
import math
|
|
2
|
+
import os
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
import mlx.core as mx
|
|
7
|
+
import mlx.nn as nn
|
|
8
|
+
import numpy as np
|
|
9
|
+
import tqdm
|
|
10
|
+
|
|
11
|
+
from mlx_audio.codec.models.encodec.encodec import Encodec
|
|
12
|
+
|
|
13
|
+
from ..base import adjust_speed
|
|
14
|
+
from .isftnet import codec_decode
|
|
15
|
+
|
|
16
|
+
TEXT_ENCODING_OFFSET = 10_048
|
|
17
|
+
SEMANTIC_PAD_TOKEN = 10_000
|
|
18
|
+
TEXT_PAD_TOKEN = 129595
|
|
19
|
+
SEMANTIC_INFER_TOKEN = 129_599
|
|
20
|
+
|
|
21
|
+
CONTEXT_WINDOW_SIZE = 1024
|
|
22
|
+
|
|
23
|
+
SEMANTIC_RATE_HZ = 49.9
|
|
24
|
+
SEMANTIC_VOCAB_SIZE = 10_000
|
|
25
|
+
|
|
26
|
+
CODEBOOK_SIZE = 1024
|
|
27
|
+
N_COARSE_CODEBOOKS = 2
|
|
28
|
+
N_FINE_CODEBOOKS = 8
|
|
29
|
+
COARSE_RATE_HZ = 75
|
|
30
|
+
COARSE_SEMANTIC_PAD_TOKEN = 12_048
|
|
31
|
+
COARSE_INFER_TOKEN = 12_050
|
|
32
|
+
SAMPLE_RATE = 24_000
|
|
33
|
+
|
|
34
|
+
CUR_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
SUPPORTED_LANGS = [
|
|
38
|
+
("English", "en"),
|
|
39
|
+
("German", "de"),
|
|
40
|
+
("Spanish", "es"),
|
|
41
|
+
("French", "fr"),
|
|
42
|
+
("Hindi", "hi"),
|
|
43
|
+
("Italian", "it"),
|
|
44
|
+
("Japanese", "ja"),
|
|
45
|
+
("Korean", "ko"),
|
|
46
|
+
("Polish", "pl"),
|
|
47
|
+
("Portuguese", "pt"),
|
|
48
|
+
("Russian", "ru"),
|
|
49
|
+
("Turkish", "tr"),
|
|
50
|
+
("Chinese", "zh"),
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
ALLOWED_PROMPTS = {"announcer"}
|
|
54
|
+
for _, lang in SUPPORTED_LANGS:
|
|
55
|
+
for prefix in ("", f"v2{os.path.sep}"):
|
|
56
|
+
for n in range(10):
|
|
57
|
+
ALLOWED_PROMPTS.add(f"{prefix}{lang}_speaker_{n}")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@dataclass
|
|
61
|
+
class Result:
|
|
62
|
+
audio: mx.array
|
|
63
|
+
tokens: mx.array
|
|
64
|
+
|
|
65
|
+
### MARK: BEGIN BACKWARD COMPAT ###
|
|
66
|
+
def __iter__(self):
|
|
67
|
+
yield self.audio
|
|
68
|
+
yield self.tokens
|
|
69
|
+
|
|
70
|
+
def __getitem__(self, index):
|
|
71
|
+
return [self.audio, self.tokens][index]
|
|
72
|
+
|
|
73
|
+
def __len__(self):
|
|
74
|
+
return 2
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _load_voice_prompt(voice_prompt_input):
|
|
78
|
+
if isinstance(voice_prompt_input, str) and voice_prompt_input.endswith(".npz"):
|
|
79
|
+
voice_prompt = np.load(voice_prompt_input)
|
|
80
|
+
elif isinstance(voice_prompt_input, str):
|
|
81
|
+
# make sure this works on non-ubuntu
|
|
82
|
+
voice_prompt_input = os.path.join(*voice_prompt_input.split("/"))
|
|
83
|
+
if voice_prompt_input not in ALLOWED_PROMPTS:
|
|
84
|
+
raise ValueError("voice prompt not found")
|
|
85
|
+
|
|
86
|
+
path = f"{voice_prompt_input}.npz"
|
|
87
|
+
|
|
88
|
+
# TODO: Get the path from the Hugging Face cache directory
|
|
89
|
+
# TODO: If not found, download the voice from Hugging Face
|
|
90
|
+
# TODO: If still not found, raise an error
|
|
91
|
+
|
|
92
|
+
if not os.path.exists(path):
|
|
93
|
+
raise ValueError("voice prompt not found")
|
|
94
|
+
voice_prompt = np.load(path)
|
|
95
|
+
elif isinstance(voice_prompt_input, dict):
|
|
96
|
+
assert "semantic_prompt" in voice_prompt_input
|
|
97
|
+
assert "coarse_prompt" in voice_prompt_input
|
|
98
|
+
assert "fine_prompt" in voice_prompt_input
|
|
99
|
+
voice_prompt = voice_prompt_input
|
|
100
|
+
else:
|
|
101
|
+
raise ValueError("voice prompt format unrecognized")
|
|
102
|
+
return voice_prompt
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _flatten_codebooks(arr, offset_size=CODEBOOK_SIZE):
|
|
106
|
+
assert len(arr.shape) == 2
|
|
107
|
+
if offset_size is not None:
|
|
108
|
+
for n in range(1, arr.shape[0]):
|
|
109
|
+
arr[n, :] += offset_size * n
|
|
110
|
+
# MLX doesn't have ravel with order parameter, so we transpose and reshape
|
|
111
|
+
# to achieve the same effect as numpy's ravel('F')
|
|
112
|
+
flat_arr = arr.transpose().reshape(-1)
|
|
113
|
+
return flat_arr
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class Pipeline:
|
|
117
|
+
def __init__(self, model: nn.Module, tokenizer: any, config: any):
|
|
118
|
+
self.model = model
|
|
119
|
+
self.tokenizer = tokenizer
|
|
120
|
+
self.codec_model, _ = Encodec.from_pretrained(config.codec_path)
|
|
121
|
+
|
|
122
|
+
def generate_text_semantic(
|
|
123
|
+
self,
|
|
124
|
+
text: str,
|
|
125
|
+
voice: str = "announcer",
|
|
126
|
+
temperature: float = 0.7,
|
|
127
|
+
use_kv_caching: bool = False,
|
|
128
|
+
allow_early_stop: bool = True,
|
|
129
|
+
**kwargs,
|
|
130
|
+
):
|
|
131
|
+
"""Generate semantic tokens from text."""
|
|
132
|
+
verbose = kwargs.get("verbose", False)
|
|
133
|
+
if verbose:
|
|
134
|
+
print("Generating semantic tokens...")
|
|
135
|
+
if voice is not None:
|
|
136
|
+
voice_prompt = _load_voice_prompt(voice)
|
|
137
|
+
semantic_history = mx.array(voice_prompt["semantic_prompt"])
|
|
138
|
+
assert (
|
|
139
|
+
isinstance(semantic_history, mx.array)
|
|
140
|
+
and len(semantic_history.shape) == 1
|
|
141
|
+
and len(semantic_history) > 0
|
|
142
|
+
and semantic_history.min() >= 0
|
|
143
|
+
and semantic_history.max() <= SEMANTIC_VOCAB_SIZE - 1
|
|
144
|
+
)
|
|
145
|
+
else:
|
|
146
|
+
semantic_history = None
|
|
147
|
+
|
|
148
|
+
encoded_text = (
|
|
149
|
+
mx.array(self.tokenizer.encode(text, add_special_tokens=False))
|
|
150
|
+
+ TEXT_ENCODING_OFFSET
|
|
151
|
+
)
|
|
152
|
+
if len(encoded_text) > 256:
|
|
153
|
+
p = round((len(encoded_text) - 256) / len(encoded_text) * 100, 1)
|
|
154
|
+
encoded_text = encoded_text[:256]
|
|
155
|
+
encoded_text = mx.pad(
|
|
156
|
+
encoded_text,
|
|
157
|
+
(0, 256 - len(encoded_text)),
|
|
158
|
+
constant_values=TEXT_PAD_TOKEN,
|
|
159
|
+
)
|
|
160
|
+
if semantic_history is not None:
|
|
161
|
+
semantic_history = semantic_history.astype(mx.int64)
|
|
162
|
+
# lop off if history is too long, pad if needed
|
|
163
|
+
semantic_history = semantic_history[-256:]
|
|
164
|
+
semantic_history = mx.pad(
|
|
165
|
+
semantic_history,
|
|
166
|
+
(0, 256 - len(semantic_history)),
|
|
167
|
+
constant_values=SEMANTIC_PAD_TOKEN,
|
|
168
|
+
mode="constant",
|
|
169
|
+
)
|
|
170
|
+
else:
|
|
171
|
+
semantic_history = mx.array([SEMANTIC_PAD_TOKEN] * 256)
|
|
172
|
+
|
|
173
|
+
x = (
|
|
174
|
+
mx.concatenate(
|
|
175
|
+
[encoded_text, semantic_history, mx.array([SEMANTIC_INFER_TOKEN])]
|
|
176
|
+
)
|
|
177
|
+
.reshape(1, -1)
|
|
178
|
+
.astype(mx.int64)
|
|
179
|
+
)
|
|
180
|
+
n_tot_steps = 768
|
|
181
|
+
kv_cache = None
|
|
182
|
+
for i in tqdm.tqdm(range(n_tot_steps), disable=not verbose):
|
|
183
|
+
if use_kv_caching and kv_cache is not None:
|
|
184
|
+
x_input = x[:, -1:]
|
|
185
|
+
else:
|
|
186
|
+
x_input = x
|
|
187
|
+
logits, kv_cache = self.model.semantic(
|
|
188
|
+
x_input, merge_context=True, use_cache=use_kv_caching, past_kv=kv_cache
|
|
189
|
+
)
|
|
190
|
+
relevant_logits = logits[0, 0, :SEMANTIC_VOCAB_SIZE]
|
|
191
|
+
if allow_early_stop:
|
|
192
|
+
# Early stop
|
|
193
|
+
relevant_logits = mx.concatenate(
|
|
194
|
+
[relevant_logits, logits[0, 0, SEMANTIC_PAD_TOKEN].reshape(1)],
|
|
195
|
+
axis=-1,
|
|
196
|
+
)
|
|
197
|
+
next_token = mx.random.categorical(
|
|
198
|
+
relevant_logits * 1 / (temperature), num_samples=1
|
|
199
|
+
).astype(mx.int32)
|
|
200
|
+
|
|
201
|
+
if next_token == SEMANTIC_VOCAB_SIZE:
|
|
202
|
+
print(f"Early stop at step {i} with token {next_token.tolist()}")
|
|
203
|
+
break
|
|
204
|
+
x = mx.concatenate([x, next_token.reshape(1, -1)], axis=1)
|
|
205
|
+
if i == n_tot_steps - 1:
|
|
206
|
+
break
|
|
207
|
+
out = x.squeeze()[256 + 256 + 1 :]
|
|
208
|
+
return out, encoded_text
|
|
209
|
+
|
|
210
|
+
def generate_coarse(
|
|
211
|
+
self,
|
|
212
|
+
x_semantic: mx.array,
|
|
213
|
+
voice: str = "announcer",
|
|
214
|
+
temperature: float = 0.7,
|
|
215
|
+
max_coarse_history: int = 60, # min 60 (faster), max 630 (more context)
|
|
216
|
+
sliding_window_len: int = 60,
|
|
217
|
+
use_kv_caching: bool = False,
|
|
218
|
+
**kwargs,
|
|
219
|
+
):
|
|
220
|
+
"""Generate coarse tokens from semantic tokens."""
|
|
221
|
+
verbose = kwargs.get("verbose", False)
|
|
222
|
+
if verbose:
|
|
223
|
+
print("Generating coarse tokens...")
|
|
224
|
+
semantic_to_coarse_ratio = (
|
|
225
|
+
COARSE_RATE_HZ / SEMANTIC_RATE_HZ * N_COARSE_CODEBOOKS
|
|
226
|
+
)
|
|
227
|
+
max_semantic_history = int(
|
|
228
|
+
math.floor(max_coarse_history / semantic_to_coarse_ratio)
|
|
229
|
+
)
|
|
230
|
+
if voice is not None:
|
|
231
|
+
voice_prompt = _load_voice_prompt(voice)
|
|
232
|
+
x_semantic_history = mx.array(voice_prompt["semantic_prompt"])
|
|
233
|
+
x_coarse_history = mx.array(voice_prompt["coarse_prompt"])
|
|
234
|
+
assert (
|
|
235
|
+
isinstance(x_semantic_history, mx.array)
|
|
236
|
+
and len(x_semantic_history.shape) == 1
|
|
237
|
+
and len(x_semantic_history) > 0
|
|
238
|
+
and x_semantic_history.min() >= 0
|
|
239
|
+
and x_semantic_history.max() <= SEMANTIC_VOCAB_SIZE - 1
|
|
240
|
+
and isinstance(x_coarse_history, mx.array)
|
|
241
|
+
and len(x_coarse_history.shape) == 2
|
|
242
|
+
and x_coarse_history.shape[0] == N_COARSE_CODEBOOKS
|
|
243
|
+
and x_coarse_history.shape[-1] >= 0
|
|
244
|
+
and x_coarse_history.min() >= 0
|
|
245
|
+
and x_coarse_history.max() <= CODEBOOK_SIZE - 1
|
|
246
|
+
and (
|
|
247
|
+
round(x_coarse_history.shape[-1] / len(x_semantic_history), 1)
|
|
248
|
+
== round(semantic_to_coarse_ratio / N_COARSE_CODEBOOKS, 1)
|
|
249
|
+
)
|
|
250
|
+
)
|
|
251
|
+
x_coarse_history = (
|
|
252
|
+
_flatten_codebooks(x_coarse_history) + SEMANTIC_VOCAB_SIZE
|
|
253
|
+
)
|
|
254
|
+
# trim histories correctly
|
|
255
|
+
n_semantic_hist_provided = min(
|
|
256
|
+
max_semantic_history,
|
|
257
|
+
len(x_semantic_history) - len(x_semantic_history) % 2,
|
|
258
|
+
int(math.floor(len(x_coarse_history) / semantic_to_coarse_ratio)),
|
|
259
|
+
)
|
|
260
|
+
n_coarse_hist_provided = int(
|
|
261
|
+
round(n_semantic_hist_provided * semantic_to_coarse_ratio)
|
|
262
|
+
)
|
|
263
|
+
x_semantic_history = x_semantic_history[-n_semantic_hist_provided:].astype(
|
|
264
|
+
mx.int32
|
|
265
|
+
)
|
|
266
|
+
x_coarse_history = x_coarse_history[-n_coarse_hist_provided:].astype(
|
|
267
|
+
mx.int32
|
|
268
|
+
)
|
|
269
|
+
# TODO: bit of a hack for time alignment (sounds better)
|
|
270
|
+
x_coarse_history = x_coarse_history[:-2]
|
|
271
|
+
else:
|
|
272
|
+
x_semantic_history = mx.array([], dtype=mx.int32)
|
|
273
|
+
x_coarse_history = mx.array([], dtype=mx.int32)
|
|
274
|
+
|
|
275
|
+
n_steps = int(
|
|
276
|
+
round(
|
|
277
|
+
math.floor(
|
|
278
|
+
len(x_semantic) * semantic_to_coarse_ratio / N_COARSE_CODEBOOKS
|
|
279
|
+
)
|
|
280
|
+
* N_COARSE_CODEBOOKS
|
|
281
|
+
)
|
|
282
|
+
)
|
|
283
|
+
x_semantic = mx.concatenate([x_semantic_history, x_semantic]).astype(mx.int32)
|
|
284
|
+
x_coarse = x_coarse_history.astype(mx.int32)
|
|
285
|
+
base_semantic_idx = len(x_semantic_history)
|
|
286
|
+
# Inference
|
|
287
|
+
x_semantic_in = x_semantic.reshape(1, -1)
|
|
288
|
+
x_coarse_in = x_coarse.reshape(1, -1)
|
|
289
|
+
n_window_steps = int(round(n_steps / sliding_window_len))
|
|
290
|
+
n_step = 0
|
|
291
|
+
for _ in tqdm.tqdm(
|
|
292
|
+
range(n_window_steps), total=n_window_steps, disable=not verbose
|
|
293
|
+
):
|
|
294
|
+
semantic_idx = base_semantic_idx + int(
|
|
295
|
+
round(n_step / semantic_to_coarse_ratio)
|
|
296
|
+
)
|
|
297
|
+
x_in = x_semantic_in[:, max(0, semantic_idx - max_semantic_history) :]
|
|
298
|
+
x_in = x_in[:, :256]
|
|
299
|
+
x_in = mx.pad(
|
|
300
|
+
x_in,
|
|
301
|
+
((0, 0), (0, 256 - x_in.shape[-1])),
|
|
302
|
+
constant_values=COARSE_SEMANTIC_PAD_TOKEN,
|
|
303
|
+
)
|
|
304
|
+
x_in = mx.concatenate(
|
|
305
|
+
[
|
|
306
|
+
x_in,
|
|
307
|
+
mx.array([COARSE_INFER_TOKEN]).reshape(1, -1),
|
|
308
|
+
x_coarse_in[:, -max_coarse_history:],
|
|
309
|
+
],
|
|
310
|
+
axis=1,
|
|
311
|
+
)
|
|
312
|
+
kv_cache = None
|
|
313
|
+
for _ in range(sliding_window_len):
|
|
314
|
+
if n_step >= n_steps:
|
|
315
|
+
continue
|
|
316
|
+
is_major_step = n_step % N_COARSE_CODEBOOKS == 0
|
|
317
|
+
x_input = (
|
|
318
|
+
x_in[:, -1:] if use_kv_caching and kv_cache is not None else x_in
|
|
319
|
+
)
|
|
320
|
+
logits, kv_cache = self.model.coarse_acoustics(
|
|
321
|
+
x_input, use_cache=use_kv_caching, past_kv=kv_cache
|
|
322
|
+
)
|
|
323
|
+
logit_start_idx = (
|
|
324
|
+
SEMANTIC_VOCAB_SIZE + (1 - int(is_major_step)) * CODEBOOK_SIZE
|
|
325
|
+
)
|
|
326
|
+
logit_end_idx = (
|
|
327
|
+
SEMANTIC_VOCAB_SIZE + (2 - int(is_major_step)) * CODEBOOK_SIZE
|
|
328
|
+
)
|
|
329
|
+
logit_end_idx = min(logit_end_idx, logits.shape[-1])
|
|
330
|
+
relevant_logits = logits[0, 0, logit_start_idx:logit_end_idx]
|
|
331
|
+
item_next = mx.random.categorical(
|
|
332
|
+
relevant_logits * (1 / temperature), num_samples=1
|
|
333
|
+
).astype(mx.int32)
|
|
334
|
+
|
|
335
|
+
item_next += logit_start_idx
|
|
336
|
+
x_coarse_in = mx.concatenate(
|
|
337
|
+
[x_coarse_in, item_next.reshape(1, 1)], axis=1
|
|
338
|
+
)
|
|
339
|
+
x_in = mx.concatenate([x_in, item_next.reshape(1, 1)], axis=1)
|
|
340
|
+
n_step += 1
|
|
341
|
+
|
|
342
|
+
gen_coarse_arr = x_coarse_in[0, len(x_coarse_history) :]
|
|
343
|
+
gen_coarse_audio_arr = (
|
|
344
|
+
gen_coarse_arr.reshape(-1, N_COARSE_CODEBOOKS).T - SEMANTIC_VOCAB_SIZE
|
|
345
|
+
)
|
|
346
|
+
for n in range(1, N_COARSE_CODEBOOKS):
|
|
347
|
+
gen_coarse_audio_arr[n, :] -= n * CODEBOOK_SIZE
|
|
348
|
+
|
|
349
|
+
return gen_coarse_audio_arr
|
|
350
|
+
|
|
351
|
+
def generate_fine(
|
|
352
|
+
self,
|
|
353
|
+
x_coarse_gen: mx.array,
|
|
354
|
+
temperature: float = 0.7,
|
|
355
|
+
**kwargs,
|
|
356
|
+
):
|
|
357
|
+
verbose = kwargs.get("verbose", False)
|
|
358
|
+
"""Generate fine tokens from coarse tokens."""
|
|
359
|
+
if verbose:
|
|
360
|
+
print("Generating fine tokens...")
|
|
361
|
+
x_fine_history = None
|
|
362
|
+
n_coarse = x_coarse_gen.shape[0]
|
|
363
|
+
in_arr = mx.concatenate(
|
|
364
|
+
[
|
|
365
|
+
x_coarse_gen,
|
|
366
|
+
mx.zeros((N_FINE_CODEBOOKS - n_coarse, x_coarse_gen.shape[1]))
|
|
367
|
+
+ CODEBOOK_SIZE, # padding
|
|
368
|
+
],
|
|
369
|
+
axis=0,
|
|
370
|
+
)
|
|
371
|
+
n_history = 0
|
|
372
|
+
n_remove_from_end = 0
|
|
373
|
+
# need to pad if too short (since non-causal model)
|
|
374
|
+
if in_arr.shape[1] < 1024:
|
|
375
|
+
n_remove_from_end = 1024 - in_arr.shape[1]
|
|
376
|
+
in_arr = mx.concatenate(
|
|
377
|
+
[
|
|
378
|
+
in_arr,
|
|
379
|
+
mx.zeros((N_FINE_CODEBOOKS, n_remove_from_end)) + CODEBOOK_SIZE,
|
|
380
|
+
],
|
|
381
|
+
axis=1,
|
|
382
|
+
)
|
|
383
|
+
# Inference
|
|
384
|
+
n_loops = (
|
|
385
|
+
max(0, int(math.ceil((x_coarse_gen.shape[1] - (1024 - n_history)) / 512)))
|
|
386
|
+
+ 1
|
|
387
|
+
)
|
|
388
|
+
in_arr = in_arr.T
|
|
389
|
+
for n in tqdm.tqdm(range(n_loops), disable=not verbose):
|
|
390
|
+
start_idx = mx.min(mx.array([n * 512, in_arr.shape[0] - 1024])).item()
|
|
391
|
+
start_fill_idx = mx.min(
|
|
392
|
+
mx.array([n_history + n * 512, in_arr.shape[0] - 512])
|
|
393
|
+
).item()
|
|
394
|
+
rel_start_fill_idx = start_fill_idx - start_idx
|
|
395
|
+
in_buffer = in_arr[start_idx : start_idx + 1024, :][None]
|
|
396
|
+
for nn in range(n_coarse, N_FINE_CODEBOOKS):
|
|
397
|
+
logits = self.model.fine_acoustics(nn, in_buffer)
|
|
398
|
+
if temperature is None:
|
|
399
|
+
relevant_logits = logits[0, rel_start_fill_idx:, :CODEBOOK_SIZE]
|
|
400
|
+
codebook_preds = mx.argmax(relevant_logits, -1)
|
|
401
|
+
else:
|
|
402
|
+
relevant_logits = logits[0, :, :CODEBOOK_SIZE] / temperature
|
|
403
|
+
codebook_preds = (
|
|
404
|
+
mx.random.categorical(
|
|
405
|
+
relevant_logits[rel_start_fill_idx:1024], num_samples=1
|
|
406
|
+
)
|
|
407
|
+
.reshape(-1)
|
|
408
|
+
.astype(mx.int32)
|
|
409
|
+
)
|
|
410
|
+
in_buffer[0, rel_start_fill_idx:, nn] = codebook_preds
|
|
411
|
+
for nn in range(n_coarse, N_FINE_CODEBOOKS):
|
|
412
|
+
in_arr[
|
|
413
|
+
start_fill_idx : start_fill_idx + (1024 - rel_start_fill_idx), nn
|
|
414
|
+
] = in_buffer[0, rel_start_fill_idx:, nn]
|
|
415
|
+
gen_fine_arr = in_arr.squeeze().T
|
|
416
|
+
gen_fine_arr = gen_fine_arr[:, n_history:]
|
|
417
|
+
if n_remove_from_end > 0:
|
|
418
|
+
gen_fine_arr = gen_fine_arr[:, :-n_remove_from_end]
|
|
419
|
+
assert gen_fine_arr.shape[-1] == x_coarse_gen.shape[-1]
|
|
420
|
+
return gen_fine_arr
|
|
421
|
+
|
|
422
|
+
def __call__(
|
|
423
|
+
self,
|
|
424
|
+
text: str,
|
|
425
|
+
voice: str = None,
|
|
426
|
+
temperature: float = 0.7,
|
|
427
|
+
speed: float = 1.0,
|
|
428
|
+
use_kv_caching: bool = False,
|
|
429
|
+
**kwargs,
|
|
430
|
+
):
|
|
431
|
+
semantic_tokens, tokens = self.generate_text_semantic(
|
|
432
|
+
text, voice, temperature, use_kv_caching, **kwargs
|
|
433
|
+
)
|
|
434
|
+
coarse_tokens = self.generate_coarse(
|
|
435
|
+
semantic_tokens, voice, temperature, use_kv_caching, **kwargs
|
|
436
|
+
)
|
|
437
|
+
fine_tokens = self.generate_fine(coarse_tokens, temperature, **kwargs)
|
|
438
|
+
# TODO: adjust speed
|
|
439
|
+
# audio_arr = adjust_speed(fine_tokens, speed)
|
|
440
|
+
audio_arr = codec_decode(self.codec_model, fine_tokens)
|
|
441
|
+
|
|
442
|
+
yield Result(audio=audio_arr, tokens=tokens)
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
|
|
4
|
+
import mlx.core as mx
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass
|
|
9
|
+
class BaseModelArgs:
|
|
10
|
+
@classmethod
|
|
11
|
+
def from_dict(cls, params):
|
|
12
|
+
return cls(
|
|
13
|
+
**{
|
|
14
|
+
k: v
|
|
15
|
+
for k, v in params.items()
|
|
16
|
+
if k in inspect.signature(cls).parameters
|
|
17
|
+
}
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def check_array_shape(arr):
|
|
22
|
+
shape = arr.shape
|
|
23
|
+
|
|
24
|
+
# Check if the shape has 4 dimensions
|
|
25
|
+
if len(shape) != 3:
|
|
26
|
+
return False
|
|
27
|
+
|
|
28
|
+
out_channels, kH, KW = shape
|
|
29
|
+
|
|
30
|
+
# Check if out_channels is the largest, and kH and KW are the same
|
|
31
|
+
if (out_channels >= kH) and (out_channels >= KW) and (kH == KW):
|
|
32
|
+
return True
|
|
33
|
+
else:
|
|
34
|
+
return False
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def adjust_speed(audio_array, speed_factor):
|
|
38
|
+
"""
|
|
39
|
+
Adjust the speed of the audio by resampling
|
|
40
|
+
speed_factor > 1: faster
|
|
41
|
+
speed_factor < 1: slower
|
|
42
|
+
"""
|
|
43
|
+
# Ensure we're working with MLX arrays
|
|
44
|
+
if not isinstance(audio_array, mx.array):
|
|
45
|
+
audio_array = mx.array(audio_array)
|
|
46
|
+
|
|
47
|
+
# Calculate new length
|
|
48
|
+
old_length = audio_array.shape[0]
|
|
49
|
+
new_length = int(old_length / speed_factor)
|
|
50
|
+
|
|
51
|
+
# Create new time points
|
|
52
|
+
old_indices = mx.arange(old_length)
|
|
53
|
+
new_indices = mx.linspace(0, old_length - 1, new_length)
|
|
54
|
+
|
|
55
|
+
# Resample using linear interpolation
|
|
56
|
+
# Since mx doesn't have interp, we'll implement it directly
|
|
57
|
+
indices_floor = mx.floor(new_indices).astype(mx.int32)
|
|
58
|
+
indices_ceil = mx.minimum(indices_floor + 1, old_length - 1)
|
|
59
|
+
weights_ceil = new_indices - indices_floor
|
|
60
|
+
weights_floor = 1.0 - weights_ceil
|
|
61
|
+
|
|
62
|
+
# Perform the interpolation
|
|
63
|
+
result = (
|
|
64
|
+
weights_floor.reshape(-1, 1) * audio_array[indices_floor]
|
|
65
|
+
+ weights_ceil.reshape(-1, 1) * audio_array[indices_ceil]
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
return result
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@dataclass
|
|
72
|
+
class GenerationResult:
|
|
73
|
+
audio: mx.array
|
|
74
|
+
samples: int
|
|
75
|
+
sample_rate: int
|
|
76
|
+
segment_idx: int
|
|
77
|
+
token_count: int
|
|
78
|
+
audio_samples: int
|
|
79
|
+
audio_duration: str
|
|
80
|
+
real_time_factor: float
|
|
81
|
+
prompt: dict
|
|
82
|
+
audio_samples: dict
|
|
83
|
+
processing_time_seconds: float
|
|
84
|
+
peak_memory_usage: float
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .dia import Model
|