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,265 @@
|
|
|
1
|
+
// src/core/mel.h — shared log-mel spectrogram computation.
|
|
2
|
+
//
|
|
3
|
+
// Replaces the 9 copy-pasted mel spectrogram implementations across the
|
|
4
|
+
// src/ model files (parakeet.cpp, canary.cpp, canary_ctc.cpp, cohere.cpp,
|
|
5
|
+
// qwen3_asr.cpp, voxtral.cpp, voxtral4b.cpp, granite_speech.cpp,
|
|
6
|
+
// crispasr). Two algorithm clusters are supported via enums:
|
|
7
|
+
//
|
|
8
|
+
// NeMo / Conformer style — ln + per-mel z-score, (T, n_mels) output
|
|
9
|
+
// used by parakeet, canary, canary_ctc, cohere
|
|
10
|
+
//
|
|
11
|
+
// Whisper / HF style — log10 + global clip (max-8+4)/4, (n_mels, T) output
|
|
12
|
+
// used by whisper, qwen3, voxtral, voxtral4b, granite
|
|
13
|
+
//
|
|
14
|
+
// The function is parameterised rather than having two entry points
|
|
15
|
+
// because the STFT + mel projection steps are identical; only the log
|
|
16
|
+
// base, normalization, and output transpose differ. Keeping them in one
|
|
17
|
+
// code path means numerical differences between clusters stay localised
|
|
18
|
+
// to the post-processing step, not the heavy computation.
|
|
19
|
+
//
|
|
20
|
+
// Models continue to own their own FFT function — it's passed in as a
|
|
21
|
+
// function pointer so we don't have to unify the 9 near-identical
|
|
22
|
+
// Cooley-Tukey implementations in this first pass. (They can be
|
|
23
|
+
// consolidated in a follow-up; the win there is small compared to the
|
|
24
|
+
// mel extraction itself.)
|
|
25
|
+
|
|
26
|
+
#pragma once
|
|
27
|
+
|
|
28
|
+
#include <cstdint>
|
|
29
|
+
#include <vector>
|
|
30
|
+
|
|
31
|
+
namespace core_mel {
|
|
32
|
+
|
|
33
|
+
// Real-to-complex FFT callback signature. N is always a power of two.
|
|
34
|
+
// Output layout: interleaved (re, im) pairs, length 2*N floats.
|
|
35
|
+
// Each model passes its own FFT so we don't disturb numerical paths.
|
|
36
|
+
using FftR2C = void (*)(const float* in, int N, float* out);
|
|
37
|
+
|
|
38
|
+
enum class LogBase {
|
|
39
|
+
Ln,
|
|
40
|
+
Log10,
|
|
41
|
+
|
|
42
|
+
// Skip the log step entirely. The compute() output is the raw
|
|
43
|
+
// mel-projected spectrum (Power or Magnitude per spec_kind), with
|
|
44
|
+
// any post-processing (normalization, layout transpose) still
|
|
45
|
+
// applied. Used by the Resemble VoiceEncoder
|
|
46
|
+
// (chatterbox/models/voice_encoder/melspec.py — mel_type='amp':
|
|
47
|
+
// mel_basis @ |stft|^2 with no dB conversion). Pair with
|
|
48
|
+
// log_guard = MaxClip and log_eps = 0 to also disable the
|
|
49
|
+
// pre-log floor (which would otherwise raise small values to
|
|
50
|
+
// log_eps before the log step is even attempted).
|
|
51
|
+
None,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// What to project through the mel filterbank: |X|^2 (power) — Whisper /
|
|
55
|
+
// most encoders — or |X| (magnitude) — HF Gemma4AudioFeatureExtractor.
|
|
56
|
+
enum class SpecKind { Power, Magnitude };
|
|
57
|
+
|
|
58
|
+
enum class Normalization {
|
|
59
|
+
// Per-mel band z-score across time: (x - mean) / sqrt(var + 1e-5).
|
|
60
|
+
// Used by parakeet / canary / canary_ctc / cohere.
|
|
61
|
+
PerFeatureZ,
|
|
62
|
+
|
|
63
|
+
// Global clip-and-scale: y = (max(x, max(x)-8) + 4) / 4.
|
|
64
|
+
// Used by whisper / qwen3 / voxtral / granite.
|
|
65
|
+
GlobalClipMax,
|
|
66
|
+
|
|
67
|
+
// Global clip with fixed ceiling (max-like value is baked into the
|
|
68
|
+
// normalization rather than computed): y = (max(x, fixed_max-8) + 4) / 4.
|
|
69
|
+
// Used by voxtral4b with fixed_max = 1.5.
|
|
70
|
+
GlobalClipFixed,
|
|
71
|
+
|
|
72
|
+
// No post-log normalization — raw log10(max(mel, mel_floor)) is the
|
|
73
|
+
// final feature. Used by Gemma4AudioFeatureExtractor (no per_bin_mean
|
|
74
|
+
// or per_bin_stddev, no whisper-style clip-and-scale).
|
|
75
|
+
None,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
enum class Layout {
|
|
79
|
+
// Row-major (T, n_mels) — each frame's n_mels values contiguous.
|
|
80
|
+
// Used by the NeMo cluster.
|
|
81
|
+
TimeMels,
|
|
82
|
+
|
|
83
|
+
// Row-major (n_mels, T) — each mel band's full time series contiguous.
|
|
84
|
+
// Used by the HF/Whisper cluster.
|
|
85
|
+
MelsTime,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
enum class LogGuard {
|
|
89
|
+
// log(x + log_eps): NeMo convention (parakeet, canary, canary_ctc, cohere).
|
|
90
|
+
AddEpsilon,
|
|
91
|
+
|
|
92
|
+
// log(max(x, log_eps)): HF / Whisper convention.
|
|
93
|
+
MaxClip,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
enum class MatmulPrecision {
|
|
97
|
+
// Float32 accumulator. Fastest, matches NeMo numerical path.
|
|
98
|
+
Float,
|
|
99
|
+
|
|
100
|
+
// Float64 accumulator, promoted before multiply-add. Matches the
|
|
101
|
+
// HF / Whisper / Qwen3 / Voxtral numerical path which explicitly
|
|
102
|
+
// uses double for the mel projection.
|
|
103
|
+
Double,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// Filterbank storage layout in memory. Both are row-major floats.
|
|
107
|
+
enum class FbLayout {
|
|
108
|
+
// [n_mels, n_freqs]: fb[m * n_freqs + k]. NeMo cluster.
|
|
109
|
+
MelsFreqs,
|
|
110
|
+
|
|
111
|
+
// [n_freqs, n_mels]: fb[k * n_mels + m]. HF / Whisper cluster
|
|
112
|
+
// (WhisperFeatureExtractor.mel_filters).
|
|
113
|
+
FreqsMels,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
struct Params {
|
|
117
|
+
int n_fft = 400; // power-of-two FFT size
|
|
118
|
+
int hop_length = 160; // frame stride in samples
|
|
119
|
+
int win_length = 400; // window length, must be <= n_fft
|
|
120
|
+
int n_mels = 128;
|
|
121
|
+
|
|
122
|
+
LogBase log_base = LogBase::Log10;
|
|
123
|
+
LogGuard log_guard = LogGuard::AddEpsilon;
|
|
124
|
+
SpecKind spec_kind = SpecKind::Power;
|
|
125
|
+
Normalization norm = Normalization::GlobalClipMax;
|
|
126
|
+
Layout layout = Layout::MelsTime;
|
|
127
|
+
FbLayout fb_layout = FbLayout::MelsFreqs;
|
|
128
|
+
MatmulPrecision matmul = MatmulPrecision::Float;
|
|
129
|
+
|
|
130
|
+
// Small positive constant used in the log guard:
|
|
131
|
+
// AddEpsilon -> log(x + log_eps)
|
|
132
|
+
// MaxClip -> log(max(x, log_eps))
|
|
133
|
+
// NeMo uses 2^-24; Whisper uses 1e-10. Pass what the model originally used.
|
|
134
|
+
float log_eps = 1e-10f;
|
|
135
|
+
|
|
136
|
+
// For Normalization::GlobalClipFixed: the fixed ceiling used in place
|
|
137
|
+
// of the per-audio max. Ignored for other normalization modes.
|
|
138
|
+
float fixed_max = 1.5f;
|
|
139
|
+
|
|
140
|
+
// Apply symmetric padding of n_fft/2 samples before/after the input
|
|
141
|
+
// (matches torchaudio / NeMo center=True). Set false if the caller has
|
|
142
|
+
// already padded the input.
|
|
143
|
+
bool center_pad = true;
|
|
144
|
+
|
|
145
|
+
// Use reflect padding instead of zero padding for center_pad.
|
|
146
|
+
// torchaudio and librosa use reflect padding by default. NeMo uses zero padding.
|
|
147
|
+
bool center_pad_reflect = false;
|
|
148
|
+
|
|
149
|
+
// Pre-emphasis coefficient: x[i] -= preemph * x[i-1] applied BEFORE
|
|
150
|
+
// center-padding (so the first sample is preserved as-is, matching
|
|
151
|
+
// NeMo's `torch.cat((x[:,0:1], x[:,1:] - α*x[:,:-1]))`). 0 disables.
|
|
152
|
+
// NeMo's AudioToMelSpectrogramPreprocessor defaults to 0.97 and applies
|
|
153
|
+
// the filter at inference time. The HF / Whisper cluster does NOT
|
|
154
|
+
// apply pre-emphasis. Pass 0.97 for the NeMo cluster (parakeet,
|
|
155
|
+
// canary, canary_ctc, cohere if their preprocessor configs match).
|
|
156
|
+
float preemph = 0.0f;
|
|
157
|
+
|
|
158
|
+
// Drop the last STFT frame. Matches Whisper / HF feature extractor
|
|
159
|
+
// convention that produces floor((n - n_fft) / hop + 1) - 1 frames
|
|
160
|
+
// instead of the full count.
|
|
161
|
+
bool drop_last_frame = false;
|
|
162
|
+
|
|
163
|
+
// If (after drop_last_frame) the frame count is odd, also drop the
|
|
164
|
+
// first frame so the caller sees an even T. Used by voxtral4b, which
|
|
165
|
+
// feeds mel into a stride-2 conv and needs an even temporal length.
|
|
166
|
+
bool drop_first_frame_if_odd = false;
|
|
167
|
+
|
|
168
|
+
// Pad the mel output on the right so the final length is exactly this
|
|
169
|
+
// many frames. 0 disables. Voxtral 3B pads to 3000 (= 30s at hop=160).
|
|
170
|
+
//
|
|
171
|
+
// Padding happens AFTER the log step but BEFORE normalization, so the
|
|
172
|
+
// padded positions are filled with the log of log_eps (i.e. the value
|
|
173
|
+
// the log guard would produce for a zero-energy frame) rather than
|
|
174
|
+
// plain zero. This matches voxtral's behaviour where padded frames
|
|
175
|
+
// participate in the global-max calculation at a sensible floor.
|
|
176
|
+
int pad_to_T = 0;
|
|
177
|
+
|
|
178
|
+
// Stack `stacked_frames` consecutive mel frames into a single wider
|
|
179
|
+
// frame. With stacked_frames=2 the output goes from (T, n_mels) to
|
|
180
|
+
// (T/2, n_mels * 2) where row i is [mel[2i, :], mel[2i+1, :]]. If the
|
|
181
|
+
// frame count is not a multiple of stacked_frames the trailing
|
|
182
|
+
// remainder is dropped. Used by granite-speech's audio encoder which
|
|
183
|
+
// expects a (T/2, 160) input built from consecutive pairs of 80-mel
|
|
184
|
+
// frames. Default 1 (no stacking). Currently only supported with
|
|
185
|
+
// Layout::TimeMels; other layouts leave the knob ignored.
|
|
186
|
+
int stacked_frames = 1;
|
|
187
|
+
|
|
188
|
+
// Per-backend opt-in for all OpenMP-safe outer loops: independent STFT
|
|
189
|
+
// frames, scalar mel-projection frames, and PerFeatureZ mel bands. Each
|
|
190
|
+
// worker preserves the original inner accumulation order, so enabling this
|
|
191
|
+
// remains bit-identical to the scalar implementation. The global env var
|
|
192
|
+
// CRISPASR_MEL_PARALLEL enables the same path for every backend.
|
|
193
|
+
bool allow_parallel = false;
|
|
194
|
+
|
|
195
|
+
// Worker cap for parallel frontend regions. Values <= 0 use the OpenMP
|
|
196
|
+
// runtime default. Backends with their own thread setting should forward
|
|
197
|
+
// it here to avoid oversubscribing the host.
|
|
198
|
+
int parallel_threads = 0;
|
|
199
|
+
|
|
200
|
+
// Backwards-compatible, narrower opt-in for only the STFT frame loop. Keep
|
|
201
|
+
// this for backends that have audited their FFT callback but have not opted
|
|
202
|
+
// into the complete frontend path above.
|
|
203
|
+
bool allow_parallel_stft = false;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// Compute log-mel spectrogram from raw PCM samples.
|
|
207
|
+
//
|
|
208
|
+
// samples : float32 PCM at the caller's sample rate (usually 16 kHz)
|
|
209
|
+
// n_samples : sample count
|
|
210
|
+
// window : float32[n_fft] Hann/Hamming window padded with zeros if
|
|
211
|
+
// win_length < n_fft (caller's responsibility). When the
|
|
212
|
+
// model stores only the win_length-sized window in its GGUF,
|
|
213
|
+
// this helper pads it inside compute().
|
|
214
|
+
// mel_fb : float32[n_mels * n_freqs] row-major filterbank with
|
|
215
|
+
// n_freqs = n_fft/2 + 1
|
|
216
|
+
// fft : model-specific FFT function pointer (see FftR2C above)
|
|
217
|
+
// params : configuration (see Params struct)
|
|
218
|
+
// T_out [out] : number of output frames
|
|
219
|
+
//
|
|
220
|
+
// Returns the flat log-mel buffer in the layout specified by params.layout.
|
|
221
|
+
std::vector<float> compute(const float* samples, int n_samples,
|
|
222
|
+
const float* window, // length win_length (we center-pad inside to n_fft)
|
|
223
|
+
int win_length,
|
|
224
|
+
const float* mel_fb, // [n_mels, n_freqs]
|
|
225
|
+
int n_freqs, FftR2C fft, const Params& params, int& T_out);
|
|
226
|
+
|
|
227
|
+
// HTK-mel-scale triangular filterbank builder. Matches torchaudio's
|
|
228
|
+
// MelSpectrogram defaults (mel_scale='htk', norm=None) and the inline
|
|
229
|
+
// builders that ecapa_lid / firered_vad / firered_asr / mimo_tokenizer
|
|
230
|
+
// have copies of.
|
|
231
|
+
//
|
|
232
|
+
// sr : sample rate
|
|
233
|
+
// n_fft : STFT size
|
|
234
|
+
// n_mels : number of mel bands
|
|
235
|
+
// fmin : low edge in Hz (use 0)
|
|
236
|
+
// fmax : high edge in Hz; pass <= 0 for sr/2 (Nyquist)
|
|
237
|
+
// layout : MelsFreqs ([n_mels, n_freqs] row-major) or
|
|
238
|
+
// FreqsMels ([n_freqs, n_mels] row-major).
|
|
239
|
+
//
|
|
240
|
+
// Returns a flat float32 vector with the requested layout, sized
|
|
241
|
+
// n_mels * (n_fft/2+1).
|
|
242
|
+
std::vector<float> build_htk_fb(int sr, int n_fft, int n_mels, float fmin, float fmax,
|
|
243
|
+
FbLayout layout = FbLayout::MelsFreqs);
|
|
244
|
+
|
|
245
|
+
// Slaney-mel-scale triangular filterbank builder with Slaney area
|
|
246
|
+
// normalization. Matches `librosa.filters.mel(htk=False, norm='slaney')`
|
|
247
|
+
// — the librosa default — used by Chatterbox's 24 kHz prompt-mel
|
|
248
|
+
// (`chatterbox/models/s3gen/utils/mel.py:56`), the S3Tokenizer mel
|
|
249
|
+
// (16 kHz, 128 bins), and any other model that takes its mel basis
|
|
250
|
+
// from librosa without overriding the defaults.
|
|
251
|
+
//
|
|
252
|
+
// Differs from build_htk_fb() in two ways:
|
|
253
|
+
// 1. Mel scale is the piecewise Slaney curve (linear below 1 kHz at
|
|
254
|
+
// 200/3 Hz per mel, log above 1 kHz with logstep = ln(6.4)/27).
|
|
255
|
+
// vs HTK's single-formula 2595 * log10(1 + f/700).
|
|
256
|
+
// 2. Slaney norm scales each triangular filter by 2/(f_hi - f_lo),
|
|
257
|
+
// so each filter has roughly equal area regardless of bandwidth.
|
|
258
|
+
// Without this, the higher-frequency wider filters would dominate
|
|
259
|
+
// the projection.
|
|
260
|
+
//
|
|
261
|
+
// Same arg semantics as build_htk_fb. Returns the same flat shape.
|
|
262
|
+
std::vector<float> build_slaney_fb(int sr, int n_fft, int n_mels, float fmin, float fmax,
|
|
263
|
+
FbLayout layout = FbLayout::MelsFreqs);
|
|
264
|
+
|
|
265
|
+
} // namespace core_mel
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// core/ngram_loop_fix.h — collapse degenerate greedy n-gram loops in decoded
|
|
2
|
+
// text.
|
|
3
|
+
//
|
|
4
|
+
// Autoregressive ASR decoders (higgs-audio-v3-stt, MOSS-Transcribe, ... — all
|
|
5
|
+
// Qwen3-1.7B-class LMs decoded greedily) occasionally fall into a repeated
|
|
6
|
+
// n-gram attractor and emit the same phrase until the max-token cap
|
|
7
|
+
// ("Hey, hey, hey, ..." / "run hey hey hey run ..."). higgs-audio ships an
|
|
8
|
+
// `ngram_loop_fix.py` post-process for exactly this; the collapse below is that
|
|
9
|
+
// algorithm, extracted here so multiple backends share one implementation.
|
|
10
|
+
//
|
|
11
|
+
// The transform is a pure text post-process: it never touches the token
|
|
12
|
+
// stream, so per-token / logit parity against a Python reference is unchanged.
|
|
13
|
+
// It is a no-op on non-degenerate text — only *immediately* repeated n-grams
|
|
14
|
+
// beyond `max_rep` reps are trimmed — so a clean transcript passes through
|
|
15
|
+
// byte-for-byte.
|
|
16
|
+
|
|
17
|
+
#pragma once
|
|
18
|
+
|
|
19
|
+
#include <cctype>
|
|
20
|
+
#include <cstdlib>
|
|
21
|
+
#include <string>
|
|
22
|
+
#include <vector>
|
|
23
|
+
|
|
24
|
+
namespace core_ngram {
|
|
25
|
+
|
|
26
|
+
// Collapse immediately-repeated n-grams (window size `n`) in `w` to at most
|
|
27
|
+
// `max_rep` consecutive reps. Walks left-to-right building `out`; whenever the
|
|
28
|
+
// next n words equal the tail of `out` and that tail already repeats >= max_rep
|
|
29
|
+
// times, the duplicate n-gram is dropped.
|
|
30
|
+
inline std::vector<std::string> collapse(const std::vector<std::string>& w, int n, int max_rep) {
|
|
31
|
+
std::vector<std::string> out;
|
|
32
|
+
const int L = (int)w.size();
|
|
33
|
+
int i = 0;
|
|
34
|
+
auto tail_eq = [&]() {
|
|
35
|
+
for (int k = 0; k < n; k++)
|
|
36
|
+
if (w[i + k] != out[out.size() - n + k])
|
|
37
|
+
return false;
|
|
38
|
+
return true;
|
|
39
|
+
};
|
|
40
|
+
while (i < L) {
|
|
41
|
+
bool matched = false;
|
|
42
|
+
if ((int)out.size() >= n && i + n <= L && tail_eq()) {
|
|
43
|
+
int reps = 1;
|
|
44
|
+
while ((int)out.size() >= n * (reps + 1)) {
|
|
45
|
+
bool eq = true;
|
|
46
|
+
const size_t b = out.size() - (size_t)n * (reps + 1);
|
|
47
|
+
for (int k = 0; k < n; k++)
|
|
48
|
+
if (out[b + k] != out[out.size() - n + k]) {
|
|
49
|
+
eq = false;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
if (!eq)
|
|
53
|
+
break;
|
|
54
|
+
reps++;
|
|
55
|
+
}
|
|
56
|
+
if (reps >= max_rep) {
|
|
57
|
+
i += n;
|
|
58
|
+
matched = true;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (!matched) {
|
|
62
|
+
out.push_back(w[i]);
|
|
63
|
+
i++;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Split `text` on whitespace into words.
|
|
70
|
+
inline std::vector<std::string> split_words(const std::string& text) {
|
|
71
|
+
std::vector<std::string> words;
|
|
72
|
+
size_t i = 0;
|
|
73
|
+
while (i < text.size()) {
|
|
74
|
+
while (i < text.size() && std::isspace((unsigned char)text[i]))
|
|
75
|
+
i++;
|
|
76
|
+
size_t j = i;
|
|
77
|
+
while (j < text.size() && !std::isspace((unsigned char)text[j]))
|
|
78
|
+
j++;
|
|
79
|
+
if (j > i)
|
|
80
|
+
words.push_back(text.substr(i, j - i));
|
|
81
|
+
i = j;
|
|
82
|
+
}
|
|
83
|
+
return words;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Same collapse algorithm as `collapse()`, but tracks original indices
|
|
87
|
+
// (into `words`) instead of copying strings. `idx` is the current
|
|
88
|
+
// surviving subsequence (indices into `words`) to collapse further;
|
|
89
|
+
// returns the subsequence of `idx` that survives this pass.
|
|
90
|
+
inline std::vector<int> collapse_indices(const std::vector<std::string>& words, const std::vector<int>& idx, int n,
|
|
91
|
+
int max_rep) {
|
|
92
|
+
std::vector<int> out; // indices into `words`
|
|
93
|
+
const int L = (int)idx.size();
|
|
94
|
+
int i = 0;
|
|
95
|
+
auto tail_eq = [&]() {
|
|
96
|
+
for (int k = 0; k < n; k++)
|
|
97
|
+
if (words[idx[i + k]] != words[out[out.size() - n + k]])
|
|
98
|
+
return false;
|
|
99
|
+
return true;
|
|
100
|
+
};
|
|
101
|
+
while (i < L) {
|
|
102
|
+
bool matched = false;
|
|
103
|
+
if ((int)out.size() >= n && i + n <= L && tail_eq()) {
|
|
104
|
+
int reps = 1;
|
|
105
|
+
while ((int)out.size() >= n * (reps + 1)) {
|
|
106
|
+
bool eq = true;
|
|
107
|
+
const size_t b = out.size() - (size_t)n * (reps + 1);
|
|
108
|
+
for (int k = 0; k < n; k++)
|
|
109
|
+
if (words[out[b + k]] != words[out[out.size() - n + k]]) {
|
|
110
|
+
eq = false;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
if (!eq)
|
|
114
|
+
break;
|
|
115
|
+
reps++;
|
|
116
|
+
}
|
|
117
|
+
if (reps >= max_rep) {
|
|
118
|
+
i += n;
|
|
119
|
+
matched = true;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (!matched) {
|
|
123
|
+
out.push_back(idx[i]);
|
|
124
|
+
i++;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Runs the same n=max_n..1 collapse passes as `fix_loops`, but returns the
|
|
131
|
+
// ascending subsequence of original indices into `words` that survive —
|
|
132
|
+
// i.e. which words `fix_loops` would keep. Callers with a parallel
|
|
133
|
+
// per-word array (timestamps, confidences) use this to filter that array
|
|
134
|
+
// in lockstep with the text collapse, instead of just cleaning the flat
|
|
135
|
+
// text and leaving duplicates in word-level output (issue #218 follow-up:
|
|
136
|
+
// `fix_loops` alone cleans `seg.text` but not `seg.words`/tokens, which
|
|
137
|
+
// are built independently from the raw token stream).
|
|
138
|
+
// Global diagnostic opt-out: CRISPASR_NGRAM_LOOPFIX_OFF=1 turns every
|
|
139
|
+
// fix_loops/fix_loops_keep_indices call into an identity pass, exposing the
|
|
140
|
+
// RAW decoded text. For A/B-ing whether a loop originates in the decode
|
|
141
|
+
// itself (quant drift, #218) or is merely being masked by the collapse.
|
|
142
|
+
inline bool loopfix_disabled() {
|
|
143
|
+
const char* e = std::getenv("CRISPASR_NGRAM_LOOPFIX_OFF");
|
|
144
|
+
return e && std::atoi(e) != 0;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
inline std::vector<int> fix_loops_keep_indices(const std::vector<std::string>& words, int max_n = 16) {
|
|
148
|
+
std::vector<int> idx(words.size());
|
|
149
|
+
for (size_t i = 0; i < words.size(); i++)
|
|
150
|
+
idx[i] = (int)i;
|
|
151
|
+
if (loopfix_disabled())
|
|
152
|
+
return idx;
|
|
153
|
+
for (int n = max_n; n >= 1; n--)
|
|
154
|
+
idx = collapse_indices(words, idx, n, n == 1 ? 3 : 2);
|
|
155
|
+
return idx;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Split `text` on whitespace, collapse repeated n-grams from `max_n` down to 1
|
|
159
|
+
// (unigrams kept up to 3 reps, longer n-grams up to 2), and re-join with single
|
|
160
|
+
// spaces. Returns cleaned text.
|
|
161
|
+
inline std::string fix_loops(const std::string& text, int max_n = 16) {
|
|
162
|
+
std::vector<std::string> words = split_words(text);
|
|
163
|
+
std::vector<int> keep = fix_loops_keep_indices(words, max_n);
|
|
164
|
+
std::string out;
|
|
165
|
+
for (size_t k = 0; k < keep.size(); k++) {
|
|
166
|
+
if (k)
|
|
167
|
+
out += ' ';
|
|
168
|
+
out += words[keep[k]];
|
|
169
|
+
}
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
} // namespace core_ngram
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <algorithm>
|
|
4
|
+
#include <cstddef>
|
|
5
|
+
#include <vector>
|
|
6
|
+
|
|
7
|
+
namespace core_repetition_loop {
|
|
8
|
+
|
|
9
|
+
constexpr std::size_t min_generated_tokens = 96;
|
|
10
|
+
constexpr std::size_t repeats = 4;
|
|
11
|
+
constexpr std::size_t min_period = 8;
|
|
12
|
+
constexpr std::size_t max_period = 32;
|
|
13
|
+
|
|
14
|
+
// Match cohere-transcribe's conservative Transformers stopping criterion:
|
|
15
|
+
// after at least 96 generated tokens, stop when the current suffix contains
|
|
16
|
+
// four immediately repeated blocks of any length from 8 through 32 tokens.
|
|
17
|
+
inline bool triggered(const std::vector<int>& generated) {
|
|
18
|
+
if (generated.size() < min_generated_tokens)
|
|
19
|
+
return false;
|
|
20
|
+
|
|
21
|
+
const std::size_t largest_period = std::min(max_period, generated.size() / repeats);
|
|
22
|
+
for (std::size_t period = min_period; period <= largest_period; ++period) {
|
|
23
|
+
const std::size_t first = generated.size() - repeats * period;
|
|
24
|
+
bool matches = true;
|
|
25
|
+
for (std::size_t repeat = 1; repeat < repeats && matches; ++repeat) {
|
|
26
|
+
const std::size_t offset = first + repeat * period;
|
|
27
|
+
for (std::size_t token = 0; token < period; ++token) {
|
|
28
|
+
if (generated[first + token] != generated[offset + token]) {
|
|
29
|
+
matches = false;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (matches)
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Return the first generated-prefix length that would trigger the guard, or
|
|
41
|
+
// zero when no prefix triggers it. Batched generation uses this to reproduce
|
|
42
|
+
// row-wise stopping after the ragged decoder has completed the physical batch.
|
|
43
|
+
inline std::size_t first_trigger_length(const std::vector<int>& generated) {
|
|
44
|
+
std::vector<int> prefix;
|
|
45
|
+
prefix.reserve(generated.size());
|
|
46
|
+
for (int token : generated) {
|
|
47
|
+
prefix.push_back(token);
|
|
48
|
+
if (triggered(prefix))
|
|
49
|
+
return prefix.size();
|
|
50
|
+
}
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
} // namespace core_repetition_loop
|