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,488 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
import math
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Optional, Tuple
|
|
5
|
+
|
|
6
|
+
import mlx.core as mx
|
|
7
|
+
import mlx.nn as nn
|
|
8
|
+
|
|
9
|
+
from ..base import (
|
|
10
|
+
LanguageModelOutput,
|
|
11
|
+
create_attention_mask,
|
|
12
|
+
scaled_dot_product_attention,
|
|
13
|
+
)
|
|
14
|
+
from ..cache import SimpleKVCache
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class TextConfig:
|
|
19
|
+
d_model: int = 768
|
|
20
|
+
model_type: str = "florence2"
|
|
21
|
+
encoder_attention_heads: int = 8
|
|
22
|
+
decoder_attention_heads: int = 8
|
|
23
|
+
encoder_ffn_dim: int = 3072
|
|
24
|
+
decoder_ffn_dim: int = 3072
|
|
25
|
+
dropout: float = 0.1
|
|
26
|
+
attention_dropout: float = 0.0
|
|
27
|
+
activation_dropout: float = 0.0
|
|
28
|
+
activation_function: str = "gelu"
|
|
29
|
+
init_std: float = 0.02
|
|
30
|
+
encoder_layerdrop: float = 0.0
|
|
31
|
+
decoder_layerdrop: float = 0.0
|
|
32
|
+
scale_embedding: bool = False
|
|
33
|
+
use_cache: bool = True
|
|
34
|
+
max_position_embeddings: int = 1024
|
|
35
|
+
vocab_size: int = 51289
|
|
36
|
+
pad_token_id: int = 1
|
|
37
|
+
bos_token_id: int = 0
|
|
38
|
+
eos_token_id: int = 2
|
|
39
|
+
encoder_layers: int = 6
|
|
40
|
+
decoder_layers: int = 6
|
|
41
|
+
|
|
42
|
+
@classmethod
|
|
43
|
+
def from_dict(cls, params):
|
|
44
|
+
return cls(
|
|
45
|
+
**{
|
|
46
|
+
k: v
|
|
47
|
+
for k, v in params.items()
|
|
48
|
+
if k in inspect.signature(cls).parameters
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class Florence2Attention(nn.Module):
|
|
54
|
+
def __init__(
|
|
55
|
+
self, config: TextConfig, is_decoder: bool = False, is_causal: bool = False
|
|
56
|
+
):
|
|
57
|
+
super().__init__()
|
|
58
|
+
self.embed_dim = config.d_model
|
|
59
|
+
self.num_heads = (
|
|
60
|
+
config.decoder_attention_heads
|
|
61
|
+
if is_decoder
|
|
62
|
+
else config.encoder_attention_heads
|
|
63
|
+
)
|
|
64
|
+
self.is_decoder = is_decoder
|
|
65
|
+
self.is_causal = is_causal
|
|
66
|
+
self.head_dim = self.embed_dim // self.num_heads
|
|
67
|
+
self.scaling = self.head_dim**-0.5
|
|
68
|
+
|
|
69
|
+
self.k_proj = nn.Linear(self.embed_dim, self.embed_dim)
|
|
70
|
+
self.v_proj = nn.Linear(self.embed_dim, self.embed_dim)
|
|
71
|
+
self.q_proj = nn.Linear(self.embed_dim, self.embed_dim)
|
|
72
|
+
self.out_proj = nn.Linear(self.embed_dim, self.embed_dim)
|
|
73
|
+
|
|
74
|
+
def __call__(
|
|
75
|
+
self,
|
|
76
|
+
hidden_states,
|
|
77
|
+
key_value_states=None,
|
|
78
|
+
cache: Optional[SimpleKVCache] = None,
|
|
79
|
+
attention_mask=None,
|
|
80
|
+
layer_head_mask=None,
|
|
81
|
+
):
|
|
82
|
+
batch_size, tgt_len, _ = hidden_states.shape
|
|
83
|
+
|
|
84
|
+
q = (
|
|
85
|
+
self.q_proj(hidden_states)
|
|
86
|
+
.reshape(batch_size, tgt_len, self.num_heads, self.head_dim)
|
|
87
|
+
.transpose(0, 2, 1, 3)
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
is_cross_attention = key_value_states is not None
|
|
91
|
+
|
|
92
|
+
batch_size, tgt_len, _ = hidden_states.shape
|
|
93
|
+
src_len = (
|
|
94
|
+
key_value_states.shape[1]
|
|
95
|
+
if key_value_states is not None
|
|
96
|
+
else hidden_states.shape[1]
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
if (
|
|
100
|
+
is_cross_attention
|
|
101
|
+
and cache.cache_length > 0
|
|
102
|
+
and cache.keys.shape[2] == key_value_states.shape[1]
|
|
103
|
+
):
|
|
104
|
+
# k = cache[0]
|
|
105
|
+
# v = cache[1]
|
|
106
|
+
k = cache.keys
|
|
107
|
+
v = cache.values
|
|
108
|
+
|
|
109
|
+
elif is_cross_attention:
|
|
110
|
+
# Cross attention
|
|
111
|
+
k = (
|
|
112
|
+
self.k_proj(key_value_states)
|
|
113
|
+
.reshape(batch_size, src_len, self.num_heads, self.head_dim)
|
|
114
|
+
.transpose(0, 2, 1, 3)
|
|
115
|
+
)
|
|
116
|
+
v = (
|
|
117
|
+
self.v_proj(key_value_states)
|
|
118
|
+
.reshape(batch_size, src_len, self.num_heads, self.head_dim)
|
|
119
|
+
.transpose(0, 2, 1, 3)
|
|
120
|
+
)
|
|
121
|
+
elif cache is not None:
|
|
122
|
+
# reuse k, v, self_attention
|
|
123
|
+
k = (
|
|
124
|
+
self.k_proj(hidden_states)
|
|
125
|
+
.reshape(batch_size, src_len, self.num_heads, -1)
|
|
126
|
+
.transpose(0, 2, 1, 3)
|
|
127
|
+
)
|
|
128
|
+
v = (
|
|
129
|
+
self.v_proj(hidden_states)
|
|
130
|
+
.reshape(batch_size, src_len, self.num_heads, -1)
|
|
131
|
+
.transpose(0, 2, 1, 3)
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
k, v = cache.update_and_fetch(k, v)
|
|
135
|
+
else:
|
|
136
|
+
# Self attention
|
|
137
|
+
k = (
|
|
138
|
+
self.k_proj(hidden_states)
|
|
139
|
+
.reshape(batch_size, src_len, self.num_heads, self.head_dim)
|
|
140
|
+
.transpose(0, 2, 1, 3)
|
|
141
|
+
)
|
|
142
|
+
v = (
|
|
143
|
+
self.v_proj(hidden_states)
|
|
144
|
+
.reshape(batch_size, src_len, self.num_heads, self.head_dim)
|
|
145
|
+
.transpose(0, 2, 1, 3)
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
if self.is_decoder:
|
|
149
|
+
cache.update(k, v)
|
|
150
|
+
|
|
151
|
+
if self.is_causal and self.is_decoder:
|
|
152
|
+
causal_mask = create_attention_mask(hidden_states)
|
|
153
|
+
attention_mask = causal_mask
|
|
154
|
+
|
|
155
|
+
attn_output = (
|
|
156
|
+
scaled_dot_product_attention(
|
|
157
|
+
q, k, v, cache=cache, scale=self.scaling, mask=attention_mask
|
|
158
|
+
)
|
|
159
|
+
.transpose(0, 2, 1, 3)
|
|
160
|
+
.reshape(batch_size, tgt_len, -1)
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
attn_output = self.out_proj(attn_output)
|
|
164
|
+
|
|
165
|
+
return attn_output
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class Florence2EncoderLayer(nn.Module):
|
|
169
|
+
def __init__(self, config: TextConfig):
|
|
170
|
+
super().__init__()
|
|
171
|
+
self.embed_dim = config.d_model
|
|
172
|
+
self.self_attn = Florence2Attention(config, is_decoder=False, is_causal=False)
|
|
173
|
+
self.self_attn_layer_norm = nn.LayerNorm(self.embed_dim)
|
|
174
|
+
self.activation_fn = nn.GELU()
|
|
175
|
+
self.fc1 = nn.Linear(self.embed_dim, config.encoder_ffn_dim)
|
|
176
|
+
self.fc2 = nn.Linear(config.encoder_ffn_dim, self.embed_dim)
|
|
177
|
+
self.final_layer_norm = nn.LayerNorm(self.embed_dim)
|
|
178
|
+
|
|
179
|
+
def __call__(self, hidden_states, attention_mask=None):
|
|
180
|
+
residual = hidden_states
|
|
181
|
+
hidden_states = self.self_attn(hidden_states, attention_mask=attention_mask)
|
|
182
|
+
hidden_states = residual + hidden_states
|
|
183
|
+
hidden_states = self.self_attn_layer_norm(hidden_states)
|
|
184
|
+
|
|
185
|
+
residual = hidden_states
|
|
186
|
+
hidden_states = self.activation_fn(self.fc1(hidden_states))
|
|
187
|
+
hidden_states = self.fc2(hidden_states)
|
|
188
|
+
hidden_states = residual + hidden_states
|
|
189
|
+
hidden_states = self.final_layer_norm(hidden_states)
|
|
190
|
+
|
|
191
|
+
return hidden_states
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
class Florence2DecoderLayer(nn.Module):
|
|
195
|
+
def __init__(self, config: TextConfig):
|
|
196
|
+
super().__init__()
|
|
197
|
+
self.embed_dim = config.d_model
|
|
198
|
+
self.self_attn = Florence2Attention(config, is_decoder=True, is_causal=True)
|
|
199
|
+
self.dropout = config.dropout
|
|
200
|
+
self.activation_fn = nn.GELU()
|
|
201
|
+
self.activation_dropout = config.activation_dropout
|
|
202
|
+
|
|
203
|
+
self.self_attn_layer_norm = nn.LayerNorm(self.embed_dim)
|
|
204
|
+
self.encoder_attn = Florence2Attention(config, is_decoder=True)
|
|
205
|
+
self.encoder_attn_layer_norm = nn.LayerNorm(self.embed_dim)
|
|
206
|
+
self.fc1 = nn.Linear(self.embed_dim, config.decoder_ffn_dim)
|
|
207
|
+
self.fc2 = nn.Linear(config.decoder_ffn_dim, self.embed_dim)
|
|
208
|
+
self.final_layer_norm = nn.LayerNorm(self.embed_dim)
|
|
209
|
+
|
|
210
|
+
def __call__(
|
|
211
|
+
self,
|
|
212
|
+
hidden_states,
|
|
213
|
+
encoder_hidden_states,
|
|
214
|
+
attention_mask=None,
|
|
215
|
+
encoder_attention_mask=None,
|
|
216
|
+
cache: Optional[Tuple[SimpleKVCache, SimpleKVCache]] = None,
|
|
217
|
+
):
|
|
218
|
+
residual = hidden_states
|
|
219
|
+
|
|
220
|
+
# decoder uni-directional self-attention cached key/values tuple is at positions 1,2
|
|
221
|
+
self_attn_cache = cache[0] if cache[0] is not None else None
|
|
222
|
+
|
|
223
|
+
hidden_states = self.self_attn(
|
|
224
|
+
hidden_states, attention_mask=attention_mask, cache=self_attn_cache
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
hidden_states = residual + hidden_states
|
|
228
|
+
hidden_states = self.self_attn_layer_norm(hidden_states)
|
|
229
|
+
|
|
230
|
+
if encoder_hidden_states is not None:
|
|
231
|
+
residual = hidden_states
|
|
232
|
+
|
|
233
|
+
mask = create_attention_mask(hidden_states)
|
|
234
|
+
|
|
235
|
+
# cross_attn cached key/values tuple is at positions 3,4 of cache tuple
|
|
236
|
+
cross_attn_cache = cache[-1] if cache[-1] is not None else None
|
|
237
|
+
|
|
238
|
+
hidden_states = self.encoder_attn(
|
|
239
|
+
hidden_states,
|
|
240
|
+
key_value_states=encoder_hidden_states,
|
|
241
|
+
attention_mask=mask,
|
|
242
|
+
cache=cross_attn_cache,
|
|
243
|
+
)
|
|
244
|
+
hidden_states = residual + hidden_states
|
|
245
|
+
hidden_states = self.encoder_attn_layer_norm(hidden_states)
|
|
246
|
+
|
|
247
|
+
# Fully Connected
|
|
248
|
+
residual = hidden_states
|
|
249
|
+
hidden_states = self.activation_fn(self.fc1(hidden_states))
|
|
250
|
+
hidden_states = self.fc2(hidden_states)
|
|
251
|
+
hidden_states = residual + hidden_states
|
|
252
|
+
hidden_states = self.final_layer_norm(hidden_states)
|
|
253
|
+
|
|
254
|
+
return hidden_states
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
class Florence2Encoder(nn.Module):
|
|
258
|
+
def __init__(self, config: TextConfig):
|
|
259
|
+
super().__init__()
|
|
260
|
+
self.config = config
|
|
261
|
+
self.dropout = config.dropout
|
|
262
|
+
self.layerdrop = config.encoder_layerdrop
|
|
263
|
+
|
|
264
|
+
embed_dim = config.d_model
|
|
265
|
+
self.embed_scale = math.sqrt(embed_dim) if config.scale_embedding else 1.0
|
|
266
|
+
self.offset = 2
|
|
267
|
+
self.embed_positions = nn.Embedding(
|
|
268
|
+
config.max_position_embeddings + self.offset, embed_dim
|
|
269
|
+
)
|
|
270
|
+
self.layers = [
|
|
271
|
+
Florence2EncoderLayer(config) for _ in range(config.encoder_layers)
|
|
272
|
+
]
|
|
273
|
+
self.layernorm_embedding = nn.LayerNorm(embed_dim)
|
|
274
|
+
|
|
275
|
+
def __call__(self, input_ids=None, inputs_embeds=None, attention_mask=None):
|
|
276
|
+
|
|
277
|
+
if inputs_embeds is None:
|
|
278
|
+
inputs_embeds = self.embed_tokens(input_ids)
|
|
279
|
+
input_shape = inputs_embeds.shape
|
|
280
|
+
else:
|
|
281
|
+
input_shape = inputs_embeds.shape
|
|
282
|
+
|
|
283
|
+
positions = mx.arange(input_shape[1])
|
|
284
|
+
|
|
285
|
+
if positions.ndim == 1:
|
|
286
|
+
positions = mx.expand_dims(positions, axis=0)
|
|
287
|
+
|
|
288
|
+
embed_pos = self.embed_positions(positions + self.offset)
|
|
289
|
+
|
|
290
|
+
hidden_states = inputs_embeds + embed_pos
|
|
291
|
+
hidden_states = self.layernorm_embedding(hidden_states)
|
|
292
|
+
|
|
293
|
+
for encoder_layer in self.layers:
|
|
294
|
+
# Add LayerDrop (see https://arxiv.org/abs/1909.11556 for description)
|
|
295
|
+
dropout_probability = mx.random.uniform()
|
|
296
|
+
if self.training and (dropout_probability < self.layerdrop):
|
|
297
|
+
continue
|
|
298
|
+
hidden_states = encoder_layer(hidden_states, attention_mask)
|
|
299
|
+
|
|
300
|
+
return hidden_states
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
class Florence2Decoder(nn.Module):
|
|
304
|
+
def __init__(self, config: TextConfig):
|
|
305
|
+
super().__init__()
|
|
306
|
+
self.config = config
|
|
307
|
+
self.dropout = config.dropout
|
|
308
|
+
self.layerdrop = config.decoder_layerdrop
|
|
309
|
+
self.padding_idx = config.pad_token_id
|
|
310
|
+
self.max_target_positions = config.max_position_embeddings
|
|
311
|
+
self.embed_scale = math.sqrt(config.d_model) if config.scale_embedding else 1.0
|
|
312
|
+
self.offset = 2
|
|
313
|
+
self.embed_positions = nn.Embedding(
|
|
314
|
+
config.max_position_embeddings + self.offset, config.d_model
|
|
315
|
+
)
|
|
316
|
+
self.layers = [
|
|
317
|
+
Florence2DecoderLayer(config) for _ in range(config.decoder_layers)
|
|
318
|
+
]
|
|
319
|
+
self.layernorm_embedding = nn.LayerNorm(config.d_model)
|
|
320
|
+
|
|
321
|
+
def __call__(
|
|
322
|
+
self,
|
|
323
|
+
input_ids=None,
|
|
324
|
+
attention_mask=None,
|
|
325
|
+
encoder_hidden_states=None,
|
|
326
|
+
encoder_attention_mask=None,
|
|
327
|
+
head_mask=None,
|
|
328
|
+
cross_attn_head_mask=None,
|
|
329
|
+
inputs_embeds=None,
|
|
330
|
+
cache=None,
|
|
331
|
+
):
|
|
332
|
+
if input_ids is not None and inputs_embeds is not None:
|
|
333
|
+
raise ValueError(
|
|
334
|
+
"You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time"
|
|
335
|
+
)
|
|
336
|
+
elif input_ids is not None:
|
|
337
|
+
inputs_embeds = self.embed_tokens(input_ids)
|
|
338
|
+
input_shape = inputs_embeds.shape # for 2d masks
|
|
339
|
+
positions = input_ids
|
|
340
|
+
elif inputs_embeds is not None:
|
|
341
|
+
input_shape = inputs_embeds.shape[:-1] # for 4d masks
|
|
342
|
+
positions = inputs_embeds[:, :, -1]
|
|
343
|
+
else:
|
|
344
|
+
raise ValueError(
|
|
345
|
+
"You have to specify either decoder_input_ids or decoder_inputs_embeds"
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
if positions.ndim == 1:
|
|
349
|
+
positions = mx.expand_dims(positions, axis=0)
|
|
350
|
+
|
|
351
|
+
cache_length = cache[0][0].keys.shape[2] if cache[0][0].cache_length > 0 else 0
|
|
352
|
+
|
|
353
|
+
bsz, seq_len = inputs_embeds.shape[:2]
|
|
354
|
+
positions = mx.arange(
|
|
355
|
+
cache_length,
|
|
356
|
+
cache_length + seq_len,
|
|
357
|
+
dtype=mx.int64,
|
|
358
|
+
)
|
|
359
|
+
positions = mx.expand_dims(positions, axis=0)
|
|
360
|
+
|
|
361
|
+
embed_pos = self.embed_positions(positions + self.offset)
|
|
362
|
+
|
|
363
|
+
hidden_states = inputs_embeds + embed_pos
|
|
364
|
+
hidden_states = self.layernorm_embedding(hidden_states)
|
|
365
|
+
|
|
366
|
+
for decoder_layer, c in zip(self.layers, cache):
|
|
367
|
+
# add LayerDrop (see https://arxiv.org/abs/1909.11556 for description)
|
|
368
|
+
dropout_probability = mx.random.uniform()
|
|
369
|
+
if self.training and (dropout_probability < self.layerdrop):
|
|
370
|
+
continue
|
|
371
|
+
hidden_states = decoder_layer(
|
|
372
|
+
hidden_states=hidden_states,
|
|
373
|
+
encoder_hidden_states=encoder_hidden_states,
|
|
374
|
+
attention_mask=attention_mask,
|
|
375
|
+
encoder_attention_mask=encoder_attention_mask,
|
|
376
|
+
cache=c,
|
|
377
|
+
)
|
|
378
|
+
|
|
379
|
+
return hidden_states
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
class Florence2LanguageModel(nn.Module):
|
|
383
|
+
def __init__(self, config: TextConfig):
|
|
384
|
+
super().__init__()
|
|
385
|
+
self.config = config
|
|
386
|
+
self.shared = nn.Embedding(config.vocab_size, config.d_model)
|
|
387
|
+
self.encoder = Florence2Encoder(config)
|
|
388
|
+
self.decoder = Florence2Decoder(config)
|
|
389
|
+
if config.scale_embedding:
|
|
390
|
+
self.embed_scale = math.sqrt(config.d_model)
|
|
391
|
+
else:
|
|
392
|
+
self.embed_scale = 1.0
|
|
393
|
+
|
|
394
|
+
def __call__(
|
|
395
|
+
self,
|
|
396
|
+
input_ids=None,
|
|
397
|
+
inputs_embeds=None,
|
|
398
|
+
decoder_input_ids=None,
|
|
399
|
+
decoder_inputs_embeds=None,
|
|
400
|
+
attention_mask=None,
|
|
401
|
+
decoder_attention_mask=None,
|
|
402
|
+
encoder_outputs=None,
|
|
403
|
+
cache=None,
|
|
404
|
+
):
|
|
405
|
+
self.encoder.embed_tokens = self.shared
|
|
406
|
+
self.decoder.embed_tokens = self.shared
|
|
407
|
+
|
|
408
|
+
if decoder_input_ids is None and decoder_inputs_embeds is None:
|
|
409
|
+
if input_ids is None:
|
|
410
|
+
raise ValueError(
|
|
411
|
+
"If no `decoder_input_ids` or `decoder_inputs_embeds` are "
|
|
412
|
+
"passed, `input_ids` cannot be `None`. Please pass either "
|
|
413
|
+
"`input_ids` or `decoder_input_ids` or `decoder_inputs_embeds`."
|
|
414
|
+
)
|
|
415
|
+
|
|
416
|
+
decoder_input_ids = mx.zeros_like(input_ids)
|
|
417
|
+
decoder_input_ids[:, 1:] = input_ids[:, :-1]
|
|
418
|
+
decoder_input_ids[:, 0] = self.config.bos_token_id
|
|
419
|
+
|
|
420
|
+
if inputs_embeds is not None:
|
|
421
|
+
inputs_embeds = inputs_embeds * self.embed_scale
|
|
422
|
+
|
|
423
|
+
if cache is None:
|
|
424
|
+
cache = [(SimpleKVCache(), SimpleKVCache())] * len(self.decoder.layers)
|
|
425
|
+
|
|
426
|
+
if encoder_outputs is None:
|
|
427
|
+
encoder_outputs = self.encoder(
|
|
428
|
+
input_ids=input_ids,
|
|
429
|
+
inputs_embeds=inputs_embeds,
|
|
430
|
+
attention_mask=attention_mask,
|
|
431
|
+
)
|
|
432
|
+
|
|
433
|
+
decoder_outputs = self.decoder(
|
|
434
|
+
input_ids=decoder_input_ids,
|
|
435
|
+
attention_mask=decoder_attention_mask,
|
|
436
|
+
encoder_hidden_states=encoder_outputs,
|
|
437
|
+
encoder_attention_mask=attention_mask,
|
|
438
|
+
inputs_embeds=decoder_inputs_embeds,
|
|
439
|
+
cache=cache,
|
|
440
|
+
)
|
|
441
|
+
return decoder_outputs, encoder_outputs
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
class LanguageModel(nn.Module):
|
|
445
|
+
def __init__(self, config: TextConfig):
|
|
446
|
+
super().__init__()
|
|
447
|
+
self.config = config
|
|
448
|
+
self.model = Florence2LanguageModel(config)
|
|
449
|
+
self.lm_head = nn.Linear(config.d_model, config.vocab_size, bias=False)
|
|
450
|
+
|
|
451
|
+
def __call__(
|
|
452
|
+
self,
|
|
453
|
+
input_ids=None,
|
|
454
|
+
inputs_embeds=None,
|
|
455
|
+
decoder_input_ids=None,
|
|
456
|
+
decoder_inputs_embeds=None,
|
|
457
|
+
attention_mask=None,
|
|
458
|
+
decoder_attention_mask=None,
|
|
459
|
+
encoder_outputs=None,
|
|
460
|
+
cache=None,
|
|
461
|
+
):
|
|
462
|
+
decoder_outputs, encoder_outputs = self.model(
|
|
463
|
+
input_ids,
|
|
464
|
+
inputs_embeds,
|
|
465
|
+
decoder_input_ids,
|
|
466
|
+
decoder_inputs_embeds,
|
|
467
|
+
attention_mask,
|
|
468
|
+
decoder_attention_mask,
|
|
469
|
+
encoder_outputs,
|
|
470
|
+
cache,
|
|
471
|
+
)
|
|
472
|
+
out = self.lm_head(decoder_outputs)
|
|
473
|
+
return LanguageModelOutput(logits=out, encoder_outputs=encoder_outputs)
|
|
474
|
+
|
|
475
|
+
@property
|
|
476
|
+
def layers(self):
|
|
477
|
+
return range(self.model.config.decoder_layers)
|
|
478
|
+
|
|
479
|
+
@property
|
|
480
|
+
def head_dim(self):
|
|
481
|
+
return self.config.d_model // self.config.decoder_attention_heads
|
|
482
|
+
|
|
483
|
+
@property
|
|
484
|
+
def n_kv_heads(self):
|
|
485
|
+
return self.config.decoder_attention_heads
|
|
486
|
+
|
|
487
|
+
def make_cache(self):
|
|
488
|
+
return [(SimpleKVCache(), SimpleKVCache()) for n in self.layers]
|