diff --git a/ggml/src/ggml-hrx/dispatch/command-plan.h b/ggml/src/ggml-hrx/dispatch/command-plan.h index 4f81b55e78ab..145840391a7f 100644 --- a/ggml/src/ggml-hrx/dispatch/command-plan.h +++ b/ggml/src/ggml-hrx/dispatch/command-plan.h @@ -103,7 +103,8 @@ inline const CommandPlanAlternateValue * find_alternate_value(const Graph & } for (const CommandPlanAlternateValue & alternate : plan.metadata.alternate_values()) { - if (alternate.type != type || alternate.byte_count != byte_count) { + // the scale is part of what a reader asks for: a copy stored at another scale is a different value (engine #2159) + if (alternate.type != type || alternate.byte_count != byte_count || alternate.scale_log2 != scale_log2) { continue; } const Value * alternate_value = graph.values().find(alternate.graph_value); diff --git a/tests/hrx-backend-test.cpp b/tests/hrx-backend-test.cpp index dee609dcab95..c1df73f3de22 100644 --- a/tests/hrx-backend-test.cpp +++ b/tests/hrx-backend-test.cpp @@ -8469,6 +8469,25 @@ static void run_alias_value_import_checks() { REQUIRE(aliased_binding->offset == 64); REQUIRE(aliased_binding->length == 8 * sizeof(float)); + // engine #2159: an alternate stored at a scale is found only by a reader that asks for that scale, also through an + // alias. Value 1 aliases value 0; value 0 has an f16 copy stored at 2^-6. + { + ggml::hrx::Graph alias_graph; + alias_graph.values() = value_map; + ggml::hrx::CommandPlan alias_plan; + ggml::hrx::Status alias_status; + REQUIRE(alias_plan.metadata.append_alternate_value( + { ggml::hrx::ValueId(0), ggml::hrx::ValueId(7), GGML_TYPE_F16, 16, "test.scaled_f16", 6 }, alias_status)); + const auto * scaled = + ggml::hrx::find_alternate_value(alias_graph, alias_plan, ggml::hrx::ValueId(1), GGML_TYPE_F16, 16, 6); + REQUIRE(scaled != nullptr); + REQUIRE(scaled->scale_log2 == 6); + REQUIRE(ggml::hrx::find_alternate_value(alias_graph, alias_plan, ggml::hrx::ValueId(1), GGML_TYPE_F16, 16) == + nullptr); + REQUIRE(ggml::hrx::find_alternate_value(alias_graph, alias_plan, ggml::hrx::ValueId(0), GGML_TYPE_F16, 16) == + nullptr); + } + ggml_free(ctx); }