oa/ml/type.gen.rs
1// @generated by tool/gen/fn/generate.py; DO NOT EDIT.
2// schema=ml_types.json schema_version=1 generator_version=64
3// schema_sha256=b76205a6ba3bd3e38e279b8b03af44a1d72c97d507f9d5bf4ce27e303151d02c
4use super::training::{TrainingCommandDisposition, TrainingCommandError, TrainingState};
5use crate::{DType, Matrix};
6use std::path::PathBuf;
7#[derive(Clone, Debug)]
8pub struct CheckpointManagerConfig {
9 /// Root directory beneath which the model directory is created.
10 pub directory: PathBuf,
11 /// Stable filename component and master checkpoint stem.
12 pub model_name: String,
13 /// Optional incremental-checkpoint directory/filename component.
14 pub context: String,
15 /// Maximum retained incremental checkpoints; zero disables rotation.
16 pub max_keep: usize,
17 /// Whether an improved metric updates the master checkpoint.
18 pub save_best: bool,
19 /// Metric name written into progress metadata and filenames.
20 pub metric_name: String,
21 /// Whether a lower metric is considered better.
22 pub lower_is_better: bool,
23}
24
25#[derive(Clone, Copy, Debug, Default, PartialEq)]
26pub struct RolloutCollectorConfig {
27 /// Number of vector-environment steps in each collection.
28 pub horizon: usize,
29 /// Base seed for initial reset and categorical samples.
30 pub seed: u64,
31 /// Generalized-advantage estimator policy.
32 pub gae: GaeConfig,
33}
34
35#[derive(Clone, Copy, Debug, PartialEq)]
36pub struct TradingConfig {
37 /// Independent device lanes (round-robin over supplied contiguous segments).
38 pub environments: u32,
39 /// Positive closed-bar window length.
40 pub window: u32,
41 /// Episode length in bars, 1..=1,000,000; fill counts remain exact in F32.
42 pub horizon: u32,
43 /// Full 64-bit deterministic reset seed.
44 pub seed: u64,
45 /// Initial analytical capital per independent lane.
46 pub capital: f32,
47 /// Fraction of equity budgeted for entry margin and costs, in (0,1]. Instrument execution rules may additionally admit explicit leverage.
48 pub exposure: f32,
49 /// Actual-notional taker fee fraction on every execution leg.
50 pub taker_fee: f32,
51 /// Adverse one-way slippage in basis points, excluding spread.
52 pub slippage_bps: f32,
53 /// Full bid/ask spread in basis points; half is charged per execution leg.
54 pub spread_bps: f32,
55 /// Peak-equity drawdown fraction that terminates and closes inventory.
56 pub max_drawdown: f32,
57 /// Perpetuals use short/flat/long; Spot uses flat/long (no short category).
58 pub perpetual: bool,
59 /// Close and terminate at the horizon; otherwise truncate with final-state bootstrap.
60 pub liquidate_at_horizon: bool,
61 /// Observed book rows a flat-to-position entry rests at its passive touch before taker fallback; zero disables maker execution. Requires per-row books.
62 pub maker_window_steps: u32,
63 /// Maximum passive requotes per entry leg toward the moved touch, bounded by the IOC slippage guard; exhausted budget falls back to taker.
64 pub maker_requotes: u32,
65 /// Actual-notional fee fraction on passive fills. Consumers resolve a missing venue maker rate to taker_fee themselves; this field is only the charged rate.
66 pub maker_fee: f32,
67}
68
69pub struct BatchNorm2dResult {
70 /// Normalized and affine-transformed NCHW values.
71 pub output: Matrix,
72 /// Population mean for each channel.
73 pub mean: Matrix,
74 /// Population variance for each channel.
75 pub variance: Matrix,
76}
77
78pub struct MaxPool2dResult {
79 /// Maximum value selected from each pooling window.
80 pub output: Matrix,
81 /// Flat input index selected for each output element.
82 pub indices: Matrix,
83}
84
85pub struct MaxPool1dResult {
86 /// Maximum value selected from each pooling window.
87 pub output: Matrix,
88 /// Flat input index selected for each output element.
89 pub indices: Matrix,
90}
91
92pub struct AdaptiveMaxPool1dResult {
93 /// Maximum value selected from each pooling window.
94 pub output: Matrix,
95 /// Flat input index selected for each output element.
96 pub indices: Matrix,
97}
98
99pub struct MaxPool3dResult {
100 /// Maximum value selected from each pooling window.
101 pub output: Matrix,
102 /// Flat input index selected for each output element.
103 pub indices: Matrix,
104}
105
106pub struct AdaptiveMaxPool2dResult {
107 /// Maximum value selected from each pooling window.
108 pub output: Matrix,
109 /// Flat input index selected for each output element.
110 pub indices: Matrix,
111}
112
113pub struct AdaptiveMaxPool3dResult {
114 /// Maximum value selected from each pooling window.
115 pub output: Matrix,
116 /// Flat input index selected for each output element.
117 pub indices: Matrix,
118}
119
120/// Nearest-code indices and gathered code vectors.
121pub struct VqAssignResult {
122 /// I32 nearest-code index for every latent row.
123 pub indices: Matrix,
124 /// Gathered winning code for every latent row.
125 pub quantized: Matrix,
126}
127
128#[derive(Clone, Copy, Debug, PartialEq)]
129pub struct Mamba3PreprocessConfig {
130 /// Width of the z and x projection slices.
131 pub inner_size: usize,
132 /// Width of each B/C state row.
133 pub state_size: usize,
134 /// Number of selective-state heads.
135 pub num_heads: usize,
136 /// Number of rotary angle pairs.
137 pub num_rope_angles: usize,
138 /// Number of shared B/C groups.
139 pub num_groups: usize,
140 /// Number of B/C rows per group.
141 pub mimo_rank: usize,
142 /// Epsilon used by B/C RMS normalization.
143 pub epsilon: f32,
144 /// Inclusive lower bound for transformed dt.
145 pub dt_min: f32,
146 /// Inclusive upper bound for transformed dt.
147 pub dt_max: f32,
148 /// Positive floor for the magnitude of the negative A token.
149 pub a_floor: f32,
150}
151
152#[derive(Clone)]
153pub struct Mamba3PreprocessResult {
154 /// Value projection slice.
155 pub x: Matrix,
156 /// Gate projection slice.
157 pub z: Matrix,
158 /// RMS-normalized B rows.
159 pub bh: Matrix,
160 /// RMS-normalized C rows.
161 pub ch: Matrix,
162 /// Clamped positive time steps.
163 pub dt: Matrix,
164 /// Negative A-times-dt log decays.
165 pub adt: Matrix,
166 /// Raw trapezoidal gates.
167 pub trap: Matrix,
168 /// Raw rotary angular velocities.
169 pub angle: Matrix,
170}
171
172#[derive(Clone, Copy, Debug, PartialEq, Eq)]
173pub struct SsmConfig {
174 /// Batch size.
175 pub batch_size: usize,
176 /// Sequence length.
177 pub sequence_length: usize,
178 /// Number of value heads.
179 pub num_heads: usize,
180 /// Number of shared Q/K groups, or zero for num_heads.
181 pub num_groups: usize,
182 /// Value width per head.
183 pub head_dim: usize,
184 /// Selective recurrent state width.
185 pub state_size: usize,
186 /// Number of rotary pairs in the state axis.
187 pub num_rope_angles: usize,
188 /// MIMO rank; SISO callers use one.
189 pub mimo_rank: usize,
190 /// Apply the SiLU z gate.
191 pub has_z: bool,
192 /// Apply the learned D skip.
193 pub has_d: bool,
194 /// Apply MIMO output normalization; SISO requires false.
195 pub has_output_norm: bool,
196}
197
198/// One categorical action and its differentiable policy statistics.
199pub struct PolicyResult {
200 /// I32 action index for every environment.
201 pub action: Matrix,
202 /// Log probability of each selected action.
203 pub log_probability: Matrix,
204 /// Categorical entropy for every environment.
205 pub entropy: Matrix,
206 /// Critic value passed through without a storage copy.
207 pub value: Matrix,
208}
209
210/// One bounded continuous action and its differentiable policy statistics.
211pub struct ContinuousPolicyResult {
212 /// Action after tanh squashing and affine mapping to the requested range.
213 pub action: Matrix,
214 /// Unsquashed normal sample, retained for exact policy reevaluation.
215 pub raw_action: Matrix,
216 /// Summed corrected log probability for every environment.
217 pub log_probability: Matrix,
218 /// Summed base-normal entropy for every environment.
219 pub entropy: Matrix,
220 /// Critic value passed through without a storage copy.
221 pub value: Matrix,
222}
223
224#[derive(Clone, Copy, Debug, PartialEq)]
225pub struct ValidationResult {
226 /// Sample-weighted mean validation loss, or NaN when no value is available.
227 pub loss: f64,
228 /// Number of validation batches consumed.
229 pub batches: u64,
230 /// Number of validation samples consumed.
231 pub samples: u64,
232}
233
234#[derive(Clone, Debug, PartialEq)]
235pub struct DqnTrainerConfig {
236 /// Number of optimizer updates to complete.
237 pub updates: u64,
238 /// Replay transitions consumed by one update.
239 pub batch_size: usize,
240 /// Completed-update interval between exact online-to-target copies.
241 pub target_update_interval: u64,
242 /// Per-transition observation shape expected from replay.
243 pub observation_shape: Vec<usize>,
244 /// Base seed used by deterministic replay sampling.
245 pub seed: u64,
246 /// Bellman-target configuration.
247 pub loss: DqnLossConfig,
248}
249
250#[derive(Clone, Debug, PartialEq)]
251pub struct SacTrainerConfig {
252 /// Number of critic/actor update pairs to complete.
253 pub updates: u64,
254 /// Replay transitions consumed by each pair.
255 pub batch_size: usize,
256 /// Number of scalar continuous action dimensions.
257 pub action_dimensions: usize,
258 /// Completed-pair interval between exact critic-to-target copies.
259 pub target_update_interval: u64,
260 /// Per-transition observation shape expected from replay.
261 pub observation_shape: Vec<usize>,
262 /// Inclusive lower action mapping bound.
263 pub action_minimum: f32,
264 /// Inclusive upper action mapping bound.
265 pub action_maximum: f32,
266 /// Base deterministic replay and policy seed.
267 pub seed: u64,
268 /// Critic discount and fixed entropy coefficient.
269 pub loss: SacLossConfig,
270}
271
272#[derive(Clone, Debug, PartialEq, Eq)]
273pub struct TrainingCommandResult {
274 /// Processed command sequence.
275 pub sequence: u64,
276 /// Revision after processing.
277 pub revision: u64,
278 /// Whether the command was applied.
279 pub disposition: TrainingCommandDisposition,
280 /// Live state after processing.
281 pub state: TrainingState,
282 /// Rejection evidence, or `None` for an applied command.
283 pub error: Option<TrainingCommandError>,
284}
285
286#[derive(Clone, Copy, Debug)]
287pub struct TrainingSessionConfig {
288 /// Maximum queued commands before non-blocking enqueue rejects work.
289 pub command_capacity: usize,
290 /// Maximum retained command results.
291 pub result_capacity: usize,
292 /// Maximum retained lifecycle snapshots.
293 pub snapshot_capacity: usize,
294}
295
296#[derive(Clone, Debug)]
297pub struct ItTrainingConfig {
298 /// Completed optimizer steps restored before this lifecycle starts. `total_steps` remains the absolute final budget, not an additional-step count. Restored steps select the next epoch/cursor/scheduler position but are excluded from this process's loss and timing aggregates.
299 pub initial_step: u64,
300 /// Completed-step budget; zero keeps the loop open-ended.
301 pub total_steps: u64,
302 /// Fixed steps per epoch; zero disables epoch boundaries.
303 pub steps_per_epoch: u64,
304 /// Variable epoch lengths. When nonempty, these replace `steps_per_epoch` and their sum becomes `total_steps`.
305 pub epoch_steps: Vec<u64>,
306 /// Samples completed by one step. Zero is normalized to one.
307 pub batch_size: u64,
308 /// Optional sequence work per sample for throughput accounting.
309 pub sequence_length: u64,
310 /// Human-readable sequence unit used by progress and summary callbacks.
311 pub sequence_unit: String,
312 /// Optional fixed source units consumed by one sample.
313 pub source_units_per_sample: f64,
314 /// Human-readable source unit used by progress and summary callbacks.
315 pub source_unit: String,
316 /// Stable name for the device timer represented in reports.
317 pub timer_name: String,
318 /// Collect exact device timestamps around submitted training work.
319 pub enable_gpu_timing: bool,
320}
321
322#[derive(Clone, Debug, Default, PartialEq)]
323pub struct PpoTrainerConfig {
324 /// Number of complete rollout/update cycles.
325 pub rollouts: u64,
326 /// Time steps collected in each rollout.
327 pub horizon: usize,
328 /// Vector environments represented by each step.
329 pub environments: usize,
330 /// Full-batch optimizer passes over each finalized rollout.
331 pub update_epochs: u64,
332 /// Maximum sequences evaluated by one update tape; zero means full batch. Minibatches accumulate sample-weighted gradients with unchanged parameters and one optimizer step per epoch. Advantages normalize over the rollout. Each minibatch completes before the next to bound live device memory.
333 pub update_minibatch_size: usize,
334 /// Per-environment observation shape, excluding the environment axis.
335 pub observation_shape: Vec<usize>,
336 /// Base deterministic categorical sampling seed.
337 pub seed: u64,
338 /// Whether optimizer updates collect Vulkan timestamp statistics. Time all update submissions, summing disjoint minibatch and optimizer intervals into one sample per epoch. Collection remains caller-owned.
339 pub enable_gpu_timing: bool,
340 /// Generalized-advantage estimator policy.
341 pub gae: GaeConfig,
342 /// Clipped PPO objective coefficients.
343 pub loss: PpoLossConfig,
344}
345
346#[derive(Clone, Debug, PartialEq, Eq)]
347pub struct ItRolloutTrainingConfig {
348 /// Number of complete collection cycles.
349 pub rollouts: u64,
350 /// Time steps stored by each rollout.
351 pub horizon: usize,
352 /// Vector environments represented by each time step.
353 pub environments: usize,
354 /// Full-batch optimizer passes after each collection.
355 pub update_epochs: u64,
356 /// Device timer label for update steps.
357 pub timer_name: String,
358 /// Whether each optimizer update records and resolves Vulkan timestamps.
359 pub enable_gpu_timing: bool,
360}
361
362#[derive(Clone, Debug, PartialEq, Eq)]
363pub struct ReplayConfig {
364 /// Maximum number of retained transitions.
365 pub capacity: usize,
366 /// Per-transition observation shape, excluding the batch axis.
367 pub observation_shape: Vec<usize>,
368 /// Per-transition action shape; empty denotes one scalar action.
369 pub action_shape: Vec<usize>,
370 /// Action storage representation; currently F32 or I32.
371 pub action_dtype: DType,
372}
373
374#[derive(Clone, Debug)]
375pub struct McpTrainingConfig {
376 /// Enable safe-point pause/resume/checkpoint/evaluate/parameter/recapture commands.
377 pub enable_commands: bool,
378 /// Enable `training_pause` and `training_resume`.
379 pub enable_pause_resume: bool,
380 /// Enable `training_checkpoint`.
381 pub enable_checkpoint: bool,
382 /// Enable `training_evaluate`.
383 pub enable_evaluate: bool,
384 /// Enable `training_set_parameter`.
385 pub enable_set_parameter: bool,
386 /// Enable `training_request_recapture`.
387 pub enable_recapture: bool,
388 /// Enable `training_stop` (separately gated because it changes the terminal path).
389 pub enable_stop: bool,
390}
391
392#[derive(Clone, Copy, Debug, PartialEq, Eq)]
393pub struct PolicyEvaluationConfig {
394 /// Number of vector-environment steps to evaluate.
395 pub horizon: usize,
396 /// Reset seed and deterministic greedy operation seed.
397 pub seed: u64,
398}
399
400#[derive(Clone, Copy, Debug, PartialEq)]
401pub struct DqnLossConfig {
402 /// Next-state value discount in the inclusive range `[0, 1]`.
403 pub discount: f32,
404}
405
406/// Selected action values, detached targets, and scalar DQN loss.
407pub struct DqnLossResult {
408 /// Q values selected by the batch's action indices, shaped `[batch]`.
409 pub selected_q: Matrix,
410 /// Detached Bellman targets, shaped `[batch]`.
411 pub target_q: Matrix,
412 /// Mean unit-beta Smooth L1 loss between selected and target Q values.
413 pub loss: Matrix,
414}
415
416#[derive(Clone, Copy, Debug, PartialEq)]
417pub struct PpoLossConfig {
418 /// Symmetric policy-ratio clipping distance.
419 pub clip_epsilon: f32,
420 /// Multiplier for critic mean-squared error.
421 pub value_coefficient: f32,
422 /// Multiplier subtracted for policy entropy.
423 pub entropy_coefficient: f32,
424}
425
426/// PPO loss components retained for metrics and reverse mode.
427pub struct PpoLossResult {
428 /// Mean negative clipped surrogate objective.
429 pub policy_loss: Matrix,
430 /// Mean-squared critic error.
431 pub value_loss: Matrix,
432 /// Mean policy entropy.
433 pub entropy: Matrix,
434 /// `policy_loss + value_coefficient * value_loss - entropy_coefficient * entropy`.
435 pub total_loss: Matrix,
436}
437
438#[derive(Clone, Copy, Debug, PartialEq)]
439pub struct SacLossConfig {
440 /// Next-state value discount in the inclusive range `[0, 1]`.
441 pub discount: f32,
442 /// Non-negative entropy temperature.
443 pub entropy_coefficient: f32,
444}
445
446/// Detached target and twin-critic SAC loss components.
447pub struct SacCriticLossResult {
448 /// Detached entropy-regularized Bellman target, shaped `[batch]`.
449 pub target_q: Matrix,
450 /// Mean-squared loss for the first critic.
451 pub q1_loss: Matrix,
452 /// Mean-squared loss for the second critic.
453 pub q2_loss: Matrix,
454 /// Sum of both critic losses.
455 pub total_loss: Matrix,
456}
457
458#[derive(Clone, Copy, Debug, PartialEq, Eq)]
459pub struct CategoricalActorCriticConfig {
460 /// Number of scalar features in each observation.
461 pub observation_size: usize,
462 /// Number of discrete actions; must be at least two.
463 pub action_count: usize,
464 /// Width of both hidden layers in each independent tower.
465 pub hidden_size: usize,
466 /// Seed for the first of six independent Xavier-uniform projections.
467 pub seed: u64,
468}
469
470#[derive(Clone, Copy, Debug, PartialEq)]
471pub struct GaeConfig {
472 /// Reward discount applied to value bootstrap and the reverse trace.
473 pub gamma: f32,
474 /// Trace discount applied to the next advantage.
475 pub lambda: f32,
476}
477
478/// Generalized advantages and their matching value targets.
479pub struct GaeResult {
480 /// Advantage estimates with the same `[time, environments]` shape as reward.
481 pub advantage: Matrix,
482 /// Returns computed as `advantage + value`.
483 pub returns: Matrix,
484}
485
486#[derive(Clone, Debug, PartialEq, Eq)]
487pub struct RolloutConfig {
488 /// Number of time steps retained per collection cycle.
489 pub time: usize,
490 /// Number of vector environments represented by every step.
491 pub environments: usize,
492 /// Per-environment observation shape, excluding the environment axis.
493 pub observation_shape: Vec<usize>,
494}