7878 7. Print detailed tensor outputs:
7979
8080 $ litert run model.tflite --print-tensors --sample-size 10
81+
82+ 8. Run with multiple accelerators (npu -> gpu -> cpu fallback):
83+
84+ $ litert run model.tflite --npu --gpu --cpu
85+
86+ OR explicitly:
87+
88+ $ litert run model.tflite --accelerator npu,gpu,cpu
8189 """ ),
8290)
8391@deps .require_extra ("run" )
118126 flag_value = "android" ,
119127 help = "Target Android platform to run." ,
120128)
129+ @click .option (
130+ "--accelerator" ,
131+ type = str ,
132+ help = "Comma-separated list of hardware accelerators (e.g. npu,gpu,cpu)." ,
133+ )
121134@click .option (
122135 "--cpu" ,
123- "accelerator" ,
124- flag_value = "cpu" ,
125- default = True ,
126- help = "Use CPU accelerator (Default)." ,
136+ is_flag = True ,
137+ help = "Use CPU accelerator." ,
127138)
128139@click .option (
129140 "--gpu" ,
130- "accelerator" ,
131- flag_value = "gpu" ,
141+ is_flag = True ,
132142 help = "Use GPU accelerator." ,
133143)
134144@click .option (
135145 "--npu" ,
136- "accelerator" ,
137- flag_value = "npu" ,
146+ is_flag = True ,
138147 help = "Use NPU accelerator." ,
139148)
140149@click .option (
@@ -169,7 +178,10 @@ def run_cmd(
169178 model_params : Sequence [str ],
170179 model_help : bool ,
171180 target : str ,
172- accelerator : str ,
181+ accelerator : str | None ,
182+ cpu : bool ,
183+ gpu : bool ,
184+ npu : bool ,
173185 signature_index : int ,
174186 iterations : int ,
175187 print_tensors : bool ,
@@ -185,11 +197,33 @@ def run_cmd(
185197 model_help: Show help specific to the matched model plugin.
186198 target: Execution target ('desktop' or 'android').
187199 accelerator: Hardware accelerator ('cpu', 'gpu', or 'npu').
200+ cpu: Use CPU accelerator.
201+ gpu: Use GPU accelerator.
202+ npu: Use NPU accelerator.
188203 signature_index: Index of model signature to run.
189204 iterations: Number of times to execute the model for benchmarking.
190205 print_tensors: Whether to print output tensor elements.
191206 sample_size: Number of sample elements to print from tensors.
192207 """
208+ # Resolve the order of accelerators
209+ accelerator_list = []
210+ if accelerator :
211+ accelerator_list = [
212+ a .strip ().lower () for a in accelerator .split ("," ) if a .strip ()
213+ ]
214+ else :
215+ if npu :
216+ accelerator_list .append ("npu" )
217+ if gpu :
218+ accelerator_list .append ("gpu" )
219+ if cpu :
220+ accelerator_list .append ("cpu" )
221+
222+ if not accelerator_list :
223+ accelerator_list = ["cpu" ]
224+
225+ accelerator = "," .join (accelerator_list )
226+
193227 # Quiet if default is true
194228 if constants .DEFAULT_QUIET :
195229
0 commit comments