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,120 @@
|
|
|
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
|
+
|
|
17
|
+
from collections import OrderedDict
|
|
18
|
+
from typing import List
|
|
19
|
+
|
|
20
|
+
import mlx.core as mx
|
|
21
|
+
import mlx.nn as nn
|
|
22
|
+
|
|
23
|
+
from mlx_audio.codec.models.vocos.vocos import VocosBackbone
|
|
24
|
+
from mlx_audio.tts.models.spark.modules.blocks.sampler import SamplingBlock
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Decoder(nn.Module):
|
|
28
|
+
"""Decoder module with convnext and upsampling blocks
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
sample_ratios (List[int]): sample ratios
|
|
32
|
+
example: [2, 2] means downsample by 2x and then upsample by 2x
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
def __init__(
|
|
36
|
+
self,
|
|
37
|
+
input_channels: int,
|
|
38
|
+
vocos_dim: int,
|
|
39
|
+
vocos_intermediate_dim: int,
|
|
40
|
+
vocos_num_layers: int,
|
|
41
|
+
out_channels: int,
|
|
42
|
+
condition_dim: int = None,
|
|
43
|
+
sample_ratios: List[int] = [1, 1],
|
|
44
|
+
use_tanh_at_final: bool = False,
|
|
45
|
+
):
|
|
46
|
+
super().__init__()
|
|
47
|
+
|
|
48
|
+
self.linear_pre = nn.Linear(input_channels, vocos_dim)
|
|
49
|
+
modules = []
|
|
50
|
+
for ratio in sample_ratios:
|
|
51
|
+
module_list = [
|
|
52
|
+
SamplingBlock(
|
|
53
|
+
dim=vocos_dim,
|
|
54
|
+
groups=vocos_dim,
|
|
55
|
+
upsample_scale=ratio,
|
|
56
|
+
),
|
|
57
|
+
VocosBackbone(
|
|
58
|
+
input_channels=vocos_dim,
|
|
59
|
+
dim=vocos_dim,
|
|
60
|
+
intermediate_dim=vocos_intermediate_dim,
|
|
61
|
+
num_layers=2,
|
|
62
|
+
),
|
|
63
|
+
]
|
|
64
|
+
modules.append(module_list)
|
|
65
|
+
|
|
66
|
+
self.downsample = modules
|
|
67
|
+
|
|
68
|
+
self.vocos_backbone = VocosBackbone(
|
|
69
|
+
input_channels=vocos_dim,
|
|
70
|
+
dim=vocos_dim,
|
|
71
|
+
intermediate_dim=vocos_intermediate_dim,
|
|
72
|
+
num_layers=vocos_num_layers,
|
|
73
|
+
adanorm_num_embeddings=condition_dim,
|
|
74
|
+
)
|
|
75
|
+
self.linear = nn.Linear(vocos_dim, out_channels)
|
|
76
|
+
self.use_tanh_at_final = use_tanh_at_final
|
|
77
|
+
|
|
78
|
+
def __call__(self, x: mx.array, c: mx.array = None):
|
|
79
|
+
"""encoder forward.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
x (mx.array): (batch_size, input_channels, length)
|
|
83
|
+
|
|
84
|
+
Returns:
|
|
85
|
+
x (mx.array): (batch_size, encode_channels, length)
|
|
86
|
+
"""
|
|
87
|
+
x = self.linear_pre(x.transpose(0, 2, 1))
|
|
88
|
+
for modules in self.downsample:
|
|
89
|
+
for module in modules:
|
|
90
|
+
x = module(x)
|
|
91
|
+
|
|
92
|
+
x = self.vocos_backbone(x.transpose(0, 2, 1), bandwidth_id=c)
|
|
93
|
+
x = self.linear(x).transpose(0, 2, 1)
|
|
94
|
+
if self.use_tanh_at_final:
|
|
95
|
+
x = mx.tanh(x)
|
|
96
|
+
|
|
97
|
+
return x
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
# test
|
|
101
|
+
if __name__ == "__main__":
|
|
102
|
+
test_input = mx.random.normal(
|
|
103
|
+
(8, 1024, 50), dtype=mx.float32
|
|
104
|
+
) # Batch size = 8, 1024 channels, length = 50
|
|
105
|
+
condition = mx.random.randint(0, 100, (256, 8)) # 8, 256
|
|
106
|
+
decoder = Decoder(
|
|
107
|
+
input_channels=1024,
|
|
108
|
+
vocos_dim=384,
|
|
109
|
+
vocos_intermediate_dim=2048,
|
|
110
|
+
vocos_num_layers=12,
|
|
111
|
+
out_channels=256,
|
|
112
|
+
condition_dim=256,
|
|
113
|
+
sample_ratios=[2, 2],
|
|
114
|
+
)
|
|
115
|
+
output = decoder(test_input, condition)
|
|
116
|
+
print(output.shape) # torch.Size([8, 256, 200])
|
|
117
|
+
if output.shape == (8, 256, 200):
|
|
118
|
+
print("Decoder test passed")
|
|
119
|
+
else:
|
|
120
|
+
print("Decoder test failed")
|
|
@@ -0,0 +1,136 @@
|
|
|
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
|
+
|
|
17
|
+
from typing import List
|
|
18
|
+
|
|
19
|
+
import mlx.core as mx
|
|
20
|
+
import mlx.nn as nn
|
|
21
|
+
|
|
22
|
+
from mlx_audio.codec.models.vocos.vocos import VocosBackbone
|
|
23
|
+
from mlx_audio.tts.models.spark.modules.blocks.sampler import SamplingBlock
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Encoder(nn.Module):
|
|
27
|
+
"""Encoder module with convnext and downsampling blocks"""
|
|
28
|
+
|
|
29
|
+
def __init__(
|
|
30
|
+
self,
|
|
31
|
+
input_channels: int,
|
|
32
|
+
vocos_dim: int,
|
|
33
|
+
vocos_intermediate_dim: int,
|
|
34
|
+
vocos_num_layers: int,
|
|
35
|
+
out_channels: int,
|
|
36
|
+
sample_ratios: List[int] = [1, 1],
|
|
37
|
+
):
|
|
38
|
+
super().__init__()
|
|
39
|
+
"""
|
|
40
|
+
Encoder module with VocosBackbone and sampling blocks.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
sample_ratios (List[int]): sample ratios
|
|
44
|
+
example: [2, 2] means downsample by 2x and then upsample by 2x
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
self.encoder = VocosBackbone(
|
|
48
|
+
input_channels=input_channels,
|
|
49
|
+
dim=vocos_dim,
|
|
50
|
+
intermediate_dim=vocos_intermediate_dim,
|
|
51
|
+
num_layers=vocos_num_layers,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
modules = []
|
|
55
|
+
|
|
56
|
+
for ratio in sample_ratios:
|
|
57
|
+
modules.append(
|
|
58
|
+
[
|
|
59
|
+
SamplingBlock(
|
|
60
|
+
dim=vocos_dim,
|
|
61
|
+
groups=vocos_dim,
|
|
62
|
+
downsample_scale=ratio,
|
|
63
|
+
),
|
|
64
|
+
VocosBackbone(
|
|
65
|
+
input_channels=vocos_dim,
|
|
66
|
+
dim=vocos_dim,
|
|
67
|
+
intermediate_dim=vocos_intermediate_dim,
|
|
68
|
+
num_layers=2,
|
|
69
|
+
bias=True,
|
|
70
|
+
),
|
|
71
|
+
]
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
self.downsample = modules
|
|
75
|
+
|
|
76
|
+
self.project = nn.Linear(vocos_dim, out_channels)
|
|
77
|
+
|
|
78
|
+
def __call__(self, x: mx.array, *args):
|
|
79
|
+
"""
|
|
80
|
+
Args:
|
|
81
|
+
x (mx.array): (batch_size, input_channels, length)
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
x (mx.array): (batch_size, encode_channels, length)
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
x = self.encoder(x)
|
|
88
|
+
|
|
89
|
+
for modules in self.downsample:
|
|
90
|
+
for module in modules:
|
|
91
|
+
x = x.transpose(0, 2, 1)
|
|
92
|
+
x = module(x)
|
|
93
|
+
|
|
94
|
+
x = self.project(x)
|
|
95
|
+
return x.transpose(0, 2, 1)
|
|
96
|
+
|
|
97
|
+
def sanitize(self, weights):
|
|
98
|
+
sanitized_weights = {}
|
|
99
|
+
for k, v in weights.items():
|
|
100
|
+
if "dwconv.weight" in k:
|
|
101
|
+
if v.shape[1] < v.shape[-1]:
|
|
102
|
+
sanitized_weights[k] = v.transpose(0, 2, 1)
|
|
103
|
+
else:
|
|
104
|
+
sanitized_weights[k] = v
|
|
105
|
+
elif "embed.weight" in k:
|
|
106
|
+
if v.shape[1] > v.shape[-1]:
|
|
107
|
+
sanitized_weights[k] = v.transpose(0, 2, 1)
|
|
108
|
+
else:
|
|
109
|
+
sanitized_weights[k] = v
|
|
110
|
+
|
|
111
|
+
else:
|
|
112
|
+
sanitized_weights[k] = v
|
|
113
|
+
|
|
114
|
+
return sanitized_weights
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
# test
|
|
118
|
+
if __name__ == "__main__":
|
|
119
|
+
test_input = mx.random.normal(
|
|
120
|
+
(8, 1024, 50), dtype=mx.float32
|
|
121
|
+
) # Batch size = 8, 1024 channels, length = 50
|
|
122
|
+
encoder = Encoder(
|
|
123
|
+
input_channels=1024,
|
|
124
|
+
vocos_dim=384,
|
|
125
|
+
vocos_intermediate_dim=2048,
|
|
126
|
+
vocos_num_layers=12,
|
|
127
|
+
out_channels=256,
|
|
128
|
+
sample_ratios=[2, 2],
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
output = encoder(test_input)
|
|
132
|
+
print(output.shape) # torch.Size([8, 256, 12])
|
|
133
|
+
if output.shape == (8, 256, 12):
|
|
134
|
+
print("test successful")
|
|
135
|
+
else:
|
|
136
|
+
print("test failed")
|
nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/encoder_decoder/wave_generator.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import mlx.core as mx
|
|
2
|
+
import mlx.nn as nn
|
|
3
|
+
|
|
4
|
+
from mlx_audio.codec.models.descript.dac import (
|
|
5
|
+
ResidualUnit,
|
|
6
|
+
Snake1d,
|
|
7
|
+
WNConv1d,
|
|
8
|
+
WNConvTranspose1d,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class DecoderBlock(nn.Module):
|
|
13
|
+
def __init__(
|
|
14
|
+
self,
|
|
15
|
+
input_dim: int = 16,
|
|
16
|
+
output_dim: int = 8,
|
|
17
|
+
kernel_size: int = 2,
|
|
18
|
+
stride: int = 1,
|
|
19
|
+
):
|
|
20
|
+
super().__init__()
|
|
21
|
+
self.block = nn.Sequential(
|
|
22
|
+
Snake1d(input_dim),
|
|
23
|
+
WNConvTranspose1d(
|
|
24
|
+
input_dim,
|
|
25
|
+
output_dim,
|
|
26
|
+
kernel_size=kernel_size,
|
|
27
|
+
stride=stride,
|
|
28
|
+
padding=(kernel_size - stride) // 2,
|
|
29
|
+
),
|
|
30
|
+
ResidualUnit(output_dim, dilation=1),
|
|
31
|
+
ResidualUnit(output_dim, dilation=3),
|
|
32
|
+
ResidualUnit(output_dim, dilation=9),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
def __call__(self, x):
|
|
36
|
+
return self.block(x)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class WaveGenerator(nn.Module):
|
|
40
|
+
def __init__(
|
|
41
|
+
self,
|
|
42
|
+
input_channel,
|
|
43
|
+
channels,
|
|
44
|
+
rates,
|
|
45
|
+
kernel_sizes,
|
|
46
|
+
d_out: int = 1,
|
|
47
|
+
):
|
|
48
|
+
super().__init__()
|
|
49
|
+
|
|
50
|
+
# Add first conv layer
|
|
51
|
+
layers = [WNConv1d(input_channel, channels, kernel_size=7, padding=3)]
|
|
52
|
+
|
|
53
|
+
# Add upsampling + MRF blocks
|
|
54
|
+
for i, (kernel_size, stride) in enumerate(zip(kernel_sizes, rates)):
|
|
55
|
+
input_dim = channels // 2**i
|
|
56
|
+
output_dim = channels // 2 ** (i + 1)
|
|
57
|
+
layers += [DecoderBlock(input_dim, output_dim, kernel_size, stride)]
|
|
58
|
+
|
|
59
|
+
# Add final conv layer
|
|
60
|
+
layers += [
|
|
61
|
+
Snake1d(output_dim),
|
|
62
|
+
WNConv1d(output_dim, d_out, kernel_size=7, padding=3),
|
|
63
|
+
nn.Tanh(),
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
self.model = layers
|
|
67
|
+
|
|
68
|
+
def __call__(self, x):
|
|
69
|
+
x = x.transpose(0, 2, 1)
|
|
70
|
+
for module in self.model:
|
|
71
|
+
x = module(x)
|
|
72
|
+
return x.transpose(0, 2, 1)
|
|
73
|
+
|
|
74
|
+
def sanitize(self, weights):
|
|
75
|
+
sanitized_weights = {}
|
|
76
|
+
for k, v in weights.items():
|
|
77
|
+
|
|
78
|
+
if "decoder.model" in k:
|
|
79
|
+
if "block.layers" not in k:
|
|
80
|
+
k = k.replace("block", "block.layers")
|
|
81
|
+
sanitized_weights[k] = v
|
|
82
|
+
|
|
83
|
+
if ".alpha" in k:
|
|
84
|
+
if v.shape[1] > v.shape[-1]:
|
|
85
|
+
sanitized_weights[k] = v.transpose(0, 2, 1)
|
|
86
|
+
else:
|
|
87
|
+
sanitized_weights[k] = v
|
|
88
|
+
|
|
89
|
+
elif (
|
|
90
|
+
"decoder.model" in k
|
|
91
|
+
and "block.layers.1" in k
|
|
92
|
+
and ("weight_v" in k or "weight_g" in k)
|
|
93
|
+
and k.count("block") == 1
|
|
94
|
+
):
|
|
95
|
+
|
|
96
|
+
if v.shape[0] > v.shape[-1]:
|
|
97
|
+
sanitized_weights[k] = v.transpose(1, 2, 0)
|
|
98
|
+
else:
|
|
99
|
+
sanitized_weights[k] = v
|
|
100
|
+
else:
|
|
101
|
+
sanitized_weights[k] = v
|
|
102
|
+
return sanitized_weights
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
if __name__ == "__main__":
|
|
106
|
+
test_input = mx.random.normal((8, 1024, 50), dtype=mx.float32)
|
|
107
|
+
wave_generator = WaveGenerator(1024, 16, [2, 2], [7, 7])
|
|
108
|
+
output = wave_generator(test_input)
|
|
109
|
+
print(output.shape)
|
|
110
|
+
if output.shape == (8, 1, 203):
|
|
111
|
+
print("WaveGenerator test passed")
|
|
112
|
+
else:
|
|
113
|
+
print("WaveGenerator test failed")
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Finite Scalar Quantization: VQ-VAE Made Simple - https://arxiv.org/abs/2309.15505
|
|
3
|
+
Code adapted from Jax version in Appendix A.1
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from contextlib import nullcontext
|
|
9
|
+
from functools import partial, wraps
|
|
10
|
+
from typing import List, Tuple
|
|
11
|
+
|
|
12
|
+
import mlx.core as mx
|
|
13
|
+
import mlx.nn as nn
|
|
14
|
+
|
|
15
|
+
# helper functions
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def exists(v):
|
|
19
|
+
return v is not None
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def default(*args):
|
|
23
|
+
for arg in args:
|
|
24
|
+
if exists(arg):
|
|
25
|
+
return arg
|
|
26
|
+
return None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def maybe(fn):
|
|
30
|
+
@wraps(fn)
|
|
31
|
+
def inner(x, *args, **kwargs):
|
|
32
|
+
if not exists(x):
|
|
33
|
+
return x
|
|
34
|
+
return fn(x, *args, **kwargs)
|
|
35
|
+
|
|
36
|
+
return inner
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# tensor helpers
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def round_ste(z: mx.array) -> mx.array:
|
|
43
|
+
"""Round with straight through gradients."""
|
|
44
|
+
zhat = z.round()
|
|
45
|
+
return z + (zhat - z)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# main class
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class FSQ(nn.Module):
|
|
52
|
+
def __init__(
|
|
53
|
+
self,
|
|
54
|
+
levels: List[int],
|
|
55
|
+
dim: int | None = None,
|
|
56
|
+
num_codebooks=1,
|
|
57
|
+
keep_num_codebooks_dim: bool | None = None,
|
|
58
|
+
scale: float | None = None,
|
|
59
|
+
allowed_dtypes: Tuple[mx.dtype, ...] = (mx.float32, mx.float64),
|
|
60
|
+
channel_first: bool = False,
|
|
61
|
+
projection_has_bias: bool = True,
|
|
62
|
+
return_indices=True,
|
|
63
|
+
force_quantization_f32=True,
|
|
64
|
+
):
|
|
65
|
+
super().__init__()
|
|
66
|
+
_levels = mx.array(list(levels), dtype=mx.int32)
|
|
67
|
+
self._levels = _levels
|
|
68
|
+
|
|
69
|
+
_basis = mx.cumprod(mx.array([1] + list(levels[:-1])), axis=0)
|
|
70
|
+
self._basis = _basis
|
|
71
|
+
|
|
72
|
+
self.scale = scale
|
|
73
|
+
|
|
74
|
+
codebook_dim = len(levels)
|
|
75
|
+
self.codebook_dim = codebook_dim
|
|
76
|
+
|
|
77
|
+
effective_codebook_dim = codebook_dim * num_codebooks
|
|
78
|
+
self.num_codebooks = num_codebooks
|
|
79
|
+
self.effective_codebook_dim = effective_codebook_dim
|
|
80
|
+
|
|
81
|
+
keep_num_codebooks_dim = default(keep_num_codebooks_dim, num_codebooks > 1)
|
|
82
|
+
assert not (num_codebooks > 1 and not keep_num_codebooks_dim)
|
|
83
|
+
self.keep_num_codebooks_dim = keep_num_codebooks_dim
|
|
84
|
+
|
|
85
|
+
self.dim = default(dim, len(_levels) * num_codebooks)
|
|
86
|
+
|
|
87
|
+
self.channel_first = channel_first
|
|
88
|
+
|
|
89
|
+
has_projections = self.dim != effective_codebook_dim
|
|
90
|
+
self.project_in = (
|
|
91
|
+
nn.Linear(self.dim, effective_codebook_dim, bias=projection_has_bias)
|
|
92
|
+
if has_projections
|
|
93
|
+
else nn.Identity()
|
|
94
|
+
)
|
|
95
|
+
self.project_out = (
|
|
96
|
+
nn.Linear(effective_codebook_dim, self.dim, bias=projection_has_bias)
|
|
97
|
+
if has_projections
|
|
98
|
+
else nn.Identity()
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
self.has_projections = has_projections
|
|
102
|
+
|
|
103
|
+
self.return_indices = return_indices
|
|
104
|
+
if return_indices:
|
|
105
|
+
self.codebook_size = self._levels.prod().item()
|
|
106
|
+
implicit_codebook = self._indices_to_codes(mx.arange(self.codebook_size))
|
|
107
|
+
self._implicit_codebook = implicit_codebook
|
|
108
|
+
|
|
109
|
+
self.allowed_dtypes = allowed_dtypes
|
|
110
|
+
self.force_quantization_f32 = force_quantization_f32
|
|
111
|
+
|
|
112
|
+
def atanh(self, x):
|
|
113
|
+
return mx.log((1 + x) / (1 - x)) / 2
|
|
114
|
+
|
|
115
|
+
def bound(self, z, eps: float = 1e-3):
|
|
116
|
+
"""Bound `z`, an array of shape (..., d)."""
|
|
117
|
+
half_l = (self._levels - 1) * (1 + eps) / 2
|
|
118
|
+
offset = mx.where(self._levels % 2 == 0, 0.5, 0.0)
|
|
119
|
+
shift = self.atanh(offset / half_l) # original atanh
|
|
120
|
+
return mx.tanh(z + shift) * half_l - offset
|
|
121
|
+
|
|
122
|
+
def quantize(self, z):
|
|
123
|
+
"""Quantizes z, returns quantized zhat, same shape as z."""
|
|
124
|
+
quantized = round_ste(self.bound(z))
|
|
125
|
+
half_width = self._levels // 2 # Renormalize to [-1, 1].
|
|
126
|
+
return quantized / half_width
|
|
127
|
+
|
|
128
|
+
def _scale_and_shift(self, zhat_normalized):
|
|
129
|
+
half_width = self._levels // 2
|
|
130
|
+
return (zhat_normalized * half_width) + half_width
|
|
131
|
+
|
|
132
|
+
def _scale_and_shift_inverse(self, zhat):
|
|
133
|
+
half_width = self._levels // 2
|
|
134
|
+
return (zhat - half_width) / half_width
|
|
135
|
+
|
|
136
|
+
def _indices_to_codes(self, indices):
|
|
137
|
+
level_indices = self.indices_to_level_indices(indices)
|
|
138
|
+
codes = self._scale_and_shift_inverse(level_indices)
|
|
139
|
+
return codes
|
|
140
|
+
|
|
141
|
+
def codes_to_indices(self, zhat):
|
|
142
|
+
"""Converts a `code` to an index in the codebook."""
|
|
143
|
+
assert zhat.shape[-1] == self.codebook_dim
|
|
144
|
+
zhat = self._scale_and_shift(zhat)
|
|
145
|
+
return (zhat * self._basis).sum(axis=-1).astype(mx.int32)
|
|
146
|
+
|
|
147
|
+
def indices_to_level_indices(self, indices):
|
|
148
|
+
"""Converts indices to indices at each level, perhaps needed for a transformer with factorized embeddings"""
|
|
149
|
+
indices = mx.reshape(indices, (indices.shape[0], -1, 1))
|
|
150
|
+
codes_non_centered = (indices // self._basis) % self._levels
|
|
151
|
+
return codes_non_centered
|
|
152
|
+
|
|
153
|
+
def indices_to_codes(self, indices):
|
|
154
|
+
"""Inverse of `codes_to_indices`."""
|
|
155
|
+
assert exists(indices)
|
|
156
|
+
|
|
157
|
+
is_img_or_video = indices.ndim >= (3 + int(self.keep_num_codebooks_dim))
|
|
158
|
+
|
|
159
|
+
codes = self._indices_to_codes(indices)
|
|
160
|
+
|
|
161
|
+
if self.keep_num_codebooks_dim:
|
|
162
|
+
codes = mx.reshape(codes, (codes.shape[0], -1))
|
|
163
|
+
|
|
164
|
+
codes = self.project_out(codes)
|
|
165
|
+
|
|
166
|
+
if is_img_or_video or self.channel_first:
|
|
167
|
+
codes = mx.reshape(codes, (codes.shape[0], -1, codes.shape[-1]))
|
|
168
|
+
|
|
169
|
+
return codes
|
|
170
|
+
|
|
171
|
+
def __call__(self, z):
|
|
172
|
+
"""
|
|
173
|
+
einstein notation
|
|
174
|
+
b - batch
|
|
175
|
+
n - sequence (or flattened spatial dimensions)
|
|
176
|
+
d - feature dimension
|
|
177
|
+
c - number of codebook dim
|
|
178
|
+
"""
|
|
179
|
+
|
|
180
|
+
is_img_or_video = z.ndim >= 4
|
|
181
|
+
need_move_channel_last = is_img_or_video or self.channel_first
|
|
182
|
+
|
|
183
|
+
# standardize image or video into (batch, seq, dimension)
|
|
184
|
+
|
|
185
|
+
if need_move_channel_last:
|
|
186
|
+
z = mx.reshape(z, (z.shape[0], -1, z.shape[-1]))
|
|
187
|
+
# z = mx.reshape(z, (z.shape[0], -1))
|
|
188
|
+
|
|
189
|
+
assert (
|
|
190
|
+
z.shape[-1] == self.dim
|
|
191
|
+
), f"expected dimension of {self.dim} but found dimension of {z.shape[-1]}"
|
|
192
|
+
|
|
193
|
+
z = self.project_in(z)
|
|
194
|
+
|
|
195
|
+
z = mx.reshape(z, (z.shape[0], z.shape[1], self.num_codebooks, z.shape[-1]))
|
|
196
|
+
|
|
197
|
+
# whether to force quantization step to be full precision or not
|
|
198
|
+
|
|
199
|
+
force_f32 = self.force_quantization_f32
|
|
200
|
+
|
|
201
|
+
orig_dtype = z.dtype
|
|
202
|
+
|
|
203
|
+
if force_f32 and orig_dtype not in self.allowed_dtypes:
|
|
204
|
+
z = z.float()
|
|
205
|
+
|
|
206
|
+
codes = self.quantize(z)
|
|
207
|
+
|
|
208
|
+
# returning indices could be optional
|
|
209
|
+
|
|
210
|
+
indices = None
|
|
211
|
+
|
|
212
|
+
if self.return_indices:
|
|
213
|
+
indices = self.codes_to_indices(codes)
|
|
214
|
+
|
|
215
|
+
codes = mx.reshape(codes, (codes.shape[0], codes.shape[1], -1))
|
|
216
|
+
|
|
217
|
+
codes = codes.astype(orig_dtype)
|
|
218
|
+
|
|
219
|
+
# project out
|
|
220
|
+
|
|
221
|
+
out = self.project_out(codes)
|
|
222
|
+
|
|
223
|
+
# reconstitute image or video dimensions
|
|
224
|
+
|
|
225
|
+
if need_move_channel_last:
|
|
226
|
+
out = mx.reshape(out, (out.shape[0], -1, out.shape[-1]))
|
|
227
|
+
out = mx.reshape(
|
|
228
|
+
out, (out.shape[0], out.shape[1], out.shape[2], out.shape[-1])
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
indices = mx.reshape(indices, (indices.shape[0], -1, indices.shape[-1]))
|
|
232
|
+
|
|
233
|
+
if not self.keep_num_codebooks_dim and self.return_indices:
|
|
234
|
+
indices = mx.reshape(indices, (indices.shape[0], -1, indices.shape[-1]))
|
|
235
|
+
|
|
236
|
+
# return quantized output and indices
|
|
237
|
+
|
|
238
|
+
return out, indices
|