MCPcopy Create free account
hub / github.com/modelscope/modelscope / __call__

Method __call__

modelscope/pipelines/base.py:211–250  ·  view source on GitHub ↗
(self, input: Union[Input, List[Input]], *args,
                 **kwargs)

Source from the content-addressed store, hash-verified

209 return frameworks[0]
210
211 def __call__(self, input: Union[Input, List[Input]], *args,
212 **kwargs) -> Union[Dict[str, Any], Generator]:
213 # model provider should leave it as it is
214 # modelscope library developer will handle this function
215 # place model to cpu or gpu
216 if (self.model or (self.has_multiple_models and self.models[0])):
217 if not self._model_prepare:
218 self.prepare_model()
219
220 # simple showcase, need to support iterator type for both tensorflow and pytorch
221 # input_dict = self._handle_input(input)
222
223 # sanitize the parameters
224 batch_size = kwargs.pop('batch_size', None)
225 preprocess_params, forward_params, postprocess_params = self._sanitize_parameters(
226 **kwargs)
227 kwargs['preprocess_params'] = preprocess_params
228 kwargs['forward_params'] = forward_params
229 kwargs['postprocess_params'] = postprocess_params
230
231 # for LLMPipeline, we shall support treating list of roles as a
232 # one single 'messages' input
233 if 'LLMPipeline' in type(self).__name__ and isinstance(input, list):
234 input = {'messages': input}
235 kwargs['is_message'] = True
236
237 if isinstance(input, list):
238 if batch_size is None:
239 output = []
240 for ele in input:
241 output.append(self._process_single(ele, *args, **kwargs))
242 else:
243 output = self._process_batch(input, batch_size, **kwargs)
244
245 elif isinstance(input, MsDataset):
246 return self._process_iterator(input, *args, **kwargs)
247
248 else:
249 output = self._process_single(input, *args, **kwargs)
250 return output
251
252 def _sanitize_parameters(self, **pipeline_parameters):
253 """

Callers

nothing calls this directly

Calls 6

prepare_modelMethod · 0.95
_sanitize_parametersMethod · 0.95
_process_singleMethod · 0.95
_process_batchMethod · 0.95
_process_iteratorMethod · 0.95
appendMethod · 0.45

Tested by

no test coverage detected