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

Method encode

modelscope/preprocessors/templates/base.py:409–430  ·  view source on GitHub ↗

The entrance method of Template! Args: example: The input example streaming: If is streaming mode is_training: Use template in training **kwargs: model: The model instance, use only in `is_training=False` Returns:

(self, example: Dict[str, Any], streaming: bool = False, is_training: bool = False, **kwargs)

Source from the content-addressed store, hash-verified

407 return example
408
409 def encode(self, example: Dict[str, Any], streaming: bool = False, is_training: bool = False, **kwargs) -> Tuple[Dict[str, Any], Dict[str, Any]]:
410 """The entrance method of Template!
411
412 Args:
413 example: The input example
414 streaming: If is streaming mode
415 is_training: Use template in training
416 **kwargs:
417 model: The model instance, use only in `is_training=False`
418 Returns:
419 if not streaming mode, returns tuple of (example, tokenizer_kwargs), else return example only
420 """
421 example = self.preprocess(example)
422 res = self._encode(example, **kwargs)
423 inputs = res[0]
424 if not is_training and '_data' in inputs:
425 model = kwargs.get('model')
426 assert model is not None
427 data = inputs.pop('_data')
428 data = to_device(data, model.device)
429 inputs.update(self.post_encode(model, data))
430 return res if not streaming else inputs
431
432 def _encode(self, example: Dict[str, Any], **kwargs) -> Tuple[Dict[str, Any], Dict[str, Any]]:
433 """return: inputs, tokenizer_kwargs"""

Callers 15

postprocessMethod · 0.45
forwardMethod · 0.45
postprocessMethod · 0.45
postprocessMethod · 0.45
preprocessMethod · 0.45
postprocessMethod · 0.45
image2latentMethod · 0.45
format_messagesMethod · 0.45
_encodeMethod · 0.45
baichuan_format_messagesFunction · 0.45

Calls 6

preprocessMethod · 0.95
_encodeMethod · 0.95
post_encodeMethod · 0.95
to_deviceFunction · 0.70
getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected