MCPcopy Create free account
hub / github.com/agentscope-ai/Trinity-RFT / get_verl_checkpoint_info

Function get_verl_checkpoint_info

trinity/common/models/utils.py:313–346  ·  view source on GitHub ↗

Get the checkpoint directory from a Verl root checkpoint directory. Args: checkpoint_path (str): The root checkpoint directory. step_num (Optional[int], optional): The step number. If specified, load the checkpoint with the specified step number. If None,

(
    checkpoint_path: str, step_num: Optional[int] = None, raise_error: bool = True
)

Source from the content-addressed store, hash-verified

311
312
313def get_verl_checkpoint_info(
314 checkpoint_path: str, step_num: Optional[int] = None, raise_error: bool = True
315) -> Tuple[str, int]:
316 """Get the checkpoint directory from a Verl root checkpoint directory.
317
318 Args:
319 checkpoint_path (str): The root checkpoint directory.
320 step_num (Optional[int], optional): The step number. If specified,
321 load the checkpoint with the specified step number. If None,
322 load the latest checkpoint. Defaults to None.
323 raise_error (bool): Whether to raise an error if the checkpoint does not exist.
324
325 Returns:
326 Tuple[str, int]: The checkpoint directory and the step number of the checkpoint.
327 """
328 if step_num is None:
329 # load latest checkpoint
330 iteration_file = os.path.join(checkpoint_path, "latest_checkpointed_iteration.txt")
331 if os.path.exists(iteration_file):
332 with open(
333 iteration_file, "r", encoding="utf-8"
334 ) as f: # TODO: this file may be modified simultaneously
335 iteration = f.read().strip()
336 return os.path.join(checkpoint_path, f"global_step_{iteration}"), int(iteration)
337 elif raise_error:
338 raise FileNotFoundError(f"No iteration file found in {checkpoint_path}")
339 else:
340 return None, 0 # type: ignore
341 else:
342 # load specific iteration checkpoint
343 path = os.path.join(checkpoint_path, f"global_step_{step_num}")
344 if not os.path.exists(path) and raise_error:
345 raise FileNotFoundError(f"Checkpoint {path} not found")
346 return path, step_num
347
348
349# modified from verl/model_merger/fsdp_model_merger.py

Callers 1

Calls 1

readMethod · 0.45

Tested by

no test coverage detected