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,173 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "errors"
|
|
4
|
+
require_relative "types"
|
|
5
|
+
require_relative "input"
|
|
6
|
+
require_relative "loader"
|
|
7
|
+
|
|
8
|
+
module Cohere
|
|
9
|
+
module Transcribe
|
|
10
|
+
# Reusable, serialized transcription session with lazy model loading.
|
|
11
|
+
class Transcriber
|
|
12
|
+
OPTIONS_UNSET = Object.new.freeze
|
|
13
|
+
private_constant :OPTIONS_UNSET
|
|
14
|
+
|
|
15
|
+
attr_reader :options, :progress
|
|
16
|
+
|
|
17
|
+
def initialize(positional_options = OPTIONS_UNSET, options: OPTIONS_UNSET, progress: nil, engine_factory: nil)
|
|
18
|
+
positional_given = !positional_options.equal?(OPTIONS_UNSET)
|
|
19
|
+
keyword_given = !options.equal?(OPTIONS_UNSET)
|
|
20
|
+
raise ArgumentError, "options must be supplied either positionally or by keyword, not both" if positional_given && keyword_given
|
|
21
|
+
|
|
22
|
+
selected_options = keyword_given ? options : positional_options
|
|
23
|
+
selected_options = nil if selected_options.equal?(OPTIONS_UNSET)
|
|
24
|
+
@options = selected_options.nil? ? TranscriptionOptions.new : selected_options
|
|
25
|
+
raise TypeError, "options must be a TranscriptionOptions instance" unless @options.is_a?(TranscriptionOptions)
|
|
26
|
+
raise TypeError, "progress must be callable or nil" if !progress.nil? && !progress.respond_to?(:call)
|
|
27
|
+
|
|
28
|
+
@progress = progress
|
|
29
|
+
@engine_factory = if engine_factory.nil?
|
|
30
|
+
lambda do
|
|
31
|
+
Loader.load_runtime!
|
|
32
|
+
Runtime::Engine.new(@options, progress: @progress)
|
|
33
|
+
end
|
|
34
|
+
else
|
|
35
|
+
engine_factory
|
|
36
|
+
end
|
|
37
|
+
@implementation = nil
|
|
38
|
+
@lock = Mutex.new
|
|
39
|
+
@closed = false
|
|
40
|
+
@closing = false
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def transcribe(audio, raise_on_error: false)
|
|
44
|
+
started = monotonic
|
|
45
|
+
normalized = Input.normalize(audio)
|
|
46
|
+
implementation, import_seconds, wait_seconds = implementation()
|
|
47
|
+
run = implementation.transcribe(
|
|
48
|
+
normalized,
|
|
49
|
+
raise_on_error: raise_on_error,
|
|
50
|
+
runtime_import_seconds: import_seconds,
|
|
51
|
+
serialization_wait_seconds: wait_seconds
|
|
52
|
+
)
|
|
53
|
+
with_elapsed(run, monotonic - started)
|
|
54
|
+
rescue BatchTranscriptionError => e
|
|
55
|
+
raise BatchTranscriptionError.new(with_elapsed(e.run, monotonic - started))
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def close
|
|
59
|
+
implementation = @lock.synchronize do
|
|
60
|
+
return if @closed
|
|
61
|
+
raise TranscriberBusyError, "This Transcriber is already being closed" if @closing
|
|
62
|
+
|
|
63
|
+
@closing = true
|
|
64
|
+
@implementation
|
|
65
|
+
end
|
|
66
|
+
begin
|
|
67
|
+
implementation&.close
|
|
68
|
+
rescue Exception
|
|
69
|
+
@lock.synchronize do
|
|
70
|
+
@closing = false
|
|
71
|
+
end
|
|
72
|
+
raise
|
|
73
|
+
end
|
|
74
|
+
@lock.synchronize do
|
|
75
|
+
@closed = true
|
|
76
|
+
@closing = false
|
|
77
|
+
@implementation = nil if @implementation.equal?(implementation)
|
|
78
|
+
end
|
|
79
|
+
nil
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def closed?
|
|
83
|
+
@closed
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def self.open(...)
|
|
87
|
+
transcriber = new(...)
|
|
88
|
+
return transcriber unless block_given?
|
|
89
|
+
|
|
90
|
+
begin
|
|
91
|
+
yield transcriber
|
|
92
|
+
ensure
|
|
93
|
+
transcriber.close
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
private
|
|
98
|
+
|
|
99
|
+
def implementation
|
|
100
|
+
started = monotonic
|
|
101
|
+
@lock.synchronize do
|
|
102
|
+
wait_seconds = monotonic - started
|
|
103
|
+
raise TranscriberClosedError, "This Transcriber has been closed" if @closed
|
|
104
|
+
raise TranscriberBusyError, "This Transcriber is being closed" if @closing
|
|
105
|
+
|
|
106
|
+
import_seconds = 0.0
|
|
107
|
+
unless @implementation
|
|
108
|
+
import_started = monotonic
|
|
109
|
+
@implementation = @engine_factory.call
|
|
110
|
+
unless @implementation.respond_to?(:transcribe) && @implementation.respond_to?(:close)
|
|
111
|
+
@implementation = nil
|
|
112
|
+
raise TranscriptionRuntimeError, "engine_factory returned an invalid transcription engine"
|
|
113
|
+
end
|
|
114
|
+
import_seconds = monotonic - import_started
|
|
115
|
+
end
|
|
116
|
+
[@implementation, import_seconds, wait_seconds]
|
|
117
|
+
end
|
|
118
|
+
rescue TranscriptionError
|
|
119
|
+
raise
|
|
120
|
+
rescue SystemExit => e
|
|
121
|
+
detail = e.message.to_s
|
|
122
|
+
detail = "Transcription runtime initialization failed" if detail.empty? || detail == "SystemExit"
|
|
123
|
+
raise TranscriptionRuntimeError, detail
|
|
124
|
+
rescue ScriptError => e
|
|
125
|
+
raise TranscriptionRuntimeError,
|
|
126
|
+
"Cannot initialize the transcription runtime: #{e.class}: #{e.message}"
|
|
127
|
+
rescue StandardError => e
|
|
128
|
+
raise TranscriptionRuntimeError,
|
|
129
|
+
"Cannot initialize the transcription runtime: #{e.class}: #{e.message}"
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def with_elapsed(run, elapsed)
|
|
133
|
+
statistics = run.statistics.with(
|
|
134
|
+
elapsed_seconds: elapsed,
|
|
135
|
+
real_time_factor_x: elapsed.positive? ? run.statistics.successful_audio_seconds / elapsed : 0.0
|
|
136
|
+
)
|
|
137
|
+
run.with(statistics: statistics)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def monotonic
|
|
141
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
module_function
|
|
146
|
+
|
|
147
|
+
def transcribe(audio, options: nil, progress: nil, raise_on_error: false)
|
|
148
|
+
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
149
|
+
transcriber = Transcriber.new(options, progress: progress)
|
|
150
|
+
run = nil
|
|
151
|
+
batch_error = nil
|
|
152
|
+
begin
|
|
153
|
+
begin
|
|
154
|
+
run = transcriber.transcribe(audio, raise_on_error: raise_on_error)
|
|
155
|
+
rescue BatchTranscriptionError => e
|
|
156
|
+
batch_error = e
|
|
157
|
+
end
|
|
158
|
+
ensure
|
|
159
|
+
transcriber.close
|
|
160
|
+
end
|
|
161
|
+
elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started
|
|
162
|
+
selected = batch_error ? batch_error.run : run
|
|
163
|
+
statistics = selected.statistics.with(
|
|
164
|
+
elapsed_seconds: elapsed,
|
|
165
|
+
real_time_factor_x: elapsed.positive? ? selected.statistics.successful_audio_seconds / elapsed : 0.0
|
|
166
|
+
)
|
|
167
|
+
selected = selected.with(statistics: statistics)
|
|
168
|
+
raise BatchTranscriptionError.new(selected) if batch_error
|
|
169
|
+
|
|
170
|
+
selected
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Cohere
|
|
4
|
+
module Transcribe
|
|
5
|
+
module ASR
|
|
6
|
+
# Mutable, run-local telemetry for native ASR batching. The public
|
|
7
|
+
# statistics object intentionally remains immutable; Engine copies these
|
|
8
|
+
# counters into it after a group completes.
|
|
9
|
+
class BatchTelemetry
|
|
10
|
+
attr_accessor :asr_batches,
|
|
11
|
+
:processor_rows,
|
|
12
|
+
:generated_tokens,
|
|
13
|
+
:oom_retries,
|
|
14
|
+
:effective_batch_min,
|
|
15
|
+
:effective_batch_max,
|
|
16
|
+
:final_batch_size,
|
|
17
|
+
:final_batch_cap,
|
|
18
|
+
:feature_worker_seconds,
|
|
19
|
+
:h2d_seconds,
|
|
20
|
+
:generate_device_seconds,
|
|
21
|
+
:generation_analysis_seconds
|
|
22
|
+
attr_reader :batch_history
|
|
23
|
+
|
|
24
|
+
def initialize
|
|
25
|
+
@asr_batches = 0
|
|
26
|
+
@processor_rows = 0
|
|
27
|
+
@generated_tokens = 0
|
|
28
|
+
@oom_retries = 0
|
|
29
|
+
@effective_batch_min = 0
|
|
30
|
+
@effective_batch_max = 0
|
|
31
|
+
@final_batch_size = 0
|
|
32
|
+
@final_batch_cap = 0
|
|
33
|
+
@feature_worker_seconds = 0.0
|
|
34
|
+
@h2d_seconds = 0.0
|
|
35
|
+
@generate_device_seconds = 0.0
|
|
36
|
+
@generation_analysis_seconds = 0.0
|
|
37
|
+
@batch_history = []
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def record_success(rows, max_new_tokens:, generated_tokens: 0, generated_tokens_by_row: [],
|
|
41
|
+
generation_call_wall_seconds: nil, padded_audio_seconds: nil,
|
|
42
|
+
native_metrics: nil)
|
|
43
|
+
prepare_seconds = native_metrics && (
|
|
44
|
+
native_metrics.fetch(:feature_wall_seconds, 0.0) +
|
|
45
|
+
native_metrics.fetch(:mel_pack_seconds, 0.0)
|
|
46
|
+
)
|
|
47
|
+
h2d_seconds = native_metrics&.fetch(:encoder_input_seconds, nil)
|
|
48
|
+
generate_device_seconds = native_metrics && (
|
|
49
|
+
native_metrics.fetch(:encoder_compute_seconds, 0.0) +
|
|
50
|
+
native_metrics.fetch(:decoder_total_seconds, 0.0)
|
|
51
|
+
)
|
|
52
|
+
generation_analysis_seconds = native_metrics&.fetch(:render_seconds, nil)
|
|
53
|
+
@asr_batches += 1
|
|
54
|
+
@processor_rows += rows
|
|
55
|
+
@generated_tokens += generated_tokens
|
|
56
|
+
@effective_batch_min = @effective_batch_min.zero? ? rows : [@effective_batch_min, rows].min
|
|
57
|
+
@effective_batch_max = [@effective_batch_max, rows].max
|
|
58
|
+
@feature_worker_seconds += prepare_seconds.to_f
|
|
59
|
+
@h2d_seconds += h2d_seconds.to_f
|
|
60
|
+
@generate_device_seconds += generate_device_seconds.to_f
|
|
61
|
+
@generation_analysis_seconds += generation_analysis_seconds.to_f
|
|
62
|
+
@batch_history << {
|
|
63
|
+
"segments" => rows,
|
|
64
|
+
"processor_rows" => rows,
|
|
65
|
+
"max_new_tokens" => max_new_tokens,
|
|
66
|
+
"generated_tokens" => generated_tokens,
|
|
67
|
+
"generated_tokens_by_row" => generated_tokens_by_row.freeze,
|
|
68
|
+
"prepare_seconds" => prepare_seconds,
|
|
69
|
+
"h2d_seconds" => h2d_seconds,
|
|
70
|
+
"generation_call_wall_seconds" => generation_call_wall_seconds,
|
|
71
|
+
"generate_device_seconds" => generate_device_seconds,
|
|
72
|
+
"generation_analysis_seconds" => generation_analysis_seconds,
|
|
73
|
+
"padded_audio_seconds" => padded_audio_seconds
|
|
74
|
+
}.freeze
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def record_oom(rows, max_new_tokens:)
|
|
78
|
+
@oom_retries += 1
|
|
79
|
+
@batch_history << {
|
|
80
|
+
"event" => "oom",
|
|
81
|
+
"segments" => rows,
|
|
82
|
+
"max_new_tokens" => max_new_tokens
|
|
83
|
+
}.freeze
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def finalize(controller)
|
|
87
|
+
@final_batch_size = controller.current_size
|
|
88
|
+
@final_batch_cap = controller.max_size
|
|
89
|
+
self
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Persistent batch-size controller. OOM learning and fatal circuit state
|
|
94
|
+
# live with the retained native session, not with one audio file.
|
|
95
|
+
class BatchController
|
|
96
|
+
DEVICE_DEFAULTS = { "cuda" => 24, "mps" => 8, "cpu" => 4 }.freeze
|
|
97
|
+
|
|
98
|
+
attr_reader :adaptive,
|
|
99
|
+
:audio_budget_seconds,
|
|
100
|
+
:initial_size,
|
|
101
|
+
:max_size,
|
|
102
|
+
:memory_budget_bytes,
|
|
103
|
+
:target_memory_ratio,
|
|
104
|
+
:total_memory_bytes
|
|
105
|
+
attr_accessor :circuit_breaker_error, :current_size, :growth_cooldown
|
|
106
|
+
|
|
107
|
+
def self.create(options, device:, durations:, memory: nil, physical_max: nil)
|
|
108
|
+
default_initial = DEVICE_DEFAULTS.fetch(device.to_s, DEVICE_DEFAULTS.fetch("cpu"))
|
|
109
|
+
requested_initial = options.batch_size || if options.batch_max_size
|
|
110
|
+
[default_initial, options.batch_max_size].min
|
|
111
|
+
else
|
|
112
|
+
default_initial
|
|
113
|
+
end
|
|
114
|
+
initial = physical_max ? [requested_initial, physical_max].min : requested_initial
|
|
115
|
+
free_bytes, total_bytes = memory || [0, 0]
|
|
116
|
+
free_bytes = Integer(free_bytes)
|
|
117
|
+
total_bytes = Integer(total_bytes)
|
|
118
|
+
requested_maximum = if !options.adaptive_batch
|
|
119
|
+
requested_initial
|
|
120
|
+
elsif options.batch_max_size
|
|
121
|
+
options.batch_max_size
|
|
122
|
+
elsif options.batch_size
|
|
123
|
+
options.batch_size
|
|
124
|
+
elsif device.to_s == "cuda"
|
|
125
|
+
total_gib = total_bytes.fdiv(1024**3)
|
|
126
|
+
[requested_initial, [128, (total_gib * 4).to_i].min].max
|
|
127
|
+
else
|
|
128
|
+
default_initial
|
|
129
|
+
end
|
|
130
|
+
maximum = [requested_initial, requested_maximum].max
|
|
131
|
+
maximum = [maximum, physical_max].min if physical_max
|
|
132
|
+
maximum = [initial, maximum].max
|
|
133
|
+
longest = durations.map { |duration| Float(duration) }.max || 1.0
|
|
134
|
+
audio_budget = options.batch_audio_seconds || (initial * [longest, 0.25].max)
|
|
135
|
+
|
|
136
|
+
used_bytes = [total_bytes - free_bytes, 0].max
|
|
137
|
+
memory_budget = if device.to_s == "cuda" && total_bytes.positive?
|
|
138
|
+
[
|
|
139
|
+
(options.batch_vram_target * total_bytes).to_i,
|
|
140
|
+
used_bytes + (0.95 * free_bytes).to_i
|
|
141
|
+
].min
|
|
142
|
+
else
|
|
143
|
+
0
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
new(
|
|
147
|
+
current_size: initial,
|
|
148
|
+
max_size: maximum,
|
|
149
|
+
initial_size: initial,
|
|
150
|
+
audio_budget_seconds: audio_budget,
|
|
151
|
+
adaptive: options.adaptive_batch,
|
|
152
|
+
target_memory_ratio: options.batch_vram_target,
|
|
153
|
+
total_memory_bytes: total_bytes,
|
|
154
|
+
memory_budget_bytes: memory_budget
|
|
155
|
+
)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def initialize(current_size:, max_size:, initial_size:, audio_budget_seconds:, adaptive:,
|
|
159
|
+
target_memory_ratio:, total_memory_bytes: 0, memory_budget_bytes: 0)
|
|
160
|
+
@current_size = positive_integer(current_size, "current_size")
|
|
161
|
+
@max_size = positive_integer(max_size, "max_size")
|
|
162
|
+
@initial_size = positive_integer(initial_size, "initial_size")
|
|
163
|
+
raise ArgumentError, "max_size must be at least current_size" if @max_size < @current_size
|
|
164
|
+
|
|
165
|
+
@audio_budget_seconds = Float(audio_budget_seconds)
|
|
166
|
+
raise ArgumentError, "audio_budget_seconds must be positive" unless @audio_budget_seconds.positive?
|
|
167
|
+
|
|
168
|
+
raise ArgumentError, "adaptive must be a boolean" unless [true, false].include?(adaptive)
|
|
169
|
+
|
|
170
|
+
@adaptive = adaptive
|
|
171
|
+
@target_memory_ratio = Float(target_memory_ratio)
|
|
172
|
+
@total_memory_bytes = Integer(total_memory_bytes)
|
|
173
|
+
@memory_budget_bytes = Integer(memory_budget_bytes)
|
|
174
|
+
@growth_cooldown = 0
|
|
175
|
+
@circuit_breaker_error = nil
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def configure_group(options, durations)
|
|
179
|
+
longest = durations.map { |duration| Float(duration) }.max || 1.0
|
|
180
|
+
@audio_budget_seconds = options.batch_audio_seconds || (@initial_size * [longest, 0.25].max)
|
|
181
|
+
self
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def take_count(rows)
|
|
185
|
+
return 0 if rows.empty?
|
|
186
|
+
|
|
187
|
+
longest = [yield(rows.first), 1.0 / SAMPLE_RATE].max
|
|
188
|
+
frame_limited = [(@audio_budget_seconds / longest).floor, 1].max
|
|
189
|
+
[rows.length, @current_size, frame_limited].min
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def record_oom(attempted_rows)
|
|
193
|
+
rows = positive_integer(attempted_rows, "attempted_rows")
|
|
194
|
+
@growth_cooldown = [@growth_cooldown, 2].max
|
|
195
|
+
if rows <= 1
|
|
196
|
+
@current_size = 1
|
|
197
|
+
return self
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
@max_size = [@max_size, rows - 1].min
|
|
201
|
+
@current_size = [1, [@max_size, rows / 2].min].max
|
|
202
|
+
self
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def record_success(attempted_rows, baseline_reserved_bytes: 0, peak_reserved_bytes: 0)
|
|
206
|
+
rows = positive_integer(attempted_rows, "attempted_rows")
|
|
207
|
+
if @growth_cooldown.positive?
|
|
208
|
+
@growth_cooldown -= 1
|
|
209
|
+
return self
|
|
210
|
+
end
|
|
211
|
+
return self unless @adaptive && @current_size < @max_size && rows >= @current_size
|
|
212
|
+
return self unless @total_memory_bytes.positive? && peak_reserved_bytes.positive?
|
|
213
|
+
|
|
214
|
+
budget = @memory_budget_bytes.positive? ? @memory_budget_bytes : (@target_memory_ratio * @total_memory_bytes).to_i
|
|
215
|
+
headroom = (budget - peak_reserved_bytes).fdiv(@total_memory_bytes)
|
|
216
|
+
return self if headroom <= 0.05
|
|
217
|
+
|
|
218
|
+
factor = headroom >= 0.20 ? 1.25 : 1.125
|
|
219
|
+
proposed = [@current_size + 1, (@current_size * factor).ceil].max
|
|
220
|
+
incremental = [1, peak_reserved_bytes - baseline_reserved_bytes].max
|
|
221
|
+
available = [0, budget - baseline_reserved_bytes].max
|
|
222
|
+
memory_estimate = (rows * available).div(incremental)
|
|
223
|
+
proposed = [proposed, [@current_size, memory_estimate].max].min if memory_estimate.positive?
|
|
224
|
+
@current_size = [@max_size, proposed].min
|
|
225
|
+
self
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def open_circuit(error)
|
|
229
|
+
return @circuit_breaker_error if @circuit_breaker_error
|
|
230
|
+
|
|
231
|
+
@circuit_breaker_error = FailurePolicy.fingerprint(error)
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def circuit_open?
|
|
235
|
+
!@circuit_breaker_error.nil?
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
private
|
|
239
|
+
|
|
240
|
+
def positive_integer(value, field)
|
|
241
|
+
integer = Integer(value)
|
|
242
|
+
raise ArgumentError, "#{field} must be positive" unless integer.positive?
|
|
243
|
+
|
|
244
|
+
integer
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
# A batch cap scoped to higher-token truncation retries. An OOM here must
|
|
249
|
+
# not reduce the ordinary ASR controller learned from the base limit.
|
|
250
|
+
class RetryBatchCap
|
|
251
|
+
attr_reader :current_size
|
|
252
|
+
|
|
253
|
+
def initialize(current_size)
|
|
254
|
+
@current_size = Integer(current_size)
|
|
255
|
+
raise ArgumentError, "current_size must be positive" unless @current_size.positive?
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def record_oom(attempted_rows)
|
|
259
|
+
rows = Integer(attempted_rows)
|
|
260
|
+
proposed = rows > 1 ? rows / 2 : 1
|
|
261
|
+
@current_size = [1, [@current_size, proposed].min].max
|
|
262
|
+
self
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
BatchExecutionResult = Data.define(:values, :errors, :telemetry) do
|
|
267
|
+
def success?
|
|
268
|
+
errors.all?(&:nil?)
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
# Generic recursive recovery around a native batch operation. Results
|
|
273
|
+
# remain in input order, data-local failures are isolated, fatal failures
|
|
274
|
+
# open a persistent circuit, and learned caps are honored by siblings that
|
|
275
|
+
# have not yet been attempted.
|
|
276
|
+
class BatchExecutor
|
|
277
|
+
attr_reader :telemetry
|
|
278
|
+
|
|
279
|
+
def initialize(controller, duration: nil, memory: nil, operation_metrics: nil, telemetry: BatchTelemetry.new)
|
|
280
|
+
@controller = controller
|
|
281
|
+
@duration = duration || method(:default_duration)
|
|
282
|
+
@memory = memory
|
|
283
|
+
@operation_metrics = operation_metrics
|
|
284
|
+
@telemetry = telemetry
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def execute(rows, max_new_tokens:, base_max_new_tokens:, retry_cap: nil, &operation)
|
|
288
|
+
raise ArgumentError, "a native batch operation block is required" unless operation
|
|
289
|
+
|
|
290
|
+
source = rows.to_a
|
|
291
|
+
values = Array.new(source.length)
|
|
292
|
+
errors = Array.new(source.length)
|
|
293
|
+
indexed = source.each_with_index.map { |row, index| [index, row] }
|
|
294
|
+
high_token_retry = max_new_tokens > base_max_new_tokens
|
|
295
|
+
retry_cap ||= RetryBatchCap.new([source.length, 1].max) if high_token_retry
|
|
296
|
+
process(
|
|
297
|
+
indexed,
|
|
298
|
+
values,
|
|
299
|
+
errors,
|
|
300
|
+
max_new_tokens: max_new_tokens,
|
|
301
|
+
high_token_retry: high_token_retry,
|
|
302
|
+
retry_cap: retry_cap,
|
|
303
|
+
operation: operation
|
|
304
|
+
)
|
|
305
|
+
@telemetry.finalize(@controller)
|
|
306
|
+
BatchExecutionResult.new(values: values.freeze, errors: errors.freeze, telemetry: @telemetry)
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
private
|
|
310
|
+
|
|
311
|
+
def process(indexed, values, errors, max_new_tokens:, high_token_retry:, retry_cap:, operation:)
|
|
312
|
+
return if indexed.empty?
|
|
313
|
+
|
|
314
|
+
if @controller.circuit_open?
|
|
315
|
+
error = CircuitOpenError.new(@controller.circuit_breaker_error)
|
|
316
|
+
indexed.each { |pair| errors[pair.first] = error }
|
|
317
|
+
return
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
effective_cap = high_token_retry ? retry_cap.current_size : @controller.current_size
|
|
321
|
+
if indexed.length > effective_cap
|
|
322
|
+
indexed.each_slice([effective_cap, 1].max) do |slice|
|
|
323
|
+
process(
|
|
324
|
+
slice,
|
|
325
|
+
values,
|
|
326
|
+
errors,
|
|
327
|
+
max_new_tokens: max_new_tokens,
|
|
328
|
+
high_token_retry: high_token_retry,
|
|
329
|
+
retry_cap: retry_cap,
|
|
330
|
+
operation: operation
|
|
331
|
+
)
|
|
332
|
+
end
|
|
333
|
+
return
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
rows = indexed.map(&:last)
|
|
337
|
+
memory_before = memory_snapshot
|
|
338
|
+
operation_started = monotonic
|
|
339
|
+
output = operation.call(rows)
|
|
340
|
+
operation_seconds = monotonic - operation_started
|
|
341
|
+
native_metrics = @operation_metrics&.call
|
|
342
|
+
memory_after = memory_snapshot
|
|
343
|
+
unless output.is_a?(Array) && output.length == rows.length
|
|
344
|
+
raise ExecutionError.new(
|
|
345
|
+
"Native Cohere batch returned #{output.respond_to?(:length) ? output.length : "a non-array result"} " \
|
|
346
|
+
"for #{rows.length} inputs",
|
|
347
|
+
failure_kind: :fatal
|
|
348
|
+
)
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
indexed.each_with_index { |(index, _row), lane| values[index] = output.fetch(lane) }
|
|
352
|
+
generated_tokens_by_row = output.map do |value|
|
|
353
|
+
value.respond_to?(:generated_tokens) ? Integer(value.generated_tokens) : 0
|
|
354
|
+
end
|
|
355
|
+
generated_tokens = generated_tokens_by_row.sum
|
|
356
|
+
@telemetry.record_success(
|
|
357
|
+
rows.length,
|
|
358
|
+
max_new_tokens: max_new_tokens,
|
|
359
|
+
generated_tokens: generated_tokens,
|
|
360
|
+
generated_tokens_by_row: generated_tokens_by_row,
|
|
361
|
+
generation_call_wall_seconds: operation_seconds,
|
|
362
|
+
padded_audio_seconds: rows.length * rows.map { |row| Float(@duration.call(row)) }.max.to_f,
|
|
363
|
+
native_metrics: native_metrics
|
|
364
|
+
)
|
|
365
|
+
baseline_reserved, peak_reserved = reserved_memory(memory_before, memory_after)
|
|
366
|
+
@controller.record_success(
|
|
367
|
+
rows.length,
|
|
368
|
+
baseline_reserved_bytes: baseline_reserved,
|
|
369
|
+
peak_reserved_bytes: peak_reserved
|
|
370
|
+
)
|
|
371
|
+
rescue NoMemoryError, SystemStackError, ScriptError, StandardError => e
|
|
372
|
+
handle_failure(
|
|
373
|
+
e,
|
|
374
|
+
indexed,
|
|
375
|
+
values,
|
|
376
|
+
errors,
|
|
377
|
+
max_new_tokens: max_new_tokens,
|
|
378
|
+
high_token_retry: high_token_retry,
|
|
379
|
+
retry_cap: retry_cap,
|
|
380
|
+
operation: operation
|
|
381
|
+
)
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
def handle_failure(error, indexed, values, errors, max_new_tokens:, high_token_retry:, retry_cap:, operation:)
|
|
385
|
+
kind = FailurePolicy.classify(error)
|
|
386
|
+
if kind == :fatal
|
|
387
|
+
@controller.open_circuit(error)
|
|
388
|
+
indexed.each { |pair| errors[pair.first] = error }
|
|
389
|
+
return
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
if kind == :oom
|
|
393
|
+
@telemetry.record_oom(indexed.length, max_new_tokens: max_new_tokens)
|
|
394
|
+
if high_token_retry
|
|
395
|
+
retry_cap.record_oom(indexed.length)
|
|
396
|
+
else
|
|
397
|
+
@controller.record_oom(indexed.length)
|
|
398
|
+
end
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
if indexed.length == 1
|
|
402
|
+
errors[indexed.first.first] = error
|
|
403
|
+
return
|
|
404
|
+
end
|
|
405
|
+
|
|
406
|
+
split = kind == :oom ? balanced_split(indexed.map(&:last)) : indexed.length / 2
|
|
407
|
+
[indexed.first(split), indexed.drop(split)].each do |half|
|
|
408
|
+
process(
|
|
409
|
+
half,
|
|
410
|
+
values,
|
|
411
|
+
errors,
|
|
412
|
+
max_new_tokens: max_new_tokens,
|
|
413
|
+
high_token_retry: high_token_retry,
|
|
414
|
+
retry_cap: retry_cap,
|
|
415
|
+
operation: operation
|
|
416
|
+
)
|
|
417
|
+
end
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
def balanced_split(rows)
|
|
421
|
+
return 1 if rows.length < 2
|
|
422
|
+
|
|
423
|
+
first_duration = Float(@duration.call(rows.first))
|
|
424
|
+
best_index = rows.length / 2
|
|
425
|
+
best_cost = Float::INFINITY
|
|
426
|
+
(1...rows.length).each do |index|
|
|
427
|
+
left_cost = index * first_duration
|
|
428
|
+
right_cost = (rows.length - index) * Float(@duration.call(rows.fetch(index)))
|
|
429
|
+
cost = [left_cost, right_cost].max
|
|
430
|
+
if cost < best_cost
|
|
431
|
+
best_cost = cost
|
|
432
|
+
best_index = index
|
|
433
|
+
end
|
|
434
|
+
end
|
|
435
|
+
best_index
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
def default_duration(row)
|
|
439
|
+
return row.fetch(:duration) if row.respond_to?(:fetch)
|
|
440
|
+
return row.duration if row.respond_to?(:duration)
|
|
441
|
+
|
|
442
|
+
1.0
|
|
443
|
+
end
|
|
444
|
+
|
|
445
|
+
def memory_snapshot
|
|
446
|
+
return nil unless @memory
|
|
447
|
+
|
|
448
|
+
free_bytes, total_bytes = @memory.call
|
|
449
|
+
free_bytes = Integer(free_bytes)
|
|
450
|
+
total_bytes = Integer(total_bytes)
|
|
451
|
+
return nil unless free_bytes >= 0 && total_bytes.positive? && free_bytes <= total_bytes
|
|
452
|
+
|
|
453
|
+
[free_bytes, total_bytes]
|
|
454
|
+
rescue StandardError
|
|
455
|
+
nil
|
|
456
|
+
end
|
|
457
|
+
|
|
458
|
+
def reserved_memory(before, after)
|
|
459
|
+
samples = [before, after].compact
|
|
460
|
+
return [0, 0] if samples.empty?
|
|
461
|
+
|
|
462
|
+
used = samples.map { |free_bytes, total_bytes| total_bytes - free_bytes }
|
|
463
|
+
[used.first, used.max]
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
def monotonic
|
|
467
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
468
|
+
end
|
|
469
|
+
end
|
|
470
|
+
end
|
|
471
|
+
end
|
|
472
|
+
end
|