示例#1
0
 def _load_from_directory(self, path):
     if self._model_type is None:
         raise NotFound(
             "Type of transformers model not found. "
             "This should be present in a file called "
             "'_model_type.txt' in the artifacts of the bundle."
         )
     if self._tokenizer_type is None:
         raise NotFound(
             "Type of transformers tokenizer not found. "
             "This should be present in a file called 'tokenizer_type.txt' "
             "in the artifacts of the bundle."
         )
     transformers_model = getattr(
         import_module("transformers"), self._model_type
     ).from_pretrained(path)
     tokenizer = getattr(
         import_module("transformers"), self._tokenizer_type
     ).from_pretrained(path)
     return {"model": transformers_model, "tokenizer": tokenizer}
示例#2
0
文件: service.py 项目: umihui/BentoML
    def get_inference_api(self, api_name):
        """Find the inference API in this BentoService with a specific name.

        When the api_name is None, this returns the first Inference API found in the
        `self.inference_apis` list.

        :param api_name: the target Inference API's name
        :return:
        """
        if api_name:
            try:
                return next((api for api in self.inference_apis
                             if api.name == api_name))
            except StopIteration:
                raise NotFound("Can't find API '{}' in service '{}'".format(
                    api_name, self.name))
        elif len(self.inference_apis) > 0:
            return self.inference_apis[0]
        else:
            raise NotFound(
                f"Can't find any inference API in service '{self.name}'")