@@ -12,13 +12,7 @@ struct Args {
1212 device : String ,
1313
1414 /// source image paths (can specify multiple)
15- #[ argh(
16- option,
17- default = "vec![
18- String::from(\" ./assets/sam3-demo.jpg\" ),
19- // String::from(\" ./assets/bus.jpg\" )
20- ]"
21- ) ]
15+ #[ argh( option, default = "vec![String::from(\" ./assets/sam3-demo.jpg\" )]" ) ]
2216 source : Vec < String > ,
2317
2418 /// prompts: "text;pos:x,y,w,h;neg:x,y,w,h" (can specify multiple)
@@ -29,37 +23,61 @@ struct Args {
2923 #[ argh( option, default = "0.5" ) ]
3024 conf : f32 ,
3125
32- /// image batch size min
26+ /// show mask
27+ #[ argh( switch) ]
28+ show_mask : bool ,
29+
30+ /// dtype
31+ #[ argh( option, default = "String::from(\" q4f16\" )" ) ]
32+ dtype : String ,
33+
34+ /// vision encoder batch min
3335 #[ argh( option, default = "1" ) ]
34- batch_min : usize ,
36+ vision_batch_min : usize ,
3537
36- /// image batch size
38+ /// vision encoder batch opt
3739 #[ argh( option, default = "1" ) ]
38- batch : usize ,
40+ vision_batch : usize ,
3941
40- /// image batch size max
42+ /// vision encoder batch max
4143 #[ argh( option, default = "8" ) ]
42- batch_max : usize ,
44+ vision_batch_max : usize ,
4345
44- /// text batch size min
46+ /// text encoder batch min
4547 #[ argh( option, default = "1" ) ]
4648 text_batch_min : usize ,
4749
48- /// text batch size
50+ /// text encoder batch opt
4951 #[ argh( option, default = "4" ) ]
5052 text_batch : usize ,
5153
52- /// text batch size max
54+ /// text encoder batch max
5355 #[ argh( option, default = "16" ) ]
5456 text_batch_max : usize ,
5557
56- /// dtype
57- #[ argh( option, default = "String::from( \" q4f16 \" ) " ) ]
58- dtype : String ,
58+ /// geometry encoder batch min
59+ #[ argh( option, default = "1 " ) ]
60+ geo_batch_min : usize ,
5961
60- /// show mask
61- #[ argh( switch) ]
62- show_mask : bool ,
62+ /// geometry encoder batch opt
63+ #[ argh( option, default = "8" ) ]
64+ geo_batch : usize ,
65+
66+ /// geometry encoder batch max
67+ #[ argh( option, default = "16" ) ]
68+ geo_batch_max : usize ,
69+
70+ /// decoder batch min
71+ #[ argh( option, default = "1" ) ]
72+ decoder_batch_min : usize ,
73+
74+ /// decoder batch opt
75+ #[ argh( option, default = "1" ) ]
76+ decoder_batch : usize ,
77+
78+ /// decoder batch max
79+ #[ argh( option, default = "8" ) ]
80+ decoder_batch_max : usize ,
6381}
6482
6583fn main ( ) -> Result < ( ) > {
@@ -80,16 +98,28 @@ fn main() -> Result<()> {
8098 . collect :: < std:: result:: Result < Vec < _ > , _ > > ( )
8199 . map_err ( |e| anyhow:: anyhow!( "{}" , e) ) ?;
82100
83- // Build model
101+ // Build model with per-encoder batch sizes
84102 let config = Config :: sam3_image_predictor ( )
85103 . with_dtype_all ( args. dtype . parse ( ) ?)
86104 . with_class_confs ( & [ args. conf ] )
87- . with_batch_size_all_min_opt_max ( args. batch_min , args. batch , args. batch_max )
105+ // Per-encoder batch sizes for TensorRT (min, opt, max)
106+ . with_visual_encoder_batch_min_opt_max (
107+ args. vision_batch_min ,
108+ args. vision_batch ,
109+ args. vision_batch_max ,
110+ )
88111 . with_textual_encoder_batch_min_opt_max (
89112 args. text_batch_min ,
90113 args. text_batch ,
91114 args. text_batch_max ,
92115 )
116+ . with_encoder_batch_min_opt_max ( args. geo_batch_min , args. geo_batch , args. geo_batch_max )
117+ . with_decoder_batch_min_opt_max (
118+ args. decoder_batch_min ,
119+ args. decoder_batch ,
120+ args. decoder_batch_max ,
121+ )
122+ // Device configuration
93123 // => If your GPU memory is insufficient, you can place some modules on CPU
94124 // .with_visual_encoder_device(args.device.parse()?)
95125 // .with_textual_encoder_device(args.device.parse()?)
@@ -109,7 +139,7 @@ fn main() -> Result<()> {
109139
110140 // DataLoader with batch iteration
111141 let dataloader = DataLoader :: from_paths ( & args. source ) ?
112- . with_batch ( args. batch )
142+ . with_batch ( args. vision_batch )
113143 . with_progress_bar ( true )
114144 . build ( ) ?;
115145
@@ -125,10 +155,10 @@ fn main() -> Result<()> {
125155 }
126156 }
127157
128- // Cache info
129- let ( cached_count, mem_mb) = model. cache_stats ( ) ;
130- println ! ( "Cache: {} texts, ~{}MB" , cached_count, mem_mb) ;
158+ // Cache stats
159+ model. cache_stats ( ) ;
131160
161+ // Performance stats
132162 usls:: perf ( false ) ;
133163
134164 Ok ( ( ) )
0 commit comments