def upload(
        self,
        bento_service: "BentoService",
        version: str = None,
        labels: Dict = None,
    ) -> "BentoUri":
        """
        Save and upload given :class:`~bentoml.BentoService`
        to YataiService.

        Args:
            bento_service (:class:`~bentoml.BentoService`):
                a BentoService instance
            version (`str`, `optional`):
                version of ``bento_service``
            labels (`dict`, `optional`):
                :class:`~bentoml.BentoService` metadata

        Returns:
            BentoUri as gRPC stub for save location of BentoService.

        Example::

            from bentoml.yatai.client import get_yatai_client

            svc = MyBentoService()
            svc.save()

            remote_yatai_client = get_yatai_client('https://remote.yatai.service:50050')
            remote_path = remote_yatai_client.repository.upload(svc)
        """
        with TempDirectory() as tmpdir:
            save_to_dir(bento_service, tmpdir, version, silent=True)
            return self.upload_from_dir(tmpdir, labels)
Example #2
0
    def upload(self, bento_service, version=None, labels=None):
        """Save and upload given bento_service to yatai_service, which manages all your
        saved BentoService bundles and model serving deployments.

        Args:
            bento_service (bentoml.service.BentoService): a Bento Service instance
            version (str): optional,
        Return:
            URI to where the BentoService is being saved to
        """
        with TempDirectory() as tmpdir:
            save_to_dir(bento_service, tmpdir, version, silent=True)
            return self.upload_from_dir(tmpdir, labels)
Example #3
0
    def save_to_dir(self, path, version=None):
        """Save this BentoService along with all its artifacts, source code and
        dependencies to target file path, assuming path exist and empty. If target path
        is not empty, this call may override existing files in the given path.

        :param path (str): Destination of where the bento service will be saved
        :param version: optional - save with version override
        """
        return save_to_dir(self, path, version)
Example #4
0
def gen_test_bundle(tmpdir):
    # When the ExampleBentoService got saved and loaded again in the test, the two class
    # attribute below got set to the loaded BentoService class. Resetting it here so it
    # does not effect other tests
    ExampleBentoService._bento_service_bundle_path = None
    ExampleBentoService._bento_service_bundle_version = None
    test_svc = ExampleBentoService()

    pickle_model = PickleModel()
    test_svc.pack('model', pickle_model)

    sklearn_model = RandomForestRegressor(n_estimators=2)
    sklearn_model.fit(
        [[i] for _ in range(100) for i in range(10)],
        [i for _ in range(100) for i in range(10)],
    )
    test_svc.pack('sk_model', sklearn_model)

    save_to_dir(test_svc, tmpdir, silent=True)
    return tmpdir
Example #5
0
        return [input_data.shape for input_data in input_datas]

    def predict_legacy_images(self, original, compared):
        return (original == compared).all()

    def predict_json(self, input_datas):
        assert input_datas is not None
        return input_datas


if __name__ == "__main__":
    # When the ExampleBentoService got saved and loaded again in the test, the two class
    # attribute below got set to the loaded BentoService class. Resetting it here so it
    # does not effect other tests
    ExampleBentoService._bento_service_bundle_path = None
    ExampleBentoService._bento_service_bundle_version = None
    test_svc = ExampleBentoService()

    pickle_model = PickleModel()
    test_svc.pack('model', pickle_model)

    sklearn_model = RandomForestRegressor(n_estimators=2)
    sklearn_model.fit(
        [[i] for _ in range(100) for i in range(10)],
        [i for _ in range(100) for i in range(10)],
    )
    test_svc.pack('sk_model', sklearn_model)

    tmpdir = sys.argv[1]
    save_to_dir(test_svc, tmpdir, silent=True)