44import torch
55
66
7+ CHOSEN_PARAMETERS = {
8+ "hvit_t" : (10 , 10 , 5 ),
9+ "hvit_s" : (10 , 10 , 5 ),
10+ "hvit_b" : (8 , 10 , 5 ),
11+ "hvit_l" : (8 , 8 , 4 ),
12+ }
13+
14+
715def main ():
816 parser = argparse .ArgumentParser ()
917 parser .add_argument ("--n_epochs" , type = int , default = 100 )
1018 parser .add_argument ("--n_iterations" , type = int , default = None )
19+ parser .add_argument ("--model_type" , default = "hvit_t" , choices = ["hvit_t" , "hvit_s" , "hvit_b" , "hvit_l" ])
20+ parser .add_argument ("--batch_size" , type = int , default = 1 )
21+ parser .add_argument ("--dataset_choice" , default = "both" , choices = ["lm" , "em" , "both" ])
1122 args = parser .parse_args ()
1223
13- model_type = "hvit_t"
24+ model_type = args .model_type
25+ # Pinned per-model config (batch_size_2d, z_slices, max_num_objects); not CLI-tunable.
26+ batch_size_2d , z_slice , max_num_objects = CHOSEN_PARAMETERS [model_type ]
27+ z_slices = [z_slice ]
1428 data_path = "/mnt/vast-nhr/projects/cidas/cca/data"
1529 save_root = os .environ .get ("SAVE_ROOT" , "/mnt/vast-nhr/projects/cidas/cca/models/micro_sam2/joint/v0" )
1630
@@ -23,17 +37,17 @@ def main():
2337 name = name ,
2438 model_type = model_type ,
2539 input_path = data_path ,
26- batch_size = 1 ,
27- batch_size_2d = 8 ,
28- z_slices = [ 8 ] ,
29- dataset_choice = "both" ,
40+ batch_size = args . batch_size ,
41+ batch_size_2d = batch_size_2d ,
42+ z_slices = z_slices ,
43+ dataset_choice = args . dataset_choice ,
3044 n_workers = 8 ,
3145 n_epochs = args .n_epochs ,
3246 n_iterations = args .n_iterations ,
3347 lr = 1e-5 , # single LR for all parameters
3448 save_root = save_root ,
3549 checkpoint_path = None , # downloads default SAM2 weights if None
36- max_num_objects = 5 , # lower than interactive-only (8): joint also holds the UNETR decoder
50+ max_num_objects = max_num_objects , # lower than interactive-only (8): joint also holds the UNETR decoder
3751 prob_to_use_pt_input = 1.0 , # always point/box prompts, never the GT mask
3852 prob_to_use_box_input = 0.5 , # conditional prob of a box instead of a click
3953 num_frames_to_correct = 2 , # max frames per volume receiving correction clicks
@@ -58,6 +72,17 @@ def main():
5872 from micro_sam .v2 .training import train_joint_sam2
5973 train_joint_sam2 (** common )
6074
75+ rank = int (os .environ .get ("RANK" , "0" ))
76+ if torch .cuda .is_available () and rank == 0 :
77+ peak_alloc = torch .cuda .max_memory_allocated () / 1024 ** 3
78+ peak_reserved = torch .cuda .max_memory_reserved () / 1024 ** 3
79+ print (
80+ f"[peak-memory] model_type={ model_type } batch_size={ args .batch_size } "
81+ f"batch_size_2d={ batch_size_2d } z_slices={ z_slices } "
82+ f"max_num_objects={ max_num_objects } "
83+ f"allocated={ peak_alloc :.2f} GiB reserved={ peak_reserved :.2f} GiB" , flush = True
84+ )
85+
6186
6287if __name__ == "__main__" :
6388 main ()
0 commit comments