MCPcopy
hub / github.com/PaddlePaddle/PaddleNLP / __init__

Method __init__

llm/predictor.py:348–372  ·  view source on GitHub ↗
(self, config: PredictorArgument, tokenizer: PretrainedTokenizer = None)

Source from the content-addressed store, hash-verified

346
347class StaticGraphPredictor(BasePredictor):
348 def __init__(self, config: PredictorArgument, tokenizer: PretrainedTokenizer = None):
349 super().__init__(config, tokenizer)
350
351 params_path = os.path.join(self.config.model_name_or_path, self.config.model_prefix + ".pdiparams")
352 model_path = os.path.join(self.config.model_name_or_path, self.config.model_prefix + ".pdmodel")
353 inference_config = paddle.inference.Config(model_path, params_path)
354
355 if self.config.device == "gpu":
356 # set GPU configs accordingly
357 inference_config.enable_use_gpu(100, 0)
358 elif self.config.device == "cpu":
359 # set CPU configs accordingly,
360 # such as enable_mkldnn, set_cpu_math_library_num_threads
361 inference_config.disable_gpu()
362 inference_config.disable_glog_info()
363 inference_config.enable_new_executor()
364 if in_pir_executor_mode():
365 inference_config.enable_new_ir()
366 if in_cinn_mode():
367 inference_config.enable_cinn()
368
369 with static_mode_guard():
370 self.predictor = paddle.inference.create_predictor(inference_config)
371
372 self.return_tensors = "np"
373
374 def _preprocess(self, input_text: str | list[str]):
375 inputs = super()._preprocess(input_text)

Callers

nothing calls this directly

Calls 4

static_mode_guardFunction · 0.90
joinMethod · 0.80
__init__Method · 0.45
create_predictorMethod · 0.45

Tested by

no test coverage detected