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,256 @@
|
|
|
1
|
+
# Copyright (c) Kyutai, all rights reserved.
|
|
2
|
+
# This source code is licensed under the license found in the
|
|
3
|
+
# LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
|
|
9
|
+
import mlx.core as mx
|
|
10
|
+
import mlx.nn as nn
|
|
11
|
+
|
|
12
|
+
from .kv_cache import KVCache, RotatingKVCache
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass
|
|
16
|
+
class TransformerConfig:
|
|
17
|
+
d_model: int
|
|
18
|
+
num_heads: int
|
|
19
|
+
num_layers: int
|
|
20
|
+
causal: bool
|
|
21
|
+
norm_first: bool
|
|
22
|
+
bias_ff: bool
|
|
23
|
+
bias_attn: bool
|
|
24
|
+
layer_scale: float | None
|
|
25
|
+
positional_embedding: str
|
|
26
|
+
use_conv_block: bool
|
|
27
|
+
cross_attention: bool
|
|
28
|
+
conv_kernel_size: int
|
|
29
|
+
use_conv_bias: bool
|
|
30
|
+
gating: bool
|
|
31
|
+
norm: str
|
|
32
|
+
context: int
|
|
33
|
+
max_period: int
|
|
34
|
+
max_seq_len: int
|
|
35
|
+
kv_repeat: int
|
|
36
|
+
dim_feedforward: int
|
|
37
|
+
conv_layout: bool
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def head_dim(self) -> int:
|
|
41
|
+
return self.d_model // self.num_heads
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class Id(nn.Module):
|
|
45
|
+
def __init__(self):
|
|
46
|
+
super().__init__()
|
|
47
|
+
|
|
48
|
+
def __call__(self, xs: mx.array) -> mx.array:
|
|
49
|
+
return xs
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class LayerScale(nn.Module):
|
|
53
|
+
def __init__(self, dim: int):
|
|
54
|
+
super().__init__()
|
|
55
|
+
|
|
56
|
+
self.scale = mx.ones(dim)
|
|
57
|
+
|
|
58
|
+
def __call__(self, xs: mx.array) -> mx.array:
|
|
59
|
+
return xs * self.scale
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class Attention(nn.Module):
|
|
63
|
+
def __init__(self, cfg: TransformerConfig):
|
|
64
|
+
super().__init__()
|
|
65
|
+
|
|
66
|
+
num_kv = cfg.num_heads // cfg.kv_repeat
|
|
67
|
+
out_dim = cfg.d_model + 2 * num_kv * cfg.d_model // cfg.num_heads
|
|
68
|
+
self.cfg = cfg
|
|
69
|
+
self.in_proj = nn.Linear(cfg.d_model, out_dim, bias=cfg.bias_attn)
|
|
70
|
+
self.out_proj = nn.Linear(cfg.d_model, cfg.d_model, bias=cfg.bias_attn)
|
|
71
|
+
self.scale = cfg.head_dim ** (-0.5)
|
|
72
|
+
self.rope = None
|
|
73
|
+
if cfg.positional_embedding == "rope":
|
|
74
|
+
self.rope = nn.RoPE(cfg.head_dim, traditional=True, base=cfg.max_period)
|
|
75
|
+
|
|
76
|
+
def __call__(
|
|
77
|
+
self,
|
|
78
|
+
xs: mx.array,
|
|
79
|
+
cache: KVCache | RotatingKVCache,
|
|
80
|
+
mask: mx.array | None = None,
|
|
81
|
+
) -> mx.array:
|
|
82
|
+
assert self.cfg.kv_repeat == 1, "only kv_repeat==1 is supported"
|
|
83
|
+
|
|
84
|
+
b, t, hd = xs.shape
|
|
85
|
+
qkv = self.in_proj(xs).reshape(b, t, 3, self.cfg.num_heads, self.cfg.head_dim)
|
|
86
|
+
q = qkv[:, :, 0].transpose(0, 2, 1, 3)
|
|
87
|
+
k = qkv[:, :, 1].transpose(0, 2, 1, 3)
|
|
88
|
+
v = qkv[:, :, 2].transpose(0, 2, 1, 3)
|
|
89
|
+
if self.rope is not None:
|
|
90
|
+
q = self.rope(q, offset=cache.offset)
|
|
91
|
+
k = self.rope(k, offset=cache.offset)
|
|
92
|
+
|
|
93
|
+
k, v = cache.update_and_fetch(k, v)
|
|
94
|
+
k_len = k.shape[2]
|
|
95
|
+
k_target_len = t + min(self.cfg.context, k_len - t)
|
|
96
|
+
if k_target_len < k_len:
|
|
97
|
+
k = k[:, :, k_len - k_target_len :]
|
|
98
|
+
v = v[:, :, k_len - k_target_len :]
|
|
99
|
+
|
|
100
|
+
xs = mx.fast.scaled_dot_product_attention(q, k, v, scale=self.scale, mask=mask)
|
|
101
|
+
xs = xs.transpose(0, 2, 1, 3).reshape(b, t, hd)
|
|
102
|
+
xs = self.out_proj(xs)
|
|
103
|
+
return xs
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class MlpGating(nn.Module):
|
|
107
|
+
def __init__(self, cfg: TransformerConfig):
|
|
108
|
+
super().__init__()
|
|
109
|
+
|
|
110
|
+
hidden = 2 * cfg.dim_feedforward // 3
|
|
111
|
+
if cfg.dim_feedforward == 4 * cfg.d_model:
|
|
112
|
+
hidden = 11 * cfg.d_model // 4
|
|
113
|
+
|
|
114
|
+
self.linear_in = nn.Linear(cfg.d_model, 2 * hidden, bias=cfg.bias_ff)
|
|
115
|
+
self.linear_out = nn.Linear(hidden, cfg.d_model, bias=cfg.bias_ff)
|
|
116
|
+
|
|
117
|
+
def __call__(self, xs: mx.array) -> mx.array:
|
|
118
|
+
xs = self.linear_in(xs)
|
|
119
|
+
b, t, _ = xs.shape
|
|
120
|
+
xs = xs.reshape(b, t, 2, -1)
|
|
121
|
+
return self.linear_out(nn.silu(xs[:, :, 0]) * xs[:, :, 1])
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class MlpNoGating(nn.Module):
|
|
125
|
+
def __init__(self, cfg: TransformerConfig):
|
|
126
|
+
super().__init__()
|
|
127
|
+
|
|
128
|
+
self.linear1 = nn.Linear(cfg.d_model, cfg.dim_feedforward, bias=cfg.bias_ff)
|
|
129
|
+
self.linear2 = nn.Linear(cfg.dim_feedforward, cfg.d_model, bias=cfg.bias_ff)
|
|
130
|
+
|
|
131
|
+
def __call__(self, xs: mx.array) -> mx.array:
|
|
132
|
+
return self.linear2(nn.gelu_approx(self.linear1(xs)))
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class TransformerLayer(nn.Module):
|
|
136
|
+
def __init__(self, cfg: TransformerConfig):
|
|
137
|
+
super().__init__()
|
|
138
|
+
|
|
139
|
+
assert not cfg.use_conv_block, "conv-block is not supported"
|
|
140
|
+
assert not cfg.cross_attention, "cross-attn is not supported"
|
|
141
|
+
if cfg.gating:
|
|
142
|
+
self.gating = MlpGating(cfg)
|
|
143
|
+
else:
|
|
144
|
+
# TODO: Use a better name?
|
|
145
|
+
self.gating = MlpNoGating(cfg)
|
|
146
|
+
|
|
147
|
+
if cfg.norm == "layer_norm":
|
|
148
|
+
self.norm1 = nn.LayerNorm(cfg.d_model, 1e-5)
|
|
149
|
+
self.norm2 = nn.LayerNorm(cfg.d_model, 1e-5)
|
|
150
|
+
elif cfg.norm == "rms_norm":
|
|
151
|
+
self.norm1 = nn.RMSNorm(cfg.d_model, 1e-8)
|
|
152
|
+
self.norm2 = nn.RMSNorm(cfg.d_model, 1e-8)
|
|
153
|
+
else:
|
|
154
|
+
raise ValueError(f"unsupported norm type {cfg.norm}")
|
|
155
|
+
|
|
156
|
+
if cfg.layer_scale is not None:
|
|
157
|
+
self.layer_scale_1 = LayerScale(cfg.d_model)
|
|
158
|
+
self.layer_scale_2 = LayerScale(cfg.d_model)
|
|
159
|
+
else:
|
|
160
|
+
self.layer_scale_1 = Id()
|
|
161
|
+
self.layer_scale_2 = Id()
|
|
162
|
+
self.self_attn = Attention(cfg)
|
|
163
|
+
|
|
164
|
+
def __call__(
|
|
165
|
+
self,
|
|
166
|
+
xs: mx.array,
|
|
167
|
+
cache: KVCache | RotatingKVCache,
|
|
168
|
+
) -> mx.array:
|
|
169
|
+
n1 = self.norm1(xs)
|
|
170
|
+
n1 = self.self_attn(n1, cache=cache)
|
|
171
|
+
xs = xs + self.layer_scale_1(n1)
|
|
172
|
+
xs = xs + self.layer_scale_2(self.gating(self.norm2(xs)))
|
|
173
|
+
return xs
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
class Transformer(nn.Module):
|
|
177
|
+
def __init__(self, cfg: TransformerConfig):
|
|
178
|
+
super().__init__()
|
|
179
|
+
|
|
180
|
+
self.cfg = cfg
|
|
181
|
+
self.layers = [TransformerLayer(cfg=cfg) for _ in range(cfg.num_layers)]
|
|
182
|
+
|
|
183
|
+
def __call__(
|
|
184
|
+
self,
|
|
185
|
+
xs: mx.array,
|
|
186
|
+
cache: list[KVCache] | list[RotatingKVCache],
|
|
187
|
+
) -> mx.array:
|
|
188
|
+
for layer, c in zip(self.layers, cache):
|
|
189
|
+
xs = layer(xs, cache=c)
|
|
190
|
+
return xs
|
|
191
|
+
|
|
192
|
+
def make_cache(self) -> list[KVCache]:
|
|
193
|
+
num_kv_heads = self.cfg.num_heads // self.cfg.kv_repeat
|
|
194
|
+
return [
|
|
195
|
+
KVCache(head_dim=self.cfg.head_dim, n_kv_heads=num_kv_heads)
|
|
196
|
+
for _ in self.layers
|
|
197
|
+
]
|
|
198
|
+
|
|
199
|
+
def make_rot_cache(self) -> list[RotatingKVCache]:
|
|
200
|
+
num_kv_heads = self.cfg.num_heads // self.cfg.kv_repeat
|
|
201
|
+
return [
|
|
202
|
+
RotatingKVCache(
|
|
203
|
+
head_dim=self.cfg.head_dim,
|
|
204
|
+
n_kv_heads=num_kv_heads,
|
|
205
|
+
max_size=self.cfg.max_seq_len,
|
|
206
|
+
)
|
|
207
|
+
for _ in self.layers
|
|
208
|
+
]
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
class ProjectedTransformer(nn.Module):
|
|
212
|
+
def __init__(self, cfg: TransformerConfig, input_dim: int, output_dims: list[int]):
|
|
213
|
+
super().__init__()
|
|
214
|
+
|
|
215
|
+
self.conv_layout = cfg.conv_layout
|
|
216
|
+
self.transformer = Transformer(cfg)
|
|
217
|
+
if input_dim == cfg.d_model:
|
|
218
|
+
self.input_proj = None
|
|
219
|
+
else:
|
|
220
|
+
self.input_proj = nn.Linear(input_dim, cfg.d_model, bias=False)
|
|
221
|
+
|
|
222
|
+
output_projs = []
|
|
223
|
+
for output_dim in output_dims:
|
|
224
|
+
if output_dim == cfg.d_model:
|
|
225
|
+
p = None
|
|
226
|
+
else:
|
|
227
|
+
p = nn.Linear(cfg.d_model, output_dim, bias=False)
|
|
228
|
+
output_projs.append(p)
|
|
229
|
+
self.output_projs = output_projs
|
|
230
|
+
|
|
231
|
+
def __call__(
|
|
232
|
+
self,
|
|
233
|
+
xs: mx.array,
|
|
234
|
+
cache: list[KVCache] | list[RotatingKVCache],
|
|
235
|
+
) -> list[mx.array]:
|
|
236
|
+
if self.conv_layout:
|
|
237
|
+
xs = xs.swapaxes(1, 2)
|
|
238
|
+
if self.input_proj is not None:
|
|
239
|
+
xs = self.input_proj(xs)
|
|
240
|
+
xs = self.transformer(xs, cache=cache)
|
|
241
|
+
outs = []
|
|
242
|
+
for output_proj in self.output_projs:
|
|
243
|
+
if output_proj is None:
|
|
244
|
+
out = xs
|
|
245
|
+
else:
|
|
246
|
+
out = output_proj(xs)
|
|
247
|
+
if self.conv_layout:
|
|
248
|
+
out = out.swapaxes(1, 2)
|
|
249
|
+
outs.append(out)
|
|
250
|
+
return outs
|
|
251
|
+
|
|
252
|
+
def make_cache(self) -> list[KVCache]:
|
|
253
|
+
return self.transformer.make_cache()
|
|
254
|
+
|
|
255
|
+
def make_rot_cache(self) -> list[RotatingKVCache]:
|
|
256
|
+
return self.transformer.make_rot_cache()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .model_v2 import S3TokenizerV2
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import Iterable, Optional, Tuple
|
|
3
|
+
|
|
4
|
+
import mlx.core as mx
|
|
5
|
+
import mlx.nn as nn
|
|
6
|
+
import numpy as np
|
|
7
|
+
from einops.array_api import rearrange
|
|
8
|
+
|
|
9
|
+
from .utils import make_non_pad_mask, mask_to_bias
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class ModelConfig:
|
|
14
|
+
n_mels: int = 128
|
|
15
|
+
n_audio_ctx: int = 1500
|
|
16
|
+
n_audio_state: int = 1280
|
|
17
|
+
n_audio_head: int = 20
|
|
18
|
+
n_audio_layer: int = 6
|
|
19
|
+
n_codebook_size: int = 4096
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def sinusoids(length: int, channels: int, max_timescale: float = 10000) -> mx.array:
|
|
23
|
+
"""Returns sinusoids for positional embedding"""
|
|
24
|
+
assert channels % 2 == 0
|
|
25
|
+
log_timescale_increment = np.log(max_timescale) / (channels // 2 - 1)
|
|
26
|
+
inv_timescales = mx.exp(-log_timescale_increment * mx.arange(channels // 2))
|
|
27
|
+
scaled_time = mx.arange(length)[:, None] * inv_timescales[None, :]
|
|
28
|
+
return mx.concatenate([mx.sin(scaled_time), mx.cos(scaled_time)], axis=1)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class MultiHeadAttention(nn.Module):
|
|
32
|
+
def __init__(self, n_state: int, n_head: int):
|
|
33
|
+
super().__init__()
|
|
34
|
+
self.n_head = n_head
|
|
35
|
+
self.query = nn.Linear(n_state, n_state)
|
|
36
|
+
self.key = nn.Linear(n_state, n_state, bias=False)
|
|
37
|
+
self.value = nn.Linear(n_state, n_state)
|
|
38
|
+
self.out = nn.Linear(n_state, n_state)
|
|
39
|
+
|
|
40
|
+
def __call__(
|
|
41
|
+
self,
|
|
42
|
+
x: mx.array,
|
|
43
|
+
mask: Optional[mx.array] = None,
|
|
44
|
+
) -> Tuple[mx.array, mx.array]:
|
|
45
|
+
q = self.query(x)
|
|
46
|
+
k = self.key(x)
|
|
47
|
+
v = self.value(x)
|
|
48
|
+
|
|
49
|
+
wv, qk = self.qkv_attention(q, k, v, mask)
|
|
50
|
+
return self.out(wv), qk
|
|
51
|
+
|
|
52
|
+
def qkv_attention(
|
|
53
|
+
self, q: mx.array, k: mx.array, v: mx.array, mask: Optional[mx.array] = None
|
|
54
|
+
) -> Tuple[mx.array, mx.array | None]:
|
|
55
|
+
B, T, D = q.shape
|
|
56
|
+
scale = (D // self.n_head) ** -0.25
|
|
57
|
+
|
|
58
|
+
q = q.reshape(B, T, self.n_head, -1).transpose(0, 2, 1, 3) * scale
|
|
59
|
+
k = k.reshape(B, T, self.n_head, -1).transpose(0, 2, 1, 3) * scale
|
|
60
|
+
v = v.reshape(B, T, self.n_head, -1).transpose(0, 2, 1, 3)
|
|
61
|
+
|
|
62
|
+
output = mx.fast.scaled_dot_product_attention(q, k, v, scale=1, mask=mask)
|
|
63
|
+
output = output.transpose(0, 2, 1, 3).reshape(B, T, D)
|
|
64
|
+
return output, None
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class ResidualAttentionBlock(nn.Module):
|
|
68
|
+
def __init__(self, n_state: int, n_head: int):
|
|
69
|
+
super().__init__()
|
|
70
|
+
|
|
71
|
+
self.attn = MultiHeadAttention(n_state, n_head)
|
|
72
|
+
self.attn_ln = nn.LayerNorm(n_state)
|
|
73
|
+
|
|
74
|
+
n_mlp = n_state * 4
|
|
75
|
+
self.mlp = nn.Sequential(
|
|
76
|
+
nn.Linear(n_state, n_mlp), nn.GELU(), nn.Linear(n_mlp, n_state)
|
|
77
|
+
)
|
|
78
|
+
self.mlp_ln = nn.LayerNorm(n_state)
|
|
79
|
+
|
|
80
|
+
def __call__(
|
|
81
|
+
self,
|
|
82
|
+
x: mx.array,
|
|
83
|
+
mask: Optional[mx.array] = None,
|
|
84
|
+
) -> mx.array:
|
|
85
|
+
x = x + self.attn(self.attn_ln(x), mask=mask)[0]
|
|
86
|
+
x = x + self.mlp(self.mlp_ln(x))
|
|
87
|
+
return x
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class AudioEncoder(nn.Module):
|
|
91
|
+
def __init__(
|
|
92
|
+
self,
|
|
93
|
+
n_mels: int,
|
|
94
|
+
n_ctx: int,
|
|
95
|
+
n_state: int,
|
|
96
|
+
n_head: int,
|
|
97
|
+
n_layer: int,
|
|
98
|
+
stride: int,
|
|
99
|
+
):
|
|
100
|
+
super().__init__()
|
|
101
|
+
self.stride = stride
|
|
102
|
+
|
|
103
|
+
self.conv1 = nn.Conv1d(
|
|
104
|
+
in_channels=n_mels,
|
|
105
|
+
out_channels=n_state,
|
|
106
|
+
kernel_size=3,
|
|
107
|
+
stride=stride,
|
|
108
|
+
padding=1,
|
|
109
|
+
)
|
|
110
|
+
self.conv2 = nn.Conv1d(
|
|
111
|
+
in_channels=n_state,
|
|
112
|
+
out_channels=n_state,
|
|
113
|
+
kernel_size=3,
|
|
114
|
+
stride=2,
|
|
115
|
+
padding=1,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
self.positional_embedding = sinusoids(n_ctx, n_state)
|
|
119
|
+
|
|
120
|
+
self.blocks = [ResidualAttentionBlock(n_state, n_head) for _ in range(n_layer)]
|
|
121
|
+
|
|
122
|
+
def __call__(self, x: mx.array, x_len: mx.array) -> Tuple[mx.array, mx.array]:
|
|
123
|
+
"""
|
|
124
|
+
x : mx.array, shape = (batch_size, n_mels, T)
|
|
125
|
+
the mel spectrogram of the audio
|
|
126
|
+
x_len: mx.array, shape = (batch_size,)
|
|
127
|
+
length of each audio in x
|
|
128
|
+
"""
|
|
129
|
+
mask = make_non_pad_mask(x_len)
|
|
130
|
+
mask = mx.expand_dims(mask, axis=1) # (B, 1, T)
|
|
131
|
+
|
|
132
|
+
x = x.transpose(0, 2, 1) # (B, T, n_mels)
|
|
133
|
+
mask_transposed = mask.transpose(0, 2, 1) # (B, T, 1)
|
|
134
|
+
|
|
135
|
+
x = self.conv1(x * mask_transposed)
|
|
136
|
+
x = nn.gelu(x)
|
|
137
|
+
x_len = (x_len + 2 - 1 * (3 - 1) - 1) // self.stride + 1
|
|
138
|
+
|
|
139
|
+
mask = make_non_pad_mask(x_len)
|
|
140
|
+
mask_transposed = mx.expand_dims(mask, axis=-1) # (B, T, 1)
|
|
141
|
+
x = self.conv2(x * mask_transposed)
|
|
142
|
+
x = nn.gelu(x)
|
|
143
|
+
|
|
144
|
+
x_len = (x_len + 2 - 1 * (3 - 1) - 1) // 2 + 1
|
|
145
|
+
|
|
146
|
+
mask = make_non_pad_mask(x_len)
|
|
147
|
+
mask = mask_to_bias(mask, x.dtype)
|
|
148
|
+
mask = mx.expand_dims(mask, axis=1) # (B, 1, T)
|
|
149
|
+
|
|
150
|
+
x = x + self.positional_embedding[: x.shape[1], :]
|
|
151
|
+
|
|
152
|
+
for block in self.blocks:
|
|
153
|
+
x = block(x, mx.expand_dims(mask, axis=1))
|
|
154
|
+
|
|
155
|
+
return x, x_len
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class EuclideanCodebook(nn.Module):
|
|
159
|
+
"""Codebook with Euclidean distance.
|
|
160
|
+
Args:
|
|
161
|
+
dim (int): Dimension.
|
|
162
|
+
codebook_size (int): Codebook size.
|
|
163
|
+
"""
|
|
164
|
+
|
|
165
|
+
def __init__(self, dim: int, codebook_size: int):
|
|
166
|
+
super().__init__()
|
|
167
|
+
self.codebook_size = codebook_size
|
|
168
|
+
self.embed = mx.zeros((codebook_size, dim))
|
|
169
|
+
|
|
170
|
+
def preprocess(self, x: mx.array) -> mx.array:
|
|
171
|
+
x = rearrange(x, "... d -> (...) d")
|
|
172
|
+
return x
|
|
173
|
+
|
|
174
|
+
def quantize(self, x: mx.array) -> mx.array:
|
|
175
|
+
embed = self.embed.T
|
|
176
|
+
dist = -(
|
|
177
|
+
mx.sum(x.astype(mx.float32) ** 2, axis=1, keepdims=True)
|
|
178
|
+
- 2 * x @ embed
|
|
179
|
+
+ mx.sum(embed.astype(mx.float32) ** 2, axis=0, keepdims=True)
|
|
180
|
+
)
|
|
181
|
+
embed_ind = mx.argmax(dist, axis=-1)
|
|
182
|
+
return embed_ind
|
|
183
|
+
|
|
184
|
+
def postprocess_emb(self, embed_ind: mx.array, shape: tuple) -> mx.array:
|
|
185
|
+
return embed_ind.reshape(*shape[:-1])
|
|
186
|
+
|
|
187
|
+
def dequantize(self, embed_ind: mx.array) -> mx.array:
|
|
188
|
+
quantize = self.embed[embed_ind]
|
|
189
|
+
return quantize
|
|
190
|
+
|
|
191
|
+
def encode(self, x: mx.array) -> mx.array:
|
|
192
|
+
shape = x.shape
|
|
193
|
+
# pre-process
|
|
194
|
+
x = self.preprocess(x)
|
|
195
|
+
# quantize
|
|
196
|
+
embed_ind = self.quantize(x)
|
|
197
|
+
# post-process
|
|
198
|
+
embed_ind = self.postprocess_emb(embed_ind, shape)
|
|
199
|
+
return embed_ind
|
|
200
|
+
|
|
201
|
+
def decode(self, embed_ind: mx.array) -> mx.array:
|
|
202
|
+
quantize = self.dequantize(embed_ind)
|
|
203
|
+
return quantize
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
class VectorQuantization(nn.Module):
|
|
207
|
+
"""Vector quantization implementation
|
|
208
|
+
Args:
|
|
209
|
+
dim (int): Dimension
|
|
210
|
+
codebook_size (int): Codebook size
|
|
211
|
+
"""
|
|
212
|
+
|
|
213
|
+
def __init__(self, dim: int, codebook_size: int):
|
|
214
|
+
super().__init__()
|
|
215
|
+
self._codebook = EuclideanCodebook(dim=dim, codebook_size=codebook_size)
|
|
216
|
+
self.codebook_size = codebook_size
|
|
217
|
+
|
|
218
|
+
@property
|
|
219
|
+
def codebook(self):
|
|
220
|
+
return self._codebook.embed
|
|
221
|
+
|
|
222
|
+
def encode(self, x: mx.array) -> mx.array:
|
|
223
|
+
x = x / mx.sqrt(mx.sum(x**2, axis=-1, keepdims=True) + 1e-8)
|
|
224
|
+
embed_in = self._codebook.encode(x)
|
|
225
|
+
return embed_in
|
|
226
|
+
|
|
227
|
+
def decode(self, embed_ind: mx.array) -> mx.array:
|
|
228
|
+
quantize = self._codebook.decode(embed_ind)
|
|
229
|
+
quantize = rearrange(quantize, "b n d -> b d n")
|
|
230
|
+
return quantize
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
class S3Tokenizer(nn.Module):
|
|
234
|
+
"""S3 tokenizer implementation
|
|
235
|
+
Args:
|
|
236
|
+
config (ModelConfig): Config
|
|
237
|
+
"""
|
|
238
|
+
|
|
239
|
+
def __init__(self, name: str, config: ModelConfig = ModelConfig()):
|
|
240
|
+
super().__init__()
|
|
241
|
+
self.config = config
|
|
242
|
+
self.encoder = AudioEncoder(
|
|
243
|
+
self.config.n_mels,
|
|
244
|
+
self.config.n_audio_ctx,
|
|
245
|
+
self.config.n_audio_state,
|
|
246
|
+
self.config.n_audio_head,
|
|
247
|
+
self.config.n_audio_layer,
|
|
248
|
+
2 if name == "speech_tokenizer_v1_25hz" else 1,
|
|
249
|
+
)
|
|
250
|
+
self.quantizer = VectorQuantization(
|
|
251
|
+
self.config.n_audio_state, self.config.n_codebook_size
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
def __call__(self, mel: mx.array, mel_len: mx.array) -> Tuple[mx.array, mx.array]:
|
|
255
|
+
return self.quantize(mel, mel_len)
|
|
256
|
+
|
|
257
|
+
def quantize(self, mel: mx.array, mel_len: mx.array) -> Tuple[mx.array, mx.array]:
|
|
258
|
+
hidden, code_len = self.encoder(mel, mel_len)
|
|
259
|
+
code = self.quantizer.encode(hidden)
|
|
260
|
+
return code, code_len
|