From e5406fe8d1b3be85c6c8c895772fb65fac573c48 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Wed, 11 Nov 2026 07:50:07 -0400 Subject: [PATCH] hrx: the alias fallback of the alternate-value lookup compares the scale (a miss in #298; engine #2159) #298 gave an f16 activation copy a scale (stored = value * 2^-6) and made the lookup ask for a scale, so that a reader which does not know about scales only finds unscaled copies. The last step of the graph-aware lookup, which matches an alternate of another value with the same storage range, did not compare the scale. A reader asking for the unscaled copy through an alias could be handed the scaled one, and the other way round, and would then scale its result wrongly. Test: hrx-backend-test alias_value_import. Value 1 aliases value 0, value 0 has an f16 copy at 2^-6: the scale-6 lookup through the alias finds it, the default lookup does not. Co-Authored-By: Claude Fable 5.2 --- ggml/src/ggml-hrx/dispatch/command-plan.h | 3 ++- tests/hrx-backend-test.cpp | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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); }