cohere-transcribe 0.1.0
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +21 -0
- data/LICENSE.txt +201 -0
- data/NOTICE +5 -0
- data/README.md +265 -0
- data/THIRD_PARTY_NOTICES.md +67 -0
- data/exe/cohere-transcribe +8 -0
- data/exe/cohere-transcribe-doctor +8 -0
- data/ext/cohere_transcribe_native/CMakeLists.txt +262 -0
- data/ext/cohere_transcribe_native/README.md +26 -0
- data/ext/cohere_transcribe_native/audio_abi.cpp +1416 -0
- data/ext/cohere_transcribe_native/audio_exports.macos +5 -0
- data/ext/cohere_transcribe_native/audio_exports.map +10 -0
- data/ext/cohere_transcribe_native/cohere_abi.cpp +1209 -0
- data/ext/cohere_transcribe_native/exports.macos +40 -0
- data/ext/cohere_transcribe_native/exports.map +45 -0
- data/ext/cohere_transcribe_native/extconf.rb +89 -0
- data/ext/cohere_transcribe_native/test/abi_smoke.rb +232 -0
- data/ext/cohere_transcribe_native/test/audio_matrix_smoke.cpp +121 -0
- data/ext/cohere_transcribe_native/test/audio_reliability_smoke.cpp +198 -0
- data/ext/cohere_transcribe_native/test/native_abi_reliability_smoke.cpp +186 -0
- data/ext/cohere_transcribe_native/test/native_batch_projection_probe.rb +81 -0
- data/ext/cohere_transcribe_native/test/native_cancellation_smoke.cpp +194 -0
- data/lib/cohere/transcribe/alignment/ATTRIBUTION.md +23 -0
- data/lib/cohere/transcribe/alignment/LICENSE.ctc-forced-aligner +407 -0
- data/lib/cohere/transcribe/alignment/LICENSE.torchaudio +25 -0
- data/lib/cohere/transcribe/alignment/LICENSE.uroman +26 -0
- data/lib/cohere/transcribe/alignment/aligner.rb +476 -0
- data/lib/cohere/transcribe/alignment/ctc.rb +224 -0
- data/lib/cohere/transcribe/alignment/text.rb +237 -0
- data/lib/cohere/transcribe/alignment/uroman_data.rb +4950 -0
- data/lib/cohere/transcribe/api.rb +173 -0
- data/lib/cohere/transcribe/asr/batching.rb +472 -0
- data/lib/cohere/transcribe/asr/failure_policy.rb +112 -0
- data/lib/cohere/transcribe/asr/native.rb +676 -0
- data/lib/cohere/transcribe/audio/ATTRIBUTION.md +8 -0
- data/lib/cohere/transcribe/audio/LICENSE.auditok +21 -0
- data/lib/cohere/transcribe/audio/decoder.rb +315 -0
- data/lib/cohere/transcribe/audio/ffmpeg_native.rb +248 -0
- data/lib/cohere/transcribe/audio/segmentation.rb +260 -0
- data/lib/cohere/transcribe/cli.rb +727 -0
- data/lib/cohere/transcribe/configuration.rb +282 -0
- data/lib/cohere/transcribe/constants.rb +14 -0
- data/lib/cohere/transcribe/dense_converter.rb +548 -0
- data/lib/cohere/transcribe/doctor.rb +576 -0
- data/lib/cohere/transcribe/errors.rb +57 -0
- data/lib/cohere/transcribe/gguf_writer.rb +268 -0
- data/lib/cohere/transcribe/hub.rb +436 -0
- data/lib/cohere/transcribe/input.rb +110 -0
- data/lib/cohere/transcribe/licenses/crispasr.txt +21 -0
- data/lib/cohere/transcribe/loader.rb +128 -0
- data/lib/cohere/transcribe/model_identity.rb +440 -0
- data/lib/cohere/transcribe/output/publication.rb +1118 -0
- data/lib/cohere/transcribe/output/rendering.rb +105 -0
- data/lib/cohere/transcribe/output/timing.rb +86 -0
- data/lib/cohere/transcribe/python_text.rb +70 -0
- data/lib/cohere/transcribe/pytorch_checkpoint.rb +1180 -0
- data/lib/cohere/transcribe/runtime/engine.rb +1676 -0
- data/lib/cohere/transcribe/runtime/model_provider.rb +390 -0
- data/lib/cohere/transcribe/runtime/precision.rb +57 -0
- data/lib/cohere/transcribe/runtime/preparation.rb +215 -0
- data/lib/cohere/transcribe/runtime/resources.rb +165 -0
- data/lib/cohere/transcribe/runtime/word_pipeline.rb +364 -0
- data/lib/cohere/transcribe/safetensors.rb +579 -0
- data/lib/cohere/transcribe/state/checkpoint.rb +224 -0
- data/lib/cohere/transcribe/state/contracts.rb +141 -0
- data/lib/cohere/transcribe/state/io.rb +727 -0
- data/lib/cohere/transcribe/state/locking.rb +211 -0
- data/lib/cohere/transcribe/state/manifest.rb +155 -0
- data/lib/cohere/transcribe/state.rb +7 -0
- data/lib/cohere/transcribe/types.rb +535 -0
- data/lib/cohere/transcribe/vad/ATTRIBUTION.md +14 -0
- data/lib/cohere/transcribe/vad/LICENSE.faster-whisper +21 -0
- data/lib/cohere/transcribe/vad/LICENSE.silero-vad +21 -0
- data/lib/cohere/transcribe/vad/silero.rb +344 -0
- data/lib/cohere/transcribe/vad/silero_vad_v6.onnx +0 -0
- data/lib/cohere/transcribe/vad/timestamps.rb +219 -0
- data/lib/cohere/transcribe/version.rb +7 -0
- data/lib/cohere/transcribe.rb +26 -0
- data/sig/cohere/transcribe.rbs +250 -0
- data/vendor/crispasr/AUTHORS +510 -0
- data/vendor/crispasr/LICENSE +21 -0
- data/vendor/crispasr/UPSTREAM.md +9 -0
- data/vendor/crispasr/VERSION +1 -0
- data/vendor/crispasr/ggml/AUTHORS +335 -0
- data/vendor/crispasr/ggml/CMakeLists.txt +512 -0
- data/vendor/crispasr/ggml/LICENSE +21 -0
- data/vendor/crispasr/ggml/README.md +49 -0
- data/vendor/crispasr/ggml/cmake/FindNCCL.cmake +36 -0
- data/vendor/crispasr/ggml/cmake/GitVars.cmake +22 -0
- data/vendor/crispasr/ggml/cmake/common.cmake +50 -0
- data/vendor/crispasr/ggml/cmake/ggml-config.cmake.in +191 -0
- data/vendor/crispasr/ggml/ggml.pc.in +10 -0
- data/vendor/crispasr/ggml/include/ggml-alloc.h +85 -0
- data/vendor/crispasr/ggml/include/ggml-backend.h +431 -0
- data/vendor/crispasr/ggml/include/ggml-blas.h +25 -0
- data/vendor/crispasr/ggml/include/ggml-cann.h +123 -0
- data/vendor/crispasr/ggml/include/ggml-cpp.h +39 -0
- data/vendor/crispasr/ggml/include/ggml-cpu.h +151 -0
- data/vendor/crispasr/ggml/include/ggml-cuda.h +50 -0
- data/vendor/crispasr/ggml/include/ggml-hexagon.h +19 -0
- data/vendor/crispasr/ggml/include/ggml-metal.h +61 -0
- data/vendor/crispasr/ggml/include/ggml-opencl.h +26 -0
- data/vendor/crispasr/ggml/include/ggml-openvino.h +37 -0
- data/vendor/crispasr/ggml/include/ggml-opt.h +256 -0
- data/vendor/crispasr/ggml/include/ggml-rpc.h +35 -0
- data/vendor/crispasr/ggml/include/ggml-sycl.h +49 -0
- data/vendor/crispasr/ggml/include/ggml-virtgpu.h +14 -0
- data/vendor/crispasr/ggml/include/ggml-vulkan.h +29 -0
- data/vendor/crispasr/ggml/include/ggml-webgpu.h +19 -0
- data/vendor/crispasr/ggml/include/ggml-zdnn.h +17 -0
- data/vendor/crispasr/ggml/include/ggml-zendnn.h +22 -0
- data/vendor/crispasr/ggml/include/ggml.h +2887 -0
- data/vendor/crispasr/ggml/include/gguf.h +204 -0
- data/vendor/crispasr/ggml/src/CMakeLists.txt +493 -0
- data/vendor/crispasr/ggml/src/ggml-alloc.c +1323 -0
- data/vendor/crispasr/ggml/src/ggml-backend-dl.cpp +48 -0
- data/vendor/crispasr/ggml/src/ggml-backend-dl.h +44 -0
- data/vendor/crispasr/ggml/src/ggml-backend-impl.h +275 -0
- data/vendor/crispasr/ggml/src/ggml-backend-meta.cpp +2145 -0
- data/vendor/crispasr/ggml/src/ggml-backend-reg.cpp +586 -0
- data/vendor/crispasr/ggml/src/ggml-backend.cpp +2437 -0
- data/vendor/crispasr/ggml/src/ggml-common.h +1900 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/CMakeLists.txt +718 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/amx.cpp +249 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/amx.h +8 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/common.h +115 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/mmq.cpp +2512 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/mmq.h +10 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/arm/cpu-feats.cpp +98 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/arm/quants.c +4244 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/arm/repack.cpp +5156 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/loongarch/quants.c +2158 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/powerpc/cpu-feats.cpp +82 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/powerpc/quants.c +2304 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/riscv/cpu-feats.cpp +38 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/riscv/quants.c +4455 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/riscv/repack.cpp +1703 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/s390/cpu-feats.cpp +50 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/s390/quants.c +1465 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/wasm/quants.c +1220 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/x86/cpu-feats.cpp +327 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/x86/quants.c +3970 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/x86/repack.cpp +6407 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch-fallback.h +349 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/binary-ops.cpp +154 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/binary-ops.h +16 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/cmake/FindSIMD.cmake +100 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/common.h +95 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ggml-cpu-impl.h +539 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ggml-cpu.c +3791 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ggml-cpu.cpp +703 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/hbm.cpp +55 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/hbm.h +8 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kernels.cpp +939 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kernels.h +90 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kleidiai.cpp +1513 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kleidiai.h +17 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/llamafile/sgemm.cpp +4051 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/llamafile/sgemm.h +25 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ops.cpp +11662 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ops.h +121 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/quants.c +1288 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/quants.h +103 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/repack.cpp +4836 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/repack.h +245 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/simd-gemm.h +226 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/simd-mappings.h +1329 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime.cpp +1025 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime.h +13 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime1_kernels.cpp +3196 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime_kernels.h +26 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/traits.cpp +36 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/traits.h +38 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/unary-ops.cpp +336 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/unary-ops.h +35 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/vec.cpp +681 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/vec.h +1606 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/CMakeLists.txt +272 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/acc.cu +61 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/acc.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/add-id.cu +58 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/add-id.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/arange.cu +34 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/arange.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/argmax.cu +91 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/argmax.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/argsort.cu +265 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/argsort.cuh +19 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/binbcast.cu +534 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/binbcast.cuh +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/clamp.cu +45 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/clamp.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/col2im-1d.cu +81 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/col2im-1d.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/common.cuh +1489 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/concat.cu +204 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/concat.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv-transpose-1d.cu +97 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv-transpose-1d.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-dw.cu +161 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-dw.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-transpose.cu +115 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-transpose.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d.cu +166 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/convert.cu +892 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/convert.cuh +66 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/count-equal.cu +64 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/count-equal.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cp-async.cuh +57 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cpy-utils.cuh +217 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cpy.cu +581 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cpy.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cross-entropy-loss.cu +177 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cross-entropy-loss.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cumsum.cu +307 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cumsum.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/dequantize.cuh +99 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/diag.cu +77 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/diag.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/diagmask.cu +40 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/diagmask.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-common.cuh +1212 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-mma-f16.cuh +1860 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-tile.cu +57 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-tile.cuh +1309 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-vec.cuh +600 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-wmma-f16.cu +696 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-wmma-f16.cuh +51 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn.cu +620 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fill.cu +37 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fill.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/gated_delta_net.cu +273 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/gated_delta_net.cuh +4 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/getrows.cu +332 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/getrows.cuh +15 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ggml-cuda.cu +5580 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/gla.cu +93 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/gla.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/im2col.cu +274 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/im2col.cuh +6 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mean.cu +75 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mean.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mma.cuh +1333 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmf.cu +191 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmf.cuh +908 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmid.cu +164 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmid.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmq.cu +372 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmq.cuh +4175 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmvf.cu +862 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmvf.cuh +14 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmvq.cu +1161 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmvq.cuh +16 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/norm.cu +756 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/norm.cuh +20 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-adamw.cu +78 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-adamw.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-sgd.cu +49 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-sgd.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/out-prod.cu +68 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/out-prod.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pad.cu +106 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pad.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pad_reflect_1d.cu +91 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pad_reflect_1d.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pool2d.cu +94 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pool2d.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/quantize.cu +443 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/quantize.cuh +41 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/reduce_rows.cuh +39 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/roll.cu +67 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/roll.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/rope.cu +665 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/rope.cuh +9 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/scale.cu +34 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/scale.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/set-rows.cu +330 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/set-rows.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/set.cu +39 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/set.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/softcap.cu +34 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/softcap.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/softmax.cu +472 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/softmax.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/solve_tri.cu +275 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/solve_tri.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ssm-conv.cu +197 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ssm-conv.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ssm-scan.cu +342 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ssm-scan.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/sum.cu +41 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/sum.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/sumrows.cu +43 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/sumrows.cuh +4 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_16.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_32.cu +6 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_8.cu +11 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_1.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_2.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_4.cu +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_16.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_32.cu +6 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_4.cu +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_8.cu +11 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_1.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_2.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_16.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_2.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_4.cu +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_8.cu +11 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_64-ncols2_1.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_1.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_2.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_4.cu +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_8.cu +11 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq112-dv112.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq128-dv128.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq256-dv256.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq320-dv256.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq40-dv40.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq512-dv512.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq576-dv512.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq64-dv64.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq72-dv72.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq80-dv80.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq96-dv96.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_1.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_10.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_11.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_12.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_13.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_14.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_15.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_16.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_2.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_3.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_4.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_5.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_6.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_7.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_8.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_9.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq1_s.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_s.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xs.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xxs.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_s.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_xxs.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_nl.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_xs.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-mxfp4.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-nvfp4.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q1_0.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q2_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q3_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_0.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_1.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_0.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_1.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q6_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q8_0.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/top-k.cu +95 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/top-k.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/topk-moe.cu +415 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/topk-moe.cuh +27 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/tri.cu +136 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/tri.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/tsembd.cu +47 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/tsembd.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/unary.cu +644 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/unary.cuh +116 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/upscale.cu +293 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/upscale.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/vecdotq.cuh +1317 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/vendors/cuda.h +28 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/vendors/hip.h +306 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/vendors/musa.h +148 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/wkv.cu +199 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/wkv.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-impl.h +783 -0
- data/vendor/crispasr/ggml/src/ggml-metal/CMakeLists.txt +124 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-common.cpp +457 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-common.h +52 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-context.h +41 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-context.m +778 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-device.cpp +2117 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-device.h +299 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-device.m +2093 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-impl.h +1267 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-ops.cpp +5023 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-ops.h +111 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal.cpp +954 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal.metal +11756 -0
- data/vendor/crispasr/ggml/src/ggml-opt.cpp +1094 -0
- data/vendor/crispasr/ggml/src/ggml-quants.c +5491 -0
- data/vendor/crispasr/ggml/src/ggml-quants.h +112 -0
- data/vendor/crispasr/ggml/src/ggml-threading.cpp +12 -0
- data/vendor/crispasr/ggml/src/ggml-threading.h +14 -0
- data/vendor/crispasr/ggml/src/ggml.c +7925 -0
- data/vendor/crispasr/ggml/src/ggml.cpp +26 -0
- data/vendor/crispasr/ggml/src/gguf.cpp +1556 -0
- data/vendor/crispasr/src/cohere-arch.h +137 -0
- data/vendor/crispasr/src/cohere.cpp +5642 -0
- data/vendor/crispasr/src/cohere.h +327 -0
- data/vendor/crispasr/src/cohere_batch_planner.h +82 -0
- data/vendor/crispasr/src/cohere_chunking.h +64 -0
- data/vendor/crispasr/src/cohere_decoder_batch_layout.h +60 -0
- data/vendor/crispasr/src/cohere_encoder_padded_layout.h +27 -0
- data/vendor/crispasr/src/cohere_frontend.cpp +189 -0
- data/vendor/crispasr/src/cohere_frontend.h +31 -0
- data/vendor/crispasr/src/cohere_ragged_controller.h +149 -0
- data/vendor/crispasr/src/cohere_token_renderer.h +181 -0
- data/vendor/crispasr/src/core/attention.h +924 -0
- data/vendor/crispasr/src/core/audio_chunking.h +97 -0
- data/vendor/crispasr/src/core/beam_decode.h +486 -0
- data/vendor/crispasr/src/core/cpu_ops.h +135 -0
- data/vendor/crispasr/src/core/gguf_loader.cpp +1021 -0
- data/vendor/crispasr/src/core/gguf_loader.h +216 -0
- data/vendor/crispasr/src/core/gpu_backend_pref.h +119 -0
- data/vendor/crispasr/src/core/mel.cpp +519 -0
- data/vendor/crispasr/src/core/mel.h +265 -0
- data/vendor/crispasr/src/core/ngram_loop_fix.h +173 -0
- data/vendor/crispasr/src/core/repetition_loop_guard.h +54 -0
- data/vendor/crispasr/src/crispasr_imatrix.cpp +255 -0
- data/vendor/crispasr/src/crispasr_imatrix.h +38 -0
- metadata +596 -0
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "digest"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
require "numo/narray"
|
|
6
|
+
|
|
7
|
+
require_relative "../constants"
|
|
8
|
+
require_relative "../errors"
|
|
9
|
+
require_relative "../hub"
|
|
10
|
+
require_relative "../output/timing"
|
|
11
|
+
require_relative "../python_text"
|
|
12
|
+
require_relative "../types"
|
|
13
|
+
require_relative "ctc"
|
|
14
|
+
require_relative "text"
|
|
15
|
+
|
|
16
|
+
module Cohere
|
|
17
|
+
module Transcribe
|
|
18
|
+
module Alignment
|
|
19
|
+
class BackendUnavailable < TranscriptionRuntimeError; end
|
|
20
|
+
|
|
21
|
+
ModelArtifact = Data.define(:filename, :size, :sha256)
|
|
22
|
+
|
|
23
|
+
# Integrity-pinned access to an ONNX export of the exact reference MMS
|
|
24
|
+
# checkpoint. Model weights remain in the standard Hugging Face cache and
|
|
25
|
+
# are never included in the gem or passed through another language.
|
|
26
|
+
class ModelProvider
|
|
27
|
+
REPOSITORY = "onnx-community/mms-300m-1130-forced-aligner-ONNX"
|
|
28
|
+
REVISION = "2100fb247d8e43962eef24491597fbeb8b469531"
|
|
29
|
+
SOURCE_REPOSITORY = "MahmoudAshraf/mms-300m-1130-forced-aligner"
|
|
30
|
+
SOURCE_REVISION = "49402e9577b1158620820667c218cd494cc44486"
|
|
31
|
+
LICENSE = "CC-BY-NC-4.0"
|
|
32
|
+
UTILITY_REPOSITORY = "https://github.com/MahmoudAshraf97/ctc-forced-aligner.git"
|
|
33
|
+
UTILITY_REVISION = "11855d1de76af2b490dd2e8e2db2661805ae90a0"
|
|
34
|
+
UROMAN_COMPATIBILITY_VERSION = "1.3.1.1-compatible-ruby-port"
|
|
35
|
+
ARTIFACTS = {
|
|
36
|
+
"fp32" => ModelArtifact.new(
|
|
37
|
+
filename: "onnx/model.onnx",
|
|
38
|
+
size: 1_262_529_881,
|
|
39
|
+
sha256: "429e5d05c62acc8a9264db874a1b131e359fc626e40c253ac7b1fe52b11149b4"
|
|
40
|
+
),
|
|
41
|
+
"fp16" => ModelArtifact.new(
|
|
42
|
+
filename: "onnx/model_fp16.onnx",
|
|
43
|
+
size: 631_591_191,
|
|
44
|
+
sha256: "e98082b382375f3528ec7514e175b5cd0eb77fcc4d4531a7142b9e45a1ce6deb"
|
|
45
|
+
)
|
|
46
|
+
}.freeze
|
|
47
|
+
|
|
48
|
+
attr_reader :hub
|
|
49
|
+
|
|
50
|
+
def initialize(hub: Hub.new, artifacts: ARTIFACTS)
|
|
51
|
+
@hub = hub
|
|
52
|
+
@artifacts = artifacts
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def fetch(dtype)
|
|
56
|
+
artifact = @artifacts.fetch(dtype) do
|
|
57
|
+
raise ArgumentError, "Unsupported aligner dtype: #{dtype.inspect}"
|
|
58
|
+
end
|
|
59
|
+
path = hub.download(REPOSITORY, artifact.filename, revision: REVISION)
|
|
60
|
+
with_integrity_lock(Pathname("#{path}.integrity.lock")) do |lock|
|
|
61
|
+
lock.flock(File::LOCK_EX)
|
|
62
|
+
return path if valid?(path, artifact)
|
|
63
|
+
|
|
64
|
+
FileUtils.rm_f(path)
|
|
65
|
+
path = hub.download(REPOSITORY, artifact.filename, revision: REVISION)
|
|
66
|
+
unless valid?(path, artifact)
|
|
67
|
+
FileUtils.rm_f(path)
|
|
68
|
+
raise BackendUnavailable,
|
|
69
|
+
"Downloaded aligner #{artifact.filename} failed its pinned size/SHA-256 check"
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
path
|
|
73
|
+
rescue Hub::Error, SystemCallError => e
|
|
74
|
+
raise BackendUnavailable, "Cannot prepare MMS aligner: #{e.message}"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
private
|
|
78
|
+
|
|
79
|
+
def with_integrity_lock(path)
|
|
80
|
+
flags = File::RDWR | File::CREAT
|
|
81
|
+
flags |= File::NOFOLLOW if defined?(File::NOFOLLOW)
|
|
82
|
+
flags |= File::CLOEXEC if defined?(File::CLOEXEC)
|
|
83
|
+
descriptor = ::IO.sysopen(path.to_s, flags, 0o600)
|
|
84
|
+
lock = File.new(descriptor, "r+", autoclose: true)
|
|
85
|
+
descriptor = nil
|
|
86
|
+
opened = lock.stat
|
|
87
|
+
current = path.lstat
|
|
88
|
+
unless opened.file? && !current.symlink? && opened.dev == current.dev && opened.ino == current.ino
|
|
89
|
+
raise BackendUnavailable,
|
|
90
|
+
"Aligner integrity lock changed while it was being opened or is not regular: #{path}"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
yield lock
|
|
94
|
+
rescue Errno::ELOOP, Errno::EISDIR, Errno::ENXIO => e
|
|
95
|
+
raise BackendUnavailable, "Aligner integrity lock is not a regular file: #{path}", cause: e
|
|
96
|
+
ensure
|
|
97
|
+
lock&.close
|
|
98
|
+
::IO.new(descriptor).close if descriptor
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def valid?(path, artifact)
|
|
102
|
+
File.file?(path) && File.size(path) == artifact.size &&
|
|
103
|
+
Digest::SHA256.file(path).hexdigest == artifact.sha256
|
|
104
|
+
rescue SystemCallError
|
|
105
|
+
false
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Lazy ONNX Runtime session with an explicitly reported execution
|
|
110
|
+
# provider. FP16 is admitted only when the CUDA provider is genuinely
|
|
111
|
+
# available; the packaged CPU runtime always uses the full FP32 export.
|
|
112
|
+
class Session
|
|
113
|
+
CPU_PROVIDER = "CPUExecutionProvider"
|
|
114
|
+
CUDA_PROVIDER = "CUDAExecutionProvider"
|
|
115
|
+
SESSION_OPTIONS = {
|
|
116
|
+
graph_optimization_level: :all,
|
|
117
|
+
log_severity_level: 4
|
|
118
|
+
}.freeze
|
|
119
|
+
|
|
120
|
+
attr_reader :dtype, :device, :load_seconds, :provider
|
|
121
|
+
|
|
122
|
+
def initialize(dtype: "fp32", device: "cpu", model_provider: ModelProvider.new,
|
|
123
|
+
session: nil, session_factory: nil, available_providers: nil)
|
|
124
|
+
@dtype = dtype
|
|
125
|
+
@device = device
|
|
126
|
+
@model_provider = model_provider
|
|
127
|
+
@session = session
|
|
128
|
+
@session_factory = session_factory
|
|
129
|
+
@available_providers = available_providers
|
|
130
|
+
@provider = session ? CPU_PROVIDER : nil
|
|
131
|
+
@load_seconds = 0.0
|
|
132
|
+
validate_configuration!
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def run(input_values)
|
|
136
|
+
values = session.run(["logits"], { "input_values" => input_values }, output_type: :numo)
|
|
137
|
+
raise TranscriptionRuntimeError, "MMS ONNX aligner must return one logits tensor" unless values.is_a?(Array) && values.length == 1
|
|
138
|
+
|
|
139
|
+
values.first
|
|
140
|
+
rescue BackendUnavailable, TranscriptionRuntimeError
|
|
141
|
+
raise
|
|
142
|
+
rescue StandardError => e
|
|
143
|
+
raise BackendUnavailable, "MMS ONNX inference failed: #{e.class}: #{e.message}"
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def load!
|
|
147
|
+
session
|
|
148
|
+
self
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def close
|
|
152
|
+
@session.close if @session.respond_to?(:close)
|
|
153
|
+
ensure
|
|
154
|
+
@session = nil
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
private
|
|
158
|
+
|
|
159
|
+
def validate_configuration!
|
|
160
|
+
raise ArgumentError, "aligner dtype must be fp32 or fp16" unless %w[fp32 fp16].include?(dtype)
|
|
161
|
+
return unless dtype == "fp16" && device != "cuda"
|
|
162
|
+
|
|
163
|
+
raise BackendUnavailable, "FP16 word alignment requires a CUDA ONNX Runtime provider"
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def session
|
|
167
|
+
return @session if @session
|
|
168
|
+
|
|
169
|
+
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
170
|
+
path = @model_provider.fetch(dtype)
|
|
171
|
+
providers = available_providers
|
|
172
|
+
@provider = device == "cuda" && providers.include?(CUDA_PROVIDER) ? CUDA_PROVIDER : CPU_PROVIDER
|
|
173
|
+
if dtype == "fp16" && @provider != CUDA_PROVIDER
|
|
174
|
+
raise BackendUnavailable,
|
|
175
|
+
"FP16 word alignment requested, but CUDAExecutionProvider is unavailable " \
|
|
176
|
+
"(available: #{providers.join(", ")})"
|
|
177
|
+
end
|
|
178
|
+
options = SESSION_OPTIONS.merge(providers: [@provider])
|
|
179
|
+
@session = if @session_factory
|
|
180
|
+
@session_factory.call(path.to_s, **options)
|
|
181
|
+
else
|
|
182
|
+
require_onnxruntime!
|
|
183
|
+
OnnxRuntime::InferenceSession.new(path.to_s, **options)
|
|
184
|
+
end
|
|
185
|
+
validate_contract!(@session)
|
|
186
|
+
@session
|
|
187
|
+
ensure
|
|
188
|
+
@load_seconds += Process.clock_gettime(Process::CLOCK_MONOTONIC) - started if started
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def available_providers
|
|
192
|
+
return @available_providers if @available_providers
|
|
193
|
+
|
|
194
|
+
require_onnxruntime!
|
|
195
|
+
@available_providers = OnnxRuntime::InferenceSession.allocate.send(:providers)
|
|
196
|
+
rescue StandardError => e
|
|
197
|
+
raise BackendUnavailable, "Cannot inspect ONNX Runtime providers: #{e.class}: #{e.message}"
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def require_onnxruntime!
|
|
201
|
+
require "onnxruntime"
|
|
202
|
+
library = ENV.fetch("COHERE_TRANSCRIBE_ONNXRUNTIME_LIBRARY", nil)
|
|
203
|
+
OnnxRuntime.ffi_lib = [File.expand_path(library)] if library && OnnxRuntime.autoload?(:FFI)
|
|
204
|
+
rescue LoadError => e
|
|
205
|
+
raise BackendUnavailable, "ONNX Runtime is unavailable: #{e.message}"
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def validate_contract!(candidate)
|
|
209
|
+
return unless candidate.respond_to?(:inputs) && candidate.respond_to?(:outputs)
|
|
210
|
+
|
|
211
|
+
inputs = candidate.inputs
|
|
212
|
+
outputs = candidate.outputs
|
|
213
|
+
valid_input = inputs.length == 1 && inputs.first[:name] == "input_values" &&
|
|
214
|
+
inputs.first[:type] == "tensor(float)"
|
|
215
|
+
valid_output = outputs.length == 1 && outputs.first[:name] == "logits" &&
|
|
216
|
+
outputs.first[:type] == "tensor(float)"
|
|
217
|
+
return if valid_input && valid_output
|
|
218
|
+
|
|
219
|
+
raise BackendUnavailable, "Pinned MMS ONNX graph has an unexpected input/output contract"
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
# Full-file MMS emissions plus per-ASR-segment CTC Viterbi alignment.
|
|
224
|
+
# The 30 s windows, 2 s context, 20 ms stride, wildcard column, and
|
|
225
|
+
# uniform per-segment recovery are the same as the Python reference.
|
|
226
|
+
class Aligner
|
|
227
|
+
SAMPLE_RATE = 16_000
|
|
228
|
+
INPUTS_TO_LOGITS_RATIO = 320
|
|
229
|
+
WINDOW_SECONDS = 30
|
|
230
|
+
CONTEXT_SECONDS = 2
|
|
231
|
+
WINDOW_SAMPLES = WINDOW_SECONDS * SAMPLE_RATE
|
|
232
|
+
CONTEXT_SAMPLES = CONTEXT_SECONDS * SAMPLE_RATE
|
|
233
|
+
INPUT_SAMPLES = WINDOW_SAMPLES + (2 * CONTEXT_SAMPLES)
|
|
234
|
+
WINDOW_FRAMES = WINDOW_SAMPLES / INPUTS_TO_LOGITS_RATIO
|
|
235
|
+
CONTEXT_FRAMES = CONTEXT_SAMPLES / INPUTS_TO_LOGITS_RATIO
|
|
236
|
+
STRIDE_MS = INPUTS_TO_LOGITS_RATIO * 1_000.0 / SAMPLE_RATE
|
|
237
|
+
ISO3 = { "ar" => "ara", "en" => "eng" }.freeze
|
|
238
|
+
VOCABULARY = {
|
|
239
|
+
"<blank>" => 0, "<pad>" => 1, "</s>" => 2, "<unk>" => 3,
|
|
240
|
+
"a" => 4, "i" => 5, "e" => 6, "n" => 7, "o" => 8, "u" => 9,
|
|
241
|
+
"t" => 10, "s" => 11, "r" => 12, "m" => 13, "k" => 14,
|
|
242
|
+
"l" => 15, "d" => 16, "g" => 17, "h" => 18, "y" => 19,
|
|
243
|
+
"b" => 20, "p" => 21, "w" => 22, "c" => 23, "v" => 24,
|
|
244
|
+
"j" => 25, "z" => 26, "f" => 27, "'" => 28, "q" => 29,
|
|
245
|
+
"x" => 30
|
|
246
|
+
}.freeze
|
|
247
|
+
BLANK_ID = VOCABULARY.fetch("<blank>")
|
|
248
|
+
|
|
249
|
+
attr_reader :session, :batch_size, :emissions_seconds, :viterbi_seconds
|
|
250
|
+
|
|
251
|
+
def initialize(dtype: "fp32", device: "cpu", batch_size: 4, session: nil, **session_options)
|
|
252
|
+
raise ArgumentError, "aligner batch_size must be positive" unless batch_size.is_a?(Integer) && batch_size.positive?
|
|
253
|
+
|
|
254
|
+
@session = session || Session.new(dtype: dtype, device: device, **session_options)
|
|
255
|
+
@batch_size = batch_size
|
|
256
|
+
@learned_batch_size = batch_size
|
|
257
|
+
@emissions_seconds = 0.0
|
|
258
|
+
@viterbi_seconds = 0.0
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
def provider
|
|
262
|
+
session.provider
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
def load_seconds
|
|
266
|
+
session.load_seconds
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
def load!
|
|
270
|
+
session.load! if session.respond_to?(:load!)
|
|
271
|
+
self
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
def close
|
|
275
|
+
session.close
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
def align(audio, segment_times, segment_texts, language:)
|
|
279
|
+
raise ArgumentError, "segment_times and segment_texts must have equal lengths" unless segment_times.length == segment_texts.length
|
|
280
|
+
|
|
281
|
+
emissions, stride_ms = compute_emissions(audio)
|
|
282
|
+
started = monotonic
|
|
283
|
+
align_emissions(emissions, stride_ms, segment_times, segment_texts, language: language)
|
|
284
|
+
ensure
|
|
285
|
+
@viterbi_seconds += monotonic - started if started
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
def compute_emissions(audio)
|
|
289
|
+
started = monotonic
|
|
290
|
+
samples = mono_float32(audio)
|
|
291
|
+
raise ArgumentError, "Cannot compute CTC emissions for empty audio" if samples.empty?
|
|
292
|
+
|
|
293
|
+
total_windows = (samples.length + WINDOW_SAMPLES - 1) / WINDOW_SAMPLES
|
|
294
|
+
extension_samples = (total_windows * WINDOW_SAMPLES) - samples.length
|
|
295
|
+
extension_frames = extension_samples / INPUTS_TO_LOGITS_RATIO
|
|
296
|
+
frame_count = (total_windows * WINDOW_FRAMES) - extension_frames
|
|
297
|
+
raise TranscriptionRuntimeError, "MMS aligner produced no usable CTC frames" unless frame_count.positive?
|
|
298
|
+
|
|
299
|
+
emissions = nil
|
|
300
|
+
write_offset = 0
|
|
301
|
+
first_window = 0
|
|
302
|
+
current_batch_size = [batch_size, @learned_batch_size].min
|
|
303
|
+
while first_window < total_windows
|
|
304
|
+
window_count = [current_batch_size, total_windows - first_window].min
|
|
305
|
+
begin
|
|
306
|
+
input = build_window_batch(samples, first_window, window_count)
|
|
307
|
+
logits = session.run(input)
|
|
308
|
+
batch_log_probs = crop_and_normalize(logits, window_count)
|
|
309
|
+
rescue NoMemoryError, StandardError => e
|
|
310
|
+
raise unless out_of_memory?(e) && current_batch_size > 1
|
|
311
|
+
|
|
312
|
+
current_batch_size = [1, current_batch_size / 2].max
|
|
313
|
+
@learned_batch_size = current_batch_size
|
|
314
|
+
next
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
expected_frames = window_count * WINDOW_FRAMES
|
|
318
|
+
unless batch_log_probs.shape[0] == expected_frames
|
|
319
|
+
raise TranscriptionRuntimeError, "MMS aligner returned an unexpected frame count"
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
class_count = batch_log_probs.shape[1]
|
|
323
|
+
unless class_count == VOCABULARY.length
|
|
324
|
+
raise TranscriptionRuntimeError,
|
|
325
|
+
"MMS aligner returned #{class_count} classes; expected #{VOCABULARY.length}"
|
|
326
|
+
end
|
|
327
|
+
emissions ||= Numo::SFloat.zeros(frame_count, class_count + 1)
|
|
328
|
+
if first_window + window_count == total_windows && extension_frames.positive?
|
|
329
|
+
kept = batch_log_probs.shape[0] - extension_frames
|
|
330
|
+
batch_log_probs = batch_log_probs[0...kept, true]
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
next_offset = write_offset + batch_log_probs.shape[0]
|
|
334
|
+
raise TranscriptionRuntimeError, "MMS aligner produced too many CTC frames" if next_offset > emissions.shape[0]
|
|
335
|
+
|
|
336
|
+
emissions[write_offset...next_offset, 0...class_count] = batch_log_probs
|
|
337
|
+
write_offset = next_offset
|
|
338
|
+
first_window += window_count
|
|
339
|
+
end
|
|
340
|
+
unless emissions && write_offset == emissions.shape[0]
|
|
341
|
+
raise TranscriptionRuntimeError,
|
|
342
|
+
"MMS emission assembly mismatch: wrote #{write_offset}, expected #{frame_count}"
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
[emissions, STRIDE_MS]
|
|
346
|
+
ensure
|
|
347
|
+
@emissions_seconds += monotonic - started if started
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
def align_emissions(emissions, stride_ms, segment_times, segment_texts, language:)
|
|
351
|
+
frame_count, emission_classes = emissions.shape
|
|
352
|
+
star_id = emission_classes - 1
|
|
353
|
+
raise TranscriptionRuntimeError, "MMS wildcard column collides with its tokenizer vocabulary" if VOCABULARY.value?(star_id)
|
|
354
|
+
|
|
355
|
+
dictionary = VOCABULARY.merge("<star>" => star_id).freeze
|
|
356
|
+
index_to_token = dictionary.invert.freeze
|
|
357
|
+
iso_language = ISO3.fetch(language, language)
|
|
358
|
+
words = []
|
|
359
|
+
fallback_count = 0
|
|
360
|
+
|
|
361
|
+
segment_times.zip(segment_texts).each_with_index do |((start_time, end_time), text), segment_index|
|
|
362
|
+
text = PythonText.strip(text.to_s)
|
|
363
|
+
next if text.empty?
|
|
364
|
+
|
|
365
|
+
first_frame = [(start_time * 1_000 / stride_ms).round(half: :even), 0].max
|
|
366
|
+
last_frame = [(end_time * 1_000 / stride_ms).round(half: :even), frame_count].min
|
|
367
|
+
if last_frame - first_frame < 2
|
|
368
|
+
fallback_count += 1
|
|
369
|
+
words.concat(uniform_fallback(text, start_time, end_time, segment_index))
|
|
370
|
+
next
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
begin
|
|
374
|
+
tokens_starred, text_starred = Text.preprocess(text, iso_language)
|
|
375
|
+
targets = tokens_starred.join(" ").split.filter_map { |token| dictionary[token] }
|
|
376
|
+
raise ArgumentError, "Transcript produced no aligner vocabulary tokens" if targets.empty?
|
|
377
|
+
|
|
378
|
+
path = CTC.forced_align(emissions[first_frame...last_frame, true], targets, blank: BLANK_ID)
|
|
379
|
+
segments = CTC.merge_repeats(path, index_to_token)
|
|
380
|
+
spans = CTC.spans(tokens_starred, segments, index_to_token.fetch(BLANK_ID))
|
|
381
|
+
results = Text.postprocess(text_starred, spans, stride_ms)
|
|
382
|
+
expected_tokens = PythonText.split(text)
|
|
383
|
+
unless results.map { |word| word.fetch(:text) } == expected_tokens
|
|
384
|
+
raise ArgumentError,
|
|
385
|
+
"forced alignment did not preserve the complete ASR transcript " \
|
|
386
|
+
"(#{results.length}/#{expected_tokens.length} words)"
|
|
387
|
+
end
|
|
388
|
+
rescue StandardError
|
|
389
|
+
fallback_count += 1
|
|
390
|
+
words.concat(uniform_fallback(text, start_time, end_time, segment_index))
|
|
391
|
+
next
|
|
392
|
+
end
|
|
393
|
+
|
|
394
|
+
results.each_with_index do |word, word_index|
|
|
395
|
+
absolute_start = (start_time + word.fetch(:start)).clamp(start_time, end_time)
|
|
396
|
+
absolute_end = (start_time + word.fetch(:end)).clamp(absolute_start, end_time)
|
|
397
|
+
words << TranscriptionWord.new(
|
|
398
|
+
start: absolute_start,
|
|
399
|
+
end: absolute_end,
|
|
400
|
+
text: word.fetch(:text),
|
|
401
|
+
segment_index: segment_index,
|
|
402
|
+
segment_word_index: word_index,
|
|
403
|
+
timing_source: "ctc"
|
|
404
|
+
)
|
|
405
|
+
end
|
|
406
|
+
end
|
|
407
|
+
[words.freeze, fallback_count]
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
private
|
|
411
|
+
|
|
412
|
+
def mono_float32(audio)
|
|
413
|
+
if audio.respond_to?(:ndim)
|
|
414
|
+
raise ArgumentError, "MMS alignment expects mono audio" unless audio.ndim == 1
|
|
415
|
+
|
|
416
|
+
audio.cast_to(Numo::SFloat)
|
|
417
|
+
elsif audio.is_a?(Array) && audio.none?(Array)
|
|
418
|
+
Numo::SFloat.cast(audio)
|
|
419
|
+
else
|
|
420
|
+
raise ArgumentError, "MMS alignment expects an indexable mono waveform"
|
|
421
|
+
end
|
|
422
|
+
rescue TypeError, ArgumentError => e
|
|
423
|
+
raise ArgumentError, "MMS alignment audio must contain real samples: #{e.message}"
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
def build_window_batch(audio, first_window, window_count)
|
|
427
|
+
batch = Numo::SFloat.zeros(window_count, INPUT_SAMPLES)
|
|
428
|
+
window_count.times do |row|
|
|
429
|
+
window_index = first_window + row
|
|
430
|
+
requested_start = (window_index * WINDOW_SAMPLES) - CONTEXT_SAMPLES
|
|
431
|
+
requested_end = requested_start + INPUT_SAMPLES
|
|
432
|
+
source_start = [0, requested_start].max
|
|
433
|
+
source_end = [audio.length, requested_end].min
|
|
434
|
+
next if source_end <= source_start
|
|
435
|
+
|
|
436
|
+
destination_start = source_start - requested_start
|
|
437
|
+
destination_end = destination_start + (source_end - source_start)
|
|
438
|
+
batch[row, destination_start...destination_end] = audio[source_start...source_end]
|
|
439
|
+
end
|
|
440
|
+
batch
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
def crop_and_normalize(logits, expected_batch)
|
|
444
|
+
logits = Numo::SFloat.cast(logits) unless logits.is_a?(Numo::NArray)
|
|
445
|
+
unless logits.ndim == 3 && logits.shape[0] == expected_batch &&
|
|
446
|
+
logits.shape[1] >= CONTEXT_FRAMES + WINDOW_FRAMES
|
|
447
|
+
raise TranscriptionRuntimeError,
|
|
448
|
+
"MMS aligner returned invalid logits shape #{logits.shape.inspect}"
|
|
449
|
+
end
|
|
450
|
+
|
|
451
|
+
classes = logits.shape[2]
|
|
452
|
+
cropped = logits[true, CONTEXT_FRAMES...(CONTEXT_FRAMES + WINDOW_FRAMES), true]
|
|
453
|
+
.reshape(expected_batch * WINDOW_FRAMES, classes)
|
|
454
|
+
maxima = cropped.max(1).reshape(cropped.shape[0], 1)
|
|
455
|
+
shifted = cropped - maxima
|
|
456
|
+
denominators = Numo::NMath.log(Numo::NMath.exp(shifted).sum(1)).reshape(cropped.shape[0], 1)
|
|
457
|
+
(shifted - denominators).cast_to(Numo::SFloat)
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
def uniform_fallback(text, start_time, end_time, segment_index)
|
|
461
|
+
Output::Timing.uniform_words(
|
|
462
|
+
text, start_time, end_time, segment_index, "uniform_fallback"
|
|
463
|
+
)
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
def out_of_memory?(error)
|
|
467
|
+
error.is_a?(NoMemoryError) || /out of memory|bad_alloc|failed to allocate|memory allocation/i.match?(error.message)
|
|
468
|
+
end
|
|
469
|
+
|
|
470
|
+
def monotonic
|
|
471
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
472
|
+
end
|
|
473
|
+
end
|
|
474
|
+
end
|
|
475
|
+
end
|
|
476
|
+
end
|