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,255 @@
|
|
|
1
|
+
# Copyright © 2023-2024 Apple Inc.
|
|
2
|
+
|
|
3
|
+
import math
|
|
4
|
+
from typing import List, Optional, Union
|
|
5
|
+
|
|
6
|
+
import mlx.core as mx
|
|
7
|
+
import mlx.nn as nn
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class SuScaledRoPE(nn.Module):
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
dims: int,
|
|
14
|
+
base: float = 10000.0,
|
|
15
|
+
max_position_embeddings: int = 131072,
|
|
16
|
+
original_max_position_embeddings: int = 4096,
|
|
17
|
+
short_factor: Union[List[float], float] = 1.0,
|
|
18
|
+
long_factor: Union[List[float], float] = 1.0,
|
|
19
|
+
short_mscale: float = None,
|
|
20
|
+
long_mscale: float = None,
|
|
21
|
+
):
|
|
22
|
+
"""
|
|
23
|
+
Su Scaled Rotary Embedding layer.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
dims (int): The feature dimensions to be rotated.
|
|
27
|
+
base (int, optional): Base for the exponential scaling.
|
|
28
|
+
max_position_embeddings (int, optional): The maximum sequence
|
|
29
|
+
length that this model was trained with. This is used to determine
|
|
30
|
+
the size of the original RoPE embeddings when using long scaling.
|
|
31
|
+
Default: ``131072``.
|
|
32
|
+
original_max_position_embeddings (int, optional): The maximum
|
|
33
|
+
sequence length that this model was trained with. This is used to
|
|
34
|
+
determine the size of the original RoPE embeddings when using long
|
|
35
|
+
scaling. Default: ``4096``.
|
|
36
|
+
short_factor (float or list[float], optional): List of scaling
|
|
37
|
+
factors for sequences of length lesser than
|
|
38
|
+
``original_max_position_embeddings``. Default: ``1.0``.
|
|
39
|
+
long_factor (float or list[float], optional): List of scaling
|
|
40
|
+
factors for sequences of length greater than
|
|
41
|
+
``original_max_position_embeddings``. Default: ``1.0``.
|
|
42
|
+
short_mscale (float, optional): Scale the input prior to embedding.
|
|
43
|
+
long_mscale (float, optional): Scale the input prior to embedding.
|
|
44
|
+
"""
|
|
45
|
+
super().__init__()
|
|
46
|
+
freqs = base ** (mx.arange(0, dims, 2, dtype=mx.float32) / dims)
|
|
47
|
+
self._freqs = mx.array(long_factor, dtype=mx.float32) * freqs
|
|
48
|
+
self.original_max_position_embeddings = original_max_position_embeddings
|
|
49
|
+
self.scale = long_mscale or math.sqrt(
|
|
50
|
+
1
|
|
51
|
+
+ math.log(max_position_embeddings / original_max_position_embeddings)
|
|
52
|
+
/ math.log(original_max_position_embeddings)
|
|
53
|
+
)
|
|
54
|
+
self.dim = dims
|
|
55
|
+
|
|
56
|
+
def __call__(self, x, offset: int = 0):
|
|
57
|
+
x[..., : self.dim] = self.scale * x[..., : self.dim]
|
|
58
|
+
return mx.fast.rope(
|
|
59
|
+
x,
|
|
60
|
+
self.dim,
|
|
61
|
+
traditional=False,
|
|
62
|
+
base=None,
|
|
63
|
+
scale=1.0,
|
|
64
|
+
offset=offset,
|
|
65
|
+
freqs=self._freqs,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class Llama3RoPE(nn.Module):
|
|
70
|
+
|
|
71
|
+
def __init__(
|
|
72
|
+
self,
|
|
73
|
+
dims: int,
|
|
74
|
+
max_position_embeddings: int = 2048,
|
|
75
|
+
traditional: bool = False,
|
|
76
|
+
base: float = 10000,
|
|
77
|
+
scaling_config: dict = None,
|
|
78
|
+
):
|
|
79
|
+
super().__init__()
|
|
80
|
+
self.dims = dims
|
|
81
|
+
self.max_position_embeddings = max_position_embeddings
|
|
82
|
+
self.traditional = traditional
|
|
83
|
+
|
|
84
|
+
factor = scaling_config["factor"]
|
|
85
|
+
low_freq_factor = scaling_config.get("low_freq_factor", 1.0)
|
|
86
|
+
high_freq_factor = scaling_config.get("high_freq_factor", 4.0)
|
|
87
|
+
old_context_len = scaling_config.get(
|
|
88
|
+
"original_max_position_embeddings",
|
|
89
|
+
8192,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
low_freq_wavelen = old_context_len / low_freq_factor
|
|
93
|
+
high_freq_wavelen = old_context_len / high_freq_factor
|
|
94
|
+
|
|
95
|
+
freqs = base ** (mx.arange(0, dims, 2) / dims)
|
|
96
|
+
wavelens = 2 * mx.pi * freqs
|
|
97
|
+
|
|
98
|
+
freqs = mx.where(wavelens > low_freq_wavelen, freqs * factor, freqs)
|
|
99
|
+
is_medium_freq = (wavelens > high_freq_wavelen) & (wavelens < low_freq_wavelen)
|
|
100
|
+
smooth_factors = (old_context_len / wavelens - low_freq_factor) / (
|
|
101
|
+
high_freq_factor - low_freq_factor
|
|
102
|
+
)
|
|
103
|
+
smooth_freqs = freqs / ((1 - smooth_factors) / factor + smooth_factors)
|
|
104
|
+
self._freqs = mx.where(is_medium_freq, smooth_freqs, freqs)
|
|
105
|
+
|
|
106
|
+
def extra_repr(self):
|
|
107
|
+
return (
|
|
108
|
+
f"{self.dims}, traditional={self.traditional}, "
|
|
109
|
+
f"max_position_embeddings={self.max_position_embeddings}"
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
def __call__(self, x, offset: int = 0):
|
|
113
|
+
return mx.fast.rope(
|
|
114
|
+
x,
|
|
115
|
+
self.dims,
|
|
116
|
+
traditional=self.traditional,
|
|
117
|
+
base=None,
|
|
118
|
+
scale=1.0,
|
|
119
|
+
offset=offset,
|
|
120
|
+
freqs=self._freqs,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class YarnRoPE(nn.Module):
|
|
125
|
+
def __init__(
|
|
126
|
+
self,
|
|
127
|
+
dims,
|
|
128
|
+
traditional=False,
|
|
129
|
+
max_position_embeddings=2048,
|
|
130
|
+
base=10000,
|
|
131
|
+
scaling_factor=1.0,
|
|
132
|
+
original_max_position_embeddings=4096,
|
|
133
|
+
beta_fast=32,
|
|
134
|
+
beta_slow=1,
|
|
135
|
+
mscale=1,
|
|
136
|
+
mscale_all_dim=0,
|
|
137
|
+
):
|
|
138
|
+
super().__init__()
|
|
139
|
+
|
|
140
|
+
def yarn_find_correction_dim(num_rotations):
|
|
141
|
+
return (
|
|
142
|
+
dims
|
|
143
|
+
* math.log(
|
|
144
|
+
original_max_position_embeddings / (num_rotations * 2 * math.pi)
|
|
145
|
+
)
|
|
146
|
+
) / (2 * math.log(base))
|
|
147
|
+
|
|
148
|
+
def yarn_find_correction_range():
|
|
149
|
+
low = math.floor(yarn_find_correction_dim(beta_fast))
|
|
150
|
+
high = math.ceil(yarn_find_correction_dim(beta_slow))
|
|
151
|
+
return max(low, 0), min(high, dims - 1)
|
|
152
|
+
|
|
153
|
+
def yarn_get_mscale(scale=1, mscale=1):
|
|
154
|
+
if scale <= 1:
|
|
155
|
+
return 1.0
|
|
156
|
+
return 0.1 * mscale * math.log(scale) + 1.0
|
|
157
|
+
|
|
158
|
+
def yarn_linear_ramp_mask(min_val, max_val, dim):
|
|
159
|
+
if min_val == max_val:
|
|
160
|
+
max_val += 0.001 # Prevent singularity
|
|
161
|
+
|
|
162
|
+
linear_func = (mx.arange(dim, dtype=mx.float32) - min_val) / (
|
|
163
|
+
max_val - min_val
|
|
164
|
+
)
|
|
165
|
+
return mx.clip(linear_func, 0, 1)
|
|
166
|
+
|
|
167
|
+
self.mscale = yarn_get_mscale(scaling_factor, mscale) / yarn_get_mscale(
|
|
168
|
+
scaling_factor, mscale_all_dim
|
|
169
|
+
)
|
|
170
|
+
freq_extra = base ** (mx.arange(0, dims, 2, dtype=mx.float32) / dims)
|
|
171
|
+
freq_inter = scaling_factor * base ** (
|
|
172
|
+
mx.arange(0, dims, 2, dtype=mx.float32) / dims
|
|
173
|
+
)
|
|
174
|
+
low, high = yarn_find_correction_range()
|
|
175
|
+
freq_mask = 1.0 - yarn_linear_ramp_mask(low, high, dims // 2)
|
|
176
|
+
self._freqs = (freq_inter * freq_extra) / (
|
|
177
|
+
freq_inter * freq_mask + freq_extra * (1 - freq_mask)
|
|
178
|
+
)
|
|
179
|
+
self.dims = dims
|
|
180
|
+
self.traditional = traditional
|
|
181
|
+
|
|
182
|
+
def __call__(self, x, offset=0):
|
|
183
|
+
if self.mscale != 1.0:
|
|
184
|
+
x[..., : self.dims] = self.mscale * x[..., : self.dims]
|
|
185
|
+
return mx.fast.rope(
|
|
186
|
+
x,
|
|
187
|
+
self.dims,
|
|
188
|
+
traditional=self.traditional,
|
|
189
|
+
base=None,
|
|
190
|
+
scale=1.0,
|
|
191
|
+
offset=offset,
|
|
192
|
+
freqs=self._freqs,
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def initialize_rope(
|
|
197
|
+
dims,
|
|
198
|
+
base,
|
|
199
|
+
traditional,
|
|
200
|
+
scaling_config: Optional[dict] = None,
|
|
201
|
+
max_position_embeddings: Optional[int] = None,
|
|
202
|
+
):
|
|
203
|
+
if scaling_config is not None:
|
|
204
|
+
rope_type = scaling_config.get("type") or scaling_config.get(
|
|
205
|
+
"rope_type", "default"
|
|
206
|
+
)
|
|
207
|
+
else:
|
|
208
|
+
rope_type = "default"
|
|
209
|
+
|
|
210
|
+
if rope_type in ["default", "linear"]:
|
|
211
|
+
scale = 1 / scaling_config["factor"] if rope_type == "linear" else 1.0
|
|
212
|
+
return nn.RoPE(dims, traditional=traditional, base=base, scale=scale)
|
|
213
|
+
|
|
214
|
+
elif rope_type == "llama3":
|
|
215
|
+
return Llama3RoPE(
|
|
216
|
+
dims=dims,
|
|
217
|
+
max_position_embeddings=max_position_embeddings,
|
|
218
|
+
traditional=traditional,
|
|
219
|
+
base=base,
|
|
220
|
+
scaling_config=scaling_config,
|
|
221
|
+
)
|
|
222
|
+
elif rope_type == "yarn":
|
|
223
|
+
scaling_factor = scaling_config["factor"]
|
|
224
|
+
rope_kwargs = {
|
|
225
|
+
key: scaling_config[key]
|
|
226
|
+
for key in [
|
|
227
|
+
"original_max_position_embeddings",
|
|
228
|
+
"beta_fast",
|
|
229
|
+
"beta_slow",
|
|
230
|
+
"mscale",
|
|
231
|
+
"mscale_all_dim",
|
|
232
|
+
]
|
|
233
|
+
if key in scaling_config
|
|
234
|
+
}
|
|
235
|
+
return YarnRoPE(
|
|
236
|
+
dims=dims,
|
|
237
|
+
max_position_embeddings=max_position_embeddings,
|
|
238
|
+
traditional=traditional,
|
|
239
|
+
base=base,
|
|
240
|
+
**rope_kwargs,
|
|
241
|
+
)
|
|
242
|
+
elif rope_type == "longrope":
|
|
243
|
+
return SuScaledRoPE(
|
|
244
|
+
dims=dims,
|
|
245
|
+
base=base,
|
|
246
|
+
max_position_embeddings=max_position_embeddings,
|
|
247
|
+
original_max_position_embeddings=scaling_config[
|
|
248
|
+
"original_max_position_embeddings"
|
|
249
|
+
],
|
|
250
|
+
short_factor=scaling_config["short_factor"],
|
|
251
|
+
long_factor=scaling_config["long_factor"],
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
else:
|
|
255
|
+
raise ValueError(f"Unsupported RoPE type {rope_type}")
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import math
|
|
2
|
+
from functools import partial
|
|
3
|
+
from typing import Callable, Dict, List, Optional
|
|
4
|
+
|
|
5
|
+
import mlx.core as mx
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def make_sampler(
|
|
9
|
+
temp: float = 0.0,
|
|
10
|
+
top_p: float = 0.0,
|
|
11
|
+
min_p: float = 0.0,
|
|
12
|
+
min_tokens_to_keep: int = 1,
|
|
13
|
+
top_k: int = 0,
|
|
14
|
+
xtc_probability: float = 0.0,
|
|
15
|
+
xtc_threshold: float = 0.0,
|
|
16
|
+
xtc_special_tokens: List[int] = [],
|
|
17
|
+
) -> Callable[mx.array, mx.array]:
|
|
18
|
+
"""
|
|
19
|
+
Make a sampler function for use with ``generate_step``.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
temp (float): The temperature for sampling, if 0 the argmax is used.
|
|
23
|
+
Default: ``0``.
|
|
24
|
+
top_p (float, optional): Nulceus sampling, higher means model considers
|
|
25
|
+
more less likely words.
|
|
26
|
+
min_p (float, optional): The minimum value (scaled by the top token's
|
|
27
|
+
probability) that a token probability must have to be considered.
|
|
28
|
+
min_tokens_to_keep (int, optional): Minimum number of tokens that cannot
|
|
29
|
+
be filtered by min_p sampling.
|
|
30
|
+
top_k (int, optional): The top k tokens ranked by probability to constrain
|
|
31
|
+
the sampling to.
|
|
32
|
+
xtc_probability (float, optional): The probability of applying XTC
|
|
33
|
+
sampling.
|
|
34
|
+
xtc_threshold (float, optional): The threshold the probs need to reach
|
|
35
|
+
for being sampled.
|
|
36
|
+
xtc_special_tokens (list(int), optional): List of special tokens IDs to
|
|
37
|
+
be excluded from XTC sampling.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
Callable[mx.array, mx.array]:
|
|
42
|
+
A sampler which takes log-probabilities and returns tokens.
|
|
43
|
+
"""
|
|
44
|
+
if temp == 0:
|
|
45
|
+
return lambda x: mx.argmax(x, axis=-1)
|
|
46
|
+
|
|
47
|
+
# Create sampler chain
|
|
48
|
+
sampling_methods = []
|
|
49
|
+
if top_k > 0:
|
|
50
|
+
sampling_methods.append(lambda x: apply_top_k(x, top_k))
|
|
51
|
+
if top_p > 0 and top_p < 1.0:
|
|
52
|
+
sampling_methods.append(lambda x: apply_top_p(x, top_p))
|
|
53
|
+
if min_p != 0.0:
|
|
54
|
+
sampling_methods.append(lambda x: apply_min_p(x, min_p, min_tokens_to_keep))
|
|
55
|
+
if xtc_probability > 0.0:
|
|
56
|
+
sampling_methods.append(
|
|
57
|
+
lambda x: apply_xtc(x, xtc_probability, xtc_threshold, xtc_special_tokens)
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
# Apply the sampling methods
|
|
61
|
+
def sampler(logits):
|
|
62
|
+
for method in sampling_methods:
|
|
63
|
+
logits = method(logits)
|
|
64
|
+
|
|
65
|
+
# Return the sampled token
|
|
66
|
+
return categorical_sampling(logits, temp)
|
|
67
|
+
|
|
68
|
+
return sampler
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def make_logits_processors(
|
|
72
|
+
logit_bias: Optional[Dict[int, float]] = None,
|
|
73
|
+
repetition_penalty: Optional[float] = None,
|
|
74
|
+
repetition_context_size: Optional[int] = 20,
|
|
75
|
+
):
|
|
76
|
+
"""
|
|
77
|
+
Make logits processors for use with ``generate_step``.
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
repetition_penalty (float, optional): The penalty factor for repeating
|
|
81
|
+
tokens.
|
|
82
|
+
repetition_context_size (int, optional): The number of tokens to
|
|
83
|
+
consider for repetition penalty. Default: ``20``.
|
|
84
|
+
logit_bias (dictionary, optional): Additive logit bias.
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
List[Callable[[mx.array, mx.array], mx.array]]:
|
|
88
|
+
A list of logits processors. Each processor in the list is a
|
|
89
|
+
callable which takes an array of tokens and an array of logits
|
|
90
|
+
and returns the updated logits.
|
|
91
|
+
"""
|
|
92
|
+
logits_processors = []
|
|
93
|
+
if logit_bias:
|
|
94
|
+
indices = mx.array(list(logit_bias.keys()))
|
|
95
|
+
values = mx.array(list(logit_bias.values()))
|
|
96
|
+
|
|
97
|
+
def logit_bias_processor(_, logits):
|
|
98
|
+
logits[:, indices] += values
|
|
99
|
+
return logits
|
|
100
|
+
|
|
101
|
+
logits_processors.append(logit_bias_processor)
|
|
102
|
+
|
|
103
|
+
if repetition_penalty and repetition_penalty != 0.0:
|
|
104
|
+
logits_processors.append(
|
|
105
|
+
make_repetition_penalty(repetition_penalty, repetition_context_size)
|
|
106
|
+
)
|
|
107
|
+
return logits_processors
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@partial(mx.compile, inputs=mx.random.state, outputs=mx.random.state)
|
|
111
|
+
def apply_top_k(
|
|
112
|
+
logprobs: mx.array,
|
|
113
|
+
top_k: int,
|
|
114
|
+
) -> mx.array:
|
|
115
|
+
"""
|
|
116
|
+
Sample from only the top K tokens ranked by probability.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
logprobs: A vector of log probabilities.
|
|
120
|
+
top_k (int): Top k tokens to sample from.
|
|
121
|
+
"""
|
|
122
|
+
vocab_size = logprobs.shape[-1]
|
|
123
|
+
if not isinstance(top_k, int) or not (0 < top_k < vocab_size):
|
|
124
|
+
raise ValueError(
|
|
125
|
+
f"`top_k` has to be an integer in the (0, {vocab_size}] interval," f" but is {top_k}."
|
|
126
|
+
)
|
|
127
|
+
mask_idx = mx.argpartition(-logprobs, kth=top_k - 1, axis=-1)[..., top_k:]
|
|
128
|
+
masked_logprobs = mx.put_along_axis(
|
|
129
|
+
logprobs, mask_idx, mx.array(-float("inf"), logprobs.dtype), axis=-1
|
|
130
|
+
)
|
|
131
|
+
return masked_logprobs
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
@partial(mx.compile, inputs=mx.random.state, outputs=mx.random.state)
|
|
135
|
+
def apply_min_p(
|
|
136
|
+
logprobs: mx.array,
|
|
137
|
+
min_p: float,
|
|
138
|
+
min_tokens_to_keep: int = 1,
|
|
139
|
+
) -> mx.array:
|
|
140
|
+
"""
|
|
141
|
+
Apply min-p sampling to the logprobs.
|
|
142
|
+
|
|
143
|
+
Min-p keeps all tokens that are above a minimum probability, scaled by the
|
|
144
|
+
probability of the most likely token. As a result, the filter is more
|
|
145
|
+
aggressive given a very high-probability token.
|
|
146
|
+
|
|
147
|
+
Args:
|
|
148
|
+
logprobs: A vector of log probabilities.
|
|
149
|
+
min_p (float): Minimum token probability. Typical values are in the
|
|
150
|
+
0.01-0.2 range, comparably selective as setting `top_p` in the
|
|
151
|
+
0.99-0.8 range.
|
|
152
|
+
min_tokens_to_keep (int, optional): Minimum number of tokens that cannot
|
|
153
|
+
be filtered. Default: ``1``.
|
|
154
|
+
|
|
155
|
+
"""
|
|
156
|
+
if not (0 <= min_p <= 1.0):
|
|
157
|
+
raise ValueError(f"`min_p` has to be a float in the [0, 1] interval, but is {min_p}")
|
|
158
|
+
if not isinstance(min_tokens_to_keep, int) or (min_tokens_to_keep < 1):
|
|
159
|
+
raise ValueError(
|
|
160
|
+
f"`min_tokens_to_keep` has to be a positive integer, but is {min_tokens_to_keep}"
|
|
161
|
+
)
|
|
162
|
+
# reference implementation: https://github.com/huggingface/transformers/blob/main/src/transformers/generation/logits_process.py#L531-L605
|
|
163
|
+
|
|
164
|
+
# Indices sorted in decreasing order
|
|
165
|
+
sorted_indices = mx.argsort(-logprobs, axis=-1)
|
|
166
|
+
sorted_logprobs = mx.take_along_axis(logprobs, sorted_indices, axis=-1)
|
|
167
|
+
|
|
168
|
+
# Top probability
|
|
169
|
+
top_logprobs = sorted_logprobs[:, 0:1]
|
|
170
|
+
|
|
171
|
+
# Calculate the min_p threshold
|
|
172
|
+
scaled_min_p = top_logprobs + math.log(min_p)
|
|
173
|
+
|
|
174
|
+
# Mask tokens that have a probability less than the scaled min_p
|
|
175
|
+
tokens_to_remove = sorted_logprobs < scaled_min_p
|
|
176
|
+
tokens_to_remove[..., :min_tokens_to_keep] = False
|
|
177
|
+
|
|
178
|
+
# Create pool of tokens with probability less than scaled min_p
|
|
179
|
+
selected_logprobs = mx.where(tokens_to_remove, -float("inf"), sorted_logprobs)
|
|
180
|
+
|
|
181
|
+
# Create a mapping to rearrange back to original indices
|
|
182
|
+
inverse_indices = mx.put_along_axis(
|
|
183
|
+
mx.zeros_like(sorted_indices),
|
|
184
|
+
sorted_indices,
|
|
185
|
+
mx.arange(sorted_indices.shape[-1], dtype=sorted_indices.dtype),
|
|
186
|
+
axis=-1,
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
# Rearrange selected_logprobs back to original order
|
|
190
|
+
original_order_logprobs = mx.take_along_axis(selected_logprobs, inverse_indices, axis=-1)
|
|
191
|
+
|
|
192
|
+
return original_order_logprobs
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
@partial(mx.compile, inputs=mx.random.state, outputs=mx.random.state)
|
|
196
|
+
def apply_top_p(logprobs: mx.array, top_p: float) -> mx.array:
|
|
197
|
+
"""
|
|
198
|
+
Apply top-p (nucleus) sampling to logits.
|
|
199
|
+
|
|
200
|
+
Args:
|
|
201
|
+
logprobs: A vector of log probabilities.
|
|
202
|
+
top_p: The cumulative probability threshold for top-p filtering.
|
|
203
|
+
Returns:
|
|
204
|
+
token selected based on the top-p criterion.
|
|
205
|
+
"""
|
|
206
|
+
# referenced implementation from https://github.com/huggingface/transformers/blob/main/src/transformers/generation/logits_process.py#L449-L460
|
|
207
|
+
probs = mx.exp(logprobs)
|
|
208
|
+
# sort in ascending order
|
|
209
|
+
sorted_indices = mx.argsort(logprobs, axis=-1)
|
|
210
|
+
sorted_probs = mx.take_along_axis(probs, sorted_indices, axis=-1)
|
|
211
|
+
|
|
212
|
+
cumulative_probs = mx.cumsum(sorted_probs, axis=-1)
|
|
213
|
+
|
|
214
|
+
# Rearrange cumulative probs back to original order
|
|
215
|
+
inverse_indices = mx.put_along_axis(
|
|
216
|
+
mx.zeros_like(sorted_indices),
|
|
217
|
+
sorted_indices,
|
|
218
|
+
mx.arange(sorted_indices.shape[-1], dtype=sorted_indices.dtype),
|
|
219
|
+
axis=-1,
|
|
220
|
+
)
|
|
221
|
+
cumulative_probs = mx.take_along_axis(cumulative_probs, inverse_indices, axis=-1)
|
|
222
|
+
|
|
223
|
+
# select tokens with cumulative probs below threshold
|
|
224
|
+
return mx.where(
|
|
225
|
+
cumulative_probs > 1 - top_p,
|
|
226
|
+
logprobs,
|
|
227
|
+
-float("inf"),
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
@partial(mx.compile, inputs=mx.random.state, outputs=mx.random.state)
|
|
232
|
+
def apply_xtc(
|
|
233
|
+
logits: mx.array,
|
|
234
|
+
xtc_probability: float,
|
|
235
|
+
xtc_threshold: float,
|
|
236
|
+
xtc_special_tokens: List[int],
|
|
237
|
+
) -> mx.array:
|
|
238
|
+
"""
|
|
239
|
+
Apply XTC sampling to the logits.
|
|
240
|
+
|
|
241
|
+
Args:
|
|
242
|
+
logits: The logits from the model's output.
|
|
243
|
+
xtc_probability (float): Probability of XTC sampling to happen for each token
|
|
244
|
+
xtc_threshold (float): The threshold the probs need to reach for being sampled.
|
|
245
|
+
special_tokens_ids (list(int)): List of special tokens IDs to be excluded from XTC sampling.
|
|
246
|
+
"""
|
|
247
|
+
if not (0 <= xtc_threshold <= 0.5):
|
|
248
|
+
raise ValueError(
|
|
249
|
+
f"`threshold` has to be a float in the [0, 0.5] interval, but is {xtc_threshold}"
|
|
250
|
+
)
|
|
251
|
+
if not (0 <= xtc_probability <= 1.0):
|
|
252
|
+
raise ValueError(
|
|
253
|
+
f"`probability` has to be a float in the [0, 1] interval, but is {xtc_probability}"
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
probs = mx.softmax(logits, -1)
|
|
257
|
+
mask = probs > mx.where(probs > xtc_threshold, probs, mx.inf).min()
|
|
258
|
+
if xtc_special_tokens:
|
|
259
|
+
mask[..., xtc_special_tokens] = False
|
|
260
|
+
|
|
261
|
+
return mx.where(
|
|
262
|
+
mx.random.uniform(0, 1) > xtc_probability,
|
|
263
|
+
logits,
|
|
264
|
+
mx.where(mask, -mx.inf, logits),
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
@partial(mx.compile, inputs=mx.random.state, outputs=mx.random.state)
|
|
269
|
+
def categorical_sampling(logits, temp):
|
|
270
|
+
return mx.random.categorical(logits * (1 / temp))
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def make_repetition_penalty(penalty: float, context_size: int = 20):
|
|
274
|
+
"""
|
|
275
|
+
Make repetition penalty processor.
|
|
276
|
+
|
|
277
|
+
Paper: https://arxiv.org/abs/1909.05858
|
|
278
|
+
|
|
279
|
+
Args:
|
|
280
|
+
penalty (float): The repetition penalty factor to be applied.
|
|
281
|
+
context_size (int): The number of previous tokens to use.
|
|
282
|
+
Default: ``20``.
|
|
283
|
+
|
|
284
|
+
Returns:
|
|
285
|
+
Callable[[mx.array, List[int]], mx.array]:
|
|
286
|
+
The repetition penalty processor.
|
|
287
|
+
"""
|
|
288
|
+
if penalty < 0 or not isinstance(penalty, (int, float)):
|
|
289
|
+
raise ValueError(f"penalty must be a non-negative float, got {penalty}")
|
|
290
|
+
|
|
291
|
+
def repetition_penalty_processor(tokens, logits):
|
|
292
|
+
if len(tokens) > 0:
|
|
293
|
+
tokens = tokens[-context_size:]
|
|
294
|
+
selected_logits = logits[:, tokens]
|
|
295
|
+
selected_logits = mx.where(
|
|
296
|
+
selected_logits < 0,
|
|
297
|
+
selected_logits * penalty,
|
|
298
|
+
selected_logits / penalty,
|
|
299
|
+
)
|
|
300
|
+
logits[:, tokens] = selected_logits
|
|
301
|
+
return logits
|
|
302
|
+
|
|
303
|
+
return repetition_penalty_processor
|