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,283 @@
|
|
|
1
|
+
# Copyright (c) 2021 Zhengyang Chen (chenzhengyang117@gmail.com)
|
|
2
|
+
# 2022 Hongji Wang (jijijiang77@gmail.com)
|
|
3
|
+
# 2023 Bing Han (hanbing97@sjtu.edu.cn)
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
""" This implementation is adapted from github repo:
|
|
18
|
+
https://github.com/lawlict/ECAPA-TDNN.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
import mlx.core as mx
|
|
22
|
+
import mlx.nn as nn
|
|
23
|
+
|
|
24
|
+
from mlx_audio.tts.models.spark.modules.speaker import pooling_layers as pooling_layers
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Res2Conv1dReluBn(nn.Module):
|
|
28
|
+
"""
|
|
29
|
+
in_channels == out_channels == channels
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def __init__(
|
|
33
|
+
self,
|
|
34
|
+
channels,
|
|
35
|
+
kernel_size=1,
|
|
36
|
+
stride=1,
|
|
37
|
+
padding=0,
|
|
38
|
+
dilation=1,
|
|
39
|
+
bias=True,
|
|
40
|
+
scale=4,
|
|
41
|
+
):
|
|
42
|
+
super().__init__()
|
|
43
|
+
assert channels % scale == 0, "{} % {} != 0".format(channels, scale)
|
|
44
|
+
self.scale = scale
|
|
45
|
+
self.width = channels // scale
|
|
46
|
+
self.channels = channels
|
|
47
|
+
self.nums = scale if scale == 1 else scale - 1
|
|
48
|
+
|
|
49
|
+
self.convs = []
|
|
50
|
+
self.bns = []
|
|
51
|
+
for i in range(self.nums):
|
|
52
|
+
self.convs.append(
|
|
53
|
+
nn.Conv1d(
|
|
54
|
+
self.width,
|
|
55
|
+
self.width,
|
|
56
|
+
kernel_size,
|
|
57
|
+
stride,
|
|
58
|
+
padding,
|
|
59
|
+
dilation,
|
|
60
|
+
bias=bias,
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
self.bns.append(nn.BatchNorm(self.width))
|
|
64
|
+
# self.convs = [*self.convs] # nn.ModuleList(self.convs)
|
|
65
|
+
# self.bns = [*self.bns] # nn.ModuleList(self.bns)
|
|
66
|
+
|
|
67
|
+
def __call__(self, x):
|
|
68
|
+
out = []
|
|
69
|
+
|
|
70
|
+
spx = mx.split(x, self.scale, axis=1)
|
|
71
|
+
sp = spx[0]
|
|
72
|
+
for i, (conv, bn) in enumerate(zip(self.convs, self.bns)):
|
|
73
|
+
# Order: conv -> relu -> bn
|
|
74
|
+
if i >= 1:
|
|
75
|
+
sp = sp + spx[i]
|
|
76
|
+
|
|
77
|
+
sp = conv(sp.transpose(0, 2, 1))
|
|
78
|
+
sp = bn(nn.relu(sp)).transpose(0, 2, 1)
|
|
79
|
+
out.append(sp)
|
|
80
|
+
if self.scale != 1:
|
|
81
|
+
out.append(spx[self.nums])
|
|
82
|
+
out = mx.concatenate(out, axis=1)
|
|
83
|
+
return out
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
""" Conv1d + BatchNorm1d + ReLU
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class Conv1dReluBn(nn.Module):
|
|
91
|
+
|
|
92
|
+
def __init__(
|
|
93
|
+
self,
|
|
94
|
+
in_channels,
|
|
95
|
+
out_channels,
|
|
96
|
+
kernel_size=1,
|
|
97
|
+
stride=1,
|
|
98
|
+
padding=0,
|
|
99
|
+
dilation=1,
|
|
100
|
+
bias=True,
|
|
101
|
+
):
|
|
102
|
+
super().__init__()
|
|
103
|
+
self.conv = nn.Conv1d(
|
|
104
|
+
in_channels, out_channels, kernel_size, stride, padding, dilation, bias=bias
|
|
105
|
+
)
|
|
106
|
+
self.bn = nn.BatchNorm(out_channels)
|
|
107
|
+
|
|
108
|
+
def __call__(self, x):
|
|
109
|
+
x = self.conv(x.swapaxes(1, 2)).swapaxes(1, 2)
|
|
110
|
+
x = nn.relu(x)
|
|
111
|
+
x = self.bn(x.swapaxes(1, 2)).swapaxes(1, 2)
|
|
112
|
+
return x
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
""" The SE connection of 1D case.
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class SE_Connect(nn.Module):
|
|
120
|
+
|
|
121
|
+
def __init__(self, channels, se_bottleneck_dim=128):
|
|
122
|
+
super().__init__()
|
|
123
|
+
self.linear1 = nn.Linear(channels, se_bottleneck_dim)
|
|
124
|
+
self.linear2 = nn.Linear(se_bottleneck_dim, channels)
|
|
125
|
+
|
|
126
|
+
def __call__(self, x):
|
|
127
|
+
out = mx.mean(x, axis=2)
|
|
128
|
+
out = nn.relu(self.linear1(out))
|
|
129
|
+
out = mx.sigmoid(self.linear2(out))
|
|
130
|
+
out = x * out[:, :, None]
|
|
131
|
+
return out
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
""" SE-Res2Block of the ECAPA-TDNN architecture.
|
|
135
|
+
"""
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
class SE_Res2Block(nn.Module):
|
|
139
|
+
|
|
140
|
+
def __init__(self, channels, kernel_size, stride, padding, dilation, scale):
|
|
141
|
+
super().__init__()
|
|
142
|
+
self.se_res2block = [
|
|
143
|
+
Conv1dReluBn(channels, channels, kernel_size=1, stride=1, padding=0),
|
|
144
|
+
Res2Conv1dReluBn(
|
|
145
|
+
channels, kernel_size, stride, padding, dilation, scale=scale
|
|
146
|
+
),
|
|
147
|
+
Conv1dReluBn(channels, channels, kernel_size=1, stride=1, padding=0),
|
|
148
|
+
SE_Connect(channels),
|
|
149
|
+
]
|
|
150
|
+
|
|
151
|
+
def __call__(self, x):
|
|
152
|
+
res = x
|
|
153
|
+
for module in self.se_res2block:
|
|
154
|
+
x = module(x)
|
|
155
|
+
return x + res
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class ECAPA_TDNN(nn.Module):
|
|
159
|
+
|
|
160
|
+
def __init__(
|
|
161
|
+
self,
|
|
162
|
+
channels=512,
|
|
163
|
+
feat_dim=80,
|
|
164
|
+
embed_dim=192,
|
|
165
|
+
pooling_func="ASTP",
|
|
166
|
+
global_context_att=False,
|
|
167
|
+
emb_bn=False,
|
|
168
|
+
):
|
|
169
|
+
super().__init__()
|
|
170
|
+
|
|
171
|
+
self.layer1 = Conv1dReluBn(feat_dim, channels, kernel_size=5, padding=2)
|
|
172
|
+
self.layer2 = SE_Res2Block(
|
|
173
|
+
channels, kernel_size=3, stride=1, padding=2, dilation=2, scale=8
|
|
174
|
+
)
|
|
175
|
+
self.layer3 = SE_Res2Block(
|
|
176
|
+
channels, kernel_size=3, stride=1, padding=3, dilation=3, scale=8
|
|
177
|
+
)
|
|
178
|
+
self.layer4 = SE_Res2Block(
|
|
179
|
+
channels, kernel_size=3, stride=1, padding=4, dilation=4, scale=8
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
cat_channels = channels * 3
|
|
183
|
+
out_channels = 512 * 3
|
|
184
|
+
self.conv = nn.Conv1d(cat_channels, out_channels, kernel_size=1)
|
|
185
|
+
self.pool = getattr(pooling_layers, pooling_func)(
|
|
186
|
+
in_dim=out_channels, global_context_att=global_context_att
|
|
187
|
+
)
|
|
188
|
+
self.pool_out_dim = self.pool.get_out_dim()
|
|
189
|
+
self.bn = nn.BatchNorm(self.pool_out_dim)
|
|
190
|
+
self.linear = nn.Linear(self.pool_out_dim, embed_dim)
|
|
191
|
+
self.emb_bn = emb_bn
|
|
192
|
+
if emb_bn: # better in SSL for SV
|
|
193
|
+
self.bn2 = nn.BatchNorm(embed_dim)
|
|
194
|
+
else:
|
|
195
|
+
self.bn2 = nn.Identity()
|
|
196
|
+
|
|
197
|
+
def __call__(self, x, return_latent=False):
|
|
198
|
+
x = x.transpose(0, 2, 1) # (B,T,F) -> (B,F,T)
|
|
199
|
+
|
|
200
|
+
out1 = self.layer1(x)
|
|
201
|
+
out2 = self.layer2(out1)
|
|
202
|
+
out3 = self.layer3(out2)
|
|
203
|
+
out4 = self.layer4(out3)
|
|
204
|
+
|
|
205
|
+
out = mx.concatenate([out2, out3, out4], axis=1)
|
|
206
|
+
|
|
207
|
+
out = self.conv(out.transpose(0, 2, 1)).transpose(0, 2, 1)
|
|
208
|
+
latent = nn.relu(out)
|
|
209
|
+
out = self.pool(latent)
|
|
210
|
+
out = self.bn(out)
|
|
211
|
+
out = self.linear(out)
|
|
212
|
+
if self.emb_bn:
|
|
213
|
+
out = self.bn2(out)
|
|
214
|
+
|
|
215
|
+
if return_latent:
|
|
216
|
+
return out, latent
|
|
217
|
+
return out
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def ECAPA_TDNN_c1024(feat_dim, embed_dim, pooling_func="ASTP", emb_bn=False):
|
|
221
|
+
return ECAPA_TDNN(
|
|
222
|
+
channels=1024,
|
|
223
|
+
feat_dim=feat_dim,
|
|
224
|
+
embed_dim=embed_dim,
|
|
225
|
+
pooling_func=pooling_func,
|
|
226
|
+
emb_bn=emb_bn,
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def ECAPA_TDNN_GLOB_c1024(feat_dim, embed_dim, pooling_func="ASTP", emb_bn=False):
|
|
231
|
+
return ECAPA_TDNN(
|
|
232
|
+
channels=1024,
|
|
233
|
+
feat_dim=feat_dim,
|
|
234
|
+
embed_dim=embed_dim,
|
|
235
|
+
pooling_func=pooling_func,
|
|
236
|
+
global_context_att=True,
|
|
237
|
+
emb_bn=emb_bn,
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def ECAPA_TDNN_c512(feat_dim, embed_dim, pooling_func="ASTP", emb_bn=False):
|
|
242
|
+
return ECAPA_TDNN(
|
|
243
|
+
channels=512,
|
|
244
|
+
feat_dim=feat_dim,
|
|
245
|
+
embed_dim=embed_dim,
|
|
246
|
+
pooling_func=pooling_func,
|
|
247
|
+
emb_bn=emb_bn,
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def ECAPA_TDNN_GLOB_c512(feat_dim, embed_dim, pooling_func="ASTP", emb_bn=False):
|
|
252
|
+
return ECAPA_TDNN(
|
|
253
|
+
channels=512,
|
|
254
|
+
feat_dim=feat_dim,
|
|
255
|
+
embed_dim=embed_dim,
|
|
256
|
+
pooling_func=pooling_func,
|
|
257
|
+
global_context_att=True,
|
|
258
|
+
emb_bn=emb_bn,
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
if __name__ == "__main__":
|
|
263
|
+
from mlx.utils import tree_flatten
|
|
264
|
+
|
|
265
|
+
x = mx.zeros(shape=(1, 200, 100))
|
|
266
|
+
model = ECAPA_TDNN_GLOB_c512(feat_dim=100, embed_dim=256, pooling_func="ASTP")
|
|
267
|
+
model.eval()
|
|
268
|
+
out, latent = model(x, True)
|
|
269
|
+
print(out.shape)
|
|
270
|
+
print(latent.shape)
|
|
271
|
+
# Count parameters for MLX model
|
|
272
|
+
num_params = 0
|
|
273
|
+
|
|
274
|
+
weights = dict(tree_flatten(model.parameters()))
|
|
275
|
+
|
|
276
|
+
for k, v in weights.items():
|
|
277
|
+
num_params += v.size
|
|
278
|
+
print("{} M".format(num_params / 1e6))
|
|
279
|
+
|
|
280
|
+
# from thop import profile
|
|
281
|
+
# x_np = torch.randn(1, 200, 80)
|
|
282
|
+
# flops, params = profile(model, inputs=(x_np, ))
|
|
283
|
+
# print("FLOPs: {} G, Params: {} M".format(flops / 1e9, params / 1e6))
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
# Copyright (c) 2025 SparkAudio
|
|
2
|
+
# 2025 Xinsheng Wang (w.xinshawn@gmail.com)
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
# Adapted from https://github.com/lucidrains/naturalspeech2-pytorch/blob/659bec7f7543e7747e809e950cc2f84242fbeec7/naturalspeech2_pytorch/naturalspeech2_pytorch.py#L532
|
|
17
|
+
|
|
18
|
+
from collections import namedtuple
|
|
19
|
+
from functools import wraps
|
|
20
|
+
|
|
21
|
+
import mlx.core as mx
|
|
22
|
+
import mlx.nn as nn
|
|
23
|
+
from einops import rearrange, repeat
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def exists(val):
|
|
27
|
+
return val is not None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def once(fn):
|
|
31
|
+
called = False
|
|
32
|
+
|
|
33
|
+
@wraps(fn)
|
|
34
|
+
def inner(x):
|
|
35
|
+
nonlocal called
|
|
36
|
+
if called:
|
|
37
|
+
return
|
|
38
|
+
called = True
|
|
39
|
+
return fn(x)
|
|
40
|
+
|
|
41
|
+
return inner
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
print_once = once(print)
|
|
45
|
+
|
|
46
|
+
# main class
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class Attend(nn.Module):
|
|
50
|
+
def __init__(self, dropout=0.0, causal=False):
|
|
51
|
+
super().__init__()
|
|
52
|
+
self.dropout = dropout
|
|
53
|
+
self.attn_dropout = nn.Dropout(dropout)
|
|
54
|
+
self.causal = causal
|
|
55
|
+
self.mask = None
|
|
56
|
+
|
|
57
|
+
def get_mask(self, n, device=None):
|
|
58
|
+
if exists(self.mask) and self.mask.shape[-1] >= n:
|
|
59
|
+
return self.mask[:n, :n]
|
|
60
|
+
|
|
61
|
+
mask = mx.triu(mx.ones((n, n), dtype=mx.bool_), 1)
|
|
62
|
+
self.mask = mask
|
|
63
|
+
return mask
|
|
64
|
+
|
|
65
|
+
def __call__(self, q, k, v, mask=None):
|
|
66
|
+
"""
|
|
67
|
+
einstein notation
|
|
68
|
+
b - batch
|
|
69
|
+
h - heads
|
|
70
|
+
n, i, j - sequence length (base sequence length, source, target)
|
|
71
|
+
d - feature dimension
|
|
72
|
+
"""
|
|
73
|
+
n = q.shape[-2]
|
|
74
|
+
|
|
75
|
+
scale = q.shape[-1] ** -0.5
|
|
76
|
+
|
|
77
|
+
# Handle different dimensions for k and v
|
|
78
|
+
kv_einsum_eq = "b j d" if k.ndim == 3 else "b h j d"
|
|
79
|
+
|
|
80
|
+
# similarity
|
|
81
|
+
if k.ndim == 3:
|
|
82
|
+
k = mx.expand_dims(k, axis=1)
|
|
83
|
+
k = mx.broadcast_to(k, q.shape)
|
|
84
|
+
|
|
85
|
+
if v.ndim == 3:
|
|
86
|
+
v = mx.expand_dims(v, axis=1)
|
|
87
|
+
v = mx.broadcast_to(v, q.shape[:-1] + (v.shape[-1],))
|
|
88
|
+
|
|
89
|
+
# q: [b h i d], k: [b h j d]
|
|
90
|
+
sim = mx.matmul(q, mx.transpose(k, (0, 1, 3, 2))) * scale
|
|
91
|
+
|
|
92
|
+
# key padding mask
|
|
93
|
+
if exists(mask):
|
|
94
|
+
mask = mx.reshape(mask, (mask.shape[0], 1, 1, mask.shape[1]))
|
|
95
|
+
sim = mx.where(mask, sim, -1e9)
|
|
96
|
+
|
|
97
|
+
# causal mask
|
|
98
|
+
if self.causal:
|
|
99
|
+
causal_mask = self.get_mask(n)
|
|
100
|
+
sim = mx.where(causal_mask, -1e9, sim)
|
|
101
|
+
|
|
102
|
+
# attention
|
|
103
|
+
attn = mx.softmax(sim, axis=-1)
|
|
104
|
+
|
|
105
|
+
if self.dropout > 0 and self.training:
|
|
106
|
+
attn = self.attn_dropout(attn)
|
|
107
|
+
|
|
108
|
+
# aggregate values
|
|
109
|
+
out = mx.matmul(attn, v)
|
|
110
|
+
|
|
111
|
+
return out
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def Sequential(*mods):
|
|
115
|
+
return nn.Sequential(*[mod for mod in mods if exists(mod)])
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def default(val, d):
|
|
119
|
+
if exists(val):
|
|
120
|
+
return val
|
|
121
|
+
return d() if callable(d) else d
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class RMSNorm(nn.Module):
|
|
125
|
+
def __init__(self, dim, scale=True, dim_cond=None):
|
|
126
|
+
super().__init__()
|
|
127
|
+
self.cond = exists(dim_cond)
|
|
128
|
+
self.to_gamma_beta = nn.Linear(dim_cond, dim * 2) if self.cond else None
|
|
129
|
+
|
|
130
|
+
self.scale = dim**0.5
|
|
131
|
+
self.gamma = mx.ones((dim,)) if scale else None
|
|
132
|
+
|
|
133
|
+
def __call__(self, x, cond=None):
|
|
134
|
+
def normalize(input, p=2.0, dim=1, eps=1e-12):
|
|
135
|
+
norm = mx.power(
|
|
136
|
+
mx.sum(mx.power(mx.abs(input), p), axis=dim, keepdims=True), 1 / p
|
|
137
|
+
)
|
|
138
|
+
return input / mx.maximum(norm, eps)
|
|
139
|
+
|
|
140
|
+
gamma = default(self.gamma, 1)
|
|
141
|
+
out = normalize(x, dim=-1) * self.scale * gamma
|
|
142
|
+
|
|
143
|
+
if not self.cond:
|
|
144
|
+
return out
|
|
145
|
+
|
|
146
|
+
assert exists(cond)
|
|
147
|
+
gamma, beta = mx.split(self.to_gamma_beta(cond), 2, axis=-1)
|
|
148
|
+
gamma = mx.expand_dims(gamma, axis=1)
|
|
149
|
+
beta = mx.expand_dims(beta, axis=1)
|
|
150
|
+
return out * gamma + beta
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
class CausalConv1d(nn.Module):
|
|
154
|
+
def __init__(self, in_channels, out_channels, kernel_size, dilation=1, stride=1):
|
|
155
|
+
super().__init__()
|
|
156
|
+
self.conv = nn.Conv1d(
|
|
157
|
+
in_channels, out_channels, kernel_size, stride=stride, dilation=dilation
|
|
158
|
+
)
|
|
159
|
+
self.kernel_size = kernel_size
|
|
160
|
+
self.dilation = dilation
|
|
161
|
+
self.stride = stride
|
|
162
|
+
assert stride == 1
|
|
163
|
+
self.causal_padding = dilation * (kernel_size - 1)
|
|
164
|
+
|
|
165
|
+
def __call__(self, x):
|
|
166
|
+
causal_padded_x = mx.pad(x, [(0, 0), (0, 0), (self.causal_padding, 0)])
|
|
167
|
+
return self.conv(causal_padded_x)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
class GEGLU(nn.Module):
|
|
171
|
+
def __call__(self, x):
|
|
172
|
+
x, gate = mx.split(x, 2, axis=-1)
|
|
173
|
+
return nn.gelu(gate) * x
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def FeedForward(dim, mult=4, causal_conv=False):
|
|
177
|
+
dim_inner = int(dim * mult * 2 / 3)
|
|
178
|
+
|
|
179
|
+
conv = None
|
|
180
|
+
if causal_conv:
|
|
181
|
+
conv = [
|
|
182
|
+
lambda x: mx.transpose(x, (0, 2, 1)), # b n d -> b d n
|
|
183
|
+
CausalConv1d(dim_inner, dim_inner, 3),
|
|
184
|
+
lambda x: mx.transpose(x, (0, 2, 1)), # b d n -> b n d
|
|
185
|
+
]
|
|
186
|
+
|
|
187
|
+
return [
|
|
188
|
+
nn.Linear(dim, dim_inner * 2),
|
|
189
|
+
GEGLU(),
|
|
190
|
+
conv,
|
|
191
|
+
nn.Linear(dim_inner, dim),
|
|
192
|
+
]
|
|
193
|
+
else:
|
|
194
|
+
return [
|
|
195
|
+
nn.Linear(dim, dim_inner * 2),
|
|
196
|
+
GEGLU(),
|
|
197
|
+
nn.Linear(dim_inner, dim),
|
|
198
|
+
]
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
class Attention(nn.Module):
|
|
202
|
+
def __init__(
|
|
203
|
+
self,
|
|
204
|
+
dim,
|
|
205
|
+
*,
|
|
206
|
+
dim_context=None,
|
|
207
|
+
causal=False,
|
|
208
|
+
dim_head=64,
|
|
209
|
+
heads=8,
|
|
210
|
+
dropout=0.0,
|
|
211
|
+
cross_attn_include_queries=False,
|
|
212
|
+
):
|
|
213
|
+
super().__init__()
|
|
214
|
+
self.scale = dim_head**-0.5
|
|
215
|
+
self.heads = heads
|
|
216
|
+
self.cross_attn_include_queries = cross_attn_include_queries
|
|
217
|
+
|
|
218
|
+
dim_inner = dim_head * heads
|
|
219
|
+
dim_context = default(dim_context, dim)
|
|
220
|
+
|
|
221
|
+
self.attend = Attend(causal=causal, dropout=dropout)
|
|
222
|
+
self.to_q = nn.Linear(dim, dim_inner, bias=False)
|
|
223
|
+
self.to_kv = nn.Linear(dim_context, dim_inner * 2, bias=False)
|
|
224
|
+
self.to_out = nn.Linear(dim_inner, dim, bias=False)
|
|
225
|
+
|
|
226
|
+
def __call__(self, x, context=None, mask=None):
|
|
227
|
+
h, has_context = self.heads, exists(context)
|
|
228
|
+
|
|
229
|
+
context = default(context, x)
|
|
230
|
+
|
|
231
|
+
if has_context and self.cross_attn_include_queries:
|
|
232
|
+
context = mx.concatenate([x, context], axis=-2)
|
|
233
|
+
|
|
234
|
+
q = self.to_q(x)
|
|
235
|
+
kv = self.to_kv(context)
|
|
236
|
+
k, v = mx.split(kv, 2, axis=-1)
|
|
237
|
+
|
|
238
|
+
# Reshape for multi-head attention
|
|
239
|
+
q = mx.reshape(q, (q.shape[0], q.shape[1], h, -1))
|
|
240
|
+
q = mx.transpose(q, (0, 2, 1, 3)) # b n (h d) -> b h n d
|
|
241
|
+
|
|
242
|
+
k = mx.reshape(k, (k.shape[0], k.shape[1], h, -1))
|
|
243
|
+
k = mx.transpose(k, (0, 2, 1, 3)) # b n (h d) -> b h n d
|
|
244
|
+
|
|
245
|
+
v = mx.reshape(v, (v.shape[0], v.shape[1], h, -1))
|
|
246
|
+
v = mx.transpose(v, (0, 2, 1, 3)) # b n (h d) -> b h n d
|
|
247
|
+
|
|
248
|
+
out = self.attend(q, k, v, mask=mask)
|
|
249
|
+
|
|
250
|
+
out = mx.transpose(out, (0, 2, 1, 3)) # b h n d -> b n h d
|
|
251
|
+
out = mx.reshape(out, (out.shape[0], out.shape[1], -1)) # b n h d -> b n (h d)
|
|
252
|
+
|
|
253
|
+
return self.to_out(out)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
class PerceiverResampler(nn.Module):
|
|
257
|
+
def __init__(
|
|
258
|
+
self,
|
|
259
|
+
*,
|
|
260
|
+
dim,
|
|
261
|
+
depth=2,
|
|
262
|
+
dim_context=None,
|
|
263
|
+
num_latents=32,
|
|
264
|
+
dim_head=64,
|
|
265
|
+
heads=8,
|
|
266
|
+
ff_mult=4,
|
|
267
|
+
):
|
|
268
|
+
super().__init__()
|
|
269
|
+
dim_context = default(dim_context, dim)
|
|
270
|
+
|
|
271
|
+
self.proj_context = (
|
|
272
|
+
nn.Linear(dim_context, dim) if dim_context != dim else nn.Identity()
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
self.latents = mx.random.normal(shape=(num_latents, dim), scale=0.02)
|
|
276
|
+
|
|
277
|
+
self.layers = []
|
|
278
|
+
for _ in range(depth):
|
|
279
|
+
self.layers.append(
|
|
280
|
+
[
|
|
281
|
+
Attention(
|
|
282
|
+
dim=dim,
|
|
283
|
+
dim_head=dim_head,
|
|
284
|
+
heads=heads,
|
|
285
|
+
cross_attn_include_queries=True,
|
|
286
|
+
),
|
|
287
|
+
FeedForward(dim=dim, mult=ff_mult),
|
|
288
|
+
]
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
self.norm = RMSNorm(dim)
|
|
292
|
+
|
|
293
|
+
def __call__(self, x, mask=None):
|
|
294
|
+
batch = x.shape[0]
|
|
295
|
+
|
|
296
|
+
x = self.proj_context(x)
|
|
297
|
+
|
|
298
|
+
latents = mx.broadcast_to(self.latents, (batch,) + self.latents.shape)
|
|
299
|
+
|
|
300
|
+
for attn, ff in self.layers:
|
|
301
|
+
latents = attn(latents, x, mask=mask) + latents
|
|
302
|
+
skip_connect = latents
|
|
303
|
+
for module in ff:
|
|
304
|
+
latents = module(latents)
|
|
305
|
+
|
|
306
|
+
latents = skip_connect + latents
|
|
307
|
+
|
|
308
|
+
return self.norm(latents)
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
if __name__ == "__main__":
|
|
312
|
+
from mlx.utils import tree_flatten
|
|
313
|
+
|
|
314
|
+
model = PerceiverResampler(dim=256, dim_context=80)
|
|
315
|
+
x = mx.random.normal(shape=(8, 200, 80))
|
|
316
|
+
out = model(x)
|
|
317
|
+
print("Output shape:", out.shape) # [8, 32, 80]
|
|
318
|
+
|
|
319
|
+
# Count parameters for MLX model
|
|
320
|
+
num_params = 0
|
|
321
|
+
|
|
322
|
+
weights = dict(tree_flatten(model.parameters()))
|
|
323
|
+
|
|
324
|
+
for k, v in weights.items():
|
|
325
|
+
num_params += v.size
|
|
326
|
+
print("{} M".format(num_params / 1e6))
|