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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Phase 6d Track 4: bridge from fuel-inference's runtime state into
//! graph placement planning.
//!
//! The Lightbulb-contributed inference layer (this crate) handles
//! memory-pressure admission, MoE expert routing, speculative decoding
//! batching — all *runtime* policies. Placement policy belongs to the
//! planner (today: the picker's `compile_plan` on the pipelined
//! executor; tomorrow: the load-time incremental planner). This module
//! is where the two meet.
//!
//! ## History
//!
//! The original bridge implemented `fuel-graph-router::SchedulerRule`
//! and plugged into the legacy `RuleScheduler` pipeline. That crate
//! retired with executor-unification Session 6 (2026-06-11); the rule
//! survives as a self-contained placement-bias pass over a plain
//! per-node placement map, with no legacy planner types in its
//! signature. The load-time planner program picks it up as a
//! placement-bias input when its admission/placement stages land.
//!
//! ## Today
//!
//! [`MemoryPressureRule`] is the pilot integration: a pass that
//! consults `MemoryScheduler`-style memory pressure state to bias
//! placement toward keeping ops on the same device as their primary
//! input when memory is tight (avoiding extra `Op::Copy` emissions).
//!
//! ## Roadmap
//!
//! Future rules in this module bridge MoE routing (route expert
//! batches to specific backends), speculative-decode draft/target
//! pairing (co-locate them), and tiered-storage residency hints.
use ;
use DeviceLocation;
use HashMap;
use crateMemoryScheduler;
/// Per-node device assignment the bias passes read and refine.
/// Plain map — the planner-side consumer translates it into
/// `graph.set_placement` calls / plan pins as appropriate.
pub type Placement = ;
/// A snapshot of memory-pressure state captured from a
/// `MemoryScheduler` at the moment a graph is being planned. Owned
/// (no lifetime) so the rule can be cloned into a planning
/// pipeline without lifetime gymnastics.
/// Placement-bias pass that makes each op follow its primary input's
/// device when memory is under pressure. Reduces `Op::Copy` emissions
/// at the cost of potentially missing a backend that would have run
/// the op faster — under pressure, the avoided D2D / H2D / D2H
/// transfer is usually the bigger win.
///
/// Intended to run over a placement map that has already been seeded
/// (every node assigned a baseline device): the pass rewrites
/// non-Const consumers to follow their first input.
/// Convenience: build a `MemoryPressureRule` from a live scheduler.
/// Maps `DeviceLocation` keys for use in tests / planner inspection.
///
/// Reserved for future use — currently empty, but the symbol is
/// exported so downstream callers can pin the API surface they
/// depend on.
// Tests live in `tests/scheduler_bridge.rs` as an integration test —
// fuel-inference's lib-test target has unrelated pre-existing
// compile errors (Device::Cpu API drift) that would otherwise mask
// real failures here.