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,659 @@
|
|
|
1
|
+
import math
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from typing import List, Optional, Tuple, Union
|
|
4
|
+
|
|
5
|
+
import mlx.core as mx
|
|
6
|
+
import mlx.nn as nn
|
|
7
|
+
|
|
8
|
+
from ..base import BaseModelArgs
|
|
9
|
+
from .istftnet import AdainResBlk1d, ConvWeighted
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class LinearNorm(nn.Module):
|
|
13
|
+
def __init__(self, in_dim, out_dim, bias=True, w_init_gain="linear"):
|
|
14
|
+
super().__init__()
|
|
15
|
+
self.linear_layer = nn.Linear(in_dim, out_dim, bias=bias)
|
|
16
|
+
|
|
17
|
+
def __call__(self, x):
|
|
18
|
+
return self.linear_layer(x)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class TextEncoder(nn.Module):
|
|
22
|
+
def __init__(self, channels, kernel_size, depth, n_symbols, actv=nn.LeakyReLU(0.2)):
|
|
23
|
+
super().__init__()
|
|
24
|
+
self.embedding = nn.Embedding(n_symbols, channels)
|
|
25
|
+
padding = (kernel_size - 1) // 2
|
|
26
|
+
self.cnn = []
|
|
27
|
+
for _ in range(depth):
|
|
28
|
+
self.cnn.append(
|
|
29
|
+
[
|
|
30
|
+
ConvWeighted(
|
|
31
|
+
channels, channels, kernel_size=kernel_size, padding=padding
|
|
32
|
+
),
|
|
33
|
+
nn.LayerNorm(channels),
|
|
34
|
+
actv,
|
|
35
|
+
nn.Dropout(0.2),
|
|
36
|
+
]
|
|
37
|
+
)
|
|
38
|
+
# MLX doesn't have built-in LSTM, so we'll implement a simplified version
|
|
39
|
+
self.lstm = LSTM(channels, channels // 2)
|
|
40
|
+
|
|
41
|
+
def __call__(self, x, input_lengths, m):
|
|
42
|
+
x = self.embedding(x)
|
|
43
|
+
x = mx.transpose(x, (0, 2, 1))
|
|
44
|
+
m = mx.expand_dims(m, axis=1)
|
|
45
|
+
x = mx.where(m, 0.0, x)
|
|
46
|
+
|
|
47
|
+
for conv in self.cnn:
|
|
48
|
+
for layer in conv:
|
|
49
|
+
if isinstance(layer, (ConvWeighted, nn.LayerNorm)):
|
|
50
|
+
x = x.swapaxes(2, 1)
|
|
51
|
+
x = (
|
|
52
|
+
layer(x, mx.conv1d)
|
|
53
|
+
if isinstance(layer, ConvWeighted)
|
|
54
|
+
else layer(x)
|
|
55
|
+
)
|
|
56
|
+
x = x.swapaxes(2, 1)
|
|
57
|
+
else:
|
|
58
|
+
x = layer(x)
|
|
59
|
+
|
|
60
|
+
x = mx.where(m, 0.0, x)
|
|
61
|
+
|
|
62
|
+
x = x.swapaxes(2, 1)
|
|
63
|
+
x, _ = self.lstm(x)
|
|
64
|
+
x = x.swapaxes(2, 1)
|
|
65
|
+
x_pad = mx.zeros([x.shape[0], x.shape[1], m.shape[-1]])
|
|
66
|
+
x_pad[:, :, : x.shape[-1]] = x
|
|
67
|
+
x = mx.where(m, 0.0, x_pad)
|
|
68
|
+
return x
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class AdaLayerNorm(nn.Module):
|
|
72
|
+
# Works fine in MLX
|
|
73
|
+
def __init__(self, style_dim, channels, eps=1e-5):
|
|
74
|
+
super().__init__()
|
|
75
|
+
self.channels = channels
|
|
76
|
+
self.eps = eps
|
|
77
|
+
self.fc = nn.Linear(style_dim, channels * 2)
|
|
78
|
+
|
|
79
|
+
def __call__(self, x, s):
|
|
80
|
+
h = self.fc(s)
|
|
81
|
+
h = mx.reshape(h, (h.shape[0], h.shape[1], 1))
|
|
82
|
+
gamma, beta = mx.split(h, 2, axis=1)
|
|
83
|
+
gamma = gamma.transpose(2, 0, 1)
|
|
84
|
+
beta = beta.transpose(2, 0, 1)
|
|
85
|
+
|
|
86
|
+
mean = mx.mean(x, axis=-1, keepdims=True)
|
|
87
|
+
var = mx.var(x, axis=-1, keepdims=True)
|
|
88
|
+
x = (x - mean) / mx.sqrt(var + self.eps)
|
|
89
|
+
|
|
90
|
+
return (1 + gamma) * x + beta
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class LSTM(nn.Module):
|
|
94
|
+
def __init__(
|
|
95
|
+
self,
|
|
96
|
+
input_size: int,
|
|
97
|
+
hidden_size: int,
|
|
98
|
+
bias: bool = True,
|
|
99
|
+
batch_first: bool = True,
|
|
100
|
+
):
|
|
101
|
+
super().__init__()
|
|
102
|
+
|
|
103
|
+
self.input_size = input_size
|
|
104
|
+
self.hidden_size = hidden_size
|
|
105
|
+
self.bias = bias
|
|
106
|
+
self.batch_first = batch_first
|
|
107
|
+
# Initialize scale for weight initialization
|
|
108
|
+
scale = 1.0 / math.sqrt(hidden_size)
|
|
109
|
+
|
|
110
|
+
# Forward direction weights and biases
|
|
111
|
+
self.Wx_forward = mx.random.uniform(
|
|
112
|
+
low=-scale, high=scale, shape=(4 * hidden_size, input_size)
|
|
113
|
+
)
|
|
114
|
+
self.Wh_forward = mx.random.uniform(
|
|
115
|
+
low=-scale, high=scale, shape=(4 * hidden_size, hidden_size)
|
|
116
|
+
)
|
|
117
|
+
self.bias_ih_forward = (
|
|
118
|
+
mx.random.uniform(low=-scale, high=scale, shape=(4 * hidden_size,))
|
|
119
|
+
if bias
|
|
120
|
+
else None
|
|
121
|
+
)
|
|
122
|
+
self.bias_hh_forward = (
|
|
123
|
+
mx.random.uniform(low=-scale, high=scale, shape=(4 * hidden_size,))
|
|
124
|
+
if bias
|
|
125
|
+
else None
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
# Backward direction weights and biases
|
|
129
|
+
self.Wx_backward = mx.random.uniform(
|
|
130
|
+
low=-scale, high=scale, shape=(4 * hidden_size, input_size)
|
|
131
|
+
)
|
|
132
|
+
self.Wh_backward = mx.random.uniform(
|
|
133
|
+
low=-scale, high=scale, shape=(4 * hidden_size, hidden_size)
|
|
134
|
+
)
|
|
135
|
+
self.bias_ih_backward = (
|
|
136
|
+
mx.random.uniform(low=-scale, high=scale, shape=(4 * hidden_size,))
|
|
137
|
+
if bias
|
|
138
|
+
else None
|
|
139
|
+
)
|
|
140
|
+
self.bias_hh_backward = (
|
|
141
|
+
mx.random.uniform(low=-scale, high=scale, shape=(4 * hidden_size,))
|
|
142
|
+
if bias
|
|
143
|
+
else None
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
def _extra_repr(self):
|
|
147
|
+
return (
|
|
148
|
+
f"input_size={self.input_size}, "
|
|
149
|
+
f"hidden_size={self.hidden_size}, bias={self.bias}"
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
def _forward_direction(self, x, hidden=None, cell=None):
|
|
153
|
+
"""Process sequence in forward direction"""
|
|
154
|
+
# Pre-compute input projections
|
|
155
|
+
if self.bias_ih_forward is not None and self.bias_hh_forward is not None:
|
|
156
|
+
x_proj = mx.addmm(
|
|
157
|
+
self.bias_ih_forward + self.bias_hh_forward, x, self.Wx_forward.T
|
|
158
|
+
)
|
|
159
|
+
else:
|
|
160
|
+
x_proj = x @ self.Wx_forward.T
|
|
161
|
+
|
|
162
|
+
all_hidden = []
|
|
163
|
+
all_cell = []
|
|
164
|
+
|
|
165
|
+
seq_len = x.shape[-2]
|
|
166
|
+
|
|
167
|
+
# Initialize hidden and cell states if not provided
|
|
168
|
+
if hidden is None:
|
|
169
|
+
hidden = mx.zeros((x.shape[0], self.hidden_size))
|
|
170
|
+
if cell is None:
|
|
171
|
+
cell = mx.zeros((x.shape[0], self.hidden_size))
|
|
172
|
+
|
|
173
|
+
# Process sequence in forward direction (0 to seq_len-1)
|
|
174
|
+
for idx in range(seq_len):
|
|
175
|
+
ifgo = x_proj[..., idx, :]
|
|
176
|
+
ifgo = ifgo + hidden @ self.Wh_forward.T
|
|
177
|
+
|
|
178
|
+
# Split gates
|
|
179
|
+
i, f, g, o = mx.split(ifgo, 4, axis=-1)
|
|
180
|
+
|
|
181
|
+
# Apply activations
|
|
182
|
+
i = mx.sigmoid(i)
|
|
183
|
+
f = mx.sigmoid(f)
|
|
184
|
+
g = mx.tanh(g)
|
|
185
|
+
o = mx.sigmoid(o)
|
|
186
|
+
|
|
187
|
+
# Update cell and hidden states
|
|
188
|
+
cell = f * cell + i * g
|
|
189
|
+
hidden = o * mx.tanh(cell)
|
|
190
|
+
|
|
191
|
+
all_cell.append(cell)
|
|
192
|
+
all_hidden.append(hidden)
|
|
193
|
+
|
|
194
|
+
return mx.stack(all_hidden, axis=-2), mx.stack(all_cell, axis=-2)
|
|
195
|
+
|
|
196
|
+
def _backward_direction(self, x, hidden=None, cell=None):
|
|
197
|
+
"""Process sequence in backward direction"""
|
|
198
|
+
# Pre-compute input projections
|
|
199
|
+
if self.bias_ih_backward is not None and self.bias_hh_backward is not None:
|
|
200
|
+
x_proj = mx.addmm(
|
|
201
|
+
self.bias_ih_backward + self.bias_hh_backward, x, self.Wx_backward.T
|
|
202
|
+
)
|
|
203
|
+
else:
|
|
204
|
+
x_proj = x @ self.Wx_backward.T
|
|
205
|
+
|
|
206
|
+
all_hidden = []
|
|
207
|
+
all_cell = []
|
|
208
|
+
|
|
209
|
+
seq_len = x.shape[-2]
|
|
210
|
+
|
|
211
|
+
# Initialize hidden and cell states if not provided
|
|
212
|
+
if hidden is None:
|
|
213
|
+
hidden = mx.zeros((x.shape[0], self.hidden_size))
|
|
214
|
+
if cell is None:
|
|
215
|
+
cell = mx.zeros((x.shape[0], self.hidden_size))
|
|
216
|
+
|
|
217
|
+
# Process sequence in backward direction (seq_len-1 to 0)
|
|
218
|
+
for idx in range(seq_len - 1, -1, -1):
|
|
219
|
+
ifgo = x_proj[..., idx, :]
|
|
220
|
+
ifgo = ifgo + hidden @ self.Wh_backward.T
|
|
221
|
+
|
|
222
|
+
# Split gates
|
|
223
|
+
i, f, g, o = mx.split(ifgo, 4, axis=-1)
|
|
224
|
+
|
|
225
|
+
# Apply activations
|
|
226
|
+
i = mx.sigmoid(i)
|
|
227
|
+
f = mx.sigmoid(f)
|
|
228
|
+
g = mx.tanh(g)
|
|
229
|
+
o = mx.sigmoid(o)
|
|
230
|
+
|
|
231
|
+
# Update cell and hidden states
|
|
232
|
+
cell = f * cell + i * g
|
|
233
|
+
hidden = o * mx.tanh(cell)
|
|
234
|
+
|
|
235
|
+
# Insert at beginning to maintain original sequence order
|
|
236
|
+
all_cell.insert(0, cell)
|
|
237
|
+
all_hidden.insert(0, hidden)
|
|
238
|
+
|
|
239
|
+
return mx.stack(all_hidden, axis=-2), mx.stack(all_cell, axis=-2)
|
|
240
|
+
|
|
241
|
+
def __call__(
|
|
242
|
+
self,
|
|
243
|
+
x,
|
|
244
|
+
hidden_forward=None,
|
|
245
|
+
cell_forward=None,
|
|
246
|
+
hidden_backward=None,
|
|
247
|
+
cell_backward=None,
|
|
248
|
+
):
|
|
249
|
+
"""
|
|
250
|
+
Process input sequence in both directions and concatenate the results.
|
|
251
|
+
|
|
252
|
+
Args:
|
|
253
|
+
x: Input tensor of shape (batch_size, seq_len, input_size)
|
|
254
|
+
hidden_forward: Initial hidden state for forward direction
|
|
255
|
+
cell_forward: Initial cell state for forward direction
|
|
256
|
+
hidden_backward: Initial hidden state for backward direction
|
|
257
|
+
cell_backward: Initial cell state for backward direction
|
|
258
|
+
|
|
259
|
+
Returns:
|
|
260
|
+
Tuple of:
|
|
261
|
+
- Combined output hidden states (batch_size, seq_len, 2*hidden_size)
|
|
262
|
+
- Tuple of final states ((forward_hidden, forward_cell), (backward_hidden, backward_cell))
|
|
263
|
+
"""
|
|
264
|
+
|
|
265
|
+
if x.ndim == 2:
|
|
266
|
+
x = mx.expand_dims(x, axis=0) # (1, seq_len, input_size)
|
|
267
|
+
|
|
268
|
+
# Forward direction
|
|
269
|
+
forward_hidden, forward_cell = self._forward_direction(
|
|
270
|
+
x, hidden_forward, cell_forward
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
# Backward direction
|
|
274
|
+
backward_hidden, backward_cell = self._backward_direction(
|
|
275
|
+
x, hidden_backward, cell_backward
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
# Concatenate outputs along the feature dimension
|
|
279
|
+
output = mx.concatenate([forward_hidden, backward_hidden], axis=-1)
|
|
280
|
+
|
|
281
|
+
# Return combined output and final states for both directions
|
|
282
|
+
return output, (
|
|
283
|
+
(forward_hidden[..., -1, :], forward_cell[..., -1, :]),
|
|
284
|
+
(backward_hidden[..., 0, :], backward_cell[..., 0, :]),
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
class ProsodyPredictor(nn.Module):
|
|
289
|
+
def __init__(self, style_dim, d_hid, nlayers, max_dur=50, dropout=0.1):
|
|
290
|
+
super().__init__()
|
|
291
|
+
self.text_encoder = DurationEncoder(
|
|
292
|
+
sty_dim=style_dim, d_model=d_hid, nlayers=nlayers, dropout=dropout
|
|
293
|
+
)
|
|
294
|
+
self.lstm = LSTM(d_hid + style_dim, d_hid // 2)
|
|
295
|
+
self.duration_proj = LinearNorm(d_hid, max_dur)
|
|
296
|
+
self.shared = LSTM(d_hid + style_dim, d_hid // 2)
|
|
297
|
+
|
|
298
|
+
# F0 and N blocks
|
|
299
|
+
self.F0 = [
|
|
300
|
+
AdainResBlk1d(
|
|
301
|
+
d_hid, d_hid, style_dim, dropout_p=dropout, conv_type=mx.conv1d
|
|
302
|
+
),
|
|
303
|
+
AdainResBlk1d(
|
|
304
|
+
d_hid,
|
|
305
|
+
d_hid // 2,
|
|
306
|
+
style_dim,
|
|
307
|
+
upsample=True,
|
|
308
|
+
dropout_p=dropout,
|
|
309
|
+
conv_type=mx.conv1d,
|
|
310
|
+
),
|
|
311
|
+
AdainResBlk1d(
|
|
312
|
+
d_hid // 2,
|
|
313
|
+
d_hid // 2,
|
|
314
|
+
style_dim,
|
|
315
|
+
dropout_p=dropout,
|
|
316
|
+
conv_type=mx.conv1d,
|
|
317
|
+
),
|
|
318
|
+
]
|
|
319
|
+
|
|
320
|
+
self.N = [
|
|
321
|
+
AdainResBlk1d(
|
|
322
|
+
d_hid, d_hid, style_dim, dropout_p=dropout, conv_type=mx.conv1d
|
|
323
|
+
),
|
|
324
|
+
AdainResBlk1d(
|
|
325
|
+
d_hid,
|
|
326
|
+
d_hid // 2,
|
|
327
|
+
style_dim,
|
|
328
|
+
upsample=True,
|
|
329
|
+
dropout_p=dropout,
|
|
330
|
+
conv_type=mx.conv1d,
|
|
331
|
+
),
|
|
332
|
+
AdainResBlk1d(
|
|
333
|
+
d_hid // 2,
|
|
334
|
+
d_hid // 2,
|
|
335
|
+
style_dim,
|
|
336
|
+
dropout_p=dropout,
|
|
337
|
+
conv_type=mx.conv1d,
|
|
338
|
+
),
|
|
339
|
+
]
|
|
340
|
+
|
|
341
|
+
self.F0_proj = nn.Conv1d(d_hid // 2, 1, 1, padding=0)
|
|
342
|
+
self.N_proj = nn.Conv1d(d_hid // 2, 1, 1, padding=0)
|
|
343
|
+
|
|
344
|
+
def __call__(self, texts, style, text_lengths, alignment, m):
|
|
345
|
+
d = self.text_encoder(texts, style, text_lengths, m)
|
|
346
|
+
x, _ = self.lstm(d, text_lengths)
|
|
347
|
+
|
|
348
|
+
# Apply dropout during inference
|
|
349
|
+
x = mx.dropout(x, p=0.5)
|
|
350
|
+
|
|
351
|
+
duration = self.duration_proj(x)
|
|
352
|
+
en = mx.matmul(mx.transpose(d), alignment)
|
|
353
|
+
return mx.squeeze(duration, axis=-1), en
|
|
354
|
+
|
|
355
|
+
def F0Ntrain(self, x, s):
|
|
356
|
+
x = mx.array(x)
|
|
357
|
+
s = mx.array(s)
|
|
358
|
+
x, _ = self.shared(mx.transpose(x, (0, 2, 1)))
|
|
359
|
+
|
|
360
|
+
# F0 prediction
|
|
361
|
+
F0 = mx.transpose(x, (0, 2, 1))
|
|
362
|
+
for block in self.F0:
|
|
363
|
+
F0 = block(F0, s)
|
|
364
|
+
|
|
365
|
+
F0 = F0.swapaxes(2, 1)
|
|
366
|
+
F0 = self.F0_proj(F0)
|
|
367
|
+
F0 = F0.swapaxes(2, 1)
|
|
368
|
+
|
|
369
|
+
# N prediction
|
|
370
|
+
N = mx.transpose(x, (0, 2, 1))
|
|
371
|
+
for block in self.N:
|
|
372
|
+
N = block(N, s)
|
|
373
|
+
N = N.swapaxes(2, 1)
|
|
374
|
+
N = self.N_proj(N)
|
|
375
|
+
N = N.swapaxes(2, 1)
|
|
376
|
+
|
|
377
|
+
return mx.squeeze(F0, axis=1), mx.squeeze(N, axis=1)
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
class DurationEncoder(nn.Module):
|
|
381
|
+
def __init__(self, sty_dim, d_model, nlayers, dropout=0.1):
|
|
382
|
+
super().__init__()
|
|
383
|
+
self.lstms = []
|
|
384
|
+
for _ in range(nlayers):
|
|
385
|
+
self.lstms.extend(
|
|
386
|
+
[LSTM(d_model + sty_dim, d_model // 2), AdaLayerNorm(sty_dim, d_model)]
|
|
387
|
+
)
|
|
388
|
+
self.dropout = dropout
|
|
389
|
+
self.d_model = d_model
|
|
390
|
+
self.sty_dim = sty_dim
|
|
391
|
+
|
|
392
|
+
def __call__(self, x, style, text_lengths, m):
|
|
393
|
+
x = x.transpose(2, 0, 1)
|
|
394
|
+
s = mx.broadcast_to(style, (x.shape[0], x.shape[1], style.shape[-1]))
|
|
395
|
+
x = mx.concatenate([x, s], axis=-1)
|
|
396
|
+
x = mx.where(m[..., None].transpose(1, 0, 2), 0.0, x)
|
|
397
|
+
x = x.transpose(1, 2, 0)
|
|
398
|
+
|
|
399
|
+
for block in self.lstms:
|
|
400
|
+
if isinstance(block, AdaLayerNorm):
|
|
401
|
+
x = block(x.transpose(0, 2, 1), style).transpose(0, 2, 1)
|
|
402
|
+
x = mx.concatenate([x, s.transpose(1, 2, 0)], axis=1)
|
|
403
|
+
x = mx.where(m[..., None].transpose(0, 2, 1), 0.0, x)
|
|
404
|
+
else:
|
|
405
|
+
x = x.transpose(0, 2, 1)[0]
|
|
406
|
+
x, _ = block(x)
|
|
407
|
+
x = x.transpose(0, 2, 1)
|
|
408
|
+
x_pad = mx.zeros([x.shape[0], x.shape[1], m.shape[-1]])
|
|
409
|
+
x_pad[:, :, : x.shape[-1]] = x
|
|
410
|
+
x = x_pad
|
|
411
|
+
return x.transpose(0, 2, 1)
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
# https://github.com/yl4579/StyleTTS2/blob/main/Utils/PLBERT/util.py
|
|
415
|
+
# TODO: Implement this in MLX
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
@dataclass
|
|
419
|
+
class AlbertModelArgs(BaseModelArgs):
|
|
420
|
+
num_hidden_layers: int
|
|
421
|
+
num_attention_heads: int
|
|
422
|
+
hidden_size: int
|
|
423
|
+
intermediate_size: int
|
|
424
|
+
max_position_embeddings: int
|
|
425
|
+
model_type: str = "albert"
|
|
426
|
+
embedding_size: int = 128
|
|
427
|
+
inner_group_num: int = 1
|
|
428
|
+
num_hidden_groups: int = 1
|
|
429
|
+
hidden_dropout_prob: float = 0.1
|
|
430
|
+
attention_probs_dropout_prob: float = 0.1
|
|
431
|
+
type_vocab_size: int = 2
|
|
432
|
+
initializer_range: float = 0.02
|
|
433
|
+
layer_norm_eps: float = 1e-12
|
|
434
|
+
vocab_size: int = 30522
|
|
435
|
+
dropout: float = 0.0
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
class AlbertEmbeddings(nn.Module):
|
|
439
|
+
def __init__(self, config: AlbertModelArgs):
|
|
440
|
+
super().__init__()
|
|
441
|
+
self.word_embeddings = nn.Embedding(config.vocab_size, config.embedding_size)
|
|
442
|
+
self.position_embeddings = nn.Embedding(
|
|
443
|
+
config.max_position_embeddings, config.embedding_size
|
|
444
|
+
)
|
|
445
|
+
self.token_type_embeddings = nn.Embedding(
|
|
446
|
+
config.type_vocab_size, config.embedding_size
|
|
447
|
+
)
|
|
448
|
+
self.LayerNorm = nn.LayerNorm(config.embedding_size, eps=config.layer_norm_eps)
|
|
449
|
+
self.dropout = nn.Dropout(config.hidden_dropout_prob)
|
|
450
|
+
|
|
451
|
+
def __call__(self, input_ids, token_type_ids=None, position_ids=None):
|
|
452
|
+
seq_length = input_ids.shape[1]
|
|
453
|
+
if position_ids is None:
|
|
454
|
+
position_ids = mx.arange(seq_length, dtype=mx.int32)[None, :]
|
|
455
|
+
if token_type_ids is None:
|
|
456
|
+
token_type_ids = mx.zeros_like(input_ids)
|
|
457
|
+
|
|
458
|
+
words_embeddings = self.word_embeddings(input_ids)
|
|
459
|
+
position_embeddings = self.position_embeddings(position_ids)
|
|
460
|
+
token_type_embeddings = self.token_type_embeddings(token_type_ids)
|
|
461
|
+
|
|
462
|
+
embeddings = words_embeddings + position_embeddings + token_type_embeddings
|
|
463
|
+
embeddings = self.LayerNorm(embeddings)
|
|
464
|
+
embeddings = self.dropout(embeddings)
|
|
465
|
+
return embeddings
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
class AlbertSelfAttention(nn.Module):
|
|
469
|
+
def __init__(self, config: AlbertModelArgs):
|
|
470
|
+
super().__init__()
|
|
471
|
+
self.num_attention_heads = config.num_attention_heads
|
|
472
|
+
self.attention_head_size = int(config.hidden_size / config.num_attention_heads)
|
|
473
|
+
self.all_head_size = self.num_attention_heads * self.attention_head_size
|
|
474
|
+
|
|
475
|
+
self.query = nn.Linear(config.hidden_size, self.all_head_size)
|
|
476
|
+
self.key = nn.Linear(config.hidden_size, self.all_head_size)
|
|
477
|
+
self.value = nn.Linear(config.hidden_size, self.all_head_size)
|
|
478
|
+
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
|
|
479
|
+
|
|
480
|
+
self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
|
481
|
+
|
|
482
|
+
self.dropout = nn.Dropout(config.attention_probs_dropout_prob)
|
|
483
|
+
|
|
484
|
+
def transpose_for_scores(self, x):
|
|
485
|
+
new_x_shape = x.shape[:-1] + (
|
|
486
|
+
self.num_attention_heads,
|
|
487
|
+
self.attention_head_size,
|
|
488
|
+
)
|
|
489
|
+
x = x.reshape(new_x_shape)
|
|
490
|
+
return x.transpose(0, 2, 1, 3)
|
|
491
|
+
|
|
492
|
+
def __call__(self, hidden_states, attention_mask=None):
|
|
493
|
+
mixed_query_layer = self.query(hidden_states)
|
|
494
|
+
mixed_key_layer = self.key(hidden_states)
|
|
495
|
+
mixed_value_layer = self.value(hidden_states)
|
|
496
|
+
|
|
497
|
+
query_layer = self.transpose_for_scores(mixed_query_layer)
|
|
498
|
+
key_layer = self.transpose_for_scores(mixed_key_layer)
|
|
499
|
+
value_layer = self.transpose_for_scores(mixed_value_layer)
|
|
500
|
+
|
|
501
|
+
attention_scores = mx.matmul(query_layer, key_layer.transpose(0, 1, 3, 2))
|
|
502
|
+
attention_scores = attention_scores / math.sqrt(self.attention_head_size)
|
|
503
|
+
if attention_mask is not None:
|
|
504
|
+
attention_scores = attention_scores + attention_mask
|
|
505
|
+
|
|
506
|
+
attention_probs = mx.softmax(attention_scores, axis=-1)
|
|
507
|
+
attention_probs = self.dropout(attention_probs)
|
|
508
|
+
|
|
509
|
+
context_layer = mx.matmul(attention_probs, value_layer)
|
|
510
|
+
context_layer = context_layer.transpose(0, 2, 1, 3)
|
|
511
|
+
new_context_layer_shape = context_layer.shape[:-2] + (self.all_head_size,)
|
|
512
|
+
context_layer = context_layer.reshape(new_context_layer_shape)
|
|
513
|
+
|
|
514
|
+
context_layer = self.dense(context_layer)
|
|
515
|
+
context_layer = self.LayerNorm(context_layer + hidden_states)
|
|
516
|
+
|
|
517
|
+
return context_layer
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
class AlbertSelfOutput(nn.Module):
|
|
521
|
+
def __init__(self, config: AlbertModelArgs):
|
|
522
|
+
super().__init__()
|
|
523
|
+
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
|
|
524
|
+
self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
|
525
|
+
self.dropout = nn.Dropout(config.hidden_dropout_prob)
|
|
526
|
+
|
|
527
|
+
def __call__(self, hidden_states, input_tensor):
|
|
528
|
+
hidden_states = self.dense(hidden_states)
|
|
529
|
+
hidden_states = self.dropout(hidden_states)
|
|
530
|
+
hidden_states = self.LayerNorm(hidden_states + input_tensor)
|
|
531
|
+
return hidden_states
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
class AlbertIntermediate(nn.Module):
|
|
535
|
+
def __init__(self, config: AlbertModelArgs):
|
|
536
|
+
super().__init__()
|
|
537
|
+
self.dense = nn.Linear(config.hidden_size, config.intermediate_size)
|
|
538
|
+
self.intermediate_act_fn = nn.GELU()
|
|
539
|
+
|
|
540
|
+
def __call__(self, hidden_states):
|
|
541
|
+
hidden_states = self.dense(hidden_states)
|
|
542
|
+
hidden_states = self.intermediate_act_fn(hidden_states)
|
|
543
|
+
return hidden_states
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
class AlbertOutput(nn.Module):
|
|
547
|
+
def __init__(self, config: AlbertModelArgs):
|
|
548
|
+
super().__init__()
|
|
549
|
+
self.dense = nn.Linear(config.intermediate_size, config.hidden_size)
|
|
550
|
+
self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
|
551
|
+
self.dropout = nn.Dropout(config.hidden_dropout_prob)
|
|
552
|
+
|
|
553
|
+
def __call__(self, hidden_states, input_tensor):
|
|
554
|
+
hidden_states = self.dense(hidden_states)
|
|
555
|
+
hidden_states = self.dropout(hidden_states)
|
|
556
|
+
hidden_states = self.LayerNorm(hidden_states + input_tensor)
|
|
557
|
+
return hidden_states
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
class AlbertLayer(nn.Module):
|
|
561
|
+
def __init__(self, config: AlbertModelArgs):
|
|
562
|
+
super().__init__()
|
|
563
|
+
self.attention = AlbertSelfAttention(config)
|
|
564
|
+
|
|
565
|
+
self.seq_len_dim = 1
|
|
566
|
+
self.full_layer_layer_norm = nn.LayerNorm(
|
|
567
|
+
config.hidden_size, eps=config.layer_norm_eps
|
|
568
|
+
)
|
|
569
|
+
self.ffn = nn.Linear(config.hidden_size, config.intermediate_size)
|
|
570
|
+
self.ffn_output = nn.Linear(config.intermediate_size, config.hidden_size)
|
|
571
|
+
self.activation = nn.GELU()
|
|
572
|
+
|
|
573
|
+
def __call__(self, hidden_states, attention_mask=None):
|
|
574
|
+
attention_output = self.attention(hidden_states, attention_mask)
|
|
575
|
+
ffn_output = self.ff_chunk(attention_output)
|
|
576
|
+
hidden_states = self.full_layer_layer_norm(ffn_output + attention_output)
|
|
577
|
+
return hidden_states
|
|
578
|
+
|
|
579
|
+
def ff_chunk(self, attention_output: mx.array) -> mx.array:
|
|
580
|
+
ffn_output = self.ffn(attention_output)
|
|
581
|
+
ffn_output = self.activation(ffn_output)
|
|
582
|
+
ffn_output = self.ffn_output(ffn_output)
|
|
583
|
+
return ffn_output
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
class AlbertLayerGroup(nn.Module):
|
|
587
|
+
def __init__(self, config: AlbertModelArgs):
|
|
588
|
+
super().__init__()
|
|
589
|
+
self.albert_layers = [
|
|
590
|
+
AlbertLayer(config) for _ in range(config.inner_group_num)
|
|
591
|
+
]
|
|
592
|
+
|
|
593
|
+
def __call__(self, hidden_states, attention_mask=None):
|
|
594
|
+
for layer_module in self.albert_layers:
|
|
595
|
+
hidden_states = layer_module(hidden_states, attention_mask)
|
|
596
|
+
return hidden_states
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
class AlbertEncoder(nn.Module):
|
|
600
|
+
def __init__(self, config: AlbertModelArgs):
|
|
601
|
+
super().__init__()
|
|
602
|
+
self.config = config
|
|
603
|
+
self.embedding_hidden_mapping_in = nn.Linear(
|
|
604
|
+
config.embedding_size, config.hidden_size
|
|
605
|
+
)
|
|
606
|
+
self.albert_layer_groups = [
|
|
607
|
+
AlbertLayerGroup(config) for _ in range(config.num_hidden_groups)
|
|
608
|
+
]
|
|
609
|
+
|
|
610
|
+
def __call__(self, hidden_states, attention_mask=None):
|
|
611
|
+
hidden_states = self.embedding_hidden_mapping_in(hidden_states)
|
|
612
|
+
for i in range(self.config.num_hidden_layers):
|
|
613
|
+
# Number of layers in a hidden group
|
|
614
|
+
layers_per_group = int(
|
|
615
|
+
self.config.num_hidden_layers / self.config.num_hidden_groups
|
|
616
|
+
)
|
|
617
|
+
|
|
618
|
+
# Index of the hidden group
|
|
619
|
+
group_idx = int(
|
|
620
|
+
i / (self.config.num_hidden_layers / self.config.num_hidden_groups)
|
|
621
|
+
)
|
|
622
|
+
|
|
623
|
+
layer_group_output = self.albert_layer_groups[group_idx](
|
|
624
|
+
hidden_states, attention_mask
|
|
625
|
+
)
|
|
626
|
+
hidden_states = layer_group_output
|
|
627
|
+
return hidden_states
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
class CustomAlbert(nn.Module):
|
|
631
|
+
def __init__(self, config: AlbertModelArgs):
|
|
632
|
+
super().__init__()
|
|
633
|
+
self.config = config
|
|
634
|
+
self.embeddings = AlbertEmbeddings(config)
|
|
635
|
+
self.encoder = AlbertEncoder(config)
|
|
636
|
+
self.pooler = nn.Linear(config.hidden_size, config.hidden_size)
|
|
637
|
+
|
|
638
|
+
def __call__(self, input_ids, token_type_ids=None, attention_mask=None):
|
|
639
|
+
embedding_output = self.embeddings(input_ids, token_type_ids)
|
|
640
|
+
|
|
641
|
+
if attention_mask is not None:
|
|
642
|
+
attention_mask = attention_mask[:, None, None, :]
|
|
643
|
+
attention_mask = (1.0 - attention_mask) * -10000.0
|
|
644
|
+
|
|
645
|
+
encoder_outputs = self.encoder(embedding_output, attention_mask)
|
|
646
|
+
sequence_output = encoder_outputs
|
|
647
|
+
pooled_output = nn.tanh(self.pooler(sequence_output[:, 0]))
|
|
648
|
+
|
|
649
|
+
return sequence_output, pooled_output
|
|
650
|
+
|
|
651
|
+
def sanitize(self, weights):
|
|
652
|
+
sanitized_weights = {}
|
|
653
|
+
for k, v in weights.items():
|
|
654
|
+
if "position_ids" in k:
|
|
655
|
+
# Remove unused position_ids
|
|
656
|
+
continue
|
|
657
|
+
else:
|
|
658
|
+
sanitized_weights[k] = v
|
|
659
|
+
return sanitized_weights
|