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,177 @@
|
|
|
1
|
+
#include "common.cuh"
|
|
2
|
+
#include "cross-entropy-loss.cuh"
|
|
3
|
+
#include "sum.cuh"
|
|
4
|
+
|
|
5
|
+
#include <cmath>
|
|
6
|
+
#include <cstdint>
|
|
7
|
+
|
|
8
|
+
template <bool use_shared>
|
|
9
|
+
static __global__ void cross_entropy_loss_f32(
|
|
10
|
+
const float * __restrict__ logits, const float * __restrict__ labels, float * __restrict__ dst, const int nclasses, const int k) {
|
|
11
|
+
extern __shared__ float tmp[];
|
|
12
|
+
|
|
13
|
+
logits += int64_t(blockIdx.x)*nclasses;
|
|
14
|
+
labels += int64_t(blockIdx.x)*nclasses;
|
|
15
|
+
|
|
16
|
+
// Find maximum for softmax:
|
|
17
|
+
float max_logit = -INFINITY;
|
|
18
|
+
for (int i = threadIdx.x; i < nclasses; i += WARP_SIZE) {
|
|
19
|
+
const float val = logits[i];
|
|
20
|
+
max_logit = fmaxf(max_logit, val);
|
|
21
|
+
|
|
22
|
+
if (use_shared) {
|
|
23
|
+
tmp[i] = val;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
max_logit = warp_reduce_max(max_logit);
|
|
27
|
+
|
|
28
|
+
// Calculate log(softmax(logits)) which is just logits - max:
|
|
29
|
+
float sum = 0.0f;
|
|
30
|
+
for (int i = threadIdx.x; i < nclasses; i += WARP_SIZE) {
|
|
31
|
+
const float logit_i = use_shared ? tmp[i] : logits[i];
|
|
32
|
+
sum += expf(logit_i - max_logit);
|
|
33
|
+
}
|
|
34
|
+
sum = warp_reduce_sum(sum);
|
|
35
|
+
sum = logf(sum);
|
|
36
|
+
|
|
37
|
+
// log(exp(logits - max) / sum) = (logits - max) - log(sum)
|
|
38
|
+
float loss = 0.0f;
|
|
39
|
+
for (int i = threadIdx.x; i < nclasses; i += WARP_SIZE) {
|
|
40
|
+
const float logit_i = use_shared ? tmp[i] : logits[i];
|
|
41
|
+
loss += (logit_i - max_logit - sum) * labels[i];
|
|
42
|
+
}
|
|
43
|
+
loss = -warp_reduce_sum(loss) / (float)k;
|
|
44
|
+
|
|
45
|
+
if (threadIdx.x != 0) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
dst[blockIdx.x] = loss;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
template <bool use_shared>
|
|
53
|
+
static __global__ void cross_entropy_loss_back_f32(
|
|
54
|
+
const float * __restrict__ grad, const float * __restrict__ logits, const float * __restrict__ labels,
|
|
55
|
+
float * __restrict__ dst, const int nclasses) {
|
|
56
|
+
extern __shared__ float tmp[];
|
|
57
|
+
|
|
58
|
+
logits += int64_t(blockIdx.x)*nclasses;
|
|
59
|
+
labels += int64_t(blockIdx.x)*nclasses;
|
|
60
|
+
dst += int64_t(blockIdx.x)*nclasses;
|
|
61
|
+
|
|
62
|
+
float maxval = -INFINITY;
|
|
63
|
+
for (int i = threadIdx.x; i < nclasses; i += WARP_SIZE) {
|
|
64
|
+
const float val = logits[i];
|
|
65
|
+
maxval = fmaxf(maxval, val);
|
|
66
|
+
|
|
67
|
+
if (use_shared) {
|
|
68
|
+
tmp[i] = val;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
maxval = warp_reduce_max(maxval);
|
|
72
|
+
|
|
73
|
+
float sum = 0.0f;
|
|
74
|
+
for (int i = threadIdx.x; i < nclasses; i += WARP_SIZE) {
|
|
75
|
+
const float val = expf((use_shared ? tmp[i] : logits[i]) - maxval);
|
|
76
|
+
sum += val;
|
|
77
|
+
|
|
78
|
+
if (use_shared) {
|
|
79
|
+
tmp[i] = val;
|
|
80
|
+
} else {
|
|
81
|
+
dst[i] = val;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
sum = warp_reduce_sum(sum);
|
|
85
|
+
const float sm_scale = 1.0f/sum;
|
|
86
|
+
|
|
87
|
+
const float d_by_nrows = *grad/gridDim.x;
|
|
88
|
+
for (int i = threadIdx.x; i < nclasses; i += WARP_SIZE) {
|
|
89
|
+
const float val = use_shared ? tmp[i] : dst[i];
|
|
90
|
+
dst[i] = (val*sm_scale - labels[i])*d_by_nrows;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
void ggml_cuda_cross_entropy_loss(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
95
|
+
const ggml_tensor * src0 = dst->src[0];
|
|
96
|
+
const ggml_tensor * src1 = dst->src[1];
|
|
97
|
+
|
|
98
|
+
GGML_ASSERT(src0->type == GGML_TYPE_F32);
|
|
99
|
+
GGML_ASSERT(src1->type == GGML_TYPE_F32);
|
|
100
|
+
GGML_ASSERT( dst->type == GGML_TYPE_F32);
|
|
101
|
+
|
|
102
|
+
GGML_ASSERT(ggml_is_contiguous(src0));
|
|
103
|
+
GGML_ASSERT(ggml_is_contiguous(src1));
|
|
104
|
+
GGML_ASSERT(ggml_is_contiguous(dst));
|
|
105
|
+
|
|
106
|
+
const int64_t ne00 = src0->ne[0];
|
|
107
|
+
const int64_t nrows = ggml_nrows(src0);
|
|
108
|
+
|
|
109
|
+
const float * src0_d = (const float *) src0->data;
|
|
110
|
+
const float * src1_d = (const float *) src1->data;
|
|
111
|
+
float * dst_d = (float *) dst->data;
|
|
112
|
+
|
|
113
|
+
ggml_cuda_pool & pool = ctx.pool();
|
|
114
|
+
cudaStream_t stream = ctx.stream();
|
|
115
|
+
|
|
116
|
+
const dim3 blocks_dim(WARP_SIZE, 1, 1);
|
|
117
|
+
const dim3 blocks_num(nrows, 1, 1);
|
|
118
|
+
const size_t nbytes_shared = ne00*sizeof(float);
|
|
119
|
+
|
|
120
|
+
const int id = ggml_cuda_get_device();
|
|
121
|
+
const size_t smpbo = ggml_cuda_info().devices[id].smpbo;
|
|
122
|
+
|
|
123
|
+
ggml_cuda_pool_alloc<float> dst_tmp(pool, blocks_num.x);
|
|
124
|
+
|
|
125
|
+
if (nbytes_shared <= smpbo) {
|
|
126
|
+
CUDA_SET_SHARED_MEMORY_LIMIT((cross_entropy_loss_f32<true>), smpbo);
|
|
127
|
+
cross_entropy_loss_f32<true><<<blocks_num, blocks_dim, nbytes_shared, stream>>>(src0_d, src1_d, dst_tmp.ptr, ne00, nrows);
|
|
128
|
+
} else {
|
|
129
|
+
cross_entropy_loss_f32<false><<<blocks_num, blocks_dim, 0, stream>>>(src0_d, src1_d, dst_tmp.ptr, ne00, nrows);
|
|
130
|
+
}
|
|
131
|
+
CUDA_CHECK(cudaGetLastError());
|
|
132
|
+
|
|
133
|
+
// Combine results from individual blocks:
|
|
134
|
+
sum_f32_cuda(pool, dst_tmp.ptr, dst_d, blocks_num.x, stream);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
void ggml_cuda_cross_entropy_loss_back(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
138
|
+
const ggml_tensor * grad = dst->src[0];
|
|
139
|
+
const ggml_tensor * src0f = dst->src[1];
|
|
140
|
+
const ggml_tensor * src1f = dst->src[2];
|
|
141
|
+
|
|
142
|
+
GGML_ASSERT(src0f->type == GGML_TYPE_F32);
|
|
143
|
+
GGML_ASSERT(src1f->type == GGML_TYPE_F32);
|
|
144
|
+
GGML_ASSERT( grad->type == GGML_TYPE_F32);
|
|
145
|
+
GGML_ASSERT( dst->type == GGML_TYPE_F32);
|
|
146
|
+
|
|
147
|
+
GGML_ASSERT(ggml_is_scalar(grad));
|
|
148
|
+
GGML_ASSERT(ggml_is_contiguous(src0f));
|
|
149
|
+
GGML_ASSERT(ggml_is_contiguous(src1f));
|
|
150
|
+
GGML_ASSERT(ggml_is_contiguous(dst));
|
|
151
|
+
GGML_ASSERT(ggml_are_same_shape(src0f, src1f));
|
|
152
|
+
GGML_ASSERT(ggml_are_same_shape(src0f, dst));
|
|
153
|
+
|
|
154
|
+
const int64_t ne00 = src0f->ne[0];
|
|
155
|
+
const int64_t nrows = ggml_nrows(src0f);
|
|
156
|
+
|
|
157
|
+
const float * grad_d = (const float *) grad->data;
|
|
158
|
+
const float * src0f_d = (const float *) src0f->data;
|
|
159
|
+
const float * src1f_d = (const float *) src1f->data;
|
|
160
|
+
float * dst_d = (float *) dst->data;
|
|
161
|
+
|
|
162
|
+
cudaStream_t stream = ctx.stream();
|
|
163
|
+
|
|
164
|
+
const dim3 blocks_dim(WARP_SIZE, 1, 1);
|
|
165
|
+
const dim3 blocks_num(nrows, 1, 1);
|
|
166
|
+
const size_t nbytes_shared = ne00*sizeof(float);
|
|
167
|
+
|
|
168
|
+
const int id = ggml_cuda_get_device();
|
|
169
|
+
const size_t smpbo = ggml_cuda_info().devices[id].smpbo;
|
|
170
|
+
|
|
171
|
+
if (nbytes_shared <= smpbo) {
|
|
172
|
+
CUDA_SET_SHARED_MEMORY_LIMIT((cross_entropy_loss_back_f32<true>), smpbo);
|
|
173
|
+
cross_entropy_loss_back_f32<true><<<blocks_num, blocks_dim, nbytes_shared, stream>>>(grad_d, src0f_d, src1f_d, dst_d, ne00);
|
|
174
|
+
} else {
|
|
175
|
+
cross_entropy_loss_back_f32<false><<<blocks_num, blocks_dim, 0, stream>>>(grad_d, src0f_d, src1f_d, dst_d, ne00);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
#include <algorithm>
|
|
2
|
+
#include "cumsum.cuh"
|
|
3
|
+
#include "convert.cuh"
|
|
4
|
+
#include "ggml-cuda/common.cuh"
|
|
5
|
+
#include "ggml.h"
|
|
6
|
+
|
|
7
|
+
#ifdef GGML_CUDA_USE_CUB
|
|
8
|
+
# include <cub/cub.cuh>
|
|
9
|
+
#endif // GGML_CUDA_USE_CUB
|
|
10
|
+
|
|
11
|
+
template<typename T, int BLOCK_SIZE>
|
|
12
|
+
static __global__ void cumsum_cub_kernel(
|
|
13
|
+
const T * __restrict__ src,
|
|
14
|
+
T * __restrict__ dst,
|
|
15
|
+
const int64_t ne00, const int64_t ne01, const int64_t ne02, const int64_t ne03,
|
|
16
|
+
const int64_t s01, const int64_t s02, const int64_t s03,
|
|
17
|
+
const int64_t s1, const int64_t s2, const int64_t s3) {
|
|
18
|
+
#ifdef GGML_CUDA_USE_CUB
|
|
19
|
+
using BlockScanT = cub::BlockScan<T, BLOCK_SIZE>;
|
|
20
|
+
|
|
21
|
+
__shared__ typename BlockScanT::TempStorage temp_storage;
|
|
22
|
+
__shared__ T block_carry;
|
|
23
|
+
|
|
24
|
+
const int tid = threadIdx.x;
|
|
25
|
+
constexpr int UNROLL_FACTOR = 4;
|
|
26
|
+
constexpr int TILE_SIZE = BLOCK_SIZE * UNROLL_FACTOR;
|
|
27
|
+
|
|
28
|
+
const int64_t i1 = blockIdx.x;
|
|
29
|
+
const int64_t i2 = blockIdx.y;
|
|
30
|
+
const int64_t i3 = blockIdx.z;
|
|
31
|
+
|
|
32
|
+
if (i1 >= ne01 || i2 >= ne02 || i3 >= ne03) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const T * src_row = src + i1 * s01 + i2 * s02 + i3 * s03;
|
|
37
|
+
T * dst_row = dst + i1 * s1 + i2 * s2 + i3 * s3;
|
|
38
|
+
|
|
39
|
+
if (tid == 0) {
|
|
40
|
+
block_carry = 0;
|
|
41
|
+
}
|
|
42
|
+
__syncthreads();
|
|
43
|
+
|
|
44
|
+
for (int64_t start = 0; start < ne00; start += TILE_SIZE) {
|
|
45
|
+
T items[UNROLL_FACTOR];
|
|
46
|
+
T thread_sum = T(0);
|
|
47
|
+
|
|
48
|
+
#pragma unroll
|
|
49
|
+
for (int i = 0; i < UNROLL_FACTOR; i++) {
|
|
50
|
+
int64_t idx = start + tid * UNROLL_FACTOR + i;
|
|
51
|
+
T val = (idx < ne00) ? src_row[idx] : T(0);
|
|
52
|
+
thread_sum += val;
|
|
53
|
+
items[i] = thread_sum;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Block-wide scan on thread sums
|
|
57
|
+
T thread_prefix;
|
|
58
|
+
T block_total;
|
|
59
|
+
BlockScanT(temp_storage).InclusiveSum(thread_sum, thread_prefix, block_total);
|
|
60
|
+
__syncthreads();
|
|
61
|
+
|
|
62
|
+
// Add offset to each item and store
|
|
63
|
+
T thread_offset = thread_prefix - thread_sum + block_carry;
|
|
64
|
+
#pragma unroll
|
|
65
|
+
for (int i = 0; i < UNROLL_FACTOR; i++) {
|
|
66
|
+
int64_t idx = start + tid * UNROLL_FACTOR + i;
|
|
67
|
+
if (idx < ne00) {
|
|
68
|
+
dst_row[idx] = items[i] + thread_offset;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
__syncthreads();
|
|
73
|
+
|
|
74
|
+
// Update carry for next tile
|
|
75
|
+
if (tid == 0) {
|
|
76
|
+
block_carry += block_total;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
#else
|
|
80
|
+
NO_DEVICE_CODE;
|
|
81
|
+
#endif // GGML_CUDA_USE_CUB
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Fallback kernel implementation
|
|
85
|
+
template<typename T>
|
|
86
|
+
static __global__ void cumsum_kernel(
|
|
87
|
+
const T * src, T * dst,
|
|
88
|
+
const int64_t ne00, const int64_t ne01, const int64_t ne02, const int64_t ne03,
|
|
89
|
+
const int64_t s00, const int64_t s01, const int64_t s02, const int64_t s03,
|
|
90
|
+
const int64_t s0, const int64_t s1, const int64_t s2, const int64_t s3) {
|
|
91
|
+
|
|
92
|
+
GGML_UNUSED_VARS(s00, s0);
|
|
93
|
+
|
|
94
|
+
const int tid = threadIdx.x;
|
|
95
|
+
constexpr int warp_size = ggml_cuda_get_physical_warp_size();
|
|
96
|
+
const int lane = tid % warp_size;
|
|
97
|
+
const int warp = tid / warp_size;
|
|
98
|
+
const int warps_per_block = blockDim.x / warp_size;
|
|
99
|
+
|
|
100
|
+
extern __shared__ float smem[];
|
|
101
|
+
float * s_vals = smem;
|
|
102
|
+
float * s_warp_sums = smem + blockDim.x;
|
|
103
|
+
float * s_carry = smem + blockDim.x + warps_per_block;
|
|
104
|
+
float * s_chunk_total = s_carry + 1;
|
|
105
|
+
|
|
106
|
+
// Initialize carry
|
|
107
|
+
if (tid == 0) {
|
|
108
|
+
*s_carry = 0.0f;
|
|
109
|
+
}
|
|
110
|
+
__syncthreads();
|
|
111
|
+
|
|
112
|
+
const int64_t i3 = blockIdx.z;
|
|
113
|
+
const int64_t i2 = blockIdx.y;
|
|
114
|
+
const int64_t i1 = blockIdx.x;
|
|
115
|
+
if (i3 >= ne03 || i2 >= ne02 || i1 >= ne01) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const T * src_row = src + i1 * s01 + i2 * s02 + i3 * s03;
|
|
120
|
+
T * dst_row = dst + i1 * s1 + i2 * s2 + i3 * s3;
|
|
121
|
+
|
|
122
|
+
// register blocking: process 4 elements per thread to hide latency
|
|
123
|
+
// and reduce synchronization overhead
|
|
124
|
+
constexpr int num_unroll = 4;
|
|
125
|
+
T temp[num_unroll];
|
|
126
|
+
|
|
127
|
+
for (int64_t i = 0; i < ne00; i += num_unroll * blockDim.x) {
|
|
128
|
+
int64_t idx = i + tid * num_unroll;
|
|
129
|
+
|
|
130
|
+
// thread local sequential scan
|
|
131
|
+
temp[0] = (idx < ne00 ? src_row[idx] : T(0));
|
|
132
|
+
#pragma unroll
|
|
133
|
+
for (int64_t j = 1; j < num_unroll; j++) {
|
|
134
|
+
temp[j] = temp[j - 1];
|
|
135
|
+
if (idx + j < ne00) {
|
|
136
|
+
temp[j] += src_row[idx + j];
|
|
137
|
+
} else {
|
|
138
|
+
temp[j] += 0;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// last emenent is sum of all values assigned to thread
|
|
143
|
+
float val = (idx < ne00) ? ggml_cuda_cast<float, T>(temp[num_unroll - 1]) : 0.0f;
|
|
144
|
+
|
|
145
|
+
// Warp inclusive scan
|
|
146
|
+
val = warp_prefix_inclusive_sum<T, warp_size>(val);
|
|
147
|
+
s_vals[tid] = val;
|
|
148
|
+
|
|
149
|
+
if (lane == warp_size - 1) {
|
|
150
|
+
s_warp_sums[warp] = val;
|
|
151
|
+
}
|
|
152
|
+
__syncthreads();
|
|
153
|
+
|
|
154
|
+
// Exclusive scan of warp sums (warp 0 only)
|
|
155
|
+
if (warp == 0) {
|
|
156
|
+
float w = (tid < warps_per_block) ? s_warp_sums[tid] : 0.0f;
|
|
157
|
+
float inc = warp_prefix_inclusive_sum<T, warp_size>(w);
|
|
158
|
+
if (tid < warps_per_block) {
|
|
159
|
+
s_warp_sums[tid] = inc - w; // exclusive sum
|
|
160
|
+
}
|
|
161
|
+
if (tid == warps_per_block - 1) {
|
|
162
|
+
*s_chunk_total = inc; // total sum of this chunk
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
__syncthreads();
|
|
166
|
+
|
|
167
|
+
// write back results
|
|
168
|
+
float carry = *s_carry;
|
|
169
|
+
// calculate sum offset for this thread
|
|
170
|
+
float final_val_offset = s_vals[tid] + s_warp_sums[warp] + carry - temp[num_unroll - 1];
|
|
171
|
+
|
|
172
|
+
#pragma unroll
|
|
173
|
+
for (int32_t j = 0; j < num_unroll; j++) {
|
|
174
|
+
if (idx + j < ne00) {
|
|
175
|
+
dst_row[idx + j] = temp[j] + ggml_cuda_cast<T, float>(final_val_offset);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
__syncthreads();
|
|
180
|
+
|
|
181
|
+
// Update carry for next chunk
|
|
182
|
+
if (tid == 0) {
|
|
183
|
+
*s_carry += *s_chunk_total;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
#ifdef GGML_CUDA_USE_CUB
|
|
189
|
+
template <typename T>
|
|
190
|
+
static void cumsum_cub(ggml_cuda_pool & pool,
|
|
191
|
+
const T * src,
|
|
192
|
+
T * dst,
|
|
193
|
+
int64_t ne,
|
|
194
|
+
cudaStream_t stream) {
|
|
195
|
+
size_t tmp_size = 0;
|
|
196
|
+
|
|
197
|
+
// Query how much temp storage CUDA UnBound (CUB) needs
|
|
198
|
+
cub::DeviceScan::InclusiveSum(nullptr, // d_temp_storage (null = just query size)
|
|
199
|
+
tmp_size, // reference to size (will be set by CUB)
|
|
200
|
+
src, // input pointer
|
|
201
|
+
dst, // output pointer
|
|
202
|
+
ne, // number of elements
|
|
203
|
+
stream // CUDA stream to use
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
ggml_cuda_pool_alloc<uint8_t> tmp_alloc(pool, tmp_size);
|
|
207
|
+
|
|
208
|
+
// Perform the inclusive scan
|
|
209
|
+
cub::DeviceScan::InclusiveSum((void *) tmp_alloc.get(), tmp_size, src, dst, ne, stream);
|
|
210
|
+
}
|
|
211
|
+
#endif // GGML_CUDA_USE_CUB
|
|
212
|
+
|
|
213
|
+
template<typename T>
|
|
214
|
+
static void cumsum_cuda(
|
|
215
|
+
[[maybe_unused]] ggml_backend_cuda_context & ctx, const T * src, T * dst,
|
|
216
|
+
const int64_t ne00, const int64_t ne01, const int64_t ne02, const int64_t ne03,
|
|
217
|
+
const int64_t nb00, const int64_t nb01, const int64_t nb02, const int64_t nb03,
|
|
218
|
+
const int64_t nb0, const int64_t nb1, const int64_t nb2, const int64_t nb3,
|
|
219
|
+
cudaStream_t stream) {
|
|
220
|
+
|
|
221
|
+
const size_t type_size = sizeof(T);
|
|
222
|
+
bool use_cub = false;
|
|
223
|
+
#ifdef GGML_CUDA_USE_CUB
|
|
224
|
+
// Check if we can use CUB (data must be contiguous along innermost dimension)
|
|
225
|
+
const bool is_contiguous = (nb00 == type_size) && (nb0 == type_size);
|
|
226
|
+
|
|
227
|
+
if (is_contiguous) {
|
|
228
|
+
use_cub = true;
|
|
229
|
+
const int64_t nrows = ne01 * ne02 * ne03;
|
|
230
|
+
// TODO: Compare with DeviceSegmentedScan::InclusiveSegmentedSum for nrows > 1 once InclusiveSegmentedSum is released
|
|
231
|
+
// Heuristics were determined as part of https://github.com/ggml-org/llama.cpp/pull/17004
|
|
232
|
+
if (((nrows == 1) && (ne00 > 1024)) || (ne00 / nrows > 4096)) {
|
|
233
|
+
for (int i=0; i<nrows; i++) {
|
|
234
|
+
cumsum_cub(ctx.pool(), src + i * ne00, dst + i * ne00, ne00, stream);
|
|
235
|
+
}
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
#endif // GGML_CUDA_USE_CUB
|
|
240
|
+
dim3 grid_dims(ne01, ne02, ne03);
|
|
241
|
+
const auto &info = ggml_cuda_info().devices[ggml_cuda_get_device()];
|
|
242
|
+
const int warp_size = info.warp_size;
|
|
243
|
+
const int num_warps = (ne00 + warp_size - 1) / warp_size;
|
|
244
|
+
int block_size = num_warps * warp_size;
|
|
245
|
+
block_size = std::min(block_size, CUDA_CUMSUM_BLOCK_SIZE);
|
|
246
|
+
dim3 block_dims(block_size, 1, 1);
|
|
247
|
+
const int warps_per_block = block_size / warp_size;
|
|
248
|
+
const size_t shmem_size = (block_size + warps_per_block + 2) * sizeof(float);
|
|
249
|
+
|
|
250
|
+
if (use_cub && ne00 >= 1024) {
|
|
251
|
+
cumsum_cub_kernel<T, CUDA_CUMSUM_BLOCK_SIZE><<<grid_dims, CUDA_CUMSUM_BLOCK_SIZE, 0, stream>>>(
|
|
252
|
+
src, dst,
|
|
253
|
+
ne00, ne01, ne02, ne03,
|
|
254
|
+
nb01 / type_size, nb02 / type_size, nb03 / type_size,
|
|
255
|
+
nb1 / type_size, nb2 / type_size, nb3 / type_size
|
|
256
|
+
);
|
|
257
|
+
} else {
|
|
258
|
+
cumsum_kernel<<<grid_dims, block_dims, shmem_size, stream>>>(
|
|
259
|
+
src, dst,
|
|
260
|
+
ne00, ne01, ne02, ne03,
|
|
261
|
+
nb00 / type_size, nb01 / type_size, nb02 / type_size, nb03 / type_size,
|
|
262
|
+
nb0 / type_size, nb1 / type_size, nb2 / type_size, nb3 / type_size
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
void ggml_cuda_op_cumsum(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
268
|
+
const ggml_tensor * src0 = dst->src[0];
|
|
269
|
+
cudaStream_t stream = ctx.stream();
|
|
270
|
+
|
|
271
|
+
GGML_ASSERT(src0->type == dst->type);
|
|
272
|
+
switch(src0->type) {
|
|
273
|
+
case GGML_TYPE_F32:
|
|
274
|
+
{
|
|
275
|
+
cumsum_cuda(
|
|
276
|
+
ctx, (const float *)src0->data, (float *)dst->data,
|
|
277
|
+
src0->ne[0], src0->ne[1], src0->ne[2], src0->ne[3],
|
|
278
|
+
src0->nb[0], src0->nb[1], src0->nb[2], src0->nb[3],
|
|
279
|
+
dst->nb[0], dst->nb[1], dst->nb[2], dst->nb[3],
|
|
280
|
+
stream
|
|
281
|
+
);
|
|
282
|
+
} break;
|
|
283
|
+
// We do not support those on CPU for now anyway, so comment them out because they cause errors on some CI platforms
|
|
284
|
+
/*case GGML_TYPE_F16:
|
|
285
|
+
{
|
|
286
|
+
cumsum_cuda(
|
|
287
|
+
(const half *)src0->data, (half *)dst->data,
|
|
288
|
+
src0->ne[0], src0->ne[1], src0->ne[2], src0->ne[3],
|
|
289
|
+
src0->nb[0], src0->nb[1], src0->nb[2], src0->nb[3],
|
|
290
|
+
dst->nb[0], dst->nb[1], dst->nb[2], dst->nb[3],
|
|
291
|
+
stream
|
|
292
|
+
);
|
|
293
|
+
} break;
|
|
294
|
+
case GGML_TYPE_BF16:
|
|
295
|
+
{
|
|
296
|
+
cumsum_cuda(
|
|
297
|
+
(const nv_bfloat16 *)src0->data, (nv_bfloat16 *)dst->data,
|
|
298
|
+
src0->ne[0], src0->ne[1], src0->ne[2], src0->ne[3],
|
|
299
|
+
src0->nb[0], src0->nb[1], src0->nb[2], src0->nb[3],
|
|
300
|
+
dst->nb[0], dst->nb[1], dst->nb[2], dst->nb[3],
|
|
301
|
+
stream
|
|
302
|
+
);
|
|
303
|
+
} break;*/
|
|
304
|
+
default:
|
|
305
|
+
GGML_ABORT("fatal error");
|
|
306
|
+
}
|
|
307
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#include "common.cuh"
|
|
2
|
+
|
|
3
|
+
static __device__ __forceinline__ void dequantize_q1_0(const void * vx, const int64_t ib, const int iqs, float2 & v){
|
|
4
|
+
const block_q1_0 * x = (const block_q1_0 *) vx;
|
|
5
|
+
|
|
6
|
+
const float d = x[ib].d;
|
|
7
|
+
|
|
8
|
+
const int bit_index_0 = iqs;
|
|
9
|
+
const int bit_index_1 = iqs + 1;
|
|
10
|
+
|
|
11
|
+
const int byte_index_0 = bit_index_0 / 8;
|
|
12
|
+
const int bit_offset_0 = bit_index_0 % 8;
|
|
13
|
+
|
|
14
|
+
const int byte_index_1 = bit_index_1 / 8;
|
|
15
|
+
const int bit_offset_1 = bit_index_1 % 8;
|
|
16
|
+
|
|
17
|
+
// Extract bits: 1 = +d, 0 = -d (branchless)
|
|
18
|
+
const int bit_0 = (x[ib].qs[byte_index_0] >> bit_offset_0) & 1;
|
|
19
|
+
const int bit_1 = (x[ib].qs[byte_index_1] >> bit_offset_1) & 1;
|
|
20
|
+
|
|
21
|
+
v.x = (2*bit_0 - 1) * d;
|
|
22
|
+
v.y = (2*bit_1 - 1) * d;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static __device__ __forceinline__ void dequantize_q4_0(const void * vx, const int64_t ib, const int iqs, float2 & v){
|
|
26
|
+
const block_q4_0 * x = (const block_q4_0 *) vx;
|
|
27
|
+
|
|
28
|
+
const float d = x[ib].d;
|
|
29
|
+
|
|
30
|
+
const int vui = x[ib].qs[iqs];
|
|
31
|
+
|
|
32
|
+
v.x = vui & 0xF;
|
|
33
|
+
v.y = vui >> 4;
|
|
34
|
+
|
|
35
|
+
v.x = (v.x - 8.0f) * d;
|
|
36
|
+
v.y = (v.y - 8.0f) * d;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static __device__ __forceinline__ void dequantize_q4_1(const void * vx, const int64_t ib, const int iqs, float2 & v){
|
|
40
|
+
const block_q4_1 * x = (const block_q4_1 *) vx;
|
|
41
|
+
|
|
42
|
+
const float2 dm = __half22float2(x[ib].dm);
|
|
43
|
+
|
|
44
|
+
const int vui = x[ib].qs[iqs];
|
|
45
|
+
|
|
46
|
+
v.x = vui & 0xF;
|
|
47
|
+
v.y = vui >> 4;
|
|
48
|
+
|
|
49
|
+
v.x = (v.x * dm.x) + dm.y;
|
|
50
|
+
v.y = (v.y * dm.x) + dm.y;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static __device__ __forceinline__ void dequantize_q5_0(const void * vx, const int64_t ib, const int iqs, float2 & v){
|
|
54
|
+
const block_q5_0 * x = (const block_q5_0 *) vx;
|
|
55
|
+
|
|
56
|
+
const float d = x[ib].d;
|
|
57
|
+
|
|
58
|
+
uint32_t qh;
|
|
59
|
+
memcpy(&qh, x[ib].qh, sizeof(qh));
|
|
60
|
+
|
|
61
|
+
const int xh_0 = ((qh >> (iqs + 0)) << 4) & 0x10;
|
|
62
|
+
const int xh_1 = ((qh >> (iqs + 12)) ) & 0x10;
|
|
63
|
+
|
|
64
|
+
v.x = ((x[ib].qs[iqs] & 0xf) | xh_0);
|
|
65
|
+
v.y = ((x[ib].qs[iqs] >> 4) | xh_1);
|
|
66
|
+
|
|
67
|
+
v.x = (v.x - 16.0f) * d;
|
|
68
|
+
v.y = (v.y - 16.0f) * d;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static __device__ __forceinline__ void dequantize_q5_1(const void * vx, const int64_t ib, const int iqs, float2 & v){
|
|
72
|
+
const block_q5_1 * x = (const block_q5_1 *) vx;
|
|
73
|
+
|
|
74
|
+
const float2 dm = __half22float2(x[ib].dm);
|
|
75
|
+
|
|
76
|
+
uint32_t qh;
|
|
77
|
+
memcpy(&qh, x[ib].qh, sizeof(qh));
|
|
78
|
+
|
|
79
|
+
const int xh_0 = ((qh >> (iqs + 0)) << 4) & 0x10;
|
|
80
|
+
const int xh_1 = ((qh >> (iqs + 12)) ) & 0x10;
|
|
81
|
+
|
|
82
|
+
v.x = ((x[ib].qs[iqs] & 0xf) | xh_0);
|
|
83
|
+
v.y = ((x[ib].qs[iqs] >> 4) | xh_1);
|
|
84
|
+
|
|
85
|
+
v.x = (v.x * dm.x) + dm.y;
|
|
86
|
+
v.y = (v.y * dm.x) + dm.y;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static __device__ __forceinline__ void dequantize_q8_0(const void * vx, const int64_t ib, const int iqs, float2 & v){
|
|
90
|
+
const block_q8_0 * x = (const block_q8_0 *) vx;
|
|
91
|
+
|
|
92
|
+
const float d = x[ib].d;
|
|
93
|
+
|
|
94
|
+
v.x = x[ib].qs[iqs + 0];
|
|
95
|
+
v.y = x[ib].qs[iqs + 1];
|
|
96
|
+
|
|
97
|
+
v.x *= d;
|
|
98
|
+
v.y *= d;
|
|
99
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#include "convert.cuh"
|
|
2
|
+
#include "diag.cuh"
|
|
3
|
+
#include "ggml.h"
|
|
4
|
+
|
|
5
|
+
template <typename T>
|
|
6
|
+
static __global__ void diag_kernel(T * __restrict__ dst,
|
|
7
|
+
const T * __restrict__ src,
|
|
8
|
+
const int64_t ne0,
|
|
9
|
+
const int64_t ne1,
|
|
10
|
+
const int64_t ne2,
|
|
11
|
+
const int64_t ne3,
|
|
12
|
+
const int64_t total_elements) {
|
|
13
|
+
const int64_t global_idx = blockIdx.x * blockDim.x + threadIdx.x;
|
|
14
|
+
|
|
15
|
+
if (global_idx >= total_elements) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const int64_t i0 = global_idx % ne0;
|
|
20
|
+
const int64_t i1 = (global_idx / ne0) % ne1;
|
|
21
|
+
const int64_t i2 = (global_idx / (ne0 * ne1)) % ne2;
|
|
22
|
+
const int64_t i3 = global_idx / (ne0 * ne1 * ne2);
|
|
23
|
+
|
|
24
|
+
const int64_t dst_idx = ((i3 * ne2 + i2) * ne1 + i1) * ne0 + i0;
|
|
25
|
+
|
|
26
|
+
if (i0 == i1) {
|
|
27
|
+
const int64_t batch_idx = i3 * ne2 + i2;
|
|
28
|
+
const int64_t src_idx = batch_idx * ne0 + i0;
|
|
29
|
+
dst[dst_idx] = src[src_idx];
|
|
30
|
+
} else {
|
|
31
|
+
dst[dst_idx] = ggml_cuda_cast<T>(0);
|
|
32
|
+
}
|
|
33
|
+
GGML_UNUSED_VARS(ne3);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
void ggml_cuda_op_diag(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
37
|
+
const ggml_tensor * src0 = dst->src[0];
|
|
38
|
+
|
|
39
|
+
void * dst_d = dst->data;
|
|
40
|
+
const void * src0_d = src0->data;
|
|
41
|
+
|
|
42
|
+
cudaStream_t stream = ctx.stream();
|
|
43
|
+
|
|
44
|
+
GGML_ASSERT(ggml_is_contiguous(dst));
|
|
45
|
+
GGML_ASSERT(ggml_is_contiguous(src0));
|
|
46
|
+
|
|
47
|
+
const int64_t ne00 = src0->ne[0];
|
|
48
|
+
const int64_t ne01 = src0->ne[1];
|
|
49
|
+
const int64_t ne02 = src0->ne[2];
|
|
50
|
+
const int64_t ne03 = src0->ne[3];
|
|
51
|
+
|
|
52
|
+
const int64_t ne0 = dst->ne[0];
|
|
53
|
+
const int64_t ne1 = dst->ne[1];
|
|
54
|
+
const int64_t ne2 = dst->ne[2];
|
|
55
|
+
const int64_t ne3 = dst->ne[3];
|
|
56
|
+
|
|
57
|
+
GGML_ASSERT(ne00 == ne0);
|
|
58
|
+
GGML_ASSERT(ne01 == 1);
|
|
59
|
+
GGML_ASSERT(ne02 == ne2);
|
|
60
|
+
GGML_ASSERT(ne03 == ne3);
|
|
61
|
+
|
|
62
|
+
const int64_t n_elems = ggml_nelements(dst);
|
|
63
|
+
const int64_t num_blocks = (n_elems + CUDA_DIAG_BLOCK_SIZE - 1) / CUDA_DIAG_BLOCK_SIZE;
|
|
64
|
+
|
|
65
|
+
switch (dst->type) {
|
|
66
|
+
case GGML_TYPE_F32:
|
|
67
|
+
diag_kernel<<<num_blocks, CUDA_DIAG_BLOCK_SIZE, 0, stream>>>((float *) dst_d, (const float *) src0_d, ne0,
|
|
68
|
+
ne1, ne2, ne3, n_elems);
|
|
69
|
+
break;
|
|
70
|
+
case GGML_TYPE_F16:
|
|
71
|
+
diag_kernel<<<num_blocks, CUDA_DIAG_BLOCK_SIZE, 0, stream>>>((half *) dst_d, (const half *) src0_d, ne0,
|
|
72
|
+
ne1, ne2, ne3, n_elems);
|
|
73
|
+
break;
|
|
74
|
+
default:
|
|
75
|
+
GGML_ABORT("unsupported type");
|
|
76
|
+
}
|
|
77
|
+
}
|