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,600 @@
|
|
|
1
|
+
#include "common.cuh"
|
|
2
|
+
#include "fattn-common.cuh"
|
|
3
|
+
|
|
4
|
+
static int ggml_cuda_fattn_vec_get_nthreads_host(const int cc) {
|
|
5
|
+
return 128;
|
|
6
|
+
GGML_UNUSED(cc);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static constexpr __device__ int ggml_cuda_fattn_vec_get_nthreads_device() {
|
|
10
|
+
return 128;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Currently llvm with the amdgcn target does not support unrolling loops
|
|
14
|
+
// that contain a break that can not be resolved at compile time.
|
|
15
|
+
#ifdef __clang__
|
|
16
|
+
#pragma clang diagnostic push
|
|
17
|
+
#pragma clang diagnostic ignored "-Wpass-failed"
|
|
18
|
+
#endif // __clang__
|
|
19
|
+
template<int D, int ncols, ggml_type type_K, ggml_type type_V, bool use_logit_softcap> // D == head size
|
|
20
|
+
__launch_bounds__(ggml_cuda_fattn_vec_get_nthreads_device(), 1)
|
|
21
|
+
static __global__ void flash_attn_ext_vec(
|
|
22
|
+
const char * __restrict__ Q,
|
|
23
|
+
const char * __restrict__ K,
|
|
24
|
+
const char * __restrict__ V,
|
|
25
|
+
const char * __restrict__ mask,
|
|
26
|
+
const char * __restrict__ sinks,
|
|
27
|
+
const int * __restrict__ KV_max,
|
|
28
|
+
float * __restrict__ dst,
|
|
29
|
+
float2 * __restrict__ dst_meta,
|
|
30
|
+
const float scale,
|
|
31
|
+
const float max_bias,
|
|
32
|
+
const float m0,
|
|
33
|
+
const float m1,
|
|
34
|
+
const uint32_t n_head_log2,
|
|
35
|
+
const float logit_softcap,
|
|
36
|
+
const int32_t ne00, const uint3 ne01, const int32_t ne02, const int32_t ne03,
|
|
37
|
+
const int32_t nb01, const int32_t nb02, const int32_t nb03,
|
|
38
|
+
const int32_t ne10, const int32_t ne11, const int32_t ne12, const int32_t ne13,
|
|
39
|
+
const int32_t nb11, const int32_t nb12, const int64_t nb13,
|
|
40
|
+
const int32_t nb21, const int32_t nb22, const int64_t nb23,
|
|
41
|
+
const int32_t ne31, const int32_t ne32, const int32_t ne33,
|
|
42
|
+
const int32_t nb31, const int32_t nb32, const int64_t nb33) {
|
|
43
|
+
#ifdef FLASH_ATTN_AVAILABLE
|
|
44
|
+
|
|
45
|
+
// Skip unused kernel variants for faster compilation:
|
|
46
|
+
if (use_logit_softcap && !(D == 128 || D == 256)) {
|
|
47
|
+
GGML_UNUSED_VARS(Q, K, V, mask, sinks, KV_max, dst, dst_meta, scale,
|
|
48
|
+
max_bias, m0, m1, n_head_log2, logit_softcap,
|
|
49
|
+
ne00, ne01, ne02, ne03,
|
|
50
|
+
nb01, nb02, nb03,
|
|
51
|
+
ne10, ne11, ne12, ne13,
|
|
52
|
+
nb11, nb12, nb13,
|
|
53
|
+
nb21, nb22, nb23,
|
|
54
|
+
ne31, ne32, ne33,
|
|
55
|
+
nb31, nb32, nb33);
|
|
56
|
+
NO_DEVICE_CODE;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//In this kernel Q, K, V are matrices while i, j, k are matrix indices.
|
|
61
|
+
|
|
62
|
+
constexpr int cpy_nb = ggml_cuda_get_max_cpy_bytes();
|
|
63
|
+
constexpr int cpy_ne = cpy_nb / 4;
|
|
64
|
+
|
|
65
|
+
#ifdef GGML_USE_HIP
|
|
66
|
+
#ifdef RDNA
|
|
67
|
+
constexpr int nthreads_KQ_q = 2;
|
|
68
|
+
#else
|
|
69
|
+
constexpr int nthreads_KQ_q = 4;
|
|
70
|
+
#endif // RDNA
|
|
71
|
+
constexpr int nthreads_V_q = (D/4 < 32 ? D/4 : 32);
|
|
72
|
+
#else
|
|
73
|
+
constexpr int nthreads_KQ_q = (D/4 < 32 ? D/4 : 32);
|
|
74
|
+
constexpr int nthreads_V_q = (D/4 < 32 ? D/4 : 32);
|
|
75
|
+
#endif // GGML_USE_HIP
|
|
76
|
+
|
|
77
|
+
constexpr int nthreads = ggml_cuda_fattn_vec_get_nthreads_device();
|
|
78
|
+
constexpr int nthreads_KQ = (type_K == GGML_TYPE_F16 || type_K == GGML_TYPE_BF16) ? 128 / cpy_nb : nthreads_KQ_q;
|
|
79
|
+
constexpr int nthreads_V = (type_V == GGML_TYPE_F16 || type_V == GGML_TYPE_BF16) ? 128 / cpy_nb : nthreads_V_q;
|
|
80
|
+
|
|
81
|
+
static_assert(WARP_SIZE % nthreads_KQ == 0, "bad nthreads_K");
|
|
82
|
+
static_assert(WARP_SIZE % nthreads_V == 0, "bad nthreads_V");
|
|
83
|
+
|
|
84
|
+
constexpr int V_rows_per_thread = (type_V == GGML_TYPE_F16 || type_V == GGML_TYPE_BF16) ? 2*cpy_ne : 4;
|
|
85
|
+
constexpr int V_cols_per_iter = WARP_SIZE / nthreads_V;
|
|
86
|
+
|
|
87
|
+
constexpr vec_dot_KQ_t vec_dot_KQ = get_vec_dot_KQ<type_K, D, nthreads_KQ>();
|
|
88
|
+
constexpr bool Q_q8_1 = type_K != GGML_TYPE_F16 && type_K != GGML_TYPE_BF16;
|
|
89
|
+
#ifdef V_DOT2_F32_F16_AVAILABLE
|
|
90
|
+
constexpr dequantize_V_t dequantize_V = get_dequantize_V<type_V, half, V_rows_per_thread>();
|
|
91
|
+
#else
|
|
92
|
+
constexpr dequantize_V_t dequantize_V = get_dequantize_V<type_V, float, V_rows_per_thread>();
|
|
93
|
+
#endif // V_DOT2_F32_F16_AVAILABLE
|
|
94
|
+
|
|
95
|
+
const int ic0 = blockIdx.x * ncols; // Index of the Q/QKV column to work on.
|
|
96
|
+
|
|
97
|
+
const int sequence = blockIdx.z / ne02;
|
|
98
|
+
const int head = blockIdx.z - sequence*ne02;
|
|
99
|
+
const int gqa_ratio = ne02 / ne12; // With grouped query attention there are > 1 Q matrices per K, V matrix.
|
|
100
|
+
Q += nb03*sequence + nb02* head + nb01*ic0;
|
|
101
|
+
K += nb13*sequence + nb12*(head / gqa_ratio);
|
|
102
|
+
V += nb23*sequence + nb22*(head / gqa_ratio);
|
|
103
|
+
|
|
104
|
+
const half * maskh = (const half *) (mask + nb33*(sequence % ne33) + nb31*ic0);
|
|
105
|
+
|
|
106
|
+
const float slope = get_alibi_slope(max_bias, head, n_head_log2, m0, m1);
|
|
107
|
+
|
|
108
|
+
static_assert(D % (2*WARP_SIZE) == 0, "D not divisible by 2*WARP_SIZE == 64.");
|
|
109
|
+
constexpr int nwarps = nthreads / WARP_SIZE;
|
|
110
|
+
const int tid = WARP_SIZE*threadIdx.y + threadIdx.x;
|
|
111
|
+
__builtin_assume(tid < nthreads);
|
|
112
|
+
|
|
113
|
+
constexpr int ne_KQ = ncols*D;
|
|
114
|
+
constexpr int ne_combine = nwarps*V_cols_per_iter*D;
|
|
115
|
+
#ifdef V_DOT2_F32_F16_AVAILABLE
|
|
116
|
+
half2 VKQ[ncols][(D/2)/nthreads_V] = {{{0.0f, 0.0f}}};
|
|
117
|
+
__shared__ half KQ[ne_KQ > ne_combine ? ne_KQ : ne_combine];
|
|
118
|
+
#else
|
|
119
|
+
float2 VKQ[ncols][(D/2)/nthreads_V] = {{{0.0f, 0.0f}}};
|
|
120
|
+
__shared__ float KQ[ne_KQ > ne_combine ? ne_KQ : ne_combine];
|
|
121
|
+
#endif // V_DOT2_F32_F16_AVAILABLE
|
|
122
|
+
|
|
123
|
+
float KQ_max[ncols];
|
|
124
|
+
float KQ_sum[ncols];
|
|
125
|
+
#pragma unroll
|
|
126
|
+
for (int j = 0; j < ncols; ++j) {
|
|
127
|
+
KQ_max[j] = -FLT_MAX/2.0f;
|
|
128
|
+
KQ_sum[j] = 0.0f;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Convert Q to float2 (f16 K) or q8_1 (quantized K) and store in registers:
|
|
132
|
+
#ifdef V_DOT2_F32_F16_AVAILABLE
|
|
133
|
+
half2 Q_reg[ncols][(D/2)/nthreads_KQ]; // Will be initialized completely.
|
|
134
|
+
#else
|
|
135
|
+
__align__(16) float2 Q_reg[ncols][(D/2)/nthreads_KQ] = {{{0.0f, 0.0f}}}; // May be only partially initialized.
|
|
136
|
+
#endif // V_DOT2_F32_F16_AVAILABLE
|
|
137
|
+
int Q_i32[ncols][1 > D/(sizeof(int)*nthreads_KQ) ? 1 : D/(sizeof(int)*nthreads_KQ)];
|
|
138
|
+
float2 Q_ds[ncols][1 > D/(sizeof(int)*nthreads_KQ) ? 1 : D/(sizeof(int)*nthreads_KQ)];
|
|
139
|
+
if constexpr (Q_q8_1) {
|
|
140
|
+
#pragma unroll
|
|
141
|
+
for (int j0 = 0; j0 < ncols; j0 += nwarps) {
|
|
142
|
+
const int j = j0 + threadIdx.y;
|
|
143
|
+
|
|
144
|
+
if (j0 + nwarps > ncols && j >= ncols) {
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Reuse KQ as temporary storage for converting Q to q8_1:
|
|
149
|
+
int * tmp_q_i32 = (int *) &KQ[j*D];
|
|
150
|
+
float2 * tmp_q_ds = (float2 *) (tmp_q_i32 + D/sizeof(int));
|
|
151
|
+
|
|
152
|
+
// Set memory to zero if out of bounds:
|
|
153
|
+
if (ncols > 1 && ic0 + j >= int(ne01.z)) {
|
|
154
|
+
#pragma unroll
|
|
155
|
+
for (int i0 = 0; i0 < int(D/sizeof(int)); i0 += WARP_SIZE) {
|
|
156
|
+
const int i = i0 + threadIdx.x;
|
|
157
|
+
|
|
158
|
+
if (i0 + WARP_SIZE <= int(D/sizeof(int)) || i < int(D/sizeof(int))) {
|
|
159
|
+
tmp_q_i32[i] = 0;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (threadIdx.x < D/QK8_1) {
|
|
163
|
+
tmp_q_ds[threadIdx.x] = make_float2(0.0f, 0.0f);
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
const float * Q_f = (const float *) (Q + j*nb01);
|
|
167
|
+
constexpr int nthreads_quantize = D/sizeof(int) < WARP_SIZE ? D/sizeof(int) : WARP_SIZE;
|
|
168
|
+
#pragma unroll
|
|
169
|
+
for (int i0 = 0; i0 < int(D/sizeof(int)); i0 += nthreads_quantize) {
|
|
170
|
+
quantize_q8_1_to_shared<float2, nthreads_quantize>
|
|
171
|
+
(Q_f + i0*sizeof(int), scale, tmp_q_i32 + i0, tmp_q_ds + i0/QI8_1);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
__syncthreads();
|
|
177
|
+
|
|
178
|
+
#pragma unroll
|
|
179
|
+
for (int j = 0; j < ncols; ++j) {
|
|
180
|
+
int * tmp_q_i32 = (int *) &KQ[j*D];
|
|
181
|
+
float2 * tmp_q_ds = (float2 *) (tmp_q_i32 + D/sizeof(int));
|
|
182
|
+
|
|
183
|
+
#pragma unroll
|
|
184
|
+
for (int i0 = 0; i0 < int(D/sizeof(int)); i0 += nthreads_KQ) {
|
|
185
|
+
const int i = i0 + (nthreads_KQ == WARP_SIZE ? threadIdx.x : threadIdx.x % nthreads_KQ);
|
|
186
|
+
|
|
187
|
+
Q_i32[j][i0/nthreads_KQ] = tmp_q_i32[i];
|
|
188
|
+
Q_ds[j][i0/nthreads_KQ] = tmp_q_ds[i/QI8_1];
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
__syncthreads();
|
|
193
|
+
} else {
|
|
194
|
+
#ifdef V_DOT2_F32_F16_AVAILABLE
|
|
195
|
+
const half2 scale_h2 = make_half2(scale, scale);
|
|
196
|
+
#pragma unroll
|
|
197
|
+
for (int j = 0; j < ncols; ++j) {
|
|
198
|
+
const float2 * Q_j = (const float2 *) (Q + j*nb01);
|
|
199
|
+
#pragma unroll
|
|
200
|
+
for (int i0 = 0; i0 < D/2; i0 += nthreads_KQ*cpy_ne) {
|
|
201
|
+
const int i = i0 + (nthreads_KQ == WARP_SIZE ? threadIdx.x : threadIdx.x % nthreads_KQ)*cpy_ne;
|
|
202
|
+
|
|
203
|
+
__align__(16) float2 tmp[cpy_ne] = {{0.0f, 0.0f}};
|
|
204
|
+
if (ncols == 1 || ic0 + j < int(ne01.z)) {
|
|
205
|
+
ggml_cuda_memcpy_1<cpy_nb>(tmp, &Q_j[i]);
|
|
206
|
+
ggml_cuda_memcpy_1<cpy_nb>(tmp + cpy_ne/2, &Q_j[i + cpy_ne/2]);
|
|
207
|
+
}
|
|
208
|
+
#pragma unroll
|
|
209
|
+
for (int i1 = 0; i1 < cpy_ne; ++i1) {
|
|
210
|
+
Q_reg[j][i0/nthreads_KQ + i1] = make_half2(tmp[i1].x, tmp[i1].y);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
#pragma unroll
|
|
214
|
+
for (int k = 0; k < (D/2)/nthreads_KQ; ++k) {
|
|
215
|
+
Q_reg[j][k] *= scale_h2;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
#else
|
|
219
|
+
#pragma unroll
|
|
220
|
+
for (int j = 0; j < ncols; ++j) {
|
|
221
|
+
const float2 * Q_j = (const float2 *) (Q + j*nb01);
|
|
222
|
+
#pragma unroll
|
|
223
|
+
for (int i0 = 0; i0 < D/2; i0 += nthreads_KQ*cpy_ne) {
|
|
224
|
+
const int i = i0 + (nthreads_KQ == WARP_SIZE ? threadIdx.x : threadIdx.x % nthreads_KQ)*cpy_ne;
|
|
225
|
+
if (ncols == 1 || ic0 + j < int(ne01.z)) {
|
|
226
|
+
ggml_cuda_memcpy_1<cpy_nb>(&Q_reg[j][i0/nthreads_KQ], &Q_j[i]);
|
|
227
|
+
ggml_cuda_memcpy_1<cpy_nb>(&Q_reg[j][i0/nthreads_KQ + cpy_ne/2], &Q_j[i + cpy_ne/2]);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
#pragma unroll
|
|
231
|
+
for (int k = 0; k < (D/2)/nthreads_KQ; ++k) {
|
|
232
|
+
Q_reg[j][k].x *= scale;
|
|
233
|
+
Q_reg[j][k].y *= scale;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
#endif // V_DOT2_F32_F16_AVAILABLE
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const int k_VKQ_max = KV_max ? KV_max[sequence*gridDim.x + blockIdx.x] : ne11;
|
|
240
|
+
K += blockIdx.y*nthreads * nb11;
|
|
241
|
+
V += blockIdx.y*nthreads * nb21;
|
|
242
|
+
maskh += blockIdx.y*nthreads;
|
|
243
|
+
for (int k_VKQ_0 = blockIdx.y*nthreads; k_VKQ_0 < k_VKQ_max; k_VKQ_0 += gridDim.y*nthreads,
|
|
244
|
+
// Increment pointers after each loop:
|
|
245
|
+
K += gridDim.y*nthreads*nb11, V += gridDim.y*nthreads*nb21, maskh += gridDim.y*nthreads) {
|
|
246
|
+
|
|
247
|
+
// Calculate KQ tile and keep track of new maximum KQ values:
|
|
248
|
+
float KQ_reg[ncols]; // KQ in registers.
|
|
249
|
+
|
|
250
|
+
float KQ_max_new[ncols];
|
|
251
|
+
#pragma unroll
|
|
252
|
+
for (int j = 0; j < ncols; ++j) {
|
|
253
|
+
KQ_max_new[j] = KQ_max[j];
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
#pragma unroll
|
|
257
|
+
for (int i_KQ_0 = 0; i_KQ_0 < nthreads_KQ; ++i_KQ_0) {
|
|
258
|
+
const int i_KQ = threadIdx.y*WARP_SIZE + (nthreads_KQ == WARP_SIZE ? 0 : (threadIdx.x & ~(nthreads_KQ-1))) + i_KQ_0;
|
|
259
|
+
|
|
260
|
+
#pragma unroll
|
|
261
|
+
for (int j = 0; j < ncols; ++j) {
|
|
262
|
+
float sum = vec_dot_KQ(K + i_KQ*nb11, Q_reg[j], Q_i32[j], Q_ds[j]);
|
|
263
|
+
sum = warp_reduce_sum<nthreads_KQ>(sum);
|
|
264
|
+
|
|
265
|
+
if (use_logit_softcap) {
|
|
266
|
+
sum = logit_softcap*tanhf(sum);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (mask && (ncols == 1 || ic0 + j < int(ne01.z))) {
|
|
270
|
+
sum += slope*__half2float(maskh[j*ne11 + i_KQ]);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
KQ_max_new[j] = fmaxf(KQ_max_new[j], sum + FATTN_KQ_MAX_OFFSET);
|
|
274
|
+
|
|
275
|
+
if ((nthreads_KQ == WARP_SIZE ? threadIdx.x : threadIdx.x % nthreads_KQ) == uint32_t(i_KQ_0)) {
|
|
276
|
+
KQ_reg[j] = sum;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
#pragma unroll
|
|
282
|
+
for (int j = 0; j < ncols; ++j) {
|
|
283
|
+
#pragma unroll
|
|
284
|
+
for (int offset = nthreads_KQ; offset < WARP_SIZE; offset <<= 1) {
|
|
285
|
+
KQ_max_new[j] = fmaxf(KQ_max_new[j], __shfl_xor_sync(0xFFFFFFFF, KQ_max_new[j], offset, WARP_SIZE));
|
|
286
|
+
}
|
|
287
|
+
const float KQ_max_scale = expf(KQ_max[j] - KQ_max_new[j]);
|
|
288
|
+
KQ_max[j] = KQ_max_new[j];
|
|
289
|
+
|
|
290
|
+
KQ_reg[j] = expf(KQ_reg[j] - KQ_max[j]);
|
|
291
|
+
KQ_sum[j] = KQ_sum[j]*KQ_max_scale + KQ_reg[j];
|
|
292
|
+
KQ[j*nthreads + tid] = KQ_reg[j];
|
|
293
|
+
|
|
294
|
+
#ifdef V_DOT2_F32_F16_AVAILABLE
|
|
295
|
+
const half2 KQ_max_scale_h2 = make_half2(KQ_max_scale, KQ_max_scale);
|
|
296
|
+
#pragma unroll
|
|
297
|
+
for (int i_VKQ_0 = 0; i_VKQ_0 < D/2; i_VKQ_0 += nthreads_V) {
|
|
298
|
+
VKQ[j][i_VKQ_0/nthreads_V] *= KQ_max_scale_h2;
|
|
299
|
+
}
|
|
300
|
+
#else
|
|
301
|
+
#pragma unroll
|
|
302
|
+
for (int i_VKQ_0 = 0; i_VKQ_0 < D/2; i_VKQ_0 += nthreads_V) {
|
|
303
|
+
VKQ[j][i_VKQ_0/nthreads_V].x *= KQ_max_scale;
|
|
304
|
+
VKQ[j][i_VKQ_0/nthreads_V].y *= KQ_max_scale;
|
|
305
|
+
}
|
|
306
|
+
#endif // V_DOT2_F32_F16_AVAILABLE
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
#ifndef GGML_USE_HIP
|
|
310
|
+
__syncwarp();
|
|
311
|
+
#endif // GGML_USE_HIP
|
|
312
|
+
|
|
313
|
+
#pragma unroll
|
|
314
|
+
for (int k0 = 0; k0 < WARP_SIZE; k0 += V_cols_per_iter) {
|
|
315
|
+
const int k = threadIdx.y*WARP_SIZE + k0 + (nthreads_V == WARP_SIZE ? 0 : threadIdx.x / nthreads_V);
|
|
316
|
+
|
|
317
|
+
#ifdef V_DOT2_F32_F16_AVAILABLE
|
|
318
|
+
half2 KQ_k[ncols];
|
|
319
|
+
#pragma unroll
|
|
320
|
+
for (int j = 0; j < ncols; ++j) {
|
|
321
|
+
KQ_k[j] = __half2half2(KQ[j*nthreads + k]);
|
|
322
|
+
}
|
|
323
|
+
#pragma unroll
|
|
324
|
+
for (int i_VKQ_0 = 0; i_VKQ_0 < D/2; i_VKQ_0 += nthreads_V*V_rows_per_thread/2) {
|
|
325
|
+
half2 tmp[V_rows_per_thread/2];
|
|
326
|
+
if constexpr (type_V == GGML_TYPE_BF16) {
|
|
327
|
+
float2 tmp_f[V_rows_per_thread/2];
|
|
328
|
+
dequantize_V(V + k*nb21, tmp_f,
|
|
329
|
+
2*i_VKQ_0 + (nthreads_V == WARP_SIZE ? threadIdx.x : threadIdx.x % nthreads_V)*V_rows_per_thread);
|
|
330
|
+
#pragma unroll
|
|
331
|
+
for (int i_VKQ_1 = 0; i_VKQ_1 < V_rows_per_thread/2; ++i_VKQ_1) {
|
|
332
|
+
tmp[i_VKQ_1] = __float22half2_rn(tmp_f[i_VKQ_1]);
|
|
333
|
+
}
|
|
334
|
+
} else {
|
|
335
|
+
dequantize_V(V + k*nb21, tmp,
|
|
336
|
+
2*i_VKQ_0 + (nthreads_V == WARP_SIZE ? threadIdx.x : threadIdx.x % nthreads_V)*V_rows_per_thread);
|
|
337
|
+
}
|
|
338
|
+
#pragma unroll
|
|
339
|
+
for (int i_VKQ_1 = 0; i_VKQ_1 < V_rows_per_thread/2; ++i_VKQ_1) {
|
|
340
|
+
#pragma unroll
|
|
341
|
+
for (int j = 0; j < ncols; ++j) {
|
|
342
|
+
VKQ[j][i_VKQ_0/nthreads_V + i_VKQ_1] += tmp[i_VKQ_1]*KQ_k[j];
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
#else
|
|
347
|
+
float KQ_k[ncols];
|
|
348
|
+
#pragma unroll
|
|
349
|
+
for (int j = 0; j < ncols; ++j) {
|
|
350
|
+
KQ_k[j] = KQ[j*nthreads + k];
|
|
351
|
+
}
|
|
352
|
+
#pragma unroll
|
|
353
|
+
for (int i_VKQ_0 = 0; i_VKQ_0 < D/2; i_VKQ_0 += nthreads_V*V_rows_per_thread/2) {
|
|
354
|
+
float2 tmp[V_rows_per_thread/2];
|
|
355
|
+
dequantize_V(V + k*nb21, tmp,
|
|
356
|
+
2*i_VKQ_0 + (nthreads_V == WARP_SIZE ? threadIdx.x : threadIdx.x % nthreads_V)*V_rows_per_thread);
|
|
357
|
+
#pragma unroll
|
|
358
|
+
for (int i_VKQ_1 = 0; i_VKQ_1 < V_rows_per_thread/2; ++i_VKQ_1) {
|
|
359
|
+
#pragma unroll
|
|
360
|
+
for (int j = 0; j < ncols; ++j) {
|
|
361
|
+
VKQ[j][i_VKQ_0/nthreads_V + i_VKQ_1].x += tmp[i_VKQ_1].x*KQ_k[j];
|
|
362
|
+
VKQ[j][i_VKQ_0/nthreads_V + i_VKQ_1].y += tmp[i_VKQ_1].y*KQ_k[j];
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
#endif // V_DOT2_F32_F16_AVAILABLE
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (sinks && blockIdx.y == 0) {
|
|
371
|
+
const float sink = ((const float *) sinks)[head];
|
|
372
|
+
|
|
373
|
+
#pragma unroll
|
|
374
|
+
for (int j0 = 0; j0 < ncols; j0 += nwarps) {
|
|
375
|
+
const int j = j0 + threadIdx.y;
|
|
376
|
+
|
|
377
|
+
if (j0 + nwarps > ncols && j >= ncols) {
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const float kqmax_new_j = fmaxf(sink, KQ_max[j]);
|
|
382
|
+
const float KQ_max_scale = expf(KQ_max[j] - kqmax_new_j);
|
|
383
|
+
KQ_max[j] = kqmax_new_j;
|
|
384
|
+
|
|
385
|
+
KQ_sum[j] = KQ_sum[j]*KQ_max_scale + (threadIdx.x == 0 ? expf(sink - KQ_max[j]) : 0.0f);
|
|
386
|
+
|
|
387
|
+
#ifdef V_DOT2_F32_F16_AVAILABLE
|
|
388
|
+
const half2 KQ_max_scale_h2 = make_half2(KQ_max_scale, KQ_max_scale);
|
|
389
|
+
#pragma unroll
|
|
390
|
+
for (int i_VKQ_0 = 0; i_VKQ_0 < D/2; i_VKQ_0 += nthreads_V) {
|
|
391
|
+
VKQ[j][i_VKQ_0/nthreads_V] *= KQ_max_scale_h2;
|
|
392
|
+
}
|
|
393
|
+
#else
|
|
394
|
+
#pragma unroll
|
|
395
|
+
for (int i_VKQ_0 = 0; i_VKQ_0 < D/2; i_VKQ_0 += nthreads_V) {
|
|
396
|
+
VKQ[j][i_VKQ_0/nthreads_V].x *= KQ_max_scale;
|
|
397
|
+
VKQ[j][i_VKQ_0/nthreads_V].y *= KQ_max_scale;
|
|
398
|
+
}
|
|
399
|
+
#endif // V_DOT2_F32_F16_AVAILABLE
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
__shared__ float KQ_max_shared[ncols][WARP_SIZE];
|
|
404
|
+
__shared__ float KQ_sum_shared[ncols][WARP_SIZE];
|
|
405
|
+
#pragma unroll
|
|
406
|
+
for (int j = 0; j < ncols; ++j) {
|
|
407
|
+
if (threadIdx.y == 0) {
|
|
408
|
+
KQ_max_shared[j][threadIdx.x] = -FLT_MAX/2.0f;
|
|
409
|
+
KQ_sum_shared[j][threadIdx.x] = 0.0f;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
__syncthreads();
|
|
414
|
+
|
|
415
|
+
#pragma unroll
|
|
416
|
+
for (int j = 0; j < ncols; ++j) {
|
|
417
|
+
if (threadIdx.x == 0) {
|
|
418
|
+
KQ_max_shared[j][threadIdx.y] = KQ_max[j];
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
__syncthreads();
|
|
422
|
+
|
|
423
|
+
#pragma unroll
|
|
424
|
+
for (int j_VKQ = 0; j_VKQ < ncols; ++j_VKQ) {
|
|
425
|
+
if (ncols > 1 && ic0 + j_VKQ >= int(ne01.z)) {
|
|
426
|
+
break;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
float kqmax_new = KQ_max_shared[j_VKQ][threadIdx.x];
|
|
430
|
+
kqmax_new = warp_reduce_max(kqmax_new);
|
|
431
|
+
const float kqmax_scale = expf(KQ_max[j_VKQ] - kqmax_new);
|
|
432
|
+
KQ_max[j_VKQ] = kqmax_new;
|
|
433
|
+
|
|
434
|
+
#ifdef V_DOT2_F32_F16_AVAILABLE
|
|
435
|
+
half2 * VKQ_tmp = (half2 *) KQ + threadIdx.y*(V_cols_per_iter*D/2)
|
|
436
|
+
+ (nthreads_V == WARP_SIZE ? 0 : threadIdx.x / nthreads_V)*(D/2);
|
|
437
|
+
|
|
438
|
+
const half2 kqmax_scale_h2 = make_half2(kqmax_scale, kqmax_scale);
|
|
439
|
+
#pragma unroll
|
|
440
|
+
for (int i_VKQ_0 = 0; i_VKQ_0 < D/2; i_VKQ_0 += nthreads_V) {
|
|
441
|
+
VKQ[j_VKQ][i_VKQ_0/nthreads_V] *= kqmax_scale_h2;
|
|
442
|
+
}
|
|
443
|
+
#pragma unroll
|
|
444
|
+
for (int i_VKQ_0 = 0; i_VKQ_0 < D/2; i_VKQ_0 += nthreads_V*V_rows_per_thread/2) {
|
|
445
|
+
const int i_VKQ = i_VKQ_0 + (nthreads_V == WARP_SIZE ? threadIdx.x : threadIdx.x % nthreads_V)*(V_rows_per_thread/2);
|
|
446
|
+
|
|
447
|
+
ggml_cuda_memcpy_1<V_rows_per_thread*sizeof(half)>(VKQ_tmp + i_VKQ, &VKQ[j_VKQ][i_VKQ_0/nthreads_V]);
|
|
448
|
+
}
|
|
449
|
+
#else
|
|
450
|
+
float2 * VKQ_tmp = (float2 *) KQ + threadIdx.y*(V_cols_per_iter*D/2)
|
|
451
|
+
+ (nthreads_V == WARP_SIZE ? 0 : threadIdx.x / nthreads_V)*(D/2);
|
|
452
|
+
|
|
453
|
+
#pragma unroll
|
|
454
|
+
for (int i_VKQ_0 = 0; i_VKQ_0 < D/2; i_VKQ_0 += nthreads_V) {
|
|
455
|
+
VKQ[j_VKQ][i_VKQ_0/nthreads_V].x *= kqmax_scale;
|
|
456
|
+
VKQ[j_VKQ][i_VKQ_0/nthreads_V].y *= kqmax_scale;
|
|
457
|
+
}
|
|
458
|
+
#pragma unroll
|
|
459
|
+
for (int i_VKQ_0 = 0; i_VKQ_0 < D/2; i_VKQ_0 += nthreads_V*V_rows_per_thread/2) {
|
|
460
|
+
const int i_VKQ = i_VKQ_0 + (nthreads_V == WARP_SIZE ? threadIdx.x : threadIdx.x % nthreads_V)*(V_rows_per_thread/2);
|
|
461
|
+
|
|
462
|
+
ggml_cuda_memcpy_1<V_rows_per_thread/2*sizeof(float)>(VKQ_tmp + i_VKQ, &VKQ[j_VKQ][i_VKQ_0/nthreads_V]);
|
|
463
|
+
ggml_cuda_memcpy_1<V_rows_per_thread/2*sizeof(float)>(VKQ_tmp + i_VKQ + V_rows_per_thread/4, &VKQ[j_VKQ][i_VKQ_0/nthreads_V + V_rows_per_thread/4]);
|
|
464
|
+
}
|
|
465
|
+
#endif // V_DOT2_F32_F16_AVAILABLE
|
|
466
|
+
|
|
467
|
+
KQ_sum[j_VKQ] *= kqmax_scale;
|
|
468
|
+
KQ_sum[j_VKQ] = warp_reduce_sum(KQ_sum[j_VKQ]);
|
|
469
|
+
if (threadIdx.x == 0) {
|
|
470
|
+
KQ_sum_shared[j_VKQ][threadIdx.y] = KQ_sum[j_VKQ];
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
__syncthreads();
|
|
474
|
+
|
|
475
|
+
if (nthreads <= D || tid < D) {
|
|
476
|
+
KQ_sum[j_VKQ] = KQ_sum_shared[j_VKQ][threadIdx.x];
|
|
477
|
+
KQ_sum[j_VKQ] = warp_reduce_sum(KQ_sum[j_VKQ]);
|
|
478
|
+
|
|
479
|
+
#pragma unroll
|
|
480
|
+
for (int i0 = 0; i0 < D; i0 += nthreads) {
|
|
481
|
+
float dst_val = 0;
|
|
482
|
+
#pragma unroll
|
|
483
|
+
for (int w = 0; w < nwarps; ++w) {
|
|
484
|
+
#pragma unroll
|
|
485
|
+
for (int v = 0; v < V_cols_per_iter; ++v) {
|
|
486
|
+
dst_val += float(KQ[w*V_cols_per_iter*D + v*D + i0 + tid]);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
if (gridDim.y == 1) {
|
|
490
|
+
dst_val /= KQ_sum[j_VKQ];
|
|
491
|
+
}
|
|
492
|
+
dst[(((sequence*int(ne01.z) + ic0 + j_VKQ)*ne02 + head)*gridDim.y + blockIdx.y)*D + i0 + tid] = dst_val;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
if (j_VKQ < ncols-1) {
|
|
497
|
+
__syncthreads();
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
if (gridDim.y != 1 && tid < ncols && (ncols == 1 || ic0 + tid < int(ne01.z))) {
|
|
503
|
+
dst_meta[((sequence*int(ne01.z) + ic0 + tid)*ne02 + head)*gridDim.y + blockIdx.y] = make_float2(KQ_max[tid], KQ_sum[tid]);
|
|
504
|
+
}
|
|
505
|
+
#else
|
|
506
|
+
GGML_UNUSED_VARS(Q, K, V, mask, sinks, KV_max, dst, dst_meta, scale,
|
|
507
|
+
max_bias, m0, m1, n_head_log2, logit_softcap,
|
|
508
|
+
ne00, ne01, ne02, ne03,
|
|
509
|
+
nb01, nb02, nb03,
|
|
510
|
+
ne10, ne11, ne12, ne13,
|
|
511
|
+
nb11, nb12, nb13,
|
|
512
|
+
nb21, nb22, nb23,
|
|
513
|
+
ne31, ne32, ne33,
|
|
514
|
+
nb31, nb32, nb33);
|
|
515
|
+
NO_DEVICE_CODE;
|
|
516
|
+
#endif // FLASH_ATTN_AVAILABLE
|
|
517
|
+
}
|
|
518
|
+
#ifdef __clang__
|
|
519
|
+
#pragma clang diagnostic pop
|
|
520
|
+
#endif // __clang__
|
|
521
|
+
|
|
522
|
+
template <int D, int cols_per_block, ggml_type type_K, ggml_type type_V, bool use_logit_softcap>
|
|
523
|
+
void ggml_cuda_flash_attn_ext_vec_case_impl(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
524
|
+
const int cc = ggml_cuda_info().devices[ggml_cuda_get_device()].cc;
|
|
525
|
+
|
|
526
|
+
const int nthreads = ggml_cuda_fattn_vec_get_nthreads_host(cc);
|
|
527
|
+
const int nwarps = nthreads / WARP_SIZE;
|
|
528
|
+
fattn_kernel_t fattn_kernel = flash_attn_ext_vec<D, cols_per_block, type_K, type_V, use_logit_softcap>;
|
|
529
|
+
const bool need_f16_K = type_K == GGML_TYPE_F16;
|
|
530
|
+
const bool need_f16_V = type_V == GGML_TYPE_F16;
|
|
531
|
+
constexpr size_t nbytes_shared = 0;
|
|
532
|
+
launch_fattn<D, cols_per_block, 1>(ctx, dst, fattn_kernel, nwarps, nbytes_shared, D, need_f16_K, need_f16_V, false);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
template <int D, ggml_type type_K, ggml_type type_V>
|
|
536
|
+
void ggml_cuda_flash_attn_ext_vec_case(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
537
|
+
const ggml_tensor * KQV = dst;
|
|
538
|
+
const ggml_tensor * Q = dst->src[0];
|
|
539
|
+
|
|
540
|
+
float logit_softcap;
|
|
541
|
+
memcpy(&logit_softcap, (const float *) KQV->op_params + 2, sizeof(float));
|
|
542
|
+
|
|
543
|
+
if (Q->ne[1] == 1) {
|
|
544
|
+
constexpr int cols_per_block = 1;
|
|
545
|
+
if (logit_softcap == 0.0f) {
|
|
546
|
+
constexpr bool use_logit_softcap = false;
|
|
547
|
+
ggml_cuda_flash_attn_ext_vec_case_impl<D, cols_per_block, type_K, type_V, use_logit_softcap>(ctx, dst);
|
|
548
|
+
} else {
|
|
549
|
+
constexpr bool use_logit_softcap = true;
|
|
550
|
+
ggml_cuda_flash_attn_ext_vec_case_impl<D, cols_per_block, type_K, type_V, use_logit_softcap>(ctx, dst);
|
|
551
|
+
}
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
constexpr int cols_per_block = 2;
|
|
556
|
+
if (logit_softcap == 0.0f) {
|
|
557
|
+
constexpr bool use_logit_softcap = false;
|
|
558
|
+
ggml_cuda_flash_attn_ext_vec_case_impl<D, cols_per_block, type_K, type_V, use_logit_softcap>(ctx, dst);
|
|
559
|
+
} else {
|
|
560
|
+
constexpr bool use_logit_softcap = true;
|
|
561
|
+
ggml_cuda_flash_attn_ext_vec_case_impl<D, cols_per_block, type_K, type_V, use_logit_softcap>(ctx, dst);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
#define DECL_FATTN_VEC_CASE(D, type_K, type_V) \
|
|
566
|
+
template void ggml_cuda_flash_attn_ext_vec_case \
|
|
567
|
+
<D, type_K, type_V>(ggml_backend_cuda_context & ctx, ggml_tensor * dst) \
|
|
568
|
+
|
|
569
|
+
#define EXTERN_DECL_FATTN_VEC_CASES(D, type_K) \
|
|
570
|
+
extern DECL_FATTN_VEC_CASE(D, type_K, GGML_TYPE_F16); \
|
|
571
|
+
extern DECL_FATTN_VEC_CASE(D, type_K, GGML_TYPE_Q4_0); \
|
|
572
|
+
extern DECL_FATTN_VEC_CASE(D, type_K, GGML_TYPE_Q4_1); \
|
|
573
|
+
extern DECL_FATTN_VEC_CASE(D, type_K, GGML_TYPE_Q5_0); \
|
|
574
|
+
extern DECL_FATTN_VEC_CASE(D, type_K, GGML_TYPE_Q5_1); \
|
|
575
|
+
extern DECL_FATTN_VEC_CASE(D, type_K, GGML_TYPE_Q8_0); \
|
|
576
|
+
extern DECL_FATTN_VEC_CASE(D, type_K, GGML_TYPE_BF16); \
|
|
577
|
+
|
|
578
|
+
EXTERN_DECL_FATTN_VEC_CASES( 64, GGML_TYPE_F16)
|
|
579
|
+
EXTERN_DECL_FATTN_VEC_CASES( 64, GGML_TYPE_Q4_0)
|
|
580
|
+
EXTERN_DECL_FATTN_VEC_CASES( 64, GGML_TYPE_Q4_1)
|
|
581
|
+
EXTERN_DECL_FATTN_VEC_CASES( 64, GGML_TYPE_Q5_0)
|
|
582
|
+
EXTERN_DECL_FATTN_VEC_CASES( 64, GGML_TYPE_Q5_1)
|
|
583
|
+
EXTERN_DECL_FATTN_VEC_CASES( 64, GGML_TYPE_Q8_0)
|
|
584
|
+
EXTERN_DECL_FATTN_VEC_CASES( 64, GGML_TYPE_BF16)
|
|
585
|
+
|
|
586
|
+
EXTERN_DECL_FATTN_VEC_CASES(128, GGML_TYPE_F16)
|
|
587
|
+
EXTERN_DECL_FATTN_VEC_CASES(128, GGML_TYPE_Q4_0)
|
|
588
|
+
EXTERN_DECL_FATTN_VEC_CASES(128, GGML_TYPE_Q4_1)
|
|
589
|
+
EXTERN_DECL_FATTN_VEC_CASES(128, GGML_TYPE_Q5_0)
|
|
590
|
+
EXTERN_DECL_FATTN_VEC_CASES(128, GGML_TYPE_Q5_1)
|
|
591
|
+
EXTERN_DECL_FATTN_VEC_CASES(128, GGML_TYPE_Q8_0)
|
|
592
|
+
EXTERN_DECL_FATTN_VEC_CASES(128, GGML_TYPE_BF16)
|
|
593
|
+
|
|
594
|
+
EXTERN_DECL_FATTN_VEC_CASES(256, GGML_TYPE_F16)
|
|
595
|
+
EXTERN_DECL_FATTN_VEC_CASES(256, GGML_TYPE_Q4_0)
|
|
596
|
+
EXTERN_DECL_FATTN_VEC_CASES(256, GGML_TYPE_Q4_1)
|
|
597
|
+
EXTERN_DECL_FATTN_VEC_CASES(256, GGML_TYPE_Q5_0)
|
|
598
|
+
EXTERN_DECL_FATTN_VEC_CASES(256, GGML_TYPE_Q5_1)
|
|
599
|
+
EXTERN_DECL_FATTN_VEC_CASES(256, GGML_TYPE_Q8_0)
|
|
600
|
+
EXTERN_DECL_FATTN_VEC_CASES(256, GGML_TYPE_BF16)
|