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,209 @@
|
|
|
1
|
+
from typing import Any, Dict, List
|
|
2
|
+
|
|
3
|
+
import mlx.core as mx
|
|
4
|
+
import mlx.nn as nn
|
|
5
|
+
from einops.array_api import rearrange
|
|
6
|
+
|
|
7
|
+
from mlx_audio.codec.models.descript.nn.layers import WNConv1d
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def exists(val):
|
|
11
|
+
return val is not None
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def default(val, d):
|
|
15
|
+
return val if exists(val) else d
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class FactorizedVectorQuantize(nn.Module):
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
input_dim: int,
|
|
22
|
+
codebook_size: int,
|
|
23
|
+
codebook_dim: int,
|
|
24
|
+
commitment: float,
|
|
25
|
+
codebook_loss_weight: float = 1.0,
|
|
26
|
+
decay: float = 0.99,
|
|
27
|
+
threshold_ema_dead_code: float = 2,
|
|
28
|
+
momentum: float = 0.99,
|
|
29
|
+
**kwargs,
|
|
30
|
+
):
|
|
31
|
+
super().__init__()
|
|
32
|
+
self.input_dim = input_dim
|
|
33
|
+
self.codebook_size = codebook_size
|
|
34
|
+
self.commitment = commitment
|
|
35
|
+
self.codebook_dim = codebook_dim
|
|
36
|
+
self.codebook_loss_weight = codebook_loss_weight
|
|
37
|
+
self.decay = decay
|
|
38
|
+
self.threshold_ema_dead_code = threshold_ema_dead_code
|
|
39
|
+
self.momentum = momentum
|
|
40
|
+
|
|
41
|
+
requires_projection = input_dim != codebook_dim
|
|
42
|
+
|
|
43
|
+
self.in_project = (
|
|
44
|
+
WNConv1d(in_channels=input_dim, out_channels=codebook_dim, kernel_size=1)
|
|
45
|
+
if requires_projection
|
|
46
|
+
else nn.Identity()
|
|
47
|
+
)
|
|
48
|
+
self.out_project = (
|
|
49
|
+
WNConv1d(in_channels=codebook_dim, out_channels=input_dim, kernel_size=1)
|
|
50
|
+
if requires_projection
|
|
51
|
+
else nn.Identity()
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
self.codebook = nn.Embedding(self.codebook_size, codebook_dim)
|
|
55
|
+
self.cluster_size = mx.zeros((self.codebook_size,))
|
|
56
|
+
|
|
57
|
+
def __call__(self, z: mx.array) -> Dict[str, Any]:
|
|
58
|
+
"""Quantized the input tensor using a fixed codebook and returns
|
|
59
|
+
the corresponding codebook vectors
|
|
60
|
+
|
|
61
|
+
Parameters
|
|
62
|
+
----------
|
|
63
|
+
z : Tensor[B x D x T]
|
|
64
|
+
|
|
65
|
+
Returns
|
|
66
|
+
-------
|
|
67
|
+
Tensor[B x D x T]
|
|
68
|
+
Quantized continuous representation of input
|
|
69
|
+
Tensor[1]
|
|
70
|
+
Commitment loss to train encoder to predict vectors closer to codebook
|
|
71
|
+
entries
|
|
72
|
+
Tensor[1]
|
|
73
|
+
Codebook loss to update the codebook
|
|
74
|
+
Tensor[B x T]
|
|
75
|
+
Codebook indices (quantized discrete representation of input)
|
|
76
|
+
Tensor[B x D x T]
|
|
77
|
+
Projected latents (continuous representation of input before quantization)
|
|
78
|
+
"""
|
|
79
|
+
# transpose since we use linear
|
|
80
|
+
|
|
81
|
+
# Factorized codes project input into low-dimensional space if self.input_dim != self.codebook_dim
|
|
82
|
+
z_e = self.in_project(z.transpose(0, 2, 1)).transpose(0, 2, 1)
|
|
83
|
+
z_q, indices, dists = self.decode_latents(z_e)
|
|
84
|
+
|
|
85
|
+
# statistic the usage of codes
|
|
86
|
+
embed_onehot = mx.zeros(
|
|
87
|
+
(indices.shape[0], indices.shape[1], self.codebook_size), dtype=z_e.dtype
|
|
88
|
+
)
|
|
89
|
+
for i in range(indices.shape[0]):
|
|
90
|
+
for j in range(indices.shape[1]):
|
|
91
|
+
embed_onehot[i, j, indices[i, j]] = 1.0
|
|
92
|
+
avg_probs = mx.mean(embed_onehot.reshape(-1, self.codebook_size), axis=0)
|
|
93
|
+
perplexity = mx.exp(-mx.sum(avg_probs * mx.log(avg_probs + 1e-10)))
|
|
94
|
+
|
|
95
|
+
active_num = (embed_onehot.sum(0).sum(0) > 0).sum()
|
|
96
|
+
|
|
97
|
+
commit_loss = mx.zeros(0)
|
|
98
|
+
codebook_loss = mx.zeros(0)
|
|
99
|
+
|
|
100
|
+
z_q = z_e + (
|
|
101
|
+
z_q - z_e
|
|
102
|
+
) # noop in forward pass, straight-through gradient estimator in backward pass
|
|
103
|
+
|
|
104
|
+
z_q = self.out_project(z_q.transpose(0, 2, 1)).transpose(0, 2, 1)
|
|
105
|
+
|
|
106
|
+
vq_loss = (commit_loss + codebook_loss).mean()
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
"z_q": z_q,
|
|
110
|
+
"indices": indices,
|
|
111
|
+
"dists": dists,
|
|
112
|
+
"vq_loss": vq_loss,
|
|
113
|
+
"perplexity": perplexity,
|
|
114
|
+
"active_num": active_num.astype(mx.float32),
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
def vq2emb(self, vq, out_proj=True):
|
|
118
|
+
emb = self.embed_code(vq)
|
|
119
|
+
if out_proj:
|
|
120
|
+
emb = self.out_project(emb)
|
|
121
|
+
return emb
|
|
122
|
+
|
|
123
|
+
def tokenize(self, z: mx.array) -> mx.array:
|
|
124
|
+
"""tokenize the input tensor"""
|
|
125
|
+
z_e = self.in_project(z.transpose(0, 2, 1)).transpose(0, 2, 1)
|
|
126
|
+
_, indices, _ = self.decode_latents(z_e)
|
|
127
|
+
return indices
|
|
128
|
+
|
|
129
|
+
def detokenize(self, indices):
|
|
130
|
+
"""detokenize the input indices"""
|
|
131
|
+
# Check if indices are empty
|
|
132
|
+
if indices.shape[0] == 0 or indices.shape[1] == 0:
|
|
133
|
+
# Return an appropriate empty or placeholder tensor
|
|
134
|
+
return mx.zeros((1, self.input_dim, 1))
|
|
135
|
+
|
|
136
|
+
z_q = self.decode_code(indices).transpose(0, 2, 1)
|
|
137
|
+
z_q = self.out_project(z_q)
|
|
138
|
+
return z_q
|
|
139
|
+
|
|
140
|
+
def get_emb(self):
|
|
141
|
+
return self.codebook.weight
|
|
142
|
+
|
|
143
|
+
def embed_code(self, embed_id):
|
|
144
|
+
return mx.take(self.codebook.weight, embed_id, axis=0)
|
|
145
|
+
|
|
146
|
+
def decode_code(self, embed_id):
|
|
147
|
+
|
|
148
|
+
return self.embed_code(embed_id).transpose(0, 2, 1)
|
|
149
|
+
|
|
150
|
+
def normalize(self, x):
|
|
151
|
+
"""Normalize input tensor along dimension 1."""
|
|
152
|
+
norm = mx.sqrt(mx.sum(mx.power(x, 2), axis=1, keepdims=True))
|
|
153
|
+
return x / mx.maximum(norm, 1e-12)
|
|
154
|
+
|
|
155
|
+
def decode_latents(self, latents):
|
|
156
|
+
encodings = rearrange(latents, "b d t -> (b t) d")
|
|
157
|
+
codebook = self.codebook.weight
|
|
158
|
+
|
|
159
|
+
# L2 normalize encodings and codebook
|
|
160
|
+
encodings = self.normalize(encodings)
|
|
161
|
+
codebook = self.normalize(codebook)
|
|
162
|
+
|
|
163
|
+
# Compute euclidean distance between encodings and codebook,
|
|
164
|
+
# with L2 normalization, the distance is equal to cosine distance
|
|
165
|
+
dist = (
|
|
166
|
+
mx.sum(mx.power(encodings, 2), axis=1, keepdims=True)
|
|
167
|
+
- 2 * encodings @ codebook.T
|
|
168
|
+
+ mx.sum(mx.power(codebook, 2), axis=1, keepdims=True).T
|
|
169
|
+
)
|
|
170
|
+
min_encoding_indices = mx.argmax(-dist, axis=1)
|
|
171
|
+
indices = mx.reshape(min_encoding_indices, (latents.shape[0], latents.shape[2]))
|
|
172
|
+
z_q = self.decode_code(indices)
|
|
173
|
+
|
|
174
|
+
return z_q, indices, dist
|
|
175
|
+
|
|
176
|
+
def get_codes_from_indices(self, indices):
|
|
177
|
+
"""Get codebook vectors from indices.
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
indices: Tensor of shape [B, T]
|
|
181
|
+
|
|
182
|
+
Returns:
|
|
183
|
+
Tensor of shape [B, D, T]
|
|
184
|
+
"""
|
|
185
|
+
return self.decode_code(indices)
|
|
186
|
+
|
|
187
|
+
def get_output_from_indices(self, indices):
|
|
188
|
+
"""Get output from indices.
|
|
189
|
+
|
|
190
|
+
Args:
|
|
191
|
+
indices: Tensor of shape [B, T]
|
|
192
|
+
|
|
193
|
+
Returns:
|
|
194
|
+
Tensor of shape [B, D, T]
|
|
195
|
+
"""
|
|
196
|
+
z_q = self.get_codes_from_indices(indices)
|
|
197
|
+
return self.out_project(z_q.transpose(0, 2, 1)).transpose(0, 2, 1)
|
|
198
|
+
|
|
199
|
+
def sanitize(self, weights):
|
|
200
|
+
sanitized_weights = {}
|
|
201
|
+
for k, v in weights.items():
|
|
202
|
+
if "weight_v" in k:
|
|
203
|
+
if v.shape[1] > v.shape[-1]:
|
|
204
|
+
sanitized_weights[k] = v.transpose(0, 2, 1)
|
|
205
|
+
else:
|
|
206
|
+
sanitized_weights[k] = v
|
|
207
|
+
else:
|
|
208
|
+
sanitized_weights[k] = v
|
|
209
|
+
return sanitized_weights
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import random
|
|
2
|
+
from typing import List
|
|
3
|
+
|
|
4
|
+
import mlx.core as mx
|
|
5
|
+
import mlx.nn as nn
|
|
6
|
+
|
|
7
|
+
from mlx_audio.tts.models.spark.modules.finite_scalar_quantization import FSQ
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def exists(val):
|
|
11
|
+
return val is not None
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def first(l):
|
|
15
|
+
return l[0]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def default(val, d):
|
|
19
|
+
return val if exists(val) else d
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def round_up_multiple(num, mult):
|
|
23
|
+
return ceil(num / mult) * mult
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ResidualFSQ(nn.Module):
|
|
27
|
+
"""Follows Algorithm 1. in https://arxiv.org/pdf/2107.03312.pdf"""
|
|
28
|
+
|
|
29
|
+
def __init__(
|
|
30
|
+
self,
|
|
31
|
+
*,
|
|
32
|
+
levels: List[int],
|
|
33
|
+
num_quantizers,
|
|
34
|
+
dim=None,
|
|
35
|
+
is_channel_first=False,
|
|
36
|
+
quantize_dropout=False,
|
|
37
|
+
quantize_dropout_cutoff_index=0,
|
|
38
|
+
quantize_dropout_multiple_of=1,
|
|
39
|
+
**kwargs,
|
|
40
|
+
):
|
|
41
|
+
super().__init__()
|
|
42
|
+
codebook_dim = len(levels)
|
|
43
|
+
dim = default(dim, codebook_dim)
|
|
44
|
+
|
|
45
|
+
requires_projection = codebook_dim != dim
|
|
46
|
+
self.project_in = (
|
|
47
|
+
nn.Linear(dim, codebook_dim) if requires_projection else nn.Identity()
|
|
48
|
+
)
|
|
49
|
+
self.project_out = (
|
|
50
|
+
nn.Linear(codebook_dim, dim) if requires_projection else nn.Identity()
|
|
51
|
+
)
|
|
52
|
+
self.has_projections = requires_projection
|
|
53
|
+
|
|
54
|
+
self.is_channel_first = is_channel_first
|
|
55
|
+
self.num_quantizers = num_quantizers
|
|
56
|
+
|
|
57
|
+
self.levels = levels
|
|
58
|
+
self.layers = []
|
|
59
|
+
|
|
60
|
+
# Convert ListConfig to a regular list before passing to mx.array
|
|
61
|
+
levels_tensor = mx.array(list(levels))
|
|
62
|
+
|
|
63
|
+
scales = []
|
|
64
|
+
|
|
65
|
+
for ind in range(num_quantizers):
|
|
66
|
+
scales.append((levels_tensor - 1) ** -ind)
|
|
67
|
+
|
|
68
|
+
fsq = FSQ(levels=levels, dim=codebook_dim, **kwargs)
|
|
69
|
+
|
|
70
|
+
self.layers.append(fsq)
|
|
71
|
+
|
|
72
|
+
assert all([not fsq.has_projections for fsq in self.layers])
|
|
73
|
+
|
|
74
|
+
self.codebook_size = self.layers[0].codebook_size
|
|
75
|
+
|
|
76
|
+
self._scales = mx.array(scales)
|
|
77
|
+
|
|
78
|
+
self.quantize_dropout = quantize_dropout and num_quantizers > 1
|
|
79
|
+
|
|
80
|
+
assert quantize_dropout_cutoff_index >= 0
|
|
81
|
+
|
|
82
|
+
self.quantize_dropout_cutoff_index = quantize_dropout_cutoff_index
|
|
83
|
+
self.quantize_dropout_multiple_of = quantize_dropout_multiple_of # encodec paper proposes structured dropout, believe this was set to 4
|
|
84
|
+
|
|
85
|
+
@property
|
|
86
|
+
def codebooks(self):
|
|
87
|
+
codebooks = [layer._implicit_codebook for layer in self.layers]
|
|
88
|
+
codebooks = mx.stack(codebooks, axis=0)
|
|
89
|
+
return codebooks
|
|
90
|
+
|
|
91
|
+
def get_codes_from_indices(self, indices):
|
|
92
|
+
batch, quantize_dim = indices.shape[0], indices.shape[-1]
|
|
93
|
+
|
|
94
|
+
# may also receive indices in the shape of 'b h w q' (accept_image_fmap)
|
|
95
|
+
|
|
96
|
+
# MLX doesn't have pack function, so we need to reshape manually
|
|
97
|
+
original_shape = indices.shape
|
|
98
|
+
indices = mx.reshape(indices, (indices.shape[0], -1, indices.shape[-1]))
|
|
99
|
+
|
|
100
|
+
# because of quantize dropout, one can pass in indices that are coarse
|
|
101
|
+
# and the network should be able to reconstruct
|
|
102
|
+
|
|
103
|
+
if quantize_dim < self.num_quantizers:
|
|
104
|
+
assert (
|
|
105
|
+
self.quantize_dropout > 0.0
|
|
106
|
+
), "quantize dropout must be greater than 0 if you wish to reconstruct from a signal with less fine quantizations"
|
|
107
|
+
indices = mx.pad(
|
|
108
|
+
indices,
|
|
109
|
+
((0, 0), (0, 0), (0, self.num_quantizers - quantize_dim)),
|
|
110
|
+
constant_value=-1,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
# take care of quantizer dropout
|
|
114
|
+
|
|
115
|
+
mask = indices == -1
|
|
116
|
+
# MLX doesn't have masked_fill, so we use where
|
|
117
|
+
indices = mx.where(
|
|
118
|
+
mask, mx.zeros_like(indices), indices
|
|
119
|
+
) # have it fetch a dummy code to be masked out later
|
|
120
|
+
|
|
121
|
+
# MLX doesn't have get_at function, so we need to manually gather codes
|
|
122
|
+
all_codes = []
|
|
123
|
+
for q in range(self.codebooks.shape[0]):
|
|
124
|
+
q_codes = []
|
|
125
|
+
for b in range(indices.shape[0]):
|
|
126
|
+
n_codes = []
|
|
127
|
+
for n in range(indices.shape[1]):
|
|
128
|
+
idx = indices[b, n, q]
|
|
129
|
+
n_codes.append(self.codebooks[q, idx])
|
|
130
|
+
q_codes.append(mx.stack(n_codes))
|
|
131
|
+
all_codes.append(mx.stack(q_codes))
|
|
132
|
+
all_codes = mx.stack(all_codes)[:, :, :, 0, :] # Shape: (q, b, n, d)
|
|
133
|
+
|
|
134
|
+
# mask out any codes that were dropout-ed
|
|
135
|
+
# Reshape mask for broadcasting: q b n 1
|
|
136
|
+
|
|
137
|
+
mask_reshaped = mx.reshape(
|
|
138
|
+
mask, (mask.shape[2], mask.shape[0], mask.shape[1], 1)
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
all_codes = mx.where(mask_reshaped, mx.zeros_like(all_codes), all_codes)
|
|
142
|
+
|
|
143
|
+
# scale the codes
|
|
144
|
+
# Reshape scales for broadcasting: q 1 1 d
|
|
145
|
+
scales = mx.reshape(
|
|
146
|
+
self._scales, (self._scales.shape[0], 1, 1, self._scales.shape[1])
|
|
147
|
+
)
|
|
148
|
+
all_codes = all_codes * scales
|
|
149
|
+
|
|
150
|
+
# if (accept_image_fmap = True) then return shape (quantize, batch, height, width, dimension)
|
|
151
|
+
# Reshape all_codes back to original dimensions
|
|
152
|
+
if len(original_shape) > 3: # If we had height, width dimensions
|
|
153
|
+
all_codes = mx.reshape(
|
|
154
|
+
all_codes,
|
|
155
|
+
(
|
|
156
|
+
all_codes.shape[0],
|
|
157
|
+
original_shape[0],
|
|
158
|
+
*original_shape[1:-1],
|
|
159
|
+
all_codes.shape[-1],
|
|
160
|
+
),
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
return all_codes
|
|
164
|
+
|
|
165
|
+
def get_output_from_indices(self, indices):
|
|
166
|
+
codes = self.get_codes_from_indices(indices)
|
|
167
|
+
codes_summed = mx.sum(codes, axis=0)
|
|
168
|
+
return self.project_out(codes_summed)
|
|
169
|
+
|
|
170
|
+
def __call__(
|
|
171
|
+
self, x, return_all_codes=False, rand_quantize_dropout_fixed_seed=None
|
|
172
|
+
):
|
|
173
|
+
num_quant, quant_dropout_multiple_of = (
|
|
174
|
+
self.num_quantizers,
|
|
175
|
+
self.quantize_dropout_multiple_of,
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
# handle channel first
|
|
179
|
+
|
|
180
|
+
if self.is_channel_first:
|
|
181
|
+
# Manually implement rearrange and pack functionality
|
|
182
|
+
# First, move dimension d from position 1 to the end
|
|
183
|
+
shape = x.shape
|
|
184
|
+
# Assuming shape is (b, d, ...)
|
|
185
|
+
new_shape = (shape[0],) + shape[2:] + (shape[1],)
|
|
186
|
+
x = mx.transpose(x, (0,) + tuple(range(2, len(shape))) + (1,))
|
|
187
|
+
|
|
188
|
+
# Pack operation: flatten all dimensions between b and d
|
|
189
|
+
# This is equivalent to pack([x], "b * d")
|
|
190
|
+
ps = x.shape
|
|
191
|
+
middle_dims = x.shape[1:-1]
|
|
192
|
+
flattened_dim = 1
|
|
193
|
+
for dim in middle_dims:
|
|
194
|
+
flattened_dim *= dim
|
|
195
|
+
x = mx.reshape(x, (x.shape[0], flattened_dim, x.shape[-1]))
|
|
196
|
+
|
|
197
|
+
# maybe project in
|
|
198
|
+
|
|
199
|
+
x = self.project_in(x)
|
|
200
|
+
|
|
201
|
+
quantized_out = 0.0
|
|
202
|
+
residual = x
|
|
203
|
+
|
|
204
|
+
all_indices = []
|
|
205
|
+
|
|
206
|
+
should_quantize_dropout = self.training and self.quantize_dropout
|
|
207
|
+
|
|
208
|
+
# sample a layer index at which to dropout further residual quantization
|
|
209
|
+
# also prepare null indices
|
|
210
|
+
|
|
211
|
+
if should_quantize_dropout:
|
|
212
|
+
|
|
213
|
+
# check if seed is manually passed in
|
|
214
|
+
|
|
215
|
+
rand = random.Random(rand_quantize_dropout_fixed_seed)
|
|
216
|
+
|
|
217
|
+
rand_quantize_dropout_index = rand.randrange(
|
|
218
|
+
self.quantize_dropout_cutoff_index, num_quant
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
if quant_dropout_multiple_of != 1:
|
|
222
|
+
rand_quantize_dropout_index = (
|
|
223
|
+
round_up_multiple(
|
|
224
|
+
rand_quantize_dropout_index + 1, quant_dropout_multiple_of
|
|
225
|
+
)
|
|
226
|
+
- 1
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
null_indices = mx.full(x.shape[:2], -1, dtype=mx.int32)
|
|
230
|
+
|
|
231
|
+
# go through the layers
|
|
232
|
+
for quantizer_index, (layer, scale) in enumerate(
|
|
233
|
+
zip(self.layers, self._scales)
|
|
234
|
+
):
|
|
235
|
+
|
|
236
|
+
if (
|
|
237
|
+
should_quantize_dropout
|
|
238
|
+
and quantizer_index > rand_quantize_dropout_index
|
|
239
|
+
):
|
|
240
|
+
all_indices.append(null_indices)
|
|
241
|
+
continue
|
|
242
|
+
|
|
243
|
+
quantized, indices = layer(residual / scale)
|
|
244
|
+
|
|
245
|
+
quantized = quantized * scale
|
|
246
|
+
|
|
247
|
+
residual = residual - quantized
|
|
248
|
+
quantized_out = quantized_out + quantized
|
|
249
|
+
|
|
250
|
+
all_indices.append(indices)
|
|
251
|
+
|
|
252
|
+
# project out, if needed
|
|
253
|
+
|
|
254
|
+
quantized_out = self.project_out(quantized_out)
|
|
255
|
+
|
|
256
|
+
# stack all indices
|
|
257
|
+
|
|
258
|
+
all_indices = mx.stack(all_indices, axis=-1)
|
|
259
|
+
|
|
260
|
+
# channel first out
|
|
261
|
+
|
|
262
|
+
if self.is_channel_first:
|
|
263
|
+
# MLX doesn't have unpack, so we need to reshape manually
|
|
264
|
+
# Assuming ps contains the original batch dimensions
|
|
265
|
+
# Reshape to combine all dimensions between batch and the last dimension
|
|
266
|
+
batch_size = ps[0] if isinstance(ps, tuple) else ps
|
|
267
|
+
quantized_out = mx.reshape(
|
|
268
|
+
quantized_out, (batch_size, -1, quantized_out.shape[-1])
|
|
269
|
+
).swapaxes(
|
|
270
|
+
2, 1
|
|
271
|
+
) # swap to match torch output
|
|
272
|
+
all_indices = mx.reshape(
|
|
273
|
+
all_indices, (batch_size, -1, all_indices.shape[-1])
|
|
274
|
+
).swapaxes(
|
|
275
|
+
2, 1
|
|
276
|
+
) # swap to match torch output
|
|
277
|
+
|
|
278
|
+
# return
|
|
279
|
+
ret = (quantized_out, all_indices)
|
|
280
|
+
|
|
281
|
+
if not return_all_codes:
|
|
282
|
+
return ret
|
|
283
|
+
|
|
284
|
+
# whether to return all codes from all codebooks across layers
|
|
285
|
+
|
|
286
|
+
all_codes = self.get_codes_from_indices(all_indices)
|
|
287
|
+
|
|
288
|
+
# will return all codes in shape (quantizer, batch, sequence length, codebook dimension)
|
|
289
|
+
|
|
290
|
+
return (*ret, all_codes)
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
if __name__ == "__main__":
|
|
294
|
+
model = ResidualFSQ(
|
|
295
|
+
levels=[4, 4, 4, 4, 4, 4],
|
|
296
|
+
num_quantizers=1,
|
|
297
|
+
dim=30,
|
|
298
|
+
is_channel_first=True,
|
|
299
|
+
quantize_dropout=False,
|
|
300
|
+
)
|
|
301
|
+
x = mx.random.normal((2, 30, 10))
|
|
302
|
+
quantize, embed_ind = model(x)
|
|
303
|
+
|
|
304
|
+
emb_from_ind = model.get_output_from_indices(embed_ind.transpose(0, 2, 1))
|
|
305
|
+
|
|
306
|
+
print(quantize == emb_from_ind.transpose(0, 2, 1))
|
|
307
|
+
|
|
308
|
+
print("quantize shape", quantize.shape)
|
|
309
|
+
print("embed_ind", embed_ind)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|