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