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
//! Per-token cross-layer context for `encode_one_layer` (ADR-028 iter-390).
//!
//! Bundles the local variables that forward_decode's pre-loop section
//! computes once and the layer-encoding loop reads many times. This is
//! the prerequisite for iter-391's extraction of the layer body into a
//! `&self` method, which in turn enables iter-392's parallel encoding
//! across worker threads.
//!
//! # Why this struct exists
//!
//! Before iter-388: forward_decode's layer loop body had `&mut self.X`
//! borrows everywhere — extraction would require massive refactoring of
//! borrow patterns.
//!
//! After iter-388: layer body is `&self`-only on `self` accesses.
//! Remaining cross-loop state lives in 59 local `let` bindings inside
//! forward_decode's pre-loop section. `LayerCtx` bundles these so
//! `encode_one_layer(&self, layer_idx, ctx, session, gpu)` can be a
//! clean signature instead of taking 30+ parameters.
//!
//! # Field categories
//!
//! 1. **Token state**: `seq_pos`, `input_token` — passed in to
//! forward_decode.
//! 2. **Model constants**: `num_layers`, `hs`, `top_k`, `num_experts`,
//! `moe_int`, `eps` — derived from self at fn entry.
//! 3. **KV-cache state**: `kv_info` (Vec of per-layer (is_sliding,
//! write_pos, capacity, seq_len) tuples) — computed pre-loop.
//! 4. **Debug/dump flags**: `dump_layers`, `dump_detail_layer`,
//! `dump_after_post_attn`, `dump_sliding_l0`, `dump_run_name` —
//! INVESTIGATION_ENV-derived.
//! 5. **Buffer-split config**: `dual_buffer_splits` (per iter-374
//! multi-split support).
//! 6. **Profiling state**: `per_layer_disp_enabled`,
//! `per_layer_disp_log` (mutable shared via &mut).
/// Per-token, cross-layer encoding context. Built once in
/// forward_decode's pre-loop section, then passed (`&LayerCtx`) to
/// each invocation of `encode_one_layer`.
///
/// `Copy` is derived so ADR-031 Phase B can construct a child `parallel_ctx`
/// with `dual_buffer_splits: &[]` via struct-update syntax (`..ctx`). All
/// 13 fields are `Copy` (usize, bool, Option<usize>, f32, u32, &[T], &str).
pub