From d4f5c26049774bb786276eb517f1e6b070d28ff4 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Thu, 19 Nov 2026 14:11:44 +0800 Subject: [PATCH 01/40] CUDA: use 64-bit dst offsets in mul_mat_q (#32374) The MMQ kernels computed the dst tile offset (jt*J*stride_col_dst) in 32-bit int. For a dst with more than 2^31 elements, column tiles that start past INT_MAX/nrows wrap around and write out of bounds. This happens with an all-logits output head, e.g. llama-perplexity -c 32768 -b 32768 -ub 16384 on a 248320-vocab model: the q8_0 output matmul has a 248320 x 16384 dst (4.07e9 elements) and aborts with an illegal memory access. Widen the offsets in mul_mat_q and the stream-k fixup to int64_t, and add a (disabled by default, ~9 GB) test-backend-ops case. Assisted-by: Claude Opus 5.5 --- ggml/src/ggml-cuda/mmq.cuh | 8 ++++---- tests/test-backend-ops.cpp | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ggml/src/ggml-cuda/mmq.cuh b/ggml/src/ggml-cuda/mmq.cuh index 7fb09a353786..be2f11430079 100644 --- a/ggml/src/ggml-cuda/mmq.cuh +++ b/ggml/src/ggml-cuda/mmq.cuh @@ -1094,7 +1094,7 @@ static __global__ void mul_mat_q( int col_high = min(col_low + J, ncols_dst); int offset_y = wt*stride_sample_y + zt*stride_channel_y; int offset_y_scale = wt*nchannels_y.z*ncols_y + zt*ncols_y; - int offset_dst = wt*stride_sample_dst + zt*stride_channel_dst + jt*J*stride_col_dst; + int64_t offset_dst = (int64_t) wt*stride_sample_dst + (int64_t) zt*stride_channel_dst + (int64_t) jt*J*stride_col_dst; if (ids_dst) { const ggml_cuda_mm_id_tile_spec tsj = tile_spec[jt]; @@ -1176,7 +1176,7 @@ static __global__ void mul_mat_q( int col_high = min(col_low + J, ncols_dst); int offset_y = wt*stride_sample_y + zt*stride_channel_y; int offset_y_scale = wt*nchannels_y.z*ncols_y + zt*ncols_y; - int offset_dst = wt*stride_sample_dst + zt*stride_channel_dst + jt*J*stride_col_dst; + int64_t offset_dst = (int64_t) wt*stride_sample_dst + (int64_t) zt*stride_channel_dst + (int64_t) jt*J*stride_col_dst; if (ids_dst) { const ggml_cuda_mm_id_tile_spec tsj = tile_spec[jt]; @@ -1257,7 +1257,7 @@ static __global__ void mul_mat_q( int col_high = min(col_low + J, ncols_dst); int offset_y = wt*stride_sample_y + zt*stride_channel_y; int offset_y_scale = wt*nchannels_y.z*ncols_y + zt*ncols_y; - int offset_dst = wt*stride_sample_dst + zt*stride_channel_dst + jt*J*stride_col_dst; + int64_t offset_dst = (int64_t) wt*stride_sample_dst + (int64_t) zt*stride_channel_dst + (int64_t) jt*J*stride_col_dst; if (ids_dst) { const ggml_cuda_mm_id_tile_spec tsj = tile_spec[jt]; @@ -1403,7 +1403,7 @@ static __global__ void mul_mat_q_stream_k_fixup( const int it = tmp2.x; if (!ids_dst) { - const int offset_dst = wt*stride_sample_dst + zt*stride_channel_dst + jt*J*stride_col_dst + it*I; + const int64_t offset_dst = (int64_t) wt*stride_sample_dst + (int64_t) zt*stride_channel_dst + (int64_t) jt*J*stride_col_dst + it*I; dst += offset_dst; const int i_max = nrows_x - it*I - 1; diff --git a/tests/test-backend-ops.cpp b/tests/test-backend-ops.cpp index b20e0d3fe76e..b001c79d152a 100644 --- a/tests/test-backend-ops.cpp +++ b/tests/test-backend-ops.cpp @@ -11917,6 +11917,9 @@ static std::vector> make_test_cases_eval() { // > 2^31-element dst (8.9 GB), about 45 GB peak memory. Too large to be enabled by default. // kernel_mul_mm dst offset of the last batch is past INT32_MAX: rows 0-31 use full tiles, rows 32-39 use edge tiles. test_cases.emplace_back(new test_mul_mat(GGML_TYPE_F32, GGML_TYPE_F32, 1048576, 40, 64, {1, 1}, {53, 1})); + // CUDA mul_mat_q: > 2^31-element dst (8.9 GB), the dst offset of column tiles starting past column 8648 does not fit in 32 bits + // (same shape class as a 248k-vocab output head with a 16k ubatch of outputs) + test_cases.emplace_back(new test_mul_mat(GGML_TYPE_Q8_0, GGML_TYPE_F32, 248320, 8960, 32, {1, 1}, {1, 1})); // kernel_mul_mm_id: the index of tokens 32768-33791 does not fit in 16 bits (about 0.3 GB peak memory). test_cases.emplace_back(new test_mul_mat_id(GGML_TYPE_F32, GGML_TYPE_F32, 4, 2, false, 64, 33792, 64)); From ecafc67145201e59336bf389d0ab1a91b89a8fac Mon Sep 17 00:00:00 2001 From: Daniil Sterkhov Date: Wed, 18 Nov 2026 23:13:06 -0700 Subject: [PATCH 02/40] vulkan: use floating-point zero for storage-only FP16 in DIAG/TRI (#32379) * vulkan: Change integer zero to floating-point zero for storage-only FP16 in DIAG/TRI. Assisted-by: OpenAI Codex * delete narrow test --- ggml/src/ggml-vulkan/vulkan-shaders/diag.comp | 2 +- ggml/src/ggml-vulkan/vulkan-shaders/tri.comp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ggml/src/ggml-vulkan/vulkan-shaders/diag.comp b/ggml/src/ggml-vulkan/vulkan-shaders/diag.comp index 790a5421d08f..8a9b219e6d72 100644 --- a/ggml/src/ggml-vulkan/vulkan-shaders/diag.comp +++ b/ggml/src/ggml-vulkan/vulkan-shaders/diag.comp @@ -22,6 +22,6 @@ void main() { if (i10 == i11) { data_d[get_doffset() + dst_idx(idx)] = D_TYPE(data_a[get_aoffset() + i13*p.nb03 + i12*p.nb02 + 0*p.nb01 + i10*p.nb00]); } else { - data_d[get_doffset() + dst_idx(idx)] = D_TYPE(0); + data_d[get_doffset() + dst_idx(idx)] = D_TYPE(0.0); } } diff --git a/ggml/src/ggml-vulkan/vulkan-shaders/tri.comp b/ggml/src/ggml-vulkan/vulkan-shaders/tri.comp index 2585540af181..d77139aefc3e 100644 --- a/ggml/src/ggml-vulkan/vulkan-shaders/tri.comp +++ b/ggml/src/ggml-vulkan/vulkan-shaders/tri.comp @@ -36,6 +36,6 @@ void main() { if (pass) { data_d[get_doffset() + dst_idx(idx)] = D_TYPE(data_a[get_aoffset() + src0_idx(idx)]); } else { - data_d[get_doffset() + dst_idx(idx)] = D_TYPE(0); + data_d[get_doffset() + dst_idx(idx)] = D_TYPE(0.0); } } From 573aa89de6b6912b7433c4da20a013f743dd1009 Mon Sep 17 00:00:00 2001 From: Jeff Bolz Date: Thu, 19 Nov 2026 00:14:14 -0600 Subject: [PATCH 03/40] vulkan: Implement stream-k MUL_MAT (#28528) * vulkan: Implement stream-k MUL_MAT Stream-k tries to split chunks of 256 K elements evenly across all SMs. Workgroups that finish a tile write to dst, others write to scratch, and there's a resolve shader similar to split-k. The shader code is implemented for scalar+cm1+cm2, but only currently enabled for cm2. The heuristic for enabling on coopmat2 is pretty simple due to the large tile size (one workgroup per SM), but would be more complex for the tile sizes being used for cm1, and it doesn't make sense for me to tune that on NVIDIA devices. Assisted-by: Codex * address review feedback --- ggml/src/ggml-vulkan/ggml-vulkan-common.h | 2 +- ggml/src/ggml-vulkan/ggml-vulkan-debug.cpp | 6 +- .../ggml-vulkan/ggml-vulkan-push-constants.h | 58 ++++ ggml/src/ggml-vulkan/ggml-vulkan-types.h | 8 +- ggml/src/ggml-vulkan/ggml-vulkan.cpp | 247 +++++++++++++++--- .../mul_mat_stream_k_fixup.comp | 86 ++++++ .../ggml-vulkan/vulkan-shaders/mul_mm.comp | 183 +++++++++---- .../vulkan-shaders/mul_mm_cm2.comp | 162 +++++++++--- .../vulkan-shaders/vulkan-shaders-gen.cpp | 1 + tests/test-backend-ops.cpp | 6 + 10 files changed, 622 insertions(+), 137 deletions(-) create mode 100644 ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_stream_k_fixup.comp diff --git a/ggml/src/ggml-vulkan/ggml-vulkan-common.h b/ggml/src/ggml-vulkan/ggml-vulkan-common.h index 69028c04251b..ea3b3b4b8772 100644 --- a/ggml/src/ggml-vulkan/ggml-vulkan-common.h +++ b/ggml/src/ggml-vulkan/ggml-vulkan-common.h @@ -101,7 +101,7 @@ void deferred_memset(void * dst, uint32_t val, size_t size, std::vectorprealloc_split_k), m, n, k, k, k, m, k*m, k*n, m*n, - split_k, batch, batch, batch, 1, 1, n, + split_k, 0, batch, batch, batch, 1, 1, n, k * sizeof(Y_TYPE), m * sizeof(float) ); } @@ -693,7 +693,7 @@ void ggml_vk_test_dequant_matmul(ggml_backend_vk_context * ctx, size_t m, size_t ctx, subctx, p, { qx_buf, 0, qx_sz }, { qy_buf, 0, qy_sz }, { d_buf, 0, d_sz }, { ctx->prealloc_split_k, 0, ctx->prealloc_size_split_k }, m, n, k, k, k, m, k*m, k*n, m*n, - split_k, batch, batch, batch, 1, 1, n, + split_k, 0, batch, batch, batch, 1, 1, n, (uint64_t)(k / ggml_blck_size(GGML_TYPE_Q8_1)) * ggml_type_size(GGML_TYPE_Q8_1), m * sizeof(float) ); } @@ -703,7 +703,7 @@ void ggml_vk_test_dequant_matmul(ggml_backend_vk_context * ctx, size_t m, size_t ctx, subctx, p, { qx_buf, 0, qx_sz }, { y_buf, 0, y_sz }, { d_buf, 0, d_sz }, { ctx->prealloc_split_k, 0, ctx->prealloc_size_split_k }, m, n, k, k, k, m, k*m, k*n, m*n, - split_k, batch, batch, batch, 1, 1, n, + split_k, 0, batch, batch, batch, 1, 1, n, k * sizeof(float), m * sizeof(float) ); } diff --git a/ggml/src/ggml-vulkan/ggml-vulkan-push-constants.h b/ggml/src/ggml-vulkan/ggml-vulkan-push-constants.h index caa852e28bf7..176dbb72ad21 100644 --- a/ggml/src/ggml-vulkan/ggml-vulkan-push-constants.h +++ b/ggml/src/ggml-vulkan/ggml-vulkan-push-constants.h @@ -13,8 +13,38 @@ struct vk_mat_mat_push_constants { uint32_t k_split; uint32_t ne02; uint32_t ne12; uint32_t broadcast2; uint32_t broadcast3; uint32_t padded_N; + uint32_t k_units_per_tile; + uint32_t work_units_per_group; + uint32_t groups_with_extra_unit; + uint32_t k_units_mp; + uint32_t blocks_m_mp; + uint32_t blocks_n_mp; + uint32_t ne12_mp; + uint32_t broadcast2_mp; + uint32_t broadcast3_mp; + uint32_t div_Ls0; + uint32_t div_Ls1; }; +struct vk_mat_mat_stream_k_fixup_push_constants { + uint32_t M; uint32_t N; + uint32_t BM; uint32_t BN; + uint32_t k_units_per_tile; + uint32_t blocks_m; + uint32_t blocks_n; + uint32_t work_units_per_group; + uint32_t groups_with_extra_unit; + uint32_t k_units_mp; + uint32_t blocks_m_mp; + uint32_t blocks_n_mp; + uint32_t work_units_mp; + uint32_t large_group_work_mp; + uint32_t div_Ls0; + uint32_t div_Ls1; +}; + +static_assert(sizeof(vk_mat_mat_push_constants) <= 128); + struct vk_mat_vec_push_constants { uint32_t ncols; uint32_t stride_a; @@ -403,6 +433,34 @@ template void init_pushconst_fastdiv(T &p) { static_assert(!std::is_const::value, "unexpected type"); } +inline void init_pushconst_fastdiv(vk_mat_mat_push_constants &p) { + uint32_t ne12_L, broadcast2_L, broadcast3_L; + init_fastdiv_values(p.ne12, p.ne12_mp, ne12_L); + init_fastdiv_values(p.broadcast2, p.broadcast2_mp, broadcast2_L); + init_fastdiv_values(p.broadcast3, p.broadcast3_mp, broadcast3_L); + p.div_Ls1 = pack_fastdiv_L(ne12_L, broadcast2_L, broadcast3_L); +} + +inline void init_pushconst_fastdiv(vk_mat_mat_push_constants &p, uint32_t blocks_m, uint32_t blocks_n) { + uint32_t k_units_L, blocks_m_L, blocks_n_L; + init_fastdiv_values(p.k_units_per_tile, p.k_units_mp, k_units_L); + init_fastdiv_values(blocks_m, p.blocks_m_mp, blocks_m_L); + init_fastdiv_values(blocks_n, p.blocks_n_mp, blocks_n_L); + p.div_Ls0 = pack_fastdiv_L(k_units_L, blocks_m_L, blocks_n_L); + init_pushconst_fastdiv(p); +} + +template <> inline void init_pushconst_fastdiv(vk_mat_mat_stream_k_fixup_push_constants &p) { + uint32_t k_units_L, blocks_m_L, blocks_n_L, work_units_L, large_group_work_L; + init_fastdiv_values(p.k_units_per_tile, p.k_units_mp, k_units_L); + init_fastdiv_values(p.blocks_m, p.blocks_m_mp, blocks_m_L); + init_fastdiv_values(p.blocks_n, p.blocks_n_mp, blocks_n_L); + init_fastdiv_values(p.work_units_per_group, p.work_units_mp, work_units_L); + init_fastdiv_values(p.work_units_per_group + 1, p.large_group_work_mp, large_group_work_L); + p.div_Ls0 = pack_fastdiv_L(k_units_L, blocks_m_L, blocks_n_L); + p.div_Ls1 = pack_fastdiv_L(work_units_L, large_group_work_L, 0); +} + template <> inline void init_pushconst_fastdiv(vk_op_unary_push_constants &p) { // Compute magic values to divide by these six numbers. uint32_t ne0_012L; diff --git a/ggml/src/ggml-vulkan/ggml-vulkan-types.h b/ggml/src/ggml-vulkan/ggml-vulkan-types.h index 54c7a36909e4..f976c579582c 100644 --- a/ggml/src/ggml-vulkan/ggml-vulkan-types.h +++ b/ggml/src/ggml-vulkan/ggml-vulkan-types.h @@ -259,10 +259,11 @@ struct vk_matmul_pipeline_key { ggml_type type_b; bool mul_mat_id; bool f16acc; + bool stream_k = false; bool operator<(const vk_matmul_pipeline_key & o) const { - return std::tie(type_a, type_b, mul_mat_id, f16acc) - < std::tie(o.type_a, o.type_b, o.mul_mat_id, o.f16acc); + return std::tie(type_a, type_b, mul_mat_id, f16acc, stream_k) + < std::tie(o.type_a, o.type_b, o.mul_mat_id, o.f16acc, o.stream_k); } }; @@ -819,6 +820,7 @@ struct vk_device_struct { matmul_tile_selector_t matmul_id_tile_selector; vk_pipeline pipeline_matmul_split_k_reduce; + vk_pipeline pipeline_matmul_stream_k_fixup; vk_pipeline pipeline_quantize_q8_1_x4; vk_pipeline pipeline_dequant[GGML_TYPE_COUNT]; @@ -1023,6 +1025,8 @@ struct vk_device_struct { std::map fusion_counts; bool disable_descriptor_reuse; std::atomic buffer_destroy_count {}; + bool disable_stream_k; + bool force_stream_k; bool disable_host_visible_vidmem; bool allow_sysmem_fallback; bool disable_graph_optimize; diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vulkan.cpp index 616a17c4c8c4..e279693cb837 100644 --- a/ggml/src/ggml-vulkan/ggml-vulkan.cpp +++ b/ggml/src/ggml-vulkan/ggml-vulkan.cpp @@ -2467,6 +2467,7 @@ void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) { FOR_EACH_LUT_FP4_TYPE(X) const int mul_mat_id_param_count = 5; + constexpr uint32_t stream_k_spec_id = 15; using spec_fn_t = std::function(const std::vector&, bool)>; auto const &create_mm_pipelines = [&]( @@ -2478,6 +2479,11 @@ void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) { bool disable_robustness = false, bool require_full_subgroups = false, uint32_t required_subgroup_size = 0, bool create_aligned = true, bool pin_subgroup_to_warp = false ) { + GGML_ASSERT(!key.stream_k || (!key.mul_mat_id && param_count == 3 && push_constant_size == sizeof(vk_mat_mat_push_constants) && create_aligned)); + // Non-ID matmul shaders declare the Stream-K scratch binding in all specializations. + if (!key.mul_mat_id) { + ++param_count; + } auto& vec = device->pipeline_matmul[key]; const bool first_call = vec.empty(); for (size_t i = 0; i < tile_configs.size(); i++) { @@ -2495,25 +2501,40 @@ void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) { vk_matmul_pipeline_pair pair{}; pair.align = tc.align; pair.narrow_n_max = tc.narrow_n_max; - std::string suffix = "_" + std::to_string(i); - pair.unaligned = std::make_shared(); + if (!key.stream_k) { + pair.unaligned = std::make_shared(); + } if (create_aligned) { pair.aligned = std::make_shared(); } + if (key.stream_k) { + // Tile selection reads unaligned even when selecting an aligned pipeline. + pair.unaligned = pair.aligned; + } vec.push_back(pair); } - ggml_vk_create_pipeline(device, vec[i].unaligned, - vec[i].unaligned->name.empty() ? (shader_name + "_" + std::to_string(i)).c_str() : vec[i].unaligned->name.c_str(), - spv_len, spv_data, "main", param_count, push_constant_size, - tc.wg_denoms, spec_fn(tc.warptile, false), 1, - disable_robustness, rfs, rsgs); + if (!key.stream_k) { + ggml_vk_create_pipeline(device, vec[i].unaligned, + vec[i].unaligned->name.empty() ? (shader_name + "_" + std::to_string(i)).c_str() : vec[i].unaligned->name.c_str(), + spv_len, spv_data, "main", param_count, push_constant_size, + tc.wg_denoms, spec_fn(tc.warptile, false), 1, + disable_robustness, rfs, rsgs); + } if (vec[i].aligned) { + auto spec = spec_fn(tc.warptile, true); + if (key.stream_k) { + if (spec.size() <= stream_k_spec_id) { + spec.resize(stream_k_spec_id + 1); + } + spec[stream_k_spec_id] = 1; + } + const std::string name = shader_name + (key.stream_k ? "_stream_k_" : "_aligned_") + std::to_string(i); ggml_vk_create_pipeline(device, vec[i].aligned, - vec[i].aligned->name.empty() ? (shader_name + "_aligned_" + std::to_string(i)).c_str() : vec[i].aligned->name.c_str(), + vec[i].aligned->name.empty() ? name.c_str() : vec[i].aligned->name.c_str(), spv_len, spv_data, "main", param_count, push_constant_size, - tc.wg_denoms, spec_fn(tc.warptile, true), tc.align, + tc.wg_denoms, spec, tc.align, disable_robustness, rfs, rsgs); } } @@ -2611,13 +2632,19 @@ void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) { } spec_fn_t cm2_spec = [&](const std::vector& wt, bool a) { return ggml_vk_mul_mm_cm2_spec(wt, a); }; + auto create_cm2_pipelines = [&](vk_matmul_pipeline_key key, const std::vector& tc, + const std::string& name, size_t len, const void* data, uint32_t pc_size, uint32_t pc, const spec_fn_t& spec) { + create_mm_pipelines(key, tc, name, len, data, pc_size, pc, spec, true); + key.stream_k = true; + create_mm_pipelines(key, tc, name, len, data, pc_size, pc, spec, true); + }; // F16 x F16 - create_mm_pipelines({GGML_TYPE_F16, GGML_TYPE_F16, false, true}, tc_mm, "matmul_f16_f16acc", matmul_f16_f16acc_cm2_len, matmul_f16_f16acc_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec, true); - create_mm_pipelines({GGML_TYPE_F16, GGML_TYPE_F16, false, false}, tc_mm, "matmul_f16", matmul_f16_cm2_len, matmul_f16_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec, true); + create_cm2_pipelines({GGML_TYPE_F16, GGML_TYPE_F16, false, true}, tc_mm, "matmul_f16_f16acc", matmul_f16_f16acc_cm2_len, matmul_f16_f16acc_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec); + create_cm2_pipelines({GGML_TYPE_F16, GGML_TYPE_F16, false, false}, tc_mm, "matmul_f16", matmul_f16_cm2_len, matmul_f16_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec); #if defined(GGML_VULKAN_BFLOAT16_GLSLC_SUPPORT) if (device->coopmat_bf16_support) { - create_mm_pipelines({GGML_TYPE_BF16, GGML_TYPE_BF16, false, false}, tc_mm, "matmul_bf16", matmul_bf16_cm2_len, matmul_bf16_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec, true); + create_cm2_pipelines({GGML_TYPE_BF16, GGML_TYPE_BF16, false, false}, tc_mm, "matmul_bf16", matmul_bf16_cm2_len, matmul_bf16_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec); } #endif for (const auto type : non_lut_quant_types) { @@ -2627,18 +2654,18 @@ void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) { } auto& tc = ((type >= GGML_TYPE_Q2_K && type <= GGML_TYPE_Q6_K) || type == GGML_TYPE_TQ1_0 || type == GGML_TYPE_TQ2_0) ? tc_mmq_k : tc_mmq; spec_fn_t qs = [&, type](const std::vector& wt, bool a) { return ggml_vk_mul_mm_cm2_spec(wt, a, (uint32_t)type); }; - create_mm_pipelines({type, GGML_TYPE_F16, false, true}, tc, "matmul_quant_f16_f16acc", matmul_quant_f16_f16acc_cm2_len, matmul_quant_f16_f16acc_cm2_data, sizeof(vk_mat_mat_push_constants), 3, qs, true); - create_mm_pipelines({type, GGML_TYPE_F16, false, false}, tc, "matmul_quant_f16", matmul_quant_f16_cm2_len, matmul_quant_f16_cm2_data, sizeof(vk_mat_mat_push_constants), 3, qs, true); + create_cm2_pipelines({type, GGML_TYPE_F16, false, true}, tc, "matmul_quant_f16_f16acc", matmul_quant_f16_f16acc_cm2_len, matmul_quant_f16_f16acc_cm2_data, sizeof(vk_mat_mat_push_constants), 3, qs); + create_cm2_pipelines({type, GGML_TYPE_F16, false, false}, tc, "matmul_quant_f16", matmul_quant_f16_cm2_len, matmul_quant_f16_cm2_data, sizeof(vk_mat_mat_push_constants), 3, qs); } - create_mm_pipelines({GGML_TYPE_Q4_K, GGML_TYPE_F16, false, true}, tc_mmq_k, "matmul_q4_k_f16_f16acc", matmul_q4_k_f16_f16acc_cm2_len, matmul_q4_k_f16_f16acc_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec, true); - create_mm_pipelines({GGML_TYPE_Q4_K, GGML_TYPE_F16, false, false}, tc_mmq_k, "matmul_q4_k_f16", matmul_q4_k_f16_cm2_len, matmul_q4_k_f16_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec, true); - create_mm_pipelines({GGML_TYPE_Q5_K, GGML_TYPE_F16, false, true}, tc_mmq_k, "matmul_q5_k_f16_f16acc", matmul_q5_k_f16_f16acc_cm2_len, matmul_q5_k_f16_f16acc_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec, true); - create_mm_pipelines({GGML_TYPE_Q5_K, GGML_TYPE_F16, false, false}, tc_mmq_k, "matmul_q5_k_f16", matmul_q5_k_f16_cm2_len, matmul_q5_k_f16_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec, true); + create_cm2_pipelines({GGML_TYPE_Q4_K, GGML_TYPE_F16, false, true}, tc_mmq_k, "matmul_q4_k_f16_f16acc", matmul_q4_k_f16_f16acc_cm2_len, matmul_q4_k_f16_f16acc_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec); + create_cm2_pipelines({GGML_TYPE_Q4_K, GGML_TYPE_F16, false, false}, tc_mmq_k, "matmul_q4_k_f16", matmul_q4_k_f16_cm2_len, matmul_q4_k_f16_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec); + create_cm2_pipelines({GGML_TYPE_Q5_K, GGML_TYPE_F16, false, true}, tc_mmq_k, "matmul_q5_k_f16_f16acc", matmul_q5_k_f16_f16acc_cm2_len, matmul_q5_k_f16_f16acc_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec); + create_cm2_pipelines({GGML_TYPE_Q5_K, GGML_TYPE_F16, false, false}, tc_mmq_k, "matmul_q5_k_f16", matmul_q5_k_f16_cm2_len, matmul_q5_k_f16_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec); #define X_CM2(TYPE, tstr) \ { auto tc = filter_tc(tc_mmq, TYPE, false); \ if (!tc.empty()) { \ - create_mm_pipelines({TYPE, GGML_TYPE_F16, false, true}, tc, "matmul_" #tstr "_f16_f16acc", matmul_##tstr##_f16_f16acc_cm2_len, matmul_##tstr##_f16_f16acc_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec, true); \ - create_mm_pipelines({TYPE, GGML_TYPE_F16, false, false}, tc, "matmul_" #tstr "_f16", matmul_##tstr##_f16_cm2_len, matmul_##tstr##_f16_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec, true); \ + create_cm2_pipelines({TYPE, GGML_TYPE_F16, false, true}, tc, "matmul_" #tstr "_f16_f16acc", matmul_##tstr##_f16_f16acc_cm2_len, matmul_##tstr##_f16_f16acc_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec); \ + create_cm2_pipelines({TYPE, GGML_TYPE_F16, false, false}, tc, "matmul_" #tstr "_f16", matmul_##tstr##_f16_cm2_len, matmul_##tstr##_f16_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec); \ } } FOR_EACH_LUT_TYPE_NONFP4(X_CM2) #if defined(GGML_VULKAN_FLOAT_E2M1_GLSLC_SUPPORT) && defined(GGML_VULKAN_FLOAT_E4M3_GLSLC_SUPPORT) @@ -2646,8 +2673,8 @@ void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) { #define X_CM2_OCP(TYPE, tstr) \ { auto tc = filter_tc(tc_mmq, TYPE, false); \ if (!tc.empty()) { \ - create_mm_pipelines({TYPE, GGML_TYPE_F16, false, true}, tc, "matmul_" #tstr "_f16_ocp_f16acc", matmul_##tstr##_f16_ocp_f16acc_cm2_len, matmul_##tstr##_f16_ocp_f16acc_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec, true); \ - create_mm_pipelines({TYPE, GGML_TYPE_F16, false, false}, tc, "matmul_" #tstr "_f16_ocp", matmul_##tstr##_f16_ocp_cm2_len, matmul_##tstr##_f16_ocp_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec, true); \ + create_cm2_pipelines({TYPE, GGML_TYPE_F16, false, true}, tc, "matmul_" #tstr "_f16_ocp_f16acc", matmul_##tstr##_f16_ocp_f16acc_cm2_len, matmul_##tstr##_f16_ocp_f16acc_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec); \ + create_cm2_pipelines({TYPE, GGML_TYPE_F16, false, false}, tc, "matmul_" #tstr "_f16_ocp", matmul_##tstr##_f16_ocp_cm2_len, matmul_##tstr##_f16_ocp_cm2_data, sizeof(vk_mat_mat_push_constants), 3, cm2_spec); \ } } FOR_EACH_LUT_FP4_TYPE(X_CM2_OCP) #undef X_CM2_OCP @@ -3515,6 +3542,7 @@ void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) { ggml_vk_create_pipeline(device, device->pipeline_get_rows_back_f32, "get_rows_back_f32", get_rows_back_f32_len, get_rows_back_f32_data, "main", 3, sizeof(vk_op_binary_push_constants), {256, 1, 1}, {}, 1, true); ggml_vk_create_pipeline(device, device->pipeline_matmul_split_k_reduce, "split_k_reduce", split_k_reduce_len, split_k_reduce_data, "main", 2, 2 * sizeof(uint32_t), {256 * 4, 1, 1}, {}, 1); + ggml_vk_create_pipeline(device, device->pipeline_matmul_stream_k_fixup, "stream_k_fixup", stream_k_fixup_len, stream_k_fixup_data, "main", 2, sizeof(vk_mat_mat_stream_k_fixup_push_constants), {1, 32, 1}, {}, 1); ggml_vk_create_pipeline(device, device->pipeline_flash_attn_split_k_reduce, "fa_split_k_reduce", fa_split_k_reduce_len, fa_split_k_reduce_data, "main", 3, sizeof(vk_op_flash_attn_split_k_reduce_push_constants), {1, device->subgroup_size, 1}, {device->subgroup_size}, 1, true); #if defined(VK_KHR_cooperative_matrix) && defined(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT) @@ -5375,6 +5403,8 @@ vk_device ggml_vk_get_device(size_t idx) { device->serialize_submissions = getenv("GGML_VK_SERIALIZE_SUBMISSIONS") != nullptr; device->disable_fusion = getenv("GGML_VK_DISABLE_FUSION") != nullptr; + device->disable_stream_k = getenv("GGML_VK_DISABLE_STREAM_K") != nullptr; + device->force_stream_k = getenv("GGML_VK_FORCE_STREAM_K") != nullptr; device->disable_descriptor_reuse = getenv("GGML_VK_DISABLE_DESCRIPTOR_REUSE") != nullptr; @@ -6408,14 +6438,113 @@ static uint32_t ggml_vk_guess_split_k(ggml_backend_vk_context * ctx, uint32_t m, return split_k; } +static uint32_t ggml_vk_guess_stream_k_groups( + ggml_backend_vk_context * ctx, const vk_pipeline & pipeline, + uint32_t m, uint32_t n, uint32_t k, uint32_t stride_d, uint32_t batch, uint32_t split_k, bool disable_split_k) { + if (disable_split_k) { + return 0; + } + if (ctx->device->disable_stream_k) { + return 0; + } + // TODO: Tune the CM1 and scalar workgroup counts before enabling Stream-K. + if (!ctx->device->coopmat2) { + return 0; + } + if (ctx->device->shader_core_count == 0) { + return 0; + } + + const uint32_t bm = pipeline->wg_denoms[0]; + const uint32_t bn = pipeline->wg_denoms[1]; + if (bm % 32 != 0 || m % bm != 0 || n % bn != 0 || k % 256 != 0 || stride_d != m) { + return 0; + } + + const uint32_t k_units = k / 256; + if (k_units == 1) { + return 0; + } + + const uint64_t tiles = uint64_t(m / bm) * (n / bn) * batch; + const uint64_t total_work_units = tiles * k_units; + if (total_work_units > UINT32_MAX) { + return 0; + } + + // Coopmat2 tiles are tuned for one resident workgroup per SM. + const uint32_t target_groups = ctx->device->shader_core_count; + const uint64_t regular_groups = tiles * split_k; + const uint64_t regular_waves = CEIL_DIV(regular_groups, target_groups); + const uint64_t regular_capacity = regular_waves * target_groups; + + const uint32_t stream_k_groups = std::min(target_groups, total_work_units); + if (stream_k_groups > ctx->device->properties.limits.maxComputeWorkGroupCount[0] || + bm / 32 > ctx->device->properties.limits.maxComputeWorkGroupCount[1]) { + return 0; + } + if (!ctx->device->force_stream_k) { + if (regular_waves == 1 && stream_k_groups == regular_groups) { + return 0; + } + // Stream-K does not offset its overhead when the regular grid fills most of the last wave. + // Use a lower cutoff for short K with no K split and narrow N tiles. + if ((split_k == 1 && k <= 4096 && bn <= 128 && regular_groups * 4 >= regular_capacity * 3) || + regular_groups * 10 >= regular_capacity * 9) { + return 0; + } + } + + return stream_k_groups; +} + void ggml_vk_matmul( ggml_backend_vk_context * ctx, vk_context& subctx, vk_pipeline& pipeline, vk_subbuffer&& a, vk_subbuffer&& b, vk_subbuffer&& d, vk_subbuffer&& split_k_buffer, uint32_t m, uint32_t n, uint32_t k, uint32_t stride_a, uint32_t stride_b, uint32_t stride_d, uint32_t batch_stride_a, uint32_t batch_stride_b, uint32_t batch_stride_d, - uint32_t split_k, uint32_t batch, uint32_t ne02, uint32_t ne12, uint32_t broadcast2, uint32_t broadcast3, + uint32_t split_k, uint32_t stream_k_groups, uint32_t batch, uint32_t ne02, uint32_t ne12, uint32_t broadcast2, uint32_t broadcast3, uint32_t padded_n, uint64_t b_col_bytes, uint64_t d_col_bytes) { VK_LOG_DEBUG("ggml_vk_matmul(a: (" << a.buffer->buffer << ", " << a.offset << ", " << a.size << "), b: (" << b.buffer->buffer << ", " << b.offset << ", " << b.size << "), d: (" << d.buffer->buffer << ", " << d.offset << ", " << d.size << "), split_k: (" << (split_k_buffer.buffer != nullptr ? split_k_buffer.buffer->buffer : VK_NULL_HANDLE) << ", " << split_k_buffer.offset << ", " << split_k_buffer.size << "), m: " << m << ", n: " << n << ", k: " << k << ", stride_a: " << stride_a << ", stride_b: " << stride_b << ", stride_d: " << stride_d << ", batch_stride_a: " << batch_stride_a << ", batch_stride_b: " << batch_stride_b << ", batch_stride_d: " << batch_stride_d << ", split_k: " << split_k << ", batch: " << batch << ", ne02: " << ne02 << ", ne12: " << ne12 << ", broadcast2: " << broadcast2 << ", broadcast3: " << broadcast3 << ", padded_n: " << padded_n << ")"); + if (stream_k_groups != 0) { + GGML_ASSERT(batch_stride_d == m * n); + if (ctx->prealloc_split_k_need_sync) { + ggml_vk_sync_buffers(ctx, subctx); + } + + ggml_pipeline_request_descriptor_sets(ctx, pipeline, 1); + ggml_pipeline_request_descriptor_sets(ctx, ctx->device->pipeline_matmul_stream_k_fixup, 1); + + const uint32_t bm = pipeline->wg_denoms[0]; + const uint32_t bn = pipeline->wg_denoms[1]; + const uint32_t k_units_per_tile = k / 256; + const uint32_t blocks_m = m / bm; + const uint32_t blocks_n = n / bn; + const uint32_t total_work_units = blocks_m * blocks_n * batch * k_units_per_tile; + const uint32_t work_units_per_group = total_work_units / stream_k_groups; + const uint32_t groups_with_extra_unit = total_work_units % stream_k_groups; + + vk_mat_mat_push_constants pc1 = { + m, n, k, stride_a, stride_b, stride_d, batch_stride_a, batch_stride_b, batch_stride_d, 0, batch, k, ne02, ne12, broadcast2, broadcast3, padded_n, + k_units_per_tile, work_units_per_group, groups_with_extra_unit, + 0, 0, 0, 0, 0, 0, 0, 0 + }; + init_pushconst_fastdiv(pc1, blocks_m, blocks_n); + + ggml_vk_dispatch_pipeline(ctx, subctx, pipeline, { a, b, d, split_k_buffer }, pc1, { stream_k_groups * pipeline->wg_denoms[0], 1, 1 }); + ggml_vk_sync_buffers(ctx, subctx); + + vk_mat_mat_stream_k_fixup_push_constants pc2 = { + m, n, bm, bn, k_units_per_tile, blocks_m, blocks_n, work_units_per_group, groups_with_extra_unit, + 0, 0, 0, 0, 0, 0, 0 + }; + init_pushconst_fastdiv(pc2); + + ggml_vk_dispatch_pipeline(ctx, subctx, ctx->device->pipeline_matmul_stream_k_fixup, { split_k_buffer, d }, pc2, { stream_k_groups, bm, 1 }); + ctx->prealloc_split_k_need_sync = true; + return; + } + if (split_k == 1) { // a small tile can still produce more workgroups than the device allows on the n axis: // split the dispatch into n-chunks, shifting the B and D column windows @@ -6438,8 +6567,12 @@ void ggml_vk_matmul( while (base_work_group_z < batch) { uint32_t groups_z = std::min(batch - base_work_group_z, ctx->device->properties.limits.maxComputeWorkGroupCount[2]); - const vk_mat_mat_push_constants pc = { m, n_chunk, k, stride_a, stride_b, stride_d, batch_stride_a, batch_stride_b, batch_stride_d, base_work_group_z, batch, k, ne02, ne12, broadcast2, broadcast3, uint32_t(padded_n - n_base) }; - ggml_vk_dispatch_pipeline(ctx, subctx, pipeline, { a, b_chunk, d_chunk }, pc, { m, n_chunk, groups_z }); + vk_mat_mat_push_constants pc = { + m, n_chunk, k, stride_a, stride_b, stride_d, batch_stride_a, batch_stride_b, batch_stride_d, base_work_group_z, batch, k, ne02, ne12, broadcast2, broadcast3, uint32_t(padded_n - n_base), + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + init_pushconst_fastdiv(pc); + ggml_vk_dispatch_pipeline(ctx, subctx, pipeline, { a, b_chunk, d_chunk, d_chunk }, pc, { m, n_chunk, groups_z }); base_work_group_z += groups_z; } } @@ -6462,9 +6595,13 @@ void ggml_vk_matmul( while (base_work_group_z < batch) { uint32_t groups_z = std::min(batch - base_work_group_z, ctx->device->properties.limits.maxComputeWorkGroupCount[2]); - const vk_mat_mat_push_constants pc1 = { m, n, k, stride_a, stride_b, stride_d, batch_stride_a, batch_stride_b, batch_stride_d, base_work_group_z, batch, k_split, ne02, ne12, broadcast2, broadcast3, padded_n }; + vk_mat_mat_push_constants pc1 = { + m, n, k, stride_a, stride_b, stride_d, batch_stride_a, batch_stride_b, batch_stride_d, base_work_group_z, batch, k_split, ne02, ne12, broadcast2, broadcast3, padded_n, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + init_pushconst_fastdiv(pc1); // Make sure enough workgroups get assigned for split k to work - ggml_vk_dispatch_pipeline(ctx, subctx, pipeline, { a, b, split_k_buffer }, pc1, { (CEIL_DIV(m, pipeline->wg_denoms[0]) * pipeline->wg_denoms[0]) * split_k, n, groups_z }); + ggml_vk_dispatch_pipeline(ctx, subctx, pipeline, { a, b, split_k_buffer, split_k_buffer }, pc1, { (CEIL_DIV(m, pipeline->wg_denoms[0]) * pipeline->wg_denoms[0]) * split_k, n, groups_z }); base_work_group_z += groups_z; } ggml_vk_sync_buffers(ctx, subctx); @@ -6518,10 +6655,11 @@ static bool ggml_vk_get_mul_mat_mat_f16acc(ggml_backend_vk_context * ctx, ggml_t return ctx->device->fp16 && prec_allows_f16; } -static const std::vector* ggml_vk_get_mul_mat_mat_pipeline_map( - ggml_backend_vk_context * ctx, ggml_type src0_type, ggml_type src1_type, ggml_prec prec, bool mul_mat_id = false) { +static const std::vector * ggml_vk_get_mul_mat_mat_pipeline_map( + ggml_backend_vk_context * ctx, ggml_type src0_type, ggml_type src1_type, ggml_prec prec, + bool mul_mat_id = false, bool stream_k = false) { bool f16acc = ggml_vk_get_mul_mat_mat_f16acc(ctx, src0_type, src1_type, prec); - vk_matmul_pipeline_key key{src0_type, src1_type, mul_mat_id, f16acc}; + vk_matmul_pipeline_key key{src0_type, src1_type, mul_mat_id, f16acc, stream_k}; auto it = ctx->device->pipeline_matmul.find(key); if (it == ctx->device->pipeline_matmul.end() || it->second.empty()) { // Try without f16acc @@ -6894,25 +7032,50 @@ static void ggml_vk_mul_mat_q_f16(ggml_backend_vk_context * ctx, vk_context& sub const bool y_f32_kernel = y_kernel_type == GGML_TYPE_F32; const bool y_needs_reformat = !quantize_y && (!ggml_vk_dim01_contiguous(src1) || y_kernel_type != src1->type); - const std::vector* mmp_map = - ggml_vk_get_mul_mat_mat_pipeline_map(ctx, src0->type, y_kernel_type, ggml_prec_get_acc(dst)); + ggml_type mmp_type_a = src0->type; + const ggml_type mmp_type_b = y_kernel_type; + const std::vector * mmp_map = + ggml_vk_get_mul_mat_mat_pipeline_map(ctx, mmp_type_a, mmp_type_b, ggml_prec_get_acc(dst)); const bool qx_needs_dequant = mmp_map == nullptr || x_non_contig; const bool qy_needs_dequant = y_needs_reformat; if (qx_needs_dequant) { // dequant src0 to f16 - mmp_map = ggml_vk_get_mul_mat_mat_pipeline_map(ctx, f16_type, y_kernel_type, ggml_prec_get_acc(dst)); + mmp_type_a = f16_type; + mmp_map = ggml_vk_get_mul_mat_mat_pipeline_map(ctx, mmp_type_a, mmp_type_b, ggml_prec_get_acc(dst)); } GGML_ASSERT(mmp_map != nullptr); + const std::vector * regular_mmp_map = mmp_map; + bool use_stream_k = ctx->device->coopmat2 && !ctx->device->disable_stream_k && !disable_split_k; + if (use_stream_k) { + mmp_map = ggml_vk_get_mul_mat_mat_pipeline_map(ctx, mmp_type_a, mmp_type_b, ggml_prec_get_acc(dst), false, true); + if (mmp_map == nullptr) { + mmp_map = regular_mmp_map; + use_stream_k = false; + } + } + const uint32_t kpad = quantize_y ? 0 : ggml_vk_align_size(ne10, ggml_vk_guess_matmul_pipeline_align_map(ctx, *mmp_map, ne01, ne11, false)); const bool aligned = !quantize_y && ne10 == kpad && ne01 > 8 && ne11 > 8; + const bool needs_64b_indexing = ggml_nbytes(src0) > ctx->device->properties.limits.maxStorageBufferRange; + if (use_stream_k && !aligned) { + mmp_map = regular_mmp_map; + use_stream_k = false; + } vk_pipeline pipeline = ggml_vk_guess_matmul_pipeline_map(ctx, *mmp_map, ne01, ne11, aligned, false); - if (ggml_nbytes(src0) > ctx->device->properties.limits.maxStorageBufferRange) { + const bool narrow_n = mmp_map->back().narrow_n_max != 0 && ne11 <= mmp_map->back().narrow_n_max; + const uint32_t split_k = ggml_vk_guess_split_k(ctx, ne01, ne11, ne10, disable_split_k, pipeline, narrow_n); + const uint32_t stream_k_groups = use_stream_k ? ggml_vk_guess_stream_k_groups(ctx, pipeline, ne01, ne11, ne10, stride_d, ne12 * ne13, split_k, disable_split_k) : 0; + if (use_stream_k && stream_k_groups == 0) { + pipeline = ggml_vk_guess_matmul_pipeline_map(ctx, *regular_mmp_map, ne01, ne11, aligned, false); + } + + if (needs_64b_indexing) { pipeline = ggml_vk_get_64b_indexing_pipeline(ctx, pipeline); } @@ -6923,9 +7086,6 @@ static void ggml_vk_mul_mat_q_f16(ggml_backend_vk_context * ctx, vk_context& sub const uint64_t y_ne = padded_n * ne10 * ne12 * ne13; const uint64_t d_ne = ggml_nelements(dst); - const bool narrow_n = mmp_map->back().narrow_n_max != 0 && ne11 <= mmp_map->back().narrow_n_max; - const uint32_t split_k = ggml_vk_guess_split_k(ctx, ne01, ne11, ne10, disable_split_k, pipeline, narrow_n); - const uint64_t qx_sz = ggml_type_size(src0->type) * x_ne / ggml_blck_size(src0->type); const uint64_t qy_sz = ggml_type_size(src1->type) * y_ne / ggml_blck_size(src1->type); const uint64_t x_sz = !qx_needs_dequant ? qx_sz : sizeof(ggml_fp16_t) * x_ne; @@ -6953,12 +7113,13 @@ static void ggml_vk_mul_mat_q_f16(ggml_backend_vk_context * ctx, vk_context& sub to_q8_1 = ggml_vk_get_quantize_pipeline(ctx, GGML_TYPE_Q8_1); } + const uint64_t stream_k_size = stream_k_groups != 0 ? uint64_t(stream_k_groups) * pipeline->wg_denoms[0] * pipeline->wg_denoms[1] * sizeof(float) : 0; + const uint64_t split_k_size = stream_k_groups != 0 ? stream_k_size : (split_k > 1 ? d_sz * split_k : 0); { - const uint64_t split_k_size = split_k > 1 ? d_sz * split_k : 0; if ( (qx_needs_dequant && x_sz > ctx->device->properties.limits.maxStorageBufferRange) || (qy_needs_dequant && y_sz > ctx->device->properties.limits.maxStorageBufferRange) || - (split_k > 1 && split_k_size > ctx->device->properties.limits.maxStorageBufferRange)) { + (split_k_size > ctx->device->properties.limits.maxStorageBufferRange)) { GGML_ABORT("Requested preallocation size is too large"); } if (qx_needs_dequant && ctx->prealloc_size_x < x_sz) { @@ -6969,7 +7130,7 @@ static void ggml_vk_mul_mat_q_f16(ggml_backend_vk_context * ctx, vk_context& sub ctx->prealloc_size_y = y_sz; ggml_vk_preallocate_buffers(ctx, subctx); } - if (split_k > 1 && ctx->prealloc_size_split_k < split_k_size) { + if (split_k_size != 0 && ctx->prealloc_size_split_k < split_k_size) { ctx->prealloc_size_split_k = split_k_size; ggml_vk_preallocate_buffers(ctx, subctx); } @@ -6984,7 +7145,7 @@ static void ggml_vk_mul_mat_q_f16(ggml_backend_vk_context * ctx, vk_context& sub if (quantize_y) { ggml_pipeline_request_descriptor_sets(ctx, to_q8_1, 1); } - if (split_k > 1) { + if (stream_k_groups == 0 && split_k > 1) { ggml_pipeline_request_descriptor_sets(ctx, ctx->device->pipeline_matmul_split_k_reduce, 1); } } @@ -7092,10 +7253,10 @@ static void ggml_vk_mul_mat_q_f16(ggml_backend_vk_context * ctx, vk_context& sub ggml_vk_matmul( ctx, subctx, pipeline, { d_X, x_buf_offset, x_range }, { d_Y, y_buf_offset, y_range }, - ggml_vk_subbuffer(ctx, d_D, d_buf_offset), { ctx->prealloc_split_k, 0, d_sz * split_k }, + ggml_vk_subbuffer(ctx, d_D, d_buf_offset), { ctx->prealloc_split_k, 0, split_k_size }, ne01, ne11, ne10, ne10, ne10, stride_d, stride_batch_x, stride_batch_y, stride_batch_d, - split_k, ne12*ne13, ne02, ne12, r2, r3, padded_n, + split_k, stream_k_groups, ne12*ne13, ne02, ne12, r2, r3, padded_n, b_col_bytes, (uint64_t)dst->nb[1] ); // NOLINT diff --git a/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_stream_k_fixup.comp b/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_stream_k_fixup.comp new file mode 100644 index 000000000000..c8a1961569be --- /dev/null +++ b/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_stream_k_fixup.comp @@ -0,0 +1,86 @@ +#version 450 + +#include "utils.glsl" + +layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in; + +layout (binding = 0) readonly buffer S4 {vec4 data_s4[];}; +layout (binding = 1) buffer D4 {vec4 data_d4[];}; + +layout (push_constant) uniform parameter { + uint M; + uint N; + uint BM; + uint BN; + uint k_units_per_tile; + uint blocks_m; + uint blocks_n; + uint work_units_per_group; + uint groups_with_extra_unit; + uint k_units_mp; + uint blocks_m_mp; + uint blocks_n_mp; + uint work_units_mp; + uint large_group_work_mp; + uint div_Ls0; + uint div_Ls1; +} p; + +const uint RESOLVE_ROWS = 32; + +// A normal matmul workgroup accumulates one BM x BN output tile over the full K range. +// Stream-K divides that accumulation into work units. Each work unit covers 256 consecutive K values and produces a BM x BN partial sum. +// Work units are ordered [K unit, M tile, N tile, batch] and divided into one contiguous range per main workgroup. +// A main workgroup writes its partial sum to D when it reaches the end of an output tile, or to scratch when its range stops within a tile. +// Scratch has shape [BM, BN, stream_k_groups] and stores float partial sums. +// Element [r, c, g] is workgroup g's contribution to local output element [r, c] in the last output tile of its range. +// The output tile for each scratch slot is derived from the workgroup's range and is not stored in scratch. +// Only the last output tile in a workgroup's range can stop early, so one scratch slot is enough. +// Fixup workgroup (x, y) handles main workgroup x and rows 32*y through 32*y+31. +// If main workgroup x starts within a tile and completes it, fixup adds the earlier groups' partial sums from scratch to D. + +// Find the main workgroup whose range contains work. +// With q = work_units_per_group and r = groups_with_extra_unit, the first r workgroups get q + 1 units and all others get q. +// group(work) = work / (q + 1) when work < r*(q + 1), otherwise r + (work - r*(q + 1))/q. +uint group_for_work(uint work) { + const uint large_group_work = p.work_units_per_group + 1; + const uint large_work = large_group_work * p.groups_with_extra_unit; + if (work < large_work) { + return fastdiv(work, p.large_group_work_mp, fastdiv_L(p.div_Ls1, 1)); + } + return p.groups_with_extra_unit + fastdiv(work - large_work, p.work_units_mp, fastdiv_L(p.div_Ls1, 0)); +} + +void main() { + const uint group_idx = gl_WorkGroupID.x; + const uint work_unit = group_idx * p.work_units_per_group + min(group_idx, p.groups_with_extra_unit); + const uint work_unit_end = work_unit + p.work_units_per_group + uint(group_idx < p.groups_with_extra_unit); + + const uint tile_idx = fastdiv(work_unit, p.k_units_mp, fastdiv_L(p.div_Ls0, 0)); + const uint tile_work = tile_idx * p.k_units_per_tile; + // Only a range that starts within a tile and completes it needs fixup. + if (work_unit == tile_work || work_unit_end < tile_work + p.k_units_per_tile) { + return; + } + + const uint first_group = group_for_work(tile_work); + const uint outer_tile = fastdiv(tile_idx, p.blocks_m_mp, fastdiv_L(p.div_Ls0, 1)); + const uint ir = tile_idx - outer_tile * p.blocks_m; + const uint batch_idx = fastdiv(outer_tile, p.blocks_n_mp, fastdiv_L(p.div_Ls0, 2)); + const uint ic = outer_tile - batch_idx * p.blocks_n; + const uint row_base = gl_WorkGroupID.y * RESOLVE_ROWS; + + for (uint stripe_elem = gl_LocalInvocationIndex * 4; stripe_elem < RESOLVE_ROWS * p.BN; stripe_elem += gl_WorkGroupSize.x * 4) { + const uint r = row_base + (stripe_elem & (RESOLVE_ROWS - 1)); + const uint c = stripe_elem / RESOLVE_ROWS; + const uint elem_idx = c * p.BM + r; + const uint dst_idx = batch_idx * p.M * p.N + (ic * p.BN + c) * p.M + ir * p.BM + r; + + // D contains the completing segment. Add the earlier segments from scratch. + vec4 result = data_d4[dst_idx / 4]; + for (uint previous_group = first_group; previous_group < group_idx; ++previous_group) { + result += data_s4[(previous_group * p.BM * p.BN + elem_idx) / 4]; + } + data_d4[dst_idx / 4] = result; + } +} diff --git a/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm.comp b/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm.comp index 19d37870bd69..68de7637347e 100644 --- a/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm.comp +++ b/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm.comp @@ -38,6 +38,7 @@ layout (constant_id = 12) const uint MmTypeA = 0; #include "types.glsl" #include "dot_product_funcs.glsl" +#include "utils.glsl" #ifndef MULMAT_QUANT #ifndef LOAD_VEC_A @@ -121,6 +122,9 @@ layout (binding = 0) readonly buffer BUF_Q5_K_P32 { block_q5_K_packed32 data[] layout (binding = 1) readonly buffer B {B_TYPE data_b[];}; layout (binding = 1) readonly buffer B_SCALAR {B_TYPE_SCALAR data_b_scalar[];}; layout (binding = 2) writeonly buffer D {D_TYPE data_d[];}; +#ifndef MUL_MAT_ID +layout (binding = 3) writeonly buffer S {D_TYPE data_s[];}; +#endif #ifdef MUL_MAT_ID layout (binding = 3) readonly buffer IDS {int data_ids[];}; @@ -155,6 +159,18 @@ layout (push_constant) uniform parameter uint ne12; uint broadcast2; uint broadcast3; + uint padded_N; + uint k_units_per_tile; + uint work_units_per_group; + uint groups_with_extra_unit; + uint k_units_mp; + uint blocks_m_mp; + uint blocks_n_mp; + uint ne12_mp; + uint broadcast2_mp; + uint broadcast3_mp; + uint div_Ls0; + uint div_Ls1; #endif } p; @@ -189,6 +205,9 @@ layout(constant_id = 13) const bool APPLY_SLM_A_RESHAPE = false; const uint SHMEM_STRIDE_PAD = 1; const bool APPLY_SLM_A_RESHAPE = false; #endif +#ifndef MUL_MAT_ID +layout(constant_id = 15) const bool stream_k = false; +#endif #define SHMEM_STRIDE (BK / 2 + SHMEM_STRIDE_PAD) shared FLOAT_TYPEV2 buf_a[BM * SHMEM_STRIDE]; @@ -218,27 +237,24 @@ void main() { _ne1 = data_row_map[2 + 2 * tile_idx]; const uint ic = 0; #else - const uint ic = gl_WorkGroupID.y; + const uint group_idx = gl_WorkGroupID.x; + uint stream_k_work_unit; + uint stream_k_work_unit_end; + + if (stream_k) { + stream_k_work_unit = group_idx * p.work_units_per_group + min(group_idx, p.groups_with_extra_unit); + stream_k_work_unit_end = stream_k_work_unit + p.work_units_per_group + uint(group_idx < p.groups_with_extra_unit); + } #endif #if defined(NEEDS_INIT_IQ_SHMEM) || defined(MULMAT_QUANT) init_iq_shmem(gl_WorkGroupSize); #endif -#ifndef MUL_MAT_ID - const uint batch_idx = gl_WorkGroupID.z + p.base_work_group_z; - - const uint i13 = batch_idx / p.ne12; - const uint i12 = batch_idx % p.ne12; - - const uint i03 = i13 / p.broadcast3; - const uint i02 = i12 / p.broadcast2; - - const uint batch_idx_a = i03 * p.ne02 + i02; -#endif - +#ifdef MUL_MAT_ID const uint blocks_m = (p.M + BM - 1) / BM; const uint ir = gl_WorkGroupID.x % blocks_m; const uint ik = gl_WorkGroupID.x / blocks_m; +#endif const uint WNITER = (WM * WN) / (WARP * TM * TN * WMITER); const uint WSUBM = WM / WMITER; @@ -288,6 +304,41 @@ void main() { const uint loadstride_a = gl_WorkGroupSize.x * LOAD_VEC_A_EFF * LOAD_VEC_BATCH_A / BK; const uint loadstride_b = gl_WorkGroupSize.x * LOAD_VEC_B_EFF * LOAD_VEC_BATCH_B / BK; +#ifndef MUL_MAT_ID + do { + uint stream_k_tile_k_unit; + uint stream_k_tile_k_units; + uint ir; + uint ic; + uint batch_idx; + uint ik; + + if (stream_k) { + const uint tile_idx = fastdiv(stream_k_work_unit, p.k_units_mp, fastdiv_L(p.div_Ls0, 0)); + stream_k_tile_k_unit = stream_k_work_unit - tile_idx * p.k_units_per_tile; + stream_k_tile_k_units = min(stream_k_work_unit_end - stream_k_work_unit, p.k_units_per_tile - stream_k_tile_k_unit); + + const uint blocks_m = p.M / BM; + const uint blocks_n = p.N / BN; + const uint outer_tile = fastdiv(tile_idx, p.blocks_m_mp, fastdiv_L(p.div_Ls0, 1)); + ir = tile_idx - outer_tile * blocks_m; + batch_idx = fastdiv(outer_tile, p.blocks_n_mp, fastdiv_L(p.div_Ls0, 2)); + ic = outer_tile - batch_idx * blocks_n; + } else { + const uint blocks_m = (p.M + BM - 1) / BM; + ic = gl_WorkGroupID.y; + batch_idx = gl_WorkGroupID.z + p.base_work_group_z; + ir = group_idx % blocks_m; + ik = group_idx / blocks_m; + } + + const uint i13 = fastdiv(batch_idx, p.ne12_mp, fastdiv_L(p.div_Ls1, 0)); + const uint i12 = batch_idx - i13 * p.ne12; + const uint i03 = fastdiv(i13, p.broadcast3_mp, fastdiv_L(p.div_Ls1, 2)); + const uint i02 = fastdiv(i12, p.broadcast2_mp, fastdiv_L(p.div_Ls1, 1)); + const uint batch_idx_a = i03 * p.ne02 + i02; +#endif + #ifdef MUL_MAT_ID load_row_ids(row_begin); uint required_work_items = _ne1 * BK / LOAD_VEC_B_EFF / LOAD_VEC_BATCH_B; @@ -298,8 +349,15 @@ void main() { const uint start_k = 0; const uint end_k = p.K; #else - const uint start_k = ik * p.k_split; - const uint end_k = min(p.K, (ik + 1) * p.k_split); + uint start_k; + uint end_k; + if (stream_k) { + start_k = stream_k_tile_k_unit * 256; + end_k = (stream_k_tile_k_unit + stream_k_tile_k_units) * 256; + } else { + start_k = ik * p.k_split; + end_k = min(p.K, (ik + 1) * p.k_split); + } #endif uint pos_a = @@ -438,7 +496,17 @@ void main() { const uint dc = ic * BN + warp_c * WN; #ifndef MUL_MAT_ID - const uint offsets = batch_idx * p.batch_stride_d + ik * p.batch_stride_d * p.num_batches; + uint offsets = batch_idx * p.batch_stride_d; + if (!stream_k) { + offsets += ik * p.batch_stride_d * p.num_batches; + } +#endif + +#ifndef MUL_MAT_ID + bool stream_k_store_scratch; + if (stream_k) { + stream_k_store_scratch = stream_k_tile_k_unit + stream_k_tile_k_units != p.k_units_per_tile; + } #endif #ifdef COOPMAT @@ -462,36 +530,44 @@ void main() { } } #else - const bool is_aligned = p.stride_d % 4 == 0; // Assumption: D_TYPE == float - [[unroll]] for (uint cm_row = 0; cm_row < cms_per_row; cm_row++) { [[unroll]] for (uint cm_col = 0; cm_col < cms_per_col; cm_col++) { - const bool is_in_bounds = dr + (cm_row + 1) * TM <= p.M && dc + (cm_col + 1) * TN <= p.N; - - if (is_aligned && is_in_bounds) { - // Full coopMat is within bounds and stride_d is aligned with 16B - coopmat cm_dtype = coopmat(sums[cm_col * cms_per_row + cm_row]); - coopMatStore(cm_dtype, data_d, offsets + (dc + cm_col * TN) * p.stride_d + dr + cm_row * TM, p.stride_d, gl_CooperativeMatrixLayoutColumnMajor); - } else if (is_in_bounds) { - // Full coopMat is within bounds, but stride_d is not aligned - coopMatStore(sums[cm_col * cms_per_row + cm_row], coopmat_stage, warp_i * TM * TN, TM, gl_CooperativeMatrixLayoutColumnMajor); - - controlBarrier(gl_ScopeSubgroup, gl_ScopeSubgroup, gl_StorageSemanticsShared, gl_SemanticsAcquireRelease); - [[unroll]] for (uint col = 0; col < TN; col += storestride) { - data_d[offsets + (dc + cm_col * TN + col + store_c) * p.stride_d + dr + cm_row * TM + store_r] = D_TYPE(coopmat_stage[warp_i * TM * TN + (col + store_c) * TM + store_r]); + coopmat cm_dtype = coopmat(sums[cm_col * cms_per_row + cm_row]); + if (stream_k) { + if (stream_k_store_scratch) { + const uint scratch_offset = group_idx * BM * BN + (warp_c * WN + cm_col * TN) * BM + warp_r * WM + cm_row * TM; + coopMatStore(cm_dtype, data_s, scratch_offset, BM, gl_CooperativeMatrixLayoutColumnMajor); + } else { + coopMatStore(cm_dtype, data_d, offsets + (dc + cm_col * TN) * p.stride_d + dr + cm_row * TM, p.stride_d, gl_CooperativeMatrixLayoutColumnMajor); } - controlBarrier(gl_ScopeSubgroup, gl_ScopeSubgroup, gl_StorageSemanticsShared, gl_SemanticsAcquireRelease); - } else if (dr + cm_row * TM < p.M && dc + cm_col * TN < p.N) { - // Partial coopMat is within bounds - coopMatStore(sums[cm_col * cms_per_row + cm_row], coopmat_stage, warp_i * TM * TN, TM, gl_CooperativeMatrixLayoutColumnMajor); - - controlBarrier(gl_ScopeSubgroup, gl_ScopeSubgroup, gl_StorageSemanticsShared, gl_SemanticsAcquireRelease); - [[unroll]] for (uint col = 0; col < TN; col += storestride) { - if (dr + cm_row * TM + store_r < p.M && dc + cm_col * TN + col + store_c < p.N) { + } else { + const bool is_aligned = p.stride_d % 4 == 0; // Assumption: D_TYPE == float + const bool is_in_bounds = dr + (cm_row + 1) * TM <= p.M && dc + (cm_col + 1) * TN <= p.N; + + if (is_aligned && is_in_bounds) { + // Full coopMat is within bounds and stride_d is aligned with 16B + coopMatStore(cm_dtype, data_d, offsets + (dc + cm_col * TN) * p.stride_d + dr + cm_row * TM, p.stride_d, gl_CooperativeMatrixLayoutColumnMajor); + } else if (is_in_bounds) { + // Full coopMat is within bounds, but stride_d is not aligned + coopMatStore(sums[cm_col * cms_per_row + cm_row], coopmat_stage, warp_i * TM * TN, TM, gl_CooperativeMatrixLayoutColumnMajor); + + controlBarrier(gl_ScopeSubgroup, gl_ScopeSubgroup, gl_StorageSemanticsShared, gl_SemanticsAcquireRelease); + [[unroll]] for (uint col = 0; col < TN; col += storestride) { data_d[offsets + (dc + cm_col * TN + col + store_c) * p.stride_d + dr + cm_row * TM + store_r] = D_TYPE(coopmat_stage[warp_i * TM * TN + (col + store_c) * TM + store_r]); } + controlBarrier(gl_ScopeSubgroup, gl_ScopeSubgroup, gl_StorageSemanticsShared, gl_SemanticsAcquireRelease); + } else if (dr + cm_row * TM < p.M && dc + cm_col * TN < p.N) { + // Partial coopMat is within bounds + coopMatStore(sums[cm_col * cms_per_row + cm_row], coopmat_stage, warp_i * TM * TN, TM, gl_CooperativeMatrixLayoutColumnMajor); + + controlBarrier(gl_ScopeSubgroup, gl_ScopeSubgroup, gl_StorageSemanticsShared, gl_SemanticsAcquireRelease); + [[unroll]] for (uint col = 0; col < TN; col += storestride) { + if (dr + cm_row * TM + store_r < p.M && dc + cm_col * TN + col + store_c < p.N) { + data_d[offsets + (dc + cm_col * TN + col + store_c) * p.stride_d + dr + cm_row * TM + store_r] = D_TYPE(coopmat_stage[warp_i * TM * TN + (col + store_c) * TM + store_r]); + } + } + controlBarrier(gl_ScopeSubgroup, gl_ScopeSubgroup, gl_StorageSemanticsShared, gl_SemanticsAcquireRelease); } - controlBarrier(gl_ScopeSubgroup, gl_ScopeSubgroup, gl_StorageSemanticsShared, gl_SemanticsAcquireRelease); } } } @@ -519,11 +595,22 @@ void main() { data_d[row_idx.y * p.batch_stride_d + row_idx.x * p.stride_d + dr_warp + 2 * cr + 1] = D_TYPE(sums[sums_idx].y); } #else - if (dr_warp + 2 * cr < p.M && dc_warp + cc < p.N) { - data_d[offsets + (dc_warp + cc) * p.stride_d + dr_warp + 2 * cr] = D_TYPE(sums[sums_idx].x); - } - if (dr_warp + 2 * cr + 1 < p.M && dc_warp + cc < p.N) { - data_d[offsets + (dc_warp + cc) * p.stride_d + dr_warp + 2 * cr + 1] = D_TYPE(sums[sums_idx].y); + if (stream_k) { + const uint scratch_offset = group_idx * BM * BN + (dc_warp + cc - ic * BN) * BM + dr_warp + 2 * cr - ir * BM; + if (stream_k_store_scratch) { + data_s[scratch_offset] = D_TYPE(sums[sums_idx].x); + data_s[scratch_offset + 1] = D_TYPE(sums[sums_idx].y); + } else { + data_d[offsets + (dc_warp + cc) * p.stride_d + dr_warp + 2 * cr] = D_TYPE(sums[sums_idx].x); + data_d[offsets + (dc_warp + cc) * p.stride_d + dr_warp + 2 * cr + 1] = D_TYPE(sums[sums_idx].y); + } + } else { + if (dr_warp + 2 * cr < p.M && dc_warp + cc < p.N) { + data_d[offsets + (dc_warp + cc) * p.stride_d + dr_warp + 2 * cr] = D_TYPE(sums[sums_idx].x); + } + if (dr_warp + 2 * cr + 1 < p.M && dc_warp + cc < p.N) { + data_d[offsets + (dc_warp + cc) * p.stride_d + dr_warp + 2 * cr + 1] = D_TYPE(sums[sums_idx].y); + } } #endif // MUL_MAT_ID } @@ -531,4 +618,10 @@ void main() { } } #endif // COOPMAT +#ifndef MUL_MAT_ID + if (stream_k) { + stream_k_work_unit += stream_k_tile_k_units; + } + } while (stream_k && stream_k_work_unit < stream_k_work_unit_end); +#endif } diff --git a/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_cm2.comp b/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_cm2.comp index dad9260b9894..1416cf72a82c 100644 --- a/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_cm2.comp +++ b/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_cm2.comp @@ -61,6 +61,10 @@ uint mm_quant_k() { } #endif +#ifndef MUL_MAT_ID +layout (constant_id = 15) const bool stream_k = false; +#endif + layout (push_constant) uniform parameter { uint M; @@ -91,6 +95,17 @@ layout (push_constant) uniform parameter uint broadcast3; // N dimension for the B matrix can be >= p.N uint padded_N; + uint k_units_per_tile; + uint work_units_per_group; + uint groups_with_extra_unit; + uint k_units_mp; + uint blocks_m_mp; + uint blocks_n_mp; + uint ne12_mp; + uint broadcast2_mp; + uint broadcast3_mp; + uint div_Ls0; + uint div_Ls1; #endif } p; @@ -102,6 +117,9 @@ layout (binding = 0) readonly buffer A {uint8_t data_a[];}; #endif layout (binding = 1) readonly buffer B {B_TYPE data_b[];}; layout (binding = 2) writeonly buffer D {D_TYPE data_d[];}; +#ifndef MUL_MAT_ID +layout (binding = 3) writeonly buffer S {D_TYPE data_s[];}; +#endif #if defined(MUL_MAT_ID) && defined(GGML_VULKAN_COOPMAT2_DECODE_VECTOR) layout (binding = 1) readonly buffer B4 {B_TYPEV4 data_b_v4[];}; #endif @@ -261,6 +279,17 @@ void main() { const uint row_begin = tile_idx * BN; _ne1 = data_row_map[2 + 2 * tile_idx]; const uint ic = 0; +#else + const uint group_idx = gl_WorkGroupID.x; + uint stream_k_work_unit; + uint stream_k_work_unit_end; + + if (stream_k) { + // A work unit covers 256 consecutive K elements of one output tile. + // Work units are flattened as [K unit, M tile, N tile, batch]. + stream_k_work_unit = group_idx * p.work_units_per_group + min(group_idx, p.groups_with_extra_unit); + stream_k_work_unit_end = stream_k_work_unit + p.work_units_per_group + uint(group_idx < p.groups_with_extra_unit); + } #endif #ifdef MUL_MAT_ID @@ -278,43 +307,61 @@ void main() { #endif #ifndef MUL_MAT_ID - const uint batch_idx = gl_WorkGroupID.z + p.base_work_group_z; - - const uint i13 = batch_idx / p.ne12; - const uint i12 = batch_idx % p.ne12; - - const uint i03 = i13 / p.broadcast3; - const uint i02 = i12 / p.broadcast2; + do { + uint stream_k_tile_k_unit; + uint stream_k_tile_k_units; + uint ir; + uint ic; + uint batch_idx; + uint ik; + + if (stream_k) { + // The 256-element granularity does not split any supported quant block. + const uint tile_idx = fastdiv(stream_k_work_unit, p.k_units_mp, fastdiv_L(p.div_Ls0, 0)); + stream_k_tile_k_unit = stream_k_work_unit - tile_idx * p.k_units_per_tile; + stream_k_tile_k_units = min(stream_k_work_unit_end - stream_k_work_unit, p.k_units_per_tile - stream_k_tile_k_unit); + + const uint blocks_m = p.M / BM; + const uint blocks_n = p.N / BN; + const uint outer_tile = fastdiv(tile_idx, p.blocks_m_mp, fastdiv_L(p.div_Ls0, 1)); + ir = tile_idx - outer_tile * blocks_m; + batch_idx = fastdiv(outer_tile, p.blocks_n_mp, fastdiv_L(p.div_Ls0, 2)); + ic = outer_tile - batch_idx * blocks_n; + } else { + const uint blocks_m = (p.M + BM - 1) / BM; + // L2-friendly workgroup scheduling + const uint blocks_n = (p.N + BN - 1) / BN; +#if defined(MULMAT_QUANT) + const uint a_panel_bytes = (BM * p.K / mm_quant_k()) * MmABlockBytes; +#elif defined(DATA_A_F32) + const uint a_panel_bytes = BM * p.K * 4; +#elif QUANT_K == 1 + const uint a_panel_bytes = BM * p.K * 2; +#else + const uint a_panel_bytes = (BM * p.K) / 2 + (BM * p.K) / 16; +#endif + const uint group_m = clamp(GROUP_A_BUDGET / max(a_panel_bytes, 1u), 1u, min(blocks_m, 32u)); + const uint tiles_per_group = group_m * blocks_n; + const uint lin = gl_WorkGroupID.y * blocks_m + (gl_WorkGroupID.x % blocks_m); + const uint group_id = lin / tiles_per_group; + const uint first_m = group_id * group_m; + const uint gsize = min(blocks_m - first_m, group_m); + const uint in_group = lin - group_id * tiles_per_group; + ir = first_m + in_group % gsize; + ic = in_group / gsize; + batch_idx = gl_WorkGroupID.z + p.base_work_group_z; + ik = group_idx / blocks_m; + } + const uint i13 = fastdiv(batch_idx, p.ne12_mp, fastdiv_L(p.div_Ls1, 0)); + const uint i12 = batch_idx - i13 * p.ne12; + const uint i03 = fastdiv(i13, p.broadcast3_mp, fastdiv_L(p.div_Ls1, 2)); + const uint i02 = fastdiv(i12, p.broadcast2_mp, fastdiv_L(p.div_Ls1, 1)); const uint batch_idx_a = i03 * p.ne02 + i02; -#endif - +#else const uint blocks_m = (p.M + BM - 1) / BM; const uint ik = gl_WorkGroupID.x / blocks_m; - -#ifdef MUL_MAT_ID const uint ir = gl_WorkGroupID.x % blocks_m; -#else - // L2-friendly workgroup scheduling - const uint blocks_n = (p.N + BN - 1) / BN; -#if defined(MULMAT_QUANT) - const uint a_panel_bytes = (BM * p.K / mm_quant_k()) * MmABlockBytes; -#elif defined(DATA_A_F32) - const uint a_panel_bytes = BM * p.K * 4; -#elif QUANT_K == 1 - const uint a_panel_bytes = BM * p.K * 2; -#else - const uint a_panel_bytes = (BM * p.K) / 2 + (BM * p.K) / 16; -#endif - const uint group_m = clamp(GROUP_A_BUDGET / max(a_panel_bytes, 1u), 1u, min(blocks_m, 32u)); - const uint tiles_per_group = group_m * blocks_n; - const uint lin = gl_WorkGroupID.y * blocks_m + (gl_WorkGroupID.x % blocks_m); - const uint group_id = lin / tiles_per_group; - const uint first_m = group_id * group_m; - const uint gsize = min(blocks_m - first_m, group_m); - const uint in_group = lin - group_id * tiles_per_group; - const uint ir = first_m + in_group % gsize; - const uint ic = in_group / gsize; #endif #ifdef MUL_MAT_ID @@ -325,8 +372,15 @@ void main() { uint start_k = 0; const uint end_k = p.K; #else - uint start_k = ik * p.k_split; - const uint end_k = min(p.K, (ik + 1) * p.k_split); + uint start_k; + uint end_k; + if (stream_k) { + start_k = stream_k_tile_k_unit * 256; + end_k = (stream_k_tile_k_unit + stream_k_tile_k_units) * 256; + } else { + start_k = ik * p.k_split; + end_k = min(p.K, (ik + 1) * p.k_split); + } #endif #ifdef MULMAT_QUANT @@ -341,7 +395,10 @@ void main() { #else uint pos_a = batch_idx_a * (p.batch_stride_a / qk); uint pos_b = batch_idx * p.batch_stride_b; - uint pos_d = batch_idx * p.batch_stride_d + ik * p.batch_stride_d * p.num_batches; + uint pos_d = batch_idx * p.batch_stride_d; + if (!stream_k) { + pos_d += ik * p.batch_stride_d * p.num_batches; + } #endif #ifdef MULMAT_QUANT @@ -404,12 +461,15 @@ void main() { const uint UNROLL_K = (qk == 256) ? 256 : (BK * 8); const uint unroll_count = UNROLL_K / BK; - // Detect a fast path where all loads are entirely in bounds and no clamping is required - if ((ir + 1) * BM <= p.M && (ic + 1) * BN <= p.padded_N && (start_k % START_ALIGN_K) == 0 && (end_k % BK) == 0 && + bool fast_path = stream_k; + if (!stream_k) { + fast_path = (ir + 1) * BM <= p.M && (ic + 1) * BN <= p.padded_N && (start_k % START_ALIGN_K) == 0 && (end_k % BK) == 0 && #if !defined(MULMAT_QUANT) && QUANT_K == 1 - (stride_a % 8) == 0 && + (stride_a % 8) == 0 && #endif - (stride_b % 8) == 0) { + (stride_b % 8) == 0; + } + if (fast_path) { // Hint to the compiler that values are aligned (want 16B alignment) start_k &= ~(START_ALIGN_K-1); stride_b &= ~7; @@ -427,7 +487,7 @@ void main() { // The fetches and stores are pipelined to hide the latency. fetch_scales(ir * BM, pos_a, stride_a, start_k, tid, true); - if (enable_smaller_matrices && ic * BN + BNover4 >= p.N) { + if (!stream_k && enable_smaller_matrices && ic * BN + BNover4 >= p.N) { coopmat sum = coopmat(0.0); for (uint i = 0; i < k_iters; ++i) { @@ -470,7 +530,7 @@ void main() { coopMatStoreTensorNV(mat_d, data_d, pos_d, sliceTensorLayoutNV(tensorLayoutD, ic * BN, BNover4, ir * BM, BM), tensorViewTranspose); return; - } else if (enable_smaller_matrices && ic * BN + BNover2 >= p.N) { + } else if (!stream_k && enable_smaller_matrices && ic * BN + BNover2 >= p.N) { coopmat sum = coopmat(0.0); for (uint i = 0; i < k_iters; ++i) { @@ -555,8 +615,18 @@ void main() { coopmat mat_d = coopmat(sum); - coopMatStoreTensorNV(mat_d, data_d, pos_d, sliceTensorLayoutNV(tensorLayoutD, ic * BN, BN, ir * BM, BM), tensorViewTranspose); - return; + if (stream_k) { + if (stream_k_tile_k_unit + stream_k_tile_k_units != p.k_units_per_tile) { + tensorLayoutNV<2> tensorLayoutS = createTensorLayoutNV(2); + tensorLayoutS = setTensorLayoutDimensionNV(tensorLayoutS, BN, BM); + tensorLayoutS = setTensorLayoutStrideNV(tensorLayoutS, BM, 1); + coopMatStoreTensorNV(mat_d, data_s, group_idx * BM * BN, tensorLayoutS, tensorViewTranspose); + } else { + coopMatStoreTensorNV(mat_d, data_d, pos_d, sliceTensorLayoutNV(tensorLayoutD, ic * BN, BN, ir * BM, BM), tensorViewTranspose); + } + } else { + coopMatStoreTensorNV(mat_d, data_d, pos_d, sliceTensorLayoutNV(tensorLayoutD, ic * BN, BN, ir * BM, BM), tensorViewTranspose); + } } } else #endif // !defined(MUL_MAT_ID) @@ -720,4 +790,10 @@ void main() { coopMatStoreTensorNV(mat_d, data_d, pos_d, sliceTensorLayoutNV(tensorLayoutD, ic * BN, BN, ir * BM, BM), tensorViewTranspose); #endif } +#ifndef MUL_MAT_ID + if (stream_k) { + stream_k_work_unit += stream_k_tile_k_units; + } + } while (stream_k && stream_k_work_unit < stream_k_work_unit_end); +#endif } diff --git a/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp b/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp index 86b69d15f614..2a07746960af 100644 --- a/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +++ b/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp @@ -948,6 +948,7 @@ void process_shaders() { string_to_spv("acc_f32", "acc.comp", {{"A_TYPE", "float"}, {"B_TYPE", "float"}, {"D_TYPE", "float"}, {"FLOAT_TYPE", "float"}}); string_to_spv("split_k_reduce", "mul_mat_split_k_reduce.comp", {}); + string_to_spv("stream_k_fixup", "mul_mat_stream_k_fixup.comp", {}); string_to_spv("fa_split_k_reduce", "flash_attn_split_k_reduce.comp", {}); string_to_spv("fa_mask_opt", "flash_attn_mask_opt.comp", {}); diff --git a/tests/test-backend-ops.cpp b/tests/test-backend-ops.cpp index b001c79d152a..be577b36c2dc 100644 --- a/tests/test-backend-ops.cpp +++ b/tests/test-backend-ops.cpp @@ -12265,6 +12265,12 @@ static std::vector> make_test_cases_eval() { test_cases.emplace_back(new test_mul_mat(GGML_TYPE_Q4_0, GGML_TYPE_F32, 576, 512, 576, {1,1}, {1,1})); test_cases.emplace_back(new test_mul_mat(GGML_TYPE_Q4_0, GGML_TYPE_F32, 1, 2048, 8192, {1, 1}, {1, 1})); + + test_cases.emplace_back(new test_mul_mat(GGML_TYPE_F16, GGML_TYPE_F16, 128, 128, 4352, {1, 1}, {1, 1})); + test_cases.emplace_back(new test_mul_mat(GGML_TYPE_F32, GGML_TYPE_F32, 64, 192, 17664, {1, 1}, {1, 1})); + test_cases.emplace_back(new test_mul_mat(GGML_TYPE_Q4_0, GGML_TYPE_F32, 128, 128, 4096, {1, 1}, {2, 1})); + test_cases.emplace_back(new test_mul_mat(GGML_TYPE_Q4_K, GGML_TYPE_F32, 128, 256, 4096, {1, 1}, {1, 1})); + for (ggml_type type_a : all_types) { test_cases.emplace_back(new test_mul_mat(type_a, GGML_TYPE_F32, 1, 64, 256, {1, 1}, {1, 1})); } From 7a4117eef97ed6419241da2384b2b1c011ecd763 Mon Sep 17 00:00:00 2001 From: Birk Skyum <74932975+birkskyum@users.noreply.github.com> Date: Thu, 19 Nov 2026 07:15:09 +0100 Subject: [PATCH 04/40] vulkan : enable MMQ with mixed signedness integer dots (#31045) * vulkan : enable MMQ with mixed signedness integer dots * vulkan: specialize MMQ shaders for mixed-signedness dot products * vulkan: track integer dot product support with signed, mixed and unsigned flags * vulkan: move signed dot check to the MMVQ call sites --- ggml/src/ggml-vulkan/ggml-vulkan-types.h | 4 + ggml/src/ggml-vulkan/ggml-vulkan.cpp | 35 ++++-- .../ggml-vulkan/vulkan-shaders/mul_mmq.comp | 9 ++ .../vulkan-shaders/mul_mmq_funcs.glsl | 117 +++++++++++++----- 4 files changed, 127 insertions(+), 38 deletions(-) diff --git a/ggml/src/ggml-vulkan/ggml-vulkan-types.h b/ggml/src/ggml-vulkan/ggml-vulkan-types.h index f976c579582c..6cc76b32307c 100644 --- a/ggml/src/ggml-vulkan/ggml-vulkan-types.h +++ b/ggml/src/ggml-vulkan/ggml-vulkan-types.h @@ -747,6 +747,10 @@ struct vk_device_struct { bool shader_64b_indexing; bool integer_dot_product; + // Which 4x8 bit packed integer dot products are accelerated + bool integer_dot_signed {}; + bool integer_dot_mixed {}; + bool integer_dot_unsigned {}; // 0: default, 1: force mmvq, -1: disable mmvq int32_t mmvq_mode; diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vulkan.cpp index e279693cb837..3674579cc4ed 100644 --- a/ggml/src/ggml-vulkan/ggml-vulkan.cpp +++ b/ggml/src/ggml-vulkan/ggml-vulkan.cpp @@ -1726,6 +1726,11 @@ static bool ggml_vk_matmul_shmem_support(const vk_device& device, const std::vec return supported; } +// MMQ uses the mixed signedness dot product (MMQ_SUDOT) when the signed one is not accelerated +static bool ggml_vk_mmq_use_sudot(const vk_device& device) { + return device->integer_dot_mixed && !device->integer_dot_signed; +} + static bool ggml_vk_matmul_int_shmem_support(const vk_device& device, const std::vector& warptile, bool mul_mat_id, ggml_type src0_type) { // FLOAT_TYPE in the shader is float16_t with fp16 support, otherwise float. @@ -1782,7 +1787,12 @@ static bool ggml_vk_matmul_int_shmem_support(const vk_device& device, const std: const uint32_t buf_b_size = BN * BK_STEP * block_b_size; const uint32_t mmid_row_ids = mul_mat_id ? (BN * 2u * (uint32_t)sizeof(uint16_t)) : 0u; - const uint32_t total_size = buf_a_size + buf_b_size + mmid_row_ids + lut_size; + // Signed quants declare buf_b_qsum: 2 int32_t per B block with MMQ_SUDOT, a single int32_t without + const bool b_sums = src0_type == GGML_TYPE_Q8_0 || src0_type == GGML_TYPE_MXFP4 || src0_type == GGML_TYPE_IQ4_XS || + src0_type == GGML_TYPE_IQ3_S || src0_type == GGML_TYPE_Q3_K || src0_type == GGML_TYPE_Q6_K; + const uint32_t qsum_size = !b_sums ? 0u : ggml_vk_mmq_use_sudot(device) ? BN * BK_STEP * 2u * 4u : 4u; + + const uint32_t total_size = buf_a_size + buf_b_size + mmid_row_ids + lut_size + qsum_size; const bool supported = total_size <= device->properties.limits.maxComputeSharedMemorySize; VK_LOG_DEBUG("ggml_vk_matmul_int_shmem_support(warptile=(" << warptile[0] << "," << warptile[1] << "," << warptile[2] << "), " @@ -1906,7 +1916,7 @@ static bool ggml_vk_fa_type_needs_shmem(ggml_type type) { static bool ggml_vk_fa_scalar_uses_mmq(const vk_device& device, ggml_type k_type, ggml_type v_type) { #if defined(GGML_VULKAN_INTEGER_DOT_GLSLC_SUPPORT) - return device->integer_dot_product && device->subgroup_clustered && + return device->integer_dot_product && device->integer_dot_signed && device->subgroup_clustered && !ggml_vk_fa_type_needs_shmem(v_type) && (k_type == GGML_TYPE_Q4_0 || k_type == GGML_TYPE_Q4_1 || k_type == GGML_TYPE_Q5_0 || k_type == GGML_TYPE_Q5_1 || @@ -2952,8 +2962,13 @@ void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) { uint32_t rsgs = 0) { auto tc = filter_tc(tc_base, key.type_a, key.mul_mat_id, true); if (!tc.empty()) { - spec_fn_t identity = [](const std::vector& wt, bool) { return wt; }; - create_mm_pipelines(key, tc, name, len, data, pc_size, pc, identity, false, rsgs > 0, rsgs, false); + // constant_id 11 is MMQ_SUDOT + spec_fn_t mmq_spec = [&](const std::vector& wt, bool) { + std::vector spec = wt; + spec.push_back(ggml_vk_mmq_use_sudot(device) ? 1u : 0u); + return spec; + }; + create_mm_pipelines(key, tc, name, len, data, pc_size, pc, mmq_spec, false, rsgs > 0, rsgs, false); } }; #endif @@ -4744,7 +4759,10 @@ vk_device ggml_vk_get_device(size_t idx) { device->coopmat_support = false; } - device->integer_dot_product = device->integer_dot_product && shader_integer_dot_product_props.integerDotProduct4x8BitPackedSignedAccelerated; + device->integer_dot_signed = shader_integer_dot_product_props.integerDotProduct4x8BitPackedSignedAccelerated; + device->integer_dot_mixed = shader_integer_dot_product_props.integerDotProduct4x8BitPackedMixedSignednessAccelerated; + device->integer_dot_unsigned = shader_integer_dot_product_props.integerDotProduct4x8BitPackedUnsignedAccelerated; + device->integer_dot_product = device->integer_dot_product && (device->integer_dot_signed || device->integer_dot_mixed); device->min_imported_host_pointer_alignment = external_memory_host_props.minImportedHostPointerAlignment; @@ -5623,7 +5641,8 @@ static void ggml_vk_print_gpu_info(size_t idx) { const bool rebar = ggml_vk_has_rebar(physical_device); integer_dot_product = integer_dot_product - && shader_integer_dot_product_props.integerDotProduct4x8BitPackedSignedAccelerated + && (shader_integer_dot_product_props.integerDotProduct4x8BitPackedSignedAccelerated || + shader_integer_dot_product_props.integerDotProduct4x8BitPackedMixedSignednessAccelerated) && shader_integer_dot_product_features.shaderIntegerDotProduct; coopmat_support = coopmat_support @@ -7395,7 +7414,7 @@ static void ggml_vk_mul_mat_vec_q_f16(ggml_backend_vk_context * ctx, vk_context& const ggml_type y_kernel_type = widen_bf16 ? GGML_TYPE_F32 : src1->type; const bool f16_f32_kernel = y_kernel_type == GGML_TYPE_F32; - bool quantize_y = ctx->device->integer_dot_product && src1->type == GGML_TYPE_F32 && ggml_is_contiguous(src1) && !y_non_contig && (ne11 * ne10) % 4 == 0 && (swap_inputs || ggml_vk_src1_prec_allows_q8(dst)) && ggml_vk_should_use_mmvq(ctx->device, ne01, ne11, ne10, src0->type); + bool quantize_y = ctx->device->integer_dot_signed && src1->type == GGML_TYPE_F32 && ggml_is_contiguous(src1) && !y_non_contig && (ne11 * ne10) % 4 == 0 && (swap_inputs || ggml_vk_src1_prec_allows_q8(dst)) && ggml_vk_should_use_mmvq(ctx->device, ne01, ne11, ne10, src0->type); vk_pipeline to_fp16_vk_0 = nullptr; vk_pipeline to_fp16_vk_1 = nullptr; @@ -8463,7 +8482,7 @@ static void ggml_vk_mul_mat_vec_id_q_f16(ggml_backend_vk_context * ctx, vk_conte const bool y_non_contig = !ggml_vk_dim01_contiguous(src1); const bool f16_f32_kernel = src1->type == GGML_TYPE_F32; - bool quantize_y = ctx->device->integer_dot_product && src1->type == GGML_TYPE_F32 && ggml_is_contiguous(src1) && !y_non_contig && (ne11 * ne10) % 4 == 0 && ggml_vk_src1_prec_allows_q8(dst) && ggml_vk_should_use_mmvq(ctx->device, ne01, ne12, ne10, src0->type); + bool quantize_y = ctx->device->integer_dot_signed && src1->type == GGML_TYPE_F32 && ggml_is_contiguous(src1) && !y_non_contig && (ne11 * ne10) % 4 == 0 && ggml_vk_src1_prec_allows_q8(dst) && ggml_vk_should_use_mmvq(ctx->device, ne01, ne12, ne10, src0->type); vk_pipeline to_fp16_vk_0 = nullptr; vk_pipeline to_fp16_vk_1 = nullptr; diff --git a/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq.comp b/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq.comp index 1866386a7359..f831fd788a85 100644 --- a/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq.comp +++ b/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq.comp @@ -82,6 +82,8 @@ layout (constant_id = 7) const uint TM = 4; layout (constant_id = 8) const uint TN = 2; layout (constant_id = 9) const uint TK = 1; // Only needed for coopmat layout (constant_id = 10) const uint WARP = 32; +// Use the mixed signedness dot product, for devices that accelerate only that one +layout (constant_id = 11) const bool MMQ_SUDOT = false; #define BK 32 @@ -102,6 +104,13 @@ shared block_b_cache buf_b[BN * BK_STEP]; block_a_cache cache_a[WMITER * TM]; block_b_cache cache_b; +#if defined(DATA_A_Q8_0) || defined(DATA_A_MXFP4) || defined(DATA_A_IQ4_XS) || defined(DATA_A_IQ3_S) || defined(DATA_A_Q3_K) || defined(DATA_A_Q6_K) +// These quants are signed. MMQ_SUDOT gives them a bias and uses the sum of each half of the q8_1 block to remove it. +#define MMQ_B_SUMS +shared int32_t buf_b_qsum[MMQ_SUDOT ? BN * BK_STEP * 2 : 1]; +int32_t cache_b_qsum[2]; +#endif + #define LOAD_VEC_A (4 * QUANT_R_MMQ) #define LOAD_VEC_B 16 diff --git a/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq_funcs.glsl b/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq_funcs.glsl index d9f2f5748c6c..9d94fd2b7577 100644 --- a/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq_funcs.glsl +++ b/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq_funcs.glsl @@ -4,6 +4,19 @@ #include "types.glsl" +int32_t mmq_dot(const int32_t a, const int32_t b) { + // With MMQ_SUDOT the A quants must be unsigned + if (MMQ_SUDOT) { + return dotPacked4x8EXT(uint32_t(a), b); + } + return dotPacked4x8EXT(a, b); +} + +// With MMQ_SUDOT, flip the sign bit of each byte. This adds a bias of 128 to signed quants. +int32_t mmq_a_store(const int32_t v) { + return MMQ_SUDOT ? v ^ int32_t(0x80808080) : v; +} + // Each iqs value maps to a 32-bit integer #if defined(DATA_A_Q2_0) @@ -41,7 +54,7 @@ void block_a_to_registers(const uint reg_ib, const uint buf_ib) { ACC_TYPE mmq_dot_product(const uint ib_a) { int32_t q_sum = 0; [[unroll]] for (uint iqs = 0; iqs < 8; ++iqs) { - q_sum += dotPacked4x8EXT(cache_a[ib_a].qs[iqs], cache_b.qs[iqs]); + q_sum += mmq_dot(cache_a[ib_a].qs[iqs], cache_b.qs[iqs]); } return ACC_TYPE(float(cache_a[ib_a].dm) * (float(q_sum) * float(cache_b.ds.x) - float(cache_b.ds.y))); @@ -102,8 +115,8 @@ ACC_TYPE mmq_dot_product(const uint ib_a) { const int32_t qs_b0 = cache_b.qs[iqs]; const int32_t qs_b1 = cache_b.qs[iqs + 4]; - q_sum += dotPacked4x8EXT(qs_a.x, qs_b0); - q_sum += dotPacked4x8EXT(qs_a.y, qs_b1); + q_sum += mmq_dot(qs_a.x, qs_b0); + q_sum += mmq_dot(qs_a.y, qs_b1); } #ifdef DATA_A_Q4_0 @@ -176,8 +189,8 @@ ACC_TYPE mmq_dot_product(const uint ib_a) { const int32_t qs_b0 = cache_b.qs[iqs]; const int32_t qs_b1 = cache_b.qs[iqs + 4]; - q_sum += dotPacked4x8EXT(qs_a0, qs_b0); - q_sum += dotPacked4x8EXT(qs_a1, qs_b1); + q_sum += mmq_dot(qs_a0, qs_b0); + q_sum += mmq_dot(qs_a1, qs_b1); } #ifdef DATA_A_Q5_0 @@ -192,8 +205,8 @@ ACC_TYPE mmq_dot_product(const uint ib_a) { // 2-byte loads for Q8_0 blocks (34 bytes) void block_a_to_shmem(const uint buf_ib, const uint ib, const uint iqs, const bool is_in_bounds) { if (is_in_bounds) { - buf_a[buf_ib].qs[iqs] = pack32(i16vec2(data_a_packed16[ib].qs[iqs * 2], - data_a_packed16[ib].qs[iqs * 2 + 1])); + buf_a[buf_ib].qs[iqs] = mmq_a_store(pack32(i16vec2(data_a_packed16[ib].qs[iqs * 2], + data_a_packed16[ib].qs[iqs * 2 + 1]))); if (iqs == 0) { buf_a[buf_ib].dm = FLOAT_TYPE(data_a_packed16[ib].d); @@ -221,7 +234,10 @@ ACC_TYPE mmq_dot_product(const uint ib_a) { const int32_t qs_a = cache_a[ib_a].qs[iqs]; const int32_t qs_b = cache_b.qs[iqs]; - q_sum += dotPacked4x8EXT(qs_a, qs_b); + q_sum += mmq_dot(qs_a, qs_b); + } + if (MMQ_SUDOT) { + q_sum -= 128 * (cache_b_qsum[0] + cache_b_qsum[1]); } return ACC_TYPE(float(q_sum) * float(cache_a[ib_a].dm) * float(cache_b.ds.x)); @@ -240,8 +256,8 @@ void block_a_to_shmem(const uint buf_ib, const uint ib, const uint iqs, const bo const u8vec4 i_a0 = unpack8( qs & 0x0F0F0F0F); const u8vec4 i_a1 = unpack8((qs >> 4) & 0x0F0F0F0F); - buf_a[buf_ib].qs[iqs ] = pack32(i8vec4(kvalues_mxfp4[i_a0.x], kvalues_mxfp4[i_a0.y], kvalues_mxfp4[i_a0.z], kvalues_mxfp4[i_a0.w])); - buf_a[buf_ib].qs[iqs + 4] = pack32(i8vec4(kvalues_mxfp4[i_a1.x], kvalues_mxfp4[i_a1.y], kvalues_mxfp4[i_a1.z], kvalues_mxfp4[i_a1.w])); + buf_a[buf_ib].qs[iqs ] = mmq_a_store(pack32(i8vec4(kvalues_mxfp4[i_a0.x], kvalues_mxfp4[i_a0.y], kvalues_mxfp4[i_a0.z], kvalues_mxfp4[i_a0.w]))); + buf_a[buf_ib].qs[iqs + 4] = mmq_a_store(pack32(i8vec4(kvalues_mxfp4[i_a1.x], kvalues_mxfp4[i_a1.y], kvalues_mxfp4[i_a1.z], kvalues_mxfp4[i_a1.w]))); if (iqs == 0) { buf_a[buf_ib].d = FLOAT_TYPE(e8m0_to_fp32(data_a[ib].e) * 0.5); @@ -269,7 +285,10 @@ ACC_TYPE mmq_dot_product(const uint ib_a) { [[unroll]] for (uint iqs = 0; iqs < 8; iqs++) { const int32_t qs_a = cache_a[ib_a].qs[iqs]; - q_sum += dotPacked4x8EXT(qs_a, cache_b.qs[iqs]); + q_sum += mmq_dot(qs_a, cache_b.qs[iqs]); + } + if (MMQ_SUDOT) { + q_sum -= 128 * (cache_b_qsum[0] + cache_b_qsum[1]); } return ACC_TYPE(float(cache_a[ib_a].d) * float(cache_b.ds.x) * float(q_sum)); @@ -284,8 +303,8 @@ void block_a_to_shmem(const uint buf_ib, const uint ib, const uint iqs, const bo const uint32_t vui = data_a_packed32[ib_k].qs[4 * ib32 + iqs]; const i32vec2 qs = iq4nl_to_i8x8(vui); - buf_a[buf_ib].qs[iqs ] = qs.x; - buf_a[buf_ib].qs[iqs + 4] = qs.y; + buf_a[buf_ib].qs[iqs ] = mmq_a_store(qs.x); + buf_a[buf_ib].qs[iqs + 4] = mmq_a_store(qs.y); if (iqs == 0) { const uint sl = (data_a_packed32[ib_k].scales_l >> (4 * ib32)) & 0xF; @@ -313,7 +332,10 @@ void block_a_to_registers(const uint reg_ib, const uint buf_ib) { ACC_TYPE mmq_dot_product(const uint ib_a) { int32_t q_sum = 0; [[unroll]] for (uint iqs = 0; iqs < 8; iqs++) { - q_sum += dotPacked4x8EXT(cache_a[ib_a].qs[iqs], cache_b.qs[iqs]); + q_sum += mmq_dot(cache_a[ib_a].qs[iqs], cache_b.qs[iqs]); + } + if (MMQ_SUDOT) { + q_sum -= 128 * (cache_b_qsum[0] + cache_b_qsum[1]); } return ACC_TYPE(float(cache_a[ib_a].d) * float(cache_b.ds.x) * float(q_sum)); @@ -372,8 +394,8 @@ ACC_TYPE mmq_dot_product(const uint ib_a) { const int32_t scale_m = int32_t(scale >> 4) * 0x01010101; // Duplicate 8-bit value across 32-bits. const int32_t qs_a = int32_t((cache_a[ib_a].qs[iqs / 4] >> ((iqs % 4) * 2)) & 0x03030303); - sum_d += dotPacked4x8EXT(qs_a, cache_b.qs[iqs]) * (scale & 0xF); - sum_m += dotPacked4x8EXT(scale_m, cache_b.qs[iqs]); + sum_d += mmq_dot(qs_a, cache_b.qs[iqs]) * (scale & 0xF); + sum_m += mmq_dot(scale_m, cache_b.qs[iqs]); } return ACC_TYPE(float(cache_b.ds.x) * (float(cache_a[ib_a].dm.x) * float(sum_d) - float(cache_a[ib_a].dm.y) * float(sum_m))); @@ -435,18 +457,26 @@ ACC_TYPE mmq_dot_product(const uint ib_a) { int32_t q_sum = 0; [[unroll]] for (uint iqs = 0; iqs < 4; iqs++) { - // Subtract 4 from the quants to correct the 3rd bit offset - const int32_t qs_a = pack32(unpack8(int32_t((cache_a[ib_a].qs[iqs / 2] >> ((iqs % 2) * 4)) & 0x0F0F0F0F)) - int8_t(4)); + // Subtract 4 from the quants to correct the 3rd bit offset. MMQ_SUDOT keeps them unsigned and subtracts 4 times the B sum. + const int32_t qs_u = int32_t((cache_a[ib_a].qs[iqs / 2] >> ((iqs % 2) * 4)) & 0x0F0F0F0F); + const int32_t qs_a = MMQ_SUDOT ? qs_u : pack32(unpack8(qs_u) - int8_t(4)); - q_sum += dotPacked4x8EXT(qs_a, cache_b.qs[iqs]); + q_sum += mmq_dot(qs_a, cache_b.qs[iqs]); + } + if (MMQ_SUDOT) { + q_sum -= 4 * cache_b_qsum[0]; } result += float(cache_a[ib_a].d_scales[0]) * float(q_sum); q_sum = 0; [[unroll]] for (uint iqs = 4; iqs < 8; iqs++) { - const int32_t qs_a = pack32(unpack8(int32_t((cache_a[ib_a].qs[iqs / 2] >> ((iqs % 2) * 4)) & 0x0F0F0F0F)) - int8_t(4)); + const int32_t qs_u = int32_t((cache_a[ib_a].qs[iqs / 2] >> ((iqs % 2) * 4)) & 0x0F0F0F0F); + const int32_t qs_a = MMQ_SUDOT ? qs_u : pack32(unpack8(qs_u) - int8_t(4)); - q_sum += dotPacked4x8EXT(qs_a, cache_b.qs[iqs]); + q_sum += mmq_dot(qs_a, cache_b.qs[iqs]); + } + if (MMQ_SUDOT) { + q_sum -= 4 * cache_b_qsum[1]; } result += float(cache_a[ib_a].d_scales[1]) * float(q_sum); @@ -518,7 +548,7 @@ ACC_TYPE mmq_dot_product(const uint ib_a) { const int32_t qs_a = cache_a[ib_a].qs[iqs]; #endif - q_sum += dotPacked4x8EXT(qs_a, cache_b.qs[iqs]); + q_sum += mmq_dot(qs_a, cache_b.qs[iqs]); } return ACC_TYPE(float(cache_b.ds.x) * float(cache_a[ib_a].dm.x) * float(q_sum) - float(cache_a[ib_a].dm.y) * float(cache_b.ds.y)); @@ -539,10 +569,11 @@ void block_a_to_shmem(const uint buf_ib, const uint ib, const uint iqs, const bo const uint qh_shift = ((iqs_k % 32) / 8) * 2; const i8vec2 vals00 = (unpack8(int32_t((data_a_packed16[ib_k].ql[ql_idx * 2 ] >> ql_shift) & uint16_t(0x0F0F))).xy | - unpack8(int32_t(((data_a_packed16[ib_k].qh[qh_idx * 2 ] >> qh_shift) & uint16_t(0x0303)) << 4)).xy) - int8_t(32); + unpack8(int32_t(((data_a_packed16[ib_k].qh[qh_idx * 2 ] >> qh_shift) & uint16_t(0x0303)) << 4)).xy); const i8vec2 vals01 = (unpack8(int32_t((data_a_packed16[ib_k].ql[ql_idx * 2 + 1] >> ql_shift) & uint16_t(0x0F0F))).xy | - unpack8(int32_t(((data_a_packed16[ib_k].qh[qh_idx * 2 + 1] >> qh_shift) & uint16_t(0x0303)) << 4)).xy) - int8_t(32); - buf_a[buf_ib].qs[iqs] = pack32(i8vec4(vals00.x, vals00.y, vals01.x, vals01.y)); + unpack8(int32_t(((data_a_packed16[ib_k].qh[qh_idx * 2 + 1] >> qh_shift) & uint16_t(0x0303)) << 4)).xy); + // MMQ_SUDOT keeps the quants unsigned and subtracts 32 times the B sum + buf_a[buf_ib].qs[iqs] = MMQ_SUDOT ? pack32(i8vec4(vals00, vals01)) : pack32(i8vec4(vals00 - int8_t(32), vals01 - int8_t(32))); if (iqs == 0) { const uint is = iqs_k / 4; @@ -574,7 +605,10 @@ ACC_TYPE mmq_dot_product(const uint ib_a) { [[unroll]] for (uint iqs = 0; iqs < 4; iqs++) { const int32_t qs_a = cache_a[ib_a].qs[iqs]; - q_sum += dotPacked4x8EXT(qs_a, cache_b.qs[iqs]); + q_sum += mmq_dot(qs_a, cache_b.qs[iqs]); + } + if (MMQ_SUDOT) { + q_sum -= 32 * cache_b_qsum[0]; } result += float(cache_a[ib_a].d_scales[0]) * float(q_sum); q_sum = 0; @@ -582,7 +616,10 @@ ACC_TYPE mmq_dot_product(const uint ib_a) { [[unroll]] for (uint iqs = 4; iqs < 8; iqs++) { const int32_t qs_a = cache_a[ib_a].qs[iqs]; - q_sum += dotPacked4x8EXT(qs_a, cache_b.qs[iqs]); + q_sum += mmq_dot(qs_a, cache_b.qs[iqs]); + } + if (MMQ_SUDOT) { + q_sum -= 32 * cache_b_qsum[1]; } result += float(cache_a[ib_a].d_scales[1]) * float(q_sum); @@ -612,8 +649,8 @@ void block_a_to_shmem(const uint buf_ib, const uint ib, const uint iqs, const bo const ivec4 m0 = -(ivec4(signs, signs >> 1, signs >> 2, signs >> 3) & 1); const ivec4 m1 = -(ivec4(signs >> 4, signs >> 5, signs >> 6, signs >> 7) & 1); - buf_a[buf_ib].qs[2 * iqs ] = pack32(i8vec4((vals0 ^ m0) - m0)); - buf_a[buf_ib].qs[2 * iqs + 1] = pack32(i8vec4((vals1 ^ m1) - m1)); + buf_a[buf_ib].qs[2 * iqs ] = mmq_a_store(pack32(i8vec4((vals0 ^ m0) - m0))); + buf_a[buf_ib].qs[2 * iqs + 1] = mmq_a_store(pack32(i8vec4((vals1 ^ m1) - m1))); if (iqs == 0) { const uint scale = (uint(data_a_packed16[ib_k].scales[ib32 / 4]) >> ((ib32 & 3) * 4)) & 0xF; @@ -641,7 +678,10 @@ void block_a_to_registers(const uint reg_ib, const uint buf_ib) { ACC_TYPE mmq_dot_product(const uint ib_a) { int32_t q_sum = 0; [[unroll]] for (uint iqs = 0; iqs < 8; iqs++) { - q_sum += dotPacked4x8EXT(cache_a[ib_a].qs[iqs], cache_b.qs[iqs]); + q_sum += mmq_dot(cache_a[ib_a].qs[iqs], cache_b.qs[iqs]); + } + if (MMQ_SUDOT) { + q_sum -= 128 * (cache_b_qsum[0] + cache_b_qsum[1]); } return ACC_TYPE(float(cache_a[ib_a].d) * float(cache_b.ds.x) * float(q_sum)); @@ -662,6 +702,12 @@ void block_b_to_shmem(const uint buf_ib, const uint ib, const uint iqs, const bo buf_b[buf_ib].qs[iqs * 4 + 1] = values.y; buf_b[buf_ib].qs[iqs * 4 + 2] = values.z; buf_b[buf_ib].qs[iqs * 4 + 3] = values.w; +#ifdef MMQ_B_SUMS + if (MMQ_SUDOT) { + buf_b_qsum[buf_ib * 2 + iqs] = dotPacked4x8EXT(values.x, 0x01010101u) + dotPacked4x8EXT(values.y, 0x01010101u) + + dotPacked4x8EXT(values.z, 0x01010101u) + dotPacked4x8EXT(values.w, 0x01010101u); + } +#endif } else { if (iqs == 0) { buf_b[buf_ib].ds = FLOAT_TYPEV2(0.0f); @@ -671,6 +717,11 @@ void block_b_to_shmem(const uint buf_ib, const uint ib, const uint iqs, const bo buf_b[buf_ib].qs[iqs * 4 + 1] = 0; buf_b[buf_ib].qs[iqs * 4 + 2] = 0; buf_b[buf_ib].qs[iqs * 4 + 3] = 0; +#ifdef MMQ_B_SUMS + if (MMQ_SUDOT) { + buf_b_qsum[buf_ib * 2 + iqs] = 0; + } +#endif } } @@ -679,4 +730,10 @@ void block_b_to_registers(const uint ib) { [[unroll]] for (uint iqs = 0; iqs < BK / 4; iqs++) { cache_b.qs[iqs] = buf_b[ib].qs[iqs]; } +#ifdef MMQ_B_SUMS + if (MMQ_SUDOT) { + cache_b_qsum[0] = buf_b_qsum[ib * 2]; + cache_b_qsum[1] = buf_b_qsum[ib * 2 + 1]; + } +#endif } From 39039aa27fe65244913d8a07303b8733f614fe20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Thu, 19 Nov 2026 07:50:33 +0100 Subject: [PATCH 05/40] llama : fall back to buffered I/O on EIO (#32545) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * llama : fall back to buffered I/O on EIO Signed-off-by: Adrien Gallouët * Preserve bytes already read, resumes at the current file offset Signed-off-by: Adrien Gallouët --------- Signed-off-by: Adrien Gallouët --- src/llama-mmap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/llama-mmap.cpp b/src/llama-mmap.cpp index 9688a7ed4e92..93496c3b7f8e 100644 --- a/src/llama-mmap.cpp +++ b/src/llama-mmap.cpp @@ -513,7 +513,7 @@ struct llama_file::impl { if (errno == EINTR) { continue; } - if (errno == EFAULT || errno == EINVAL) { + if (errno == EFAULT || errno == EINVAL || errno == EIO) { LLAMA_LOG_WARN("%s: file '%s' falling back to buffered I/O due to %s\n", __func__, fname.c_str(), strerror(errno)); const size_t read_offset = tell(); @@ -522,7 +522,7 @@ struct llama_file::impl { alignment = 1; init_fp("rb"); seek(read_offset, SEEK_SET); - read_raw_unsafe(ptr, len); + read_raw_unsafe(static_cast(ptr) + bytes_read, to_read); return; } throw std::runtime_error(format("read error: %s", strerror(errno))); From 80437488a497756df005fb64b50cfadb0cdcf83a Mon Sep 17 00:00:00 2001 From: Aleksander Grygier Date: Thu, 19 Nov 2026 08:37:35 +0100 Subject: [PATCH 06/40] ui: cut Llama Chat's first-load JavaScript by 63%, load diagrams, math and PDFs on demand (#32555) * ui: import Lucide icons by path in modules that run in Node Assisted-by: Claude (Opus 5.5 Medium) * ui: register highlight.js languages once, from lowlight's modules Assisted-by: Claude (Opus 5.5 Medium) * ui: load the pdf.js worker and nerdamer as files of their own Assisted-by: Claude (Opus 5.5 Medium) * ui: draw Mermaid diagrams with Pele Assisted-by: Claude (Opus 5.5 Medium) * ui: pin dependency versions and use one Svelte across the UI packages Assisted-by: Claude (Opus 5.5 Medium) * ui: build Llama Chat as split chunks Assisted-by: Claude (Opus 5.5 Medium) * ui: load KaTeX and pdf.js on first use Assisted-by: Claude (Opus 5.5 Medium) --- scripts/ui-assets.cmake | 13 +- ui/apps/chat/package-lock.json | 1240 +---------------- ui/apps/chat/package.json | 6 +- ui/apps/chat/scripts/vite-plugin-nerdamer.ts | 12 +- ui/apps/chat/src/app.css | 18 +- .../MarkdownContent/MarkdownContent.svelte | 2 +- .../MarkdownContent/markdown-content.css | 16 +- .../MarkdownContent/markdown-diagrams.ts | 99 +- .../MarkdownContent/markdown-processor.ts | 4 +- .../plugins/rehype/lazy-katex.ts | 56 + .../MarkdownEditor/markdown-block-widget.ts | 6 +- .../app/content/MermaidPreviewControls.svelte | 3 +- .../app/models/ModelsManager/row-actions.ts | 7 +- .../chat/src/lib/constants/icons.constants.ts | 36 +- .../chat/src/lib/constants/mcp.constants.ts | 4 +- .../lib/constants/mermaid-blocks.constants.ts | 19 + .../src/lib/constants/settings.constants.ts | 24 +- .../src/lib/constants/tool-ui.constants.ts | 24 +- .../chat/src/lib/constants/ui.constants.ts | 4 +- .../chat/src/lib/services/sandbox.service.ts | 4 +- ui/apps/chat/src/lib/utils/mcp.ts | 18 +- ui/apps/chat/src/lib/utils/pdf-processing.ts | 28 +- ui/apps/chat/src/virtual-nerdamer.d.ts | 4 +- .../client/pdf-processing.svelte.test.ts | 48 + ui/apps/chat/tests/e2e/pwa.e2e.ts | 18 +- .../content/MarkdownContent.stories.svelte | 22 + .../stories/fixtures/mermaid-diagrams.ts | 54 + ui/apps/chat/tests/unit/lazy-katex.test.ts | 32 + ui/apps/chat/tests/unit/pwa.spec.ts | 52 +- ui/apps/chat/tsconfig.json | 2 + ui/apps/chat/vite.config.ts | 2 +- ui/lib/ui/package-lock.json | 83 +- ui/lib/ui/package.json | 39 +- ui/lib/ui/src/lib/models/constants.ts | 12 +- ui/lib/ui/src/lib/utils/code.ts | 6 +- 35 files changed, 634 insertions(+), 1383 deletions(-) create mode 100644 ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/lazy-katex.ts create mode 100644 ui/apps/chat/tests/client/pdf-processing.svelte.test.ts create mode 100644 ui/apps/chat/tests/stories/fixtures/mermaid-diagrams.ts create mode 100644 ui/apps/chat/tests/unit/lazy-katex.test.ts diff --git a/scripts/ui-assets.cmake b/scripts/ui-assets.cmake index bfaa4ca4cdc5..90d0bdf338b8 100644 --- a/scripts/ui-assets.cmake +++ b/scripts/ui-assets.cmake @@ -41,7 +41,7 @@ function(mime_from_ext name out_var) set(m "text/html; charset=utf-8") elseif(ext_str STREQUAL "css") set(m "text/css") - elseif(ext_str STREQUAL "js") + elseif(ext_str STREQUAL "js" OR ext_str STREQUAL "mjs") set(m "application/javascript") elseif(ext_str STREQUAL "json") set(m "application/json") @@ -98,9 +98,12 @@ function(ui_validate_assets files in_dir) set(found_build_json TRUE) elseif(base STREQUAL "version.json") set(found_version_json TRUE) - elseif(base MATCHES "^bundle.*\\.js$") + # the app's entry: bundle[hash].js/.css from a single-bundle build (builds before the + # split one, prebuilt archives included), or entry/start[hash].js and the CSS in + # _app/immutable/assets from a split build + elseif(base MATCHES "^bundle.*\\.js$" OR f MATCHES "(^|/)_app/immutable/entry/start\\.[^/]*\\.js$") set(found_bundle_js TRUE) - elseif(base MATCHES "^bundle.*\\.css$") + elseif(base MATCHES "^bundle.*\\.css$" OR f MATCHES "(^|/)_app/immutable/assets/[^/]*\\.css$") set(found_bundle_css TRUE) endif() endforeach() @@ -125,10 +128,10 @@ function(ui_validate_assets files in_dir) list(APPEND missing "version.json") endif() if(NOT found_bundle_js) - list(APPEND missing "bundle[hash].js") + list(APPEND missing "_app/immutable/entry/start[hash].js (or bundle[hash].js)") endif() if(NOT found_bundle_css) - list(APPEND missing "bundle[hash].css") + list(APPEND missing "_app/immutable/assets/[name][hash].css (or bundle[hash].css)") endif() if(missing) diff --git a/ui/apps/chat/package-lock.json b/ui/apps/chat/package-lock.json index 11778042c5ce..ef7891ba3e38 100644 --- a/ui/apps/chat/package-lock.json +++ b/ui/apps/chat/package-lock.json @@ -51,8 +51,8 @@ "dompurify": "3.4.17", "eslint": "10.14.0", "eslint-config-prettier": "10.1.8", - "eslint-plugin-perfectionist": "^5.10.1", - "eslint-plugin-simple-import-sort": "^14.0.0", + "eslint-plugin-perfectionist": "5.13.0", + "eslint-plugin-simple-import-sort": "14.0.0", "eslint-plugin-storybook": "10.6.6", "eslint-plugin-svelte": "3.24.1", "fflate": "0.8.3", @@ -60,9 +60,9 @@ "highlight.js": "11.11.1", "http-server": "14.1.1", "mdsvex": "0.12.7", - "mermaid": "11.17.2", "mode-watcher": "1.1.0", "pdfjs-dist": "5.4.54", + "pele": "1.13.0", "playwright": "1.56.1", "prettier": "3.8.3", "prettier-plugin-svelte": "4.1.0", @@ -107,20 +107,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@antfu/install-pkg": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@antfu/install-pkg/-/install-pkg-2.1.0.tgz", - "integrity": "sha512-sdg9NxU3zR4Mnawfbc/x6GB5Wf17WYud5qOuEuxXjaKpYpMkISSJEjItGebXJ2bQ4DIcly4NYH23mtkGJjvKUw==", - "dev": true, - "license": "MIT", - "dependencies": { - "package-manager-detector": "^1.8.0", - "tinyexec": "^1.3.1" - }, - "funding": { - "url": "https://github.com/sponsors/antfu" - } - }, "node_modules/@babel/code-frame": { "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.7.tgz", @@ -220,13 +206,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@braintree/sanitize-url": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/@braintree/sanitize-url/-/sanitize-url-7.1.2.tgz", - "integrity": "sha512-jigsZK+sMF/cuiB7sERuo9V7N9jx+dhmHHnQyDSVdpZwVutaBu7WvNYqMDLSgFgfB30n452TP3vjDAvFC973mA==", - "dev": true, - "license": "MIT" - }, "node_modules/@cacheable/memory": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@cacheable/memory/-/memory-2.2.0.tgz", @@ -258,13 +237,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@chevrotain/types": { - "version": "11.1.2", - "resolved": "https://registry.npmjs.org/@chevrotain/types/-/types-11.1.2.tgz", - "integrity": "sha512-U+HFai5+zmJCkK86QsaJtoITlboZHBqrVketcO2ROv865xfCMSFpELQoz1GkX5GzME8pTa+3kbKrZHQtI0gdbw==", - "dev": true, - "license": "Apache-2.0" - }, "node_modules/@chromatic-com/storybook": { "version": "5.5.1", "resolved": "https://registry.npmjs.org/@chromatic-com/storybook/-/storybook-5.5.1.tgz", @@ -1190,25 +1162,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "node_modules/@iconify/types": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@iconify/types/-/types-2.0.0.tgz", - "integrity": "sha512-+wluvCrRhXrhyOmRDJ3q8mux9JkKy5SJ/v8ol2tu4FVjyYvtEzkc/3pK15ET6RKg4b4w4BmTk1+gsCUhf21Ykg==", - "dev": true, - "license": "MIT" - }, - "node_modules/@iconify/utils": { - "version": "3.1.7", - "resolved": "https://registry.npmjs.org/@iconify/utils/-/utils-3.1.7.tgz", - "integrity": "sha512-JZHlwdID+dy+lTgbYC8NEC4zeugqeYsc6jewvzb4c58kHauJn+X7rNwQjxz5p2qSjqaEeQoLkCIQ9v/H4PK0/w==", - "dev": true, - "license": "MIT", - "dependencies": { - "@antfu/install-pkg": "^2.0.1", - "@iconify/types": "^2.0.0", - "import-meta-resolve": "^4.2.0" - } - }, "node_modules/@img/colour": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@img/colour/-/colour-1.1.0.tgz", @@ -1984,16 +1937,6 @@ "react": ">=16" } }, - "node_modules/@mermaid-js/parser": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/@mermaid-js/parser/-/parser-1.2.1.tgz", - "integrity": "sha512-n12NohV3mrUyUL2o93IgG/ifeW9FTyeJn3zDxkhwa8MJ9Fxg3HQMlA3RiGmD/3UnJvheztkjjQAjA2T4LmUcpw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@chevrotain/types": "~11.1.2" - } - }, "node_modules/@modelcontextprotocol/sdk": { "version": "1.32.1", "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.32.1.tgz", @@ -4640,290 +4583,6 @@ "assertion-error": "^2.0.1" } }, - "node_modules/@types/d3": { - "version": "7.4.3", - "resolved": "https://registry.npmjs.org/@types/d3/-/d3-7.4.3.tgz", - "integrity": "sha512-lZXZ9ckh5R8uiFVt8ogUNf+pIrK4EsWrx2Np75WvF/eTpJ0FMHNhjXk8CKEx/+gpHbNQyJWehbFaTvqmHWB3ww==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/d3-array": "*", - "@types/d3-axis": "*", - "@types/d3-brush": "*", - "@types/d3-chord": "*", - "@types/d3-color": "*", - "@types/d3-contour": "*", - "@types/d3-delaunay": "*", - "@types/d3-dispatch": "*", - "@types/d3-drag": "*", - "@types/d3-dsv": "*", - "@types/d3-ease": "*", - "@types/d3-fetch": "*", - "@types/d3-force": "*", - "@types/d3-format": "*", - "@types/d3-geo": "*", - "@types/d3-hierarchy": "*", - "@types/d3-interpolate": "*", - "@types/d3-path": "*", - "@types/d3-polygon": "*", - "@types/d3-quadtree": "*", - "@types/d3-random": "*", - "@types/d3-scale": "*", - "@types/d3-scale-chromatic": "*", - "@types/d3-selection": "*", - "@types/d3-shape": "*", - "@types/d3-time": "*", - "@types/d3-time-format": "*", - "@types/d3-timer": "*", - "@types/d3-transition": "*", - "@types/d3-zoom": "*" - } - }, - "node_modules/@types/d3-array": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/@types/d3-array/-/d3-array-3.2.2.tgz", - "integrity": "sha512-hOLWVbm7uRza0BYXpIIW5pxfrKe0W+D5lrFiAEYR+pb6w3N2SwSMaJbXdUfSEv+dT4MfHBLtn5js0LAWaO6otw==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/d3-axis": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/@types/d3-axis/-/d3-axis-3.0.6.tgz", - "integrity": "sha512-pYeijfZuBd87T0hGn0FO1vQ/cgLk6E1ALJjfkC0oJ8cbwkZl3TpgS8bVBLZN+2jjGgg38epgxb2zmoGtSfvgMw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/d3-selection": "*" - } - }, - "node_modules/@types/d3-brush": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/@types/d3-brush/-/d3-brush-3.0.6.tgz", - "integrity": "sha512-nH60IZNNxEcrh6L1ZSMNA28rj27ut/2ZmI3r96Zd+1jrZD++zD3LsMIjWlvg4AYrHn/Pqz4CF3veCxGjtbqt7A==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/d3-selection": "*" - } - }, - "node_modules/@types/d3-chord": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/@types/d3-chord/-/d3-chord-3.0.6.tgz", - "integrity": "sha512-LFYWWd8nwfwEmTZG9PfQxd17HbNPksHBiJHaKuY1XeqscXacsS2tyoo6OdRsjf+NQYeB6XrNL3a25E3gH69lcg==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/d3-color": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/@types/d3-color/-/d3-color-3.1.3.tgz", - "integrity": "sha512-iO90scth9WAbmgv7ogoq57O9YpKmFBbmoEoCHDB2xMBY0+/KVrqAaCDyCE16dUspeOvIxFFRI+0sEtqDqy2b4A==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/d3-contour": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/@types/d3-contour/-/d3-contour-3.0.6.tgz", - "integrity": "sha512-BjzLgXGnCWjUSYGfH1cpdo41/hgdWETu4YxpezoztawmqsvCeep+8QGfiY6YbDvfgHz/DkjeIkkZVJavB4a3rg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/d3-array": "*", - "@types/geojson": "*" - } - }, - "node_modules/@types/d3-delaunay": { - "version": "6.0.4", - "resolved": "https://registry.npmjs.org/@types/d3-delaunay/-/d3-delaunay-6.0.4.tgz", - "integrity": "sha512-ZMaSKu4THYCU6sV64Lhg6qjf1orxBthaC161plr5KuPHo3CNm8DTHiLw/5Eq2b6TsNP0W0iJrUOFscY6Q450Hw==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/d3-dispatch": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/@types/d3-dispatch/-/d3-dispatch-3.0.7.tgz", - "integrity": "sha512-5o9OIAdKkhN1QItV2oqaE5KMIiXAvDWBDPrD85e58Qlz1c1kI/J0NcqbEG88CoTwJrYe7ntUCVfeUl2UJKbWgA==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/d3-drag": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/@types/d3-drag/-/d3-drag-3.0.7.tgz", - "integrity": "sha512-HE3jVKlzU9AaMazNufooRJ5ZpWmLIoc90A37WU2JMmeq28w1FQqCZswHZ3xR+SuxYftzHq6WU6KJHvqxKzTxxQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/d3-selection": "*" - } - }, - "node_modules/@types/d3-dsv": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/@types/d3-dsv/-/d3-dsv-3.0.7.tgz", - "integrity": "sha512-n6QBF9/+XASqcKK6waudgL0pf/S5XHPPI8APyMLLUHd8NqouBGLsU8MgtO7NINGtPBtk9Kko/W4ea0oAspwh9g==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/d3-ease": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@types/d3-ease/-/d3-ease-3.0.2.tgz", - "integrity": "sha512-NcV1JjO5oDzoK26oMzbILE6HW7uVXOHLQvHshBUW4UMdZGfiY6v5BeQwh9a9tCzv+CeefZQHJt5SRgK154RtiA==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/d3-fetch": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/@types/d3-fetch/-/d3-fetch-3.0.7.tgz", - "integrity": "sha512-fTAfNmxSb9SOWNB9IoG5c8Hg6R+AzUHDRlsXsDZsNp6sxAEOP0tkP3gKkNSO/qmHPoBFTxNrjDprVHDQDvo5aA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/d3-dsv": "*" - } - }, - "node_modules/@types/d3-force": { - "version": "3.0.10", - "resolved": "https://registry.npmjs.org/@types/d3-force/-/d3-force-3.0.10.tgz", - "integrity": "sha512-ZYeSaCF3p73RdOKcjj+swRlZfnYpK1EbaDiYICEEp5Q6sUiqFaFQ9qgoshp5CzIyyb/yD09kD9o2zEltCexlgw==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/d3-format": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/@types/d3-format/-/d3-format-3.0.4.tgz", - "integrity": "sha512-fALi2aI6shfg7vM5KiR1wNJnZ7r6UuggVqtDA+xiEdPZQwy/trcQaHnwShLuLdta2rTymCNpxYTiMZX/e09F4g==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/d3-geo": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@types/d3-geo/-/d3-geo-3.1.1.tgz", - "integrity": "sha512-65Emv9fQiQQqphLlRkuQ5ypPsOmWPhtBGCMv61JDPEPMvsx+gzhGf74yw1a78xFKPj6zw4AgQICJoQv0vK9M2w==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/geojson": "*" - } - }, - "node_modules/@types/d3-hierarchy": { - "version": "3.1.7", - "resolved": "https://registry.npmjs.org/@types/d3-hierarchy/-/d3-hierarchy-3.1.7.tgz", - "integrity": "sha512-tJFtNoYBtRtkNysX1Xq4sxtjK8YgoWUNpIiUee0/jHGRwqvzYxkq0hGVbbOGSz+JgFxxRu4K8nb3YpG3CMARtg==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/d3-interpolate": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/@types/d3-interpolate/-/d3-interpolate-3.0.4.tgz", - "integrity": "sha512-mgLPETlrpVV1YRJIglr4Ez47g7Yxjl1lj7YKsiMCb27VJH9W8NVM6Bb9d8kkpG/uAQS5AmbA48q2IAolKKo1MA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/d3-color": "*" - } - }, - "node_modules/@types/d3-path": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@types/d3-path/-/d3-path-3.1.1.tgz", - "integrity": "sha512-VMZBYyQvbGmWyWVea0EHs/BwLgxc+MKi1zLDCONksozI4YJMcTt8ZEuIR4Sb1MMTE8MMW49v0IwI5+b7RmfWlg==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/d3-polygon": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@types/d3-polygon/-/d3-polygon-3.0.2.tgz", - "integrity": "sha512-ZuWOtMaHCkN9xoeEMr1ubW2nGWsp4nIql+OPQRstu4ypeZ+zk3YKqQT0CXVe/PYqrKpZAi+J9mTs05TKwjXSRA==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/d3-quadtree": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/@types/d3-quadtree/-/d3-quadtree-3.0.6.tgz", - "integrity": "sha512-oUzyO1/Zm6rsxKRHA1vH0NEDG58HrT5icx/azi9MF1TWdtttWl0UIUsjEQBBh+SIkrpd21ZjEv7ptxWys1ncsg==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/d3-random": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/@types/d3-random/-/d3-random-3.0.4.tgz", - "integrity": "sha512-UHYId5WTCx4L4YNel7NU00XUXXgvgpgZOvp10PuvsQENjMDXhh2RyFc0KBjO7B45ne4Ha1yVH7ii0vnzKkuzWA==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/d3-scale": { - "version": "4.0.9", - "resolved": "https://registry.npmjs.org/@types/d3-scale/-/d3-scale-4.0.9.tgz", - "integrity": "sha512-dLmtwB8zkAeO/juAMfnV+sItKjlsw2lKdZVVy6LRr0cBmegxSABiLEpGVmSJJ8O08i4+sGR6qQtb6WtuwJdvVw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/d3-time": "*" - } - }, - "node_modules/@types/d3-scale-chromatic": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@types/d3-scale-chromatic/-/d3-scale-chromatic-3.1.0.tgz", - "integrity": "sha512-iWMJgwkK7yTRmWqRB5plb1kadXyQ5Sj8V/zYlFGMUBbIPKQScw+Dku9cAAMgJG+z5GYDoMjWGLVOvjghDEFnKQ==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/d3-selection": { - "version": "3.0.12", - "resolved": "https://registry.npmjs.org/@types/d3-selection/-/d3-selection-3.0.12.tgz", - "integrity": "sha512-Qe/KWYhEiIIxGs7HrAAjMfShxKldx19SJtr5zu53f3afPsdZNz7HHtdTLXo/kqeiWNXVycI24kSnfzBYkTzpgw==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/d3-shape": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/@types/d3-shape/-/d3-shape-3.2.0.tgz", - "integrity": "sha512-kVd74ta9eof3eJOvbNd1vGKS/XERRyQbT26Og63hIsvDO84cjD5gEOhsXf26w3FSoNlPVz84DOFcKv/oou+fMw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/d3-path": "*" - } - }, - "node_modules/@types/d3-time": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/@types/d3-time/-/d3-time-3.0.4.tgz", - "integrity": "sha512-yuzZug1nkAAaBlBBikKZTgzCeA+k1uy4ZFwWANOfKw5z5LRhV0gNA7gNkKm7HoK+HRN0wX3EkxGk0fpbWhmB7g==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/d3-time-format": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/@types/d3-time-format/-/d3-time-format-4.0.3.tgz", - "integrity": "sha512-5xg9rC+wWL8kdDj153qZcsJ0FWiFt0J5RB6LYUNZjwSnesfblqrI/bJ1wBdJ8OQfncgbJG5+2F+qfqnqyzYxyg==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/d3-timer": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@types/d3-timer/-/d3-timer-3.0.2.tgz", - "integrity": "sha512-Ps3T8E8dZDam6fUyNiMkekK3XUsaUEik+idO9/YjPtfj2qruF8tFBXS7XhtE4iIXBLxhmLjP3SXpLhVf21I9Lw==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/d3-transition": { - "version": "3.0.9", - "resolved": "https://registry.npmjs.org/@types/d3-transition/-/d3-transition-3.0.9.tgz", - "integrity": "sha512-uZS5shfxzO3rGlu0cC3bjmMFKsXv+SmZZcgp0KD22ts4uGXp5EVYGzu/0YdwZeKmddhcAccYtREJKkPfXkZuCg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/d3-selection": "*" - } - }, - "node_modules/@types/d3-zoom": { - "version": "3.0.9", - "resolved": "https://registry.npmjs.org/@types/d3-zoom/-/d3-zoom-3.0.9.tgz", - "integrity": "sha512-0sE1406XBYJGiqD3AusTl9ZqC//2mIXix51tbom25gDCA8ri4xnSZg28CaSE8Srl6FClqABUKfsn0qghgdepMA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/d3-interpolate": "*", - "@types/d3-selection": "*" - } - }, "node_modules/@types/debug": { "version": "4.1.13", "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.13.tgz", @@ -4955,13 +4614,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/geojson": { - "version": "7946.0.16", - "resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-7946.0.16.tgz", - "integrity": "sha512-6C8nqWur3j98U6+lXDfTUWIfgvZU+EumvpHKcYjujKH7woYyLj2sUmff0tRhrqM7BohUw7Pz3ZB1jj2gW9Fvmg==", - "dev": true, - "license": "MIT" - }, "node_modules/@types/hast": { "version": "3.0.5", "resolved": "https://registry.npmjs.org/@types/hast/-/hast-3.0.5.tgz", @@ -5296,17 +4948,6 @@ "dev": true, "license": "ISC" }, - "node_modules/@upsetjs/venn.js": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@upsetjs/venn.js/-/venn.js-2.0.0.tgz", - "integrity": "sha512-WbBhLrooyePuQ1VZxrJjtLvTc4NVfpOyKx0sKqioq9bX1C1m7Jgykkn8gLrtwumBioXIqam8DLxp88Adbue6Hw==", - "dev": true, - "license": "MIT", - "optionalDependencies": { - "d3-selection": "^3.0.0", - "d3-transition": "^3.0.1" - } - }, "node_modules/@valibot/to-json-schema": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/@valibot/to-json-schema/-/to-json-schema-1.8.0.tgz", @@ -6162,16 +5803,6 @@ "url": "https://github.com/sponsors/wooorm" } }, - "node_modules/commander": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz", - "integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">= 10" - } - }, "node_modules/consola": { "version": "3.4.2", "resolved": "https://registry.npmjs.org/consola/-/consola-3.4.2.tgz", @@ -6265,16 +5896,6 @@ "node": ">= 0.4.0" } }, - "node_modules/cose-base": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/cose-base/-/cose-base-1.0.3.tgz", - "integrity": "sha512-s9whTXInMSgAp/NVXVNuVxVKzGH2qck3aQlVHxDCdAEPgtMKwc4Wq6/QKhgdEdgbLSi9rBTAcPoRa6JpiG4ksg==", - "dev": true, - "license": "MIT", - "dependencies": { - "layout-base": "^1.0.0" - } - }, "node_modules/crelt": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/crelt/-/crelt-1.0.7.tgz", @@ -6325,642 +5946,80 @@ "license": "MIT", "peer": true }, - "node_modules/cytoscape": { - "version": "3.34.4", - "resolved": "https://registry.npmjs.org/cytoscape/-/cytoscape-3.34.4.tgz", - "integrity": "sha512-msY99tMY8iWTg+sIPGfSqDcPNOt4xcj+v/K/7qUFaCUxxlqnMkUYLBjRUzn9W5CU/R2hrmtJa5+UtovrEM2ctg==", + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", "dev": true, "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, "engines": { - "node": ">=0.10" + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } } }, - "node_modules/cytoscape-cose-bilkent": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/cytoscape-cose-bilkent/-/cytoscape-cose-bilkent-4.1.0.tgz", - "integrity": "sha512-wgQlVIUJF13Quxiv5e1gstZ08rnZj2XaLHGoFMYXz7SkNfCDOOteKBE6SYRfA9WxxI/iBc3ajfDoc6hb/MRAHQ==", + "node_modules/decode-bmp": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/decode-bmp/-/decode-bmp-0.2.1.tgz", + "integrity": "sha512-NiOaGe+GN0KJqi2STf24hfMkFitDUaIoUU3eKvP/wAbLe8o6FuW5n/x7MHPR0HKvBokp6MQY/j7w8lewEeVCIA==", "dev": true, "license": "MIT", "dependencies": { - "cose-base": "^1.0.0" + "@canvas/image-data": "^1.0.0", + "to-data-view": "^1.1.0" }, - "peerDependencies": { - "cytoscape": "^3.2.0" + "engines": { + "node": ">=8.6.0" } }, - "node_modules/cytoscape-fcose": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/cytoscape-fcose/-/cytoscape-fcose-2.2.0.tgz", - "integrity": "sha512-ki1/VuRIHFCzxWNrsshHYPs6L7TvLu3DL+TyIGEsRcvVERmxokbf5Gdk7mFxZnTdiGtnA4cfSmjZJMviqSuZrQ==", + "node_modules/decode-ico": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/decode-ico/-/decode-ico-0.4.1.tgz", + "integrity": "sha512-69NZfbKIzux1vBOd31al3XnMnH+2mqDhEgLdpygErm4d60N+UwA5Sq5WFjmEDQzumgB9fElojGwWG0vybVfFmA==", "dev": true, "license": "MIT", "dependencies": { - "cose-base": "^2.2.0" + "@canvas/image-data": "^1.0.0", + "decode-bmp": "^0.2.0", + "to-data-view": "^1.1.0" }, - "peerDependencies": { - "cytoscape": "^3.2.0" + "engines": { + "node": ">=8.6" } }, - "node_modules/cytoscape-fcose/node_modules/cose-base": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/cose-base/-/cose-base-2.2.0.tgz", - "integrity": "sha512-AzlgcsCbUMymkADOJtQm3wO9S3ltPfYOFD5033keQn9NJzIbtnZj+UdBJe7DYml/8TdbtHJW3j58SOnKhWY/5g==", + "node_modules/decode-named-character-reference": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/decode-named-character-reference/-/decode-named-character-reference-1.3.0.tgz", + "integrity": "sha512-GtpQYB283KrPp6nRw50q3U9/VfOutZOe103qlN7BPP6Ad27xYnOIWv4lPzo8HCAL+mMZofJ9KEy30fq6MfaK6Q==", "dev": true, "license": "MIT", "dependencies": { - "layout-base": "^2.0.0" - } - }, - "node_modules/cytoscape-fcose/node_modules/layout-base": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/layout-base/-/layout-base-2.0.1.tgz", - "integrity": "sha512-dp3s92+uNI1hWIpPGH3jK2kxE2lMjdXdr+DH8ynZHpd6PUlH6x6cbuXnoMmiNumznqaNO31xu9e79F0uuZ0JFg==", - "dev": true, - "license": "MIT" - }, - "node_modules/d3": { - "version": "7.9.2", - "resolved": "https://registry.npmjs.org/d3/-/d3-7.9.2.tgz", - "integrity": "sha512-ZKb/mONPVKzaO5UlcWcwN8bS4ezvQaYu+bsou+XgNABdGC800kwH651ADTbbTxMPHW13UlvbQafdmJQDk1w7Mg==", - "dev": true, - "license": "ISC", - "dependencies": { - "d3-array": "^3.2.5", - "d3-axis": "^3.0.1", - "d3-brush": "^3.0.1", - "d3-chord": "^3.0.2", - "d3-color": "^3.1.1", - "d3-contour": "^4.0.3", - "d3-delaunay": "^6.0.6", - "d3-dispatch": "^3.0.2", - "d3-drag": "^3.0.1", - "d3-dsv": "^3.0.2", - "d3-ease": "^3.0.2", - "d3-fetch": "^3.0.2", - "d3-force": "^3.0.1", - "d3-format": "^3.1.3", - "d3-geo": "^3.1.2", - "d3-hierarchy": "^3.1.3", - "d3-interpolate": "^3.0.2", - "d3-path": "^3.1.1", - "d3-polygon": "^3.0.2", - "d3-quadtree": "^3.0.2", - "d3-random": "^3.0.2", - "d3-scale": "^4.0.3", - "d3-scale-chromatic": "^3.1.1", - "d3-selection": "^3.0.1", - "d3-shape": "^3.2.1", - "d3-time": "^3.1.1", - "d3-time-format": "^4.1.1", - "d3-timer": "^3.0.2", - "d3-transition": "^3.0.2", - "d3-zoom": "^3.0.1" + "character-entities": "^2.0.0" }, - "engines": { - "node": ">=12" + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" } }, - "node_modules/d3-array": { - "version": "3.2.5", - "resolved": "https://registry.npmjs.org/d3-array/-/d3-array-3.2.5.tgz", - "integrity": "sha512-Th8qGXoBalmWsstpkuhmBuTsBQIFqYOJtjlBvNVvBfJ8E3uYusBUwUR8HU20U0qKKQkgCvKyR1YjiozWadk5QA==", + "node_modules/dedent": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/dedent/-/dedent-1.7.2.tgz", + "integrity": "sha512-WzMx3mW98SN+zn3hgemf4OzdmyNhhhKz5Ay0pUfQiMQ3e1g+xmTJWp/pKdwKVXhdSkAEGIIzqeuWrL3mV/AXbA==", "dev": true, - "license": "ISC", - "dependencies": { - "internmap": "1 - 2" + "license": "MIT", + "peerDependencies": { + "babel-plugin-macros": "^3.1.0" }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-axis": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/d3-axis/-/d3-axis-3.0.1.tgz", - "integrity": "sha512-E5QCXfaf/uJZEHHiqoWRq+bQEm2PzoVFv2rDC7CZ3wwI0MjfMW3w83J3ubobG4IJj3lShAI5eiPJhOu/8wHofA==", - "dev": true, - "license": "ISC", - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-brush": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/d3-brush/-/d3-brush-3.0.1.tgz", - "integrity": "sha512-L5Glqa/Gb7LU3ndIOMtA5mDzlJ0aXKp5ELP2X09ctWF23jO7+faIUVDbmaIi+D6k3EemXFWn1F3lkfguExoVhA==", - "dev": true, - "license": "ISC", - "dependencies": { - "d3-dispatch": "1 - 3", - "d3-drag": "2 - 3", - "d3-interpolate": "1 - 3", - "d3-selection": "3", - "d3-transition": "3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-chord": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/d3-chord/-/d3-chord-3.0.2.tgz", - "integrity": "sha512-cGmADo5M2PTi3ewJZ2lcE32eURd4JmHtQ5JwRIUcas5L1SXqufG9yPyjWp8fW0gRi7aZi9bgbZPFZO1eyZ+1CQ==", - "dev": true, - "license": "ISC", - "dependencies": { - "d3-path": "1 - 3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-color": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/d3-color/-/d3-color-3.1.1.tgz", - "integrity": "sha512-lfab8x0Bj0UO7SNsY8dZSbNIA6ipbkE3X0NG9nqjCu6CfCHZseuDnOSJY7hidKrjpP++i1M2qT+FlAdPKYRilA==", - "dev": true, - "license": "ISC", - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-contour": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/d3-contour/-/d3-contour-4.0.3.tgz", - "integrity": "sha512-5DYURc8KwXPOhSUBblU0P9rVcArsSPxPOxsfO0Eud0s28oU0sB2e80aRHRL9AZW3usT8ikFKyIHpHHLNWLdRVA==", - "dev": true, - "license": "ISC", - "dependencies": { - "d3-array": "^3.2.4" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-delaunay": { - "version": "6.0.6", - "resolved": "https://registry.npmjs.org/d3-delaunay/-/d3-delaunay-6.0.6.tgz", - "integrity": "sha512-DMQIEvSJhZCB6pwedcXaAlQ+MeKU5LlM2XakKtc73b/VM+RBiI1SRXycOEOKg2jsKj4zZ9F0KGYG6nCGwwWu/g==", - "dev": true, - "license": "ISC", - "dependencies": { - "delaunator": "5" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-dispatch": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/d3-dispatch/-/d3-dispatch-3.0.2.tgz", - "integrity": "sha512-sAzH4Y4nsLo8eSqw5jKiZt+LU2wZmL/qS+OkxQGjhwazB/D7TY34R/QK1eshfGr7cZEKymKZ/Haem7m+lu98Sg==", - "dev": true, - "license": "ISC", - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-drag": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/d3-drag/-/d3-drag-3.0.1.tgz", - "integrity": "sha512-OWeoayCq8J69hUIjvL+Mb6Q6Oaj/fyHV5XaXByEUAG+JUjIfTGDnk3qGpcXrD3VmQ3BSV96fcbM6fqq7C0tbPA==", - "dev": true, - "license": "ISC", - "dependencies": { - "d3-dispatch": "1 - 3", - "d3-selection": "3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-dsv": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/d3-dsv/-/d3-dsv-3.0.2.tgz", - "integrity": "sha512-FUnXhX7I4/AXyRCZzwfZTDGSq8PGZ4oR0tiCBqNGOZMsDrQ+6sIWNQnBzcCGhzJKZ6uCvCezTwflUqI209RRiQ==", - "dev": true, - "license": "ISC", - "dependencies": { - "commander": "7", - "iconv-lite": "0.6", - "rw": "1" - }, - "bin": { - "csv2json": "bin/dsv2json.js", - "csv2tsv": "bin/dsv2dsv.js", - "dsv2dsv": "bin/dsv2dsv.js", - "dsv2json": "bin/dsv2json.js", - "json2csv": "bin/json2dsv.js", - "json2dsv": "bin/json2dsv.js", - "json2tsv": "bin/json2dsv.js", - "tsv2csv": "bin/dsv2dsv.js", - "tsv2json": "bin/dsv2json.js" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-dsv/node_modules/iconv-lite": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", - "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", - "dev": true, - "license": "MIT", - "dependencies": { - "safer-buffer": ">= 2.1.2 < 3.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/d3-ease": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/d3-ease/-/d3-ease-3.0.2.tgz", - "integrity": "sha512-B5znKqRmKROAN4oHWQ50W/qisVjA9GXh2WMsVKdFVp4DxWmcrOsweqgUOUVsv5th96kwaZlokU6SlV4J3gak1w==", - "dev": true, - "license": "BSD-3-Clause", - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-fetch": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/d3-fetch/-/d3-fetch-3.0.2.tgz", - "integrity": "sha512-1wGF62bgjMRbF6mqbD+6rRWBL2hwWVYQjFO2UP3Wm1nIAvJZKaQxXM5caVY7athoCa8wIq9lCf7g44lPWFk50g==", - "dev": true, - "license": "ISC", - "dependencies": { - "d3-dsv": "1 - 3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-force": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/d3-force/-/d3-force-3.0.1.tgz", - "integrity": "sha512-kAaaHLFebBYwgi5cYBXAI8vKrQFMCD2MEswj2QuPKKbdU1wYLc8WXtS7O8F/b6POCIe3gJjY6hkDstHi1yMETQ==", - "dev": true, - "license": "ISC", - "dependencies": { - "d3-dispatch": "1 - 3", - "d3-quadtree": "1 - 3", - "d3-timer": "1 - 3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-format": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/d3-format/-/d3-format-3.1.3.tgz", - "integrity": "sha512-+F+/49swqmGuQJmSKnVMIDH/QkEFV5li9QRj0xm/KhyAUBv099O5PrvpQFxBp24PYph17Mnvt9mjKQV0ii0nMA==", - "dev": true, - "license": "ISC", - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-geo": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/d3-geo/-/d3-geo-3.1.2.tgz", - "integrity": "sha512-5R8ZgDQorIxmauv7R6gpE/ndz+Z0qAZssigq0aXFdvPHdY41RqtW02jrRUQAL724NdPABYXo1+gQEGBBr7uKNg==", - "dev": true, - "license": "ISC", - "dependencies": { - "d3-array": "2.5.0 - 3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-hierarchy": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/d3-hierarchy/-/d3-hierarchy-3.1.3.tgz", - "integrity": "sha512-GRajN5ZcnEwYFWqqdzhG1qJ3+fDg6WWzk47TJg7ePY7yvYAgRfD2r1mUx+wviBOWuCwamCUzjwMSdato43jbGA==", - "dev": true, - "license": "ISC", - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-interpolate": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/d3-interpolate/-/d3-interpolate-3.0.2.tgz", - "integrity": "sha512-IRzGU62DtxhvsnSTWMQIdnoZ6gA+BCWwBon1EJI6SjoN595799b6z/QRBzXfFhE8iupUPp3042yBNo0STPqnzQ==", - "dev": true, - "license": "ISC", - "dependencies": { - "d3-color": "1 - 3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-path": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/d3-path/-/d3-path-3.1.1.tgz", - "integrity": "sha512-jsbgV8zIT38ReB9O7X7gcLndTQRONSqNNd+oGIaTBdUug4r5jFmp0N6RY9R5GWbdUDucn0qoTGyfjapT4tDhcg==", - "dev": true, - "license": "ISC", - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-polygon": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/d3-polygon/-/d3-polygon-3.0.2.tgz", - "integrity": "sha512-WAUvPudGU1Dn4mDPfb6+JnnbeVEV53hG/BoT+bxts6AkZsOpTEiV1jHYX+2vtwCICNFG9Wxv8QS+eW1zE/Dwfg==", - "dev": true, - "license": "ISC", - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-quadtree": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/d3-quadtree/-/d3-quadtree-3.0.2.tgz", - "integrity": "sha512-9Lu9mqJKRbIk0d6mKDjpvPURaPdwHVK5CYbcdd0/4vBgz4ldz/7TIOse3kNERsByGNfld58KEco507AztJWyTQ==", - "dev": true, - "license": "ISC", - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-random": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/d3-random/-/d3-random-3.0.2.tgz", - "integrity": "sha512-PxJi9LNV+7mulaYO77nd+oGurXGL1fhedXjHnB3pWLUcqDnQtF4VASoqnQGHgoXLByVdv5QJ/2kfwkGn5HTS8g==", - "dev": true, - "license": "ISC", - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-sankey": { - "version": "0.12.3", - "resolved": "https://registry.npmjs.org/d3-sankey/-/d3-sankey-0.12.3.tgz", - "integrity": "sha512-nQhsBRmM19Ax5xEIPLMY9ZmJ/cDvd1BG3UVvt5h3WRxKg5zGRbvnteTyWAbzeSvlh3tW7ZEmq4VwR5mB3tutmQ==", - "dev": true, - "license": "BSD-3-Clause", - "dependencies": { - "d3-array": "1 - 2", - "d3-shape": "^1.2.0" - } - }, - "node_modules/d3-sankey/node_modules/d3-array": { - "version": "2.12.1", - "resolved": "https://registry.npmjs.org/d3-array/-/d3-array-2.12.1.tgz", - "integrity": "sha512-B0ErZK/66mHtEsR1TkPEEkwdy+WDesimkM5gpZr5Dsg54BiTA5RXtYW5qTLIAcekaS9xfZrzBLF/OAkB3Qn1YQ==", - "dev": true, - "license": "BSD-3-Clause", - "dependencies": { - "internmap": "^1.0.0" - } - }, - "node_modules/d3-sankey/node_modules/d3-path": { - "version": "1.0.9", - "resolved": "https://registry.npmjs.org/d3-path/-/d3-path-1.0.9.tgz", - "integrity": "sha512-VLaYcn81dtHVTjEHd8B+pbe9yHWpXKZUC87PzoFmsFrJqgFwDe/qxfp5MlfsfM1V5E/iVt0MmEbWQ7FVIXh/bg==", - "dev": true, - "license": "BSD-3-Clause" - }, - "node_modules/d3-sankey/node_modules/d3-shape": { - "version": "1.3.7", - "resolved": "https://registry.npmjs.org/d3-shape/-/d3-shape-1.3.7.tgz", - "integrity": "sha512-EUkvKjqPFUAZyOlhY5gzCxCeI0Aep04LwIRpsZ/mLFelJiUfnK56jo5JMDSE7yyP2kLSb6LtF+S5chMk7uqPqw==", - "dev": true, - "license": "BSD-3-Clause", - "dependencies": { - "d3-path": "1" - } - }, - "node_modules/d3-sankey/node_modules/internmap": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/internmap/-/internmap-1.0.1.tgz", - "integrity": "sha512-lDB5YccMydFBtasVtxnZ3MRBHuaoE8GKsppq+EchKL2U4nK/DmEpPHNH8MZe5HkMtpSiTSOZwfN0tzYjO/lJEw==", - "dev": true, - "license": "ISC" - }, - "node_modules/d3-scale": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/d3-scale/-/d3-scale-4.0.3.tgz", - "integrity": "sha512-66cWobCNzcMvlfoaDHCxuIv9TBUWG1BLOWdv9kHHFuCr1JdqAWPvTmsaEYDD5NRMyWZ5+7u0GqiCDfMXMqh3hg==", - "dev": true, - "license": "ISC", - "dependencies": { - "d3-array": "2.10.0 - 3", - "d3-format": "1 - 3", - "d3-interpolate": "1.2.0 - 3", - "d3-time": "2.1.1 - 3", - "d3-time-format": "2 - 4" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-scale-chromatic": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/d3-scale-chromatic/-/d3-scale-chromatic-3.1.1.tgz", - "integrity": "sha512-lA5gfN2yMvmChubmptnDiBfeGpHD7Yb1EbvCz0TZE0WHXhyR6W2allPuhKtzV5ILQRqeOdefF0qYtERReLUBDg==", - "dev": true, - "license": "ISC", - "dependencies": { - "d3-color": "1 - 3", - "d3-interpolate": "1 - 3", - "d3-scale": "1 - 4" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-selection": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/d3-selection/-/d3-selection-3.0.1.tgz", - "integrity": "sha512-ODSf35vqCrlCfp7hrm0eZjvOosSXSYLjqvIlhMBV9q9VOx7EBJG6pc+uXBswEZNJgCGJ+qnKYcWutbZDIxe/Xg==", - "dev": true, - "license": "ISC", - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-shape": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/d3-shape/-/d3-shape-3.2.1.tgz", - "integrity": "sha512-dm2o+lbKdzg9tY7GEag/dB9hcbodLfwkE/DkvqbELJXaMz0yKzWWhZqhbI7CKubukA7HnRyz0avdtvi7EPxPvw==", - "dev": true, - "license": "ISC", - "dependencies": { - "d3-path": "^3.1.1" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-time": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/d3-time/-/d3-time-3.1.1.tgz", - "integrity": "sha512-Ze7rjrhMzdeulh0/hjcfFj7XLAHOfowtEMfsoG6DU866HPynQNW7Wfen6hzXcqKTv8XzxvF6Hzr5XD6bMHr2ug==", - "dev": true, - "license": "ISC", - "dependencies": { - "d3-array": "2 - 3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-time-format": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/d3-time-format/-/d3-time-format-4.1.1.tgz", - "integrity": "sha512-22XaqjyCjpqgda20erhsOjGmC3vvYwTNYniKAd45W5UWLDF43moeOuV9qYpRqobIlsnK0UhnKZjUUJm3VgORUA==", - "dev": true, - "license": "ISC", - "dependencies": { - "d3-time": "1 - 3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-timer": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/d3-timer/-/d3-timer-3.0.2.tgz", - "integrity": "sha512-1Il1aliroVSErrv5aulRBxAY+7+DnaoLIWGd1C6SsBTWDeobWiP/V69vwb8vT6abR1kKwaNe1196pmaQ1fK90A==", - "dev": true, - "license": "ISC", - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-transition": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/d3-transition/-/d3-transition-3.0.2.tgz", - "integrity": "sha512-RcjCsdFgyFoDB+QXLC5m60ZkTN0k9zH+ovoLlTdJnDS1AbfbcuowiM4pCKSTOclNibS4f4J4cbv2m7O7y8NTOQ==", - "dev": true, - "license": "ISC", - "dependencies": { - "d3-color": "1 - 3", - "d3-dispatch": "1 - 3", - "d3-ease": "1 - 3", - "d3-interpolate": "1 - 3", - "d3-timer": "1 - 3" - }, - "engines": { - "node": ">=12" - }, - "peerDependencies": { - "d3-selection": "2 - 3" - } - }, - "node_modules/d3-zoom": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/d3-zoom/-/d3-zoom-3.0.1.tgz", - "integrity": "sha512-kfjD3BDQu/FOatpZ6JdMSyIoDwTxIpI29ySTI2J5ZlDaH1WbuJGQJ2Q9oJkWTEZEW98j6idezoomSD3Cn2zwiw==", - "dev": true, - "license": "ISC", - "dependencies": { - "d3-dispatch": "1 - 3", - "d3-drag": "2 - 3", - "d3-interpolate": "1 - 3", - "d3-selection": "2 - 3", - "d3-transition": "2 - 3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/dagre-d3-es": { - "version": "7.0.14", - "resolved": "https://registry.npmjs.org/dagre-d3-es/-/dagre-d3-es-7.0.14.tgz", - "integrity": "sha512-P4rFMVq9ESWqmOgK+dlXvOtLwYg0i7u0HBGJER0LZDJT2VHIPAMZ/riPxqJceWMStH5+E61QxFra9kIS3AqdMg==", - "dev": true, - "license": "MIT", - "dependencies": { - "d3": "^7.9.0", - "lodash-es": "^4.17.21" - } - }, - "node_modules/dayjs": { - "version": "1.11.23", - "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.23.tgz", - "integrity": "sha512-QDTCU0M0MxR3hQfnlDJfwekQiaanm1ubOD231u73WBckQ/fsamwRLiE2GBz6D3a/xF1NgfiDLJjXBa1hYOYTtQ==", - "dev": true, - "license": "MIT" - }, - "node_modules/debug": { - "version": "4.4.3", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", - "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", - "dev": true, - "license": "MIT", - "dependencies": { - "ms": "^2.1.3" - }, - "engines": { - "node": ">=6.0" - }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } - } - }, - "node_modules/decode-bmp": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/decode-bmp/-/decode-bmp-0.2.1.tgz", - "integrity": "sha512-NiOaGe+GN0KJqi2STf24hfMkFitDUaIoUU3eKvP/wAbLe8o6FuW5n/x7MHPR0HKvBokp6MQY/j7w8lewEeVCIA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@canvas/image-data": "^1.0.0", - "to-data-view": "^1.1.0" - }, - "engines": { - "node": ">=8.6.0" - } - }, - "node_modules/decode-ico": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/decode-ico/-/decode-ico-0.4.1.tgz", - "integrity": "sha512-69NZfbKIzux1vBOd31al3XnMnH+2mqDhEgLdpygErm4d60N+UwA5Sq5WFjmEDQzumgB9fElojGwWG0vybVfFmA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@canvas/image-data": "^1.0.0", - "decode-bmp": "^0.2.0", - "to-data-view": "^1.1.0" - }, - "engines": { - "node": ">=8.6" - } - }, - "node_modules/decode-named-character-reference": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/decode-named-character-reference/-/decode-named-character-reference-1.3.0.tgz", - "integrity": "sha512-GtpQYB283KrPp6nRw50q3U9/VfOutZOe103qlN7BPP6Ad27xYnOIWv4lPzo8HCAL+mMZofJ9KEy30fq6MfaK6Q==", - "dev": true, - "license": "MIT", - "dependencies": { - "character-entities": "^2.0.0" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/dedent": { - "version": "1.7.2", - "resolved": "https://registry.npmjs.org/dedent/-/dedent-1.7.2.tgz", - "integrity": "sha512-WzMx3mW98SN+zn3hgemf4OzdmyNhhhKz5Ay0pUfQiMQ3e1g+xmTJWp/pKdwKVXhdSkAEGIIzqeuWrL3mV/AXbA==", - "dev": true, - "license": "MIT", - "peerDependencies": { - "babel-plugin-macros": "^3.1.0" - }, - "peerDependenciesMeta": { - "babel-plugin-macros": { - "optional": true - } + "peerDependenciesMeta": { + "babel-plugin-macros": { + "optional": true + } } }, "node_modules/dedent-js": { @@ -7047,16 +6106,6 @@ "dev": true, "license": "MIT" }, - "node_modules/delaunator": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/delaunator/-/delaunator-5.1.0.tgz", - "integrity": "sha512-AGrQ4QSgssa1NGmWmLPqN5NY2KajF5MqxetNEO+o0n3ZwZZeTmt7bBnvzHWrmkZFxGgr4HdyFgelzgi06otLuQ==", - "dev": true, - "license": "ISC", - "dependencies": { - "robust-predicates": "^3.0.2" - } - }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -7848,16 +6897,6 @@ ], "license": "BSD-3-Clause" }, - "node_modules/fastdom": { - "version": "1.0.12", - "resolved": "https://registry.npmjs.org/fastdom/-/fastdom-1.0.12.tgz", - "integrity": "sha512-LB+xjSTEbjHE1cWsxu+tN2Xqr1kpi+V9aADI7sVM5ZMaXyYGPHULQMzpJMYqOTULK/73pUkWVzzObFRBkPr+hg==", - "dev": true, - "license": "MIT", - "dependencies": { - "strictdom": "^1.0.1" - } - }, "node_modules/fdir": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", @@ -8102,13 +7141,6 @@ "dev": true, "license": "ISC" }, - "node_modules/hachure-fill": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/hachure-fill/-/hachure-fill-0.5.2.tgz", - "integrity": "sha512-3GKBOn+m2LX9iq+JC1064cSFprJY4jL1jCXTcpnfER5HYE2l/4EfWSGzkPa/ZDBmYI0ZOEj5VHV/eKnPGkHuOg==", - "dev": true, - "license": "MIT" - }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -8519,17 +7551,6 @@ "dev": true, "license": "MIT" }, - "node_modules/import-meta-resolve": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/import-meta-resolve/-/import-meta-resolve-4.2.0.tgz", - "integrity": "sha512-Iqv2fzaTQN28s/FwZAoFq0ZSs/7hMAHJVX+w8PZl3cY19Pxk6jFFalxQoIfW2826i/fDLXv8IiEZRIT0lDuWcg==", - "dev": true, - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", @@ -8564,16 +7585,6 @@ "dev": true, "license": "MIT" }, - "node_modules/internmap": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/internmap/-/internmap-2.0.3.tgz", - "integrity": "sha512-5Hh7Y1wQbvY5ooGgPbDaL5iYLAPzMTUrjMulskHLH6wnv/A+1q5rgEaiuqEjB+oxGXIVZs1FF+R/KPN3ZSQYYg==", - "dev": true, - "license": "ISC", - "engines": { - "node": ">=12" - } - }, "node_modules/ip-address": { "version": "10.7.6", "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.7.6.tgz", @@ -8856,12 +7867,6 @@ "@keyv/serialize": "^1.1.1" } }, - "node_modules/khroma": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/khroma/-/khroma-2.1.0.tgz", - "integrity": "sha512-Ls993zuzfayK269Svk9hzpeGUKob/sIgZzyHYdjQoAdQetRKpOLj+k/QQQ/6Qi0Yz65mlROrfd+Ev+1+7dz9Kw==", - "dev": true - }, "node_modules/known-css-properties": { "version": "0.37.0", "resolved": "https://registry.npmjs.org/known-css-properties/-/known-css-properties-0.37.0.tgz", @@ -8869,13 +7874,6 @@ "dev": true, "license": "MIT" }, - "node_modules/layout-base": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/layout-base/-/layout-base-1.0.2.tgz", - "integrity": "sha512-8h2oVEZNktL4BH2JCOI90iD1yXwL6iNW7KcCKT2QZgQJR2vbqDsldCTPRU9NifTCqHZci57XvQQ15YTu+sTYPg==", - "dev": true, - "license": "MIT" - }, "node_modules/levn": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", @@ -9196,13 +8194,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/lodash-es": { - "version": "4.18.1", - "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.18.1.tgz", - "integrity": "sha512-J8xewKD/Gk22OZbhpOVSwcs60zhd95ESDwezOFuA3/099925PdHJ7OFHNTGtajL3AlZkykD32HykiMo+BIBI8A==", - "dev": true, - "license": "MIT" - }, "node_modules/longest-streak": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/longest-streak/-/longest-streak-3.1.0.tgz", @@ -9296,19 +8287,6 @@ "url": "https://github.com/sponsors/wooorm" } }, - "node_modules/marked": { - "version": "16.4.2", - "resolved": "https://registry.npmjs.org/marked/-/marked-16.4.2.tgz", - "integrity": "sha512-TI3V8YYWvkVf3KJe1dRkpnjs68JUPyEa5vjKrp1XEEJUAOaQc+Qj+L1qWbPd0SJuAdQkFU0h73sXXqwDYxsiDA==", - "dev": true, - "license": "MIT", - "bin": { - "marked": "bin/marked.js" - }, - "engines": { - "node": ">= 20" - } - }, "node_modules/math-intrinsics": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", @@ -9687,37 +8665,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/mermaid": { - "version": "11.17.2", - "resolved": "https://registry.npmjs.org/mermaid/-/mermaid-11.17.2.tgz", - "integrity": "sha512-V6K3C8EBdEsPFZXSKMJe6ppQOENxuHARr9GvHX4hh47lAbhMRD9qf4oEK7LoaRQxULMa80/qt5gHO73aCleBBg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@braintree/sanitize-url": "^7.1.2", - "@iconify/utils": "^3.0.2", - "@mermaid-js/parser": "^1.2.1", - "@types/d3": "^7.4.3", - "@upsetjs/venn.js": "^2.0.0", - "cytoscape": "^3.34.0", - "cytoscape-cose-bilkent": "^4.1.0", - "cytoscape-fcose": "^2.2.0", - "d3": "^7.9.0", - "d3-sankey": "^0.12.3", - "dagre-d3-es": "7.0.14", - "dayjs": "^1.11.21", - "dompurify": "^3.3.3", - "es-toolkit": "^1.45.1", - "fastdom": "1.0.12", - "katex": "^0.16.47", - "khroma": "^2.1.0", - "marked": "^16.3.0", - "roughjs": "^4.6.6", - "stylis": "^4.3.6", - "ts-dedent": "^2.2.0", - "uuid": "^11.1.0 || ^12 || ^13 || ^14.0.0" - } - }, "node_modules/micromark": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/micromark/-/micromark-4.0.3.tgz", @@ -10803,13 +9750,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/package-manager-detector": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/package-manager-detector/-/package-manager-detector-1.9.0.tgz", - "integrity": "sha512-zAMfbta9nPA8AKkA4WdmNAT8R8s6Dk0/xwPsqNnRidMFcLo1YkLuPDTgs2f64XdzS8vbLNnoJ+uUIkgbz7oRHA==", - "dev": true, - "license": "MIT" - }, "node_modules/parse5": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/parse5/-/parse5-8.1.1.tgz", @@ -10833,13 +9773,6 @@ "node": ">= 0.8" } }, - "node_modules/path-data-parser": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/path-data-parser/-/path-data-parser-0.1.0.tgz", - "integrity": "sha512-NOnmBpt5Y2RWbuv0LMzsayp3lVylAHLPUTut412ZA3l+C4uw4ZVkQbjShYCQ8TCpUMdPapr4YjUqLYD6v68j+w==", - "dev": true, - "license": "MIT" - }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -10901,6 +9834,16 @@ "@napi-rs/canvas": "^0.1.74" } }, + "node_modules/pele": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/pele/-/pele-1.13.0.tgz", + "integrity": "sha512-Ie8UKY9x00MsuR3jO6AzUwzK2Z6MIV3Tf4EDdITiuk8Uaz8K7g0R082WqsqNaSU8DdgkrRvZThzhit83mi/uiw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=20" + } + }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", @@ -10973,24 +9916,6 @@ "node": ">=14.19.0" } }, - "node_modules/points-on-curve": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/points-on-curve/-/points-on-curve-0.2.0.tgz", - "integrity": "sha512-0mYKnYYe9ZcqMCWhUjItv/oHjvgEsfKvnUTg8sAtnHr3GVy7rGkXCb6d5cSyqrWqL4k81b9CPg3urd+T7aop3A==", - "dev": true, - "license": "MIT" - }, - "node_modules/points-on-path": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/points-on-path/-/points-on-path-0.2.1.tgz", - "integrity": "sha512-25ClnWWuw7JbWZcgqY/gJ4FQWadKxGWk+3kR/7kD0tCaDtPPMj7oHu2ToLaVhfpnHrZzYby2w6tUA0eOIuUg8g==", - "dev": true, - "license": "MIT", - "dependencies": { - "path-data-parser": "0.1.0", - "points-on-curve": "0.2.0" - } - }, "node_modules/portfinder": { "version": "1.0.38", "resolved": "https://registry.npmjs.org/portfinder/-/portfinder-1.0.38.tgz", @@ -11713,13 +10638,6 @@ "dev": true, "license": "MIT" }, - "node_modules/robust-predicates": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/robust-predicates/-/robust-predicates-3.0.3.tgz", - "integrity": "sha512-NS3levdsRIUOmiJ8FZWCP7LG3QpJyrs/TE0Zpf1yvZu8cAJJ6QMW92H1c7kWpdIHo8RvmLxN/o2JXTKHp74lUA==", - "dev": true, - "license": "Unlicense" - }, "node_modules/rolldown": { "version": "1.2.18", "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.2.18.tgz", @@ -11764,19 +10682,6 @@ "url": "https://github.com/sponsors/oxc-project" } }, - "node_modules/roughjs": { - "version": "4.6.6", - "resolved": "https://registry.npmjs.org/roughjs/-/roughjs-4.6.6.tgz", - "integrity": "sha512-ZUz/69+SYpFN/g/lUlo2FXcIjRkSu3nDarreVdGGndHEBJ6cXPdKguS8JGxwj5HA5xIbVKSmLgr5b3AWxtRfvQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "hachure-fill": "^0.5.2", - "path-data-parser": "^0.1.0", - "points-on-curve": "^0.2.0", - "points-on-path": "^0.2.1" - } - }, "node_modules/router": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", @@ -11823,13 +10728,6 @@ "svelte": "^5.7.0" } }, - "node_modules/rw": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/rw/-/rw-1.3.3.tgz", - "integrity": "sha512-PdhdWy89SiZogBLaw42zdeqtRJ//zFd2PgQavcICDUgJT5oW10QCRKbJ6bg4r0/UY2M6BWd5tkxuGFRvCkgfHQ==", - "dev": true, - "license": "BSD-3-Clause" - }, "node_modules/sade": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/sade/-/sade-1.8.1.tgz", @@ -12273,13 +11171,6 @@ "url": "https://opencollective.com/vitest" } }, - "node_modules/strictdom": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/strictdom/-/strictdom-1.0.1.tgz", - "integrity": "sha512-cEmp9QeXXRmjj/rVp9oyiqcvyocWab/HaoN4+bwFeZ7QzykJD6L3yD4v12K1x0tHpqRqVpJevN3gW7kyM39Bqg==", - "dev": true, - "license": "MIT" - }, "node_modules/stringify-entities": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/stringify-entities/-/stringify-entities-4.0.4.tgz", @@ -12354,13 +11245,6 @@ "inline-style-parser": "0.2.7" } }, - "node_modules/stylis": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/stylis/-/stylis-4.4.0.tgz", - "integrity": "sha512-5Z9ZpRzfuH6l/UAvCPAPUo3665Nk2wLaZU3x+TLHKVzIz33+sbJqbtrYoC3KD4/uVOr2Zp+L0LySezP9OHV9yA==", - "dev": true, - "license": "MIT" - }, "node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", diff --git a/ui/apps/chat/package.json b/ui/apps/chat/package.json index b7716287ceb5..bc3f0d3315d1 100644 --- a/ui/apps/chat/package.json +++ b/ui/apps/chat/package.json @@ -110,8 +110,8 @@ "dompurify": "3.4.17", "eslint": "10.14.0", "eslint-config-prettier": "10.1.8", - "eslint-plugin-perfectionist": "^5.10.1", - "eslint-plugin-simple-import-sort": "^14.0.0", + "eslint-plugin-perfectionist": "5.13.0", + "eslint-plugin-simple-import-sort": "14.0.0", "eslint-plugin-storybook": "10.6.6", "eslint-plugin-svelte": "3.24.1", "fflate": "0.8.3", @@ -120,9 +120,9 @@ "http-server": "14.1.1", "@ggml-org/llama-brand": "0.1.0", "mdsvex": "0.12.7", - "mermaid": "11.17.2", "mode-watcher": "1.1.0", "pdfjs-dist": "5.4.54", + "pele": "1.13.0", "playwright": "1.56.1", "prettier": "3.8.3", "prettier-plugin-svelte": "4.1.0", diff --git a/ui/apps/chat/scripts/vite-plugin-nerdamer.ts b/ui/apps/chat/scripts/vite-plugin-nerdamer.ts index 84e463c6d764..c1551eb5aca8 100644 --- a/ui/apps/chat/scripts/vite-plugin-nerdamer.ts +++ b/ui/apps/chat/scripts/vite-plugin-nerdamer.ts @@ -10,7 +10,9 @@ const RESOLVED_ID = '\0' + VIRTUAL_ID; /** * Bundle the vendored nerdamer-prime source into a minified IIFE string, - * exposed as the `virtual:nerdamer` module. Flags mirror the upstream + * loaded through the `virtual:nerdamer` module. In the client build it is + * its own file, fetched on first use, so it stays out of the app bundle. + * Flags mirror the upstream * build (esbuild --bundle --minify --format=iife --global-name=nerdamer), * so only human readable source lives in the repo and minification is a * build artifact. Vendored under src/lib/vendors/, upstream snapshot: @@ -41,7 +43,13 @@ export function nerdamerPlugin(): Plugin { bundled = result.outputFiles[0].text; } - return `export default ${JSON.stringify(bundled)};`; + if (this.environment.mode === 'build' && this.environment.name === 'client') { + const ref = this.emitFile({ name: 'nerdamer.js', source: bundled, type: 'asset' }); + + return `export default () => fetch(import.meta.ROLLUP_FILE_URL_${ref}).then((res) => res.text());`; + } + + return `export default async () => ${JSON.stringify(bundled)};`; }, name: 'llamacpp:nerdamer', resolveId(id) { diff --git a/ui/apps/chat/src/app.css b/ui/apps/chat/src/app.css index 4c7fd90160a3..cca440844162 100644 --- a/ui/apps/chat/src/app.css +++ b/ui/apps/chat/src/app.css @@ -356,8 +356,22 @@ } } -.mermaidTooltip { - display: none !important; +/* + * Mermaid diagrams are drawn by Pele, which reads its colors from these. They sit on :root + * so the svg also inherits them inside the preview dialog's shadow root, and follow the theme. + */ +:root { + --pele-bg: var(--code-background); + --pele-fg: var(--code-foreground); + --pele-muted: var(--muted-foreground); + --pele-line: var(--muted-foreground); + --pele-surface: var(--background); + --pele-surface-alt: var(--muted); + --pele-border: var(--border); + --pele-accent: var(--primary); + --pele-critical: var(--destructive); + --pele-error: var(--destructive); + --pele-radius: calc(var(--radius) - 4px); } /* diff --git a/ui/apps/chat/src/lib/components/app/content/MarkdownContent/MarkdownContent.svelte b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/MarkdownContent.svelte index ab3c5ffecba5..0edd8cbcde15 100644 --- a/ui/apps/chat/src/lib/components/app/content/MarkdownContent/MarkdownContent.svelte +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/MarkdownContent.svelte @@ -625,7 +625,7 @@ if ((hasRenderedBlocks || hasUnstableBlock) && containerRef) { setupCodeBlockActions(); setupImageErrorHandlers(); - renderMermaidDiagrams(containerRef, mode.current === ColorMode.DARK); + renderMermaidDiagrams(containerRef); renderSvgDiagrams(containerRef); } }); diff --git a/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-content.css b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-content.css index 49aee0e04c72..49e04bf0c6a2 100644 --- a/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-content.css +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-content.css @@ -626,10 +626,24 @@ div.markdown-user-content :global(.table-wrapper) { /* Hide mermaid code text until rendered - prevents flash */ .markdown-content :global(pre.mermaid:not([data-mermaid-rendered])), -.markdown-content :global(pre.mermaid[data-mermaid-rendered]:not(:has(svg))) { +.markdown-content :global(pre.mermaid[data-mermaid-rendered]:not(:has(svg, .mermaid-error))) { display: none; } +/* A diagram Pele can't draw shows why, with the line it stopped at */ +.markdown-content :global(.mermaid-error) { + max-width: 100%; + padding: 1rem; + color: var(--destructive); + font-family: var(--font-mono); + font-size: 0.8125rem; + /* the caret line under the source must line up character by character */ + font-variant-ligatures: none; + text-align: left; + white-space: pre-wrap; + cursor: default; +} + /* Hide svg source until rendered - prevents flash. A rendered-but-unsanitized block (oversized source) keeps its raw text visible as a safe fallback. */ .markdown-content :global(pre.svg-block:not([data-svg-rendered])) { diff --git a/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-diagrams.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-diagrams.ts index 4bb7e44b3db9..ba607bfbce06 100644 --- a/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-diagrams.ts +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-diagrams.ts @@ -7,9 +7,15 @@ import { DIAGRAM_VIEW_RENDERED, DIAGRAM_VIEW_SOURCE, MERMAID_BLOCK_CLASS, + MERMAID_ERROR_CLASS, + MERMAID_ID_ATTR, MERMAID_RENDERED_ATTR, + MERMAID_SCROLL_CONTAINER_CLASS, + MERMAID_SVG_PADDING_X_REM, MERMAID_SYNTAX_ATTR, MERMAID_WRAPPER_CLASS, + PELE_SVG_CLASS, + PELE_THEME_VARIABLES, SVG, TOGGLE_SOURCE_BTN_CLASS } from '#lib/constants/index.ts'; @@ -19,11 +25,30 @@ import { mountSvgShadow } from '#lib/utils/svg-shadow.ts'; export type DiagramAction = { copy: string } | { previewSvg: string }; +// The width a diagram can take in its block: the scroll container's content box, less the +// svg's own horizontal padding. Undefined when the block isn't laid out (detached, hidden). +function diagramWidth(node: HTMLElement): number | undefined { + const scroll = node.closest(`.${MERMAID_SCROLL_CONTAINER_CLASS}`); + + if (!scroll?.clientWidth) return undefined; + + const box = getComputedStyle(scroll); + const rem = parseFloat(getComputedStyle(document.documentElement).fontSize); + const width = + scroll.clientWidth - + parseFloat(box.paddingLeft) - + parseFloat(box.paddingRight) - + MERMAID_SVG_PADDING_X_REM * rem; + + return width > 0 ? width : undefined; +} + /** - * Renders the mermaid diagrams in `container` that haven't been rendered yet. - * Marks nodes immediately to prevent duplicate renders during streaming. + * Renders the mermaid diagrams in `container` that haven't been rendered yet, with Pele. + * Marks nodes immediately to prevent duplicate renders during streaming. Colors come + * from the `--pele-*` variables in app.css, so a diagram follows the theme without a redraw. */ -export async function renderMermaidDiagrams(container: HTMLElement, isDark: boolean) { +export async function renderMermaidDiagrams(container: HTMLElement) { const nodes = container.querySelectorAll( `pre.${MERMAID_BLOCK_CLASS}:not([${MERMAID_RENDERED_ATTR}])` ); @@ -34,32 +59,56 @@ export async function renderMermaidDiagrams(container: HTMLElement, isDark: bool // This avoids needing a guard that would block node discovery. nodes.forEach((node) => node.setAttribute(MERMAID_RENDERED_ATTR, BooleanString.TRUE)); - // lazy load the mermaid dependecy only when needed to reduce bundle size. - const { default: mermaid } = await import('mermaid'); - - mermaid.initialize({ - flowchart: { - htmlLabels: true, - useMaxWidth: false - }, - gantt: { - useMaxWidth: false - }, - securityLevel: 'strict', - sequence: { - useMaxWidth: false - }, - startOnLoad: false, - theme: isDark ? 'dark' : 'default' - }); + const { render } = await import('pele'); - try { - await mermaid.run({ nodes: Array.from(nodes) as unknown as NodeListOf }); - } catch (error) { - console.error('Failed to render mermaid diagram:', error); + // Pele measures labels with the font it is given, so wait until the page font is in + await document.fonts?.ready; + + for (const node of nodes) { + const source = node.getAttribute(MERMAID_SYNTAX_ATTR) ?? node.textContent ?? ''; + const id = node.getAttribute(MERMAID_ID_ATTR); + + try { + const { svg } = render(source, { + fontFamily: getComputedStyle(node).fontFamily, + idPrefix: id ? id.replace(/[^\w-]/g, '_') : undefined, + // narrow blocks (phones) may turn a left-to-right diagram top-to-bottom + maxWidth: diagramWidth(node) + }); + + node.innerHTML = svg; + } catch (error) { + // the message quotes the diagram source, so it goes in as text + const message = document.createElement('div'); + + message.className = MERMAID_ERROR_CLASS; + message.textContent = error instanceof Error ? error.message : String(error); + node.replaceChildren(message); + } } } +/** + * A Pele diagram takes its colors from the page's `--pele-*` variables. Writes their current + * values into the svg, so a downloaded file keeps the colors it had on screen. Any other svg + * comes back unchanged. + */ +export function withThemeColors(svgHtml: string): string { + const svg = new DOMParser().parseFromString(svgHtml, 'image/svg+xml').documentElement; + + if (!(svg instanceof SVGElement) || !svg.classList.contains(PELE_SVG_CLASS)) return svgHtml; + + const theme = getComputedStyle(document.documentElement); + + for (const name of PELE_THEME_VARIABLES) { + const value = theme.getPropertyValue(name).trim(); + + if (value) svg.style.setProperty(name, value); + } + + return new XMLSerializer().serializeToString(svg); +} + /** * Renders the svg diagrams in `container` that haven't been rendered yet. * Sanitizes the source before injecting and marks each node so it renders once. diff --git a/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-processor.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-processor.ts index d7c4feac6b86..aed4b93e50d0 100644 --- a/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-processor.ts +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-processor.ts @@ -13,6 +13,7 @@ import { rehypeEnhanceMermaidBlocks } from './plugins/rehype/enhance-mermaid-blo import { rehypeEnhanceSvgBlocks } from './plugins/rehype/enhance-svg-blocks'; import { rehypeEnhanceTables } from './plugins/rehype/enhance-tables'; import { rehypeFileBadge } from './plugins/rehype/file-badge'; +import { rehypeLazyKatex } from './plugins/rehype/lazy-katex'; import { rehypeMermaidPre } from './plugins/rehype/mermaid-pre'; import { rehypeRtlSupport } from './plugins/rehype/rehype-rtl-support'; import { rehypeResolveAttachmentImages } from './plugins/rehype/resolve-attachment-images'; @@ -25,7 +26,6 @@ import type { Root as HastRoot } from 'hast'; import { all as lowlightAll } from 'lowlight'; import type { Root as MdastRoot } from 'mdast'; import rehypeHighlight from 'rehype-highlight'; -import rehypeKatex from 'rehype-katex'; import rehypeStringify from 'rehype-stringify'; import { remark } from 'remark'; import remarkBreaks from 'remark-breaks'; @@ -71,7 +71,7 @@ function buildPipeline({ proc = proc.use(remarkRehype, allowHtml ? { allowDangerousHtml: true } : undefined); if (!disableMath) { - proc = proc.use(rehypeKatex); // Render math using KaTeX + proc = proc.use(rehypeLazyKatex); // Render math using KaTeX, loaded on the first message with math } const pipeline = proc diff --git a/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/lazy-katex.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/lazy-katex.ts new file mode 100644 index 000000000000..e94a36bf4a6f --- /dev/null +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/lazy-katex.ts @@ -0,0 +1,56 @@ +/** + * Rehype plugin that renders math with rehype-katex, loading KaTeX only when a message has math. + * + * remark-math marks math as elements with a `language-math`, `math-inline` or `math-display` + * class; a tree without one is left alone, so a chat without math never downloads KaTeX. + */ + +import type { Element, Root } from 'hast'; +import type { Plugin, Transformer } from 'unified'; +import { visit } from 'unist-util-visit'; + +const MATH_CLASSES = ['language-math', 'math-inline', 'math-display']; + +let katexLoading: Promise> | undefined; +let katexTransformer: Transformer | undefined; + +function hasMath(tree: Root): boolean { + let found = false; + + visit(tree, 'element', (node: Element) => { + const className = node.properties?.className; + + if (Array.isArray(className) && className.some((c) => MATH_CLASSES.includes(String(c)))) { + found = true; + + return false; + } + }); + + return found; +} + +// synchronous when there is no math or KaTeX has loaded, so only the first message with math +// waits for it, and every other one renders in the same pass as before +export const rehypeLazyKatex: Plugin<[], Root> = () => { + return (tree, file) => { + if (!hasMath(tree)) return; + + // rehype-katex changes the tree in place + if (katexTransformer) { + katexTransformer(tree, file, () => {}); + + return; + } + + katexLoading ??= import('rehype-katex').then(({ default: rehypeKatex }) => { + katexTransformer = rehypeKatex() as Transformer; + + return katexTransformer; + }); + + return katexLoading.then((transform) => { + transform(tree, file, () => {}); + }); + }; +}; diff --git a/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-block-widget.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-block-widget.ts index 6deae1d3c6a8..66bdd3a83e3e 100644 --- a/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-block-widget.ts +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-block-widget.ts @@ -12,14 +12,12 @@ import { import { getMarkdownProcessor } from '#lib/components/app/content/MarkdownContent/markdown-processor.ts'; import { getCodeInfoFromTarget } from '#lib/components/app/content/MarkdownContent/markdown-utils.ts'; import { MERMAID_BLOCK_CLASS } from '#lib/constants/index.ts'; -import { ColorMode } from '#lib/enums/index.ts'; import { copyCodeToClipboard, copyToClipboard, preprocessLaTeX, splitGluedClosingCodeFences } from '#lib/utils/index.ts'; -import { mode } from 'mode-watcher'; export interface MarkdownBlockWidgetOptions { onPreviewCode?: (code: string, language: string) => void; @@ -311,9 +309,7 @@ export class MarkdownBlockWidget extends WidgetType { // mermaid draws asynchronously and changes the block's height when done if (dom.querySelector(`pre.${MERMAID_BLOCK_CLASS}`)) { - void renderMermaidDiagrams(dom, mode.current === ColorMode.DARK).then(() => - this.measure(dom, view, key) - ); + void renderMermaidDiagrams(dom).then(() => this.measure(dom, view, key)); } } } diff --git a/ui/apps/chat/src/lib/components/app/content/MermaidPreviewControls.svelte b/ui/apps/chat/src/lib/components/app/content/MermaidPreviewControls.svelte index 5c0e03021bcb..1899db38907d 100644 --- a/ui/apps/chat/src/lib/components/app/content/MermaidPreviewControls.svelte +++ b/ui/apps/chat/src/lib/components/app/content/MermaidPreviewControls.svelte @@ -3,6 +3,7 @@ import RotateCcwIcon from '@lucide/svelte/icons/rotate-ccw'; import ZoomInIcon from '@lucide/svelte/icons/zoom-in'; import ZoomOutIcon from '@lucide/svelte/icons/zoom-out'; + import { withThemeColors } from '#lib/components/app/content/MarkdownContent/markdown-diagrams.ts'; import { ICON_CLASS_DEFAULT } from '#lib/constants/index.ts'; interface Props { @@ -18,7 +19,7 @@ function downloadSvg() { if (!svgHtml) return; - const blob = new Blob([svgHtml], { type: 'image/svg+xml' }); + const blob = new Blob([withThemeColors(svgHtml)], { type: 'image/svg+xml' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); diff --git a/ui/apps/chat/src/lib/components/app/models/ModelsManager/row-actions.ts b/ui/apps/chat/src/lib/components/app/models/ModelsManager/row-actions.ts index 4265d129660d..274f87c0fbbb 100644 --- a/ui/apps/chat/src/lib/components/app/models/ModelsManager/row-actions.ts +++ b/ui/apps/chat/src/lib/components/app/models/ModelsManager/row-actions.ts @@ -1,4 +1,9 @@ -import { Compass, Eye, EyeOff, Heart, HeartOff, Trash2 } from '@lucide/svelte'; +import Compass from '@lucide/svelte/icons/compass'; +import Eye from '@lucide/svelte/icons/eye'; +import EyeOff from '@lucide/svelte/icons/eye-off'; +import Heart from '@lucide/svelte/icons/heart'; +import HeartOff from '@lucide/svelte/icons/heart-off'; +import Trash2 from '@lucide/svelte/icons/trash-2'; import { MODEL_DOWNLOAD_ICONS } from '#lib/constants/index.ts'; import { ModelRowDownloadState } from '#lib/enums/index.ts'; import { modelsStore, uiStore } from '#lib/stores/index.ts'; diff --git a/ui/apps/chat/src/lib/constants/icons.constants.ts b/ui/apps/chat/src/lib/constants/icons.constants.ts index fa0a36e20b38..ff2918ee2e7e 100644 --- a/ui/apps/chat/src/lib/constants/icons.constants.ts +++ b/ui/apps/chat/src/lib/constants/icons.constants.ts @@ -4,25 +4,23 @@ */ import { MODALITY_FLAG_KEYS, MODALITY_ORDER } from '@ggml-org/llama-ui/models'; -import { - CircleAlert as LoadFailedIcon, - Compass as DiscoverIcon, - Eject as UnloadIcon, - File as FileIcon, - FileText as FileTextIcon, - FolderOpen as CwdCommandIcon, - FoldVertical as CompactCommandIcon, - Image as ImageIcon, - Loader2 as LoadingIcon, - Mic as AudioIcon, - Package as ModelIcon, - Pause as PauseDownloadIcon, - Play as ResumeDownloadIcon, - Power as LoadIcon, - RotateCw as RetryIcon, - Sparkles as PromptCommandIcon, - Video as VideoIcon -} from '@lucide/svelte'; +import LoadFailedIcon from '@lucide/svelte/icons/circle-alert'; +import DiscoverIcon from '@lucide/svelte/icons/compass'; +import UnloadIcon from '@lucide/svelte/icons/eject'; +import FileIcon from '@lucide/svelte/icons/file'; +import FileTextIcon from '@lucide/svelte/icons/file-text'; +import CompactCommandIcon from '@lucide/svelte/icons/fold-vertical'; +import CwdCommandIcon from '@lucide/svelte/icons/folder-open'; +import ImageIcon from '@lucide/svelte/icons/image'; +import LoadingIcon from '@lucide/svelte/icons/loader-2'; +import AudioIcon from '@lucide/svelte/icons/mic'; +import ModelIcon from '@lucide/svelte/icons/package'; +import PauseDownloadIcon from '@lucide/svelte/icons/pause'; +import ResumeDownloadIcon from '@lucide/svelte/icons/play'; +import LoadIcon from '@lucide/svelte/icons/power'; +import RetryIcon from '@lucide/svelte/icons/rotate-cw'; +import PromptCommandIcon from '@lucide/svelte/icons/sparkles'; +import VideoIcon from '@lucide/svelte/icons/video'; import { ChatFormCommandAction, FileTypeCategory, ModelCapability } from '#lib/enums/index.ts'; import type { ModelCapabilities } from '#lib/types/models.js'; import type { Component } from 'svelte'; diff --git a/ui/apps/chat/src/lib/constants/mcp.constants.ts b/ui/apps/chat/src/lib/constants/mcp.constants.ts index 2a469ffbcce4..fffbdc9de96e 100644 --- a/ui/apps/chat/src/lib/constants/mcp.constants.ts +++ b/ui/apps/chat/src/lib/constants/mcp.constants.ts @@ -1,4 +1,6 @@ -import { Globe, Radio, Zap } from '@lucide/svelte'; +import Globe from '@lucide/svelte/icons/globe'; +import Radio from '@lucide/svelte/icons/radio'; +import Zap from '@lucide/svelte/icons/zap'; import { MimeTypeImage } from '#lib/enums/files.enums.ts'; import { MCPTransportType } from '#lib/enums/index.ts'; import type { ClientCapabilities, Implementation } from '#lib/types/index.ts'; diff --git a/ui/apps/chat/src/lib/constants/mermaid-blocks.constants.ts b/ui/apps/chat/src/lib/constants/mermaid-blocks.constants.ts index cd9467fb6e63..379e85c77304 100644 --- a/ui/apps/chat/src/lib/constants/mermaid-blocks.constants.ts +++ b/ui/apps/chat/src/lib/constants/mermaid-blocks.constants.ts @@ -1,6 +1,25 @@ export const MERMAID_WRAPPER_CLASS = 'mermaid-block-wrapper'; export const MERMAID_SCROLL_CONTAINER_CLASS = 'mermaid-scroll-container'; export const MERMAID_BLOCK_CLASS = 'mermaid'; +export const MERMAID_ERROR_CLASS = 'mermaid-error'; +// left plus right padding of a diagram's svg, see `pre.mermaid svg` in markdown-content.css +export const MERMAID_SVG_PADDING_X_REM = 2; + +// class Pele puts on the root of every diagram it draws +export const PELE_SVG_CLASS = 'pele'; +// the Pele colors app.css maps to the theme, written into a downloaded diagram +export const PELE_THEME_VARIABLES = [ + '--pele-bg', + '--pele-fg', + '--pele-muted', + '--pele-line', + '--pele-surface', + '--pele-surface-alt', + '--pele-border', + '--pele-accent', + '--pele-critical', + '--pele-radius' +] as const; export const MERMAID_LANGUAGE = 'mermaid'; diff --git a/ui/apps/chat/src/lib/constants/settings.constants.ts b/ui/apps/chat/src/lib/constants/settings.constants.ts index f3b4b2af4b15..4f1f77237a6e 100644 --- a/ui/apps/chat/src/lib/constants/settings.constants.ts +++ b/ui/apps/chat/src/lib/constants/settings.constants.ts @@ -5,19 +5,17 @@ import { DEFAULT_MCP_CONFIG } from './mcp.constants'; import { SETTINGS_KEYS } from './settings-keys.constants'; import { TITLE_GENERATION } from './title-generation.constants'; import { FILE_GLOB_SEARCH_PICKERS } from './working-directory.constants'; -import { - Code, - Database, - File, - Funnel, - GlassWater, - ListRestart, - Monitor, - Moon, - PencilRuler, - SlidersVertical, - Sun -} from '@lucide/svelte'; +import Code from '@lucide/svelte/icons/code'; +import Database from '@lucide/svelte/icons/database'; +import File from '@lucide/svelte/icons/file'; +import Funnel from '@lucide/svelte/icons/funnel'; +import GlassWater from '@lucide/svelte/icons/glass-water'; +import ListRestart from '@lucide/svelte/icons/list-restart'; +import Monitor from '@lucide/svelte/icons/monitor'; +import Moon from '@lucide/svelte/icons/moon'; +import PencilRuler from '@lucide/svelte/icons/pencil-ruler'; +import SlidersVertical from '@lucide/svelte/icons/sliders-vertical'; +import Sun from '@lucide/svelte/icons/sun'; import { SurfaceTheme, SyncableParameterType } from '#lib/enums/index.ts'; import { SettingsFieldType } from '#lib/enums/settings.enums.ts'; import { ColorMode } from '#lib/enums/ui.enums.ts'; diff --git a/ui/apps/chat/src/lib/constants/tool-ui.constants.ts b/ui/apps/chat/src/lib/constants/tool-ui.constants.ts index 12abe60e8de3..dce125262e3e 100644 --- a/ui/apps/chat/src/lib/constants/tool-ui.constants.ts +++ b/ui/apps/chat/src/lib/constants/tool-ui.constants.ts @@ -7,19 +7,17 @@ // (see ChatMessageToolCallBlockGetDatetime and // ChatMessageToolCallBlockSearchResults for prior art). -import { - Braces, - Clock, - Eye, - FilePen, - FilePlus, - FileSearch, - FileText, - Info, - MessagesSquare, - SearchCode, - Terminal -} from '@lucide/svelte'; +import Braces from '@lucide/svelte/icons/braces'; +import Clock from '@lucide/svelte/icons/clock'; +import Eye from '@lucide/svelte/icons/eye'; +import FilePen from '@lucide/svelte/icons/file-pen'; +import FilePlus from '@lucide/svelte/icons/file-plus'; +import FileSearch from '@lucide/svelte/icons/file-search'; +import FileText from '@lucide/svelte/icons/file-text'; +import Info from '@lucide/svelte/icons/info'; +import MessagesSquare from '@lucide/svelte/icons/messages-square'; +import SearchCode from '@lucide/svelte/icons/search-code'; +import Terminal from '@lucide/svelte/icons/terminal'; import { BuiltInTool, ToolSource } from '#lib/enums/index.ts'; import type { ToolUiEntry } from '#lib/types/index.ts'; diff --git a/ui/apps/chat/src/lib/constants/ui.constants.ts b/ui/apps/chat/src/lib/constants/ui.constants.ts index e76cd31b760b..5ac2adfbb247 100644 --- a/ui/apps/chat/src/lib/constants/ui.constants.ts +++ b/ui/apps/chat/src/lib/constants/ui.constants.ts @@ -6,7 +6,9 @@ import { SHORTCUT_SETTINGS } from './keyboard-shortcuts.constants'; import { MCP_SERVERS_ROUTE_ID, MODELS_ROUTE_ID, SETTINGS_ROUTE_ID } from './routes.constants'; -import { Search, Settings, SquarePen } from '@lucide/svelte'; +import Search from '@lucide/svelte/icons/search'; +import Settings from '@lucide/svelte/icons/settings'; +import SquarePen from '@lucide/svelte/icons/square-pen'; import McpLogo from '#lib/components/app/mcp/McpLogo.svelte'; import { SidebarAction, ToolSource } from '#lib/enums/index.ts'; import type { DesktopIconStripItem } from '#lib/types/index.ts'; diff --git a/ui/apps/chat/src/lib/services/sandbox.service.ts b/ui/apps/chat/src/lib/services/sandbox.service.ts index a52e688982a3..223771fc6d4e 100644 --- a/ui/apps/chat/src/lib/services/sandbox.service.ts +++ b/ui/apps/chat/src/lib/services/sandbox.service.ts @@ -33,9 +33,9 @@ async function getHarness(): Promise { if (!harnessCache[key]) { if (enabled) { - const { default: nerdamerJs } = await import('virtual:nerdamer'); + const { default: loadNerdamer } = await import('virtual:nerdamer'); - harnessCache[key] = buildSandboxHarness(nerdamerJs); + harnessCache[key] = buildSandboxHarness(await loadNerdamer()); } else { harnessCache[key] = buildSandboxHarness(''); } diff --git a/ui/apps/chat/src/lib/utils/mcp.ts b/ui/apps/chat/src/lib/utils/mcp.ts index 75ec000c2aa3..232099e2b6ee 100644 --- a/ui/apps/chat/src/lib/utils/mcp.ts +++ b/ui/apps/chat/src/lib/utils/mcp.ts @@ -1,14 +1,12 @@ import { extractRootDomain } from './url'; -import { - AlertTriangle, - Code, - Database, - File, - FileText, - Image, - Info, - XCircle -} from '@lucide/svelte'; +import AlertTriangle from '@lucide/svelte/icons/alert-triangle'; +import Code from '@lucide/svelte/icons/code'; +import Database from '@lucide/svelte/icons/database'; +import File from '@lucide/svelte/icons/file'; +import FileText from '@lucide/svelte/icons/file-text'; +import Image from '@lucide/svelte/icons/image'; +import Info from '@lucide/svelte/icons/info'; +import XCircle from '@lucide/svelte/icons/x-circle'; import { CODE_FILE_EXTENSION_REGEX, DEFAULT_RESOURCE_FILENAME, diff --git a/ui/apps/chat/src/lib/utils/pdf-processing.ts b/ui/apps/chat/src/lib/utils/pdf-processing.ts index a67a117c7ea2..ca5074db180d 100644 --- a/ui/apps/chat/src/lib/utils/pdf-processing.ts +++ b/ui/apps/chat/src/lib/utils/pdf-processing.ts @@ -5,23 +5,23 @@ import { MimeTypeApplication, MimeTypeImage } from '#lib/enums/index.ts'; import { browser } from '$app/env'; -import * as pdfjs from 'pdfjs-dist'; +import pdfWorkerUrl from 'pdfjs-dist/build/pdf.worker.min.mjs?url'; type TextContent = { items: Array<{ str: string }>; }; -if (browser) { - // Import worker as text and create blob URL for inline bundling - import('pdfjs-dist/build/pdf.worker.min.mjs?raw') - .then((workerModule) => { - const workerBlob = new Blob([workerModule.default], { type: 'application/javascript' }); - - pdfjs.GlobalWorkerOptions.workerSrc = URL.createObjectURL(workerBlob); - }) - .catch(() => { - console.warn('Failed to load PDF.js worker, PDF processing may not work'); - }); +let pdfjsModule: Promise | undefined; + +// pdf.js and its worker are files of their own, so the app loads them only when it opens a PDF +function loadPdfjs(): Promise { + pdfjsModule ??= import('pdfjs-dist').then((pdfjs) => { + pdfjs.GlobalWorkerOptions.workerSrc = pdfWorkerUrl; + + return pdfjs; + }); + + return pdfjsModule; } /** @@ -58,7 +58,7 @@ export async function convertPDFToText(file: File): Promise { } try { - const buffer = await getFileAsBuffer(file); + const [pdfjs, buffer] = await Promise.all([loadPdfjs(), getFileAsBuffer(file)]); const pdf = await pdfjs.getDocument({ data: buffer }).promise; const numPages = pdf.numPages; const textContentPromises: Promise[] = []; @@ -96,7 +96,7 @@ export async function convertPDFToImage(file: File, scale: number = 1.5): Promis } try { - const buffer = await getFileAsBuffer(file); + const [pdfjs, buffer] = await Promise.all([loadPdfjs(), getFileAsBuffer(file)]); const doc = await pdfjs.getDocument({ data: buffer }).promise; const pages: Promise[] = []; diff --git a/ui/apps/chat/src/virtual-nerdamer.d.ts b/ui/apps/chat/src/virtual-nerdamer.d.ts index 433fb2b3bd20..19fcd36f6dc7 100644 --- a/ui/apps/chat/src/virtual-nerdamer.d.ts +++ b/ui/apps/chat/src/virtual-nerdamer.d.ts @@ -1,4 +1,4 @@ declare module 'virtual:nerdamer' { - const code: string; - export default code; + const loadNerdamer: () => Promise; + export default loadNerdamer; } diff --git a/ui/apps/chat/tests/client/pdf-processing.svelte.test.ts b/ui/apps/chat/tests/client/pdf-processing.svelte.test.ts new file mode 100644 index 000000000000..63e941306b97 --- /dev/null +++ b/ui/apps/chat/tests/client/pdf-processing.svelte.test.ts @@ -0,0 +1,48 @@ +// pdf.js loads on first use, with its worker as a file of its own: extracting a PDF's text +// and drawing its pages go through that load. +import { convertPDFToImage, convertPDFToText } from '#lib/utils/pdf-processing.ts'; +import { describe, expect, it } from 'vitest'; + +/** A one-page PDF that shows `text`, with a correct cross-reference table. */ +function pdfWithText(text: string): File { + const stream = `BT /F1 24 Tf 72 720 Td (${text}) Tj ET`; + const objects = [ + '<< /Type /Catalog /Pages 2 0 R >>', + '<< /Type /Pages /Kids [3 0 R] /Count 1 >>', + '<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> >> >>', + `<< /Length ${stream.length} >>\nstream\n${stream}\nendstream`, + '<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>' + ]; + + let body = '%PDF-1.4\n'; + + const offsets: number[] = []; + + objects.forEach((object, i) => { + offsets.push(body.length); + body += `${i + 1} 0 obj\n${object}\nendobj\n`; + }); + + const xref = body.length; + const entries = offsets.map((offset) => `${String(offset).padStart(10, '0')} 00000 n \n`); + + body += `xref\n0 ${objects.length + 1}\n0000000000 65535 f \n${entries.join('')}`; + body += `trailer\n<< /Size ${objects.length + 1} /Root 1 0 R >>\nstartxref\n${xref}\n%%EOF\n`; + + return new File([body], 'hello.pdf', { type: 'application/pdf' }); +} + +describe('pdf-processing', () => { + it('extracts the text of a PDF', async () => { + const text = await convertPDFToText(pdfWithText('Hello from a PDF')); + + expect(text).toContain('Hello from a PDF'); + }); + + it('draws each page of a PDF as a PNG', async () => { + const pages = await convertPDFToImage(pdfWithText('Page one')); + + expect(pages).toHaveLength(1); + expect(pages[0]).toMatch(/^data:image\/png;base64,/); + }); +}); diff --git a/ui/apps/chat/tests/e2e/pwa.e2e.ts b/ui/apps/chat/tests/e2e/pwa.e2e.ts index 1b7636886d92..061cf5e1fd38 100644 --- a/ui/apps/chat/tests/e2e/pwa.e2e.ts +++ b/ui/apps/chat/tests/e2e/pwa.e2e.ts @@ -40,9 +40,10 @@ test.describe('PWA Service Worker', () => { const swResponse = await page.request.get(swActive!); const swContent = await swResponse.text(); - // Precache contains SvelteKit content-hashed bundle paths - expect(swContent).toMatch(/["'`]_app\/immutable\/bundle\.[a-zA-Z0-9_-]+\.js["'`]/); - expect(swContent).toMatch(/["'`]_app\/immutable\/assets\/bundle\.[a-zA-Z0-9_-]+\.css["'`]/); + // Precache contains SvelteKit's content-hashed entry points and CSS (a split build) + expect(swContent).toMatch(/["'`]_app\/immutable\/entry\/start\.[a-zA-Z0-9_-]+\.js["'`]/); + expect(swContent).toMatch(/["'`]_app\/immutable\/entry\/app\.[a-zA-Z0-9_-]+\.js["'`]/); + expect(swContent).toMatch(/["'`]_app\/immutable\/assets\/[a-zA-Z0-9_.-]+\.css["'`]/); expect(swContent).toMatch(/["'`]manifest\.webmanifest["'`]/); expect(swContent).toMatch(/["'`]_app\/version\.json["'`]/); }); @@ -120,16 +121,17 @@ test.describe('PWA Service Worker', () => { expect(manifest.icons.length).toBeGreaterThan(0); }); - test('index.html contains content-hashed bundle references', async ({ page }) => { + test('index.html contains content-hashed entry references', async ({ page }) => { const response = await page.request.get('/'); expect(response.ok()).toBeTruthy(); const html = await response.text(); - // SvelteKit outputs content-hashed bundle names in _app/immutable/ - expect(html).toMatch(/href="(\.\/|\/)_app\/immutable\/bundle\.[a-zA-Z0-9_-]+\.js"/); - expect(html).toMatch(/href="(\.\/|\/)_app\/immutable\/assets\/bundle\.[a-zA-Z0-9_-]+\.css"/); - expect(html).toMatch(/import\("(\.\/|\/)_app\/immutable\/bundle\.[a-zA-Z0-9_-]+\.js"\)/); + // a split build: SvelteKit's content-hashed entry points in _app/immutable/entry/ + expect(html).toMatch(/href="(\.\/|\/)_app\/immutable\/entry\/start\.[a-zA-Z0-9_-]+\.js"/); + expect(html).toMatch(/href="(\.\/|\/)_app\/immutable\/assets\/[a-zA-Z0-9_.-]+\.css"/); + expect(html).toMatch(/import\("(\.\/|\/)_app\/immutable\/entry\/start\.[a-zA-Z0-9_-]+\.js"\)/); + expect(html).toMatch(/import\("(\.\/|\/)_app\/immutable\/entry\/app\.[a-zA-Z0-9_-]+\.js"\)/); }); }); diff --git a/ui/apps/chat/tests/stories/content/MarkdownContent.stories.svelte b/ui/apps/chat/tests/stories/content/MarkdownContent.stories.svelte index a569a0643548..dbc8481c5ac3 100644 --- a/ui/apps/chat/tests/stories/content/MarkdownContent.stories.svelte +++ b/ui/apps/chat/tests/stories/content/MarkdownContent.stories.svelte @@ -1,7 +1,9 @@ + + +
-
zoomBy(DIAGRAM_ZOOM_FACTOR)} + onZoomOut={() => zoomBy(1 / DIAGRAM_ZOOM_FACTOR)} + scale={view.scale} {svgHtml} />
diff --git a/ui/apps/chat/src/lib/components/app/content/MermaidPreviewControls.svelte b/ui/apps/chat/src/lib/components/app/content/MermaidPreviewControls.svelte index 1899db38907d..18f96c5294cc 100644 --- a/ui/apps/chat/src/lib/components/app/content/MermaidPreviewControls.svelte +++ b/ui/apps/chat/src/lib/components/app/content/MermaidPreviewControls.svelte @@ -31,7 +31,7 @@
+ {/each} +
+ +
+{/if} diff --git a/ui/apps/chat/src/lib/components/app/models/ModelsSelector/ModelsSelectorReasoningBadge.svelte b/ui/apps/chat/src/lib/components/app/models/ModelsSelector/ModelsSelectorReasoningBadge.svelte new file mode 100644 index 000000000000..fabc65c5425c --- /dev/null +++ b/ui/apps/chat/src/lib/components/app/models/ModelsSelector/ModelsSelectorReasoningBadge.svelte @@ -0,0 +1,34 @@ + + + +{#if reasoning.isOff} + + +{:else if reasoning.currentEffort !== ReasoningEffort.DEFAULT} + + + + Reasoning {REASONING_EFFORT_LABELS[reasoning.currentEffort]} + +{/if} diff --git a/ui/apps/chat/src/lib/components/app/navigation/DropdownMenuSearchable.svelte b/ui/apps/chat/src/lib/components/app/navigation/DropdownMenuSearchable.svelte index 4bfccbc91d7e..bc652d811dba 100644 --- a/ui/apps/chat/src/lib/components/app/navigation/DropdownMenuSearchable.svelte +++ b/ui/apps/chat/src/lib/components/app/navigation/DropdownMenuSearchable.svelte @@ -18,10 +18,18 @@ searchClass?: string; children: Snippet; /** - * Optional sticky footer: it sticks to the bottom of DropdownMenu.Content's own - * scrollport, which must stay the scroll container (overflow-y-auto + max-height). + * Optional footer. By default it sticks to the bottom of the parent's scrollport + * (overflow-y-auto + max-height), see `scrollport`. */ footer?: Snippet; + /** + * Scroll the header and the list in a box of their own, with the footer under it + * instead of sticking. For a parent that scales as it opens (a dropdown's zoom-in): + * WebKit pins a bottom-sticky element against the scaled box, so the footer would + * ride up the list until the animation ends. The parent is then a flex column that + * does not scroll itself (flex flex-col overflow-hidden + max-height). + */ + scrollport?: boolean; } let { @@ -34,6 +42,7 @@ onSearchChange, onSearchKeyDown, placeholder = 'Search...', + scrollport = false, searchClass = '', searchValue = $bindable('') }: Props = $props(); @@ -42,32 +51,42 @@ let stickyHeaderHeight = $state(0); -
- -
+{#snippet body()} +
+ +
+ +
+ +
+ {@render children()} -
- -
- {@render children()} + {#if isEmpty} +
{emptyMessage}
+ {/if} +
+
+{/snippet} - {#if isEmpty} -
{emptyMessage}
- {/if} +{#if scrollport} +
+ {@render body()}
-
+{:else} + {@render body()} +{/if} {#if footer} -
+
Date: Fri, 20 Nov 2026 17:19:14 +0800 Subject: [PATCH 40/40] llama : move the graph node budget into the model classes (#32648) graph_max_nodes() picked the nodes-per-tensor factor from lists of architectures. Each model class now gives it through a new virtual, llama_model::graph_nodes_per_tensor(), which defaults to 8. The architectures that need 32 or 64 override it in models.h, and DFlash keeps its hparams-based rule in dflash.cpp. LoRA adapter nodes are now added for every architecture, not only for the ones on the default factor. --- src/llama-context.cpp | 39 +++------------------------------------ src/llama-model.h | 3 +++ src/models/dflash.cpp | 14 ++++++++++++++ src/models/models.h | 21 +++++++++++++++++++++ 4 files changed, 41 insertions(+), 36 deletions(-) diff --git a/src/llama-context.cpp b/src/llama-context.cpp index 7f1cc4c44cdf..ea41283f99d2 100644 --- a/src/llama-context.cpp +++ b/src/llama-context.cpp @@ -2911,42 +2911,9 @@ void llama_context::output_reorder() { // uint32_t llama_context::graph_max_nodes() const { - uint32_t res; - if (model.arch == LLM_ARCH_KIMI_K3 || model.arch == LLM_ARCH_KIMI_K31 || model.arch == LLM_ARCH_GLM5_NEXT || - model.arch == LLM_ARCH_HRM_TEXT) { - res = std::max(1024u, 64u * model.n_tensors()); - } else if (model.arch == LLM_ARCH_QWEN3NEXT || - model.arch == LLM_ARCH_KIMI_LINEAR || - model.arch == LLM_ARCH_METIS16 || - model.arch == LLM_ARCH_BAILINGMOE3 || - model.arch == LLM_ARCH_QWEN35 || - model.arch == LLM_ARCH_QWEN35MOE || - model.arch == LLM_ARCH_ZONOS3 || - model.arch == LLM_ARCH_CLEF || - model.arch == LLM_ARCH_CLOVER_MOE || - model.arch == LLM_ARCH_QWEN4EXP || - model.arch == LLM_ARCH_DEEPSEEK4 || - model.arch == LLM_ARCH_DEEPSEEK41 || - model.arch == LLM_ARCH_XING4_0 || - (model.arch == LLM_ARCH_DFLASH && model.hparams.dsv4_hc_mult > 0) || - model.arch == LLM_ARCH_NANBEIGE || - model.arch == LLM_ARCH_MINIMAX_01 || - model.arch == LLM_ARCH_MINIMAX_M3 || - model.arch == LLM_ARCH_HY_V4 || - model.arch == LLM_ARCH_INKLING2) { - res = std::max(1024u, 32u * model.n_tensors()); - } else if (model.arch == LLM_ARCH_DFLASH && model.hparams.dflash_selector_rank > 0) { - // DFlash2's convolutions and selector are shape work rather than matmuls, - // so they cost ~8.6 nodes per tensor against ~5.9 for a plain DFlash draft. - // The selector lattice scales with the draft block size; 12u was calibrated - // on block-8 drafters, so scale the budget for larger blocks (e.g. Ripple's 16). - const uint32_t block_scale = std::max(1u, model.hparams.dflash_block_size/8u); - res = std::max(1024u, 12u*block_scale*model.n_tensors()); - } else { - res = std::max(1024u, 8u*model.n_tensors()); - for (const auto & lora : model.loras) { - res += lora->get_n_nodes(); - } + uint32_t res = std::max(1024u, model.graph_nodes_per_tensor()*model.n_tensors()); + for (const auto & lora : model.loras) { + res += lora->get_n_nodes(); } // the MoE cache adds a lookup to each MoE layer, and a second expert path with a CPU share (up to ~16 tensors per layer), diff --git a/src/llama-model.h b/src/llama-model.h index 8d2f5629efae..1cc5d743a781 100644 --- a/src/llama-model.h +++ b/src/llama-model.h @@ -1052,6 +1052,9 @@ struct llama_model { llama_memory_i * create_memory(const llama_memory_params & params, const llama_cparams & cparams) const; + // graph size budget: max graph nodes per model tensor + virtual uint32_t graph_nodes_per_tensor() const { return 8; } + ggml_cgraph * build_graph(const llm_graph_params & params) const; virtual void load_stats (llama_model_loader & ml) = 0; diff --git a/src/models/dflash.cpp b/src/models/dflash.cpp index 000222f4c0d1..98a8d1d9acec 100644 --- a/src/models/dflash.cpp +++ b/src/models/dflash.cpp @@ -125,6 +125,20 @@ void llama_model_dflash::load_arch_tensors(llama_model_loader &) { } } +uint32_t llama_model_dflash::graph_nodes_per_tensor() const { + if (hparams.dsv4_hc_mult > 0) { + return 32; + } + if (hparams.dflash_selector_rank > 0) { + // DFlash2's convolutions and selector are shape work rather than matmuls, + // so they cost ~8.6 nodes per tensor against ~5.9 for a plain DFlash draft. + // The selector lattice scales with the draft block size; 12u was calibrated + // on block-8 drafters, so scale the budget for larger blocks (e.g. Ripple's 16). + return 12u*std::max(1u, hparams.dflash_block_size/8u); + } + return llama_model_base::graph_nodes_per_tensor(); +} + void llama_model_dflash::load_tensors_layers_base() { LLAMA_LOAD_LOCALS; diff --git a/src/models/models.h b/src/models/models.h index e0a4db5f7588..979ceffc271b 100644 --- a/src/models/models.h +++ b/src/models/models.h @@ -442,6 +442,7 @@ struct llama_model_nanbeige : public llama_model_base { llama_model_nanbeige(const struct llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 32; } int n_loops = 1; int n_layer_phys = 0; @@ -801,6 +802,7 @@ struct llama_model_zonos3 : public llama_model_base { llama_model_zonos3(const struct llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 32; } struct graph : public llm_build_delta_net_base { graph(const llm_graph_params & params); @@ -1282,6 +1284,7 @@ struct llama_model_deepseek4 : public llama_model_base { llama_model_deepseek4(const struct llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 32; } struct graph : public llm_graph_context { struct no_build {}; @@ -1439,6 +1442,7 @@ struct llama_model_xing4_0 : public llama_model_base { llama_model_xing4_0(const struct llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 32; } struct graph : public llm_graph_context { graph(const llama_model & model, const llm_graph_params & params); @@ -1571,6 +1575,7 @@ struct llama_model_dflash : public llama_model_base { llama_model_dflash(const struct llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override; enum variant_type { VARIANT_DFLASH, @@ -1833,6 +1838,7 @@ struct llama_model_metis16 : public llama_model_base { llama_model_metis16(const struct llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 32; } uint32_t n_pass = 1; uint32_t n_stream = 1; @@ -2134,6 +2140,7 @@ struct llama_model_hrm_text : public llama_model_base { llama_model_hrm_text(const struct llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 64; } struct graph : public llm_graph_context { graph(const llm_graph_params & params); @@ -2176,6 +2183,7 @@ struct llama_model_bailingmoe3 : public llama_model_base { llama_model_bailingmoe3(const struct llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 32; } struct graph : public llm_build_delta_net_base { graph(const llm_graph_params & params); @@ -2346,6 +2354,7 @@ struct llama_model_hy_v4 : public llama_model_base { llama_model_hy_v4(const struct llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 32; } struct graph : public llm_graph_context { graph(const llm_graph_params & params); @@ -2475,6 +2484,7 @@ struct llama_model_inkling2 : public llama_model_base { llama_model_inkling2(const struct llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 32; } struct graph : public llm_graph_context { graph(const llm_graph_params & params); @@ -2599,6 +2609,7 @@ struct llama_model_minimax_01 : public llama_model_base { llama_model_minimax_01(const struct llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 32; } struct graph : public llm_graph_context { graph(const llm_graph_params & params); @@ -2629,6 +2640,7 @@ struct llama_model_minimax_m3 : public llama_model_base { llama_model_minimax_m3(const struct llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 32; } msa_params msa_p; struct graph : public llm_graph_context { graph(const llm_graph_params & params); @@ -2673,6 +2685,7 @@ struct llama_model_qwen3next : public llama_model_base { llama_model_qwen3next(const struct llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 32; } struct graph : public llm_build_delta_net_base { graph(const llm_graph_params & params); @@ -2715,6 +2728,7 @@ struct llama_model_qwen35 : public llama_model_base { llama_model_qwen35(const struct llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 32; } struct graph : public llm_build_delta_net_base { graph(const llm_graph_params & params); @@ -2851,6 +2865,7 @@ struct llama_model_qwen4exp : public llama_model_base { void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 32; } struct graph : public llm_build_delta_net_base { graph(const llm_graph_params & params); @@ -2965,6 +2980,7 @@ struct llama_model_qwen35moe : public llama_model_base { llama_model_qwen35moe(const struct llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 32; } struct graph : public llm_build_delta_net_base { graph(const llm_graph_params & params); @@ -3007,6 +3023,7 @@ struct llama_model_clover_moe : public llama_model_base { llama_model_clover_moe(const llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 32; } struct graph : public llm_build_delta_net_base { graph(const llm_graph_params & params); @@ -3055,6 +3072,7 @@ struct llama_model_kimi_k3 : public llama_model_base { llama_model_kimi_k3(const struct llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 64; } struct graph : public llm_build_delta_net_base { graph(const llm_graph_params & params); @@ -3095,6 +3113,7 @@ struct llama_model_kimi_k31 : public llama_model_base { llama_model_kimi_k31(const struct llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 64; } struct graph : public llm_build_delta_net_base { graph(const llm_graph_params & params); @@ -3141,6 +3160,7 @@ struct llama_model_glm5_next : public llama_model_base { llama_model_glm5_next(const struct llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 64; } // k-pool indexer inputs on top of the generic hybrid input class llm_graph_input_kpool; @@ -3225,6 +3245,7 @@ struct llama_model_kimi_linear : public llama_model_base { llama_model_kimi_linear(const struct llama_model_params & params) : llama_model_base(params) {} void load_arch_hparams(llama_model_loader & ml) override; void load_arch_tensors(llama_model_loader & ml) override; + uint32_t graph_nodes_per_tensor() const override { return 32; } struct graph : public llm_build_delta_net_base { graph(const llm_graph_params & params);