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,528 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import glob
|
|
3
|
+
import math
|
|
4
|
+
import time
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from enum import Enum
|
|
7
|
+
from typing import Dict, Optional, Tuple, Union
|
|
8
|
+
|
|
9
|
+
import mlx.core as mx
|
|
10
|
+
import mlx.nn as nn
|
|
11
|
+
import numpy as np
|
|
12
|
+
import tqdm
|
|
13
|
+
from mlx.utils import tree_map, tree_unflatten
|
|
14
|
+
from mlx_lm.models.base import create_causal_mask
|
|
15
|
+
from scipy.io.wavfile import write as write_wav
|
|
16
|
+
from transformers import BertTokenizer
|
|
17
|
+
|
|
18
|
+
from ..base import BaseModelArgs, GenerationResult
|
|
19
|
+
from .pipeline import Pipeline
|
|
20
|
+
|
|
21
|
+
mx.random.seed(42)
|
|
22
|
+
|
|
23
|
+
TEXT_ENCODING_OFFSET = 10_048
|
|
24
|
+
SEMANTIC_PAD_TOKEN = 10_000
|
|
25
|
+
TEXT_PAD_TOKEN = 129595
|
|
26
|
+
SEMANTIC_INFER_TOKEN = 129_599
|
|
27
|
+
|
|
28
|
+
CONTEXT_WINDOW_SIZE = 1024
|
|
29
|
+
|
|
30
|
+
SEMANTIC_RATE_HZ = 49.9
|
|
31
|
+
SEMANTIC_VOCAB_SIZE = 10_000
|
|
32
|
+
|
|
33
|
+
CODEBOOK_SIZE = 1024
|
|
34
|
+
N_COARSE_CODEBOOKS = 2
|
|
35
|
+
N_FINE_CODEBOOKS = 8
|
|
36
|
+
COARSE_RATE_HZ = 75
|
|
37
|
+
COARSE_SEMANTIC_PAD_TOKEN = 12_048
|
|
38
|
+
COARSE_INFER_TOKEN = 12_050
|
|
39
|
+
SAMPLE_RATE = 24_000
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def filter_dataclass_fields(data_dict, dataclass_type):
|
|
43
|
+
"""Filter a dictionary to only include keys that are fields in the dataclass."""
|
|
44
|
+
valid_fields = {f.name for f in dataclass_type.__dataclass_fields__.values()}
|
|
45
|
+
return {k: v for k, v in data_dict.items() if k in valid_fields}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@dataclass
|
|
49
|
+
class SemanticConfig(BaseModelArgs):
|
|
50
|
+
bad_words_ids: list[list[int]] = None
|
|
51
|
+
block_size: int = 1024
|
|
52
|
+
input_vocab_size: int = 129600
|
|
53
|
+
output_vocab_size: int = 129600
|
|
54
|
+
n_layer: int = 12
|
|
55
|
+
n_head: int = 12
|
|
56
|
+
n_embd: int = 768
|
|
57
|
+
bias: bool = False
|
|
58
|
+
model_type: str = "semantic"
|
|
59
|
+
dropout: float = 0.0
|
|
60
|
+
architectures: list[str] = None
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@dataclass
|
|
64
|
+
class CoarseAcousticsConfig(BaseModelArgs):
|
|
65
|
+
block_size: int = 1024
|
|
66
|
+
input_vocab_size: int = 12096
|
|
67
|
+
output_vocab_size: int = 12096
|
|
68
|
+
n_layer: int = 12
|
|
69
|
+
n_head: int = 12
|
|
70
|
+
n_embd: int = 768
|
|
71
|
+
bias: bool = False
|
|
72
|
+
model_type: str = "coarse_acoustics"
|
|
73
|
+
dropout: float = 0.0
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@dataclass
|
|
77
|
+
class FineAcousticsConfig(BaseModelArgs):
|
|
78
|
+
block_size: int = 1024
|
|
79
|
+
input_vocab_size: int = 1056
|
|
80
|
+
output_vocab_size: int = 1056
|
|
81
|
+
n_layer: int = 12
|
|
82
|
+
n_head: int = 12
|
|
83
|
+
n_embd: int = 768
|
|
84
|
+
bias: bool = False
|
|
85
|
+
model_type: str = "fine_acoustics"
|
|
86
|
+
n_codes_total: int = 8
|
|
87
|
+
n_codes_given: int = 1
|
|
88
|
+
dropout: float = 0.0
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@dataclass
|
|
92
|
+
class CodecConfig(BaseModelArgs):
|
|
93
|
+
model_type: str = "codec"
|
|
94
|
+
sample_rate: int = 24000
|
|
95
|
+
target_bandwidth: float = 6.0
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@dataclass
|
|
99
|
+
class ModelConfig(BaseModelArgs):
|
|
100
|
+
semantic_config: SemanticConfig
|
|
101
|
+
coarse_acoustics_config: CoarseAcousticsConfig
|
|
102
|
+
fine_acoustics_config: FineAcousticsConfig
|
|
103
|
+
codec_config: CodecConfig
|
|
104
|
+
block_size: int = 1024
|
|
105
|
+
input_vocab_size: int = 10_048
|
|
106
|
+
output_vocab_size: int = 10_048
|
|
107
|
+
n_layer: int = 12
|
|
108
|
+
n_head: int = 12
|
|
109
|
+
n_embd: int = 768
|
|
110
|
+
dropout: float = 0.0
|
|
111
|
+
bias: bool = False
|
|
112
|
+
n_codes_total: Optional[int] = None
|
|
113
|
+
n_codes_given: Optional[int] = None
|
|
114
|
+
model_size: str = "base"
|
|
115
|
+
model_type: str = "bark"
|
|
116
|
+
initializer_range: float = 0.02
|
|
117
|
+
codec_path: str = "mlx-community/encodec-24khz-float32"
|
|
118
|
+
sample_rate: int = 24000
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class LayerNorm(nn.Module):
|
|
122
|
+
def __init__(self, dims: int, eps: float = 1e-5, bias: bool = True):
|
|
123
|
+
super().__init__()
|
|
124
|
+
self.bias = mx.zeros((dims,)) if bias else None
|
|
125
|
+
self.weight = mx.ones((dims,))
|
|
126
|
+
self.dims = dims
|
|
127
|
+
self.eps = eps
|
|
128
|
+
|
|
129
|
+
def __call__(self, x):
|
|
130
|
+
mean = mx.mean(x, axis=-1, keepdims=True)
|
|
131
|
+
var = mx.var(x, axis=-1, keepdims=True)
|
|
132
|
+
x = (x - mean) * mx.rsqrt(var + self.eps)
|
|
133
|
+
if self.bias is not None:
|
|
134
|
+
x = x * self.weight + self.bias
|
|
135
|
+
else:
|
|
136
|
+
x = x * self.weight
|
|
137
|
+
return x
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class CausalSelfAttention(nn.Module):
|
|
141
|
+
def __init__(
|
|
142
|
+
self, args: Union[SemanticConfig, CoarseAcousticsConfig, FineAcousticsConfig]
|
|
143
|
+
):
|
|
144
|
+
super().__init__()
|
|
145
|
+
self.att_proj = nn.Linear(args.n_embd, 3 * args.n_embd, bias=args.bias)
|
|
146
|
+
self.out_proj = nn.Linear(args.n_embd, args.n_embd, bias=args.bias)
|
|
147
|
+
self.attn_dropout = nn.Dropout(args.dropout)
|
|
148
|
+
self.resid_dropout = nn.Dropout(args.dropout)
|
|
149
|
+
self.n_head = args.n_head
|
|
150
|
+
self.n_embd = args.n_embd
|
|
151
|
+
self.dropout = args.dropout
|
|
152
|
+
self.bias = (
|
|
153
|
+
mx.tril(mx.ones([args.block_size, args.block_size]))
|
|
154
|
+
.reshape(1, 1, args.block_size, args.block_size)
|
|
155
|
+
.astype(mx.float32)
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
def __call__(self, x, past_kv=None, use_cache=False):
|
|
159
|
+
B, T, C = x.shape
|
|
160
|
+
query, key, value = mx.split(self.att_proj(x), 3, axis=2)
|
|
161
|
+
key = key.reshape(B, T, self.n_head, C // self.n_head).transpose(0, 2, 1, 3)
|
|
162
|
+
query = query.reshape(B, T, self.n_head, C // self.n_head).transpose(0, 2, 1, 3)
|
|
163
|
+
value = value.reshape(B, T, self.n_head, C // self.n_head).transpose(0, 2, 1, 3)
|
|
164
|
+
if past_kv is not None:
|
|
165
|
+
past_key, past_value = past_kv
|
|
166
|
+
key = mx.concatenate([past_key, key], axis=-2)
|
|
167
|
+
value = mx.concatenate([past_value, value], axis=-2)
|
|
168
|
+
|
|
169
|
+
FULL_T = key.shape[-2]
|
|
170
|
+
if use_cache is True:
|
|
171
|
+
present = (key, value)
|
|
172
|
+
else:
|
|
173
|
+
present = None
|
|
174
|
+
|
|
175
|
+
y = mx.fast.scaled_dot_product_attention(
|
|
176
|
+
query,
|
|
177
|
+
key,
|
|
178
|
+
value,
|
|
179
|
+
scale=1.0 / math.sqrt(key.shape[3]),
|
|
180
|
+
mask=self.bias[:, :, FULL_T - T : FULL_T, :FULL_T],
|
|
181
|
+
)
|
|
182
|
+
y = self.attn_dropout(y)
|
|
183
|
+
y = y.transpose(0, 2, 1, 3).reshape(B, T, C)
|
|
184
|
+
y = self.resid_dropout(self.out_proj(y))
|
|
185
|
+
return (y, present)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
class NonCausalSelfAttention(nn.Module):
|
|
189
|
+
def __init__(
|
|
190
|
+
self, args: Union[SemanticConfig, CoarseAcousticsConfig, FineAcousticsConfig]
|
|
191
|
+
):
|
|
192
|
+
super().__init__()
|
|
193
|
+
self.att_proj = nn.Linear(args.n_embd, 3 * args.n_embd, bias=args.bias)
|
|
194
|
+
self.out_proj = nn.Linear(args.n_embd, args.n_embd, bias=args.bias)
|
|
195
|
+
self.attn_dropout = nn.Dropout(args.dropout)
|
|
196
|
+
self.resid_dropout = nn.Dropout(args.dropout)
|
|
197
|
+
self.n_head = args.n_head
|
|
198
|
+
self.n_embd = args.n_embd
|
|
199
|
+
self.dropout = args.dropout
|
|
200
|
+
|
|
201
|
+
def __call__(self, x):
|
|
202
|
+
B, T, C = x.shape
|
|
203
|
+
query, key, value = mx.split(self.att_proj(x), 3, axis=2)
|
|
204
|
+
key = key.reshape(B, T, self.n_head, C // self.n_head).transpose(0, 2, 1, 3)
|
|
205
|
+
query = query.reshape(B, T, self.n_head, C // self.n_head).transpose(0, 2, 1, 3)
|
|
206
|
+
value = value.reshape(B, T, self.n_head, C // self.n_head).transpose(0, 2, 1, 3)
|
|
207
|
+
|
|
208
|
+
y = mx.fast.scaled_dot_product_attention(
|
|
209
|
+
query, key, value, scale=1.0 / math.sqrt(key.shape[3])
|
|
210
|
+
)
|
|
211
|
+
y = self.attn_dropout(y)
|
|
212
|
+
y = y.transpose(0, 2, 1, 3).reshape(B, T, C)
|
|
213
|
+
y = self.resid_dropout(self.out_proj(y))
|
|
214
|
+
return y
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
class MLP(nn.Module):
|
|
218
|
+
def __init__(
|
|
219
|
+
self, args: Union[SemanticConfig, CoarseAcousticsConfig, FineAcousticsConfig]
|
|
220
|
+
):
|
|
221
|
+
super().__init__()
|
|
222
|
+
|
|
223
|
+
self.in_proj = nn.Linear(args.n_embd, 4 * args.n_embd, bias=False)
|
|
224
|
+
self.out_proj = nn.Linear(4 * args.n_embd, args.n_embd, bias=False)
|
|
225
|
+
self.gelu = nn.GELU()
|
|
226
|
+
self.dropout = nn.Dropout(args.dropout)
|
|
227
|
+
|
|
228
|
+
def __call__(self, x: mx.array) -> mx.array:
|
|
229
|
+
x = self.in_proj(x)
|
|
230
|
+
x = self.gelu(x)
|
|
231
|
+
x = self.out_proj(x)
|
|
232
|
+
x = self.dropout(x)
|
|
233
|
+
return x
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
class Block(nn.Module):
|
|
237
|
+
def __init__(
|
|
238
|
+
self, args: Union[SemanticConfig, CoarseAcousticsConfig], layer_idx: int = 0
|
|
239
|
+
):
|
|
240
|
+
super().__init__()
|
|
241
|
+
self.args = args
|
|
242
|
+
self.layernorm_1 = LayerNorm(args.n_embd, bias=False)
|
|
243
|
+
self.attn = CausalSelfAttention(args)
|
|
244
|
+
self.layernorm_2 = LayerNorm(args.n_embd, bias=False)
|
|
245
|
+
self.mlp = MLP(args)
|
|
246
|
+
self.layer_idx = layer_idx
|
|
247
|
+
|
|
248
|
+
def __call__(self, x: mx.array, past_kv=None, use_cache=False):
|
|
249
|
+
attn_output, prev_kvs = self.attn(
|
|
250
|
+
self.layernorm_1(x), past_kv=past_kv, use_cache=use_cache
|
|
251
|
+
)
|
|
252
|
+
x = x + attn_output
|
|
253
|
+
x = x + self.mlp(self.layernorm_2(x))
|
|
254
|
+
return (x, prev_kvs)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
class FineBlock(nn.Module):
|
|
258
|
+
def __init__(self, args: FineAcousticsConfig):
|
|
259
|
+
super().__init__()
|
|
260
|
+
self.args = args
|
|
261
|
+
self.layernorm_1 = nn.LayerNorm(args.n_embd)
|
|
262
|
+
self.attn = NonCausalSelfAttention(args)
|
|
263
|
+
self.layernorm_2 = nn.LayerNorm(args.n_embd)
|
|
264
|
+
self.mlp = MLP(args)
|
|
265
|
+
|
|
266
|
+
def __call__(self, x: mx.array):
|
|
267
|
+
x = x + self.attn(self.layernorm_1(x))
|
|
268
|
+
x = x + self.mlp(self.layernorm_2(x))
|
|
269
|
+
return x
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
class GPT(nn.Module):
|
|
273
|
+
def __init__(self, args: Union[SemanticConfig, CoarseAcousticsConfig]):
|
|
274
|
+
super().__init__()
|
|
275
|
+
self.args = args
|
|
276
|
+
self.input_embeds_layer = nn.Embedding(args.input_vocab_size, args.n_embd)
|
|
277
|
+
self.position_embeds_layer = nn.Embedding(args.block_size, args.n_embd)
|
|
278
|
+
self.drop = nn.Dropout(args.dropout)
|
|
279
|
+
self.layers = [Block(args=args) for _ in range(args.n_layer)]
|
|
280
|
+
self.layernorm_final = LayerNorm(args.n_embd, bias=False)
|
|
281
|
+
self.lm_head = nn.Linear(args.n_embd, args.output_vocab_size, bias=False)
|
|
282
|
+
|
|
283
|
+
def __call__(
|
|
284
|
+
self,
|
|
285
|
+
x: mx.array,
|
|
286
|
+
merge_context: bool = False,
|
|
287
|
+
past_kv: mx.array = None,
|
|
288
|
+
position_ids: mx.array = None,
|
|
289
|
+
use_cache: bool = False,
|
|
290
|
+
) -> mx.array:
|
|
291
|
+
b, t = x.shape
|
|
292
|
+
|
|
293
|
+
if past_kv is not None:
|
|
294
|
+
assert t == 1
|
|
295
|
+
tok_emb = self.input_embeds_layer(x)
|
|
296
|
+
else:
|
|
297
|
+
if merge_context:
|
|
298
|
+
assert x.shape[1] >= 256 + 256 + 1
|
|
299
|
+
t = x.shape[1] - 256
|
|
300
|
+
tok_emb = mx.concatenate(
|
|
301
|
+
[
|
|
302
|
+
self.input_embeds_layer(x[:, :256])
|
|
303
|
+
+ self.input_embeds_layer(x[:, 256 : 256 + 256]),
|
|
304
|
+
self.input_embeds_layer(x[:, 256 + 256 :]),
|
|
305
|
+
],
|
|
306
|
+
axis=1,
|
|
307
|
+
)
|
|
308
|
+
else:
|
|
309
|
+
tok_emb = self.input_embeds_layer(x)
|
|
310
|
+
|
|
311
|
+
# past length
|
|
312
|
+
if past_kv is None:
|
|
313
|
+
past_length = 0
|
|
314
|
+
past_kv = tuple([None] * len(self.layers))
|
|
315
|
+
else:
|
|
316
|
+
past_length = past_kv[0][0].shape[-2]
|
|
317
|
+
|
|
318
|
+
if position_ids is None:
|
|
319
|
+
position_ids = mx.arange(past_length, t + past_length)
|
|
320
|
+
position_ids = position_ids.reshape(1, -1) # shape (1, t)
|
|
321
|
+
|
|
322
|
+
pos_emb = self.position_embeds_layer(
|
|
323
|
+
position_ids
|
|
324
|
+
) # position embeddings of shape (1, t, n_embd)
|
|
325
|
+
x = self.drop(tok_emb + pos_emb)
|
|
326
|
+
|
|
327
|
+
new_kv = () if use_cache else None
|
|
328
|
+
|
|
329
|
+
for i, (block, past_layer_kv) in enumerate(zip(self.layers, past_kv)):
|
|
330
|
+
x, kv = block(x, past_kv=past_layer_kv, use_cache=use_cache)
|
|
331
|
+
|
|
332
|
+
if use_cache:
|
|
333
|
+
new_kv = new_kv + (kv,)
|
|
334
|
+
|
|
335
|
+
x = self.layernorm_final(x)
|
|
336
|
+
|
|
337
|
+
logits = self.lm_head(
|
|
338
|
+
x[:, -1:, :]
|
|
339
|
+
) # note: using list [-1] to preserve the time dim
|
|
340
|
+
|
|
341
|
+
return (logits, new_kv)
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
class FineGPT(nn.Module):
|
|
345
|
+
def __init__(self, args: FineAcousticsConfig):
|
|
346
|
+
super().__init__()
|
|
347
|
+
self.args = args
|
|
348
|
+
self.n_codes_total = args.n_codes_total
|
|
349
|
+
self.input_embeds_layers = [
|
|
350
|
+
nn.Embedding(args.input_vocab_size, args.n_embd)
|
|
351
|
+
for _ in range(args.n_codes_total)
|
|
352
|
+
]
|
|
353
|
+
self.position_embeds_layer = nn.Embedding(args.block_size, args.n_embd)
|
|
354
|
+
self.drop = nn.Dropout(args.dropout)
|
|
355
|
+
self.layers = [FineBlock(args=args) for _ in range(args.n_layer)]
|
|
356
|
+
self.layernorm_final = nn.LayerNorm(args.n_embd)
|
|
357
|
+
|
|
358
|
+
self.lm_heads = [
|
|
359
|
+
nn.Linear(args.n_embd, args.output_vocab_size, bias=False)
|
|
360
|
+
for _ in range(args.n_codes_given, args.n_codes_total)
|
|
361
|
+
]
|
|
362
|
+
for i in range(self.n_codes_total - args.n_codes_given):
|
|
363
|
+
self.input_embeds_layers[i + 1].weight = self.lm_heads[i].weight
|
|
364
|
+
|
|
365
|
+
def __call__(self, pred_idx: mx.array, idx: mx.array) -> mx.array:
|
|
366
|
+
b, t, codes = idx.shape
|
|
367
|
+
assert (
|
|
368
|
+
t <= self.args.block_size
|
|
369
|
+
), f"Cannot forward sequence of length {t}, block size is only {self.config.block_size}"
|
|
370
|
+
assert pred_idx > 0, "cannot predict 0th codebook"
|
|
371
|
+
assert codes == self.n_codes_total, (b, t, codes)
|
|
372
|
+
pos = mx.arange(0, t).astype(mx.int64).reshape(1, t) # shape (1, t)
|
|
373
|
+
tok_embs = [
|
|
374
|
+
self.input_embeds_layers[i](idx[:, :, i].astype(mx.int32)).reshape(
|
|
375
|
+
b, t, -1, 1
|
|
376
|
+
)
|
|
377
|
+
for i in range(self.n_codes_total)
|
|
378
|
+
] # token embeddings of shape (b, t, n_embd)
|
|
379
|
+
tok_emb = mx.concatenate(tok_embs, axis=-1)
|
|
380
|
+
pos_emb = self.position_embeds_layer(
|
|
381
|
+
pos
|
|
382
|
+
) # position embeddings of shape (1, t, n_embd)
|
|
383
|
+
x = tok_emb[:, :, :, : pred_idx + 1].sum(axis=-1)
|
|
384
|
+
x = self.drop(x + pos_emb)
|
|
385
|
+
for block in self.layers:
|
|
386
|
+
x = block(x)
|
|
387
|
+
x = self.layernorm_final(x)
|
|
388
|
+
|
|
389
|
+
logits = self.lm_heads[pred_idx - self.args.n_codes_given](x)
|
|
390
|
+
return logits
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
class Model(nn.Module):
|
|
394
|
+
def __init__(self, config: ModelConfig):
|
|
395
|
+
super().__init__()
|
|
396
|
+
self.config = config
|
|
397
|
+
|
|
398
|
+
# Convert config dictionaries to proper configuration objects if needed
|
|
399
|
+
if isinstance(config.semantic_config, dict):
|
|
400
|
+
filtered_config = filter_dataclass_fields(
|
|
401
|
+
config.semantic_config, SemanticConfig
|
|
402
|
+
)
|
|
403
|
+
semantic_config = SemanticConfig(**filtered_config)
|
|
404
|
+
else:
|
|
405
|
+
semantic_config = config.semantic_config
|
|
406
|
+
|
|
407
|
+
if isinstance(config.coarse_acoustics_config, dict):
|
|
408
|
+
filtered_config = filter_dataclass_fields(
|
|
409
|
+
config.coarse_acoustics_config, CoarseAcousticsConfig
|
|
410
|
+
)
|
|
411
|
+
coarse_config = CoarseAcousticsConfig(**filtered_config)
|
|
412
|
+
else:
|
|
413
|
+
coarse_config = config.coarse_acoustics_config
|
|
414
|
+
|
|
415
|
+
if isinstance(config.fine_acoustics_config, dict):
|
|
416
|
+
filtered_config = filter_dataclass_fields(
|
|
417
|
+
config.fine_acoustics_config, FineAcousticsConfig
|
|
418
|
+
)
|
|
419
|
+
fine_config = FineAcousticsConfig(**filtered_config)
|
|
420
|
+
else:
|
|
421
|
+
fine_config = config.fine_acoustics_config
|
|
422
|
+
|
|
423
|
+
self.semantic = GPT(semantic_config)
|
|
424
|
+
self.fine_acoustics = FineGPT(fine_config)
|
|
425
|
+
self.coarse_acoustics = GPT(coarse_config)
|
|
426
|
+
|
|
427
|
+
self.tokenizer = BertTokenizer.from_pretrained("bert-base-multilingual-cased")
|
|
428
|
+
|
|
429
|
+
def sanitize(self, weights):
|
|
430
|
+
|
|
431
|
+
sanitized_weights = {}
|
|
432
|
+
for key, value in weights.items():
|
|
433
|
+
# there's no _orig_mod.transformer
|
|
434
|
+
if "_orig_mod.transformer." in key:
|
|
435
|
+
key = key.replace("_orig_mod.transformer.", "")
|
|
436
|
+
# transformer block mapping
|
|
437
|
+
if "h" in key:
|
|
438
|
+
layer_count = 24 if self.config.model_size == "large" else 12
|
|
439
|
+
for i in range(layer_count):
|
|
440
|
+
prefix = f"h.{i}."
|
|
441
|
+
key = key.replace(prefix, f"layers.{i}.")
|
|
442
|
+
|
|
443
|
+
# lm_head
|
|
444
|
+
if "lm_head" in key:
|
|
445
|
+
key = key.replace("_orig_mod.", "")
|
|
446
|
+
|
|
447
|
+
if "codec" in key:
|
|
448
|
+
pass
|
|
449
|
+
else:
|
|
450
|
+
sanitized_weights[key] = value
|
|
451
|
+
|
|
452
|
+
return sanitized_weights
|
|
453
|
+
|
|
454
|
+
@property
|
|
455
|
+
def sample_rate(self):
|
|
456
|
+
return self.config.sample_rate
|
|
457
|
+
|
|
458
|
+
def generate(self, text: str, voice: str = None, **kwargs):
|
|
459
|
+
pipeline = Pipeline(
|
|
460
|
+
model=self,
|
|
461
|
+
tokenizer=self.tokenizer,
|
|
462
|
+
config=self.config,
|
|
463
|
+
)
|
|
464
|
+
|
|
465
|
+
# Track overall generation time
|
|
466
|
+
start_time = time.time()
|
|
467
|
+
|
|
468
|
+
for segment_idx, (audio, tokens) in enumerate(
|
|
469
|
+
pipeline(text, voice=voice, use_kv_caching=True, **kwargs)
|
|
470
|
+
):
|
|
471
|
+
# Track per-segment generation time
|
|
472
|
+
segment_time = time.time() - start_time
|
|
473
|
+
|
|
474
|
+
samples = audio.shape[0] if audio is not None else 0
|
|
475
|
+
assert samples > 0, "No audio generated"
|
|
476
|
+
|
|
477
|
+
# Calculate token count
|
|
478
|
+
token_count = len(tokens) if tokens is not None else 0
|
|
479
|
+
|
|
480
|
+
# Calculate audio duration in seconds
|
|
481
|
+
sample_rate = self.config.sample_rate
|
|
482
|
+
audio_duration_seconds = samples / sample_rate * audio.shape[1]
|
|
483
|
+
|
|
484
|
+
# Calculate milliseconds per sample
|
|
485
|
+
ms_per_sample = (
|
|
486
|
+
1000 / sample_rate
|
|
487
|
+
) # This gives 0.0417 ms per sample at 24kHz
|
|
488
|
+
|
|
489
|
+
# Calculate real-time factor (RTF)
|
|
490
|
+
rtf = (
|
|
491
|
+
segment_time / audio_duration_seconds
|
|
492
|
+
if audio_duration_seconds > 0
|
|
493
|
+
else 0
|
|
494
|
+
)
|
|
495
|
+
|
|
496
|
+
# Format duration as HH:MM:SS.mmm
|
|
497
|
+
duration_mins = int(audio_duration_seconds // 60)
|
|
498
|
+
duration_secs = int(audio_duration_seconds % 60)
|
|
499
|
+
duration_ms = int((audio_duration_seconds % 1) * 1000)
|
|
500
|
+
duration_hours = int(audio_duration_seconds // 3600)
|
|
501
|
+
duration_str = f"{duration_hours:02d}:{duration_mins:02d}:{duration_secs:02d}.{duration_ms:03d}"
|
|
502
|
+
|
|
503
|
+
yield GenerationResult(
|
|
504
|
+
audio=audio[0],
|
|
505
|
+
samples=samples,
|
|
506
|
+
sample_rate=sample_rate,
|
|
507
|
+
segment_idx=segment_idx,
|
|
508
|
+
token_count=token_count,
|
|
509
|
+
audio_duration=duration_str,
|
|
510
|
+
real_time_factor=round(rtf, 2),
|
|
511
|
+
prompt={
|
|
512
|
+
"tokens": token_count,
|
|
513
|
+
"tokens-per-sec": (
|
|
514
|
+
round(token_count / segment_time, 2) if segment_time > 0 else 0
|
|
515
|
+
),
|
|
516
|
+
},
|
|
517
|
+
audio_samples={
|
|
518
|
+
"samples": samples,
|
|
519
|
+
"samples-per-sec": (
|
|
520
|
+
round(samples / segment_time, 2) if segment_time > 0 else 0
|
|
521
|
+
),
|
|
522
|
+
},
|
|
523
|
+
processing_time_seconds=segment_time,
|
|
524
|
+
peak_memory_usage=mx.get_peak_memory() / 1e9,
|
|
525
|
+
)
|
|
526
|
+
|
|
527
|
+
# Clear cache after each segment to avoid memory leaks
|
|
528
|
+
mx.clear_cache()
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import mlx.core as mx
|
|
2
|
+
import mlx.nn as nn
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# Loads to torch Encodec model
|
|
6
|
+
def codec_decode(codec: nn.Module, fine_tokens: mx.array):
|
|
7
|
+
arr = fine_tokens.astype(mx.int32)[None]
|
|
8
|
+
emb = codec.quantizer.decode(arr)
|
|
9
|
+
out = codec.decoder(emb).astype(mx.float32)
|
|
10
|
+
audio_arr = mx.squeeze(out, -1)
|
|
11
|
+
del arr, emb, out
|
|
12
|
+
return audio_arr
|