1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! The **size oracle**: byte size of an activation value.
//!
//! Sizes may be unknown at build time when a shape has symbolic (dynamic)
//! dimensions. The planner is generic over any `Fn(ValueId) -> Option<usize>`
//! so the *same* algorithm serves two callers:
//!
//! * **build-time** planning from fully-static shapes ([`static_size_oracle`]),
//! which returns `None` for any symbolic-shaped value and drives the planner
//! to a [`crate::PlanStatus::Deferred`] result; and
//! * **run-time** planning, where the executor supplies a closure backed by the
//! resolved concrete shapes for the current run.
use HashMap;
use ;
/// A size oracle closure that sizes values from their fully-static shapes.
///
/// Returns `None` for any symbolic-shaped value, which the planner reports as
/// [`crate::PlanStatus::Deferred`] so the executor can re-plan once shapes
/// resolve.
+ '_
/// Byte size of a value from its *static* shape, or `None` if any dimension is
/// symbolic (unknown until run time) or the element count overflows `usize`.
///
/// Uses [`onnx_runtime_ir::DataType::checked_storage_bytes`] so sub-byte packed
/// types (`int4`/`uint4`/`float4`) are sized correctly and an overflowing
/// element count becomes `None` rather than a wrapped under-count.
/// A size oracle that resolves symbolic dimensions to caller-supplied **upper
/// bounds**.
///
/// [`static_size_oracle`] answers `None` for anything dynamic, which is right
/// for a plan that must be exact but useless for a *reservation*: an LLM's
/// activations are dynamic in sequence length, so a reservation computed from
/// static shapes alone is always zero — and a zero reservation is
/// indistinguishable from a model that allocates nothing.
///
/// A reservation does not need the exact size, it needs the ceiling. Admission
/// control already knows that ceiling, because it is the largest shape it will
/// admit. Binding those bounds turns "cannot know" into "cannot exceed".
///
/// Symbols with no bound are still `None`, so the planner defers rather than
/// guessing. Partial knowledge is not a bound.
+ 'a
/// Byte size of a value with symbolic dimensions resolved through `bounds`.
///
/// Returns `None` if any dimension is symbolic and unbound, or if the element
/// count overflows.