@@ -70,34 +70,7 @@ ckp_path = os.path.join(checkpoint_root_dir, project, name, "global_step_100", "
7070state_dict = load_fsdp_state_dict_from_verl_checkpoint(ckp_path)
7171model.load_state_dict(state_dict)
7272output_dir = os.path.join(ckp_path, " huggingface" )
73-
74- def save_to_huggingface_checkpoint (state_dict : dict , output_dir : str ):
75- """ Convert state dict to Hugging Face format and save it.
76-
77- Args:
78- state_dict: The state dict loaded from the Verl checkpoint.
79- output_dir: The directory to save the Hugging Face checkpoint.
80- """
81- import os
82- import torch
83- from transformers import PreTrainedModel
84-
85- os.makedirs(output_dir, exist_ok = True )
86-
87- # Convert state dict keys to Hugging Face format if needed
88- hf_state_dict = {}
89- for key, value in state_dict.items():
90- # Add any key mapping logic here if needed
91- # Example:
92- # if key.startswith("model."):
93- # new_key = key.replace("model.", "")
94- # hf_state_dict[new_key] = value
95- # else:
96- # hf_state_dict[key] = value
97- hf_state_dict[key] = value
98- torch.save(hf_state_dict, os.path.join(output_dir, " pytorch_model.bin" ))
99-
100- save_to_huggingface_checkpoint(state_dict, output_dir)
73+ model.save_pretrained(output_dir)
10174```
10275
10376## Evaluate the Trained Model on BFCL
0 commit comments