Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[OpenVINO NPU] Add bounds checking to HFA (#37522)

Enrico Gallif1c97b4df858
diff --git a/src/plugins/intel_npu/src/plugin/npuw/attn/attn_subgraph.cpp b/src/plugins/intel_npu/src/plugin/npuw/attn/attn_subgraph.cpp
index 727c1ca94fe..ee1a41a2f47 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/attn/attn_subgraph.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/attn/attn_subgraph.cpp
@@ -331,6 +331,7 @@ void ensure_hfa_requests(ov::npuw::v1::subgraphs::InferContext& ctx, RuntimeStat
const auto& pipeline = get_subgraph_pipeline(ctx, ctx.real_subgraph_idx);
const auto* hfa = ov::npuw::attn::get_compiled_hfa(pipeline.context);
OPENVINO_ASSERT(hfa != nullptr, "Missing compiled HFA state");
+ OPENVINO_ASSERT(hfa->is_valid(), "HFA configuration must be valid");
auto& request = get_request(ctx);
const bool is_piped = request.is_subrequest_pipelined(ctx.real_subgraph_idx);
@@ -343,6 +344,10 @@ void ensure_hfa_requests(ov::npuw::v1::subgraphs::InferContext& ctx, RuntimeStat
state.hfa_requests.pipeline_requests[HFARequestSet::FINAL_TILE] = state.base_pipeline_request;
}
+ // The regular and the final tile models share the same leading input layout by construction
+ // (see build_tile_param_mapping) - the final tile model may only have extra trailing inputs.
+ OPENVINO_ASSERT(hfa->_compiled_final_tile_model->inputs().size() >= hfa->_compiled_tile_model->inputs().size(),
+ "HFA: final tile model must expose at least the regular tile model's inputs");
const size_t num_inputs = hfa->_compiled_tile_model->inputs().size();
for (size_t input_idx = 0; input_idx < num_inputs; ++input_idx) {
const auto tile_input = hfa->_compiled_tile_model->inputs()[input_idx];
@@ -442,6 +447,14 @@ void extract_and_copy_tile(const ov::SoPtr<ov::ITensor>& source_tensor,
int64_t sequence_offset,
int64_t sequence_length,
const std::string& tensor_name) {
+ OPENVINO_ASSERT(sequence_offset >= 0 && sequence_length >= 0,
+ "HFA tile extraction error: negative window for '",
+ tensor_name,
+ "' (offset=",
+ sequence_offset,
+ ", length=",
+ sequence_length,
+ ")");
if (!dest_tensor->is_continuous()) {
OPENVINO_THROW("HFA tile extraction error: destination tensor for '",
tensor_name,
@@ -490,6 +503,7 @@ bool can_reuse_tensor_zero_copy(const ov::SoPtr<ov::ITensor>& source_tensor,
int64_t sequence_offset,
int64_t tile_length) {
const auto source_shape = source_tensor->get_shape();
+ NPUW_ASSERT(sequence_dim < source_shape.size());
const int64_t source_full_length = static_cast<int64_t>(source_shape[sequence_dim]);
return (sequence_offset == 0 && tile_length == source_full_length &&
dest_tensor->get_element_type() == source_tensor->get_element_type());
@@ -953,6 +967,12 @@ ov::npuw::v1::subgraphs::RuntimeBehaviorFactory make_runtime_factory() {
auto attention_mask_tensor = hfa_inputs.at(sdpa_in.attention_mask);
auto present_value_tensor = hfa_inputs.at(sdpa_in.present_value);
const uint32_t K_SEQ_DIM = static_cast<uint32_t>(sdpa_info._k_seq_dim);
+ OPENVINO_ASSERT(K_SEQ_DIM < present_key_tensor->get_shape().size(),
+ "HFA: K sequence dimension is out of range for the present key tensor");
+ for (const auto& k_block : past_key_blocks) {
+ OPENVINO_ASSERT(K_SEQ_DIM < k_block->get_shape().size(),
+ "HFA: K sequence dimension is out of range for a past key tensor");
+ }
// total_kv_length controls how many KV tiles HFA processes.
// Use min(global_context_length, layer_bound_kv_length) to satisfy both constraints:
@@ -1150,6 +1170,22 @@ ov::npuw::v1::subgraphs::RuntimeBehaviorFactory make_runtime_factory() {
// For the fused hfa, the regular tile model has no mask input (6 inputs)
const bool uses_mask = hfa_desc->_compiled_tile_model->inputs().size() > tile_in.mask;
+ // Regular tiles read the leading mask region, while the final tile reads
+ // the trailing region. Validate both ranges before creating tensor views.
+ int64_t mask_total_length = 0;
+ if (attention_mask_tensor) {
+ OPENVINO_ASSERT(MASK_KV_SEQ_DIM < attention_mask_tensor->get_shape().size(),
+ "HFA: mask sequence dimension is out of range");
+ mask_total_length =
+ static_cast<int64_t>(attention_mask_tensor->get_shape()[MASK_KV_SEQ_DIM]);
+ OPENVINO_ASSERT(mask_total_length >= total_kv_length,
+ "HFA: attention mask is too short - it covers ",
+ mask_total_length,
+ " positions but ",
+ total_kv_length,
+ " positions are required");
+ }
+
// Iterate through KV blocks; each block contributes block_size/past_tile_size
// tiles (one-to-one per block in block-split mode, or several chunks out of a
// single continuous past tensor). PREFILL always fills the KV cache in exact
@@ -1185,8 +1221,8 @@ ov::npuw::v1::subgraphs::RuntimeBehaviorFactory make_runtime_factory() {
static_cast<int64_t>(present_key_tensor->get_shape()[K_SEQ_DIM]);
OPENVINO_ASSERT(present_seq_length == present_tile_size,
"HFA: present KV length must equal the compiled query/present tile size");
- const int64_t mask_total_length = attention_mask_tensor->get_shape()[MASK_KV_SEQ_DIM];
- const int64_t final_mask_offset = mask_total_length - final_tile_size;
+ const int64_t final_mask_offset =
+ attention_mask_tensor ? mask_total_length - final_tile_size : 0;
process_tile(final_tile_request,
hfa_desc->_compiled_final_tile_model,
present_key_tensor,
diff --git a/src/plugins/intel_npu/src/plugin/npuw/host_flash_attention.cpp b/src/plugins/intel_npu/src/plugin/npuw/host_flash_attention.cpp
index c829fc0c603..fbe6cf9bdda 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/host_flash_attention.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/host_flash_attention.cpp
@@ -1372,6 +1372,58 @@ HostFlashAttention::HostFlashAttention(const function::HostFlashAttention& func_
// Note: _compiled_tile_model and _compiled_final_tile_model will be set later by
// compile_host_flash_attention_model()
}
+
+bool HostFlashAttention::is_valid() const {
+ if (_compiled_tile_model == nullptr || _compiled_final_tile_model == nullptr || _past_tile_size <= 0 ||
+ _final_tile_size <= 0 || _sdpa_attention_info._query_size == 0 ||
+ static_cast<std::size_t>(_final_tile_size) != _sdpa_attention_info._query_size) {
+ return false;
+ }
+
+ // _context_size drives the mask tile buffer allocation loop in
+ // HFARuntimeContext::initialize_mask_cache (ceil(context_size / past_tile_size) iterations, one device
+ // allocation each), so a corrupted blob must not be able to turn it into an unbounded loop.
+ const std::size_t context_size = _sdpa_attention_info._context_size;
+ const std::size_t past_tile_size = static_cast<std::size_t>(_past_tile_size);
+ const std::size_t num_tiles = context_size / past_tile_size + (context_size % past_tile_size != 0);
+ if (context_size == 0 || num_tiles > kMaxTiles) {
+ return false;
+ }
+
+ const auto& tile_inputs = _compiled_tile_model->inputs();
+ const auto& final_inputs = _compiled_final_tile_model->inputs();
+ const auto& tile_outputs = _compiled_tile_model->outputs();
+ const auto& final_outputs = _compiled_final_tile_model->outputs();
+ const auto& tin = _sdpa_attention_info._tile_input_indices;
+ const auto& tout = _sdpa_attention_info._tile_output_indices;
+
+ auto in_range = [](std::size_t idx, std::size_t size) {
+ return idx < size;
+ };
+
+ auto seq_dim_in_range = [](std::size_t seq_dim, const ov::Output<const ov::Node>& port) {
+ const auto rank = port.get_partial_shape().rank();
+ return rank.is_static() && seq_dim < static_cast<std::size_t>(rank.get_length());
+ };
+
+ // q/k/v/acc/max/d are always present on both the regular and the final tile model.
+ // mask may legitimately be absent from the regular tile model (mask-skipping optimization);
+ // the runtime detects that case by comparing tin.mask against inputs().size(), so it is only
+ // required to be in range for the final tile model, which always consumes a mask.
+ return in_range(tin.q, tile_inputs.size()) && in_range(tin.q, final_inputs.size()) &&
+ in_range(tin.k, tile_inputs.size()) && in_range(tin.k, final_inputs.size()) &&
+ in_range(tin.v, tile_inputs.size()) && in_range(tin.v, final_inputs.size()) &&
+ seq_dim_in_range(_sdpa_attention_info._k_seq_dim, tile_inputs[tin.k]) &&
+ seq_dim_in_range(_sdpa_attention_info._k_seq_dim, final_inputs[tin.k]) &&
+ seq_dim_in_range(_sdpa_attention_info._v_seq_dim, tile_inputs[tin.v]) &&
+ seq_dim_in_range(_sdpa_attention_info._v_seq_dim, final_inputs[tin.v]) &&
+ in_range(tin.mask, final_inputs.size()) && in_range(tin.acc, tile_inputs.size()) &&
+ in_range(tin.acc, final_inputs.size()) && in_range(tin.max, tile_inputs.size()) &&
+ in_range(tin.max, final_inputs.size()) && in_range(tin.d, tile_inputs.size()) &&
+ in_range(tin.d, final_inputs.size()) && in_range(tout.acc, tile_outputs.size()) &&
+ in_range(tout.max, tile_outputs.size()) && in_range(tout.d, tile_outputs.size()) && !final_outputs.empty();
+}
+
} // namespace compiled
namespace runtime {
diff --git a/src/plugins/intel_npu/src/plugin/npuw/host_flash_attention.hpp b/src/plugins/intel_npu/src/plugin/npuw/host_flash_attention.hpp
index 8f8e26db217..0148bff98b7 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/host_flash_attention.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/host_flash_attention.hpp
@@ -10,6 +10,7 @@
#include "openvino/core/except.hpp"
#include "openvino/openvino.hpp"
+#include "openvino/runtime/icompiled_model.hpp"
#include "openvino/runtime/isync_infer_request.hpp"
#include "openvino/runtime/itensor.hpp"
#include "openvino/runtime/so_ptr.hpp"
@@ -208,6 +209,10 @@ struct HostFlashAttentionInfo {
// Compile-time host flash attention information
struct HostFlashAttention {
+ // Upper bound on the number of tiles a single HFA inference may be split into. Only used to
+ // reject corrupted _context_size / _query_size combinations coming from a cache blob.
+ static constexpr std::size_t kMaxTiles = 1u << 20;
+
// Models to compile (will be cleared after compilation)
std::shared_ptr<ov::Model> _tile_model_to_compile;
std::shared_ptr<ov::Model> _final_tile_model_to_compile;
@@ -246,10 +251,7 @@ struct HostFlashAttention {
_final_tile_model_to_compile.reset(); // Free memory after compilation
}
- bool is_valid() const {
- return _compiled_tile_model != nullptr && _compiled_final_tile_model != nullptr && _past_tile_size > 0 &&
- _final_tile_size > 0;
- }
+ bool is_valid() const;
};
} // namespace compiled
@@ -360,7 +362,7 @@ struct HFARuntimeContext {
// to be exact — context_size includes the final tile's present KV, which isn't itself
// chunked into past_tile_size units, so the division may not be exact.
const size_t context_size = hfa_desc._sdpa_attention_info._context_size;
- const size_t max_num_tiles = (context_size + past_tile_size - 1) / past_tile_size;
+ const size_t max_num_tiles = context_size / past_tile_size + (context_size % past_tile_size != 0);
m_mask_tile_buffers.reserve(max_num_tiles);
for (size_t i = 0; i < max_num_tiles; ++i) {
diff --git a/src/plugins/intel_npu/tests/unit/npuw/serialization.cpp b/src/plugins/intel_npu/tests/unit/npuw/serialization.cpp
index de1f3a6e066..0f3f44ef8b6 100644
--- a/src/plugins/intel_npu/tests/unit/npuw/serialization.cpp
+++ b/src/plugins/intel_npu/tests/unit/npuw/serialization.cpp
@@ -26,8 +26,12 @@
#include "openvino/core/memory_util.hpp"
#include "openvino/core/parallel.hpp"
#include "openvino/core/rt_info/weightless_caching_attributes.hpp"
+#include "openvino/op/add.hpp"
#include "openvino/op/constant.hpp"
+#include "openvino/op/parameter.hpp"
+#include "openvino/op/result.hpp"
#include "openvino/openvino.hpp"
+#include "openvino/runtime/iplugin.hpp"
#include "openvino/runtime/shared_buffer.hpp"
#include "openvino/util/mmap_object.hpp"
#include "pyramid_attention.hpp"
@@ -1195,6 +1199,215 @@ TEST(SerializationTest, OVTypes_HostFlashAttention_OOBTileIndexRejected) {
EXPECT_THROW(read(ss, res), ov::Exception);
}
+namespace {
+
+class HFAFakePlugin final : public ov::IPlugin {
+public:
+ std::shared_ptr<ov::ICompiledModel> compile_model(const std::shared_ptr<const ov::Model>&,
+ const ov::AnyMap&) const override {
+ OPENVINO_THROW("Unexpected compile_model call");
+ }
+ std::shared_ptr<ov::ICompiledModel> compile_model(const std::shared_ptr<const ov::Model>&,
+ const ov::AnyMap&,
+ const ov::SoPtr<ov::IRemoteContext>&) const override {
+ OPENVINO_THROW("Unexpected compile_model(context) call");
+ }
+ std::shared_ptr<ov::ICompiledModel> import_model(std::istream&, const ov::AnyMap&) const override {
+ OPENVINO_THROW("Unexpected import_model(stream) call");
+ }
+ std::shared_ptr<ov::ICompiledModel> import_model(std::istream&,
+ const ov::SoPtr<ov::IRemoteContext>&,
+ const ov::AnyMap&) const override {
+ OPENVINO_THROW("Unexpected import_model(stream, context) call");
+ }
+ std::shared_ptr<ov::ICompiledModel> import_model(const ov::Tensor&, const ov::AnyMap&) const override {
+ OPENVINO_THROW("Unexpected import_model(blob) call");
+ }
+ std::shared_ptr<ov::ICompiledModel> import_model(const ov::Tensor&,
+ const ov::SoPtr<ov::IRemoteContext>&,
+ const ov::AnyMap&) const override {
+ OPENVINO_THROW("Unexpected import_model(blob, context) call");
+ }
+ ov::SupportedOpsMap query_model(const std::shared_ptr<const ov::Model>&, const ov::AnyMap&) const override {
+ OPENVINO_THROW("Unexpected query_model call");
+ }
+ void set_property(const ov::AnyMap&) override {}
+ ov::Any get_property(const std::string& name, const ov::AnyMap&) const override {
+ OPENVINO_THROW("Unsupported property: ", name);
+ }
+ bool is_property_supported(const std::string&, const ov::AnyMap&) const override {
+ return false;
+ }
+ ov::SoPtr<ov::IRemoteContext> create_context(const ov::AnyMap&) const override {
+ OPENVINO_THROW("Unexpected create_context call");
+ }
+ ov::SoPtr<ov::IRemoteContext> get_default_context(const ov::AnyMap&) const override {
+ OPENVINO_THROW("Unexpected get_default_context call");
+ }
+};
+
+class HFAFakeCompiledModel final : public ov::ICompiledModel {
+public:
+ HFAFakeCompiledModel(const std::shared_ptr<ov::Model>& model, const std::shared_ptr<const ov::IPlugin>& plugin)
+ : ov::ICompiledModel(model, plugin, nullptr, nullptr) {}
+
+ void export_model(std::ostream&) const override {}
+ std::shared_ptr<const ov::Model> get_runtime_model() const override {
+ OPENVINO_THROW("Unexpected get_runtime_model call");
+ }
+ void set_property(const ov::AnyMap&) override {}
+ ov::Any get_property(const std::string& name) const override {
+ OPENVINO_THROW("Unsupported property: ", name);
+ }
+ std::shared_ptr<ov::ISyncInferRequest> create_sync_infer_request() const override {
+ OPENVINO_THROW("Unexpected create_sync_infer_request call");
+ }
+};
+
+// Model with a fixed number of Parameter inputs/Result outputs, used to stand in for the
+// compiled tile models that HostFlashAttention::is_valid() bound-checks against.
+std::shared_ptr<ov::Model> make_hfa_stub_model(std::size_t num_inputs, std::size_t num_outputs) {
+ ov::ParameterVector params;
+ ov::ResultVector results;
+ for (std::size_t i = 0; i < num_inputs; ++i) {
+ params.push_back(std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 1, 1, 1}));
+ }
+ for (std::size_t i = 0; i < num_outputs; ++i) {
+ auto add = std::make_shared<ov::op::v1::Add>(params.at(0), params.at(0));
+ results.push_back(std::make_shared<ov::op::v0::Result>(add));
+ }
+ return std::make_shared<ov::Model>(results, params);
+}
+
+ov::SoPtr<ov::ICompiledModel> make_hfa_fake_compiled_model(const std::shared_ptr<const ov::IPlugin>& plugin,
+ std::size_t num_inputs,
+ std::size_t num_outputs) {
+ auto model = make_hfa_stub_model(num_inputs, num_outputs);
+ return ov::SoPtr<ov::ICompiledModel>(std::make_shared<HFAFakeCompiledModel>(model, plugin));
+}
+
+ov::npuw::compiled::HostFlashAttention make_deserialized_hfa(std::size_t k_seq_dim,
+ std::size_t v_seq_dim,
+ std::size_t context_size = 32) {
+ using namespace ov::npuw::s11n;
+
+ ov::npuw::compiled::HostFlashAttention source;
+ source._sdpa_attention_info._query_size = 8;
+ source._sdpa_attention_info._context_size = context_size;
+ source._sdpa_attention_info._k_seq_dim = k_seq_dim;
+ source._sdpa_attention_info._v_seq_dim = v_seq_dim;
+ source._sdpa_attention_info._sdpa_indices = {0, {0}, {0}, 0, 0, 0};
+ source._sdpa_attention_info._tile_input_indices = {0, 1, 2, 3, 0, 1, 2};
+ source._sdpa_attention_info._tile_output_indices = {0, 1, 2};
+ source._past_tile_size = 8;
+ source._final_tile_size = 8;
+
+ ov::npuw::compiled::HostFlashAttention result;
+ std::stringstream stream;
+ write(stream, source);
+ read(stream, result);
+
+ auto plugin = std::make_shared<HFAFakePlugin>();
+ result._compiled_tile_model = make_hfa_fake_compiled_model(plugin, 3, 3);
+ result._compiled_final_tile_model = make_hfa_fake_compiled_model(plugin, 4, 3);
+ return result;
+}
+
+} // namespace
+
+// Reproduces an attacker-controlled cache blob carrying an out-of-range tile input index:
+// the raw index round-trips through the s11n write()/read() path unchecked, and is_valid()
+// must reject it once attached to compiled models whose real input/output counts are known.
+TEST(SerializationTest, HostFlashAttention_OutOfRangeTileIndexRejectedAfterDeserialization) {
+ using namespace ov::npuw::s11n;
+
+ ov::npuw::compiled::HostFlashAttention var;
+ var._sdpa_attention_info._query_size = 8;
+ var._sdpa_attention_info._context_size = 32;
+ var._sdpa_attention_info._k_seq_dim = 1;
+ var._sdpa_attention_info._v_seq_dim = 2;
+ var._sdpa_attention_info._sdpa_indices = {0, {0}, {0}, 0, 0, 0};
+ // Only 3 inputs will exist on the compiled tile models below, so index 999 is out of range.
+ var._sdpa_attention_info._tile_input_indices = {999, 1, 2, 3, 0, 1, 2};
+ var._sdpa_attention_info._tile_output_indices = {0, 1, 2};
+ var._past_tile_size = 8;
+ var._final_tile_size = 8;
+ var._can_use_tensor_view = true;
+
+ ov::npuw::compiled::HostFlashAttention res;
+ std::stringstream ss;
+ write(ss, var);
+ read(ss, res);
+
+ // The out-of-range index survives deserialization unchanged - no validation happens in
+ // the s11n layer itself.
+ EXPECT_EQ(res._sdpa_attention_info._tile_input_indices.q, static_cast<std::size_t>(999));
+
+ auto plugin = std::make_shared<HFAFakePlugin>();
+ res._compiled_tile_model = make_hfa_fake_compiled_model(plugin, /*num_inputs=*/3, /*num_outputs=*/3);
+ res._compiled_final_tile_model = make_hfa_fake_compiled_model(plugin, /*num_inputs=*/4, /*num_outputs=*/3);
+
+ EXPECT_FALSE(res.is_valid());
+}
+
+TEST(SerializationTest, HostFlashAttention_OutOfRangeKSeqDimRejectedAfterDeserialization) {
+ auto hfa = make_deserialized_hfa(/*k_seq_dim=*/4, /*v_seq_dim=*/2);
+
+ EXPECT_FALSE(hfa.is_valid());
+}
+
+TEST(SerializationTest, HostFlashAttention_OutOfRangeVSeqDimRejectedAfterDeserialization) {
+ auto hfa = make_deserialized_hfa(/*k_seq_dim=*/1, /*v_seq_dim=*/4);
+
+ EXPECT_FALSE(hfa.is_valid());
+}
+
+// Positive control for the rejection tests above: the baseline configuration they are derived from
+// must be accepted. Without it, an over-strict is_valid() - which would break every HFA inference
+// at the OPENVINO_ASSERT in ensure_hfa_requests - would still leave those tests green.
+TEST(SerializationTest, HostFlashAttention_ValidConfigurationAcceptedAfterDeserialization) {
+ auto hfa = make_deserialized_hfa(/*k_seq_dim=*/1, /*v_seq_dim=*/2);
+
+ EXPECT_TRUE(hfa.is_valid());
+}
+
+// Mask-skipping optimization: the regular tile model is compiled without a mask input, so the
+// mask index deliberately points past its inputs while still addressing the final tile model's
+// mask port. is_valid() must accept that, and must still reject an index that is out of range
+// for the final tile model as well.
+TEST(SerializationTest, HostFlashAttention_MaskSkippingConfigurationAccepted) {
+ auto hfa = make_deserialized_hfa(/*k_seq_dim=*/1, /*v_seq_dim=*/2);
+ auto plugin = std::make_shared<HFAFakePlugin>();
+
+ // Regular tile model: [acc, max, d, k, v, q]; final tile model additionally has mask at index 6.
+ hfa._sdpa_attention_info._tile_input_indices = {/*q=*/5,
+ /*k=*/3,
+ /*v=*/4,
+ /*mask=*/6,
+ /*acc=*/0,
+ /*max=*/1,
+ /*d=*/2};
+ hfa._compiled_tile_model = make_hfa_fake_compiled_model(plugin, /*num_inputs=*/6, /*num_outputs=*/3);
+ hfa._compiled_final_tile_model = make_hfa_fake_compiled_model(plugin, /*num_inputs=*/7, /*num_outputs=*/3);
+ EXPECT_TRUE(hfa.is_valid());
+
+ hfa._compiled_final_tile_model = make_hfa_fake_compiled_model(plugin, /*num_inputs=*/6, /*num_outputs=*/3);
+ EXPECT_FALSE(hfa.is_valid());
+}
+
+// _context_size feeds the mask tile buffer allocation loop in
+// HFARuntimeContext::initialize_mask_cache (ceil(context_size / past_tile_size) device allocations),
+// so zero and absurdly large values must be rejected while a partial final interval remains valid.
+TEST(SerializationTest, HostFlashAttention_InvalidContextSizeRejectedAfterDeserialization) {
+ EXPECT_FALSE(make_deserialized_hfa(/*k_seq_dim=*/1, /*v_seq_dim=*/2, /*context_size=*/0).is_valid());
+ EXPECT_TRUE(make_deserialized_hfa(/*k_seq_dim=*/1, /*v_seq_dim=*/2, /*context_size=*/33).is_valid());
+ // Would request nearly 2^61 mask tile buffers.
+ EXPECT_FALSE(make_deserialized_hfa(/*k_seq_dim=*/1,
+ /*v_seq_dim=*/2,
+ /*context_size=*/std::numeric_limits<std::size_t>::max() - 7)
+ .is_valid());
+}
+
TEST(SerializationTest, OVTypes_MoEExperts) {
using namespace ov::npuw::s11n;