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,327 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <stddef.h>
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
#include <stdbool.h>
|
|
6
|
+
|
|
7
|
+
#ifdef __cplusplus
|
|
8
|
+
extern "C" {
|
|
9
|
+
#endif
|
|
10
|
+
|
|
11
|
+
struct cohere_context;
|
|
12
|
+
|
|
13
|
+
// Thread-local diagnostic for C entry points that otherwise return NULL. The
|
|
14
|
+
// message remains valid until the next Cohere call on the same thread.
|
|
15
|
+
enum cohere_error_kind {
|
|
16
|
+
COHERE_ERROR_NONE = 0,
|
|
17
|
+
COHERE_ERROR_INVALID_ARGUMENT = 1,
|
|
18
|
+
COHERE_ERROR_OUT_OF_MEMORY = 2,
|
|
19
|
+
COHERE_ERROR_INVARIANT = 3,
|
|
20
|
+
COHERE_ERROR_RUNTIME = 4,
|
|
21
|
+
COHERE_ERROR_CANCELLED = 5,
|
|
22
|
+
};
|
|
23
|
+
enum cohere_error_kind cohere_last_error_kind(void);
|
|
24
|
+
const char* cohere_last_error_message(void);
|
|
25
|
+
|
|
26
|
+
struct cohere_context_params {
|
|
27
|
+
int n_threads; // default: number of physical cores
|
|
28
|
+
bool use_flash; // flash attention in decoder (default: false for now)
|
|
29
|
+
bool use_gpu; // false => force CPU backend
|
|
30
|
+
bool no_punctuation; // use <|nopnc|> instead of <|pnc|> in prompt (default: false)
|
|
31
|
+
bool diarize; // use <|diarize|> instead of <|nodiarize|>; model may emit
|
|
32
|
+
// <|spkchange|> and <|spk0|>..<|spk15|> tokens (experimental)
|
|
33
|
+
bool collect_alignment; // collect decoder cross-attention for native token timestamps
|
|
34
|
+
// (default: true; disable for text-only inference)
|
|
35
|
+
// Output verbosity:
|
|
36
|
+
// 0 = silent — only hard errors (failed/cannot) go to stderr
|
|
37
|
+
// 1 = normal — model loading info printed (default)
|
|
38
|
+
// 2 = verbose — per-inference timing, per-step tokens, performance report
|
|
39
|
+
int verbosity;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
struct cohere_context_params cohere_context_default_params(void);
|
|
43
|
+
|
|
44
|
+
// Load model from GGUF file produced by export_gguf.py
|
|
45
|
+
struct cohere_context* cohere_init_from_file(const char* path_model, struct cohere_context_params params);
|
|
46
|
+
|
|
47
|
+
void cohere_free(struct cohere_context* ctx);
|
|
48
|
+
|
|
49
|
+
// Cooperative, context-local inference cancellation. The callback may run on
|
|
50
|
+
// ggml worker threads and therefore must be thread-safe, non-blocking, and must
|
|
51
|
+
// not call back into Cohere/ggml. CPU and Metal graph execution use their
|
|
52
|
+
// native abort hooks; every backend is also checked between bounded inference
|
|
53
|
+
// stages and autoregressive decoder steps. Passing NULL removes the callback.
|
|
54
|
+
typedef bool (*cohere_abort_callback)(void* user_data);
|
|
55
|
+
void cohere_set_abort_callback(struct cohere_context* ctx, cohere_abort_callback callback, void* user_data);
|
|
56
|
+
|
|
57
|
+
// Report currently available and total memory for the selected ggml backend
|
|
58
|
+
// device. Values are zero when a backend cannot provide memory telemetry.
|
|
59
|
+
void cohere_backend_memory(struct cohere_context* ctx, size_t* free_bytes, size_t* total_bytes);
|
|
60
|
+
|
|
61
|
+
// Name of the ggml backend that owns the model weights (for example CPU,
|
|
62
|
+
// CUDA0, or Metal). The returned pointer is owned by ggml and remains valid
|
|
63
|
+
// for the lifetime of the context. This lets embedding runtimes report and
|
|
64
|
+
// enforce the device that was actually selected instead of trusting a request
|
|
65
|
+
// that may have fallen back during backend initialization.
|
|
66
|
+
const char* cohere_backend_name(struct cohere_context* ctx);
|
|
67
|
+
|
|
68
|
+
// Transcribe raw 16 kHz mono PCM.
|
|
69
|
+
// Returns a newly allocated UTF-8 string (caller must free()).
|
|
70
|
+
// lang: ISO-639-1 code e.g. "en", "fr", "de" (NULL → autodetect, not implemented yet)
|
|
71
|
+
char* cohere_transcribe(struct cohere_context* ctx, const float* samples, int n_samples, const char* lang);
|
|
72
|
+
|
|
73
|
+
// Vocabulary helpers
|
|
74
|
+
int cohere_n_vocab(struct cohere_context* ctx);
|
|
75
|
+
const char* cohere_token_to_str(struct cohere_context* ctx, int token_id);
|
|
76
|
+
int cohere_str_to_token(struct cohere_context* ctx, const char* str);
|
|
77
|
+
|
|
78
|
+
// Sampling: temperature > 0 enables stable softmax sampling in the
|
|
79
|
+
// transformer decoder. Default 0 keeps the bit-identical greedy path.
|
|
80
|
+
// Sticky on the context until the next call.
|
|
81
|
+
void cohere_set_temperature(struct cohere_context* ctx, float temperature, uint64_t seed);
|
|
82
|
+
void cohere_set_max_new_tokens(struct cohere_context* ctx, int max_new_tokens);
|
|
83
|
+
void cohere_set_frequency_penalty(struct cohere_context* ctx, float frequency_penalty);
|
|
84
|
+
// Stop greedy generation when the generated suffix contains four immediately
|
|
85
|
+
// repeated 8..32-token blocks after at least 96 generated tokens. This matches
|
|
86
|
+
// the conservative Transformers stopping criterion used by cohere-transcribe.
|
|
87
|
+
void cohere_set_repetition_loop_guard(struct cohere_context* ctx, bool enabled);
|
|
88
|
+
|
|
89
|
+
// Enable or disable native token-timestamp alignment. When disabled, the
|
|
90
|
+
// decoder skips the extra cross-attention graph output and device-to-host
|
|
91
|
+
// copies; returned token times fall back to linear interpolation. Sticky on
|
|
92
|
+
// the context until changed. Enabled by default.
|
|
93
|
+
void cohere_set_alignment_collection(struct cohere_context* ctx, bool enabled);
|
|
94
|
+
|
|
95
|
+
// §90 beam-search width. n > 1 activates beam search; n <= 0 clamped to 1 (greedy).
|
|
96
|
+
void cohere_set_beam_size(struct cohere_context* ctx, int n);
|
|
97
|
+
|
|
98
|
+
// ---- Extended API: per-token confidence and timing ----
|
|
99
|
+
|
|
100
|
+
// Per-token data returned by cohere_transcribe_ex().
|
|
101
|
+
struct cohere_token_data {
|
|
102
|
+
int id; // vocabulary token ID
|
|
103
|
+
char text[64]; // decoded text (SentencePiece '▁' already converted to ' ')
|
|
104
|
+
float p; // softmax probability [0, 1]
|
|
105
|
+
int64_t t0; // start time, centiseconds (absolute, includes t_offset_cs)
|
|
106
|
+
int64_t t1; // end time, centiseconds
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// Result from cohere_transcribe_ex() — free with cohere_result_free().
|
|
110
|
+
struct cohere_result {
|
|
111
|
+
char* text; // full transcript (malloc'd)
|
|
112
|
+
struct cohere_token_data* tokens; // per-token data (malloc'd)
|
|
113
|
+
int n_tokens;
|
|
114
|
+
// Decoder-level metadata. n_tokens counts rendered tokens and can be lower
|
|
115
|
+
// than generated_tokens when special or byte-fallback pieces are consumed.
|
|
116
|
+
int generated_tokens;
|
|
117
|
+
int generation_limit;
|
|
118
|
+
int generation_capacity;
|
|
119
|
+
bool stopped_by_max_tokens;
|
|
120
|
+
bool repetition_stopped;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
void cohere_result_free(struct cohere_result* r);
|
|
124
|
+
|
|
125
|
+
// Like cohere_transcribe() but also returns per-token probability and timing.
|
|
126
|
+
//
|
|
127
|
+
// t_offset_cs: absolute start time of this audio slice, in centiseconds.
|
|
128
|
+
// Token t0/t1 values equal (t_offset_cs + interpolated_offset_within_segment).
|
|
129
|
+
// Pass 0 when processing a single file without VAD segmentation.
|
|
130
|
+
// With VAD, pass (vad_segment_t0_seconds * 100).
|
|
131
|
+
//
|
|
132
|
+
// Token times are linearly interpolated across the segment duration,
|
|
133
|
+
// proportional to each token's decoded text length (best approximation
|
|
134
|
+
// without model-native timestamp tokens).
|
|
135
|
+
//
|
|
136
|
+
// Returns NULL on failure. Free result with cohere_result_free().
|
|
137
|
+
struct cohere_result* cohere_transcribe_ex(struct cohere_context* ctx, const float* samples, int n_samples,
|
|
138
|
+
const char* lang, int64_t t_offset_cs);
|
|
139
|
+
|
|
140
|
+
// ---- Stage-level entry points (for crispasr-diff testing) ----
|
|
141
|
+
// Returns malloc'd F32 buffers the caller must free(). NULL on failure.
|
|
142
|
+
|
|
143
|
+
// Log-mel spectrogram of raw 16 kHz mono PCM, row-major (n_mels, T_mel).
|
|
144
|
+
// Applies deterministic length-seeded dither, pre-emphasis (0.97), and
|
|
145
|
+
// valid-frame-only per-feature log-mel normalization exactly as the live path.
|
|
146
|
+
float* cohere_compute_mel(struct cohere_context* ctx, const float* samples, int n_samples, int* out_n_mels,
|
|
147
|
+
int* out_T_mel);
|
|
148
|
+
|
|
149
|
+
// Run just the audio encoder on a mel spectrogram. Takes (n_mels, T_mel)
|
|
150
|
+
// row-major mel as produced by cohere_compute_mel() and returns the
|
|
151
|
+
// encoder hidden state in row-major (T_enc, d_model) where T_enc is the
|
|
152
|
+
// mel frame count after the 8x conv subsampling.
|
|
153
|
+
float* cohere_run_encoder(struct cohere_context* ctx, const float* mel, int n_mels, int T_mel, int* out_T_enc,
|
|
154
|
+
int* out_d_model);
|
|
155
|
+
|
|
156
|
+
// Timing and scheduler-memory measurements from cohere_run_encoder_batch().
|
|
157
|
+
// Times cover only the named stage and exclude model loading / mel creation.
|
|
158
|
+
struct cohere_encoder_batch_stats {
|
|
159
|
+
int64_t graph_build_us;
|
|
160
|
+
int64_t graph_alloc_us;
|
|
161
|
+
int64_t input_us;
|
|
162
|
+
int64_t compute_us;
|
|
163
|
+
int64_t readback_us;
|
|
164
|
+
size_t scheduler_bytes;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
enum cohere_encoder_batch_precision {
|
|
168
|
+
// Fold [in,T,B] to [in,T*B] so CUDA uses the existing F32 SGEMM path.
|
|
169
|
+
COHERE_ENCODER_BATCH_PRECISE = 0,
|
|
170
|
+
// Preserve native 3D batching and the fastest available tensor-core path.
|
|
171
|
+
COHERE_ENCODER_BATCH_FAST = 1,
|
|
172
|
+
// Native 3D batching with GGML_PREC_F32 accumulation/output.
|
|
173
|
+
COHERE_ENCODER_BATCH_F32_ACCUM = 2,
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// Run one encoder graph over an equal-length batch. Input and output are
|
|
177
|
+
// contiguous, lane-major row-major buffers:
|
|
178
|
+
// mel: [n_batch, T_mel, n_mels]
|
|
179
|
+
// return: [n_batch, T_enc, d_model]
|
|
180
|
+
//
|
|
181
|
+
// No padding mask is applied, so every lane must have exactly T_mel frames.
|
|
182
|
+
// Unlike the production encoder path, this test/runtime primitive does not
|
|
183
|
+
// compute decoder cross-KV tensors. The returned F32 buffer must be free()'d.
|
|
184
|
+
// This compatibility entry point uses COHERE_ENCODER_BATCH_PRECISE.
|
|
185
|
+
float* cohere_run_encoder_batch(struct cohere_context* ctx, const float* mel, int n_batch, int n_mels, int T_mel,
|
|
186
|
+
int* out_T_enc, int* out_d_model, struct cohere_encoder_batch_stats* out_stats);
|
|
187
|
+
float* cohere_run_encoder_batch_ex(struct cohere_context* ctx, const float* mel, int n_batch, int n_mels, int T_mel,
|
|
188
|
+
enum cohere_encoder_batch_precision precision, int* out_T_enc, int* out_d_model,
|
|
189
|
+
struct cohere_encoder_batch_stats* out_stats);
|
|
190
|
+
|
|
191
|
+
// Variable-length research batch. mel is already-normalized lane-major
|
|
192
|
+
// [n_batch, T_mel_max, n_mels]; valid_T_mel supplies each unpadded length.
|
|
193
|
+
// Returns zero-padded [n_batch, T_enc_max, 1024] and writes n_batch valid
|
|
194
|
+
// encoder lengths to out_valid_T_enc. Uses FAST projections.
|
|
195
|
+
float* cohere_run_encoder_batch_padded(struct cohere_context* ctx, const float* mel, const int* valid_T_mel,
|
|
196
|
+
int n_batch, int n_mels, int T_mel_max, int* out_valid_T_enc,
|
|
197
|
+
int* out_T_enc_max, int* out_d_model,
|
|
198
|
+
struct cohere_encoder_batch_stats* out_stats);
|
|
199
|
+
typedef void (*cohere_padded_stage_cb)(const char* name, const float* data, int ne0, int ne1, int ne2, int ne3,
|
|
200
|
+
void* userdata);
|
|
201
|
+
// CPU-oriented localization hook. Snapshot tensors retain large intermediate
|
|
202
|
+
// activations and are not part of the production batching path.
|
|
203
|
+
int cohere_run_encoder_batch_padded_staged(struct cohere_context* ctx, const float* mel, const int* valid_T_mel,
|
|
204
|
+
int n_batch, int n_mels, int T_mel_max, cohere_padded_stage_cb cb,
|
|
205
|
+
void* userdata);
|
|
206
|
+
|
|
207
|
+
// Diagnostic variant used to localize batch-vs-B1 divergence. Each callback
|
|
208
|
+
// receives one packed lane-major F32 snapshot. n_values_per_lane describes a
|
|
209
|
+
// flattened lane because convolution snapshots are 4D while encoder states
|
|
210
|
+
// are [T, d_model]. Returns 0 on success.
|
|
211
|
+
typedef void (*cohere_batch_stage_cb)(const char* name, const float* data, int n_batch, int n_values_per_lane,
|
|
212
|
+
void* userdata);
|
|
213
|
+
int cohere_run_encoder_batch_staged(struct cohere_context* ctx, const float* mel, int n_batch, int n_mels, int T_mel,
|
|
214
|
+
cohere_batch_stage_cb cb, void* userdata);
|
|
215
|
+
int cohere_run_encoder_batch_staged_ex(struct cohere_context* ctx, const float* mel, int n_batch, int n_mels,
|
|
216
|
+
int T_mel, enum cohere_encoder_batch_precision precision,
|
|
217
|
+
cohere_batch_stage_cb cb, void* userdata);
|
|
218
|
+
|
|
219
|
+
// Dump unallocated production-B1 and batched-B1 graph metadata as TSV. Each
|
|
220
|
+
// row contains the op, type, full shape, full byte strides, and tensor name.
|
|
221
|
+
// This is a graph-construction diagnostic and performs no model computation.
|
|
222
|
+
int cohere_debug_dump_encoder_b1_graphs(struct cohere_context* ctx, int T_mel, const char* production_path,
|
|
223
|
+
const char* batch_path);
|
|
224
|
+
|
|
225
|
+
// Bounded research API for validating the independent batched decoder path
|
|
226
|
+
// (B <= 24, T_enc <= 512, n_teacher_steps <= 64).
|
|
227
|
+
// encoder_states is lane-major [n_batch, T_enc, 1024]. teacher_tokens is
|
|
228
|
+
// step-major [n_teacher_steps, n_batch]. Output 0 is the last Arabic-prompt
|
|
229
|
+
// logit row; output i+1 follows teacher step i.
|
|
230
|
+
struct cohere_decoder_batch_probe_result {
|
|
231
|
+
float* logits; // [n_outputs, n_batch, vocab_size]
|
|
232
|
+
int* argmax_ids; // [n_outputs, n_batch]
|
|
233
|
+
int n_outputs;
|
|
234
|
+
int n_batch;
|
|
235
|
+
int vocab_size;
|
|
236
|
+
size_t self_cache_bytes;
|
|
237
|
+
size_t cross_cache_bytes;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
struct cohere_decoder_batch_probe_result* cohere_run_decoder_batch_probe(
|
|
241
|
+
struct cohere_context* ctx, const float* encoder_states, int n_batch, int T_enc, int d_model,
|
|
242
|
+
const int* teacher_tokens, int n_teacher_steps);
|
|
243
|
+
// Variable-length diagnostic variant. encoder_states is padded lane-major
|
|
244
|
+
// [n_batch, T_enc_max, 1024], and valid_T_enc supplies each lane's true length.
|
|
245
|
+
// Every decoder cross-attention layer masks padded keys with a finite F16 bias.
|
|
246
|
+
struct cohere_decoder_batch_probe_result* cohere_run_decoder_batch_masked_probe(
|
|
247
|
+
struct cohere_context* ctx, const float* encoder_states, const int* valid_T_enc, int n_batch, int T_enc_max,
|
|
248
|
+
int d_model, const int* teacher_tokens, int n_teacher_steps);
|
|
249
|
+
void cohere_decoder_batch_probe_result_free(struct cohere_decoder_batch_probe_result* result);
|
|
250
|
+
|
|
251
|
+
enum cohere_generation_stop_reason {
|
|
252
|
+
COHERE_GENERATION_STOP_EOS = 0,
|
|
253
|
+
COHERE_GENERATION_STOP_MAX_TOKENS = 1,
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
struct cohere_generated_sequence {
|
|
257
|
+
int* token_ids;
|
|
258
|
+
// Device-argmax generation returns 1.0 placeholders because full logits
|
|
259
|
+
// are intentionally not copied to the host in that mode.
|
|
260
|
+
float* probabilities;
|
|
261
|
+
int n_tokens;
|
|
262
|
+
enum cohere_generation_stop_reason stop_reason;
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
enum cohere_decoder_batch_output_mode {
|
|
266
|
+
COHERE_DECODER_BATCH_OUTPUT_FULL_LOGITS = 0,
|
|
267
|
+
COHERE_DECODER_BATCH_OUTPUT_DEVICE_ARGMAX = 1,
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
struct cohere_decoder_batch_generate_stats {
|
|
271
|
+
int decode_calls;
|
|
272
|
+
int generation_steps;
|
|
273
|
+
size_t logits_readback_bytes;
|
|
274
|
+
size_t self_cache_bytes;
|
|
275
|
+
size_t cross_cache_bytes;
|
|
276
|
+
int64_t cross_kv_us;
|
|
277
|
+
int64_t reserve_us;
|
|
278
|
+
int64_t decode_us;
|
|
279
|
+
int64_t total_us;
|
|
280
|
+
size_t token_id_readback_bytes;
|
|
281
|
+
enum cohere_decoder_batch_output_mode output_mode;
|
|
282
|
+
// True when COHERE_BATCH_DECODER_PERSISTENT selected an opt-in
|
|
283
|
+
// sched-free single-token replay path.
|
|
284
|
+
bool persistent_graph;
|
|
285
|
+
int persistent_graph_count;
|
|
286
|
+
int persistent_decode_calls;
|
|
287
|
+
int64_t persistent_init_us;
|
|
288
|
+
int64_t persistent_decode_us;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
struct cohere_decoder_batch_generate_result {
|
|
292
|
+
struct cohere_generated_sequence* sequences;
|
|
293
|
+
int n_batch;
|
|
294
|
+
int generation_limit;
|
|
295
|
+
int generation_capacity;
|
|
296
|
+
struct cohere_decoder_batch_generate_stats stats;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// Reliable text-only greedy generation over a padded encoder batch. This
|
|
300
|
+
// compatibility-first path reads full logits back to the host and uses the
|
|
301
|
+
// same ordered double-precision softmax as the production B1 decoder.
|
|
302
|
+
// Alignment, sampling, frequency penalty, and beam search are rejected.
|
|
303
|
+
struct cohere_decoder_batch_generate_result* cohere_run_decoder_batch_generate(
|
|
304
|
+
struct cohere_context* ctx, const float* encoder_states, const int* valid_T_enc, int n_batch, int T_enc_max,
|
|
305
|
+
int d_model, const char* lang, int max_new_tokens);
|
|
306
|
+
// Optional device-argmax variant. FULL_LOGITS preserves the exact API above.
|
|
307
|
+
// DEVICE_ARGMAX copies only one I32 token ID per physical lane and reports
|
|
308
|
+
// probability placeholders of 1.0. Exact logit ties can be backend-dependent
|
|
309
|
+
// in DEVICE_ARGMAX; FULL_LOGITS uses the lowest vocabulary ID. Set
|
|
310
|
+
// COHERE_BATCH_DECODER_PERSISTENT=1 to test one fixed-context T=1 graph, or
|
|
311
|
+
// =progressive for lazy 64/128/256/final-context graphs. The research variants
|
|
312
|
+
// =progressive128 and =progressive256 skip smaller buckets. Unsupported graphs
|
|
313
|
+
// and allocation failures fall back to the dynamic path.
|
|
314
|
+
struct cohere_decoder_batch_generate_result* cohere_run_decoder_batch_generate_ex(
|
|
315
|
+
struct cohere_context* ctx, const float* encoder_states, const int* valid_T_enc, int n_batch, int T_enc_max,
|
|
316
|
+
int d_model, const char* lang, int max_new_tokens, enum cohere_decoder_batch_output_mode output_mode);
|
|
317
|
+
void cohere_decoder_batch_generate_result_free(struct cohere_decoder_batch_generate_result* result);
|
|
318
|
+
|
|
319
|
+
// Staged encoder: runs the encoder with per-layer snapshots for crispasr-diff.
|
|
320
|
+
// Callback receives each snapshot: name, data, T_enc, d_model.
|
|
321
|
+
typedef void (*cohere_stage_cb)(const char* name, const float* data, int T_enc, int d_model, void* userdata);
|
|
322
|
+
int cohere_run_encoder_staged(struct cohere_context* ctx, const float* mel, int n_mels, int T_mel, cohere_stage_cb cb,
|
|
323
|
+
void* userdata);
|
|
324
|
+
|
|
325
|
+
#ifdef __cplusplus
|
|
326
|
+
}
|
|
327
|
+
#endif
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <algorithm>
|
|
4
|
+
#include <cmath>
|
|
5
|
+
#include <cstddef>
|
|
6
|
+
#include <cstdint>
|
|
7
|
+
#include <numeric>
|
|
8
|
+
#include <vector>
|
|
9
|
+
|
|
10
|
+
namespace cohere_batch_planner {
|
|
11
|
+
|
|
12
|
+
// Round a graph dimension up to a stable bucket so repeated batches can reuse
|
|
13
|
+
// the same backend graph. A zero bucket preserves the exact input length.
|
|
14
|
+
// Zero is also the failure sentinel for invalid or overflowing dimensions.
|
|
15
|
+
inline int round_up_to_bucket(int length, int bucket, int maximum) {
|
|
16
|
+
if (length <= 0 || bucket < 0 || maximum <= 0 || length > maximum || bucket > maximum)
|
|
17
|
+
return 0;
|
|
18
|
+
if (bucket == 0)
|
|
19
|
+
return length;
|
|
20
|
+
const std::int64_t rounded = ((std::int64_t)length + bucket - 1) / bucket * bucket;
|
|
21
|
+
return rounded <= maximum ? (int)rounded : 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
struct batch {
|
|
25
|
+
std::vector<std::size_t> lanes;
|
|
26
|
+
int padded_length = 0;
|
|
27
|
+
std::size_t valid_length_sum = 0;
|
|
28
|
+
|
|
29
|
+
double padding_ratio() const {
|
|
30
|
+
if (lanes.empty() || valid_length_sum == 0)
|
|
31
|
+
return 0.0;
|
|
32
|
+
return (double)((std::size_t)padded_length * lanes.size()) / (double)valid_length_sum;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Stable longest-first ordering primes GGML's CUDA scratch pool with the
|
|
37
|
+
// largest shapes and keeps equal-length inputs in caller order.
|
|
38
|
+
inline std::vector<std::size_t> descending_order(const std::vector<int>& lengths) {
|
|
39
|
+
if (std::any_of(lengths.begin(), lengths.end(), [](int length) { return length <= 0; }))
|
|
40
|
+
return {};
|
|
41
|
+
|
|
42
|
+
std::vector<std::size_t> order(lengths.size());
|
|
43
|
+
std::iota(order.begin(), order.end(), 0);
|
|
44
|
+
std::stable_sort(order.begin(), order.end(), [&](std::size_t lhs, std::size_t rhs) {
|
|
45
|
+
return lengths[lhs] > lengths[rhs];
|
|
46
|
+
});
|
|
47
|
+
return order;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Build padded microbatches without dropping or reordering equal-length work.
|
|
51
|
+
// A candidate starts a new batch when it would exceed max_batch or the
|
|
52
|
+
// padded/valid work ratio. The first item always fits with ratio 1.
|
|
53
|
+
inline std::vector<batch> make_batches(const std::vector<int>& lengths, std::size_t max_batch,
|
|
54
|
+
double max_padding_ratio) {
|
|
55
|
+
if (max_batch == 0 || !std::isfinite(max_padding_ratio) || max_padding_ratio < 1.0)
|
|
56
|
+
return {};
|
|
57
|
+
const std::vector<std::size_t> order = descending_order(lengths);
|
|
58
|
+
if (!lengths.empty() && order.empty())
|
|
59
|
+
return {};
|
|
60
|
+
|
|
61
|
+
std::vector<batch> result;
|
|
62
|
+
for (std::size_t lane : order) {
|
|
63
|
+
const int length = lengths[lane];
|
|
64
|
+
bool start_new = result.empty() || result.back().lanes.size() >= max_batch;
|
|
65
|
+
if (!start_new) {
|
|
66
|
+
const batch& current = result.back();
|
|
67
|
+
const std::size_t next_sum = current.valid_length_sum + (std::size_t)length;
|
|
68
|
+
const double next_ratio =
|
|
69
|
+
(double)((std::size_t)current.padded_length * (current.lanes.size() + 1)) / (double)next_sum;
|
|
70
|
+
start_new = next_ratio > max_padding_ratio;
|
|
71
|
+
}
|
|
72
|
+
if (start_new) {
|
|
73
|
+
result.push_back({});
|
|
74
|
+
result.back().padded_length = length;
|
|
75
|
+
}
|
|
76
|
+
result.back().lanes.push_back(lane);
|
|
77
|
+
result.back().valid_length_sum += (std::size_t)length;
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
} // namespace cohere_batch_planner
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "core/audio_chunking.h"
|
|
4
|
+
|
|
5
|
+
#include <algorithm>
|
|
6
|
+
#include <cctype>
|
|
7
|
+
#include <cstddef>
|
|
8
|
+
#include <string>
|
|
9
|
+
#include <string_view>
|
|
10
|
+
#include <utility>
|
|
11
|
+
#include <vector>
|
|
12
|
+
|
|
13
|
+
namespace cohere_chunking {
|
|
14
|
+
|
|
15
|
+
// The processor enters its chunk-metadata path above 30 seconds, but each
|
|
16
|
+
// model row may contain up to 35 seconds. Boundaries are selected from the
|
|
17
|
+
// final five seconds in non-overlapping 100 ms energy windows.
|
|
18
|
+
constexpr int processor_direct_seconds = 30;
|
|
19
|
+
constexpr int max_clip_seconds = 35;
|
|
20
|
+
constexpr int boundary_search_seconds = 5;
|
|
21
|
+
constexpr int energy_window_ms = 100;
|
|
22
|
+
|
|
23
|
+
inline std::vector<std::pair<size_t, size_t>> plan(const float* samples, size_t n_samples, int sample_rate) {
|
|
24
|
+
if (!samples || n_samples == 0 || sample_rate <= 0)
|
|
25
|
+
return {};
|
|
26
|
+
const size_t max_clip = (size_t)max_clip_seconds * (size_t)sample_rate;
|
|
27
|
+
const size_t search = (size_t)boundary_search_seconds * (size_t)sample_rate;
|
|
28
|
+
const size_t energy_window = std::max<size_t>(1, (size_t)sample_rate * energy_window_ms / 1000);
|
|
29
|
+
return audio_chunking::split_at_energy_minima(samples, n_samples, max_clip, search, energy_window);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
inline bool is_ascii_space(unsigned char value) {
|
|
33
|
+
return std::isspace(value) != 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
inline std::string trim_right(std::string_view value) {
|
|
37
|
+
size_t end = value.size();
|
|
38
|
+
while (end > 0 && is_ascii_space((unsigned char)value[end - 1]))
|
|
39
|
+
--end;
|
|
40
|
+
return std::string(value.substr(0, end));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
inline std::string trim(std::string_view value) {
|
|
44
|
+
size_t begin = 0;
|
|
45
|
+
while (begin < value.size() && is_ascii_space((unsigned char)value[begin]))
|
|
46
|
+
++begin;
|
|
47
|
+
return trim_right(value.substr(begin));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Match CohereAsrProcessor._reconstruct_transcripts(): discard empty rows,
|
|
51
|
+
// preserve leading whitespace on the first row, strip later rows, and join
|
|
52
|
+
// them with exactly one Arabic word separator.
|
|
53
|
+
inline void append_text(std::string& combined, std::string_view next) {
|
|
54
|
+
if (trim(next).empty())
|
|
55
|
+
return;
|
|
56
|
+
std::string part = combined.empty() ? trim_right(next) : trim(next);
|
|
57
|
+
if (part.empty())
|
|
58
|
+
return;
|
|
59
|
+
if (!combined.empty())
|
|
60
|
+
combined.push_back(' ');
|
|
61
|
+
combined += part;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
} // namespace cohere_chunking
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <cstddef>
|
|
4
|
+
|
|
5
|
+
namespace cohere_decoder_batch {
|
|
6
|
+
|
|
7
|
+
constexpr int max_batch = 24;
|
|
8
|
+
constexpr int max_encoder_frames = 512;
|
|
9
|
+
constexpr int max_teacher_steps = 64;
|
|
10
|
+
|
|
11
|
+
constexpr std::size_t cache_slot(int layer, int lane, int n_batch) {
|
|
12
|
+
return (std::size_t)layer * (std::size_t)n_batch + (std::size_t)lane;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
constexpr std::size_t cache_element_offset(int head_dim, int max_ctx, int n_heads, int layer, int lane,
|
|
16
|
+
int n_batch, int position, int head, int component) {
|
|
17
|
+
const std::size_t slot_stride = (std::size_t)head_dim * (std::size_t)max_ctx * (std::size_t)n_heads;
|
|
18
|
+
const std::size_t head_stride = (std::size_t)head_dim * (std::size_t)max_ctx;
|
|
19
|
+
return cache_slot(layer, lane, n_batch) * slot_stride + (std::size_t)head * head_stride +
|
|
20
|
+
(std::size_t)position * (std::size_t)head_dim + (std::size_t)component;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
constexpr std::size_t graph_token_index(int lane, int token, int n_tokens) {
|
|
24
|
+
return (std::size_t)lane * (std::size_t)n_tokens + (std::size_t)token;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
constexpr std::size_t sequence_token_index(int step, int lane, int n_batch) {
|
|
28
|
+
return (std::size_t)step * (std::size_t)n_batch + (std::size_t)lane;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
constexpr std::size_t output_logit_index(int output, int lane, int token, int n_batch, int vocab_size) {
|
|
32
|
+
return ((std::size_t)output * (std::size_t)n_batch + (std::size_t)lane) * (std::size_t)vocab_size +
|
|
33
|
+
(std::size_t)token;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
constexpr bool valid_cross_length(int valid_T_enc, int T_enc_max) {
|
|
37
|
+
return T_enc_max >= 1 && T_enc_max <= max_encoder_frames && valid_T_enc >= 1 && valid_T_enc <= T_enc_max;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Host full-logit generation intentionally uses strict greater-than so exact
|
|
41
|
+
// ties resolve to the lowest vocabulary ID. Device argmax kernels are not
|
|
42
|
+
// required to preserve this tie policy.
|
|
43
|
+
inline int host_argmax_lowest(const float* values, int count) {
|
|
44
|
+
if (!values || count < 1)
|
|
45
|
+
return -1;
|
|
46
|
+
int best = 0;
|
|
47
|
+
for (int index = 1; index < count; ++index) {
|
|
48
|
+
if (values[index] > values[best])
|
|
49
|
+
best = index;
|
|
50
|
+
}
|
|
51
|
+
return best;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// GGML flash-attention mask layout: [T_enc_max, n_queries, 1, n_batch].
|
|
55
|
+
constexpr std::size_t cross_mask_index(int lane, int query, int key, int n_queries, int T_enc_max) {
|
|
56
|
+
return ((std::size_t)lane * (std::size_t)n_queries + (std::size_t)query) * (std::size_t)T_enc_max +
|
|
57
|
+
(std::size_t)key;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
} // namespace cohere_decoder_batch
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <cstddef>
|
|
4
|
+
|
|
5
|
+
namespace cohere_encoder_padded {
|
|
6
|
+
|
|
7
|
+
constexpr int max_batch = 8;
|
|
8
|
+
constexpr int max_mel_frames = 4096;
|
|
9
|
+
|
|
10
|
+
constexpr int stride2_length(int length) {
|
|
11
|
+
return (length + 1) / 2;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
constexpr int encoder_length(int mel_length) {
|
|
15
|
+
return stride2_length(stride2_length(stride2_length(mel_length)));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
constexpr std::size_t lane_time_index(int lane, int time, int padded_time) {
|
|
19
|
+
return (std::size_t)lane * (std::size_t)padded_time + (std::size_t)time;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
constexpr std::size_t lane_value_index(int lane, int time, int feature, int padded_time, int n_features) {
|
|
23
|
+
return ((std::size_t)lane * (std::size_t)padded_time + (std::size_t)time) * (std::size_t)n_features +
|
|
24
|
+
(std::size_t)feature;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
} // namespace cohere_encoder_padded
|