MCPcopy Create free account
hub / github.com/AMAP-ML/Thinking-with-Map / init_random_model

Function init_random_model

verl/scripts/init_random_model.py:77–97  ·  view source on GitHub ↗
(hf_model_path, new_config_path, output_path, trust_remote_code: bool = False)

Source from the content-addressed store, hash-verified

75
76
77def init_random_model(hf_model_path, new_config_path, output_path, trust_remote_code: bool = False):
78 config = AutoConfig.from_pretrained(hf_model_path, trust_remote_code=trust_remote_code)
79 tokenizer = AutoTokenizer.from_pretrained(hf_model_path, trust_remote_code=trust_remote_code)
80 config_dict = PretrainedConfig.get_config_dict(hf_model_path)[0]
81 print(config_dict)
82 with open(new_config_path) as f:
83 new_config_dict = json.load(f)
84 check_configs(config_dict, new_config_dict)
85 config_dict.update(new_config_dict)
86 new_confg = config.from_dict(config_dict)
87 print(f"new_config: {new_confg}")
88 if trust_remote_code:
89 model = AutoModelForCausalLM.from_pretrained(
90 hf_model_path, config=new_confg, trust_remote_code=trust_remote_code
91 )
92 else:
93 model = AutoModelForCausalLM.from_config(new_confg)
94 model.save_pretrained(output_path)
95 tokenizer.save_pretrained(output_path)
96 new_confg.save_pretrained(output_path)
97 print(f"Random model initialized and saved to {output_path}")
98
99
100if __name__ == "__main__":

Callers 1

Calls 6

check_configsFunction · 0.85
from_pretrainedMethod · 0.80
from_dictMethod · 0.80
from_configMethod · 0.80
save_pretrainedMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected