镜像自地址
https://github.com/MINT-SJTU/Evo-RL.git
已同步 2026-11-20 18:17:06 +00:00
fix: remove evo1 hardcodes and unused resume_pretrain from public code
Public training code should be policy-agnostic. This removes: - resume_pretrain config field (pretrained_path without --resume already provides the same "load weights, fresh optimizer" behavior) - evo1-specific DDP static graph and stage2 logging in lerobot_train.py - drop_last sourced from policy config (DataLoader concern, not policy) - type-inference fallback in PreTrainedConfig that was added to handle evo1 checkpoints missing a "type" field Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
这个提交包含在:
@ -161,25 +161,8 @@ class PreTrainedConfig(draccus.ChoiceRegistry, HubMixin, abc.ABC): # type: igno
|
||||
return None
|
||||
|
||||
def _save_pretrained(self, save_directory: Path) -> None:
|
||||
with tempfile.NamedTemporaryFile("w+", delete=False, suffix=".json") as tmp, draccus.config_type("json"):
|
||||
draccus.dump(self, tmp, indent=4)
|
||||
tmp_path = tmp.name
|
||||
|
||||
with open(tmp_path) as f:
|
||||
config = json.load(f)
|
||||
|
||||
if "type" not in config:
|
||||
matching_choices = [
|
||||
name for name in self.get_known_choices() if self.get_choice_class(name) is self.__class__
|
||||
]
|
||||
if len(matching_choices) != 1:
|
||||
raise ValueError(
|
||||
f"Expected exactly one registered choice for {self.__class__.__name__}, got {matching_choices}"
|
||||
)
|
||||
config["type"] = matching_choices[0]
|
||||
|
||||
with open(save_directory / CONFIG_NAME, "w") as f:
|
||||
json.dump(config, f, indent=4)
|
||||
with open(save_directory / CONFIG_NAME, "w") as f, draccus.config_type("json"):
|
||||
draccus.dump(self, f, indent=4)
|
||||
|
||||
@classmethod
|
||||
def from_pretrained(
|
||||
@ -224,34 +207,16 @@ class PreTrainedConfig(draccus.ChoiceRegistry, HubMixin, abc.ABC): # type: igno
|
||||
# apply cli overrides.
|
||||
# This is very ugly, ideally we'd like to be able to do that natively with draccus
|
||||
# something like --policy.path (in addition to --policy.type)
|
||||
with draccus.config_type("json"):
|
||||
orig_config = draccus.parse(cls, config_file, args=[])
|
||||
|
||||
if config_file is None:
|
||||
raise FileNotFoundError(f"{CONFIG_NAME} not found in {model_id}")
|
||||
|
||||
with open(config_file) as f:
|
||||
config = json.load(f)
|
||||
|
||||
if "type" in config:
|
||||
with draccus.config_type("json"):
|
||||
orig_config = draccus.parse(cls, config_file, args=[])
|
||||
else:
|
||||
parse_successes = []
|
||||
for choice_name in cls.get_known_choices():
|
||||
config_cls = cls.get_choice_class(choice_name)
|
||||
try:
|
||||
with draccus.config_type("json"):
|
||||
parsed_config = draccus.parse(config_cls, config_file, args=[])
|
||||
except Exception:
|
||||
continue
|
||||
parse_successes.append((choice_name, parsed_config))
|
||||
|
||||
if len(parse_successes) != 1:
|
||||
raise ValueError(
|
||||
f"Expected to infer exactly one policy type from {config_file}, got "
|
||||
f"{[choice for choice, _ in parse_successes]}"
|
||||
)
|
||||
orig_config = parse_successes[0][1]
|
||||
|
||||
config.pop("type", None)
|
||||
config.pop("type")
|
||||
with tempfile.NamedTemporaryFile("w+", delete=False, suffix=".json") as f:
|
||||
json.dump(config, f)
|
||||
config_file = f.name
|
||||
|
||||
@ -54,9 +54,6 @@ class TrainPipelineConfig(HubMixin):
|
||||
# Note that when resuming a run, the default behavior is to use the configuration from the checkpoint,
|
||||
# regardless of what's provided with the training command at the time of resumption.
|
||||
resume: bool = False
|
||||
# `resume_pretrain` mirrors Evo-1's stage2 handoff semantics: initialize from policy weights only while
|
||||
# starting a fresh training run with a new optimizer, scheduler and step counter.
|
||||
resume_pretrain: bool = False
|
||||
# `seed` is used for training (eg: model initialization, dataset shuffling)
|
||||
# AND for the evaluation environments.
|
||||
seed: int | None = 1000
|
||||
@ -92,16 +89,6 @@ class TrainPipelineConfig(HubMixin):
|
||||
def validate(self) -> None:
|
||||
# HACK: We parse again the cli args here to get the pretrained paths if there was some.
|
||||
policy_path = parser.get_path_arg("policy")
|
||||
if self.resume and self.resume_pretrain:
|
||||
raise ValueError("'resume' and 'resume_pretrain' are mutually exclusive.")
|
||||
|
||||
if self.resume_pretrain and not policy_path and (
|
||||
self.policy is None or self.policy.pretrained_path is None
|
||||
):
|
||||
raise ValueError(
|
||||
"'resume_pretrain=true' expects weights via '--policy.path' or 'policy.pretrained_path'."
|
||||
)
|
||||
|
||||
if policy_path:
|
||||
# Only load the policy config
|
||||
cli_overrides = parser.get_cli_overrides("policy")
|
||||
|
||||
@ -267,12 +267,6 @@ def train(
|
||||
|
||||
if is_main_process:
|
||||
logging.info("Creating policy")
|
||||
if cfg.resume_pretrain:
|
||||
logging.info(
|
||||
"resume_pretrain=true: policy weights will be initialized from %s, while optimizer,"
|
||||
" scheduler, and global step will start fresh.",
|
||||
cfg.policy.pretrained_path,
|
||||
)
|
||||
policy = make_policy(
|
||||
cfg=cfg.policy,
|
||||
ds_meta=dataset.meta,
|
||||
@ -288,9 +282,7 @@ def train(
|
||||
# Wait for all processes to finish policy creation before continuing
|
||||
accelerator.wait_for_everyone()
|
||||
|
||||
# Create processors. `resume_pretrain` intentionally follows the fresh-start path:
|
||||
# load policy weights from `pretrained_path`, but rebuild processor state from the
|
||||
# current dataset and do not restore optimizer / scheduler / global step.
|
||||
# Create processors - only provide dataset_stats if not resuming from saved processors
|
||||
processor_kwargs = {}
|
||||
postprocessor_kwargs = {}
|
||||
if (cfg.policy.pretrained_path and not cfg.resume) or not cfg.policy.pretrained_path:
|
||||
@ -401,7 +393,7 @@ def train(
|
||||
shuffle=shuffle and not cfg.dataset.streaming,
|
||||
sampler=sampler,
|
||||
pin_memory=device.type == "cuda",
|
||||
drop_last=getattr(cfg.policy, "drop_last", False),
|
||||
drop_last=False,
|
||||
prefetch_factor=2 if cfg.num_workers > 0 else None,
|
||||
)
|
||||
|
||||
@ -410,14 +402,6 @@ def train(
|
||||
policy, optimizer, dataloader, lr_scheduler = accelerator.prepare(
|
||||
policy, optimizer, dataloader, lr_scheduler
|
||||
)
|
||||
if (
|
||||
accelerator.num_processes > 1
|
||||
and cfg.policy.type == "evo1"
|
||||
and getattr(cfg.policy, "training_stage", None) == "stage2"
|
||||
and hasattr(policy, "_set_static_graph")
|
||||
):
|
||||
logging.info("Enabling DDP static graph for Evo1 stage2.")
|
||||
policy._set_static_graph()
|
||||
dl_iter = cycle(dataloader)
|
||||
|
||||
policy.train()
|
||||
|
||||
在新工单中引用
屏蔽一个用户