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,676 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "etc"
|
|
4
|
+
require "fiddle"
|
|
5
|
+
require "rbconfig"
|
|
6
|
+
require_relative "../errors"
|
|
7
|
+
require_relative "../python_text"
|
|
8
|
+
require_relative "failure_policy"
|
|
9
|
+
|
|
10
|
+
module Cohere
|
|
11
|
+
module Transcribe
|
|
12
|
+
module ASR
|
|
13
|
+
NativeWord = Data.define(:text, :start, :end, :probability)
|
|
14
|
+
NativeSegment = Data.define(:text, :start, :end, :words)
|
|
15
|
+
NativeResult = Data.define(
|
|
16
|
+
:text,
|
|
17
|
+
:segments,
|
|
18
|
+
:words,
|
|
19
|
+
:generated_tokens,
|
|
20
|
+
:generation_limit,
|
|
21
|
+
:generation_capacity,
|
|
22
|
+
:stopped_by_max_tokens,
|
|
23
|
+
:repetition_stopped
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
# Thin, process-local binding to CrispASR's stable C session ABI. The
|
|
27
|
+
# extension owns model execution; no Python process or Python runtime is
|
|
28
|
+
# involved. Loading remains lazy so configuration and CLI help stay light.
|
|
29
|
+
class NativeLibrary
|
|
30
|
+
OPEN_PARAM_VERSION = 2
|
|
31
|
+
OPEN_PARAM_INTEGER_COUNT = 12
|
|
32
|
+
NATIVE_ERROR_NAMES = {
|
|
33
|
+
0 => "none",
|
|
34
|
+
1 => "invalid_argument",
|
|
35
|
+
2 => "out_of_memory",
|
|
36
|
+
3 => "invariant",
|
|
37
|
+
4 => "runtime",
|
|
38
|
+
5 => "cancelled"
|
|
39
|
+
}.freeze
|
|
40
|
+
|
|
41
|
+
FUNCTIONS = {
|
|
42
|
+
last_error_kind: [[], :int],
|
|
43
|
+
last_error_message: [[], :voidp],
|
|
44
|
+
runtime_resolve_device: [[:voidp], :voidp],
|
|
45
|
+
runtime_supports_bf16: [[:voidp], :int],
|
|
46
|
+
set_gpu_backend: [[:voidp], :void],
|
|
47
|
+
session_open_with_params: [%i[voidp voidp voidp], :voidp],
|
|
48
|
+
session_backend: [[:voidp], :voidp],
|
|
49
|
+
session_compute_backend: [[:voidp], :voidp],
|
|
50
|
+
session_memory: [%i[voidp voidp voidp], :int],
|
|
51
|
+
session_batch_capacity: [[:voidp], :int],
|
|
52
|
+
session_cancel: [[:voidp], :int],
|
|
53
|
+
session_transcribe_lang: [%i[voidp voidp int voidp], :voidp],
|
|
54
|
+
session_transcribe_batch_lang: [%i[voidp voidp voidp int voidp], :voidp],
|
|
55
|
+
session_batch_result_count: [[:voidp], :int],
|
|
56
|
+
session_batch_result_at: [%i[voidp int], :voidp],
|
|
57
|
+
session_batch_result_free: [[:voidp], :void],
|
|
58
|
+
session_result_n_segments: [[:voidp], :int],
|
|
59
|
+
session_result_segment_text: [%i[voidp int], :voidp],
|
|
60
|
+
session_result_segment_t0: [%i[voidp int], :int64],
|
|
61
|
+
session_result_segment_t1: [%i[voidp int], :int64],
|
|
62
|
+
session_result_n_words: [%i[voidp int], :int],
|
|
63
|
+
session_result_word_text: [%i[voidp int int], :voidp],
|
|
64
|
+
session_result_word_t0: [%i[voidp int int], :int64],
|
|
65
|
+
session_result_word_t1: [%i[voidp int int], :int64],
|
|
66
|
+
session_result_word_p: [%i[voidp int int], :float],
|
|
67
|
+
session_result_generated_tokens: [[:voidp], :int],
|
|
68
|
+
session_result_generation_limit: [[:voidp], :int],
|
|
69
|
+
session_result_generation_capacity: [[:voidp], :int],
|
|
70
|
+
session_result_stopped_by_max_tokens: [[:voidp], :int],
|
|
71
|
+
session_result_repetition_stopped: [[:voidp], :int],
|
|
72
|
+
session_result_free: [[:voidp], :void],
|
|
73
|
+
session_close: [[:voidp], :void],
|
|
74
|
+
session_set_max_new_tokens: [%i[voidp int], :int],
|
|
75
|
+
session_set_beam_size: [%i[voidp int], :int],
|
|
76
|
+
session_set_repetition_loop_guard: [%i[voidp int], :int]
|
|
77
|
+
}.freeze
|
|
78
|
+
OPTIONAL_FUNCTIONS = {
|
|
79
|
+
session_batch_result_stats_v1: [%i[voidp voidp int], :int]
|
|
80
|
+
}.freeze
|
|
81
|
+
|
|
82
|
+
TYPE_MAP = {
|
|
83
|
+
void: Fiddle::TYPE_VOID,
|
|
84
|
+
voidp: Fiddle::TYPE_VOIDP,
|
|
85
|
+
int: Fiddle::TYPE_INT,
|
|
86
|
+
int64: Fiddle::TYPE_LONG_LONG,
|
|
87
|
+
float: Fiddle::TYPE_FLOAT
|
|
88
|
+
}.freeze
|
|
89
|
+
|
|
90
|
+
class << self
|
|
91
|
+
def load
|
|
92
|
+
@mutex ||= Mutex.new
|
|
93
|
+
@mutex.synchronize { @instance ||= load_uncached }
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def available?
|
|
97
|
+
load
|
|
98
|
+
true
|
|
99
|
+
rescue TranscriptionRuntimeError
|
|
100
|
+
false
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def candidate_paths
|
|
104
|
+
explicit = ENV.fetch("COHERE_TRANSCRIBE_NATIVE_LIBRARY", nil)
|
|
105
|
+
return [explicit] if explicit && !explicit.empty?
|
|
106
|
+
|
|
107
|
+
root = File.expand_path("../../../..", __dir__)
|
|
108
|
+
packaged = File.join(root, "lib", "cohere", "transcribe", "native")
|
|
109
|
+
patterns = case RbConfig::CONFIG["host_os"]
|
|
110
|
+
when /darwin/
|
|
111
|
+
["libcrispasr*.dylib"]
|
|
112
|
+
when /mswin|mingw|cygwin/
|
|
113
|
+
["crispasr*.dll", "libcrispasr*.dll"]
|
|
114
|
+
else
|
|
115
|
+
["libcrispasr.so", "libcrispasr.so.*"]
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
paths = [packaged].flat_map do |directory|
|
|
119
|
+
patterns.flat_map { |pattern| Dir.glob(File.join(directory, pattern)) }.sort
|
|
120
|
+
end
|
|
121
|
+
paths.concat(system_library_names)
|
|
122
|
+
paths.uniq
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
private
|
|
126
|
+
|
|
127
|
+
def load_uncached
|
|
128
|
+
failures = []
|
|
129
|
+
candidate_paths.each do |candidate|
|
|
130
|
+
return new(candidate)
|
|
131
|
+
rescue Fiddle::DLError, LoadError => e
|
|
132
|
+
failures << "#{candidate}: #{e.message}"
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
detail = failures.empty? ? "no candidate libraries were found" : failures.join("; ")
|
|
136
|
+
raise TranscriptionRuntimeError,
|
|
137
|
+
"The native Cohere ASR runtime could not be loaded (#{detail}). " \
|
|
138
|
+
"Set COHERE_TRANSCRIBE_NATIVE_LIBRARY to libcrispasr."
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def system_library_names
|
|
142
|
+
case RbConfig::CONFIG["host_os"]
|
|
143
|
+
when /darwin/
|
|
144
|
+
["libcrispasr.1.dylib", "libcrispasr.dylib"]
|
|
145
|
+
when /mswin|mingw|cygwin/
|
|
146
|
+
["crispasr.dll", "libcrispasr.dll"]
|
|
147
|
+
else
|
|
148
|
+
["libcrispasr.so.1", "libcrispasr.so"]
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
attr_reader :path
|
|
154
|
+
|
|
155
|
+
def initialize(path)
|
|
156
|
+
@path = path
|
|
157
|
+
preload_sibling_libraries(path) if File.absolute_path(path) == path && File.file?(path)
|
|
158
|
+
flags = Fiddle::RTLD_NOW | Fiddle::RTLD_GLOBAL
|
|
159
|
+
@handle = Fiddle::Handle.new(path, flags)
|
|
160
|
+
@functions = FUNCTIONS.to_h do |name, (arguments, result)|
|
|
161
|
+
symbol = "crispasr_#{name}"
|
|
162
|
+
address = @handle[symbol]
|
|
163
|
+
[name, Fiddle::Function.new(address, arguments.map { |type| TYPE_MAP.fetch(type) }, TYPE_MAP.fetch(result))]
|
|
164
|
+
end
|
|
165
|
+
OPTIONAL_FUNCTIONS.each do |name, (arguments, result)|
|
|
166
|
+
symbol = "crispasr_#{name}"
|
|
167
|
+
address = @handle[symbol]
|
|
168
|
+
@functions[name] = Fiddle::Function.new(
|
|
169
|
+
address,
|
|
170
|
+
arguments.map { |type| TYPE_MAP.fetch(type) },
|
|
171
|
+
TYPE_MAP.fetch(result)
|
|
172
|
+
)
|
|
173
|
+
rescue Fiddle::DLError
|
|
174
|
+
next
|
|
175
|
+
end
|
|
176
|
+
@functions.freeze
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def call(name, *)
|
|
180
|
+
@functions.fetch(name).call(*)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def function?(name)
|
|
184
|
+
@functions.key?(name)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def open_session(model_path:, device:, threads:)
|
|
188
|
+
gpu_backend = case device
|
|
189
|
+
when "cuda" then "cuda"
|
|
190
|
+
when "mps" then "metal"
|
|
191
|
+
else ""
|
|
192
|
+
end
|
|
193
|
+
call(:set_gpu_backend, c_string(gpu_backend))
|
|
194
|
+
|
|
195
|
+
use_gpu = device == "cpu" ? 0 : 1
|
|
196
|
+
values = [OPEN_PARAM_VERSION, threads, use_gpu, 0, 1, -1] + Array.new(6, 0)
|
|
197
|
+
unless values.length == OPEN_PARAM_INTEGER_COUNT
|
|
198
|
+
raise TranscriptionRuntimeError, "Native open-parameter ABI is internally inconsistent"
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
packed = values.pack("i!*")
|
|
202
|
+
pointer = call(
|
|
203
|
+
:session_open_with_params,
|
|
204
|
+
c_string(model_path.to_s),
|
|
205
|
+
c_string("cohere"),
|
|
206
|
+
Fiddle::Pointer[packed]
|
|
207
|
+
)
|
|
208
|
+
return pointer unless null_pointer?(pointer)
|
|
209
|
+
|
|
210
|
+
native_kind = Integer(call(:last_error_kind))
|
|
211
|
+
native_name = NATIVE_ERROR_NAMES.fetch(native_kind, "unknown")
|
|
212
|
+
native_message = string(call(:last_error_message)).strip
|
|
213
|
+
diagnostic = "native #{native_name} error (#{native_kind})"
|
|
214
|
+
diagnostic = "#{diagnostic}: #{native_message}" unless native_message.empty?
|
|
215
|
+
message = "Unable to load Dense Cohere model #{model_path.inspect} " \
|
|
216
|
+
"on device #{device.inspect}: #{diagnostic}"
|
|
217
|
+
raise TranscriptionRuntimeError, message
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def resolve_device(requested)
|
|
221
|
+
value = requested.to_s
|
|
222
|
+
pointer = call(:runtime_resolve_device, c_string(value))
|
|
223
|
+
resolved = string(pointer)
|
|
224
|
+
return resolved.freeze unless resolved.empty?
|
|
225
|
+
|
|
226
|
+
case value
|
|
227
|
+
when "cuda"
|
|
228
|
+
raise TranscriptionRuntimeError,
|
|
229
|
+
"--device cuda was requested, but CUDA is not available to the native runtime"
|
|
230
|
+
when "mps"
|
|
231
|
+
raise TranscriptionRuntimeError,
|
|
232
|
+
"--device mps was requested, but Metal is not available to the native runtime"
|
|
233
|
+
else
|
|
234
|
+
raise TranscriptionRuntimeError, "Unsupported native inference device: #{value.inspect}"
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def supports_bf16?(device)
|
|
239
|
+
call(:runtime_supports_bf16, c_string(device.to_s)) == 1
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
def string(pointer)
|
|
243
|
+
return "" if null_pointer?(pointer)
|
|
244
|
+
|
|
245
|
+
value = pointer.is_a?(Fiddle::Pointer) ? pointer.to_s : Fiddle::Pointer.new(pointer).to_s
|
|
246
|
+
value.force_encoding(Encoding::UTF_8).scrub
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def null_pointer?(pointer)
|
|
250
|
+
pointer.nil? || pointer == 0 || (pointer.respond_to?(:null?) && pointer.null?)
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
private
|
|
254
|
+
|
|
255
|
+
def c_string(value)
|
|
256
|
+
Fiddle::Pointer["#{value}\0"]
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
# A packaged build keeps ggml beside libcrispasr. Preloading those
|
|
260
|
+
# libraries makes that layout work even when a platform ignores
|
|
261
|
+
# $ORIGIN for a manually-loaded shared object.
|
|
262
|
+
def preload_sibling_libraries(path)
|
|
263
|
+
directory = File.dirname(path)
|
|
264
|
+
basenames = %w[libggml-base libggml-cpu libggml-cuda libggml-metal libggml]
|
|
265
|
+
basenames.each do |basename|
|
|
266
|
+
Dir.glob(File.join(directory, "#{basename}.*")).each do |dependency|
|
|
267
|
+
next unless File.file?(dependency)
|
|
268
|
+
|
|
269
|
+
Fiddle::Handle.new(dependency, Fiddle::RTLD_NOW | Fiddle::RTLD_GLOBAL)
|
|
270
|
+
rescue Fiddle::DLError
|
|
271
|
+
# The main load below reports a useful loader error if this is a
|
|
272
|
+
# required dependency; optional GPU backends may legitimately fail.
|
|
273
|
+
next
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
# One retained native Cohere model session.
|
|
280
|
+
class NativeSession
|
|
281
|
+
MAX_NATIVE_SAMPLE_COUNT = 2_147_483_647
|
|
282
|
+
NATIVE_CANCELLED_KIND = 5
|
|
283
|
+
CANCELLATION_JOIN_INTERVAL = 0.01
|
|
284
|
+
NATIVE_BATCH_STAT_FIELDS = %i[
|
|
285
|
+
abi_version field_count total_us feature_wall_us feature_worker_us mel_pack_us
|
|
286
|
+
encoder_graph_build_us encoder_graph_alloc_us encoder_input_us encoder_compute_us
|
|
287
|
+
encoder_readback_us encoder_repack_us decoder_total_us decoder_cross_kv_us
|
|
288
|
+
decoder_reserve_us decoder_decode_us render_us decoder_calls generation_steps
|
|
289
|
+
encoder_microbatches token_id_readback_bytes
|
|
290
|
+
].freeze
|
|
291
|
+
NATIVE_BATCH_STAT_ABI_VERSION = 1
|
|
292
|
+
|
|
293
|
+
NATIVE_FAILURE_KINDS = {
|
|
294
|
+
1 => :fatal,
|
|
295
|
+
2 => :oom,
|
|
296
|
+
3 => :fatal,
|
|
297
|
+
4 => :error
|
|
298
|
+
}.freeze
|
|
299
|
+
|
|
300
|
+
attr_reader :backend, :batch_capacity, :compute_backend, :device, :last_batch_metrics, :model_path
|
|
301
|
+
|
|
302
|
+
def initialize(model_path, options, threads: nil, library: NativeLibrary.load)
|
|
303
|
+
@library = library
|
|
304
|
+
@model_path = Pathname.new(model_path).expand_path.freeze
|
|
305
|
+
raise TranscriptionRuntimeError, "Native Dense model does not exist: #{@model_path}" unless @model_path.file?
|
|
306
|
+
|
|
307
|
+
@mutex = Mutex.new
|
|
308
|
+
@closed = false
|
|
309
|
+
thread_count = normalize_threads(threads)
|
|
310
|
+
@session = @library.open_session(
|
|
311
|
+
model_path: @model_path,
|
|
312
|
+
device: options.device.to_s,
|
|
313
|
+
threads: thread_count
|
|
314
|
+
)
|
|
315
|
+
@default_max_new_tokens = Integer(options.max_new_tokens)
|
|
316
|
+
@library.call(:session_set_max_new_tokens, @session, @default_max_new_tokens)
|
|
317
|
+
@library.call(:session_set_beam_size, @session, 1)
|
|
318
|
+
@library.call(
|
|
319
|
+
:session_set_repetition_loop_guard,
|
|
320
|
+
@session,
|
|
321
|
+
options.stop_repetition_loops ? 1 : 0
|
|
322
|
+
)
|
|
323
|
+
@backend = @library.string(@library.call(:session_backend, @session)).freeze
|
|
324
|
+
unless @backend == "cohere"
|
|
325
|
+
close
|
|
326
|
+
raise TranscriptionRuntimeError,
|
|
327
|
+
"Native runtime selected #{@backend.inspect}, expected the Cohere Dense backend"
|
|
328
|
+
end
|
|
329
|
+
@compute_backend = @library.string(
|
|
330
|
+
@library.call(:session_compute_backend, @session)
|
|
331
|
+
).freeze
|
|
332
|
+
@device = canonical_device(@compute_backend)
|
|
333
|
+
unless @device == options.device.to_s
|
|
334
|
+
close
|
|
335
|
+
raise TranscriptionRuntimeError,
|
|
336
|
+
"Native runtime selected #{@compute_backend.inspect} (#{@device}) " \
|
|
337
|
+
"after #{options.device.inspect} was resolved"
|
|
338
|
+
end
|
|
339
|
+
@batch_capacity = Integer(@library.call(:session_batch_capacity, @session))
|
|
340
|
+
unless @batch_capacity.positive?
|
|
341
|
+
close
|
|
342
|
+
raise TranscriptionRuntimeError, "Native runtime reported an invalid Cohere batch capacity"
|
|
343
|
+
end
|
|
344
|
+
rescue StandardError
|
|
345
|
+
close if defined?(@session) && @session
|
|
346
|
+
raise
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
def transcribe(samples, language:, offset: 0.0, max_new_tokens: nil)
|
|
350
|
+
@mutex.synchronize do
|
|
351
|
+
ensure_open!
|
|
352
|
+
@last_batch_metrics = nil
|
|
353
|
+
generation_limit = max_new_tokens.nil? ? @default_max_new_tokens : Integer(max_new_tokens)
|
|
354
|
+
set_generation_limit!(generation_limit)
|
|
355
|
+
binary, sample_count = float_samples(samples)
|
|
356
|
+
raise TranscriptionRuntimeError, "Audio segment is too large for the native ABI" \
|
|
357
|
+
if sample_count > MAX_NATIVE_SAMPLE_COUNT
|
|
358
|
+
|
|
359
|
+
run_native_inference do
|
|
360
|
+
result = @library.call(
|
|
361
|
+
:session_transcribe_lang,
|
|
362
|
+
@session,
|
|
363
|
+
Fiddle::Pointer[binary],
|
|
364
|
+
sample_count,
|
|
365
|
+
Fiddle::Pointer["#{language}\0"]
|
|
366
|
+
)
|
|
367
|
+
raise_native_failure!("Native Cohere inference returned no result") if @library.null_pointer?(result)
|
|
368
|
+
|
|
369
|
+
begin
|
|
370
|
+
materialize_result(result, offset: Float(offset))
|
|
371
|
+
ensure
|
|
372
|
+
@library.call(:session_result_free, result)
|
|
373
|
+
end
|
|
374
|
+
end
|
|
375
|
+
end
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
# True padded-encoder/ragged-decoder batching in the native Cohere
|
|
379
|
+
# runtime. The capacity is queried from the loaded adapter because its
|
|
380
|
+
# logical decoder batch may span multiple encoder microbatches.
|
|
381
|
+
def transcribe_batch(sample_batches, language:, offsets: nil, max_new_tokens: nil)
|
|
382
|
+
unless sample_batches.is_a?(Array) && sample_batches.length.between?(1, @batch_capacity)
|
|
383
|
+
raise ArgumentError,
|
|
384
|
+
"sample_batches must contain between 1 and #{@batch_capacity} audio rows"
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
offsets ||= Array.new(sample_batches.length, 0.0)
|
|
388
|
+
unless offsets.is_a?(Array) && offsets.length == sample_batches.length
|
|
389
|
+
raise ArgumentError, "offsets must contain one value per audio row"
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
@mutex.synchronize do
|
|
393
|
+
ensure_open!
|
|
394
|
+
@last_batch_metrics = nil
|
|
395
|
+
generation_limit = max_new_tokens.nil? ? @default_max_new_tokens : Integer(max_new_tokens)
|
|
396
|
+
set_generation_limit!(generation_limit)
|
|
397
|
+
|
|
398
|
+
buffers_and_counts = sample_batches.map { |samples| float_samples(samples) }
|
|
399
|
+
oversized_lane = buffers_and_counts.index { |_binary, count| count > MAX_NATIVE_SAMPLE_COUNT }
|
|
400
|
+
if oversized_lane
|
|
401
|
+
raise TranscriptionRuntimeError,
|
|
402
|
+
"Audio batch row #{oversized_lane} is too large for the native ABI"
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
run_native_inference do
|
|
406
|
+
pointers = buffers_and_counts.map { |binary, _count| Fiddle::Pointer[binary] }
|
|
407
|
+
pointer_table = pointers.map(&:to_i).pack("J*")
|
|
408
|
+
counts = buffers_and_counts.map(&:last).pack("i!*")
|
|
409
|
+
batch_result = @library.call(
|
|
410
|
+
:session_transcribe_batch_lang,
|
|
411
|
+
@session,
|
|
412
|
+
Fiddle::Pointer[pointer_table],
|
|
413
|
+
Fiddle::Pointer[counts],
|
|
414
|
+
sample_batches.length,
|
|
415
|
+
Fiddle::Pointer["#{language}\0"]
|
|
416
|
+
)
|
|
417
|
+
raise_native_failure!("Native Cohere batch inference returned no result") \
|
|
418
|
+
if @library.null_pointer?(batch_result)
|
|
419
|
+
|
|
420
|
+
begin
|
|
421
|
+
@last_batch_metrics = materialize_batch_metrics(batch_result)
|
|
422
|
+
count = @library.call(:session_batch_result_count, batch_result)
|
|
423
|
+
unless count == sample_batches.length
|
|
424
|
+
raise ExecutionError.new(
|
|
425
|
+
"Native Cohere batch returned #{count} rows for #{sample_batches.length} inputs",
|
|
426
|
+
failure_kind: :fatal
|
|
427
|
+
)
|
|
428
|
+
end
|
|
429
|
+
Array.new(count) do |lane|
|
|
430
|
+
result = @library.call(:session_batch_result_at, batch_result, lane)
|
|
431
|
+
if @library.null_pointer?(result)
|
|
432
|
+
raise ExecutionError.new(
|
|
433
|
+
"Native Cohere batch result row #{lane} is missing",
|
|
434
|
+
failure_kind: :fatal
|
|
435
|
+
)
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
materialize_result(result, offset: Float(offsets.fetch(lane)))
|
|
439
|
+
end.freeze
|
|
440
|
+
ensure
|
|
441
|
+
@library.call(:session_batch_result_free, batch_result)
|
|
442
|
+
end
|
|
443
|
+
end
|
|
444
|
+
end
|
|
445
|
+
end
|
|
446
|
+
|
|
447
|
+
def close
|
|
448
|
+
@mutex ||= Mutex.new
|
|
449
|
+
@mutex.synchronize do
|
|
450
|
+
return if @closed
|
|
451
|
+
|
|
452
|
+
@library.call(:session_close, @session) if @library && @session
|
|
453
|
+
@session = nil
|
|
454
|
+
@closed = true
|
|
455
|
+
end
|
|
456
|
+
nil
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
def closed?
|
|
460
|
+
@closed
|
|
461
|
+
end
|
|
462
|
+
|
|
463
|
+
# Current free/total memory for the selected ggml device, used by the
|
|
464
|
+
# adaptive batch controller. Returns nil when a backend has no memory
|
|
465
|
+
# telemetry rather than guessing from process RSS.
|
|
466
|
+
def memory
|
|
467
|
+
@mutex.synchronize do
|
|
468
|
+
ensure_open!
|
|
469
|
+
free_bytes = [0].pack("Q")
|
|
470
|
+
total_bytes = [0].pack("Q")
|
|
471
|
+
status = @library.call(
|
|
472
|
+
:session_memory,
|
|
473
|
+
@session,
|
|
474
|
+
Fiddle::Pointer[free_bytes],
|
|
475
|
+
Fiddle::Pointer[total_bytes]
|
|
476
|
+
)
|
|
477
|
+
return nil unless status.zero?
|
|
478
|
+
|
|
479
|
+
[free_bytes.unpack1("Q"), total_bytes.unpack1("Q")].freeze
|
|
480
|
+
end
|
|
481
|
+
end
|
|
482
|
+
|
|
483
|
+
private
|
|
484
|
+
|
|
485
|
+
def raise_native_failure!(fallback_message)
|
|
486
|
+
native_kind = Integer(@library.call(:last_error_kind))
|
|
487
|
+
native_message = @library.string(@library.call(:last_error_message)).strip
|
|
488
|
+
message = native_message.empty? ? fallback_message : "#{fallback_message}: #{native_message}"
|
|
489
|
+
raise Interrupt, message if native_kind == NATIVE_CANCELLED_KIND
|
|
490
|
+
|
|
491
|
+
failure_kind = NATIVE_FAILURE_KINDS.fetch(native_kind, native_kind.zero? ? :error : :fatal)
|
|
492
|
+
raise ExecutionError.new(message, failure_kind: failure_kind)
|
|
493
|
+
end
|
|
494
|
+
|
|
495
|
+
# Ruby cannot deliver Thread#raise (including SIGINT's Interrupt) while
|
|
496
|
+
# the receiving thread is blocked inside Fiddle. Keep the caller at an
|
|
497
|
+
# interruptible join while a private worker owns the foreign call. The
|
|
498
|
+
# caller still holds @mutex, so close and another inference cannot race
|
|
499
|
+
# the session; cancellation is the only concurrent C ABI operation.
|
|
500
|
+
def run_native_inference
|
|
501
|
+
outcome = Queue.new
|
|
502
|
+
worker = nil
|
|
503
|
+
Thread.handle_interrupt(Exception => :on_blocking) do
|
|
504
|
+
worker = Thread.new do
|
|
505
|
+
outcome << [:returned, yield]
|
|
506
|
+
rescue Exception => e # rubocop:disable Lint/RescueException -- transfer native cancellation intact
|
|
507
|
+
outcome << [:raised, e]
|
|
508
|
+
end
|
|
509
|
+
worker.report_on_exception = false
|
|
510
|
+
|
|
511
|
+
begin
|
|
512
|
+
worker.join
|
|
513
|
+
rescue Exception => e # rubocop:disable Lint/RescueException -- caller cancellation must win
|
|
514
|
+
cancel_and_hard_join(worker)
|
|
515
|
+
raise e
|
|
516
|
+
end
|
|
517
|
+
end
|
|
518
|
+
|
|
519
|
+
status, value = begin
|
|
520
|
+
outcome.pop(true)
|
|
521
|
+
rescue ThreadError
|
|
522
|
+
raise ExecutionError.new(
|
|
523
|
+
"Native Cohere inference worker exited without reporting an outcome",
|
|
524
|
+
failure_kind: :fatal
|
|
525
|
+
)
|
|
526
|
+
end
|
|
527
|
+
raise value if status == :raised
|
|
528
|
+
|
|
529
|
+
value
|
|
530
|
+
end
|
|
531
|
+
|
|
532
|
+
# A cancellation can arrive after Thread.new but before the worker has
|
|
533
|
+
# entered the C function. Retry the non-poisoning session cancel until
|
|
534
|
+
# the worker exits; never kill a thread that may still own ggml state.
|
|
535
|
+
def cancel_and_hard_join(worker)
|
|
536
|
+
loop do
|
|
537
|
+
@library.call(:session_cancel, @session)
|
|
538
|
+
return if worker.join(CANCELLATION_JOIN_INTERVAL)
|
|
539
|
+
rescue Exception # rubocop:disable Lint/RescueException -- preserve the first caller exception
|
|
540
|
+
next
|
|
541
|
+
end
|
|
542
|
+
end
|
|
543
|
+
|
|
544
|
+
def canonical_device(name)
|
|
545
|
+
case name.downcase
|
|
546
|
+
when /\Acuda/ then "cuda"
|
|
547
|
+
when /\Ametal/ then "mps"
|
|
548
|
+
when /\Acpu/ then "cpu"
|
|
549
|
+
else
|
|
550
|
+
raise TranscriptionRuntimeError,
|
|
551
|
+
"Native runtime reported an unsupported compute backend: #{name.inspect}"
|
|
552
|
+
end
|
|
553
|
+
end
|
|
554
|
+
|
|
555
|
+
def ensure_open!
|
|
556
|
+
raise TranscriberClosedError, "The native Cohere model session has been closed" if @closed
|
|
557
|
+
end
|
|
558
|
+
|
|
559
|
+
def normalize_threads(threads)
|
|
560
|
+
value = threads || ENV["COHERE_TRANSCRIBE_THREADS"] || Etc.nprocessors
|
|
561
|
+
value = Integer(value)
|
|
562
|
+
raise ArgumentError, "threads must be a positive integer" unless value.positive?
|
|
563
|
+
|
|
564
|
+
value
|
|
565
|
+
end
|
|
566
|
+
|
|
567
|
+
def set_generation_limit!(generation_limit)
|
|
568
|
+
raise ArgumentError, "max_new_tokens must be a positive integer" unless generation_limit.positive?
|
|
569
|
+
return if @library.call(:session_set_max_new_tokens, @session, generation_limit).zero?
|
|
570
|
+
|
|
571
|
+
raise TranscriptionRuntimeError, "Native Cohere inference rejected max_new_tokens=#{generation_limit}"
|
|
572
|
+
end
|
|
573
|
+
|
|
574
|
+
def float_samples(samples)
|
|
575
|
+
if defined?(Numo::NArray) && samples.is_a?(Numo::NArray)
|
|
576
|
+
array = samples.cast_to(Numo::SFloat).reshape(samples.size)
|
|
577
|
+
[array.to_binary, array.size]
|
|
578
|
+
elsif samples.is_a?(Array)
|
|
579
|
+
[samples.map { |value| Float(value) }.pack("f*"), samples.length]
|
|
580
|
+
else
|
|
581
|
+
raise TypeError, "samples must be a Numo::NArray or an Array of floats"
|
|
582
|
+
end
|
|
583
|
+
end
|
|
584
|
+
|
|
585
|
+
def materialize_result(result, offset:)
|
|
586
|
+
segments = []
|
|
587
|
+
words = []
|
|
588
|
+
count = @library.call(:session_result_n_segments, result)
|
|
589
|
+
count.times do |segment_index|
|
|
590
|
+
segment_text = @library.string(
|
|
591
|
+
@library.call(:session_result_segment_text, result, segment_index)
|
|
592
|
+
)
|
|
593
|
+
segment_text = PythonText.strip(segment_text)
|
|
594
|
+
start_time = offset + centiseconds(
|
|
595
|
+
@library.call(:session_result_segment_t0, result, segment_index)
|
|
596
|
+
)
|
|
597
|
+
end_time = offset + centiseconds(
|
|
598
|
+
@library.call(:session_result_segment_t1, result, segment_index)
|
|
599
|
+
)
|
|
600
|
+
segment_words = materialize_words(result, segment_index, offset: offset)
|
|
601
|
+
words.concat(segment_words)
|
|
602
|
+
segments << NativeSegment.new(
|
|
603
|
+
text: segment_text.freeze,
|
|
604
|
+
start: start_time,
|
|
605
|
+
end: end_time,
|
|
606
|
+
words: segment_words.freeze
|
|
607
|
+
)
|
|
608
|
+
end
|
|
609
|
+
|
|
610
|
+
text = PythonText.strip(segments.map(&:text).reject(&:empty?).join(" ")).freeze
|
|
611
|
+
NativeResult.new(
|
|
612
|
+
text: text,
|
|
613
|
+
segments: segments.freeze,
|
|
614
|
+
words: words.freeze,
|
|
615
|
+
generated_tokens: @library.call(:session_result_generated_tokens, result),
|
|
616
|
+
generation_limit: @library.call(:session_result_generation_limit, result),
|
|
617
|
+
generation_capacity: @library.call(:session_result_generation_capacity, result),
|
|
618
|
+
stopped_by_max_tokens: !@library.call(
|
|
619
|
+
:session_result_stopped_by_max_tokens,
|
|
620
|
+
result
|
|
621
|
+
).zero?,
|
|
622
|
+
repetition_stopped: !@library.call(:session_result_repetition_stopped, result).zero?
|
|
623
|
+
)
|
|
624
|
+
end
|
|
625
|
+
|
|
626
|
+
def materialize_batch_metrics(batch_result)
|
|
627
|
+
return nil unless @library.respond_to?(:function?) &&
|
|
628
|
+
@library.function?(:session_batch_result_stats_v1)
|
|
629
|
+
|
|
630
|
+
capacity = NATIVE_BATCH_STAT_FIELDS.length
|
|
631
|
+
buffer = Array.new(capacity, 0).pack("q*")
|
|
632
|
+
reported = Integer(
|
|
633
|
+
@library.call(
|
|
634
|
+
:session_batch_result_stats_v1,
|
|
635
|
+
batch_result,
|
|
636
|
+
Fiddle::Pointer[buffer],
|
|
637
|
+
capacity
|
|
638
|
+
)
|
|
639
|
+
)
|
|
640
|
+
return nil if reported < capacity
|
|
641
|
+
|
|
642
|
+
values = buffer.unpack("q*")
|
|
643
|
+
raw = NATIVE_BATCH_STAT_FIELDS.zip(values).to_h
|
|
644
|
+
return nil unless raw.fetch(:abi_version) == NATIVE_BATCH_STAT_ABI_VERSION &&
|
|
645
|
+
raw.fetch(:field_count) >= capacity
|
|
646
|
+
|
|
647
|
+
raw.each_with_object({}) do |(name, value), metrics|
|
|
648
|
+
metrics[name.to_s.end_with?("_us") ? name.to_s.sub(/_us\z/, "_seconds").to_sym : name] =
|
|
649
|
+
name.to_s.end_with?("_us") ? value.fdiv(1_000_000) : value
|
|
650
|
+
end.freeze
|
|
651
|
+
end
|
|
652
|
+
|
|
653
|
+
def materialize_words(result, segment_index, offset:)
|
|
654
|
+
count = @library.call(:session_result_n_words, result, segment_index)
|
|
655
|
+
Array.new(count) do |word_index|
|
|
656
|
+
start_cs = @library.call(:session_result_word_t0, result, segment_index, word_index)
|
|
657
|
+
end_cs = @library.call(:session_result_word_t1, result, segment_index, word_index)
|
|
658
|
+
word_text = @library.string(
|
|
659
|
+
@library.call(:session_result_word_text, result, segment_index, word_index)
|
|
660
|
+
)
|
|
661
|
+
NativeWord.new(
|
|
662
|
+
text: PythonText.strip(word_text).freeze,
|
|
663
|
+
start: start_cs.negative? ? nil : offset + centiseconds(start_cs),
|
|
664
|
+
end: end_cs.negative? ? nil : offset + centiseconds(end_cs),
|
|
665
|
+
probability: @library.call(:session_result_word_p, result, segment_index, word_index)
|
|
666
|
+
)
|
|
667
|
+
end
|
|
668
|
+
end
|
|
669
|
+
|
|
670
|
+
def centiseconds(value)
|
|
671
|
+
value.to_f / 100.0
|
|
672
|
+
end
|
|
673
|
+
end
|
|
674
|
+
end
|
|
675
|
+
end
|
|
676
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Audio segmentation attribution
|
|
2
|
+
|
|
3
|
+
The energy tokenizer in `segmentation.rb` retains the 50 ms PCM16 log-RMS calculation, silence state transitions, partial-final-frame timing, and maximum-duration behavior of Auditok 0.4.2 while implementing that behavior directly in Ruby.
|
|
4
|
+
|
|
5
|
+
- Source: <https://github.com/amsehili/auditok>
|
|
6
|
+
- PyPI source archive SHA-256: `52985096cbd3c15d650e71cb252b385875c9031da40ca8584b99fcdd9e26eaa5`
|
|
7
|
+
- Copyright: 2015-2026 Mohamed El Amine SEHILI
|
|
8
|
+
- License: MIT; see `LICENSE.auditok`
|