"""Shared S4/S16 and P/R orchestration around the unchanged sequence trainer.""" import math import torch from .sequence_trainer import SequenceTrainer, full_masks from .layer_state import packed from .checkpoint import cpu_tree def training_masks(config,device): masks=full_masks(1,config.sequence_length,config.horizon,device) masks.action_dimension=(torch.arange(config.action_dim,device=device)self.max_bytes: raise MemoryError('Allocated-memory guard exceeded') if state: for s in state.values(): for w in s.weights: if not torch.isfinite(w).all() or float(w.detach().abs().max())>self.max_fast:raise FloatingPointError('Fast-state guard') def learning_rates(self,modules): for layer in modules.values(): value=float(layer.inner_lr.detach()) if not math.isfinite(value) or not self.lr_bounds[0]<=value<=self.lr_bounds[1]:raise FloatingPointError('Inner-LR guard') def generate_chunk(adapter,prepared,noise,incoming): """The model computation receives no target, episode ID, split or source index.""" with torch.no_grad():prediction,candidate,trace=adapter.rollout(prepared,noise.clone(),incoming,differentiable=False) if prediction.shape!=(noise.shape[0],10,32) or not torch.isfinite(prediction).all():raise ValueError('Prediction shape/finite') if candidate: if trace['commits']!=1 or trace['whole_vector_from_iteration']!=9:raise RuntimeError('Commit contract') return prediction,candidate,trace