"""Future-timestep keypose supervision from the existing annotated trajectories. Query i receives the primitive target attached to demonstration time t + i, rather than another copy of time t's primitive target. Observations and optional phase supervision still describe only time t. Wrap KeyposeDataset before action normalization so its original per-timestep population continues to define stats. """ import torch from pydantic import BaseModel, ConfigDict from torch.utils.data import Dataset from lim.keypose_policy import KeyposeDataset class KeyposeSequenceDatasetConfig(BaseModel, frozen=True): model_config = ConfigDict( arbitrary_types_allowed=True, extra="forbid", use_attribute_docstrings=True ) dataset: KeyposeDataset """Unnormalized keypose dataset owning observations, slices, and full targets.""" class KeyposeSequenceDataset(Dataset): def __init__(self, config: KeyposeSequenceDatasetConfig): self.config = config self.dataset = config.dataset def __getattr__(self, name): return getattr(self.dataset, name) def __len__(self): return len(self.dataset) def __getitem__(self, index): sample = self.dataset[index] trajectory, step = self.dataset.slices[index] targets = self.dataset.trajectories["actions"][trajectory] times = torch.arange( step, step + self.dataset.num_queries, device=targets.device ).clamp_max(len(targets) - 1) # Padding holds the final world keypose and its gripper command. It is # deliberately not the zero-increment stop padding used by dense actions. # Use original physical timesteps, including filtered-out observations; # the selected slice list controls obs_t sampling, not future label time. return {**sample, "actions": targets.index_select(0, times)}