@@ -441,18 +441,20 @@ def get_model(pretrained_model_name_or_path: str) -> str:
441441 return pretrained_model_name_or_path
442442
443443
444- def get_tokenizer (pretrained_model_name_or_path : str , ) -> PreTrainedTokenizer | PreTrainedTokenizerFast :
444+ def get_tokenizer (pretrained_model_name_or_path : str ,
445+ trust_remote_code : bool = False ) -> PreTrainedTokenizer | PreTrainedTokenizerFast :
445446 if pretrained_model_name_or_path .endswith ('.json' ) or pretrained_model_name_or_path .endswith ('.model' ):
446447 from sglang .srt .hf_transformers_utils import get_tokenizer
447448
448449 return get_tokenizer (pretrained_model_name_or_path )
449450
450451 if pretrained_model_name_or_path is not None and not os .path .exists (pretrained_model_name_or_path ):
451452 pretrained_model_name_or_path = get_model (pretrained_model_name_or_path )
452- return AutoTokenizer .from_pretrained (pretrained_model_name_or_path , trust_remote_code = True )
453+ return AutoTokenizer .from_pretrained (pretrained_model_name_or_path , trust_remote_code = trust_remote_code )
453454
454455
455- def get_processor (pretrained_model_name_or_path : str , ) -> PreTrainedTokenizer | PreTrainedTokenizerFast :
456+ def get_processor (pretrained_model_name_or_path : str ,
457+ trust_remote_code : bool = False ) -> PreTrainedTokenizer | PreTrainedTokenizerFast :
456458 assert (pretrained_model_name_or_path is not None and pretrained_model_name_or_path != '' )
457459 if pretrained_model_name_or_path .endswith ('.json' ) or pretrained_model_name_or_path .endswith ('.model' ):
458460 from sglang .srt .utils .hf_transformers_utils import get_processor
@@ -461,7 +463,7 @@ def get_processor(pretrained_model_name_or_path: str, ) -> PreTrainedTokenizer |
461463
462464 if pretrained_model_name_or_path is not None and not os .path .exists (pretrained_model_name_or_path ):
463465 pretrained_model_name_or_path = get_model (pretrained_model_name_or_path )
464- return AutoProcessor .from_pretrained (pretrained_model_name_or_path , trust_remote_code = True )
466+ return AutoProcessor .from_pretrained (pretrained_model_name_or_path , trust_remote_code = trust_remote_code )
465467
466468
467469ASYNC_REQUEST_FUNCS = {
@@ -1172,9 +1174,9 @@ def parse_request_rate_range(request_rate_range):
11721174 return list (map (int , request_rate_range .split (',' )))
11731175
11741176
1175- def check_chat_template (model_path ):
1177+ def check_chat_template (model_path , trust_remote_code : bool = False ):
11761178 try :
1177- tokenizer = AutoTokenizer .from_pretrained (model_path , trust_remote_code = True )
1179+ tokenizer = AutoTokenizer .from_pretrained (model_path , trust_remote_code = args . trust_remote_code )
11781180 return 'chat_template' in tokenizer .init_kwargs
11791181 except Exception as e :
11801182 print (f'Fail to load tokenizer config with error={ e } ' )
@@ -1256,15 +1258,15 @@ def run_benchmark(args_: argparse.Namespace):
12561258 'using `--model`.' )
12571259 sys .exit (1 )
12581260
1259- if not check_chat_template (model_path ):
1261+ if not check_chat_template (model_path , args . trust_remote_code ):
12601262 print ('\n WARNING It is recommended to use the `Chat` or `Instruct` '
12611263 'model for benchmarking.\n '
12621264 'Because when the tokenizer counts the output tokens, if '
12631265 'there is gibberish, it might count incorrectly.\n ' )
12641266
12651267 print (f'{ args } \n ' )
12661268
1267- tokenizer = get_tokenizer (tokenizer_id )
1269+ tokenizer = get_tokenizer (tokenizer_id , args . trust_remote_code )
12681270
12691271 if args .dataset_name == 'sharegpt' :
12701272 assert args .random_input_len is None and args .random_output_len is None
@@ -1286,7 +1288,7 @@ def run_benchmark(args_: argparse.Namespace):
12861288 dataset_path = args .dataset_path ,
12871289 )
12881290 elif args .dataset_name == 'image' :
1289- processor = get_processor (model_path )
1291+ processor = get_processor (model_path , args . trust_remote_code )
12901292 input_requests = sample_image_requests (
12911293 num_requests = args .num_prompts ,
12921294 image_count = args .image_count ,
@@ -1502,5 +1504,11 @@ def set_ulimit(target_soft_limit=65535):
15021504 default = None ,
15031505 help = 'Disable a warmup request before the benchmark. ' ,
15041506 )
1507+ parser .add_argument (
1508+ '--trust-remote-code' ,
1509+ action = 'store_true' ,
1510+ default = False ,
1511+ help = 'Trust remote code.' ,
1512+ )
15051513 args = parser .parse_args ()
15061514 run_benchmark (args )
0 commit comments