1111
1212def main ():
1313 parser = argparse .ArgumentParser ("Publish VAAS model to Hugging Face" )
14+
1415 parser .add_argument ("--checkpoint-dir" , type = str , required = True )
1516 parser .add_argument ("--repo-id" , type = str , required = True )
1617 parser .add_argument ("--private" , action = "store_true" )
1718 parser .add_argument ("--alpha" , type = float , default = 0.5 )
1819 parser .add_argument ("--device" , type = str , default = "cpu" )
20+
21+ parser .add_argument ("--variant-name" , type = str , required = True )
22+ parser .add_argument ("--dataset-name" , type = str , required = True )
23+ parser .add_argument ("--dataset-fraction" , type = str , required = True )
24+ parser .add_argument ("--architecture-version" , type = str , default = "v1" )
25+
1926 args = parser .parse_args ()
2027
28+ # Deterministic revision generation
29+ revision = (
30+ f"{ args .architecture_version } -{ args .variant_name } -{ args .dataset_name .lower ()} "
31+ )
32+
2133 output_dir = "hf_artifact"
22- os .makedirs (output_dir , exist_ok = True )
34+
35+ if os .path .exists (output_dir ):
36+ shutil .rmtree (output_dir )
37+
38+ os .makedirs (output_dir )
2339
2440 pipeline = VAASPipeline .from_checkpoint (
2541 checkpoint_dir = args .checkpoint_dir ,
2642 device = args .device ,
2743 alpha = args .alpha ,
44+ variant = args .variant_name ,
45+ metadata = {
46+ "architecture_version" : args .architecture_version ,
47+ "dataset" : args .dataset_name ,
48+ "dataset_fraction" : args .dataset_fraction ,
49+ },
2850 )
2951
3052 model_path = os .path .join (output_dir , "model" )
@@ -45,7 +67,11 @@ def main():
4567
4668 config = {
4769 "architecture" : "VAAS" ,
48- "version" : "v1" ,
70+ "architecture_version" : args .architecture_version ,
71+ "revision" : revision ,
72+ "variant" : args .variant_name ,
73+ "dataset" : args .dataset_name ,
74+ "dataset_fraction" : args .dataset_fraction ,
4975 "alpha" : args .alpha ,
5076 "input_size" : [224 , 224 ],
5177 "px_checkpoint" : "px_model.pth" ,
@@ -57,56 +83,29 @@ def main():
5783 json .dump (config , f , indent = 2 )
5884
5985 api = HfApi ()
60- try :
61- create_repo (args .repo_id , private = args .private , exist_ok = True )
62- except Exception as e :
63- print (f"Repository creation skipped or failed: { e } " )
64-
65- src_pipeline_dir = os .path .join ("vaas" , "inference" )
66- dst_pipeline_dir = os .path .join (output_dir , "vaas" , "inference" )
6786
68- os .makedirs (dst_pipeline_dir , exist_ok = True )
69- vaas_root = os .path .join (output_dir , "vaas" )
70- os .makedirs (vaas_root , exist_ok = True )
87+ # Create revision branch if it does not exist
88+ create_repo (args .repo_id , private = args .private , exist_ok = True )
7189
72- open (os .path .join (vaas_root , "__init__.py" ), "w" ).close ()
73- open (os .path .join (dst_pipeline_dir , "__init__.py" ), "w" ).close ()
74-
75- shutil .copy (
76- os .path .join (src_pipeline_dir , "pipeline.py" ),
77- os .path .join (dst_pipeline_dir , "pipeline.py" ),
78- )
79-
80- shutil .copy (
81- os .path .join (src_pipeline_dir , "utils.py" ),
82- os .path .join (dst_pipeline_dir , "utils.py" ),
83- )
84-
85- shutil .copy (
86- os .path .join (src_pipeline_dir , "visualize.py" ),
87- os .path .join (dst_pipeline_dir , "visualize.py" ),
88- )
89-
90- src_doc_dir = os .path .join ("docs" )
91- dst_doc_dir = os .path .join (output_dir , "docs" )
92-
93- if os .path .exists (dst_doc_dir ):
94- shutil .rmtree (dst_doc_dir )
95-
96- shutil .copytree (src_doc_dir , dst_doc_dir )
97-
98- shutil .copy (
99- "hfREADME.md" ,
100- os .path .join (output_dir , "README.md" ),
90+ api .create_branch (
91+ repo_id = args .repo_id ,
92+ branch = revision ,
93+ exist_ok = True ,
10194 )
10295
10396 api .upload_folder (
10497 folder_path = output_dir ,
10598 repo_id = args .repo_id ,
10699 repo_type = "model" ,
100+ revision = revision ,
101+ create_pr = False ,
107102 )
108103
109- print (f"Published VAAS model to https://huggingface.co/{ args .repo_id } " )
104+ print (
105+ f"Published VAAS { args .variant_name } "
106+ f"(revision={ revision } ) "
107+ f"to https://huggingface.co/{ args .repo_id } "
108+ )
110109
111110
112111if __name__ == "__main__" :
0 commit comments