whispercpp 1.3.7 → 1.3.8
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 +4 -4
- data/README.md +5 -4
- data/ext/options.rb +1 -1
- data/ext/ruby_whisper.c +0 -1
- data/ext/ruby_whisper.h +7 -1
- data/ext/ruby_whisper_context.c +50 -1
- data/ext/ruby_whisper_log_settable.h +1 -2
- data/ext/ruby_whisper_params.c +9 -8
- data/ext/ruby_whisper_transcribe.cpp +0 -19
- data/ext/ruby_whisper_vad_context.c +30 -10
- data/ext/ruby_whisper_vad_context_detect.cpp +8 -9
- data/ext/ruby_whisper_vad_params.c +4 -4
- data/ext/ruby_whisper_vad_segment.c +2 -2
- data/ext/sources/CMakeLists.txt +2 -1
- data/ext/sources/cmake/parakeet.pc.in +2 -2
- data/ext/sources/cmake/whisper.pc.in +2 -2
- data/ext/sources/examples/cli/cli.cpp +9 -1
- data/ext/sources/examples/common-ggml.cpp +2 -0
- data/ext/sources/examples/vad-speech-segments/speech.cpp +3 -2
- data/ext/sources/ggml/CMakeLists.txt +3 -4
- data/ext/sources/ggml/include/ggml-cuda.h +0 -3
- data/ext/sources/ggml/include/ggml-sycl.h +8 -0
- data/ext/sources/ggml/include/ggml.h +3 -1
- data/ext/sources/ggml/src/CMakeLists.txt +8 -1
- data/ext/sources/ggml/src/ggml-backend-meta.cpp +7 -4
- data/ext/sources/ggml/src/ggml-common.h +13 -2
- data/ext/sources/ggml/src/ggml-cpu/CMakeLists.txt +1 -1
- data/ext/sources/ggml/src/ggml-cpu/amx/mmq.cpp +5 -6
- data/ext/sources/ggml/src/ggml-cpu/arch/arm/quants.c +78 -4
- data/ext/sources/ggml/src/ggml-cpu/arch/x86/quants.c +142 -4
- data/ext/sources/ggml/src/ggml-cpu/arch-fallback.h +7 -2
- data/ext/sources/ggml/src/ggml-cpu/ggml-cpu.c +14 -0
- data/ext/sources/ggml/src/ggml-cpu/llamafile/sgemm.cpp +26 -19
- data/ext/sources/ggml/src/ggml-cpu/ops.cpp +129 -46
- data/ext/sources/ggml/src/ggml-cpu/quants.c +51 -0
- data/ext/sources/ggml/src/ggml-cpu/quants.h +3 -0
- data/ext/sources/ggml/src/ggml-cpu/simd-gemm.h +1 -1
- data/ext/sources/ggml/src/ggml-cpu/simd-mappings.h +11 -0
- data/ext/sources/ggml/src/ggml-cpu/vec.cpp +2 -2
- data/ext/sources/ggml/src/ggml-cuda/binbcast.cu +90 -46
- data/ext/sources/ggml/src/ggml-cuda/col2im-1d.cu +81 -0
- data/ext/sources/ggml/src/ggml-cuda/col2im-1d.cuh +3 -0
- data/ext/sources/ggml/src/ggml-cuda/common.cuh +4 -0
- data/ext/sources/ggml/src/ggml-cuda/concat.cu +33 -21
- data/ext/sources/ggml/src/ggml-cuda/conv-transpose-1d.cu +14 -12
- data/ext/sources/ggml/src/ggml-cuda/convert.cu +86 -34
- data/ext/sources/ggml/src/ggml-cuda/cpy.cu +80 -29
- data/ext/sources/ggml/src/ggml-cuda/fattn-common.cuh +9 -5
- data/ext/sources/ggml/src/ggml-cuda/fattn-mma-f16.cuh +4 -0
- data/ext/sources/ggml/src/ggml-cuda/fattn-tile.cuh +9 -5
- data/ext/sources/ggml/src/ggml-cuda/fattn.cu +27 -21
- data/ext/sources/ggml/src/ggml-cuda/gated_delta_net.cu +40 -25
- data/ext/sources/ggml/src/ggml-cuda/gated_delta_net.cuh +10 -0
- data/ext/sources/ggml/src/ggml-cuda/getrows.cu +15 -12
- data/ext/sources/ggml/src/ggml-cuda/ggml-cuda.cu +718 -1248
- data/ext/sources/ggml/src/ggml-cuda/mmq.cu +7 -0
- data/ext/sources/ggml/src/ggml-cuda/mmvq.cu +77 -40
- data/ext/sources/ggml/src/ggml-cuda/out-prod.cu +55 -12
- data/ext/sources/ggml/src/ggml-cuda/set-rows.cu +64 -4
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_2.cu +1 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_2.cu +1 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_2.cu +1 -0
- data/ext/sources/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_2.cu +1 -0
- data/ext/sources/ggml/src/ggml-cuda/topk-moe.cu +7 -1
- data/ext/sources/ggml/src/ggml-cuda/vendors/hip.h +1 -0
- data/ext/sources/ggml/src/ggml-cuda/vendors/musa.h +1 -0
- data/ext/sources/ggml/src/ggml-hexagon/CMakeLists.txt +0 -5
- data/ext/sources/ggml/src/ggml-hexagon/ggml-hexagon.cpp +1634 -1293
- data/ext/sources/ggml/src/ggml-hexagon/htp/CMakeLists.txt +11 -40
- data/ext/sources/ggml/src/ggml-hexagon/htp/cmake-toolchain.cmake +13 -15
- data/ext/sources/ggml/src/ggml-hexagon/htp/concat-ops.c +1 -1
- data/ext/sources/ggml/src/ggml-hexagon/htp/flash-attn-ops.c +1749 -399
- data/ext/sources/ggml/src/ggml-hexagon/htp/flash-attn-ops.h +303 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hex-common.h +80 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hex-dma.h +26 -23
- data/ext/sources/ggml/src/ggml-hexagon/htp/hex-profile.h +64 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hex-utils.h +1 -83
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-fa-kernels.h +555 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-mm-kernels-tiled.h +1303 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-queue.c +9 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-queue.h +27 -4
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-utils.h +59 -37
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp-ctx.h +11 -3
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp-ops.h +52 -12
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp-vtcm.h +19 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/htp_iface.idl +2 -1
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-base.h +14 -30
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-exp.h +39 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-fa-kernels.h +232 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-mm-kernels-flat.h +1511 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-mm-kernels-tiled.h +1200 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/hvx-sigmoid.h +39 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/main.c +127 -32
- data/ext/sources/ggml/src/ggml-hexagon/htp/matmul-ops.c +3023 -4425
- data/ext/sources/ggml/src/ggml-hexagon/htp/matmul-ops.h +650 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp/rope-ops.c +48 -13
- data/ext/sources/ggml/src/ggml-hexagon/htp/ssm-conv.c +10 -9
- data/ext/sources/ggml/src/ggml-hexagon/htp/worker-pool.c +15 -3
- data/ext/sources/ggml/src/ggml-hexagon/htp/worker-pool.h +8 -0
- data/ext/sources/ggml/src/ggml-hexagon/htp-opnode.h +168 -50
- data/ext/sources/ggml/src/ggml-hexagon/libggml-htp.inf +0 -4
- data/ext/sources/ggml/src/ggml-hip/CMakeLists.txt +5 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.cpp +69 -5
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.h +4 -1
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-device.m +27 -6
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-impl.h +38 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-ops.cpp +132 -2
- data/ext/sources/ggml/src/ggml-metal/ggml-metal-ops.h +2 -0
- data/ext/sources/ggml/src/ggml-metal/ggml-metal.metal +345 -87
- data/ext/sources/ggml/src/ggml-opencl/CMakeLists.txt +13 -0
- data/ext/sources/ggml/src/ggml-opencl/fa_tune.h +92 -0
- data/ext/sources/ggml/src/ggml-opencl/ggml-opencl.cpp +4060 -357
- data/ext/sources/ggml/src/ggml-opencl/kernels/cvt.cl +198 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_f16.cl +81 -41
- data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_f32.cl +88 -39
- data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_f32_f16.cl +1995 -96
- data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_f32_q4_0.cl +1615 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_f32_q8_0.cl +1486 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/flash_attn_pre_f16.cl +156 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_mxfp4_f32_ns.cl +74 -6
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q4_0_f32_ns.cl +74 -6
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q4_1_f32_ns.cl +74 -6
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q4_k_f32_ns.cl +71 -6
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q5_0_f32_ns.cl +74 -6
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q5_1_f32_ns.cl +74 -6
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q5_k_f32_ns.cl +74 -6
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_moe_q6_k_f32_ns.cl +74 -6
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemm_noshuffle_q1_0_f32.cl +94 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q1_0_f32.cl +121 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/gemv_noshuffle_q8_0_f32.cl +1 -1
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mm_q1_0_f32_l4_lm.cl +156 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_f16_f32_l4.cl +1149 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_q1_0_f32.cl +141 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/mul_mv_q1_0_f32_flat.cl +190 -0
- data/ext/sources/ggml/src/ggml-opencl/kernels/norm.cl +5 -2
- data/ext/sources/ggml/src/ggml-opencl/kernels/set_rows.cl +500 -0
- data/ext/sources/ggml/src/ggml-opencl/libdl.h +79 -0
- data/ext/sources/ggml/src/ggml-openvino/.clang-format +0 -5
- data/ext/sources/ggml/src/ggml-openvino/CMakeLists.txt +2 -4
- data/ext/sources/ggml/src/ggml-openvino/ggml-decoder.cpp +733 -130
- data/ext/sources/ggml/src/ggml-openvino/ggml-decoder.h +76 -23
- data/ext/sources/ggml/src/ggml-openvino/ggml-openvino-extra.cpp +57 -3
- data/ext/sources/ggml/src/ggml-openvino/ggml-openvino-extra.h +29 -8
- data/ext/sources/ggml/src/ggml-openvino/ggml-openvino.cpp +307 -59
- data/ext/sources/ggml/src/ggml-openvino/ggml-quants.cpp +66 -0
- data/ext/sources/ggml/src/ggml-openvino/ggml-quants.h +10 -4
- data/ext/sources/ggml/src/ggml-openvino/openvino/decoder.h +56 -16
- data/ext/sources/ggml/src/ggml-openvino/openvino/frontend.h +1 -1
- data/ext/sources/ggml/src/ggml-openvino/openvino/input_model.h +4 -4
- data/ext/sources/ggml/src/ggml-openvino/openvino/node_context.h +94 -37
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/add_id.cpp +76 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/argsort.cpp +47 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/clamp.cpp +33 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/concat.cpp +48 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/cont.cpp +8 -16
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/cpy.cpp +14 -1
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/div.cpp +146 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/flash_attn_ext.cpp +108 -21
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/gated_delta_net.cpp +282 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/gated_delta_net.hpp +65 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/get_rows.cpp +2 -9
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/glu_geglu.cpp +21 -7
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/glu_swiglu.cpp +41 -8
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/im2col.cpp +120 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/l2_norm.cpp +44 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/mul_mat_id.cpp +226 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/mulmat.cpp +19 -9
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/norm.cpp +58 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/pad.cpp +95 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/permute.cpp +58 -13
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/repeat.cpp +74 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/reshape.cpp +13 -6
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/rms_norm.cpp +1 -1
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/rope.cpp +134 -38
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/set_rows.cpp +3 -3
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/softmax.cpp +126 -49
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/ssm_conv.cpp +59 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/sum_rows.cpp +27 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/transpose.cpp +32 -1
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/unary_silu.cpp +1 -1
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/unary_softplus.cpp +38 -0
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/view.cpp +90 -25
- data/ext/sources/ggml/src/ggml-openvino/openvino/op_table.cpp +41 -23
- data/ext/sources/ggml/src/ggml-openvino/openvino/op_table.h +18 -5
- data/ext/sources/ggml/src/ggml-openvino/openvino/pass/mark_decompression_convert_constant_folding.h +1 -1
- data/ext/sources/ggml/src/ggml-openvino/openvino/translate_session.cpp +43 -40
- data/ext/sources/ggml/src/ggml-openvino/openvino/translate_session.h +5 -4
- data/ext/sources/ggml/src/ggml-openvino/openvino/utils.cpp +548 -3
- data/ext/sources/ggml/src/ggml-openvino/openvino/utils.h +28 -26
- data/ext/sources/ggml/src/ggml-openvino/utils.cpp +383 -94
- data/ext/sources/ggml/src/ggml-openvino/utils.h +11 -8
- data/ext/sources/ggml/src/ggml-quants.c +76 -0
- data/ext/sources/ggml/src/ggml-quants.h +3 -0
- data/ext/sources/ggml/src/ggml-sycl/CMakeLists.txt +5 -5
- data/ext/sources/ggml/src/ggml-sycl/backend.hpp +2 -0
- data/ext/sources/ggml/src/ggml-sycl/binbcast.cpp +12 -0
- data/ext/sources/ggml/src/ggml-sycl/col2im-1d.cpp +102 -0
- data/ext/sources/ggml/src/ggml-sycl/col2im-1d.hpp +8 -0
- data/ext/sources/ggml/src/ggml-sycl/common.cpp +6 -8
- data/ext/sources/ggml/src/ggml-sycl/common.hpp +19 -2
- data/ext/sources/ggml/src/ggml-sycl/concat.cpp +21 -1
- data/ext/sources/ggml/src/ggml-sycl/conv2d-dw.cpp +158 -0
- data/ext/sources/ggml/src/ggml-sycl/conv2d-dw.hpp +10 -0
- data/ext/sources/ggml/src/ggml-sycl/conv2d-transpose.cpp +125 -0
- data/ext/sources/ggml/src/ggml-sycl/conv2d-transpose.hpp +10 -0
- data/ext/sources/ggml/src/ggml-sycl/conv2d.cpp +150 -0
- data/ext/sources/ggml/src/ggml-sycl/conv2d.hpp +10 -0
- data/ext/sources/ggml/src/ggml-sycl/conv3d.cpp +224 -0
- data/ext/sources/ggml/src/ggml-sycl/conv3d.hpp +8 -0
- data/ext/sources/ggml/src/ggml-sycl/convert.cpp +6 -0
- data/ext/sources/ggml/src/ggml-sycl/cpy.cpp +706 -0
- data/ext/sources/ggml/src/ggml-sycl/cpy.hpp +281 -0
- data/ext/sources/ggml/src/ggml-sycl/cross_entropy_loss.cpp +255 -0
- data/ext/sources/ggml/src/ggml-sycl/cross_entropy_loss.hpp +7 -0
- data/ext/sources/ggml/src/ggml-sycl/dequantize.hpp +15 -0
- data/ext/sources/ggml/src/ggml-sycl/dmmv.cpp +492 -319
- data/ext/sources/ggml/src/ggml-sycl/dpct/helper.hpp +15 -7
- data/ext/sources/ggml/src/ggml-sycl/element_wise.cpp +215 -115
- data/ext/sources/ggml/src/ggml-sycl/element_wise.hpp +2 -0
- data/ext/sources/ggml/src/ggml-sycl/ggml-sycl.cpp +1006 -336
- data/ext/sources/ggml/src/ggml-sycl/mmvq.cpp +252 -67
- data/ext/sources/ggml/src/ggml-sycl/mmvq.hpp +17 -0
- data/ext/sources/ggml/src/ggml-sycl/norm.cpp +103 -49
- data/ext/sources/ggml/src/ggml-sycl/outprod.cpp +45 -9
- data/ext/sources/ggml/src/ggml-sycl/pool.cpp +185 -0
- data/ext/sources/ggml/src/ggml-sycl/pool.hpp +22 -0
- data/ext/sources/ggml/src/ggml-sycl/presets.hpp +3 -1
- data/ext/sources/ggml/src/ggml-sycl/set_rows.cpp +10 -2
- data/ext/sources/ggml/src/ggml-sycl/softmax.cpp +9 -10
- data/ext/sources/ggml/src/ggml-sycl/vecdotq.hpp +35 -0
- data/ext/sources/ggml/src/ggml-vulkan/CMakeLists.txt +5 -0
- data/ext/sources/ggml/src/ggml-vulkan/ggml-vulkan.cpp +833 -215
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/col2im_1d.comp +61 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/conv2d_mm.comp +1 -1
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/conv3d_mm.comp +431 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/diag.comp +3 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn.comp +1 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm1.comp +1 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/generic_unary_head.glsl +21 -19
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/get_rows_back.comp +25 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/glu_head.glsl +23 -4
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/glu_main.glsl +14 -18
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/l2_norm.comp +4 -7
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vecq.comp +21 -24
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm.comp +31 -23
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_cm2.comp +6 -5
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_funcs.glsl +84 -67
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/norm.comp +10 -10
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/repeat_back.comp +3 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/roll.comp +3 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/tri.comp +3 -3
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/unary.comp +168 -0
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +121 -74
- data/ext/sources/ggml/src/ggml-webgpu/ggml-webgpu-shader-lib.hpp +26 -19
- data/ext/sources/ggml/src/ggml-webgpu/ggml-webgpu.cpp +31 -36
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/common_decls.tmpl +16 -2
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/flash_attn_vec_split.wgsl +7 -7
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/get_rows.wgsl +21 -0
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_decls.tmpl +439 -320
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_id_vec.wgsl +2 -2
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_vec.wgsl +45 -39
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_vec_acc.tmpl +586 -465
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/mul_mat_vec_q_acc.tmpl +63 -69
- data/ext/sources/ggml/src/ggml-webgpu/wgsl-shaders/quantize_q8.wgsl +14 -9
- data/ext/sources/ggml/src/ggml.c +36 -14
- data/ext/sources/include/whisper.h +21 -0
- data/ext/sources/src/whisper.cpp +164 -14
- data/lib/whisper/log_settable.rb +5 -8
- data/lib/whisper/model/uri.rb +0 -7
- data/sig/whisper.rbs +6 -0
- data/test/test_vad.rb +9 -0
- data/test/test_vad_context.rb +2 -2
- data/whispercpp.gemspec +1 -1
- metadata +62 -37
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-flash-attn-ops.c +0 -1878
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-matmul-ops.c +0 -2066
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-ops.c +0 -6
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-ops.h +0 -88
- data/ext/sources/ggml/src/ggml-hexagon/htp/hmx-profile.h +0 -34
- data/ext/sources/ggml/src/ggml-hexagon/htp/vtcm-utils.h +0 -16
- data/ext/sources/ggml/src/ggml-openvino/openvino/op/unary_gelu.cpp +0 -25
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/abs.comp +0 -21
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/ceil.comp +0 -22
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/clamp.comp +0 -17
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/cos.comp +0 -17
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/elu.comp +0 -27
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/exp.comp +0 -20
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/floor.comp +0 -22
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/gelu.comp +0 -25
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/gelu_erf.comp +0 -39
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/gelu_quick.comp +0 -23
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/hardsigmoid.comp +0 -22
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/hardswish.comp +0 -22
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/leaky_relu.comp +0 -22
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/neg.comp +0 -20
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/relu.comp +0 -21
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/round.comp +0 -29
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/sgn.comp +0 -21
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/sigmoid.comp +0 -20
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/silu.comp +0 -22
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/sin.comp +0 -17
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/softplus.comp +0 -23
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/sqrt.comp +0 -17
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/square.comp +0 -17
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/step.comp +0 -22
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/tanh.comp +0 -20
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/trunc.comp +0 -22
- data/ext/sources/ggml/src/ggml-vulkan/vulkan-shaders/xielu.comp +0 -35
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
#include <cstdint>
|
|
15
15
|
#include <cstdlib>
|
|
16
16
|
#include <cstring>
|
|
17
|
+
#include <fstream>
|
|
17
18
|
#include <iomanip>
|
|
18
19
|
#include <iostream>
|
|
19
20
|
#include <memory>
|
|
@@ -25,9 +26,11 @@
|
|
|
25
26
|
#include <openvino/openvino.hpp>
|
|
26
27
|
#include <openvino/runtime/compiled_model.hpp>
|
|
27
28
|
#include <openvino/runtime/infer_request.hpp>
|
|
29
|
+
#include <openvino/runtime/intel_gpu/ocl/ocl.hpp>
|
|
28
30
|
#include <openvino/runtime/intel_npu/properties.hpp>
|
|
29
31
|
#include <openvino/runtime/properties.hpp>
|
|
30
32
|
#include <openvino/runtime/tensor.hpp>
|
|
33
|
+
#include <optional>
|
|
31
34
|
#include <string>
|
|
32
35
|
#include <unordered_map>
|
|
33
36
|
#include <vector>
|
|
@@ -39,7 +42,7 @@
|
|
|
39
42
|
enum ggml_status ov_graph_compute(ggml_cgraph * cgraph, ggml_backend_t backend) {
|
|
40
43
|
ggml_backend_openvino_context * ctx = (ggml_backend_openvino_context *) backend->context;
|
|
41
44
|
try {
|
|
42
|
-
if (
|
|
45
|
+
if (ggml_openvino_getenv_int("GGML_OPENVINO_DUMP_CGRAPH")) {
|
|
43
46
|
std::string filename = "cgraph_ov.txt";
|
|
44
47
|
GgmlOvDecoder::dump_cgraph(cgraph, filename);
|
|
45
48
|
}
|
|
@@ -62,10 +65,92 @@ enum ggml_status ov_graph_compute(ggml_cgraph * cgraph, ggml_backend_t backend)
|
|
|
62
65
|
}
|
|
63
66
|
}
|
|
64
67
|
|
|
68
|
+
// For a KV cache input, return an ov::Tensor sized to n_kv (== attention_size
|
|
69
|
+
// for that layer) instead of the fully-allocated ctx_per_seq. Pre-conditions:
|
|
70
|
+
// * non-static (CPU/GPU) backend, single sequence, seq_active_start == 0
|
|
71
|
+
// * ggml KV layout is a contiguous [1, 1, ctx_per_seq, n_heads_kv*head_size]
|
|
72
|
+
// so the first n_kv rows are the live prefix and shrinking the ctx axis
|
|
73
|
+
// gives a valid tensor over the same host storage
|
|
74
|
+
// * not an SWA layer (ring cache): once the window has wrapped the first
|
|
75
|
+
// n_kv rows no longer contain the live prefix
|
|
76
|
+
// On any unmet pre-condition returns std::nullopt; the caller falls back to
|
|
77
|
+
// the full-size tensor.
|
|
78
|
+
static std::optional<ov::Tensor> try_make_kv_sliced_tensor(std::shared_ptr<GgmlOvDecoder> ggml_decoder,
|
|
79
|
+
const std::string & name,
|
|
80
|
+
const ggml_tensor * ggml_tensor) {
|
|
81
|
+
static const bool kv_slice_disabled = ggml_openvino_getenv_int("GGML_OPENVINO_DISABLE_KV_SLICE");
|
|
82
|
+
if (kv_slice_disabled) {
|
|
83
|
+
return std::nullopt;
|
|
84
|
+
}
|
|
85
|
+
if (ggml_decoder->is_static() || ggml_decoder->is_stateful()) {
|
|
86
|
+
return std::nullopt;
|
|
87
|
+
}
|
|
88
|
+
if (ggml_tensor->op != GGML_OP_NONE || ggml_tensor->view_src != nullptr) {
|
|
89
|
+
return std::nullopt;
|
|
90
|
+
}
|
|
91
|
+
const auto * op = ggml_decoder->get_tensor_used_op(ggml_tensor);
|
|
92
|
+
if (!GgmlOvDecoder::is_kvcache(ggml_tensor, op)) {
|
|
93
|
+
return std::nullopt;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const auto & compute_params = ggml_decoder->get_compute_params();
|
|
97
|
+
if (compute_params.n_seq_active != 1 || compute_params.seq_active_start != 0) {
|
|
98
|
+
return std::nullopt;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
int layer;
|
|
102
|
+
if (auto layer_opt = extract_layer_from_name(name); layer_opt.has_value()) {
|
|
103
|
+
layer = layer_opt.value();
|
|
104
|
+
} else {
|
|
105
|
+
return std::nullopt;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const bool is_swa = ggml_decoder->is_swa_layer(layer);
|
|
109
|
+
if (is_swa) {
|
|
110
|
+
return std::nullopt;
|
|
111
|
+
}
|
|
112
|
+
const int ctx_per_seq = ggml_decoder->get_ctx_per_seq();
|
|
113
|
+
const int n_kv = compute_params.attention_size;
|
|
114
|
+
if (ctx_per_seq <= 0 || n_kv <= 0 || n_kv >= ctx_per_seq) {
|
|
115
|
+
return std::nullopt;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
ov::Shape full_shape = ggml_decoder->get_shape(ggml_tensor);
|
|
119
|
+
if (full_shape.size() != 4 || full_shape[0] != 1 || full_shape[1] != 1 ||
|
|
120
|
+
static_cast<int>(full_shape[2]) != ctx_per_seq) {
|
|
121
|
+
return std::nullopt;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
ov::Shape sliced_shape = full_shape;
|
|
125
|
+
sliced_shape[2] = static_cast<size_t>(n_kv);
|
|
126
|
+
|
|
127
|
+
// Disabling for now as gpu has bug with in-place ScatterUpdate with remote tensors, can re-enable once CVS-186519 is fixed
|
|
128
|
+
// if (ggml_openvino_buffer_is_remote(ggml_tensor)) {
|
|
129
|
+
// auto remote_context = ggml_openvino_get_remote_context();
|
|
130
|
+
// auto gpu_context = remote_context->as<ov::intel_gpu::ocl::ClContext>();
|
|
131
|
+
// return gpu_context.create_tensor(ggml_decoder->get_ov_type(ggml_tensor), sliced_shape, ggml_tensor->data);
|
|
132
|
+
// }
|
|
133
|
+
|
|
134
|
+
return ov::Tensor(ggml_decoder->get_ov_type(ggml_tensor), sliced_shape, ggml_tensor->data);
|
|
135
|
+
}
|
|
136
|
+
|
|
65
137
|
ov::Tensor create_ov_output_tensor(std::shared_ptr<GgmlOvDecoder> ggml_decoder,
|
|
66
138
|
std::shared_ptr<ov::InferRequest> infer_request,
|
|
67
139
|
int output_index,
|
|
68
140
|
const ggml_tensor * ggml_tensor) {
|
|
141
|
+
if (auto sliced = try_make_kv_sliced_tensor(ggml_decoder, std::string(ggml_tensor->name), ggml_tensor)) {
|
|
142
|
+
return *sliced;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Disabling for now as gpu has bug with in-place ScatterUpdate with remote tensors, can re-enable once CVS-186519 is fixed
|
|
146
|
+
// if (ggml_tensor->extra != nullptr && !ggml_decoder->is_splited_model()) {
|
|
147
|
+
// auto * extra_base = static_cast<ggml_openvino_extra_base *>(ggml_tensor->extra);
|
|
148
|
+
// if (extra_base->type == ggml_openvino_extra_base::Type::TENSOR) {
|
|
149
|
+
// auto * tensor_extra = static_cast<ggml_openvino_tensor_extra *>(extra_base);
|
|
150
|
+
// return *tensor_extra->tensor;
|
|
151
|
+
// }
|
|
152
|
+
// }
|
|
153
|
+
|
|
69
154
|
auto output_type = ggml_decoder->get_ov_type(ggml_tensor);
|
|
70
155
|
ov::Shape output_shape;
|
|
71
156
|
if (ggml_decoder->is_static()) {
|
|
@@ -86,7 +171,9 @@ enum ggml_status ov_graph_compute_dynamic(ggml_cgraph * cgraph, std::shared_ptr<
|
|
|
86
171
|
static auto is_static = false;
|
|
87
172
|
|
|
88
173
|
if (is_naive(cgraph)) {
|
|
89
|
-
|
|
174
|
+
if (!is_model_splitted(cgraph)) {
|
|
175
|
+
return naive_compute(cgraph, core, device, config);
|
|
176
|
+
}
|
|
90
177
|
}
|
|
91
178
|
|
|
92
179
|
auto start_time = ggml_time_us();
|
|
@@ -98,18 +185,20 @@ enum ggml_status ov_graph_compute_dynamic(ggml_cgraph * cgraph, std::shared_ptr<
|
|
|
98
185
|
std::tie(m_params, c_params) = GgmlOvDecoder::compute_llm_params(cgraph, is_static);
|
|
99
186
|
|
|
100
187
|
graph_key key(cgraph);
|
|
101
|
-
bool
|
|
188
|
+
static const bool cache_enabled = !ggml_openvino_getenv_int("GGML_OPENVINO_DISABLE_CACHE");
|
|
189
|
+
bool cache_hit = false;
|
|
102
190
|
|
|
103
191
|
int64_t decoder_end_time;
|
|
104
192
|
int64_t conversion_end_time;
|
|
105
193
|
int64_t compile_end_time;
|
|
106
194
|
int64_t infer_end_time;
|
|
195
|
+
int64_t ov_raw_infer_start;
|
|
107
196
|
|
|
108
197
|
{
|
|
109
198
|
std::shared_ptr<decoder_runtime_ctx> entry;
|
|
110
199
|
ModelParams old_m_params;
|
|
111
200
|
|
|
112
|
-
{
|
|
201
|
+
if (cache_enabled) {
|
|
113
202
|
std::lock_guard<std::mutex> map_lock(r_ctx->ctx_mutex);
|
|
114
203
|
auto it = r_ctx->decoder_cache.find(key);
|
|
115
204
|
cache_hit = it != r_ctx->decoder_cache.end();
|
|
@@ -120,6 +209,10 @@ enum ggml_status ov_graph_compute_dynamic(ggml_cgraph * cgraph, std::shared_ptr<
|
|
|
120
209
|
entry = std::make_shared<decoder_runtime_ctx>(mutex);
|
|
121
210
|
r_ctx->decoder_cache[key] = entry;
|
|
122
211
|
}
|
|
212
|
+
} else {
|
|
213
|
+
auto mutex = std::make_shared<std::mutex>();
|
|
214
|
+
entry = std::make_shared<decoder_runtime_ctx>(mutex);
|
|
215
|
+
cache_hit = false;
|
|
123
216
|
}
|
|
124
217
|
|
|
125
218
|
std::lock_guard<std::mutex> lock(*(entry->mutex));
|
|
@@ -127,9 +220,14 @@ enum ggml_status ov_graph_compute_dynamic(ggml_cgraph * cgraph, std::shared_ptr<
|
|
|
127
220
|
if (cache_hit) {
|
|
128
221
|
ggml_decoder = entry->ptr;
|
|
129
222
|
old_m_params = ggml_decoder->get_model_params();
|
|
130
|
-
|
|
223
|
+
if (!ggml_decoder->is_splited_model()) {
|
|
224
|
+
cache_hit = old_m_params.can_reuse_dynamically(m_params);
|
|
225
|
+
}
|
|
131
226
|
}
|
|
132
227
|
|
|
228
|
+
std::vector<std::string> ov_input_names;
|
|
229
|
+
std::vector<std::string> ov_output_names;
|
|
230
|
+
|
|
133
231
|
if (cache_hit) {
|
|
134
232
|
std::map<std::string, std::shared_ptr<ov::Node>> model_weights;
|
|
135
233
|
ggml_decoder->set_compute_params(c_params);
|
|
@@ -141,6 +239,8 @@ enum ggml_status ov_graph_compute_dynamic(ggml_cgraph * cgraph, std::shared_ptr<
|
|
|
141
239
|
{
|
|
142
240
|
std::lock_guard<std::mutex> map_lock(r_ctx->ctx_mutex);
|
|
143
241
|
infer_request = r_ctx->infer_request_cache.at(key);
|
|
242
|
+
ov_input_names = r_ctx->ov_input_names_cache.at(key);
|
|
243
|
+
ov_output_names = r_ctx->ov_output_names_cache.at(key);
|
|
144
244
|
}
|
|
145
245
|
|
|
146
246
|
if (stateful) {
|
|
@@ -162,14 +262,15 @@ enum ggml_status ov_graph_compute_dynamic(ggml_cgraph * cgraph, std::shared_ptr<
|
|
|
162
262
|
try {
|
|
163
263
|
state_name = r_ctx->kv_state_input_name_map.at(state.get_name());
|
|
164
264
|
} catch (...) {
|
|
165
|
-
GGML_LOG_ERROR(
|
|
265
|
+
GGML_LOG_ERROR(
|
|
266
|
+
"GGML OpenVINO backend stateful inference failed: no input found for the state\n");
|
|
166
267
|
return GGML_STATUS_FAILED;
|
|
167
268
|
}
|
|
168
269
|
auto kv_tensor = get_ov_input_tensor(ggml_decoder, state_name);
|
|
169
|
-
kv_tensor.set_shape({state_tensor_shape[0], kv_tensor.get_shape()[2],
|
|
170
|
-
state_tensor_shape[
|
|
171
|
-
|
|
172
|
-
|
|
270
|
+
kv_tensor.set_shape({state_tensor_shape[0], kv_tensor.get_shape()[2], state_tensor_shape[2],
|
|
271
|
+
state_tensor_shape[3]});
|
|
272
|
+
state_tensor = kv_tensor;
|
|
273
|
+
state_tensor_shape = state_tensor.get_shape();
|
|
173
274
|
}
|
|
174
275
|
ov::Coordinate begin = {0, 0, 0, 0};
|
|
175
276
|
ov::Coordinate end = {state_tensor_shape[0], static_cast<uint32_t>(pos_data[0]),
|
|
@@ -177,7 +278,7 @@ enum ggml_status ov_graph_compute_dynamic(ggml_cgraph * cgraph, std::shared_ptr<
|
|
|
177
278
|
ov::Tensor new_state_tensor(state_tensor, begin, end);
|
|
178
279
|
state.set_state(new_state_tensor);
|
|
179
280
|
}
|
|
180
|
-
r_ctx->stateful_kv_size = pos_data[0] +
|
|
281
|
+
r_ctx->stateful_kv_size = pos_data[0] + pos_shape[3];
|
|
181
282
|
}
|
|
182
283
|
}
|
|
183
284
|
|
|
@@ -185,15 +286,17 @@ enum ggml_status ov_graph_compute_dynamic(ggml_cgraph * cgraph, std::shared_ptr<
|
|
|
185
286
|
conversion_end_time = decoder_end_time;
|
|
186
287
|
compile_end_time = decoder_end_time;
|
|
187
288
|
} else {
|
|
188
|
-
{
|
|
289
|
+
if (cache_enabled) {
|
|
189
290
|
std::lock_guard<std::mutex> map_lock(r_ctx->ctx_mutex);
|
|
190
291
|
r_ctx->infer_request_cache.erase(key);
|
|
191
292
|
}
|
|
293
|
+
bool model_is_splitted = is_model_splitted(cgraph);
|
|
192
294
|
|
|
193
295
|
std::shared_ptr<ov::Model> model;
|
|
194
296
|
auto model_weights = GgmlOvDecoder::create_weight_nodes(cgraph);
|
|
195
297
|
|
|
196
|
-
ggml_decoder = std::make_shared<GgmlOvDecoder>(cgraph, m_params, c_params, model_weights, is_static,
|
|
298
|
+
ggml_decoder = std::make_shared<GgmlOvDecoder>(cgraph, m_params, c_params, model_weights, is_static,
|
|
299
|
+
stateful, model_is_splitted);
|
|
197
300
|
decoder_end_time = ggml_time_us();
|
|
198
301
|
|
|
199
302
|
auto input_model = std::make_shared<ov::frontend::ggml::InputModel>(ggml_decoder);
|
|
@@ -201,7 +304,7 @@ enum ggml_status ov_graph_compute_dynamic(ggml_cgraph * cgraph, std::shared_ptr<
|
|
|
201
304
|
ggml_decoder->clear_model_weights();
|
|
202
305
|
conversion_end_time = ggml_time_us();
|
|
203
306
|
|
|
204
|
-
if (
|
|
307
|
+
if (ggml_openvino_getenv_int("GGML_OPENVINO_DUMP_IR")) {
|
|
205
308
|
char timestamped_filename[64];
|
|
206
309
|
auto timestamp = (long long) ggml_time_us();
|
|
207
310
|
snprintf(timestamped_filename, sizeof(timestamped_filename), "model_%lld.xml", timestamp);
|
|
@@ -219,8 +322,6 @@ enum ggml_status ov_graph_compute_dynamic(ggml_cgraph * cgraph, std::shared_ptr<
|
|
|
219
322
|
infer_request = std::make_shared<ov::InferRequest>(compiled_model.create_infer_request());
|
|
220
323
|
entry->ptr = ggml_decoder;
|
|
221
324
|
|
|
222
|
-
std::vector<std::string> ov_input_names;
|
|
223
|
-
std::vector<std::string> ov_output_names;
|
|
224
325
|
for (const auto & ov_param : model->get_parameters()) {
|
|
225
326
|
ov_input_names.push_back(ov_param->get_friendly_name());
|
|
226
327
|
}
|
|
@@ -228,66 +329,64 @@ enum ggml_status ov_graph_compute_dynamic(ggml_cgraph * cgraph, std::shared_ptr<
|
|
|
228
329
|
ov_output_names.push_back(ov_output->get_friendly_name());
|
|
229
330
|
}
|
|
230
331
|
|
|
231
|
-
{
|
|
332
|
+
if (cache_enabled) {
|
|
232
333
|
std::lock_guard<std::mutex> map_lock(r_ctx->ctx_mutex);
|
|
233
334
|
r_ctx->infer_request_cache[key] = infer_request;
|
|
234
|
-
r_ctx->ov_input_names_cache[key] =
|
|
235
|
-
r_ctx->ov_output_names_cache[key] =
|
|
335
|
+
r_ctx->ov_input_names_cache[key] = ov_input_names;
|
|
336
|
+
r_ctx->ov_output_names_cache[key] = ov_output_names;
|
|
236
337
|
}
|
|
237
338
|
|
|
238
|
-
if (stateful) {
|
|
339
|
+
if (stateful && cache_enabled) {
|
|
239
340
|
const auto * inp_pos = get_inp_pos_tensor(cgraph);
|
|
240
341
|
auto pos_shape = ggml_decoder->get_shape(inp_pos);
|
|
241
342
|
r_ctx->stateful_kv_size = pos_shape[3];
|
|
242
343
|
const auto kv_param_res_names = ggml_decoder->get_kv_param_res_names();
|
|
243
|
-
for (const auto& pair : kv_param_res_names) {
|
|
244
|
-
r_ctx->kv_state_input_name_map[pair.first+pair.second] = pair.first;
|
|
344
|
+
for (const auto & pair : kv_param_res_names) {
|
|
345
|
+
r_ctx->kv_state_input_name_map[pair.first + pair.second] = pair.first;
|
|
245
346
|
}
|
|
246
347
|
}
|
|
247
348
|
}
|
|
248
349
|
|
|
249
|
-
std::vector<std::string> ov_input_names;
|
|
250
|
-
std::vector<std::string> ov_output_names;
|
|
251
|
-
{
|
|
252
|
-
std::lock_guard<std::mutex> map_lock(r_ctx->ctx_mutex);
|
|
253
|
-
ov_input_names = r_ctx->ov_input_names_cache[key];
|
|
254
|
-
ov_output_names = r_ctx->ov_output_names_cache[key];
|
|
255
|
-
}
|
|
256
|
-
|
|
257
350
|
for (size_t i = 0; i < ov_input_names.size(); i++) {
|
|
258
351
|
auto param_name = ov_input_names[i];
|
|
259
352
|
auto input_tensor = get_ov_input_tensor(ggml_decoder, param_name);
|
|
260
353
|
infer_request->set_input_tensor(i, input_tensor);
|
|
261
354
|
|
|
262
|
-
if (
|
|
355
|
+
if (ggml_openvino_getenv_int("GGML_OPENVINO_DEBUG_INPUT")) {
|
|
263
356
|
print_input_tensor_info(param_name, input_tensor);
|
|
264
357
|
}
|
|
265
358
|
}
|
|
266
359
|
|
|
267
360
|
for (size_t i = 0; i < ov_output_names.size(); i++) {
|
|
268
361
|
auto * ggml_tensor = ggml_decoder->get_model_outputs().at(ov_output_names[i]);
|
|
362
|
+
if (ggml_nbytes(ggml_tensor) == 0) {
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
269
365
|
auto output_tensor = create_ov_output_tensor(ggml_decoder, infer_request, i, ggml_tensor);
|
|
270
366
|
infer_request->set_output_tensor(i, output_tensor);
|
|
271
367
|
}
|
|
272
368
|
|
|
369
|
+
ov_raw_infer_start = ggml_time_us();
|
|
273
370
|
infer_request->infer();
|
|
274
371
|
infer_end_time = ggml_time_us();
|
|
275
372
|
|
|
276
|
-
if (
|
|
373
|
+
if (ggml_openvino_getenv_int("GGML_OPENVINO_DEBUG_OUTPUT")) {
|
|
277
374
|
for (size_t i = 0; i < ov_output_names.size(); i++) {
|
|
278
375
|
const auto output_tensor = infer_request->get_output_tensor(i);
|
|
279
376
|
print_output_tensor_info(ov_output_names[i], output_tensor, output_tensor.data());
|
|
280
377
|
}
|
|
281
378
|
}
|
|
282
379
|
|
|
283
|
-
if (
|
|
380
|
+
if (ggml_openvino_getenv_int("GGML_OPENVINO_PROFILING")) {
|
|
284
381
|
GGML_LOG_INFO("\nGGML OpenVINO Backend: \n");
|
|
285
|
-
GGML_LOG_INFO(" - Graph decoder time:
|
|
382
|
+
GGML_LOG_INFO(" - Graph decoder time: %.3f ms \n", (decoder_end_time - start_time) / 1000.0);
|
|
286
383
|
if (!cache_hit) {
|
|
287
|
-
GGML_LOG_INFO(" - Graph conversion time:
|
|
288
|
-
|
|
384
|
+
GGML_LOG_INFO(" - Graph conversion time: %.3f ms \n",
|
|
385
|
+
(conversion_end_time - decoder_end_time) / 1000.0);
|
|
386
|
+
GGML_LOG_INFO(" - Graph compile time: %.3f ms \n", (compile_end_time - conversion_end_time) / 1000.0);
|
|
289
387
|
}
|
|
290
|
-
GGML_LOG_INFO(" - Graph inference time:
|
|
388
|
+
GGML_LOG_INFO(" - Graph inference time: %.3f ms \n", (infer_end_time - compile_end_time) / 1000.0);
|
|
389
|
+
GGML_LOG_INFO(" - OV raw infer time: %.3f ms \n", (infer_end_time - ov_raw_infer_start) / 1000.0);
|
|
291
390
|
}
|
|
292
391
|
}
|
|
293
392
|
|
|
@@ -298,17 +397,18 @@ enum ggml_status ov_graph_compute_static(ggml_cgraph * cgraph, std::shared_ptr<o
|
|
|
298
397
|
auto & core = ov_singleton_core();
|
|
299
398
|
|
|
300
399
|
auto get_prefill_chunk_size = [] {
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
return
|
|
304
|
-
}
|
|
305
|
-
return
|
|
400
|
+
static const int chunk_size = []() {
|
|
401
|
+
int env_prefill_chunk_size = ggml_openvino_getenv_int("GGML_OPENVINO_PREFILL_CHUNK_SIZE");
|
|
402
|
+
return env_prefill_chunk_size > 0 ? env_prefill_chunk_size : 256;
|
|
403
|
+
}();
|
|
404
|
+
return chunk_size;
|
|
306
405
|
};
|
|
307
406
|
|
|
308
407
|
static std::string device = "NPU";
|
|
309
408
|
static auto is_static = true;
|
|
310
409
|
static auto stateful = false;
|
|
311
|
-
|
|
410
|
+
|
|
411
|
+
auto prefill_chunk_size = get_prefill_chunk_size();
|
|
312
412
|
const auto & config = ggml_openvino_get_compile_config();
|
|
313
413
|
|
|
314
414
|
if (is_naive(cgraph)) {
|
|
@@ -326,17 +426,20 @@ enum ggml_status ov_graph_compute_static(ggml_cgraph * cgraph, std::shared_ptr<o
|
|
|
326
426
|
const auto * inp_pos = get_inp_pos_tensor(cgraph);
|
|
327
427
|
const auto is_prefill = get_is_prefill(inp_pos);
|
|
328
428
|
graph_key key(cgraph);
|
|
329
|
-
bool
|
|
429
|
+
static const bool cache_enabled = !ggml_openvino_getenv_int("GGML_OPENVINO_DISABLE_CACHE");
|
|
430
|
+
bool cache_hit = false;
|
|
330
431
|
|
|
331
432
|
int64_t decoder_end_time;
|
|
332
433
|
int64_t conversion_end_time;
|
|
333
434
|
int64_t compile_end_time;
|
|
334
435
|
int64_t infer_end_time;
|
|
436
|
+
int64_t ov_raw_infer_start;
|
|
437
|
+
int64_t ov_raw_infer_total = 0;
|
|
335
438
|
|
|
336
439
|
std::shared_ptr<decoder_runtime_ctx> entry;
|
|
337
440
|
ModelParams old_m_params;
|
|
338
441
|
|
|
339
|
-
{
|
|
442
|
+
if (cache_enabled) {
|
|
340
443
|
std::lock_guard<std::mutex> map_lock(r_ctx->ctx_mutex);
|
|
341
444
|
auto it = r_ctx->decoder_cache.find(key);
|
|
342
445
|
cache_hit = it != r_ctx->decoder_cache.end();
|
|
@@ -347,6 +450,10 @@ enum ggml_status ov_graph_compute_static(ggml_cgraph * cgraph, std::shared_ptr<o
|
|
|
347
450
|
entry = std::make_shared<decoder_runtime_ctx>(mutex);
|
|
348
451
|
r_ctx->decoder_cache[key] = entry;
|
|
349
452
|
}
|
|
453
|
+
} else {
|
|
454
|
+
auto mutex = std::make_shared<std::mutex>();
|
|
455
|
+
entry = std::make_shared<decoder_runtime_ctx>(mutex);
|
|
456
|
+
cache_hit = false;
|
|
350
457
|
}
|
|
351
458
|
|
|
352
459
|
std::lock_guard<std::mutex> lock(*(entry->mutex));
|
|
@@ -357,6 +464,9 @@ enum ggml_status ov_graph_compute_static(ggml_cgraph * cgraph, std::shared_ptr<o
|
|
|
357
464
|
cache_hit = old_m_params.can_reuse_statically(m_params);
|
|
358
465
|
}
|
|
359
466
|
|
|
467
|
+
std::vector<std::string> ov_input_names_local;
|
|
468
|
+
std::vector<std::string> ov_output_names_local;
|
|
469
|
+
|
|
360
470
|
if (cache_hit) {
|
|
361
471
|
std::map<std::string, std::shared_ptr<ov::Node>> model_weights;
|
|
362
472
|
ggml_decoder->m_is_prefill = is_prefill;
|
|
@@ -370,13 +480,15 @@ enum ggml_status ov_graph_compute_static(ggml_cgraph * cgraph, std::shared_ptr<o
|
|
|
370
480
|
std::lock_guard<std::mutex> map_lock(r_ctx->ctx_mutex);
|
|
371
481
|
infer_request =
|
|
372
482
|
is_prefill ? r_ctx->infer_request_cache_prefill.at(key) : r_ctx->infer_request_cache.at(key);
|
|
483
|
+
ov_input_names_local = r_ctx->ov_input_names_cache.at(key);
|
|
484
|
+
ov_output_names_local = r_ctx->ov_output_names_cache.at(key);
|
|
373
485
|
}
|
|
374
486
|
|
|
375
487
|
decoder_end_time = ggml_time_us();
|
|
376
488
|
conversion_end_time = decoder_end_time;
|
|
377
489
|
compile_end_time = decoder_end_time;
|
|
378
490
|
} else {
|
|
379
|
-
{
|
|
491
|
+
if (cache_enabled) {
|
|
380
492
|
std::lock_guard<std::mutex> map_lock(r_ctx->ctx_mutex);
|
|
381
493
|
r_ctx->infer_request_cache.erase(key);
|
|
382
494
|
r_ctx->infer_request_cache_prefill.erase(key);
|
|
@@ -385,10 +497,14 @@ enum ggml_status ov_graph_compute_static(ggml_cgraph * cgraph, std::shared_ptr<o
|
|
|
385
497
|
std::shared_ptr<ov::Model> model;
|
|
386
498
|
auto model_weights = GgmlOvDecoder::create_weight_nodes(cgraph);
|
|
387
499
|
|
|
388
|
-
|
|
389
|
-
|
|
500
|
+
if (m_params.n_heads_kv == -1) {
|
|
501
|
+
// graph is not a LLM, e.g. context-shift graph
|
|
502
|
+
prefill_chunk_size = inp_pos->ne[0];
|
|
503
|
+
}
|
|
504
|
+
auto ggml_decoder_prefill = std::make_shared<GgmlOvDecoder>(
|
|
505
|
+
cgraph, m_params, c_params, model_weights, is_static, stateful, false, true, prefill_chunk_size);
|
|
390
506
|
auto ggml_decoder_decode = std::make_shared<GgmlOvDecoder>(cgraph, m_params, c_params, model_weights, is_static,
|
|
391
|
-
stateful, false, prefill_chunk_size);
|
|
507
|
+
stateful, false, false, prefill_chunk_size);
|
|
392
508
|
decoder_end_time = ggml_time_us();
|
|
393
509
|
|
|
394
510
|
auto input_model_prefill = std::make_shared<ov::frontend::ggml::InputModel>(ggml_decoder_prefill);
|
|
@@ -400,7 +516,7 @@ enum ggml_status ov_graph_compute_static(ggml_cgraph * cgraph, std::shared_ptr<o
|
|
|
400
516
|
ggml_decoder_decode->clear_model_weights();
|
|
401
517
|
conversion_end_time = ggml_time_us();
|
|
402
518
|
|
|
403
|
-
if (
|
|
519
|
+
if (ggml_openvino_getenv_int("GGML_OPENVINO_DUMP_IR")) {
|
|
404
520
|
char timestamped_filename[64];
|
|
405
521
|
auto timestamp = (long long) ggml_time_us();
|
|
406
522
|
snprintf(timestamped_filename, sizeof(timestamped_filename), "model_prefill_%lld.xml", timestamp);
|
|
@@ -429,32 +545,22 @@ enum ggml_status ov_graph_compute_static(ggml_cgraph * cgraph, std::shared_ptr<o
|
|
|
429
545
|
infer_request = is_prefill ? infer_request_prefill : infer_request_decode;
|
|
430
546
|
entry->ptr = ggml_decoder;
|
|
431
547
|
|
|
432
|
-
std::vector<std::string> ov_input_names;
|
|
433
|
-
std::vector<std::string> ov_output_names;
|
|
434
548
|
for (const auto & ov_param : model->get_parameters()) {
|
|
435
|
-
|
|
549
|
+
ov_input_names_local.push_back(ov_param->get_friendly_name());
|
|
436
550
|
}
|
|
437
551
|
for (const auto & ov_output : model->get_results()) {
|
|
438
|
-
|
|
552
|
+
ov_output_names_local.push_back(ov_output->get_friendly_name());
|
|
439
553
|
}
|
|
440
554
|
|
|
441
|
-
{
|
|
555
|
+
if (cache_enabled) {
|
|
442
556
|
std::lock_guard<std::mutex> map_lock(r_ctx->ctx_mutex);
|
|
443
557
|
r_ctx->infer_request_cache_prefill[key] = infer_request_prefill;
|
|
444
558
|
r_ctx->infer_request_cache[key] = infer_request_decode;
|
|
445
|
-
r_ctx->ov_input_names_cache[key] =
|
|
446
|
-
r_ctx->ov_output_names_cache[key] =
|
|
559
|
+
r_ctx->ov_input_names_cache[key] = ov_input_names_local;
|
|
560
|
+
r_ctx->ov_output_names_cache[key] = ov_output_names_local;
|
|
447
561
|
}
|
|
448
562
|
}
|
|
449
563
|
|
|
450
|
-
std::vector<std::string> ov_input_names_local;
|
|
451
|
-
std::vector<std::string> ov_output_names_local;
|
|
452
|
-
{
|
|
453
|
-
std::lock_guard<std::mutex> map_lock(r_ctx->ctx_mutex);
|
|
454
|
-
ov_input_names_local = r_ctx->ov_input_names_cache[key];
|
|
455
|
-
ov_output_names_local = r_ctx->ov_output_names_cache[key];
|
|
456
|
-
}
|
|
457
|
-
|
|
458
564
|
if (is_prefill) {
|
|
459
565
|
auto inp_len = inp_pos->ne[0];
|
|
460
566
|
for (int chunk_index = 0; chunk_index * prefill_chunk_size < inp_len; chunk_index++) {
|
|
@@ -463,7 +569,7 @@ enum ggml_status ov_graph_compute_static(ggml_cgraph * cgraph, std::shared_ptr<o
|
|
|
463
569
|
auto input_tensor = get_ov_input_tensor_static_prefill(ggml_decoder, param_name, chunk_index);
|
|
464
570
|
infer_request->set_input_tensor(i, input_tensor);
|
|
465
571
|
|
|
466
|
-
if (
|
|
572
|
+
if (ggml_openvino_getenv_int("GGML_OPENVINO_DEBUG_INPUT")) {
|
|
467
573
|
const auto input_tensor = infer_request->get_input_tensor(i);
|
|
468
574
|
print_input_tensor_info(param_name, input_tensor);
|
|
469
575
|
}
|
|
@@ -475,9 +581,11 @@ enum ggml_status ov_graph_compute_static(ggml_cgraph * cgraph, std::shared_ptr<o
|
|
|
475
581
|
infer_request->set_output_tensor(i, output_tensor);
|
|
476
582
|
}
|
|
477
583
|
|
|
584
|
+
ov_raw_infer_start = ggml_time_us();
|
|
478
585
|
infer_request->infer();
|
|
586
|
+
ov_raw_infer_total += ggml_time_us() - ov_raw_infer_start;
|
|
479
587
|
|
|
480
|
-
if (
|
|
588
|
+
if (ggml_openvino_getenv_int("GGML_OPENVINO_DEBUG_OUTPUT")) {
|
|
481
589
|
for (size_t i = 0; i < ov_output_names_local.size(); i++) {
|
|
482
590
|
const auto output_tensor = infer_request->get_output_tensor(i);
|
|
483
591
|
print_output_tensor_info(ov_output_names_local[i], output_tensor, output_tensor.data());
|
|
@@ -491,7 +599,7 @@ enum ggml_status ov_graph_compute_static(ggml_cgraph * cgraph, std::shared_ptr<o
|
|
|
491
599
|
auto input_tensor = get_ov_input_tensor_static_decode(ggml_decoder, param_name);
|
|
492
600
|
infer_request->set_input_tensor(i, input_tensor);
|
|
493
601
|
|
|
494
|
-
if (
|
|
602
|
+
if (ggml_openvino_getenv_int("GGML_OPENVINO_DEBUG_INPUT")) {
|
|
495
603
|
const auto input_tensor = infer_request->get_input_tensor(i);
|
|
496
604
|
print_input_tensor_info(param_name, input_tensor);
|
|
497
605
|
}
|
|
@@ -503,10 +611,12 @@ enum ggml_status ov_graph_compute_static(ggml_cgraph * cgraph, std::shared_ptr<o
|
|
|
503
611
|
infer_request->set_output_tensor(i, output_tensor);
|
|
504
612
|
}
|
|
505
613
|
|
|
614
|
+
ov_raw_infer_start = ggml_time_us();
|
|
506
615
|
infer_request->infer();
|
|
507
616
|
infer_end_time = ggml_time_us();
|
|
617
|
+
ov_raw_infer_total = infer_end_time - ov_raw_infer_start;
|
|
508
618
|
|
|
509
|
-
if (
|
|
619
|
+
if (ggml_openvino_getenv_int("GGML_OPENVINO_DEBUG_OUTPUT")) {
|
|
510
620
|
for (size_t i = 0; i < ov_output_names_local.size(); i++) {
|
|
511
621
|
const auto output_tensor = infer_request->get_output_tensor(i);
|
|
512
622
|
print_output_tensor_info(ov_output_names_local[i], output_tensor, output_tensor.data());
|
|
@@ -514,19 +624,75 @@ enum ggml_status ov_graph_compute_static(ggml_cgraph * cgraph, std::shared_ptr<o
|
|
|
514
624
|
}
|
|
515
625
|
}
|
|
516
626
|
|
|
517
|
-
if (
|
|
627
|
+
if (ggml_openvino_getenv_int("GGML_OPENVINO_PROFILING")) {
|
|
518
628
|
GGML_LOG_INFO("\nGGML OpenVINO Backend: \n");
|
|
519
|
-
GGML_LOG_INFO(" - Graph decoder time:
|
|
629
|
+
GGML_LOG_INFO(" - Graph decoder time: %.3f ms \n", (decoder_end_time - start_time) / 1000.0);
|
|
520
630
|
if (!cache_hit) {
|
|
521
|
-
GGML_LOG_INFO(" - Graph conversion time:
|
|
522
|
-
GGML_LOG_INFO(" - Graph compile time:
|
|
631
|
+
GGML_LOG_INFO(" - Graph conversion time: %.3f ms \n", (conversion_end_time - decoder_end_time) / 1000.0);
|
|
632
|
+
GGML_LOG_INFO(" - Graph compile time: %.3f ms \n", (compile_end_time - conversion_end_time) / 1000.0);
|
|
523
633
|
}
|
|
524
|
-
GGML_LOG_INFO(" - Graph inference time:
|
|
634
|
+
GGML_LOG_INFO(" - Graph inference time: %.3f ms \n", (infer_end_time - compile_end_time) / 1000.0);
|
|
635
|
+
GGML_LOG_INFO(" - OV raw infer time: %.3f ms \n", ov_raw_infer_total / 1000.0);
|
|
525
636
|
}
|
|
526
637
|
|
|
527
638
|
return GGML_STATUS_SUCCESS;
|
|
528
639
|
}
|
|
529
640
|
|
|
641
|
+
// Detect whether a cgraph is a split subgraph or not.
|
|
642
|
+
// Step 1 compares each node's recorded use_count with actual fan-out references in node->src.
|
|
643
|
+
// Step 2 verifies that node inputs come from model nodes/weights/leafs; external sources imply split.
|
|
644
|
+
bool is_model_splitted(ggml_cgraph * cgraph) {
|
|
645
|
+
// check the nodes of the model are used by the following nodes, through compare the node's use count and the count of nodes that use it as input. If does not match, return true, else return false.
|
|
646
|
+
for (int i = 0; i < cgraph->n_nodes; i++) {
|
|
647
|
+
ggml_tensor * node = cgraph->nodes[i];
|
|
648
|
+
int use_count = cgraph->use_counts[ggml_hash_find(&cgraph->visited_hash_set, node)];
|
|
649
|
+
// TODO: this is a workround for the tests case from llama.cpp, fix should from the root cause in the future.
|
|
650
|
+
if ((cgraph->n_nodes <= 1 && use_count == 0) ||
|
|
651
|
+
(cgraph->n_nodes <= 1 && node->op == GGML_OP_VIEW && use_count == 1 && node->src[0] != nullptr &&
|
|
652
|
+
node->src[0]->op == GGML_OP_NONE)) {
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
if (cgraph->n_nodes == 1 &&
|
|
656
|
+
(cgraph->nodes[0]->op == GGML_OP_TRANSPOSE || cgraph->nodes[0]->op == GGML_OP_PERMUTE)) {
|
|
657
|
+
return false;
|
|
658
|
+
}
|
|
659
|
+
int input_use_count = 0;
|
|
660
|
+
for (int j = 0; j < cgraph->n_nodes; j++) {
|
|
661
|
+
ggml_tensor * other_node = cgraph->nodes[j];
|
|
662
|
+
for (int k = 0; k < GGML_MAX_SRC; k++) {
|
|
663
|
+
if (other_node->src[k] == node) {
|
|
664
|
+
input_use_count++;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
if (use_count != input_use_count && node->op != GGML_OP_NONE) {
|
|
669
|
+
return true;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
// if all nodes's src node's src is not come from the nodes in the model, we think the model is splitted. This is a complementary check for the above check, because for some special case like the output node is not used by any node, the use count and input use count are both 0, we can not determine whether the model is splitted or not just based on the first check.
|
|
673
|
+
auto model_weights = GgmlOvDecoder::create_weight_nodes(cgraph, true);
|
|
674
|
+
std::set<ggml_tensor *> model_nodes(cgraph->nodes, cgraph->nodes + cgraph->n_nodes);
|
|
675
|
+
// leaf nodes
|
|
676
|
+
std::set<ggml_tensor *> model_leafs(cgraph->leafs, cgraph->leafs + cgraph->n_leafs);
|
|
677
|
+
for (int i = 0; i < cgraph->n_nodes; i++) {
|
|
678
|
+
ggml_tensor * node = cgraph->nodes[i];
|
|
679
|
+
for (int j = 0; j < GGML_MAX_SRC; j++) {
|
|
680
|
+
ggml_tensor * src = node->src[j];
|
|
681
|
+
// the src is also not the model weights, we think the model is splitted.
|
|
682
|
+
// the src is also not in model leafs, we think the model is splitted.
|
|
683
|
+
if (src != nullptr && model_nodes.find(src) == model_nodes.end() &&
|
|
684
|
+
model_weights.find(std::string(src->name)) == model_weights.end() && !model_leafs.empty() == false &&
|
|
685
|
+
model_leafs.find(src) == model_leafs.end()) {
|
|
686
|
+
if (GgmlOvDecoder::is_inp_tok(src, node)) {
|
|
687
|
+
return false;
|
|
688
|
+
}
|
|
689
|
+
return true;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
return false;
|
|
694
|
+
}
|
|
695
|
+
|
|
530
696
|
bool is_naive(ggml_cgraph * cgraph) {
|
|
531
697
|
constexpr int naive_graph_size_threshold = 20;
|
|
532
698
|
int count = 0;
|
|
@@ -551,7 +717,7 @@ enum ggml_status naive_compute(ggml_cgraph * cgraph,
|
|
|
551
717
|
auto decoder = std::make_shared<GgmlOvDecoder>(cgraph, model_weights);
|
|
552
718
|
auto input_model = std::make_shared<ov::frontend::ggml::InputModel>(decoder);
|
|
553
719
|
auto model = ov::frontend::ggml::FrontEnd::convert(input_model, naive);
|
|
554
|
-
if (
|
|
720
|
+
if (ggml_openvino_getenv_int("GGML_OPENVINO_DUMP_IR")) {
|
|
555
721
|
ov::serialize(model, "IR_naive.xml");
|
|
556
722
|
}
|
|
557
723
|
|
|
@@ -578,40 +744,92 @@ enum ggml_status naive_compute(ggml_cgraph * cgraph,
|
|
|
578
744
|
infer_request->set_input_tensor(i, input_tensor);
|
|
579
745
|
}
|
|
580
746
|
|
|
747
|
+
// Use get_output_tensor + memcpy instead of set_output_tensor to avoid memory overwritten
|
|
748
|
+
// when i/o buffer overlaps, e.g. the cgraph is a single PERMUTE
|
|
749
|
+
|
|
750
|
+
infer_request->infer();
|
|
751
|
+
|
|
581
752
|
auto ov_results = model->get_results();
|
|
582
753
|
for (size_t i = 0; i < ov_results.size(); i++) {
|
|
754
|
+
auto output_tensor = infer_request->get_output_tensor(i);
|
|
583
755
|
auto * ggml_tensor = decoder->get_model_outputs().at(ov_results[i]->get_friendly_name());
|
|
584
|
-
|
|
585
|
-
infer_request->set_output_tensor(i, output_tensor);
|
|
756
|
+
std::memcpy(ggml_tensor->data, output_tensor.data(), output_tensor.get_byte_size());
|
|
586
757
|
}
|
|
587
|
-
|
|
588
|
-
infer_request->infer();
|
|
589
758
|
return GGML_STATUS_SUCCESS;
|
|
590
759
|
}
|
|
591
760
|
|
|
592
761
|
namespace {
|
|
762
|
+
template <typename T> void set_zero_diagonal(std::vector<T> & matrix, size_t rows, size_t cols, T zero_value = T{}) {
|
|
763
|
+
for (size_t i = 0; i < rows; ++i) {
|
|
764
|
+
size_t diag_col = std::min(i, cols - 1);
|
|
765
|
+
matrix[i * cols + diag_col] = zero_value;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
ov::Tensor make_contiguous_split_input_tensor(std::shared_ptr<GgmlOvDecoder> ggml_decoder,
|
|
770
|
+
const struct ggml_tensor * ggml_tensor,
|
|
771
|
+
const ov::Shape & input_shape) {
|
|
772
|
+
const size_t element_size = ggml_type_size(ggml_tensor->type);
|
|
773
|
+
const size_t block_size = ggml_blck_size(ggml_tensor->type);
|
|
774
|
+
|
|
775
|
+
GGML_ASSERT(block_size == 1 && "non-contiguous split inputs must be plain element types");
|
|
776
|
+
|
|
777
|
+
const struct ggml_tensor * source_tensor = ggml_tensor->view_src != nullptr ? ggml_tensor->view_src : ggml_tensor;
|
|
778
|
+
const size_t source_offset = ggml_tensor->view_src != nullptr ? ggml_tensor->view_offs : 0;
|
|
779
|
+
|
|
780
|
+
std::vector<uint8_t> source_data(ggml_nbytes(source_tensor));
|
|
781
|
+
ggml_backend_tensor_get(source_tensor, source_data.data(), 0, source_data.size());
|
|
782
|
+
|
|
783
|
+
ov::Tensor input_tensor(ggml_decoder->get_ov_type(ggml_tensor), input_shape);
|
|
784
|
+
auto * dst = static_cast<uint8_t *>(input_tensor.data());
|
|
785
|
+
size_t dst_offset = 0;
|
|
786
|
+
|
|
787
|
+
for (size_t i3 = 0; i3 < static_cast<size_t>(ggml_tensor->ne[3]); ++i3) {
|
|
788
|
+
for (size_t i2 = 0; i2 < static_cast<size_t>(ggml_tensor->ne[2]); ++i2) {
|
|
789
|
+
for (size_t i1 = 0; i1 < static_cast<size_t>(ggml_tensor->ne[1]); ++i1) {
|
|
790
|
+
for (size_t i0 = 0; i0 < static_cast<size_t>(ggml_tensor->ne[0]); ++i0) {
|
|
791
|
+
const size_t src_offset = source_offset + i3 * ggml_tensor->nb[3] + i2 * ggml_tensor->nb[2] +
|
|
792
|
+
i1 * ggml_tensor->nb[1] + i0 * ggml_tensor->nb[0];
|
|
793
|
+
std::memcpy(dst + dst_offset, source_data.data() + src_offset, element_size);
|
|
794
|
+
dst_offset += element_size;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
return input_tensor;
|
|
801
|
+
}
|
|
802
|
+
|
|
593
803
|
ov::Tensor convert_ggml_input_to_ov(std::shared_ptr<GgmlOvDecoder> ggml_decoder, const std::string & name) {
|
|
594
804
|
const auto * ggml_tensor = ggml_decoder->get_input_ggml_tensor(name);
|
|
595
805
|
|
|
596
|
-
if (
|
|
597
|
-
|
|
806
|
+
if (auto sliced = try_make_kv_sliced_tensor(ggml_decoder, name, ggml_tensor)) {
|
|
807
|
+
return *sliced;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
if (ggml_tensor->extra != nullptr && !ggml_decoder->is_splited_model()) {
|
|
598
811
|
auto * extra_base = static_cast<ggml_openvino_extra_base *>(ggml_tensor->extra);
|
|
599
|
-
if (extra_base->type
|
|
600
|
-
|
|
812
|
+
if (extra_base->type == ggml_openvino_extra_base::Type::TENSOR) {
|
|
813
|
+
// GGML_LOG_DEBUG("Using ggml_tensor->extra as ov::Tensor for input: %s\n", name.c_str());
|
|
814
|
+
auto * tensor_extra = static_cast<ggml_openvino_tensor_extra *>(extra_base);
|
|
815
|
+
return *tensor_extra->tensor;
|
|
601
816
|
}
|
|
602
|
-
auto * tensor_extra = static_cast<ggml_openvino_tensor_extra *>(extra_base);
|
|
603
|
-
return *tensor_extra->tensor;
|
|
604
817
|
}
|
|
605
818
|
|
|
606
819
|
// GGML_LOG_DEBUG("Converting ggml tensor to ov::Tensor for input: %s\n", name.c_str());
|
|
607
820
|
auto * input_data = ggml_tensor->data;
|
|
608
821
|
ov::Shape input_shape;
|
|
609
|
-
if (ggml_tensor->op == GGML_OP_VIEW) {
|
|
822
|
+
if (ggml_tensor->op == GGML_OP_VIEW && !ggml_decoder->is_splited_model()) {
|
|
610
823
|
// This case is added to make test-backend-ops work
|
|
611
824
|
input_shape = ggml_decoder->get_shape(ggml_tensor->view_src);
|
|
612
825
|
} else {
|
|
613
826
|
input_shape = ggml_decoder->get_shape(ggml_tensor);
|
|
614
827
|
}
|
|
828
|
+
|
|
829
|
+
if (ggml_decoder->is_splited_model() && !ggml_is_contiguous(ggml_tensor)) {
|
|
830
|
+
return make_contiguous_split_input_tensor(ggml_decoder, ggml_tensor, input_shape);
|
|
831
|
+
}
|
|
832
|
+
|
|
615
833
|
auto input_tensor = ov::Tensor(ggml_decoder->get_ov_type(ggml_tensor), input_shape, input_data);
|
|
616
834
|
return input_tensor;
|
|
617
835
|
}
|
|
@@ -660,6 +878,14 @@ ov::Tensor get_ov_input_tensor_static_decode(std::shared_ptr<GgmlOvDecoder> ggml
|
|
|
660
878
|
|
|
661
879
|
if (GgmlOvDecoder::is_inp_mask(ggml_tensor, op)) {
|
|
662
880
|
size_t context_size = ggml_decoder->get_ctx_size();
|
|
881
|
+
if (ggml_tensor->type == GGML_TYPE_F16) {
|
|
882
|
+
std::vector<ggml_fp16_t> padded_data =
|
|
883
|
+
pad_input<ggml_fp16_t>(ggml_tensor, 1, context_size, GGML_FP32_TO_FP16(-INFINITY));
|
|
884
|
+
ov::Tensor input_tensor(ov::element::f16, ov::Shape{1, 1, 1, context_size});
|
|
885
|
+
std::memcpy(input_tensor.data(), padded_data.data(), padded_data.size() * sizeof(ggml_fp16_t));
|
|
886
|
+
return input_tensor;
|
|
887
|
+
}
|
|
888
|
+
|
|
663
889
|
std::vector<float> padded_data = pad_input<float>(ggml_tensor, 1, context_size, -INFINITY);
|
|
664
890
|
ov::Tensor input_tensor(ov::element::f32, ov::Shape{1, 1, 1, context_size});
|
|
665
891
|
auto * data_ptr = input_tensor.data<float>();
|
|
@@ -728,9 +954,20 @@ ov::Tensor get_ov_input_tensor_static_prefill(std::shared_ptr<GgmlOvDecoder> ggm
|
|
|
728
954
|
if (GgmlOvDecoder::is_inp_mask(ggml_tensor, op)) {
|
|
729
955
|
size_t cols = ggml_tensor->ne[0];
|
|
730
956
|
size_t rows = ggml_tensor->ne[1];
|
|
731
|
-
float * ggml_data = (float *) ggml_tensor->data + chunk_index * chunk_size * cols;
|
|
732
957
|
size_t chunk_valid_rows = std::min(chunk_size, rows - chunk_index * chunk_size);
|
|
733
958
|
size_t context_size = ggml_decoder->get_ctx_size();
|
|
959
|
+
if (ggml_tensor->type == GGML_TYPE_F16) {
|
|
960
|
+
const auto * ggml_data =
|
|
961
|
+
static_cast<const ggml_fp16_t *>(ggml_tensor->data) + chunk_index * chunk_size * cols;
|
|
962
|
+
std::vector<ggml_fp16_t> padded_data = pad_input<ggml_fp16_t>(ggml_data, chunk_valid_rows, cols, chunk_size,
|
|
963
|
+
context_size, GGML_FP32_TO_FP16(-INFINITY));
|
|
964
|
+
set_zero_diagonal(padded_data, chunk_size, context_size, GGML_FP32_TO_FP16(0.0f));
|
|
965
|
+
ov::Tensor input_tensor(ov::element::f16, ov::Shape{1, 1, chunk_size, context_size});
|
|
966
|
+
std::memcpy(input_tensor.data(), padded_data.data(), padded_data.size() * sizeof(ggml_fp16_t));
|
|
967
|
+
return input_tensor;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
const auto * ggml_data = static_cast<const float *>(ggml_tensor->data) + chunk_index * chunk_size * cols;
|
|
734
971
|
std::vector<float> padded_data =
|
|
735
972
|
pad_input<float>(ggml_data, chunk_valid_rows, cols, chunk_size, context_size, -INFINITY);
|
|
736
973
|
set_zero_diagonal(padded_data, chunk_size, context_size);
|
|
@@ -753,6 +990,65 @@ size_t checksum(const void * data, size_t size) {
|
|
|
753
990
|
return sum;
|
|
754
991
|
}
|
|
755
992
|
|
|
993
|
+
bool save_ggml_tensor_data_to_txt(const ggml_tensor * tensor, const std::string & file_path) {
|
|
994
|
+
if (tensor == nullptr || tensor->data == nullptr) {
|
|
995
|
+
return false;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
std::ofstream out(file_path);
|
|
999
|
+
if (!out.is_open()) {
|
|
1000
|
+
return false;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
const size_t n = ggml_nelements(tensor);
|
|
1004
|
+
out << "name: " << tensor->name << ", type: " << ggml_type_name(tensor->type) << ", shape: [" << tensor->ne[0]
|
|
1005
|
+
<< ", " << tensor->ne[1] << ", " << tensor->ne[2] << ", " << tensor->ne[3] << "]" << ", elements: " << n
|
|
1006
|
+
<< ", data:" << '\n';
|
|
1007
|
+
|
|
1008
|
+
switch (tensor->type) {
|
|
1009
|
+
case GGML_TYPE_F32: {
|
|
1010
|
+
const auto * data = static_cast<const float *>(tensor->data);
|
|
1011
|
+
for (size_t i = 0; i < n; ++i) {
|
|
1012
|
+
out << data[i] << '\n';
|
|
1013
|
+
}
|
|
1014
|
+
break;
|
|
1015
|
+
}
|
|
1016
|
+
case GGML_TYPE_F16: {
|
|
1017
|
+
const auto * data = static_cast<const ggml_fp16_t *>(tensor->data);
|
|
1018
|
+
for (size_t i = 0; i < n; ++i) {
|
|
1019
|
+
out << ggml_fp16_to_fp32(data[i]) << '\n';
|
|
1020
|
+
}
|
|
1021
|
+
break;
|
|
1022
|
+
}
|
|
1023
|
+
case GGML_TYPE_BF16: {
|
|
1024
|
+
const auto * data = static_cast<const ggml_bf16_t *>(tensor->data);
|
|
1025
|
+
for (size_t i = 0; i < n; ++i) {
|
|
1026
|
+
out << ggml_bf16_to_fp32(data[i]) << '\n';
|
|
1027
|
+
}
|
|
1028
|
+
break;
|
|
1029
|
+
}
|
|
1030
|
+
case GGML_TYPE_I32: {
|
|
1031
|
+
const auto * data = static_cast<const int32_t *>(tensor->data);
|
|
1032
|
+
for (size_t i = 0; i < n; ++i) {
|
|
1033
|
+
out << data[i] << '\n';
|
|
1034
|
+
}
|
|
1035
|
+
break;
|
|
1036
|
+
}
|
|
1037
|
+
case GGML_TYPE_I64: {
|
|
1038
|
+
const auto * data = static_cast<const int64_t *>(tensor->data);
|
|
1039
|
+
for (size_t i = 0; i < n; ++i) {
|
|
1040
|
+
out << data[i] << '\n';
|
|
1041
|
+
}
|
|
1042
|
+
break;
|
|
1043
|
+
}
|
|
1044
|
+
default:
|
|
1045
|
+
out << "unsupported tensor type for text dump" << '\n';
|
|
1046
|
+
return false;
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
return true;
|
|
1050
|
+
}
|
|
1051
|
+
|
|
756
1052
|
void print_input_tensor_info(const std::string & name, const ov::Tensor & tensor) {
|
|
757
1053
|
std::cout << "Input name: " << name << ", Input shape: " << tensor.get_shape() << ", Address: " << tensor.data()
|
|
758
1054
|
<< std::endl;
|
|
@@ -849,13 +1145,6 @@ void print_output_tensor_info(const std::string & name, const ov::Tensor & tenso
|
|
|
849
1145
|
}
|
|
850
1146
|
}
|
|
851
1147
|
|
|
852
|
-
void set_zero_diagonal(std::vector<float> & matrix, size_t rows, size_t cols) {
|
|
853
|
-
for (size_t i = 0; i < rows; ++i) {
|
|
854
|
-
size_t diag_col = std::min(i, cols - 1);
|
|
855
|
-
matrix[i * cols + diag_col] = 0.0f;
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
|
|
859
1148
|
const ggml_tensor * get_inp_pos_tensor(ggml_cgraph * cgraph) {
|
|
860
1149
|
for (int i = 0; i < cgraph->n_nodes; ++i) {
|
|
861
1150
|
auto * op = cgraph->nodes[i];
|