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,548 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
5
|
+
require_relative "gguf_writer"
|
|
6
|
+
require_relative "model_identity"
|
|
7
|
+
require_relative "pytorch_checkpoint"
|
|
8
|
+
require_relative "safetensors"
|
|
9
|
+
|
|
10
|
+
module Cohere
|
|
11
|
+
module Transcribe
|
|
12
|
+
# Converts a native Transformers Cohere ASR dense checkpoint to the GGUF
|
|
13
|
+
# tensor contract consumed by CrispASR's Cohere backend.
|
|
14
|
+
#
|
|
15
|
+
# The tensor naming contract is derived from CrispASR, MIT-licensed by the
|
|
16
|
+
# ggml authors. See licenses/crispasr.txt for the retained license notice.
|
|
17
|
+
class DenseConverter
|
|
18
|
+
class Error < StandardError; end
|
|
19
|
+
|
|
20
|
+
Mapping = Data.define(:output_name, :source_name, :precision)
|
|
21
|
+
PlannedTensor = Data.define(:output_name, :source_tensor, :output_dtype)
|
|
22
|
+
Plan = Data.define(:tensors, :metadata, :vocabulary, :source_dtype_counts, :output_dtype_counts)
|
|
23
|
+
Result = Data.define(:path, :tensor_count, :source_dtype_counts, :output_dtype_counts)
|
|
24
|
+
|
|
25
|
+
FRONTEND_SOURCE_PATTERN = /\A(?:model\.)?preprocessor\.featurizer\.(?:fb|window)\z/
|
|
26
|
+
COUNTER_SOURCE_PATTERN = /\A(?:model\.)?encoder\.layers\.\d+\.conv\.batch_norm\.num_batches_tracked\z/
|
|
27
|
+
REQUIRED_PROMPT_TOKENS = %w[
|
|
28
|
+
▁ <|startofcontext|> <|startoftranscript|> <|emo:undefined|>
|
|
29
|
+
<|ar|> <|pnc|> <|noitn|> <|notimestamp|> <|nodiarize|> <|endoftext|>
|
|
30
|
+
].freeze
|
|
31
|
+
OUTPUT_TYPES = %i[f16 f32 bf16].freeze
|
|
32
|
+
REQUIRED_ARTIFACT_FILENAMES = %w[config.json tokenizer.json].freeze
|
|
33
|
+
WEIGHT_ARTIFACT_FILENAMES = %w[
|
|
34
|
+
model.safetensors
|
|
35
|
+
model.safetensors.index.json
|
|
36
|
+
pytorch_model.bin
|
|
37
|
+
pytorch_model.bin.index.json
|
|
38
|
+
].freeze
|
|
39
|
+
SOURCE_ARTIFACT_FILENAMES = (
|
|
40
|
+
REQUIRED_ARTIFACT_FILENAMES + WEIGHT_ARTIFACT_FILENAMES
|
|
41
|
+
).freeze
|
|
42
|
+
SOURCE_ARTIFACT_REQUIREMENTS = {
|
|
43
|
+
required: REQUIRED_ARTIFACT_FILENAMES,
|
|
44
|
+
one_weight_file: WEIGHT_ARTIFACT_FILENAMES
|
|
45
|
+
}.freeze
|
|
46
|
+
|
|
47
|
+
attr_reader :model_directory, :output_path, :output_type, :dtype_converter, :chunk_bytes, :progress
|
|
48
|
+
|
|
49
|
+
# Stable integration entry point for model stores and CLI adapters.
|
|
50
|
+
def self.convert(model_dir:, output_path:, overwrite: false, fsync: true, **)
|
|
51
|
+
new(model_dir, output_path: output_path, **).convert(overwrite: overwrite, fsync: fsync)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Every filename a downloader may need to request. The safetensors file
|
|
55
|
+
# and its sharded index are alternatives; see required_source_artifacts.
|
|
56
|
+
def self.source_artifact_filenames
|
|
57
|
+
SOURCE_ARTIFACT_FILENAMES
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def self.required_source_artifacts
|
|
61
|
+
SOURCE_ARTIFACT_REQUIREMENTS
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def initialize(model_directory, output_path:, output_type: :f16,
|
|
65
|
+
dtype_converter: Safetensors::DTypeConverter.default,
|
|
66
|
+
chunk_bytes: Safetensors::DEFAULT_CHUNK_BYTES, progress: nil)
|
|
67
|
+
@model_directory = Pathname(model_directory).expand_path
|
|
68
|
+
@output_path = Pathname(output_path).expand_path
|
|
69
|
+
@output_type = output_type.to_sym
|
|
70
|
+
@dtype_converter = dtype_converter
|
|
71
|
+
@chunk_bytes = Integer(chunk_bytes)
|
|
72
|
+
@progress = progress
|
|
73
|
+
unless OUTPUT_TYPES.include?(@output_type)
|
|
74
|
+
raise ArgumentError,
|
|
75
|
+
"Unsupported dense GGUF output type #{@output_type.inspect}"
|
|
76
|
+
end
|
|
77
|
+
raise ArgumentError, "chunk_bytes must be positive" unless @chunk_bytes.positive?
|
|
78
|
+
raise ArgumentError, "progress must respond to call" if progress && !progress.respond_to?(:call)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def convert(overwrite: false, fsync: true)
|
|
82
|
+
conversion_plan = plan
|
|
83
|
+
writer = build_writer(conversion_plan)
|
|
84
|
+
written_path = writer.write(output_path, overwrite: overwrite, fsync: fsync)
|
|
85
|
+
Result.new(
|
|
86
|
+
path: written_path,
|
|
87
|
+
tensor_count: conversion_plan.tensors.length,
|
|
88
|
+
source_dtype_counts: conversion_plan.source_dtype_counts,
|
|
89
|
+
output_dtype_counts: conversion_plan.output_dtype_counts
|
|
90
|
+
)
|
|
91
|
+
rescue Safetensors::Error, PyTorchCheckpoint::Error, GGUF::Error => e
|
|
92
|
+
raise Error, e.message
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def plan
|
|
96
|
+
@plan ||= build_plan
|
|
97
|
+
rescue Safetensors::Error, PyTorchCheckpoint::Error => e
|
|
98
|
+
raise Error, e.message
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def self.tensor_mappings(encoder_layers:, decoder_layers:)
|
|
102
|
+
mappings = []
|
|
103
|
+
add_pair = lambda do |output, source, weight_precision = :f16|
|
|
104
|
+
mappings << Mapping.new(output_name: "#{output}.weight", source_name: "#{source}.weight",
|
|
105
|
+
precision: weight_precision)
|
|
106
|
+
mappings << Mapping.new(output_name: "#{output}.bias", source_name: "#{source}.bias", precision: :f32)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
[0, 2, 3, 5, 6].each do |index|
|
|
110
|
+
add_pair.call("enc.pre.conv.#{index}", "encoder.pre_encode.conv.#{index}")
|
|
111
|
+
end
|
|
112
|
+
add_pair.call("enc.pre.out", "encoder.pre_encode.out")
|
|
113
|
+
|
|
114
|
+
encoder_layers.times do |index|
|
|
115
|
+
source = "encoder.layers.#{index}"
|
|
116
|
+
output = "enc.blk.#{index}"
|
|
117
|
+
add_pair.call("#{output}.ff1.norm", "#{source}.norm_feed_forward1", :f32)
|
|
118
|
+
add_pair.call("#{output}.ff1.up", "#{source}.feed_forward1.linear1")
|
|
119
|
+
add_pair.call("#{output}.ff1.down", "#{source}.feed_forward1.linear2")
|
|
120
|
+
add_pair.call("#{output}.attn.norm", "#{source}.norm_self_att", :f32)
|
|
121
|
+
add_pair.call("#{output}.attn.q", "#{source}.self_attn.linear_q")
|
|
122
|
+
add_pair.call("#{output}.attn.k", "#{source}.self_attn.linear_k")
|
|
123
|
+
add_pair.call("#{output}.attn.v", "#{source}.self_attn.linear_v")
|
|
124
|
+
add_pair.call("#{output}.attn.out", "#{source}.self_attn.linear_out")
|
|
125
|
+
mappings << Mapping.new(output_name: "#{output}.attn.pos.weight",
|
|
126
|
+
source_name: "#{source}.self_attn.linear_pos.weight", precision: :f16)
|
|
127
|
+
mappings << Mapping.new(output_name: "#{output}.attn.pos_bias_u",
|
|
128
|
+
source_name: "#{source}.self_attn.pos_bias_u", precision: :f32)
|
|
129
|
+
mappings << Mapping.new(output_name: "#{output}.attn.pos_bias_v",
|
|
130
|
+
source_name: "#{source}.self_attn.pos_bias_v", precision: :f32)
|
|
131
|
+
add_pair.call("#{output}.conv.norm", "#{source}.norm_conv", :f32)
|
|
132
|
+
add_pair.call("#{output}.conv.pw1", "#{source}.conv.pointwise_conv1")
|
|
133
|
+
add_pair.call("#{output}.conv.dw", "#{source}.conv.depthwise_conv")
|
|
134
|
+
add_pair.call("#{output}.conv.bn", "#{source}.conv.batch_norm", :f32)
|
|
135
|
+
mappings << Mapping.new(output_name: "#{output}.conv.bn.mean",
|
|
136
|
+
source_name: "#{source}.conv.batch_norm.running_mean", precision: :f32)
|
|
137
|
+
mappings << Mapping.new(output_name: "#{output}.conv.bn.var",
|
|
138
|
+
source_name: "#{source}.conv.batch_norm.running_var", precision: :f32)
|
|
139
|
+
add_pair.call("#{output}.conv.pw2", "#{source}.conv.pointwise_conv2")
|
|
140
|
+
add_pair.call("#{output}.ff2.norm", "#{source}.norm_feed_forward2", :f32)
|
|
141
|
+
add_pair.call("#{output}.ff2.up", "#{source}.feed_forward2.linear1")
|
|
142
|
+
add_pair.call("#{output}.ff2.down", "#{source}.feed_forward2.linear2")
|
|
143
|
+
add_pair.call("#{output}.out_norm", "#{source}.norm_out", :f32)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
add_pair.call("enc.proj", "encoder_decoder_proj")
|
|
147
|
+
mappings << Mapping.new(output_name: "dec.emb.weight",
|
|
148
|
+
source_name: "transf_decoder._embedding.token_embedding.weight", precision: :f16)
|
|
149
|
+
mappings << Mapping.new(output_name: "dec.pos.weight",
|
|
150
|
+
source_name: "transf_decoder._embedding.position_embedding.pos_enc", precision: :f16)
|
|
151
|
+
add_pair.call("dec.emb_ln", "transf_decoder._embedding.layer_norm", :f32)
|
|
152
|
+
|
|
153
|
+
decoder_layers.times do |index|
|
|
154
|
+
source = "transf_decoder._decoder.layers.#{index}"
|
|
155
|
+
output = "dec.blk.#{index}"
|
|
156
|
+
add_pair.call("#{output}.attn_ln", "#{source}.layer_norm_1", :f32)
|
|
157
|
+
add_pair.call("#{output}.attn_q", "#{source}.first_sub_layer.query_net")
|
|
158
|
+
add_pair.call("#{output}.attn_k", "#{source}.first_sub_layer.key_net")
|
|
159
|
+
add_pair.call("#{output}.attn_v", "#{source}.first_sub_layer.value_net")
|
|
160
|
+
add_pair.call("#{output}.attn_o", "#{source}.first_sub_layer.out_projection")
|
|
161
|
+
add_pair.call("#{output}.cross_ln", "#{source}.layer_norm_2", :f32)
|
|
162
|
+
add_pair.call("#{output}.cross_q", "#{source}.second_sub_layer.query_net")
|
|
163
|
+
add_pair.call("#{output}.cross_k", "#{source}.second_sub_layer.key_net")
|
|
164
|
+
add_pair.call("#{output}.cross_v", "#{source}.second_sub_layer.value_net")
|
|
165
|
+
add_pair.call("#{output}.cross_o", "#{source}.second_sub_layer.out_projection")
|
|
166
|
+
add_pair.call("#{output}.ffn_ln", "#{source}.layer_norm_3", :f32)
|
|
167
|
+
add_pair.call("#{output}.ffn_up", "#{source}.third_sub_layer.dense_in")
|
|
168
|
+
add_pair.call("#{output}.ffn_down", "#{source}.third_sub_layer.dense_out")
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
add_pair.call("dec.out_ln", "transf_decoder._decoder.final_layer_norm", :f32)
|
|
172
|
+
add_pair.call("dec.head", "log_softmax.mlp.layer0")
|
|
173
|
+
mappings.freeze
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
private
|
|
177
|
+
|
|
178
|
+
def build_plan
|
|
179
|
+
validate_directory!
|
|
180
|
+
@config = read_json_object(model_directory.join("config.json"), "model configuration")
|
|
181
|
+
validate_config!
|
|
182
|
+
@tensor_set = checkpoint_tensor_set
|
|
183
|
+
encoder_layers = detect_layer_count(:encoder)
|
|
184
|
+
decoder_layers = detect_layer_count(:decoder)
|
|
185
|
+
validate_configured_layer_count!(encoder_layers, decoder_layers)
|
|
186
|
+
|
|
187
|
+
mappings = self.class.tensor_mappings(encoder_layers: encoder_layers, decoder_layers: decoder_layers)
|
|
188
|
+
used_sources = Set.new
|
|
189
|
+
planned = mappings.map do |mapping|
|
|
190
|
+
tensor = fetch_source_tensor(mapping.source_name)
|
|
191
|
+
used_sources << tensor.name
|
|
192
|
+
dtype = case output_type
|
|
193
|
+
when :f32 then :f32
|
|
194
|
+
when :bf16 then mapping.precision == :f16 ? :bf16 : mapping.precision
|
|
195
|
+
else mapping.precision
|
|
196
|
+
end
|
|
197
|
+
PlannedTensor.new(output_name: mapping.output_name, source_tensor: tensor, output_dtype: dtype)
|
|
198
|
+
end
|
|
199
|
+
validate_unmapped_tensors!(used_sources)
|
|
200
|
+
|
|
201
|
+
vocabulary = load_vocabulary
|
|
202
|
+
metadata = build_metadata(
|
|
203
|
+
encoder_layers: encoder_layers,
|
|
204
|
+
decoder_layers: decoder_layers,
|
|
205
|
+
vocabulary: vocabulary
|
|
206
|
+
)
|
|
207
|
+
validate_shapes!(metadata, vocabulary)
|
|
208
|
+
vocabulary.freeze
|
|
209
|
+
metadata.each_value(&:freeze)
|
|
210
|
+
|
|
211
|
+
Plan.new(
|
|
212
|
+
tensors: planned.freeze,
|
|
213
|
+
metadata: metadata.freeze,
|
|
214
|
+
vocabulary: vocabulary,
|
|
215
|
+
source_dtype_counts: tally(planned.map { |item| item.source_tensor.dtype }),
|
|
216
|
+
output_dtype_counts: tally(planned.map(&:output_dtype))
|
|
217
|
+
)
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def validate_directory!
|
|
221
|
+
raise Error, "Model directory #{model_directory} does not exist" unless model_directory.directory?
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def validate_config!
|
|
225
|
+
format, = ModelIdentity.classify_model_config(@config, model_directory.to_s)
|
|
226
|
+
return if format == :dense
|
|
227
|
+
|
|
228
|
+
raise Error, "Dense GGUF conversion does not accept a saved quantized checkpoint"
|
|
229
|
+
rescue ArgumentError, TypeError => e
|
|
230
|
+
raise Error, e.message
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def detect_layer_count(kind)
|
|
234
|
+
pattern = case kind
|
|
235
|
+
when :encoder
|
|
236
|
+
/\A(?:model\.)?encoder\.layers\.(\d+)\.norm_out\.weight\z/
|
|
237
|
+
when :decoder
|
|
238
|
+
/\A(?:model\.)?transf_decoder\._decoder\.layers\.(\d+)\.layer_norm_1\.weight\z/
|
|
239
|
+
else
|
|
240
|
+
raise ArgumentError, "Unknown layer kind #{kind.inspect}"
|
|
241
|
+
end
|
|
242
|
+
indices = @tensor_set.names.filter_map { |name| pattern.match(name)&.[](1)&.to_i }.uniq.sort
|
|
243
|
+
raise Error, "Checkpoint contains no #{kind} layers" if indices.empty?
|
|
244
|
+
|
|
245
|
+
expected = (0..indices.last).to_a
|
|
246
|
+
raise Error, "Checkpoint #{kind} layer indices are not contiguous: #{indices.inspect}" unless indices == expected
|
|
247
|
+
|
|
248
|
+
indices.length
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def validate_configured_layer_count!(encoder_layers, decoder_layers)
|
|
252
|
+
encoder = @config["encoder_config"] || @config["encoder"] || {}
|
|
253
|
+
configured_encoder = encoder["num_hidden_layers"] || encoder["n_layers"]
|
|
254
|
+
decoder = @config.dig("transf_decoder", "config_dict") || {}
|
|
255
|
+
configured_decoder = decoder["num_layers"] || @config["num_hidden_layers"]
|
|
256
|
+
validate_dimension!("encoder layer count", configured_encoder, encoder_layers) if configured_encoder
|
|
257
|
+
validate_dimension!("decoder layer count", configured_decoder, decoder_layers) if configured_decoder
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
def fetch_source_tensor(base_name)
|
|
261
|
+
@tensor_set.fetch_any([base_name, "model.#{base_name}"])
|
|
262
|
+
rescue Safetensors::Error, PyTorchCheckpoint::Error => e
|
|
263
|
+
raise Error, "Cohere dense checkpoint is missing #{base_name.inspect}: #{e.message}"
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def checkpoint_tensor_set
|
|
267
|
+
if model_directory.join("model.safetensors").file? ||
|
|
268
|
+
model_directory.join("model.safetensors.index.json").file?
|
|
269
|
+
Safetensors::TensorSet.from_directory(model_directory)
|
|
270
|
+
elsif model_directory.join("pytorch_model.bin").file? ||
|
|
271
|
+
model_directory.join("pytorch_model.bin.index.json").file?
|
|
272
|
+
PyTorchCheckpoint::TensorSet.from_directory(model_directory)
|
|
273
|
+
else
|
|
274
|
+
raise Error,
|
|
275
|
+
"#{model_directory} contains neither Safetensors nor PyTorch Dense weights"
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def validate_unmapped_tensors!(used_sources)
|
|
280
|
+
unexpected = @tensor_set.tensors.values.reject do |tensor|
|
|
281
|
+
used_sources.include?(tensor.name) ||
|
|
282
|
+
(tensor.floating_point? && FRONTEND_SOURCE_PATTERN.match?(tensor.name)) ||
|
|
283
|
+
(tensor.dtype == "I64" && COUNTER_SOURCE_PATTERN.match?(tensor.name))
|
|
284
|
+
end
|
|
285
|
+
return if unexpected.empty?
|
|
286
|
+
|
|
287
|
+
examples = unexpected.first(8).map { |tensor| "#{tensor.name} (#{tensor.dtype})" }.join(", ")
|
|
288
|
+
suffix = unexpected.length > 8 ? ", ..." : ""
|
|
289
|
+
raise Error, "Checkpoint contains unmapped model tensors: #{examples}#{suffix}"
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
def load_vocabulary
|
|
293
|
+
embedding = fetch_source_tensor("transf_decoder._embedding.token_embedding.weight")
|
|
294
|
+
unless embedding.shape.length == 2 && embedding.shape[0].positive?
|
|
295
|
+
raise Error, "Tensor #{embedding.name.inspect} has an invalid vocabulary shape #{embedding.shape.inspect}"
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
expected_size = embedding.shape[0]
|
|
299
|
+
tokenizer = read_json_object(model_directory.join("tokenizer.json"), "tokenizer")
|
|
300
|
+
vocab = tokenizer.dig("model", "vocab")
|
|
301
|
+
raise Error, "#{model_directory.join("tokenizer.json")} has no model vocabulary" unless vocab.is_a?(Hash) && !vocab.empty?
|
|
302
|
+
|
|
303
|
+
tokens_by_id = {}
|
|
304
|
+
ids_by_token = {}
|
|
305
|
+
vocab.each do |token, id|
|
|
306
|
+
add_vocabulary_entry!(tokens_by_id, ids_by_token, token, id, expected_size: expected_size)
|
|
307
|
+
end
|
|
308
|
+
added = tokenizer["added_tokens"] || []
|
|
309
|
+
raise Error, "tokenizer.json added_tokens must be an array" unless added.is_a?(Array)
|
|
310
|
+
|
|
311
|
+
added.each do |entry|
|
|
312
|
+
raise Error, "tokenizer.json contains an invalid added token" unless entry.is_a?(Hash)
|
|
313
|
+
|
|
314
|
+
add_vocabulary_entry!(
|
|
315
|
+
tokens_by_id,
|
|
316
|
+
ids_by_token,
|
|
317
|
+
entry["content"],
|
|
318
|
+
entry["id"],
|
|
319
|
+
expected_size: expected_size
|
|
320
|
+
)
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
missing = (0...expected_size).reject { |id| tokens_by_id.key?(id) }
|
|
324
|
+
raise Error, "tokenizer.json vocabulary has missing token IDs: #{missing.first(8).inspect}" unless missing.empty?
|
|
325
|
+
|
|
326
|
+
missing_prompt = REQUIRED_PROMPT_TOKENS.reject { |token| ids_by_token.key?(token) }
|
|
327
|
+
raise Error, "tokenizer.json is missing Cohere prompt tokens: #{missing_prompt.join(", ")}" unless missing_prompt.empty?
|
|
328
|
+
|
|
329
|
+
(0...expected_size).map { |id| tokens_by_id.fetch(id) }
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
def add_vocabulary_entry!(tokens_by_id, ids_by_token, token, id, expected_size:)
|
|
333
|
+
raise Error, "tokenizer.json contains an invalid token/id entry" unless token.is_a?(String) && id.is_a?(Integer) && id >= 0
|
|
334
|
+
raise Error, "tokenizer.json token ID #{id} is outside the checkpoint vocabulary size #{expected_size}" if id >= expected_size
|
|
335
|
+
|
|
336
|
+
previous_token = tokens_by_id[id]
|
|
337
|
+
if previous_token && previous_token != token
|
|
338
|
+
raise Error, "tokenizer.json assigns ID #{id} to both #{previous_token.inspect} and #{token.inspect}"
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
previous_id = ids_by_token[token]
|
|
342
|
+
raise Error, "tokenizer.json assigns token #{token.inspect} to IDs #{previous_id} and #{id}" if previous_id && previous_id != id
|
|
343
|
+
|
|
344
|
+
tokens_by_id[id] = token.freeze
|
|
345
|
+
ids_by_token[token] = id
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
def build_metadata(encoder_layers:, decoder_layers:, vocabulary:)
|
|
349
|
+
embedding = fetch_source_tensor("transf_decoder._embedding.token_embedding.weight")
|
|
350
|
+
projection = fetch_source_tensor("encoder_decoder_proj.weight")
|
|
351
|
+
encoder_ffn = fetch_source_tensor("encoder.layers.0.feed_forward1.linear1.weight")
|
|
352
|
+
encoder_conv = fetch_source_tensor("encoder.layers.0.conv.depthwise_conv.weight")
|
|
353
|
+
decoder_ffn = fetch_source_tensor("transf_decoder._decoder.layers.0.third_sub_layer.dense_in.weight")
|
|
354
|
+
position = fetch_source_tensor("transf_decoder._embedding.position_embedding.pos_enc")
|
|
355
|
+
pre_conv = fetch_source_tensor("encoder.pre_encode.conv.0.weight")
|
|
356
|
+
|
|
357
|
+
require_rank!(embedding, 2)
|
|
358
|
+
require_rank!(projection, 2)
|
|
359
|
+
require_rank!(encoder_ffn, 2)
|
|
360
|
+
require_rank!(encoder_conv, 3)
|
|
361
|
+
require_rank!(decoder_ffn, 2)
|
|
362
|
+
require_rank!(position, 2)
|
|
363
|
+
require_rank!(pre_conv, 4)
|
|
364
|
+
|
|
365
|
+
vocab_size, decoder_model = embedding.shape
|
|
366
|
+
projection_decoder, encoder_model = projection.shape
|
|
367
|
+
validate_dimension!("decoder model size", projection_decoder, decoder_model)
|
|
368
|
+
validate_dimension!("tokenizer vocabulary size", vocabulary.length, vocab_size)
|
|
369
|
+
|
|
370
|
+
encoder = @config["encoder_config"] || @config["encoder"] || {}
|
|
371
|
+
decoder = @config.dig("transf_decoder", "config_dict") || {}
|
|
372
|
+
encoder_heads = positive_integer(
|
|
373
|
+
encoder["num_attention_heads"] || encoder["n_heads"], "encoder attention heads"
|
|
374
|
+
)
|
|
375
|
+
decoder_heads = positive_integer(
|
|
376
|
+
decoder["num_attention_heads"] || @config["num_attention_heads"], "decoder attention heads"
|
|
377
|
+
)
|
|
378
|
+
unless (encoder_model % encoder_heads).zero? && (decoder_model % decoder_heads).zero?
|
|
379
|
+
raise Error, "Model dimensions are not divisible by their attention head counts"
|
|
380
|
+
end
|
|
381
|
+
|
|
382
|
+
pre_conv_channels = pre_conv.shape[0]
|
|
383
|
+
raise Error, "CrispASR Cohere backend requires 256 subsampling channels, got #{pre_conv_channels}" unless pre_conv_channels == 256
|
|
384
|
+
|
|
385
|
+
subsampling = encoder["subsampling_factor"]
|
|
386
|
+
validate_dimension!("encoder subsampling factor", subsampling, 8) if subsampling
|
|
387
|
+
|
|
388
|
+
preprocessor = @config["preprocessor"] || {}
|
|
389
|
+
sample_rate = positive_integer(@config["sample_rate"] || preprocessor["sample_rate"] || 16_000,
|
|
390
|
+
"sample rate")
|
|
391
|
+
n_fft = positive_integer(preprocessor["n_fft"] || 512, "FFT length")
|
|
392
|
+
n_mels = positive_integer(
|
|
393
|
+
encoder["num_mel_bins"] || encoder["feat_in"] || preprocessor["features"] || 128,
|
|
394
|
+
"mel feature count"
|
|
395
|
+
)
|
|
396
|
+
hop_length = positive_integer(
|
|
397
|
+
preprocessor["hop_length"] || seconds_to_samples(preprocessor["window_stride"], sample_rate) || 160,
|
|
398
|
+
"hop length"
|
|
399
|
+
)
|
|
400
|
+
win_length = positive_integer(
|
|
401
|
+
preprocessor["win_length"] || seconds_to_samples(preprocessor["window_size"], sample_rate) || 400,
|
|
402
|
+
"window length"
|
|
403
|
+
)
|
|
404
|
+
max_context = positive_integer(
|
|
405
|
+
decoder["max_sequence_length"] || @config["max_position_embeddings"] || position.shape[0],
|
|
406
|
+
"decoder context length"
|
|
407
|
+
)
|
|
408
|
+
|
|
409
|
+
{
|
|
410
|
+
"general.architecture" => [:string, "cohere-transcribe"],
|
|
411
|
+
"general.name" => [:string, @config["_name_or_path"] || model_directory.basename.to_s],
|
|
412
|
+
"general.file_type" => [:uint32, { f32: 0, f16: 1, bf16: 24 }.fetch(output_type)],
|
|
413
|
+
"cohere_transcribe.frontend" => [:string, "runtime-generated-fp32"],
|
|
414
|
+
"cohere_transcribe.vocab_size" => [:uint32, vocab_size],
|
|
415
|
+
"cohere_transcribe.encoder.n_layers" => [:uint32, encoder_layers],
|
|
416
|
+
"cohere_transcribe.encoder.d_model" => [:uint32, encoder_model],
|
|
417
|
+
"cohere_transcribe.encoder.n_heads" => [:uint32, encoder_heads],
|
|
418
|
+
"cohere_transcribe.encoder.head_dim" => [:uint32, encoder_model / encoder_heads],
|
|
419
|
+
"cohere_transcribe.encoder.ffn_dim" => [:uint32, encoder_ffn.shape[0]],
|
|
420
|
+
"cohere_transcribe.encoder.conv_kernel" => [:uint32, encoder_conv.shape[2]],
|
|
421
|
+
"cohere_transcribe.decoder.n_layers" => [:uint32, decoder_layers],
|
|
422
|
+
"cohere_transcribe.decoder.d_model" => [:uint32, decoder_model],
|
|
423
|
+
"cohere_transcribe.decoder.n_heads" => [:uint32, decoder_heads],
|
|
424
|
+
"cohere_transcribe.decoder.head_dim" => [:uint32, decoder_model / decoder_heads],
|
|
425
|
+
"cohere_transcribe.decoder.ffn_dim" => [:uint32, decoder_ffn.shape[0]],
|
|
426
|
+
"cohere_transcribe.decoder.max_ctx" => [:uint32, max_context],
|
|
427
|
+
"cohere_transcribe.audio.sample_rate" => [:uint32, sample_rate],
|
|
428
|
+
"cohere_transcribe.audio.n_mels" => [:uint32, n_mels],
|
|
429
|
+
"cohere_transcribe.audio.n_fft" => [:uint32, n_fft],
|
|
430
|
+
"cohere_transcribe.audio.hop_length" => [:uint32, hop_length],
|
|
431
|
+
"cohere_transcribe.audio.win_length" => [:uint32, win_length],
|
|
432
|
+
"tokenizer.ggml.tokens" => [:string_array, vocabulary],
|
|
433
|
+
"tokenizer.ggml.model" => [:string, "llama"]
|
|
434
|
+
}
|
|
435
|
+
end
|
|
436
|
+
|
|
437
|
+
def validate_shapes!(metadata, vocabulary)
|
|
438
|
+
encoder_model = metadata.fetch("cohere_transcribe.encoder.d_model")[1]
|
|
439
|
+
decoder_model = metadata.fetch("cohere_transcribe.decoder.d_model")[1]
|
|
440
|
+
encoder_ffn = metadata.fetch("cohere_transcribe.encoder.ffn_dim")[1]
|
|
441
|
+
decoder_ffn = metadata.fetch("cohere_transcribe.decoder.ffn_dim")[1]
|
|
442
|
+
vocab_size = vocabulary.length
|
|
443
|
+
|
|
444
|
+
validate_shape!("encoder_decoder_proj.weight", [decoder_model, encoder_model])
|
|
445
|
+
validate_shape!("transf_decoder._embedding.token_embedding.weight", [vocab_size, decoder_model])
|
|
446
|
+
validate_shape!("log_softmax.mlp.layer0.weight", [vocab_size, decoder_model])
|
|
447
|
+
validate_shape!("encoder.layers.0.feed_forward1.linear1.weight", [encoder_ffn, encoder_model])
|
|
448
|
+
validate_shape!("transf_decoder._decoder.layers.0.third_sub_layer.dense_in.weight",
|
|
449
|
+
[decoder_ffn, decoder_model])
|
|
450
|
+
end
|
|
451
|
+
|
|
452
|
+
def validate_shape!(source_name, expected)
|
|
453
|
+
tensor = fetch_source_tensor(source_name)
|
|
454
|
+
return if tensor.shape == expected
|
|
455
|
+
|
|
456
|
+
raise Error, "Tensor #{tensor.name.inspect} has shape #{tensor.shape.inspect}; expected #{expected.inspect}"
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
def validate_dimension!(description, actual, expected)
|
|
460
|
+
return if Integer(actual) == Integer(expected)
|
|
461
|
+
|
|
462
|
+
raise Error, "Configured #{description} is #{actual}; checkpoint requires #{expected}"
|
|
463
|
+
end
|
|
464
|
+
|
|
465
|
+
def positive_integer(value, description)
|
|
466
|
+
integer = Integer(value)
|
|
467
|
+
raise Error, "#{description} must be positive" unless integer.positive?
|
|
468
|
+
|
|
469
|
+
integer
|
|
470
|
+
rescue ArgumentError, TypeError
|
|
471
|
+
raise Error, "#{description} is missing or invalid"
|
|
472
|
+
end
|
|
473
|
+
|
|
474
|
+
def seconds_to_samples(value, sample_rate)
|
|
475
|
+
return unless value
|
|
476
|
+
|
|
477
|
+
(Float(value) * sample_rate).round
|
|
478
|
+
rescue ArgumentError, TypeError
|
|
479
|
+
raise Error, "Audio window configuration is invalid"
|
|
480
|
+
end
|
|
481
|
+
|
|
482
|
+
def require_rank!(tensor, rank)
|
|
483
|
+
return if tensor.shape.length == rank
|
|
484
|
+
|
|
485
|
+
raise Error, "Tensor #{tensor.name.inspect} must have rank #{rank}, got #{tensor.shape.inspect}"
|
|
486
|
+
end
|
|
487
|
+
|
|
488
|
+
def build_writer(conversion_plan)
|
|
489
|
+
writer = GGUF::Writer.new
|
|
490
|
+
conversion_plan.metadata.each do |key, (type, value)|
|
|
491
|
+
case type
|
|
492
|
+
when :string then writer.add_string(key, value)
|
|
493
|
+
when :uint32 then writer.add_uint32(key, value)
|
|
494
|
+
when :string_array then writer.add_string_array(key, value)
|
|
495
|
+
else raise Error, "Unsupported converter metadata type #{type.inspect}"
|
|
496
|
+
end
|
|
497
|
+
end
|
|
498
|
+
|
|
499
|
+
total = conversion_plan.tensors.length
|
|
500
|
+
conversion_plan.tensors.each_with_index do |planned, index|
|
|
501
|
+
writer.add_tensor(
|
|
502
|
+
planned.output_name,
|
|
503
|
+
shape: planned.source_tensor.shape,
|
|
504
|
+
dtype: planned.output_dtype,
|
|
505
|
+
&tensor_writer(planned, index, total)
|
|
506
|
+
)
|
|
507
|
+
end
|
|
508
|
+
writer
|
|
509
|
+
end
|
|
510
|
+
|
|
511
|
+
def tensor_writer(planned, index, total)
|
|
512
|
+
lambda do |output|
|
|
513
|
+
tensor = planned.source_tensor
|
|
514
|
+
tensor.reader.write_tensor(
|
|
515
|
+
tensor,
|
|
516
|
+
output,
|
|
517
|
+
target_dtype: planned.output_dtype,
|
|
518
|
+
converter: dtype_converter,
|
|
519
|
+
chunk_bytes: chunk_bytes
|
|
520
|
+
)
|
|
521
|
+
progress&.call(
|
|
522
|
+
index: index + 1,
|
|
523
|
+
total: total,
|
|
524
|
+
output_name: planned.output_name,
|
|
525
|
+
source_name: tensor.name,
|
|
526
|
+
source_dtype: tensor.dtype,
|
|
527
|
+
output_dtype: planned.output_dtype
|
|
528
|
+
)
|
|
529
|
+
end
|
|
530
|
+
end
|
|
531
|
+
|
|
532
|
+
def read_json_object(path, description)
|
|
533
|
+
value = JSON.parse(path.read(encoding: "UTF-8"))
|
|
534
|
+
raise Error, "#{description.capitalize} #{path} is not a JSON object" unless value.is_a?(Hash)
|
|
535
|
+
|
|
536
|
+
value
|
|
537
|
+
rescue Errno::ENOENT
|
|
538
|
+
raise Error, "#{model_directory} is missing #{path.basename}"
|
|
539
|
+
rescue JSON::ParserError, EncodingError => e
|
|
540
|
+
raise Error, "Cannot read #{description} #{path}: #{e.message}"
|
|
541
|
+
end
|
|
542
|
+
|
|
543
|
+
def tally(values)
|
|
544
|
+
values.tally.transform_keys(&:to_s).freeze
|
|
545
|
+
end
|
|
546
|
+
end
|
|
547
|
+
end
|
|
548
|
+
end
|