Auto-sync: 2026-06-30 09:33:44
Browse filesFiles changed (5)
143 unmodified lines14414514614714814923 unmodified lines173174175176177178179180181182183184185202 unmodified lines38838939039139239339415 unmodified lines410411412413414415997 unmodified lines14131414141514161417141814 unmodified lines143314341435143614371438409 unmodified lines184818491850185118521853785 unmodified lines2639264026412642264326442645158 unmodified lines2804280528062807280828091 unmodified line281128122813281428152816143 unmodified linesfield, and executes the best chunk. This keeps the proposal geometry counterfactual whileavoiding same-state validation candidates.When ``selection_mode == 'field_optim'`` the evaluator starts from the policy mean plusoptional Gaussian multi-start proposals, performs projected gradient ascent on the learnedfield potential in action space, and executes the best optimized chunk. This is still23 unmodified lines"policy","field","field_optim","lattice","retrieval_lattice","retrieval_residual",}:raise ValueError("selection_mode must be 'policy', 'field', 'field_optim', 'lattice', ""'retrieval_lattice', or 'retrieval_residual'")if num_candidates <= 0:raise ValueError("num_candidates must be positive")202 unmodified linestask_summaries[task_id] = _summarize_rows(task_rows)effective_num_candidates = num_candidatesif selection_mode in {"lattice", "retrieval_lattice", "retrieval_residual"}:effective_num_candidates = max([int(row.get("lattice_candidate_count", 0)) for row in rows],default=0,15 unmodified linesif selection_mode in {"field", "field_optim", "retrieval_residual"}and num_candidates > 1else 0.0,"selection_margin": selection_margin,"prepend_policy_candidate": bool(prepend_policy_candidate),"field_optim_steps": field_optim_steps997 unmodified linesretrieval_residual_scales),retrieval_residual_reduce=retrieval_residual_reduce,),"selected_residual_scale": _selected_residual_scale(case,14 unmodified linesretrieval_residual_scales),retrieval_residual_reduce=retrieval_residual_reduce,),"candidate_source_group_id": case.candidate_source_group_id,}409 unmodified linespolicy_mean = model.forward_policy(observations, instructions)batch_size = policy_mean.shape[0]if selection_mode == "retrieval_residual":if action_candidates is None:raise ValueError("retrieval_residual selection requires action_candidates")785 unmodified linesprepended_policy_candidate: bool = False,residual_scale_count: int = 1,retrieval_residual_reduce: str = "none",) -> int:count = len(case.candidate_action_values)if prepended_policy_candidate and selection_mode in {"lattice", "retrieval_lattice"}:count += 1158 unmodified linesprepended_policy_candidate: bool = False,residual_scale_count: int = 1,retrieval_residual_reduce: str = "none",) -> str:if selection_mode == "policy":return "policy_continuous"1 unmodified linereturn "field_selected"if selection_mode == "field_optim":return "field_optim_selected"if selection_mode == "retrieval_residual":if retrieval_residual_reduce in _FIELD_CONDITIONED_RESIDUAL_REDUCERS:scale_count = max(1, int(residual_scale_count))143 unmodified lines14414514614714814915015115215315415523 unmodified lines179180181182183184185186187188189190191192193202 unmodified lines39639739839940040140240340440540640715 unmodified lines423424425426427428429430431997 unmodified lines142914301431143214331434143514 unmodified lines1450145114521453145414551456409 unmodified lines18661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894785 unmodified lines2680268126822683268426852686268726882689158 unmodified lines28482849285028512852285328541 unmodified line28562857285828592860286128622863286428652866286728682869143 unmodified linesfield, and executes the best chunk. This keeps the proposal geometry counterfactual whileavoiding same-state validation candidates.When ``selection_mode == 'proposal_lattice'`` the model generates a fixed typedcounterfactual proposal set directly from the current state and instruction. The learnedfield scores those model-generated proposals and executes one selected chunk, preservingclean deployment while testing whether proposal support, not field scoring, is thebottleneck.When ``selection_mode == 'field_optim'`` the evaluator starts from the policy mean plusoptional Gaussian multi-start proposals, performs projected gradient ascent on the learnedfield potential in action space, and executes the best optimized chunk. This is still23 unmodified lines"policy","field","field_optim","proposal_lattice","lattice","retrieval_lattice","retrieval_residual",}:raise ValueError("selection_mode must be 'policy', 'field', 'field_optim', ""'proposal_lattice', 'lattice', 'retrieval_lattice', or ""'retrieval_residual'")if num_candidates <= 0:raise ValueError("num_candidates must be positive")202 unmodified linestask_summaries[task_id] = _summarize_rows(task_rows)effective_num_candidates = num_candidatesif selection_mode in {"proposal_lattice","lattice","retrieval_lattice","retrieval_residual",}:effective_num_candidates = max([int(row.get("lattice_candidate_count", 0)) for row in rows],default=0,15 unmodified linesif selection_mode in {"field", "field_optim", "retrieval_residual"}and num_candidates > 1else 0.0,"proposal_types": list(model_config.proposal_types)if selection_mode == "proposal_lattice"else [],"selection_margin": selection_margin,"prepend_policy_candidate": bool(prepend_policy_candidate),"field_optim_steps": field_optim_steps997 unmodified linesretrieval_residual_scales),retrieval_residual_reduce=retrieval_residual_reduce,proposal_types=model_config.proposal_types,),"selected_residual_scale": _selected_residual_scale(case,14 unmodified linesretrieval_residual_scales),retrieval_residual_reduce=retrieval_residual_reduce,proposal_type_count=len(model_config.proposal_types),),"candidate_source_group_id": case.candidate_source_group_id,}409 unmodified linespolicy_mean = model.forward_policy(observations, instructions)batch_size = policy_mean.shape[0]if selection_mode == "proposal_lattice":proposals = model.forward_proposals(observations, instructions)return _select_lattice_action_chunk(model,observations,instructions,proposals,torch=torch,action_low=(action_low.unsqueeze(1)if action_low is not None and action_low.ndim == 3else action_low),action_high=(action_high.unsqueeze(1)if action_high is not None and action_high.ndim == 3else action_high),candidate_mask=None,candidate_type_bonus=None,selection_margin=selection_margin,baseline_action=policy_mean if prepend_policy_candidate else None,)if selection_mode == "retrieval_residual":if action_candidates is None:raise ValueError("retrieval_residual selection requires action_candidates")785 unmodified linesprepended_policy_candidate: bool = False,residual_scale_count: int = 1,retrieval_residual_reduce: str = "none",proposal_type_count: int = 0,) -> int:if selection_mode == "proposal_lattice":return int(proposal_type_count) + (1 if prepended_policy_candidate else 0)count = len(case.candidate_action_values)if prepended_policy_candidate and selection_mode in {"lattice", "retrieval_lattice"}:count += 1158 unmodified linesprepended_policy_candidate: bool = False,residual_scale_count: int = 1,retrieval_residual_reduce: str = "none",proposal_types: tuple[str, ...] = (),) -> str:if selection_mode == "policy":return "policy_continuous"1 unmodified linereturn "field_selected"if selection_mode == "field_optim":return "field_optim_selected"if selection_mode == "proposal_lattice":if prepended_policy_candidate:if selected_index == 0:return "policy_continuous"selected_index -= 1if 0 <= selected_index < len(proposal_types):return f"proposal_{proposal_types[selected_index]}"return "proposal_unknown"if selection_mode == "retrieval_residual":if retrieval_residual_reduce in _FIELD_CONDITIONED_RESIDUAL_REDUCERS:scale_count = max(1, int(residual_scale_count))
41 unmodified lines4243444546473 unmodified lines515253545556190 unmodified lines24724824925025125227 unmodified lines28028128228328428541 unmodified linesbackbone_model: str | None = Nonebackbone_freeze: bool = Truebackbone_local_files_only: bool = True# Backward-compatible aliases from the first scaffold.observation_dim: int | None = Nonelanguage_dim: int | None = None3 unmodified linesself.obs_dim = int(self.observation_dim)if self.language_dim is not None:self.lang_dim = int(self.language_dim)for name in ("obs_dim","lang_dim",190 unmodified linesself.config.action_dim,action_horizon=self.config.action_horizon,)self.effect_head = EffectHead(self.config.intervention_dim, self.config.effect_dim)self.reward_head = RewardHead(self.config.intervention_dim)self.regret_head = RegretHead(self.config.intervention_dim)27 unmodified linescontext = self.encode_context(observation, instruction)return self.policy_head(context)def forward_effect(self, observation, instruction, action, skill_type=None):z = self.encode_intervention(observation, instruction, action, skill_type=skill_type)return self.interventional_field(z)41 unmodified lines424344454647483 unmodified lines5253545556575859606162636465190 unmodified lines25625725825926026126226326426526626726826927027127227327427527627727827928027 unmodified lines30830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734841 unmodified linesbackbone_model: str | None = Nonebackbone_freeze: bool = Truebackbone_local_files_only: bool = Trueproposal_types: tuple[str, ...] = ()# Backward-compatible aliases from the first scaffold.observation_dim: int | None = Nonelanguage_dim: int | None = None3 unmodified linesself.obs_dim = int(self.observation_dim)if self.language_dim is not None:self.lang_dim = int(self.language_dim)if isinstance(self.proposal_types, str):self.proposal_types = tuple(item.strip()for item in self.proposal_types.split(",")if item.strip())else:self.proposal_types = tuple(str(item) for item in self.proposal_types)for name in ("obs_dim","lang_dim",190 unmodified linesself.config.action_dim,action_horizon=self.config.action_horizon,)self.proposal_types = tuple(self.config.proposal_types)if self.proposal_types:self.proposal_type_to_index = {proposal_type: indexfor index, proposal_type in enumerate(self.proposal_types)}self.proposal_type_embedding = nn.Embedding(len(self.proposal_types),self.config.hidden_dim,)self.proposal_head = PolicyHead(self.config.hidden_dim,self.config.action_dim,action_horizon=self.config.action_horizon,)else:self.proposal_type_to_index = {}self.proposal_type_embedding = Noneself.proposal_head = Noneself.effect_head = EffectHead(self.config.intervention_dim, self.config.effect_dim)self.reward_head = RewardHead(self.config.intervention_dim)self.regret_head = RegretHead(self.config.intervention_dim)27 unmodified linescontext = self.encode_context(observation, instruction)return self.policy_head(context)def forward_proposals(self, observation, instruction, proposal_types=None):"""Generate a typed counterfactual proposal lattice for each state.The standard policy head stays unimodal. This optional head predicts one actionchunk per configured intervention family, giving the learned field a cleandeployment-time proposal set without reading same-state dataset candidates."""if not self.proposal_types or self.proposal_type_embedding is None:raise ValueError("DoVLAConfig.proposal_types is empty")requested = tuple(proposal_types) if proposal_types is not None else self.proposal_typesmissing = [proposal_typefor proposal_type in requestedif proposal_type not in self.proposal_type_to_index]if missing:raise ValueError(f"unknown proposal_types: {missing}")context = self.encode_context(observation, instruction)indices = torch.tensor([self.proposal_type_to_index[proposal_type] for proposal_type in requested],dtype=torch.long,device=context.device,)type_features = self.proposal_type_embedding(indices)fused = context.unsqueeze(1) + type_features.unsqueeze(0)flat = fused.reshape(context.shape[0] * len(requested), context.shape[-1])proposals = self.proposal_head(flat)return proposals.reshape(context.shape[0],len(requested),self.config.action_horizon,self.config.action_dim,)def forward_effect(self, observation, instruction, action, skill_type=None):z = self.encode_intervention(observation, instruction, action, skill_type=skill_type)return self.interventional_field(z)
372 unmodified lines373374375376377378372 unmodified linesfield_preference: float = 1.0field_effect: float = 1.0field_anchor: float = 0.25# Backward-compatible aliases from the first config schema.bc_best_action: float = 1.0forward_effect_prediction: float = 1.0372 unmodified lines373374375376377378379372 unmodified linesfield_preference: float = 1.0field_effect: float = 1.0field_anchor: float = 0.25proposal: float = 0.0# Backward-compatible aliases from the first config schema.bc_best_action: float = 1.0forward_effect_prediction: float = 1.0
66 unmodified lines67686970717233 unmodified lines10610710810911011129 unmodified lines141142143144145146154 unmodified lines30130230330430530610 unmodified lines3173183193203213223233243253267 unmodified lines3343353363373383393 unmodified lines34334434534634734811 unmodified lines36036136236336436555 unmodified lines42142242342442542619 unmodified lines446447448449450451234 unmodified lines68668768868969069166 unmodified linesbackbone_feature_batch_size: int = 64policy_target_types: tuple[str, ...] = ()policy_target_map: str | Path | None = Nonedef __post_init__(self) -> None:if self.lr is not None:33 unmodified linesfor item in self.policy_target_types.split(",")if item.strip())if self.policy_target_map is not None:self.policy_target_map = Path(self.policy_target_map)29 unmodified linesbackbone_model=config.backbone_model,backbone_freeze=config.backbone_freeze,backbone_local_files_only=config.backbone_local_files_only,)self.model = Noneself.optimizer = None154 unmodified linespred_best_actions = self.model.forward_policy(best_obs, best_instructions)bc = behavior_cloning_loss(pred_best_actions, best_actions)effect = effect_prediction_loss(effect_outputs["effect_vector"], effect_target)success = success_loss(effect_outputs["success_logit"], target_success)progress = progress_loss(effect_outputs["progress"], target_progress)10 unmodified linesaction_features=action,neighbors_per_node=self.config.lattice_neighbors,)if self.config.objective == "lattice_field":anchor = float(weights.field_anchor)total = (weights.weight("bc") * bc+ float(weights.field_potential) * field["potential"]+ float(weights.field_preference) * field["preference"]+ float(weights.field_effect) * field["effect"]7 unmodified lineselse:total = (weights.weight("bc") * bc+ weights.weight("effect") * effect+ weights.weight("success") * success+ weights.weight("progress") * progress3 unmodified linesmetrics = self._batch_metrics(total=total,bc=bc,rank=rank,pred_reward=pred_reward,pred_progress=effect_outputs["progress"],11 unmodified lines)return total, metricsdef _policy_bc_targets(self, records: list[CILRecord]) -> tuple[list[CILRecord], Any]:assert torch is not Nonetarget_records: list[CILRecord] = []55 unmodified lines*,total,bc,rank,pred_reward,pred_progress,19 unmodified linesreturn {"total_loss": float(total.detach().cpu()),"bc_loss": float(bc.detach().cpu()),"rank_loss": float(rank.detach().cpu()),"rank_acc": float(rank_acc),"progress_mae": float(progress_mae),234 unmodified linesreturn {"total_loss": 0.0,"bc_loss": 0.0,"rank_loss": 0.0,"rank_acc": 0.0,"progress_mae": 0.0,66 unmodified lines6768697071727333 unmodified lines10710810911011111211311411511611711811912029 unmodified lines150151152153154155156154 unmodified lines31131231331431531631710 unmodified lines3283293303313323333343353363373383393407 unmodified lines3483493503513523533543 unmodified lines35835936036136236336411 unmodified lines37637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643755 unmodified lines49349449549649749849919 unmodified lines519520521522523524525234 unmodified lines76076176276376476576666 unmodified linesbackbone_feature_batch_size: int = 64policy_target_types: tuple[str, ...] = ()policy_target_map: str | Path | None = Noneproposal_types: tuple[str, ...] = ()def __post_init__(self) -> None:if self.lr is not None:33 unmodified linesfor item in self.policy_target_types.split(",")if item.strip())if isinstance(self.proposal_types, str):self.proposal_types = tuple(item.strip()for item in self.proposal_types.split(",")if item.strip())else:self.proposal_types = tuple(str(item) for item in self.proposal_types)if self.policy_target_map is not None:self.policy_target_map = Path(self.policy_target_map)29 unmodified linesbackbone_model=config.backbone_model,backbone_freeze=config.backbone_freeze,backbone_local_files_only=config.backbone_local_files_only,proposal_types=config.proposal_types,)self.model = Noneself.optimizer = None154 unmodified linespred_best_actions = self.model.forward_policy(best_obs, best_instructions)bc = behavior_cloning_loss(pred_best_actions, best_actions)proposal = bc * 0.0effect = effect_prediction_loss(effect_outputs["effect_vector"], effect_target)success = success_loss(effect_outputs["success_logit"], target_success)progress = progress_loss(effect_outputs["progress"], target_progress)10 unmodified linesaction_features=action,neighbors_per_node=self.config.lattice_neighbors,)if self.config.proposal_types and float(weights.proposal) > 0.0:proposal = self._proposal_bc_loss(records)if self.config.objective == "lattice_field":anchor = float(weights.field_anchor)total = (weights.weight("bc") * bc+ float(weights.proposal) * proposal+ float(weights.field_potential) * field["potential"]+ float(weights.field_preference) * field["preference"]+ float(weights.field_effect) * field["effect"]7 unmodified lineselse:total = (weights.weight("bc") * bc+ float(weights.proposal) * proposal+ weights.weight("effect") * effect+ weights.weight("success") * success+ weights.weight("progress") * progress3 unmodified linesmetrics = self._batch_metrics(total=total,bc=bc,proposal=proposal,rank=rank,pred_reward=pred_reward,pred_progress=effect_outputs["progress"],11 unmodified lines)return total, metricsdef _proposal_bc_loss(self, records: list[CILRecord]) -> Any:assert torch is not Noneassert self.model is not Nonegrouped: dict[str, CILRecord] = {}for record in records:grouped.setdefault(record.group_id, record)input_records: list[CILRecord] = []target_values: list[list[list[list[float]]]] = []target_mask: list[list[float]] = []zero_action = [[0.0 for _ in range(self.config.action_dim)]for _ in range(self.config.action_horizon)]for group_id, fallback_record in grouped.items():try:group_records = self.dataset.get_group(group_id)except KeyError:group_records = [record for record in records if record.group_id == group_id]input_records.append(group_records[0] if group_records else fallback_record)group_targets: list[list[list[float]]] = []group_mask: list[float] = []for proposal_type in self.config.proposal_types:candidates = [recordfor record in group_recordsif record.candidate_type == proposal_type]if candidates:target = max(candidates, key=_record_score)group_targets.append(vectorize_toy_action(target.action_chunk,action_dim=self.config.action_dim,action_horizon=self.config.action_horizon,))group_mask.append(1.0)else:group_targets.append(zero_action)group_mask.append(0.0)target_values.append(group_targets)target_mask.append(group_mask)if not input_records or not any(any(row) for row in target_mask):return self.model.forward_policy(self._obs_tensor(records[:1]),[records[0].instruction] if records else [""],).sum() * 0.0predictions = self.model.forward_proposals(self._obs_tensor(input_records),[record.instruction for record in input_records],)targets = torch.tensor(target_values, dtype=torch.float32, device=self.device)mask = torch.tensor(target_mask, dtype=torch.float32, device=self.device)return behavior_cloning_loss(predictions, targets, mask=mask)def _policy_bc_targets(self, records: list[CILRecord]) -> tuple[list[CILRecord], Any]:assert torch is not Nonetarget_records: list[CILRecord] = []55 unmodified lines*,total,bc,proposal,rank,pred_reward,pred_progress,19 unmodified linesreturn {"total_loss": float(total.detach().cpu()),"bc_loss": float(bc.detach().cpu()),"proposal_loss": float(proposal.detach().cpu()),"rank_loss": float(rank.detach().cpu()),"rank_acc": float(rank_acc),"progress_mae": float(progress_mae),234 unmodified linesreturn {"total_loss": 0.0,"bc_loss": 0.0,"proposal_loss": 0.0,"rank_loss": 0.0,"rank_acc": 0.0,"progress_mae": 0.0,
259 unmodified lines260261262259 unmodified linesNo files have been modified since last commit. Skipping to prevent empty commit.No files have been modified since last commit. Skipping to prevent empty commit.No files have been modified since last commit. Skipping to prevent empty commit.259 unmodified lines260261262263259 unmodified linesNo files have been modified since last commit. Skipping to prevent empty commit.No files have been modified since last commit. Skipping to prevent empty commit.No files have been modified since last commit. Skipping to prevent empty commit.No files have been modified since last commit. Skipping to prevent empty commit.
dovla_cil/eval/maniskill_policy_rollout.py+56-3
dovla_cil/models/dovla.py+63
dovla_cil/training/losses.py+1
dovla_cil/training/trainer.py+75
logs/auto_sync_hf.log+1