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,173 @@
|
|
|
1
|
+
# Copyright © Nexa AI
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
import sys
|
|
17
|
+
import numpy as np
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
# Add parent path for imports
|
|
21
|
+
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
22
|
+
|
|
23
|
+
# Import from interface (uses the factory pattern with routing)
|
|
24
|
+
from .interface import create_embedder
|
|
25
|
+
from .interface import EmbeddingConfig
|
|
26
|
+
from huggingface_hub import snapshot_download
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def download_model_if_needed(model_id, local_dir):
|
|
30
|
+
"""Download model from Hugging Face Hub if not present locally."""
|
|
31
|
+
if not os.path.exists(os.path.join(local_dir, "config.json")):
|
|
32
|
+
print(f"📥 Model not found locally. Downloading {model_id}...")
|
|
33
|
+
os.makedirs(local_dir, exist_ok=True)
|
|
34
|
+
try:
|
|
35
|
+
snapshot_download(
|
|
36
|
+
repo_id=model_id,
|
|
37
|
+
local_dir=local_dir,
|
|
38
|
+
resume_download=True,
|
|
39
|
+
local_dir_use_symlinks=False
|
|
40
|
+
)
|
|
41
|
+
print("✅ Model download completed!")
|
|
42
|
+
except Exception as e:
|
|
43
|
+
print(f"❌ Failed to download model: {e}")
|
|
44
|
+
raise
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_embedding_interface(model_path, is_local=False):
|
|
48
|
+
"""Test embedding model functionality using the interface."""
|
|
49
|
+
|
|
50
|
+
print("=" * 70)
|
|
51
|
+
print("TESTING EMBEDDING MODEL VIA INTERFACE")
|
|
52
|
+
print("=" * 70)
|
|
53
|
+
|
|
54
|
+
# Handle model path - download if it's a HF model ID
|
|
55
|
+
if not is_local and "/" in model_path:
|
|
56
|
+
# It's a HuggingFace model ID
|
|
57
|
+
local_dir = f"./modelfiles/{model_path.replace('/', '_')}"
|
|
58
|
+
download_model_if_needed(model_path, local_dir)
|
|
59
|
+
model_path = local_dir
|
|
60
|
+
|
|
61
|
+
# Create embedder using factory function (will auto-detect model type)
|
|
62
|
+
print(f"\n🔍 Creating embedder for: {model_path}")
|
|
63
|
+
embedder = create_embedder(model_path=model_path)
|
|
64
|
+
print(f"✅ Created embedder type: {type(embedder).__name__}")
|
|
65
|
+
|
|
66
|
+
# Load the model
|
|
67
|
+
print("\n📚 Loading embedding model...")
|
|
68
|
+
success = embedder.load_model(model_path)
|
|
69
|
+
|
|
70
|
+
if not success:
|
|
71
|
+
print("❌ Failed to load model!")
|
|
72
|
+
return
|
|
73
|
+
|
|
74
|
+
print("✅ Model loaded successfully!")
|
|
75
|
+
print(f"📏 Embedding dimension: {embedder.embedding_dim()}")
|
|
76
|
+
|
|
77
|
+
# Test texts
|
|
78
|
+
test_texts = [
|
|
79
|
+
"Hello, how are you?",
|
|
80
|
+
"What is machine learning?",
|
|
81
|
+
"The weather is nice today.",
|
|
82
|
+
"Python is a programming language.",
|
|
83
|
+
"Artificial intelligence is changing the world."
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
# Configure embedding with different settings
|
|
87
|
+
configs = [
|
|
88
|
+
EmbeddingConfig(batch_size=2, normalize=True, normalize_method="l2"),
|
|
89
|
+
EmbeddingConfig(batch_size=3, normalize=False),
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
for config_idx, config in enumerate(configs):
|
|
93
|
+
print(f"\n{'='*50}")
|
|
94
|
+
print(f"TEST {config_idx + 1}: Config - Batch: {config.batch_size}, "
|
|
95
|
+
f"Normalize: {config.normalize}, Method: {config.normalize_method}")
|
|
96
|
+
print('='*50)
|
|
97
|
+
|
|
98
|
+
# Generate embeddings
|
|
99
|
+
embeddings = embedder.embed(test_texts, config)
|
|
100
|
+
|
|
101
|
+
# Display results
|
|
102
|
+
print(f"\n📊 Generated {len(embeddings)} embeddings")
|
|
103
|
+
|
|
104
|
+
for i, (text, embedding) in enumerate(zip(test_texts[:3], embeddings[:3])):
|
|
105
|
+
print(f"\n Text {i+1}: '{text}'")
|
|
106
|
+
print(f" Dimension: {len(embedding)}")
|
|
107
|
+
print(f" First 5 values: {[f'{v:.4f}' for v in embedding[:5]]}")
|
|
108
|
+
|
|
109
|
+
# Calculate magnitude
|
|
110
|
+
magnitude = np.linalg.norm(embedding)
|
|
111
|
+
print(f" Magnitude: {magnitude:.6f}")
|
|
112
|
+
|
|
113
|
+
# Compute similarity matrix for normalized embeddings
|
|
114
|
+
print("\n" + "="*50)
|
|
115
|
+
print("SIMILARITY MATRIX (L2 Normalized)")
|
|
116
|
+
print("="*50)
|
|
117
|
+
|
|
118
|
+
config = EmbeddingConfig(batch_size=len(test_texts), normalize=True, normalize_method="l2")
|
|
119
|
+
embeddings = embedder.embed(test_texts, config)
|
|
120
|
+
|
|
121
|
+
# Convert to numpy for easier computation
|
|
122
|
+
embeddings_np = np.array(embeddings)
|
|
123
|
+
similarity_matrix = np.dot(embeddings_np, embeddings_np.T)
|
|
124
|
+
|
|
125
|
+
print("\nTexts:")
|
|
126
|
+
for i, text in enumerate(test_texts):
|
|
127
|
+
print(f" [{i}] {text[:30]}...")
|
|
128
|
+
|
|
129
|
+
print("\nSimilarity Matrix:")
|
|
130
|
+
print(" ", end="")
|
|
131
|
+
for i in range(len(test_texts)):
|
|
132
|
+
print(f" [{i}] ", end="")
|
|
133
|
+
print()
|
|
134
|
+
|
|
135
|
+
for i in range(len(test_texts)):
|
|
136
|
+
print(f" [{i}]", end="")
|
|
137
|
+
for j in range(len(test_texts)):
|
|
138
|
+
print(f" {similarity_matrix[i, j]:5.2f}", end="")
|
|
139
|
+
print()
|
|
140
|
+
|
|
141
|
+
# Find most similar pairs
|
|
142
|
+
print("\n🔍 Most Similar Pairs (excluding self-similarity):")
|
|
143
|
+
similarities = []
|
|
144
|
+
for i in range(len(test_texts)):
|
|
145
|
+
for j in range(i+1, len(test_texts)):
|
|
146
|
+
similarities.append((similarity_matrix[i, j], i, j))
|
|
147
|
+
|
|
148
|
+
similarities.sort(reverse=True)
|
|
149
|
+
for sim, i, j in similarities[:3]:
|
|
150
|
+
print(f" • Texts [{i}] and [{j}]: {sim:.4f}")
|
|
151
|
+
|
|
152
|
+
# Cleanup
|
|
153
|
+
embedder.close()
|
|
154
|
+
print("\n✅ Interface test completed successfully!")
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
if __name__ == "__main__":
|
|
158
|
+
import argparse
|
|
159
|
+
parser = argparse.ArgumentParser(description="Test embedding models via interface")
|
|
160
|
+
parser.add_argument(
|
|
161
|
+
"--model_path",
|
|
162
|
+
type=str,
|
|
163
|
+
default="nexaml/jina-v2-fp16-mlx",
|
|
164
|
+
help="Model path (local) or HuggingFace model ID"
|
|
165
|
+
)
|
|
166
|
+
parser.add_argument(
|
|
167
|
+
"--local",
|
|
168
|
+
action="store_true",
|
|
169
|
+
help="Indicate if model_path is a local directory"
|
|
170
|
+
)
|
|
171
|
+
args = parser.parse_args()
|
|
172
|
+
|
|
173
|
+
test_embedding_interface(args.model_path, args.local)
|
|
File without changes
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
# Copyright © Nexa AI
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import math
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
from typing import Any, Dict, List, Optional, Union
|
|
18
|
+
|
|
19
|
+
import mlx.core as mx
|
|
20
|
+
import mlx.nn as nn
|
|
21
|
+
|
|
22
|
+
import os
|
|
23
|
+
import sys
|
|
24
|
+
|
|
25
|
+
curr_dir = os.path.dirname(os.path.abspath(__file__))
|
|
26
|
+
llm_common_dir = os.path.join(curr_dir, "..", "..")
|
|
27
|
+
sys.path.append(llm_common_dir)
|
|
28
|
+
|
|
29
|
+
from mlx_lm.models.base import (
|
|
30
|
+
BaseModelArgs,
|
|
31
|
+
scaled_dot_product_attention,
|
|
32
|
+
)
|
|
33
|
+
from tokenizers import Tokenizer
|
|
34
|
+
|
|
35
|
+
@dataclass
|
|
36
|
+
class ModelArgs(BaseModelArgs):
|
|
37
|
+
model_type: str = "bert"
|
|
38
|
+
vocab_size: int = 61056 # Updated from config
|
|
39
|
+
hidden_size: int = 768
|
|
40
|
+
num_hidden_layers: int = 12
|
|
41
|
+
num_attention_heads: int = 12
|
|
42
|
+
intermediate_size: int = 3072
|
|
43
|
+
hidden_act: str = "gelu"
|
|
44
|
+
hidden_dropout_prob: float = 0.1
|
|
45
|
+
attention_probs_dropout_prob: float = 0.1
|
|
46
|
+
max_position_embeddings: int = 8192 # Updated from config
|
|
47
|
+
type_vocab_size: int = 2
|
|
48
|
+
initializer_range: float = 0.02
|
|
49
|
+
layer_norm_eps: float = 1e-12
|
|
50
|
+
pad_token_id: int = 0
|
|
51
|
+
position_embedding_type: str = "alibi" # Updated from config
|
|
52
|
+
use_cache: bool = True
|
|
53
|
+
classifier_dropout: Optional[float] = None
|
|
54
|
+
feed_forward_type: str = "geglu" # Updated from config
|
|
55
|
+
emb_pooler: str = "mean" # Updated from config
|
|
56
|
+
attn_implementation: str = "torch"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class JinaBertEmbeddings(nn.Module):
|
|
60
|
+
def __init__(self, config: ModelArgs):
|
|
61
|
+
super().__init__()
|
|
62
|
+
self.word_embeddings = nn.Embedding(config.vocab_size, config.hidden_size)
|
|
63
|
+
self.token_type_embeddings = nn.Embedding(config.type_vocab_size, config.hidden_size)
|
|
64
|
+
# Use PyTorch-style naming for weight loading compatibility
|
|
65
|
+
self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
|
66
|
+
self.position_embedding_type = getattr(config, "position_embedding_type", "absolute")
|
|
67
|
+
|
|
68
|
+
def __call__(
|
|
69
|
+
self,
|
|
70
|
+
input_ids: Optional[mx.array] = None,
|
|
71
|
+
token_type_ids: Optional[mx.array] = None,
|
|
72
|
+
) -> mx.array:
|
|
73
|
+
if token_type_ids is None:
|
|
74
|
+
input_shape = input_ids.shape
|
|
75
|
+
token_type_ids = mx.zeros(input_shape, dtype=mx.int64)
|
|
76
|
+
|
|
77
|
+
inputs_embeds = self.word_embeddings(input_ids)
|
|
78
|
+
token_type_embeddings = self.token_type_embeddings(token_type_ids)
|
|
79
|
+
|
|
80
|
+
embeddings = inputs_embeds + token_type_embeddings
|
|
81
|
+
embeddings = self.LayerNorm(embeddings)
|
|
82
|
+
return embeddings
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class JinaBertSelfAttention(nn.Module):
|
|
86
|
+
def __init__(self, config: ModelArgs, position_embedding_type=None):
|
|
87
|
+
super().__init__()
|
|
88
|
+
if config.hidden_size % config.num_attention_heads != 0:
|
|
89
|
+
raise ValueError(
|
|
90
|
+
f"The hidden size ({config.hidden_size}) is not a multiple of the number of attention "
|
|
91
|
+
f"heads ({config.num_attention_heads})"
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
self.attn_implementation = config.attn_implementation
|
|
95
|
+
self.num_attention_heads = config.num_attention_heads
|
|
96
|
+
self.attention_head_size = int(config.hidden_size / config.num_attention_heads)
|
|
97
|
+
self.all_head_size = self.num_attention_heads * self.attention_head_size
|
|
98
|
+
|
|
99
|
+
self.query = nn.Linear(config.hidden_size, self.all_head_size)
|
|
100
|
+
self.key = nn.Linear(config.hidden_size, self.all_head_size)
|
|
101
|
+
self.value = nn.Linear(config.hidden_size, self.all_head_size)
|
|
102
|
+
|
|
103
|
+
self.position_embedding_type = position_embedding_type or getattr(
|
|
104
|
+
config, "position_embedding_type", "absolute"
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
def transpose_for_scores(self, x: mx.array) -> mx.array:
|
|
108
|
+
new_x_shape = x.shape[:-1] + (self.num_attention_heads, self.attention_head_size)
|
|
109
|
+
x = x.reshape(new_x_shape)
|
|
110
|
+
return x.transpose(0, 2, 1, 3)
|
|
111
|
+
|
|
112
|
+
def __call__(
|
|
113
|
+
self,
|
|
114
|
+
hidden_states: mx.array,
|
|
115
|
+
attention_mask: Optional[mx.array] = None,
|
|
116
|
+
bias: Optional[mx.array] = None,
|
|
117
|
+
) -> mx.array:
|
|
118
|
+
mixed_query_layer = self.query(hidden_states)
|
|
119
|
+
|
|
120
|
+
key_layer = self.transpose_for_scores(self.key(hidden_states))
|
|
121
|
+
value_layer = self.transpose_for_scores(self.value(hidden_states))
|
|
122
|
+
query_layer = self.transpose_for_scores(mixed_query_layer)
|
|
123
|
+
|
|
124
|
+
scale = 1.0 / math.sqrt(self.attention_head_size)
|
|
125
|
+
|
|
126
|
+
mask = None
|
|
127
|
+
if attention_mask is not None or bias is not None:
|
|
128
|
+
if attention_mask is not None and bias is not None:
|
|
129
|
+
mask = attention_mask + bias
|
|
130
|
+
elif attention_mask is not None:
|
|
131
|
+
mask = attention_mask
|
|
132
|
+
else:
|
|
133
|
+
mask = bias
|
|
134
|
+
|
|
135
|
+
# Cast mask to same dtype as hidden_states
|
|
136
|
+
if mask is not None:
|
|
137
|
+
mask = mask.astype(hidden_states.dtype)
|
|
138
|
+
|
|
139
|
+
context_layer = scaled_dot_product_attention(
|
|
140
|
+
query_layer, key_layer, value_layer, cache=None, scale=scale, mask=mask
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
context_layer = context_layer.transpose(0, 2, 1, 3)
|
|
144
|
+
new_context_layer_shape = context_layer.shape[:-2] + (self.all_head_size,)
|
|
145
|
+
context_layer = context_layer.reshape(new_context_layer_shape)
|
|
146
|
+
return context_layer
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class JinaBertSelfOutput(nn.Module):
|
|
150
|
+
def __init__(self, config):
|
|
151
|
+
super().__init__()
|
|
152
|
+
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
|
|
153
|
+
# Use PyTorch-style naming for weight loading compatibility
|
|
154
|
+
self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
|
155
|
+
|
|
156
|
+
def __call__(self, hidden_states: mx.array, input_tensor: mx.array) -> mx.array:
|
|
157
|
+
hidden_states = self.dense(hidden_states)
|
|
158
|
+
hidden_states = self.LayerNorm(hidden_states + input_tensor)
|
|
159
|
+
return hidden_states
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
class JinaBertAttention(nn.Module):
|
|
163
|
+
def __init__(self, config, position_embedding_type=None):
|
|
164
|
+
super().__init__()
|
|
165
|
+
self.self = JinaBertSelfAttention(config, position_embedding_type=position_embedding_type)
|
|
166
|
+
self.output = JinaBertSelfOutput(config)
|
|
167
|
+
|
|
168
|
+
def __call__(
|
|
169
|
+
self,
|
|
170
|
+
hidden_states: mx.array,
|
|
171
|
+
attention_mask: Optional[mx.array] = None,
|
|
172
|
+
bias: Optional[mx.array] = None,
|
|
173
|
+
) -> mx.array:
|
|
174
|
+
self_outputs = self.self(hidden_states, attention_mask, bias)
|
|
175
|
+
attention_output = self.output(self_outputs, hidden_states)
|
|
176
|
+
return attention_output
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
class JinaBertGLUMLP(nn.Module):
|
|
180
|
+
def __init__(self, config: ModelArgs):
|
|
181
|
+
super().__init__()
|
|
182
|
+
self.config = config
|
|
183
|
+
self.gated_layers = nn.Linear(config.hidden_size, config.intermediate_size * 2, bias=False)
|
|
184
|
+
self.wo = nn.Linear(config.intermediate_size, config.hidden_size)
|
|
185
|
+
# Use PyTorch-style naming for weight loading compatibility
|
|
186
|
+
self.layernorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
|
187
|
+
|
|
188
|
+
def __call__(self, hidden_states: mx.array) -> mx.array:
|
|
189
|
+
residual_connection = hidden_states
|
|
190
|
+
hidden_states = self.gated_layers(hidden_states)
|
|
191
|
+
|
|
192
|
+
if self.config.feed_forward_type == "geglu":
|
|
193
|
+
gated = hidden_states[..., : self.config.intermediate_size]
|
|
194
|
+
non_gated = hidden_states[..., self.config.intermediate_size :]
|
|
195
|
+
hidden_states = nn.gelu(gated) * non_gated
|
|
196
|
+
else:
|
|
197
|
+
# Original GLU
|
|
198
|
+
gated = hidden_states[..., : self.config.intermediate_size]
|
|
199
|
+
non_gated = hidden_states[..., self.config.intermediate_size :]
|
|
200
|
+
hidden_states = nn.gelu(gated) * non_gated
|
|
201
|
+
|
|
202
|
+
hidden_states = self.wo(hidden_states)
|
|
203
|
+
hidden_states = self.layernorm(hidden_states + residual_connection)
|
|
204
|
+
return hidden_states
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
class JinaBertLayer(nn.Module):
|
|
208
|
+
def __init__(self, config: ModelArgs):
|
|
209
|
+
super().__init__()
|
|
210
|
+
self.attention = JinaBertAttention(config)
|
|
211
|
+
self.feed_forward_type = config.feed_forward_type
|
|
212
|
+
self.mlp = JinaBertGLUMLP(config)
|
|
213
|
+
|
|
214
|
+
def __call__(
|
|
215
|
+
self,
|
|
216
|
+
hidden_states: mx.array,
|
|
217
|
+
attention_mask: Optional[mx.array] = None,
|
|
218
|
+
bias: Optional[mx.array] = None,
|
|
219
|
+
) -> mx.array:
|
|
220
|
+
attention_output = self.attention(hidden_states, attention_mask, bias=bias)
|
|
221
|
+
layer_output = self.mlp(attention_output)
|
|
222
|
+
return layer_output
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
class JinaBertEncoder(nn.Module):
|
|
226
|
+
def __init__(self, config: ModelArgs):
|
|
227
|
+
super().__init__()
|
|
228
|
+
self.config = config
|
|
229
|
+
# Use list instead of ModuleList for PyTorch compatibility
|
|
230
|
+
self.layer = [JinaBertLayer(config) for _ in range(config.num_hidden_layers)]
|
|
231
|
+
self.gradient_checkpointing = False
|
|
232
|
+
self.num_attention_heads = config.num_attention_heads
|
|
233
|
+
self._current_alibi_size = config.max_position_embeddings
|
|
234
|
+
|
|
235
|
+
# Build ALiBi tensor
|
|
236
|
+
# self.alibi = self.rebuild_alibi_tensor(size=config.max_position_embeddings)
|
|
237
|
+
|
|
238
|
+
def rebuild_alibi_tensor(self, size: int) -> mx.array:
|
|
239
|
+
"""Build ALiBi bias tensor"""
|
|
240
|
+
n_heads = self.num_attention_heads
|
|
241
|
+
|
|
242
|
+
def _get_alibi_head_slopes(n_heads: int) -> List[float]:
|
|
243
|
+
def get_slopes_power_of_2(n):
|
|
244
|
+
start = 2 ** (-(2 ** -(math.log2(n) - 3)))
|
|
245
|
+
ratio = start
|
|
246
|
+
return [start * ratio**i for i in range(n)]
|
|
247
|
+
|
|
248
|
+
if math.log2(n_heads).is_integer():
|
|
249
|
+
return get_slopes_power_of_2(n_heads)
|
|
250
|
+
else:
|
|
251
|
+
closest_power_of_2 = 2 ** math.floor(math.log2(n_heads))
|
|
252
|
+
return (
|
|
253
|
+
get_slopes_power_of_2(closest_power_of_2)
|
|
254
|
+
+ _get_alibi_head_slopes(2 * closest_power_of_2)[0::2][
|
|
255
|
+
: n_heads - closest_power_of_2
|
|
256
|
+
]
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
context_position = mx.arange(size)[:, None]
|
|
260
|
+
memory_position = mx.arange(size)[None, :]
|
|
261
|
+
relative_position = mx.abs(memory_position - context_position)
|
|
262
|
+
relative_position = mx.expand_dims(relative_position, axis=0)
|
|
263
|
+
relative_position = mx.repeat(relative_position, n_heads, axis=0)
|
|
264
|
+
|
|
265
|
+
slopes = mx.array(_get_alibi_head_slopes(n_heads)) * -1
|
|
266
|
+
slopes = mx.expand_dims(mx.expand_dims(slopes, axis=1), axis=2)
|
|
267
|
+
alibi = slopes * relative_position
|
|
268
|
+
alibi = mx.expand_dims(alibi, axis=0)
|
|
269
|
+
|
|
270
|
+
self._current_alibi_size = size
|
|
271
|
+
return alibi
|
|
272
|
+
|
|
273
|
+
def __call__(
|
|
274
|
+
self,
|
|
275
|
+
hidden_states: mx.array,
|
|
276
|
+
attention_mask: Optional[mx.array] = None,
|
|
277
|
+
) -> mx.array:
|
|
278
|
+
_, seqlen, _ = hidden_states.shape
|
|
279
|
+
alibi_bias = self.rebuild_alibi_tensor(seqlen)
|
|
280
|
+
|
|
281
|
+
for i, layer_module in enumerate(self.layer):
|
|
282
|
+
layer_outputs = layer_module(hidden_states, attention_mask, alibi_bias)
|
|
283
|
+
hidden_states = layer_outputs
|
|
284
|
+
|
|
285
|
+
return hidden_states
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
class JinaBertPooler(nn.Module):
|
|
289
|
+
def __init__(self, config):
|
|
290
|
+
super().__init__()
|
|
291
|
+
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
|
|
292
|
+
self.activation = nn.tanh
|
|
293
|
+
|
|
294
|
+
def __call__(self, hidden_states: mx.array) -> mx.array:
|
|
295
|
+
# We "pool" the model by simply taking the hidden state corresponding
|
|
296
|
+
# to the first token.
|
|
297
|
+
first_token_tensor = hidden_states[:, 0]
|
|
298
|
+
pooled_output = self.dense(first_token_tensor)
|
|
299
|
+
pooled_output = self.activation(pooled_output)
|
|
300
|
+
return pooled_output
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
class JinaBertModel(nn.Module):
|
|
304
|
+
def __init__(self, config: ModelArgs):
|
|
305
|
+
super().__init__()
|
|
306
|
+
self.config = config
|
|
307
|
+
self.embeddings = JinaBertEmbeddings(config)
|
|
308
|
+
self.encoder = JinaBertEncoder(config)
|
|
309
|
+
# Add pooler layer for weight compatibility
|
|
310
|
+
self.pooler = JinaBertPooler(config)
|
|
311
|
+
|
|
312
|
+
def get_extended_attention_mask(self, attention_mask: mx.array, input_shape: tuple) -> mx.array:
|
|
313
|
+
"""Convert attention mask to extended format"""
|
|
314
|
+
if attention_mask.ndim == 3:
|
|
315
|
+
extended_attention_mask = attention_mask[:, None, :, :]
|
|
316
|
+
elif attention_mask.ndim == 2:
|
|
317
|
+
extended_attention_mask = attention_mask[:, None, None, :]
|
|
318
|
+
else:
|
|
319
|
+
raise ValueError(f"Wrong shape for attention_mask (shape {attention_mask.shape})")
|
|
320
|
+
|
|
321
|
+
extended_attention_mask = (1.0 - extended_attention_mask) * -10000.0
|
|
322
|
+
return extended_attention_mask
|
|
323
|
+
|
|
324
|
+
def mean_pooling(self, token_embeddings: mx.array, attention_mask: mx.array) -> mx.array:
|
|
325
|
+
input_mask_expanded = mx.expand_dims(attention_mask, axis=-1) * mx.ones_like(
|
|
326
|
+
token_embeddings
|
|
327
|
+
)
|
|
328
|
+
return mx.sum(token_embeddings * input_mask_expanded, axis=1) / mx.clip(
|
|
329
|
+
mx.sum(input_mask_expanded, axis=1), 1e-9, None
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
def __call__(
|
|
333
|
+
self,
|
|
334
|
+
input_ids: Optional[mx.array] = None,
|
|
335
|
+
attention_mask: Optional[mx.array] = None,
|
|
336
|
+
token_type_ids: Optional[mx.array] = None,
|
|
337
|
+
) -> mx.array:
|
|
338
|
+
input_shape = input_ids.shape
|
|
339
|
+
|
|
340
|
+
if attention_mask is not None:
|
|
341
|
+
extended_attention_mask = self.get_extended_attention_mask(attention_mask, input_shape)
|
|
342
|
+
else:
|
|
343
|
+
extended_attention_mask = None
|
|
344
|
+
|
|
345
|
+
embedding_output = self.embeddings(input_ids=input_ids, token_type_ids=token_type_ids)
|
|
346
|
+
encoder_outputs = self.encoder(embedding_output, attention_mask=extended_attention_mask)
|
|
347
|
+
|
|
348
|
+
return encoder_outputs
|
|
349
|
+
|
|
350
|
+
def encode(
|
|
351
|
+
self,
|
|
352
|
+
input_ids: mx.array,
|
|
353
|
+
attention_mask: mx.array,
|
|
354
|
+
token_type_ids: Optional[mx.array] = None,
|
|
355
|
+
) -> mx.array:
|
|
356
|
+
"""Encode inputs and return mean-pooled embeddings"""
|
|
357
|
+
token_embs = self(
|
|
358
|
+
input_ids=input_ids, attention_mask=attention_mask, token_type_ids=token_type_ids
|
|
359
|
+
)
|
|
360
|
+
embeddings = self.mean_pooling(token_embs, attention_mask)
|
|
361
|
+
return embeddings
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
class Model(nn.Module):
|
|
365
|
+
def __init__(self, args: ModelArgs):
|
|
366
|
+
super().__init__()
|
|
367
|
+
self.args = args
|
|
368
|
+
self.model_type = args.model_type
|
|
369
|
+
self.model = JinaBertModel(args)
|
|
370
|
+
|
|
371
|
+
def __call__(
|
|
372
|
+
self,
|
|
373
|
+
input_ids: mx.array,
|
|
374
|
+
attention_mask: Optional[mx.array] = None,
|
|
375
|
+
token_type_ids: Optional[mx.array] = None,
|
|
376
|
+
) -> mx.array:
|
|
377
|
+
return self.model(
|
|
378
|
+
input_ids=input_ids, attention_mask=attention_mask, token_type_ids=token_type_ids
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
def encode(
|
|
382
|
+
self,
|
|
383
|
+
input_ids: mx.array,
|
|
384
|
+
attention_mask: mx.array,
|
|
385
|
+
token_type_ids: Optional[mx.array] = None,
|
|
386
|
+
) -> mx.array:
|
|
387
|
+
"""Encode inputs and return mean-pooled embeddings"""
|
|
388
|
+
return self.model.encode(
|
|
389
|
+
input_ids=input_ids, attention_mask=attention_mask, token_type_ids=token_type_ids
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
def sanitize(self, weights):
|
|
393
|
+
"""Remove parameters that don't exist in our model"""
|
|
394
|
+
# No longer need to remove pooler weights since we now have them
|
|
395
|
+
return weights
|
|
396
|
+
|
|
397
|
+
@property
|
|
398
|
+
def layers(self):
|
|
399
|
+
return self.model.encoder.layer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Image generation module for MLX backend
|