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,385 @@
|
|
|
1
|
+
# Copyright © 2023-2024 Apple Inc.
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
import mlx.core as mx
|
|
8
|
+
from huggingface_hub import hf_hub_download
|
|
9
|
+
from mlx.utils import tree_unflatten
|
|
10
|
+
|
|
11
|
+
from .clip import CLIPTextModel
|
|
12
|
+
from .config import AutoencoderConfig, CLIPTextModelConfig, DiffusionConfig, UNetConfig
|
|
13
|
+
from .tokenizer import Tokenizer
|
|
14
|
+
from .unet import UNetModel
|
|
15
|
+
from .vae import Autoencoder
|
|
16
|
+
|
|
17
|
+
_DEFAULT_MODEL = "stabilityai/stable-diffusion-2-1-base"
|
|
18
|
+
_MODELS = {
|
|
19
|
+
# See https://huggingface.co/stabilityai/sdxl-turbo for the model details and license
|
|
20
|
+
"stabilityai/sdxl-turbo": {
|
|
21
|
+
"unet_config": "unet/config.json",
|
|
22
|
+
"unet": "unet/diffusion_pytorch_model.safetensors",
|
|
23
|
+
"text_encoder_config": "text_encoder/config.json",
|
|
24
|
+
"text_encoder": "text_encoder/model.safetensors",
|
|
25
|
+
"text_encoder_2_config": "text_encoder_2/config.json",
|
|
26
|
+
"text_encoder_2": "text_encoder_2/model.safetensors",
|
|
27
|
+
"vae_config": "vae/config.json",
|
|
28
|
+
"vae": "vae/diffusion_pytorch_model.safetensors",
|
|
29
|
+
"diffusion_config": "scheduler/scheduler_config.json",
|
|
30
|
+
"tokenizer_vocab": "tokenizer/vocab.json",
|
|
31
|
+
"tokenizer_merges": "tokenizer/merges.txt",
|
|
32
|
+
"tokenizer_2_vocab": "tokenizer_2/vocab.json",
|
|
33
|
+
"tokenizer_2_merges": "tokenizer_2/merges.txt",
|
|
34
|
+
},
|
|
35
|
+
# See https://huggingface.co/stabilityai/stable-diffusion-2-1-base for the model details and license
|
|
36
|
+
"stabilityai/stable-diffusion-2-1-base": {
|
|
37
|
+
"unet_config": "unet/config.json",
|
|
38
|
+
"unet": "unet/diffusion_pytorch_model.safetensors",
|
|
39
|
+
"text_encoder_config": "text_encoder/config.json",
|
|
40
|
+
"text_encoder": "text_encoder/model.safetensors",
|
|
41
|
+
"vae_config": "vae/config.json",
|
|
42
|
+
"vae": "vae/diffusion_pytorch_model.safetensors",
|
|
43
|
+
"diffusion_config": "scheduler/scheduler_config.json",
|
|
44
|
+
"tokenizer_vocab": "tokenizer/vocab.json",
|
|
45
|
+
"tokenizer_merges": "tokenizer/merges.txt",
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def map_unet_weights(key, value):
|
|
51
|
+
# Map up/downsampling
|
|
52
|
+
if "downsamplers" in key:
|
|
53
|
+
key = key.replace("downsamplers.0.conv", "downsample")
|
|
54
|
+
if "upsamplers" in key:
|
|
55
|
+
key = key.replace("upsamplers.0.conv", "upsample")
|
|
56
|
+
|
|
57
|
+
# Map the mid block
|
|
58
|
+
if "mid_block.resnets.0" in key:
|
|
59
|
+
key = key.replace("mid_block.resnets.0", "mid_blocks.0")
|
|
60
|
+
if "mid_block.attentions.0" in key:
|
|
61
|
+
key = key.replace("mid_block.attentions.0", "mid_blocks.1")
|
|
62
|
+
if "mid_block.resnets.1" in key:
|
|
63
|
+
key = key.replace("mid_block.resnets.1", "mid_blocks.2")
|
|
64
|
+
|
|
65
|
+
# Map attention layers
|
|
66
|
+
if "to_k" in key:
|
|
67
|
+
key = key.replace("to_k", "key_proj")
|
|
68
|
+
if "to_out.0" in key:
|
|
69
|
+
key = key.replace("to_out.0", "out_proj")
|
|
70
|
+
if "to_q" in key:
|
|
71
|
+
key = key.replace("to_q", "query_proj")
|
|
72
|
+
if "to_v" in key:
|
|
73
|
+
key = key.replace("to_v", "value_proj")
|
|
74
|
+
|
|
75
|
+
# Map transformer ffn
|
|
76
|
+
if "ff.net.2" in key:
|
|
77
|
+
key = key.replace("ff.net.2", "linear3")
|
|
78
|
+
if "ff.net.0" in key:
|
|
79
|
+
k1 = key.replace("ff.net.0.proj", "linear1")
|
|
80
|
+
k2 = key.replace("ff.net.0.proj", "linear2")
|
|
81
|
+
v1, v2 = mx.split(value, 2)
|
|
82
|
+
|
|
83
|
+
return [(k1, v1), (k2, v2)]
|
|
84
|
+
|
|
85
|
+
if "conv_shortcut.weight" in key:
|
|
86
|
+
value = value.squeeze()
|
|
87
|
+
|
|
88
|
+
# Transform the weights from 1x1 convs to linear
|
|
89
|
+
if len(value.shape) == 4 and ("proj_in" in key or "proj_out" in key):
|
|
90
|
+
value = value.squeeze()
|
|
91
|
+
|
|
92
|
+
if len(value.shape) == 4:
|
|
93
|
+
value = value.transpose(0, 2, 3, 1)
|
|
94
|
+
value = value.reshape(-1).reshape(value.shape)
|
|
95
|
+
|
|
96
|
+
return [(key, value)]
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def map_clip_text_encoder_weights(key, value):
|
|
100
|
+
# Remove prefixes
|
|
101
|
+
if key.startswith("text_model."):
|
|
102
|
+
key = key[11:]
|
|
103
|
+
if key.startswith("embeddings."):
|
|
104
|
+
key = key[11:]
|
|
105
|
+
if key.startswith("encoder."):
|
|
106
|
+
key = key[8:]
|
|
107
|
+
|
|
108
|
+
# Map attention layers
|
|
109
|
+
if "self_attn." in key:
|
|
110
|
+
key = key.replace("self_attn.", "attention.")
|
|
111
|
+
if "q_proj." in key:
|
|
112
|
+
key = key.replace("q_proj.", "query_proj.")
|
|
113
|
+
if "k_proj." in key:
|
|
114
|
+
key = key.replace("k_proj.", "key_proj.")
|
|
115
|
+
if "v_proj." in key:
|
|
116
|
+
key = key.replace("v_proj.", "value_proj.")
|
|
117
|
+
|
|
118
|
+
# Map ffn layers
|
|
119
|
+
if "mlp.fc1" in key:
|
|
120
|
+
key = key.replace("mlp.fc1", "linear1")
|
|
121
|
+
if "mlp.fc2" in key:
|
|
122
|
+
key = key.replace("mlp.fc2", "linear2")
|
|
123
|
+
|
|
124
|
+
return [(key, value)]
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def map_vae_weights(key, value):
|
|
128
|
+
# Map up/downsampling
|
|
129
|
+
if "downsamplers" in key:
|
|
130
|
+
key = key.replace("downsamplers.0.conv", "downsample")
|
|
131
|
+
if "upsamplers" in key:
|
|
132
|
+
key = key.replace("upsamplers.0.conv", "upsample")
|
|
133
|
+
|
|
134
|
+
# Map attention layers
|
|
135
|
+
if "to_k" in key:
|
|
136
|
+
key = key.replace("to_k", "key_proj")
|
|
137
|
+
if "to_out.0" in key:
|
|
138
|
+
key = key.replace("to_out.0", "out_proj")
|
|
139
|
+
if "to_q" in key:
|
|
140
|
+
key = key.replace("to_q", "query_proj")
|
|
141
|
+
if "to_v" in key:
|
|
142
|
+
key = key.replace("to_v", "value_proj")
|
|
143
|
+
|
|
144
|
+
# Map the mid block
|
|
145
|
+
if "mid_block.resnets.0" in key:
|
|
146
|
+
key = key.replace("mid_block.resnets.0", "mid_blocks.0")
|
|
147
|
+
if "mid_block.attentions.0" in key:
|
|
148
|
+
key = key.replace("mid_block.attentions.0", "mid_blocks.1")
|
|
149
|
+
if "mid_block.resnets.1" in key:
|
|
150
|
+
key = key.replace("mid_block.resnets.1", "mid_blocks.2")
|
|
151
|
+
|
|
152
|
+
# Map the quant/post_quant layers
|
|
153
|
+
if "quant_conv" in key:
|
|
154
|
+
key = key.replace("quant_conv", "quant_proj")
|
|
155
|
+
value = value.squeeze()
|
|
156
|
+
|
|
157
|
+
# Map the conv_shortcut to linear
|
|
158
|
+
if "conv_shortcut.weight" in key:
|
|
159
|
+
value = value.squeeze()
|
|
160
|
+
|
|
161
|
+
if len(value.shape) == 4:
|
|
162
|
+
value = value.transpose(0, 2, 3, 1)
|
|
163
|
+
value = value.reshape(-1).reshape(value.shape)
|
|
164
|
+
|
|
165
|
+
return [(key, value)]
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def _flatten(params):
|
|
169
|
+
return [(k, v) for p in params for (k, v) in p]
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _load_safetensor_weights(mapper, model, weight_file, float16: bool = False):
|
|
173
|
+
dtype = mx.float16 if float16 else mx.float32
|
|
174
|
+
weights = mx.load(weight_file)
|
|
175
|
+
weights = _flatten([mapper(k, v.astype(dtype)) for k, v in weights.items()])
|
|
176
|
+
model.update(tree_unflatten(weights))
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _check_key(key: str, part: str):
|
|
180
|
+
# Check if it's a local path
|
|
181
|
+
if os.path.exists(key) or '/' in key or '\\' in key:
|
|
182
|
+
# For local paths, we'll use a default model structure
|
|
183
|
+
return
|
|
184
|
+
if key not in _MODELS:
|
|
185
|
+
raise ValueError(
|
|
186
|
+
f"[{part}] '{key}' model not found, choose one of {{{','.join(_MODELS.keys())}}}"
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
def _get_model_path(key: str, file_path: str):
|
|
190
|
+
"""Get the full path for a model file, supporting both local and HuggingFace paths"""
|
|
191
|
+
if os.path.exists(key) or '/' in key or '\\' in key:
|
|
192
|
+
# Local path
|
|
193
|
+
return os.path.join(key, file_path)
|
|
194
|
+
else:
|
|
195
|
+
# HuggingFace path
|
|
196
|
+
return hf_hub_download(key, file_path)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def load_unet(key: str = _DEFAULT_MODEL, float16: bool = False):
|
|
200
|
+
"""Load the stable diffusion UNet from Hugging Face Hub."""
|
|
201
|
+
_check_key(key, "load_unet")
|
|
202
|
+
|
|
203
|
+
# Get the config path
|
|
204
|
+
if os.path.exists(key) or '/' in key or '\\' in key:
|
|
205
|
+
# Local path - use SDXL Turbo structure
|
|
206
|
+
unet_config = "unet/config.json"
|
|
207
|
+
else:
|
|
208
|
+
unet_config = _MODELS[key]["unet_config"]
|
|
209
|
+
|
|
210
|
+
with open(_get_model_path(key, unet_config)) as f:
|
|
211
|
+
config = json.load(f)
|
|
212
|
+
|
|
213
|
+
n_blocks = len(config["block_out_channels"])
|
|
214
|
+
model = UNetModel(
|
|
215
|
+
UNetConfig(
|
|
216
|
+
in_channels=config["in_channels"],
|
|
217
|
+
out_channels=config["out_channels"],
|
|
218
|
+
block_out_channels=config["block_out_channels"],
|
|
219
|
+
layers_per_block=[config["layers_per_block"]] * n_blocks,
|
|
220
|
+
transformer_layers_per_block=config.get(
|
|
221
|
+
"transformer_layers_per_block", (1,) * 4
|
|
222
|
+
),
|
|
223
|
+
num_attention_heads=(
|
|
224
|
+
[config["attention_head_dim"]] * n_blocks
|
|
225
|
+
if isinstance(config["attention_head_dim"], int)
|
|
226
|
+
else config["attention_head_dim"]
|
|
227
|
+
),
|
|
228
|
+
cross_attention_dim=[config["cross_attention_dim"]] * n_blocks,
|
|
229
|
+
norm_num_groups=config["norm_num_groups"],
|
|
230
|
+
down_block_types=config["down_block_types"],
|
|
231
|
+
up_block_types=config["up_block_types"][::-1],
|
|
232
|
+
addition_embed_type=config.get("addition_embed_type", None),
|
|
233
|
+
addition_time_embed_dim=config.get("addition_time_embed_dim", None),
|
|
234
|
+
projection_class_embeddings_input_dim=config.get(
|
|
235
|
+
"projection_class_embeddings_input_dim", None
|
|
236
|
+
),
|
|
237
|
+
)
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
# Download the weights and map them into the model
|
|
241
|
+
if os.path.exists(key) or '/' in key or '\\' in key:
|
|
242
|
+
# Local path - use SDXL Turbo structure
|
|
243
|
+
unet_weights = "unet/diffusion_pytorch_model.safetensors"
|
|
244
|
+
else:
|
|
245
|
+
unet_weights = _MODELS[key]["unet"]
|
|
246
|
+
|
|
247
|
+
weight_file = _get_model_path(key, unet_weights)
|
|
248
|
+
_load_safetensor_weights(map_unet_weights, model, weight_file, float16)
|
|
249
|
+
|
|
250
|
+
return model
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def load_text_encoder(
|
|
254
|
+
key: str = _DEFAULT_MODEL,
|
|
255
|
+
float16: bool = False,
|
|
256
|
+
model_key: str = "text_encoder",
|
|
257
|
+
config_key: Optional[str] = None,
|
|
258
|
+
):
|
|
259
|
+
"""Load the stable diffusion text encoder from Hugging Face Hub."""
|
|
260
|
+
_check_key(key, "load_text_encoder")
|
|
261
|
+
|
|
262
|
+
config_key = config_key or (model_key + "_config")
|
|
263
|
+
|
|
264
|
+
# Download the config and create the model
|
|
265
|
+
if os.path.exists(key) or '/' in key or '\\' in key:
|
|
266
|
+
# Local path - use SDXL Turbo structure
|
|
267
|
+
text_encoder_config = f"{model_key}/config.json"
|
|
268
|
+
else:
|
|
269
|
+
text_encoder_config = _MODELS[key][config_key]
|
|
270
|
+
|
|
271
|
+
with open(_get_model_path(key, text_encoder_config)) as f:
|
|
272
|
+
config = json.load(f)
|
|
273
|
+
|
|
274
|
+
with_projection = "WithProjection" in config["architectures"][0]
|
|
275
|
+
|
|
276
|
+
model = CLIPTextModel(
|
|
277
|
+
CLIPTextModelConfig(
|
|
278
|
+
num_layers=config["num_hidden_layers"],
|
|
279
|
+
model_dims=config["hidden_size"],
|
|
280
|
+
num_heads=config["num_attention_heads"],
|
|
281
|
+
max_length=config["max_position_embeddings"],
|
|
282
|
+
vocab_size=config["vocab_size"],
|
|
283
|
+
projection_dim=config["projection_dim"] if with_projection else None,
|
|
284
|
+
hidden_act=config.get("hidden_act", "quick_gelu"),
|
|
285
|
+
)
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
# Download the weights and map them into the model
|
|
289
|
+
if os.path.exists(key) or '/' in key or '\\' in key:
|
|
290
|
+
# Local path - use SDXL Turbo structure
|
|
291
|
+
text_encoder_weights = f"{model_key}/model.safetensors"
|
|
292
|
+
else:
|
|
293
|
+
text_encoder_weights = _MODELS[key][model_key]
|
|
294
|
+
|
|
295
|
+
weight_file = _get_model_path(key, text_encoder_weights)
|
|
296
|
+
_load_safetensor_weights(map_clip_text_encoder_weights, model, weight_file, float16)
|
|
297
|
+
|
|
298
|
+
return model
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def load_autoencoder(key: str = _DEFAULT_MODEL, float16: bool = False):
|
|
302
|
+
"""Load the stable diffusion autoencoder from Hugging Face Hub."""
|
|
303
|
+
_check_key(key, "load_autoencoder")
|
|
304
|
+
|
|
305
|
+
# Download the config and create the model
|
|
306
|
+
if os.path.exists(key) or '/' in key or '\\' in key:
|
|
307
|
+
# Local path - use SDXL Turbo structure
|
|
308
|
+
vae_config = "vae/config.json"
|
|
309
|
+
else:
|
|
310
|
+
vae_config = _MODELS[key]["vae_config"]
|
|
311
|
+
|
|
312
|
+
with open(_get_model_path(key, vae_config)) as f:
|
|
313
|
+
config = json.load(f)
|
|
314
|
+
|
|
315
|
+
model = Autoencoder(
|
|
316
|
+
AutoencoderConfig(
|
|
317
|
+
in_channels=config["in_channels"],
|
|
318
|
+
out_channels=config["out_channels"],
|
|
319
|
+
latent_channels_out=2 * config["latent_channels"],
|
|
320
|
+
latent_channels_in=config["latent_channels"],
|
|
321
|
+
block_out_channels=config["block_out_channels"],
|
|
322
|
+
layers_per_block=config["layers_per_block"],
|
|
323
|
+
norm_num_groups=config["norm_num_groups"],
|
|
324
|
+
scaling_factor=config.get("scaling_factor", 0.18215),
|
|
325
|
+
)
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
# Download the weights and map them into the model
|
|
329
|
+
if os.path.exists(key) or '/' in key or '\\' in key:
|
|
330
|
+
# Local path - use SDXL Turbo structure
|
|
331
|
+
vae_weights = "vae/diffusion_pytorch_model.safetensors"
|
|
332
|
+
else:
|
|
333
|
+
vae_weights = _MODELS[key]["vae"]
|
|
334
|
+
|
|
335
|
+
weight_file = _get_model_path(key, vae_weights)
|
|
336
|
+
_load_safetensor_weights(map_vae_weights, model, weight_file, float16)
|
|
337
|
+
|
|
338
|
+
return model
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def load_diffusion_config(key: str = _DEFAULT_MODEL):
|
|
342
|
+
"""Load the stable diffusion config from Hugging Face Hub."""
|
|
343
|
+
_check_key(key, "load_diffusion_config")
|
|
344
|
+
|
|
345
|
+
if os.path.exists(key) or '/' in key or '\\' in key:
|
|
346
|
+
# Local path - use SDXL Turbo structure
|
|
347
|
+
diffusion_config = "scheduler/scheduler_config.json"
|
|
348
|
+
else:
|
|
349
|
+
diffusion_config = _MODELS[key]["diffusion_config"]
|
|
350
|
+
|
|
351
|
+
with open(_get_model_path(key, diffusion_config)) as f:
|
|
352
|
+
config = json.load(f)
|
|
353
|
+
|
|
354
|
+
return DiffusionConfig(
|
|
355
|
+
beta_start=config["beta_start"],
|
|
356
|
+
beta_end=config["beta_end"],
|
|
357
|
+
beta_schedule=config["beta_schedule"],
|
|
358
|
+
num_train_steps=config["num_train_timesteps"],
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def load_tokenizer(
|
|
363
|
+
key: str = _DEFAULT_MODEL,
|
|
364
|
+
vocab_key: str = "tokenizer_vocab",
|
|
365
|
+
merges_key: str = "tokenizer_merges",
|
|
366
|
+
):
|
|
367
|
+
_check_key(key, "load_tokenizer")
|
|
368
|
+
|
|
369
|
+
if os.path.exists(key) or '/' in key or '\\' in key:
|
|
370
|
+
# Local path - use SDXL Turbo structure
|
|
371
|
+
vocab_file = _get_model_path(key, f"tokenizer/{vocab_key.split('_')[1]}.json")
|
|
372
|
+
merges_file = _get_model_path(key, f"tokenizer/{merges_key.split('_')[1]}.txt")
|
|
373
|
+
else:
|
|
374
|
+
vocab_file = _get_model_path(key, _MODELS[key][vocab_key])
|
|
375
|
+
merges_file = _get_model_path(key, _MODELS[key][merges_key])
|
|
376
|
+
|
|
377
|
+
with open(vocab_file, encoding="utf-8") as f:
|
|
378
|
+
vocab = json.load(f)
|
|
379
|
+
|
|
380
|
+
with open(merges_file, encoding="utf-8") as f:
|
|
381
|
+
bpe_merges = f.read().strip().split("\n")[1 : 49152 - 256 - 2 + 1]
|
|
382
|
+
bpe_merges = [tuple(m.split()) for m in bpe_merges]
|
|
383
|
+
bpe_ranks = dict(map(reversed, enumerate(bpe_merges)))
|
|
384
|
+
|
|
385
|
+
return Tokenizer(bpe_ranks, vocab)
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Copyright © 2023 Apple Inc.
|
|
2
|
+
|
|
3
|
+
import mlx.core as mx
|
|
4
|
+
|
|
5
|
+
from .config import DiffusionConfig
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _linspace(a, b, num):
|
|
9
|
+
x = mx.arange(0, num) / (num - 1)
|
|
10
|
+
return (b - a) * x + a
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _interp(y, x_new):
|
|
14
|
+
"""Interpolate the function defined by (arange(0, len(y)), y) at positions x_new."""
|
|
15
|
+
x_low = x_new.astype(mx.int32)
|
|
16
|
+
x_high = mx.minimum(x_low + 1, len(y) - 1)
|
|
17
|
+
|
|
18
|
+
y_low = y[x_low]
|
|
19
|
+
y_high = y[x_high]
|
|
20
|
+
delta_x = x_new - x_low
|
|
21
|
+
y_new = y_low * (1 - delta_x) + delta_x * y_high
|
|
22
|
+
|
|
23
|
+
return y_new
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class SimpleEulerSampler:
|
|
27
|
+
"""A simple Euler integrator that can be used to sample from our diffusion models.
|
|
28
|
+
|
|
29
|
+
The method ``step()`` performs one Euler step from x_t to x_t_prev.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def __init__(self, config: DiffusionConfig):
|
|
33
|
+
# Compute the noise schedule
|
|
34
|
+
if config.beta_schedule == "linear":
|
|
35
|
+
betas = _linspace(
|
|
36
|
+
config.beta_start, config.beta_end, config.num_train_steps
|
|
37
|
+
)
|
|
38
|
+
elif config.beta_schedule == "scaled_linear":
|
|
39
|
+
betas = _linspace(
|
|
40
|
+
config.beta_start**0.5, config.beta_end**0.5, config.num_train_steps
|
|
41
|
+
).square()
|
|
42
|
+
else:
|
|
43
|
+
raise NotImplementedError(f"{config.beta_schedule} is not implemented.")
|
|
44
|
+
|
|
45
|
+
alphas = 1 - betas
|
|
46
|
+
alphas_cumprod = mx.cumprod(alphas)
|
|
47
|
+
|
|
48
|
+
self._sigmas = mx.concatenate(
|
|
49
|
+
[mx.zeros(1), ((1 - alphas_cumprod) / alphas_cumprod).sqrt()]
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def max_time(self):
|
|
54
|
+
return len(self._sigmas) - 1
|
|
55
|
+
|
|
56
|
+
def sample_prior(self, shape, dtype=mx.float32, key=None):
|
|
57
|
+
noise = mx.random.normal(shape, key=key)
|
|
58
|
+
return (
|
|
59
|
+
noise * self._sigmas[-1] * (self._sigmas[-1].square() + 1).rsqrt()
|
|
60
|
+
).astype(dtype)
|
|
61
|
+
|
|
62
|
+
def add_noise(self, x, t, key=None):
|
|
63
|
+
noise = mx.random.normal(x.shape, key=key)
|
|
64
|
+
s = self.sigmas(t)
|
|
65
|
+
return (x + noise * s) * (s.square() + 1).rsqrt()
|
|
66
|
+
|
|
67
|
+
def sigmas(self, t):
|
|
68
|
+
return _interp(self._sigmas, t)
|
|
69
|
+
|
|
70
|
+
def timesteps(self, num_steps: int, start_time=None, dtype=mx.float32):
|
|
71
|
+
start_time = start_time or (len(self._sigmas) - 1)
|
|
72
|
+
assert 0 < start_time <= (len(self._sigmas) - 1)
|
|
73
|
+
steps = _linspace(start_time, 0, num_steps + 1).astype(dtype)
|
|
74
|
+
return list(zip(steps, steps[1:]))
|
|
75
|
+
|
|
76
|
+
def step(self, eps_pred, x_t, t, t_prev):
|
|
77
|
+
sigma = self.sigmas(t).astype(eps_pred.dtype)
|
|
78
|
+
sigma_prev = self.sigmas(t_prev).astype(eps_pred.dtype)
|
|
79
|
+
|
|
80
|
+
dt = sigma_prev - sigma
|
|
81
|
+
x_t_prev = (sigma.square() + 1).sqrt() * x_t + eps_pred * dt
|
|
82
|
+
|
|
83
|
+
x_t_prev = x_t_prev * (sigma_prev.square() + 1).rsqrt()
|
|
84
|
+
|
|
85
|
+
return x_t_prev
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class SimpleEulerAncestralSampler(SimpleEulerSampler):
|
|
89
|
+
def step(self, eps_pred, x_t, t, t_prev):
|
|
90
|
+
sigma = self.sigmas(t).astype(eps_pred.dtype)
|
|
91
|
+
sigma_prev = self.sigmas(t_prev).astype(eps_pred.dtype)
|
|
92
|
+
|
|
93
|
+
sigma2 = sigma.square()
|
|
94
|
+
sigma_prev2 = sigma_prev.square()
|
|
95
|
+
sigma_up = (sigma_prev2 * (sigma2 - sigma_prev2) / sigma2).sqrt()
|
|
96
|
+
sigma_down = (sigma_prev2 - sigma_up**2).sqrt()
|
|
97
|
+
|
|
98
|
+
dt = sigma_down - sigma
|
|
99
|
+
x_t_prev = (sigma2 + 1).sqrt() * x_t + eps_pred * dt
|
|
100
|
+
noise = mx.random.normal(x_t_prev.shape).astype(x_t_prev.dtype)
|
|
101
|
+
x_t_prev = x_t_prev + noise * sigma_up
|
|
102
|
+
|
|
103
|
+
x_t_prev = x_t_prev * (sigma_prev2 + 1).rsqrt()
|
|
104
|
+
|
|
105
|
+
return x_t_prev
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Copyright © 2023 Apple Inc.
|
|
2
|
+
|
|
3
|
+
import regex
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Tokenizer:
|
|
7
|
+
"""A simple port of CLIPTokenizer from https://github.com/huggingface/transformers/ ."""
|
|
8
|
+
|
|
9
|
+
def __init__(self, bpe_ranks, vocab):
|
|
10
|
+
self.bpe_ranks = bpe_ranks
|
|
11
|
+
self.vocab = vocab
|
|
12
|
+
self.pat = regex.compile(
|
|
13
|
+
r"""<\|startoftext\|>|<\|endoftext\|>|'s|'t|'re|'ve|'m|'ll|'d|[\p{L}]+|[\p{N}]|[^\s\p{L}\p{N}]+""",
|
|
14
|
+
regex.IGNORECASE,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
self._cache = {self.bos: self.bos, self.eos: self.eos}
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def bos(self):
|
|
21
|
+
return "<|startoftext|>"
|
|
22
|
+
|
|
23
|
+
@property
|
|
24
|
+
def bos_token(self):
|
|
25
|
+
return self.vocab[self.bos]
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def eos(self):
|
|
29
|
+
return "<|endoftext|>"
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def eos_token(self):
|
|
33
|
+
return self.vocab[self.eos]
|
|
34
|
+
|
|
35
|
+
def bpe(self, text):
|
|
36
|
+
if text in self._cache:
|
|
37
|
+
return self._cache[text]
|
|
38
|
+
|
|
39
|
+
unigrams = list(text[:-1]) + [text[-1] + "</w>"]
|
|
40
|
+
unique_bigrams = set(zip(unigrams, unigrams[1:]))
|
|
41
|
+
|
|
42
|
+
if not unique_bigrams:
|
|
43
|
+
return unigrams
|
|
44
|
+
|
|
45
|
+
# In every iteration try to merge the two most likely bigrams. If none
|
|
46
|
+
# was merged we are done.
|
|
47
|
+
#
|
|
48
|
+
# Ported from https://github.com/huggingface/transformers/blob/main/src/transformers/models/clip/tokenization_clip.py
|
|
49
|
+
while unique_bigrams:
|
|
50
|
+
bigram = min(
|
|
51
|
+
unique_bigrams, key=lambda pair: self.bpe_ranks.get(pair, float("inf"))
|
|
52
|
+
)
|
|
53
|
+
if bigram not in self.bpe_ranks:
|
|
54
|
+
break
|
|
55
|
+
|
|
56
|
+
new_unigrams = []
|
|
57
|
+
skip = False
|
|
58
|
+
for a, b in zip(unigrams, unigrams[1:]):
|
|
59
|
+
if skip:
|
|
60
|
+
skip = False
|
|
61
|
+
continue
|
|
62
|
+
|
|
63
|
+
if (a, b) == bigram:
|
|
64
|
+
new_unigrams.append(a + b)
|
|
65
|
+
skip = True
|
|
66
|
+
|
|
67
|
+
else:
|
|
68
|
+
new_unigrams.append(a)
|
|
69
|
+
|
|
70
|
+
if not skip:
|
|
71
|
+
new_unigrams.append(b)
|
|
72
|
+
|
|
73
|
+
unigrams = new_unigrams
|
|
74
|
+
unique_bigrams = set(zip(unigrams, unigrams[1:]))
|
|
75
|
+
|
|
76
|
+
self._cache[text] = unigrams
|
|
77
|
+
|
|
78
|
+
return unigrams
|
|
79
|
+
|
|
80
|
+
def tokenize(self, text, prepend_bos=True, append_eos=True):
|
|
81
|
+
if isinstance(text, list):
|
|
82
|
+
return [self.tokenize(t, prepend_bos, append_eos) for t in text]
|
|
83
|
+
|
|
84
|
+
# Lower case cleanup and split according to self.pat. Hugging Face does
|
|
85
|
+
# a much more thorough job here but this should suffice for 95% of
|
|
86
|
+
# cases.
|
|
87
|
+
clean_text = regex.sub(r"\s+", " ", text.lower())
|
|
88
|
+
tokens = regex.findall(self.pat, clean_text)
|
|
89
|
+
|
|
90
|
+
# Split the tokens according to the byte-pair merge file
|
|
91
|
+
bpe_tokens = [ti for t in tokens for ti in self.bpe(t)]
|
|
92
|
+
|
|
93
|
+
# Map to token ids and return
|
|
94
|
+
tokens = [self.vocab[t] for t in bpe_tokens]
|
|
95
|
+
if prepend_bos:
|
|
96
|
+
tokens = [self.bos_token] + tokens
|
|
97
|
+
if append_eos:
|
|
98
|
+
tokens.append(self.eos_token)
|
|
99
|
+
|
|
100
|
+
return tokens
|