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,592 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import time
|
|
3
|
+
from typing import List, Optional
|
|
4
|
+
|
|
5
|
+
import mlx.core as mx
|
|
6
|
+
import mlx.nn as nn
|
|
7
|
+
import numpy as np
|
|
8
|
+
from huggingface_hub import hf_hub_download
|
|
9
|
+
from mlx_lm.sample_utils import make_sampler
|
|
10
|
+
from tqdm import trange
|
|
11
|
+
|
|
12
|
+
from mlx_audio.codec.models import DAC
|
|
13
|
+
|
|
14
|
+
from ..base import GenerationResult
|
|
15
|
+
from .audio import audio_to_codebook, codebook_to_audio
|
|
16
|
+
from .config import DiaConfig
|
|
17
|
+
from .layers import DiaModel, KVCache
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _sample_next_token(
|
|
21
|
+
logits_BCxV: mx.array,
|
|
22
|
+
temperature: float,
|
|
23
|
+
sampler: callable,
|
|
24
|
+
) -> mx.array:
|
|
25
|
+
if temperature == 0.0:
|
|
26
|
+
return mx.argmax(logits_BCxV, axis=-1)
|
|
27
|
+
|
|
28
|
+
sampled = sampler(logits_BCxV)
|
|
29
|
+
return sampled
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Model(nn.Module):
|
|
33
|
+
def __init__(self, config: dict):
|
|
34
|
+
"""Initializes the Dia model.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
config: The configuration object for the model.
|
|
38
|
+
|
|
39
|
+
Raises:
|
|
40
|
+
RuntimeError: If there is an error loading the DAC model.
|
|
41
|
+
"""
|
|
42
|
+
super().__init__()
|
|
43
|
+
self.config = DiaConfig.load_dict(config)
|
|
44
|
+
self.model = DiaModel(self.config)
|
|
45
|
+
self.dac_model = DAC.from_pretrained("mlx-community/descript-audio-codec-44khz")
|
|
46
|
+
|
|
47
|
+
@classmethod
|
|
48
|
+
def from_local(cls, config_path: str, checkpoint_path: str) -> "Dia":
|
|
49
|
+
"""Loads the Dia model from local configuration and checkpoint files.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
config_path: Path to the configuration JSON file.
|
|
53
|
+
checkpoint_path: Path to the model checkpoint (.pth) file.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
An instance of the Dia model loaded with weights and set to eval mode.
|
|
57
|
+
|
|
58
|
+
Raises:
|
|
59
|
+
FileNotFoundError: If the config or checkpoint file is not found.
|
|
60
|
+
RuntimeError: If there is an error loading the checkpoint.
|
|
61
|
+
"""
|
|
62
|
+
config = DiaConfig.load(config_path)
|
|
63
|
+
if config is None:
|
|
64
|
+
raise FileNotFoundError(f"Config file not found at {config_path}")
|
|
65
|
+
|
|
66
|
+
dia = cls(config)
|
|
67
|
+
|
|
68
|
+
try:
|
|
69
|
+
weights = mx.load(checkpoint_path)
|
|
70
|
+
dia.model.load_weights(list(weights.items()))
|
|
71
|
+
except FileNotFoundError:
|
|
72
|
+
raise FileNotFoundError(f"Checkpoint file not found at {checkpoint_path}")
|
|
73
|
+
except Exception as e:
|
|
74
|
+
raise RuntimeError(
|
|
75
|
+
f"Error loading checkpoint from {checkpoint_path}"
|
|
76
|
+
) from e
|
|
77
|
+
|
|
78
|
+
dia.dac_model = DAC.from_pretrained("mlx-community/descript-audio-codec-44khz")
|
|
79
|
+
|
|
80
|
+
return dia
|
|
81
|
+
|
|
82
|
+
@classmethod
|
|
83
|
+
def from_pretrained(cls, model_name: str = "mlx-community/Dia-1.6B") -> "Dia":
|
|
84
|
+
"""Loads the Dia model from a Hugging Face Hub repository.
|
|
85
|
+
|
|
86
|
+
Downloads the configuration and checkpoint files from the specified
|
|
87
|
+
repository ID and then loads the model.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
model_name: The Hugging Face Hub repository ID (e.g., "NariLabs/Dia-1.6B").
|
|
91
|
+
|
|
92
|
+
Returns:
|
|
93
|
+
An instance of the Dia model loaded with weights and set to eval mode.
|
|
94
|
+
|
|
95
|
+
Raises:
|
|
96
|
+
FileNotFoundError: If config or checkpoint download/loading fails.
|
|
97
|
+
RuntimeError: If there is an error loading the checkpoint.
|
|
98
|
+
"""
|
|
99
|
+
config_path = hf_hub_download(repo_id=model_name, filename="config.json")
|
|
100
|
+
checkpoint_path = hf_hub_download(
|
|
101
|
+
repo_id=model_name, filename="model.safetensors"
|
|
102
|
+
)
|
|
103
|
+
return cls.from_local(config_path, checkpoint_path)
|
|
104
|
+
|
|
105
|
+
def load_weights(self, weights, strict: bool = True):
|
|
106
|
+
self.model.load_weights(weights, strict=strict)
|
|
107
|
+
|
|
108
|
+
def sanitize(self, weights):
|
|
109
|
+
return weights
|
|
110
|
+
|
|
111
|
+
def parameters(self):
|
|
112
|
+
return self.model.parameters()
|
|
113
|
+
|
|
114
|
+
def eval(self):
|
|
115
|
+
self.model.eval()
|
|
116
|
+
|
|
117
|
+
@property
|
|
118
|
+
def sample_rate(self):
|
|
119
|
+
return self.config.model.sample_rate
|
|
120
|
+
|
|
121
|
+
def _create_attn_mask(
|
|
122
|
+
self,
|
|
123
|
+
q_padding_mask_1d: mx.array,
|
|
124
|
+
k_padding_mask_1d: mx.array,
|
|
125
|
+
is_causal: bool = False,
|
|
126
|
+
) -> mx.array:
|
|
127
|
+
"""
|
|
128
|
+
Creates the attention mask (self or cross) mimicking JAX segment ID logic.
|
|
129
|
+
"""
|
|
130
|
+
B1, Tq = q_padding_mask_1d.shape
|
|
131
|
+
B2, Tk = k_padding_mask_1d.shape
|
|
132
|
+
assert B1 == B2, "Query and key batch dimensions must match"
|
|
133
|
+
|
|
134
|
+
p_mask_q = mx.expand_dims(q_padding_mask_1d, 2) # Shape [B, Tq, 1]
|
|
135
|
+
p_mask_k = mx.expand_dims(k_padding_mask_1d, 1) # Shape [B, 1, Tk]
|
|
136
|
+
|
|
137
|
+
# Condition A: Non-padding query attends to non-padding key
|
|
138
|
+
non_pad_attends_non_pad = mx.logical_and(
|
|
139
|
+
p_mask_q, p_mask_k
|
|
140
|
+
) # Shape [B, Tq, Tk]
|
|
141
|
+
|
|
142
|
+
# Condition B: Padding query attends to padding key
|
|
143
|
+
pad_attends_pad = mx.logical_and(
|
|
144
|
+
mx.logical_not(p_mask_q), mx.logical_not(p_mask_k)
|
|
145
|
+
) # Shape [B, Tq, Tk]
|
|
146
|
+
|
|
147
|
+
# Combine: True if padding status is compatible (both non-pad OR both pad)
|
|
148
|
+
# This implementation follows Jax TPU splash attention kernel
|
|
149
|
+
mask = mx.logical_or(
|
|
150
|
+
non_pad_attends_non_pad, pad_attends_pad
|
|
151
|
+
) # Shape [B, Tq, Tk]
|
|
152
|
+
|
|
153
|
+
if is_causal:
|
|
154
|
+
# Ensure causality for self-attention (Tq == Tk)
|
|
155
|
+
assert (
|
|
156
|
+
Tq == Tk
|
|
157
|
+
), "Causal mask requires query and key sequence lengths to be equal"
|
|
158
|
+
# Standard lower-triangular causal mask (True means allow)
|
|
159
|
+
causal_mask_2d = mx.tril(
|
|
160
|
+
mx.ones((Tq, Tk), dtype=mx.bool_)
|
|
161
|
+
) # Shape [Tq, Tk]
|
|
162
|
+
causal_mask = mx.logical_and(mask, causal_mask_2d) # Shape [B, Tq, Tk]
|
|
163
|
+
return mx.expand_dims(
|
|
164
|
+
causal_mask, 1
|
|
165
|
+
) # Shape [B, 1, Tq, Tk] for broadcasting across heads
|
|
166
|
+
else:
|
|
167
|
+
# For cross-attention or non-causal self-attention
|
|
168
|
+
return mx.expand_dims(
|
|
169
|
+
mask, 1
|
|
170
|
+
) # Shape [B, 1, Tq, Tk] for broadcasting across heads
|
|
171
|
+
|
|
172
|
+
def _prepare_text_input(
|
|
173
|
+
self, text: str
|
|
174
|
+
) -> tuple[mx.array, mx.array, mx.array, mx.array]:
|
|
175
|
+
"""Encodes text prompt, pads, and creates attention mask and positions."""
|
|
176
|
+
text_pad_value = self.config.data.text_pad_value
|
|
177
|
+
max_len = self.config.data.text_length
|
|
178
|
+
|
|
179
|
+
byte_text = text.encode("utf-8")
|
|
180
|
+
replaced_bytes = byte_text.replace(b"[S1]", b"\x01").replace(b"[S2]", b"\x02")
|
|
181
|
+
text_tokens = list(replaced_bytes)
|
|
182
|
+
|
|
183
|
+
current_len = len(text_tokens)
|
|
184
|
+
padding_needed = max_len - current_len
|
|
185
|
+
if padding_needed <= 0:
|
|
186
|
+
text_tokens = text_tokens[:max_len]
|
|
187
|
+
padded_text_np = np.array(text_tokens, dtype=np.uint8)
|
|
188
|
+
else:
|
|
189
|
+
padded_text_np = np.pad(
|
|
190
|
+
text_tokens,
|
|
191
|
+
(0, padding_needed),
|
|
192
|
+
mode="constant",
|
|
193
|
+
constant_values=text_pad_value,
|
|
194
|
+
).astype(np.uint8)
|
|
195
|
+
|
|
196
|
+
src_tokens = mx.array(padded_text_np, dtype=mx.int32)
|
|
197
|
+
src_tokens = mx.expand_dims(src_tokens, 0) # [1, S]
|
|
198
|
+
src_positions = mx.expand_dims(mx.arange(max_len, dtype=mx.int32), 0) # [1, S]
|
|
199
|
+
|
|
200
|
+
src_padding_mask = src_tokens != text_pad_value # [1, S]
|
|
201
|
+
|
|
202
|
+
enc_self_attn_mask = self._create_attn_mask(
|
|
203
|
+
src_padding_mask, src_padding_mask, is_causal=False
|
|
204
|
+
) # [1, S, S]
|
|
205
|
+
|
|
206
|
+
return src_tokens, src_positions, src_padding_mask, enc_self_attn_mask
|
|
207
|
+
|
|
208
|
+
def _split_turns(self, text: str) -> List[str]:
|
|
209
|
+
"""
|
|
210
|
+
Splits a conversation text into segments each containing a maximum of two [S1]/[S2] chunks.
|
|
211
|
+
"""
|
|
212
|
+
pattern = re.compile(
|
|
213
|
+
r"\[S1\]\s*(.*?)\s*\[S2\]\s*(.*?)(?=(?:\[S1\])|$)", re.DOTALL
|
|
214
|
+
)
|
|
215
|
+
segments = []
|
|
216
|
+
for s1_chunk, s2_chunk in pattern.findall(text):
|
|
217
|
+
segments.append(f"[S1] {s1_chunk.strip()} [S2] {s2_chunk.strip()}")
|
|
218
|
+
|
|
219
|
+
if len(segments) > 1:
|
|
220
|
+
merged_segments = []
|
|
221
|
+
for i in range(0, len(segments), 2):
|
|
222
|
+
if i + 1 < len(segments):
|
|
223
|
+
merged_segments.append(f"{segments[i]} {segments[i + 1]}")
|
|
224
|
+
else:
|
|
225
|
+
merged_segments.append(segments[i])
|
|
226
|
+
segments = merged_segments
|
|
227
|
+
|
|
228
|
+
return segments
|
|
229
|
+
|
|
230
|
+
def generate(
|
|
231
|
+
self,
|
|
232
|
+
text,
|
|
233
|
+
voice: Optional[str] = None,
|
|
234
|
+
temperature: float = 1.3,
|
|
235
|
+
top_p: float = 0.95,
|
|
236
|
+
split_pattern: str = "\n",
|
|
237
|
+
max_tokens: int | None = None,
|
|
238
|
+
verbose: bool = False,
|
|
239
|
+
ref_audio: Optional[mx.array] = None,
|
|
240
|
+
ref_text: Optional[str] = None,
|
|
241
|
+
**kwargs,
|
|
242
|
+
):
|
|
243
|
+
prompt = text.replace("\\n", "\n").replace("\\t", "\t")
|
|
244
|
+
prompts = prompt.split(split_pattern)
|
|
245
|
+
|
|
246
|
+
segments = []
|
|
247
|
+
for p in prompts:
|
|
248
|
+
if "[S1]" in p and "[S2]" in p:
|
|
249
|
+
segments.extend(self._split_turns(p))
|
|
250
|
+
else:
|
|
251
|
+
segments.append(p)
|
|
252
|
+
|
|
253
|
+
for segment_index, segment in enumerate(segments):
|
|
254
|
+
time_start = time.perf_counter()
|
|
255
|
+
|
|
256
|
+
audio, token_count = self._generate(
|
|
257
|
+
segment,
|
|
258
|
+
max_tokens=max_tokens,
|
|
259
|
+
ref_audio=ref_audio,
|
|
260
|
+
ref_text=ref_text,
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
time_end = time.perf_counter()
|
|
264
|
+
|
|
265
|
+
samples = audio.shape[0] if audio is not None else 0
|
|
266
|
+
assert samples > 0, "No audio generated"
|
|
267
|
+
|
|
268
|
+
sample_rate = self.config.model.sample_rate
|
|
269
|
+
audio_duration_seconds = samples / sample_rate
|
|
270
|
+
|
|
271
|
+
elapsed_time = time_end - time_start
|
|
272
|
+
rtf = (
|
|
273
|
+
elapsed_time / audio_duration_seconds
|
|
274
|
+
if audio_duration_seconds > 0
|
|
275
|
+
else 0
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
duration_mins = int(audio_duration_seconds // 60)
|
|
279
|
+
duration_secs = int(audio_duration_seconds % 60)
|
|
280
|
+
duration_ms = int((audio_duration_seconds % 1) * 1000)
|
|
281
|
+
duration_hours = int(audio_duration_seconds // 3600)
|
|
282
|
+
duration_str = f"{duration_hours:02d}:{duration_mins:02d}:{duration_secs:02d}.{duration_ms:03d}"
|
|
283
|
+
|
|
284
|
+
yield GenerationResult(
|
|
285
|
+
audio=audio,
|
|
286
|
+
samples=samples,
|
|
287
|
+
sample_rate=sample_rate,
|
|
288
|
+
segment_idx=segment_index,
|
|
289
|
+
token_count=token_count,
|
|
290
|
+
audio_duration=duration_str,
|
|
291
|
+
real_time_factor=rtf,
|
|
292
|
+
prompt={
|
|
293
|
+
"tokens": token_count,
|
|
294
|
+
"tokens-per-sec": (
|
|
295
|
+
round(token_count / elapsed_time, 2) if elapsed_time > 0 else 0
|
|
296
|
+
),
|
|
297
|
+
},
|
|
298
|
+
audio_samples={
|
|
299
|
+
"samples": samples,
|
|
300
|
+
"samples-per-sec": (
|
|
301
|
+
round(samples / elapsed_time, 2) if elapsed_time > 0 else 0
|
|
302
|
+
),
|
|
303
|
+
},
|
|
304
|
+
processing_time_seconds=time_end - time_start,
|
|
305
|
+
peak_memory_usage=mx.get_peak_memory() / 1e9,
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
# Clear cache after each segment to avoid memory leaks
|
|
309
|
+
mx.clear_cache()
|
|
310
|
+
|
|
311
|
+
def _generate(
|
|
312
|
+
self,
|
|
313
|
+
text: str,
|
|
314
|
+
max_tokens: Optional[int] = None,
|
|
315
|
+
cfg_scale: float = 3.0,
|
|
316
|
+
temperature: float = 1.3,
|
|
317
|
+
top_p: float = 0.95,
|
|
318
|
+
use_cfg_filter: bool = True,
|
|
319
|
+
cfg_filter_top_k: int = 35,
|
|
320
|
+
ref_audio: Optional[mx.array] = None,
|
|
321
|
+
ref_text: Optional[str] = None,
|
|
322
|
+
) -> np.ndarray:
|
|
323
|
+
"""
|
|
324
|
+
Generates audio from a text prompt (and optional audio prompt) using the Dia model.
|
|
325
|
+
|
|
326
|
+
Returns:
|
|
327
|
+
A numpy array of generated audio samples.
|
|
328
|
+
"""
|
|
329
|
+
num_channels = self.config.data.channels
|
|
330
|
+
audio_bos_value = int(self.config.data.audio_bos_value)
|
|
331
|
+
audio_eos_value = int(self.config.data.audio_eos_value)
|
|
332
|
+
audio_pad_value = int(self.config.data.audio_pad_value)
|
|
333
|
+
delay_pattern = self.config.data.delay_pattern
|
|
334
|
+
max_tokens = self.config.data.audio_length if max_tokens is None else max_tokens
|
|
335
|
+
delay_tensor = mx.array(delay_pattern, dtype=mx.int32)
|
|
336
|
+
max_delay_pattern = max(delay_pattern)
|
|
337
|
+
|
|
338
|
+
if ref_text is not None:
|
|
339
|
+
text = ref_text.strip() + " " + text
|
|
340
|
+
|
|
341
|
+
(
|
|
342
|
+
cond_src_BxS,
|
|
343
|
+
cond_src_positions_BxS,
|
|
344
|
+
cond_src_padding_mask_BxS,
|
|
345
|
+
cond_enc_self_attn_mask_Bx1xSxS,
|
|
346
|
+
) = self._prepare_text_input(text)
|
|
347
|
+
|
|
348
|
+
unc_src_BxS = mx.zeros_like(cond_src_BxS)
|
|
349
|
+
src_BxS = mx.concatenate([unc_src_BxS, cond_src_BxS], axis=0)
|
|
350
|
+
src_positions_BxS = mx.concatenate(
|
|
351
|
+
[cond_src_positions_BxS, cond_src_positions_BxS], axis=0
|
|
352
|
+
)
|
|
353
|
+
src_padding_mask_BxS = mx.concatenate(
|
|
354
|
+
[cond_src_padding_mask_BxS, cond_src_padding_mask_BxS], axis=0
|
|
355
|
+
)
|
|
356
|
+
enc_self_attn_mask_Bx1xSxS = mx.concatenate(
|
|
357
|
+
[cond_enc_self_attn_mask_Bx1xSxS, cond_enc_self_attn_mask_Bx1xSxS], axis=0
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
# 2. Encoder Pass
|
|
361
|
+
encoder_out = self.model.encoder(
|
|
362
|
+
x_ids=src_BxS,
|
|
363
|
+
src_positions=src_positions_BxS,
|
|
364
|
+
deterministic=True,
|
|
365
|
+
attn_mask=enc_self_attn_mask_Bx1xSxS,
|
|
366
|
+
) # Shape: (B, S, E)
|
|
367
|
+
|
|
368
|
+
# 3. Prepare Decoder Inputs
|
|
369
|
+
# 3-1. Allocate KV Cache (Static)
|
|
370
|
+
decoder_cross_attention_cache: list[KVCache] = (
|
|
371
|
+
self.model.decoder.precompute_cross_attention_kv(
|
|
372
|
+
max_tokens, encoder_out, src_positions_BxS
|
|
373
|
+
)
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
decoder_self_attention_cache: list[KVCache] = []
|
|
377
|
+
for _ in range(self.model.decoder.num_layers):
|
|
378
|
+
decoder_self_attention_cache.append(
|
|
379
|
+
KVCache(
|
|
380
|
+
self.config.model.decoder.gqa_query_heads,
|
|
381
|
+
max_tokens,
|
|
382
|
+
self.config.model.decoder.gqa_head_dim,
|
|
383
|
+
)
|
|
384
|
+
)
|
|
385
|
+
|
|
386
|
+
# 3-2. Initialize Decoder Inputs
|
|
387
|
+
generated_BxTxC = mx.full(
|
|
388
|
+
(2, 1, num_channels),
|
|
389
|
+
vals=audio_bos_value,
|
|
390
|
+
dtype=mx.int32,
|
|
391
|
+
)
|
|
392
|
+
|
|
393
|
+
current_step = 0
|
|
394
|
+
prompt_len_inc_bos = 1 # Start with BOS length
|
|
395
|
+
|
|
396
|
+
# 3-3. Load Audio Prompt (if provided)
|
|
397
|
+
if ref_audio is not None:
|
|
398
|
+
audio_prompt = mx.array(ref_audio)[None, None, ...] # 1, C, T
|
|
399
|
+
|
|
400
|
+
audio_prompt_codebook = audio_to_codebook(
|
|
401
|
+
self.dac_model, audio_prompt, data_config=self.config.data
|
|
402
|
+
)
|
|
403
|
+
audio_prompt_codebook = mx.concatenate(
|
|
404
|
+
[audio_prompt_codebook, audio_prompt_codebook], axis=0
|
|
405
|
+
)
|
|
406
|
+
generated_BxTxC = mx.concatenate(
|
|
407
|
+
[generated_BxTxC, audio_prompt_codebook], axis=1
|
|
408
|
+
)
|
|
409
|
+
|
|
410
|
+
prefill_len = generated_BxTxC.shape[1]
|
|
411
|
+
prompt_len_inc_bos = prefill_len
|
|
412
|
+
prefill_tgt_pos = mx.broadcast_to(
|
|
413
|
+
mx.expand_dims(mx.arange(prefill_len), 0), (2, prefill_len)
|
|
414
|
+
)
|
|
415
|
+
prefill_tgt_padding_mask = mx.any(
|
|
416
|
+
generated_BxTxC != audio_pad_value, axis=2
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
prefill_self_attn_mask = self._create_attn_mask(
|
|
420
|
+
prefill_tgt_padding_mask,
|
|
421
|
+
prefill_tgt_padding_mask,
|
|
422
|
+
is_causal=True,
|
|
423
|
+
)
|
|
424
|
+
prefill_cross_attn_mask = self._create_attn_mask(
|
|
425
|
+
prefill_tgt_padding_mask,
|
|
426
|
+
src_padding_mask_BxS,
|
|
427
|
+
is_causal=False,
|
|
428
|
+
)
|
|
429
|
+
|
|
430
|
+
_ = self.model.decoder(
|
|
431
|
+
tgt_ids_BxTxC=generated_BxTxC,
|
|
432
|
+
encoder_out=encoder_out,
|
|
433
|
+
tgt_positions=prefill_tgt_pos,
|
|
434
|
+
src_positions=src_positions_BxS,
|
|
435
|
+
deterministic=True,
|
|
436
|
+
self_attn_mask=prefill_self_attn_mask,
|
|
437
|
+
cross_attn_mask=prefill_cross_attn_mask,
|
|
438
|
+
self_attention_cache=decoder_self_attention_cache,
|
|
439
|
+
cross_attention_cache=decoder_cross_attention_cache,
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
current_step = prefill_len - 1
|
|
443
|
+
|
|
444
|
+
# 4. Autoregressive Generation Loop
|
|
445
|
+
eos_detected_channel_0 = False
|
|
446
|
+
eos_countdown = -1
|
|
447
|
+
extra_steps_after_eos = 30
|
|
448
|
+
|
|
449
|
+
# Make generated_BxTxC a fixed size tensor
|
|
450
|
+
# Length is either 1 + max tokens or 1 + prompt len + max tokens
|
|
451
|
+
padding = mx.full(
|
|
452
|
+
(2, max_tokens, num_channels),
|
|
453
|
+
vals=-1,
|
|
454
|
+
dtype=mx.int32,
|
|
455
|
+
)
|
|
456
|
+
generated_BxTxC = mx.concatenate([generated_BxTxC, padding], axis=1)
|
|
457
|
+
|
|
458
|
+
decode_step = self.model.decoder.decode_step
|
|
459
|
+
|
|
460
|
+
tgt_padding_mask = mx.any(
|
|
461
|
+
mx.expand_dims(generated_BxTxC[:, -1, :], 1) != audio_pad_value, axis=2
|
|
462
|
+
) # [B, 1]
|
|
463
|
+
|
|
464
|
+
# Generated tokens are never PAD, so we use fixed mask
|
|
465
|
+
decoder_cross_attn_mask = self._create_attn_mask(
|
|
466
|
+
tgt_padding_mask, # Query mask [B, 1]
|
|
467
|
+
src_padding_mask_BxS, # Key mask [B, S]
|
|
468
|
+
is_causal=False,
|
|
469
|
+
) # [B, 1, 1, S]
|
|
470
|
+
|
|
471
|
+
top_k = -1
|
|
472
|
+
if use_cfg_filter and cfg_filter_top_k is not None:
|
|
473
|
+
top_k = cfg_filter_top_k
|
|
474
|
+
sampler = make_sampler(temperature, top_p, top_k=top_k)
|
|
475
|
+
|
|
476
|
+
for step in trange(current_step, current_step + max_tokens):
|
|
477
|
+
tgt_ids_Bx1xC = mx.expand_dims(generated_BxTxC[:, step, :], 1)
|
|
478
|
+
tgt_pos_Bx1 = mx.full(
|
|
479
|
+
(2, 1),
|
|
480
|
+
vals=step,
|
|
481
|
+
dtype=mx.int32,
|
|
482
|
+
)
|
|
483
|
+
|
|
484
|
+
logits_Bx1xCxV = decode_step(
|
|
485
|
+
tgt_ids_Bx1xC=tgt_ids_Bx1xC,
|
|
486
|
+
tgt_pos_Bx1=tgt_pos_Bx1,
|
|
487
|
+
encoder_out=encoder_out,
|
|
488
|
+
self_attn_mask=None,
|
|
489
|
+
cross_attn_mask=decoder_cross_attn_mask,
|
|
490
|
+
self_attention_cache=decoder_self_attention_cache,
|
|
491
|
+
cross_attention_cache=decoder_cross_attention_cache,
|
|
492
|
+
)
|
|
493
|
+
|
|
494
|
+
V = self.config.model.tgt_vocab_size
|
|
495
|
+
logits_last_BxCxV = logits_Bx1xCxV[:, -1, :, :] # B, C, V
|
|
496
|
+
uncond_logits_CxV = logits_last_BxCxV[0, :, :]
|
|
497
|
+
cond_logits_CxV = logits_last_BxCxV[1, :, :]
|
|
498
|
+
|
|
499
|
+
cfg_logits_CxV = cond_logits_CxV + cfg_scale * (
|
|
500
|
+
cond_logits_CxV - uncond_logits_CxV
|
|
501
|
+
)
|
|
502
|
+
|
|
503
|
+
logits_CxV = mx.reshape(cfg_logits_CxV, (-1, V)) # C, V
|
|
504
|
+
|
|
505
|
+
# Create a mask for setting tokens beyond 1025 to -inf
|
|
506
|
+
inf_mask = mx.full(logits_CxV.shape, -float("inf"), dtype=logits_CxV.dtype)
|
|
507
|
+
keep_mask = mx.concatenate(
|
|
508
|
+
[
|
|
509
|
+
mx.ones((logits_CxV.shape[0], 1025)),
|
|
510
|
+
mx.zeros((logits_CxV.shape[0], logits_CxV.shape[1] - 1025)),
|
|
511
|
+
],
|
|
512
|
+
axis=1,
|
|
513
|
+
)
|
|
514
|
+
logits_CxV = mx.where(keep_mask == 1, logits_CxV, inf_mask)
|
|
515
|
+
|
|
516
|
+
# Sample next token
|
|
517
|
+
pred_C = _sample_next_token(
|
|
518
|
+
logits_CxV,
|
|
519
|
+
temperature=temperature,
|
|
520
|
+
sampler=sampler,
|
|
521
|
+
)
|
|
522
|
+
|
|
523
|
+
generation_step_index = step - current_step
|
|
524
|
+
if ref_audio is None:
|
|
525
|
+
pred_C = mx.where(
|
|
526
|
+
generation_step_index >= delay_tensor,
|
|
527
|
+
pred_C,
|
|
528
|
+
mx.full(pred_C.shape, audio_bos_value, dtype=pred_C.dtype),
|
|
529
|
+
)
|
|
530
|
+
|
|
531
|
+
# Update generated tokens for next step
|
|
532
|
+
pred_C_expanded = mx.broadcast_to(
|
|
533
|
+
mx.expand_dims(pred_C, 0), (2, num_channels)
|
|
534
|
+
)
|
|
535
|
+
|
|
536
|
+
# Split the tensor into parts: before the update, the update itself, and after the update
|
|
537
|
+
before_update = generated_BxTxC[:, : step + 1, :]
|
|
538
|
+
new_token = mx.expand_dims(
|
|
539
|
+
pred_C_expanded, 1
|
|
540
|
+
) # Shape: (2, 1, num_channels)
|
|
541
|
+
after_update = generated_BxTxC[:, step + 2 :, :]
|
|
542
|
+
generated_BxTxC = mx.concatenate(
|
|
543
|
+
[before_update, new_token, after_update], axis=1
|
|
544
|
+
)
|
|
545
|
+
|
|
546
|
+
if not eos_detected_channel_0 and pred_C[0] == audio_eos_value:
|
|
547
|
+
print(f"EOS detected at step {step} for channel 0")
|
|
548
|
+
eos_detected_channel_0 = True
|
|
549
|
+
eos_countdown = extra_steps_after_eos
|
|
550
|
+
|
|
551
|
+
if eos_countdown > 0:
|
|
552
|
+
step_after_eos = max_delay_pattern - eos_countdown
|
|
553
|
+
for i, d in enumerate(delay_pattern):
|
|
554
|
+
if step_after_eos == d:
|
|
555
|
+
# Update EOS token
|
|
556
|
+
# Create new array with updated value at position i in the current sequence
|
|
557
|
+
eos_values = mx.zeros((2, num_channels), dtype=mx.int32)
|
|
558
|
+
eos_values = eos_values.at[:, i].add(audio_eos_value)
|
|
559
|
+
# Replace the values at step+1
|
|
560
|
+
generated_BxTxC = generated_BxTxC.astype(mx.int32)
|
|
561
|
+
generated_BxTxC = generated_BxTxC.at[:, step + 1, :].add(
|
|
562
|
+
eos_values
|
|
563
|
+
)
|
|
564
|
+
elif step_after_eos > d:
|
|
565
|
+
# Update PAD token
|
|
566
|
+
# Create new array with updated value at position i in the current sequence
|
|
567
|
+
pad_values = mx.zeros((2, num_channels), dtype=mx.int32)
|
|
568
|
+
pad_values = pad_values.at[:, i].add(audio_pad_value)
|
|
569
|
+
# Replace the values at step+1
|
|
570
|
+
generated_BxTxC = generated_BxTxC.astype(mx.int32)
|
|
571
|
+
generated_BxTxC = generated_BxTxC.at[:, step + 1, :].add(
|
|
572
|
+
pad_values
|
|
573
|
+
)
|
|
574
|
+
|
|
575
|
+
eos_countdown -= 1
|
|
576
|
+
if eos_countdown == 0:
|
|
577
|
+
break
|
|
578
|
+
|
|
579
|
+
generation_step_index = step - current_step + 1
|
|
580
|
+
|
|
581
|
+
output_codes = generated_BxTxC[:, prompt_len_inc_bos : step + 1, :]
|
|
582
|
+
generated_codes = output_codes[0]
|
|
583
|
+
|
|
584
|
+
audio = codebook_to_audio(
|
|
585
|
+
generated_codes.transpose(1, 0),
|
|
586
|
+
self.dac_model,
|
|
587
|
+
delay_pattern,
|
|
588
|
+
B=1,
|
|
589
|
+
T=max_tokens,
|
|
590
|
+
C=num_channels,
|
|
591
|
+
)
|
|
592
|
+
return audio.squeeze(), generation_step_index
|