Exemple #1
0
    def serve(port, bento=None, with_conda=False, enable_microbatch=False):
        track_cli('serve')
        bento_service_bundle_path = resolve_bundle_path(
            bento, pip_installed_bundle_path)
        bento_service = load(bento_service_bundle_path)

        if with_conda:
            run_with_conda_env(
                bento_service_bundle_path,
                'bentoml serve {bento} --port {port} {flags}'.format(
                    bento=bento_service_bundle_path,
                    port=port,
                    flags="--enable-microbatch" if enable_microbatch else "",
                ),
            )
            return

        if enable_microbatch:
            with reserve_free_port() as api_server_port:
                # start server right after port released
                #  to reduce potential race
                marshal_server = MarshalService(
                    bento_service_bundle_path,
                    outbound_host="localhost",
                    outbound_port=api_server_port,
                    outbound_workers=1,
                )
                api_server = BentoAPIServer(bento_service,
                                            port=api_server_port)
            marshal_server.async_start(port=port)
            api_server.start()
        else:
            api_server = BentoAPIServer(bento_service, port=port)
            api_server.start()
Exemple #2
0
    def serve(port, bundle_path=bundle_path, with_conda=False):
        if with_conda:
            config = load_saved_bundle_config(bundle_path)
            metadata = config['metadata']
            env_name = metadata['service_name'] + '_' + metadata[
                'service_version']
            pip_req = os.path.join(bundle_path, 'requirements.txt')

            subprocess.call(
                'command -v conda >/dev/null 2>&1 || {{ echo >&2 "--with-conda '
                'parameter requires conda but it\'s not installed."; exit 1; }} && '
                'conda env update -n {env_name} -f {env_file} && '
                'conda init bash && '
                'eval "$(conda shell.bash hook)" && '
                'conda activate {env_name} && '
                '{{ [ -f {pip_req} ] && pip install -r {pip_req} || echo "no pip '
                'dependencies."; }} &&'
                'bentoml serve {bundle_path} --port {port}'.format(
                    env_name=env_name,
                    env_file=os.path.join(bundle_path, 'environment.yml'),
                    bundle_path=bundle_path,
                    port=port,
                    pip_req=pip_req,
                ),
                shell=True,
            )
            return

        track_cli('serve')

        bento_service = load(bundle_path)
        server = BentoAPIServer(bento_service, port=port)
        server.start()
Exemple #3
0
    def open_api_spec(bento=None):
        track_cli('open-api-spec')

        bento_service_bundle_path = resolve_bundle_path(
            bento, pip_installed_bundle_path)

        bento_service = load(bento_service_bundle_path)

        _echo(json.dumps(get_docs(bento_service), indent=2))
Exemple #4
0
    def serve(port, bento=None, with_conda=False):
        track_cli('serve')
        bento_service_bundle_path = resolve_bundle_path(
            bento, pip_installed_bundle_path)

        if with_conda:
            run_with_conda_env(
                bento_service_bundle_path,
                'bentoml serve {bento} --port {port}'.format(
                    bento=bento_service_bundle_path,
                    port=port,
                ),
            )
            return

        bento_service = load(bento_service_bundle_path)
        server = BentoAPIServer(bento_service, port=port)
        server.start()
Exemple #5
0
    def open_api_spec(bundle_path=bundle_path):
        track_cli('open-api-spec')
        bento_service = load(bundle_path)

        _echo(json.dumps(get_docs(bento_service), indent=2))
# Copyright 2019 Atalaya Tech, Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from bentoml.bundler import load
from bentoml.server.bento_sagemaker_server import BentoSagemakerServer

api_name = os.environ.get('API_NAME', None)
model_service = load('/opt/program')
server = BentoSagemakerServer(model_service, api_name)
app = server.app
 def load(self):
     bento_service = load(self.bento_service_bundle_path)
     api_server = GunicornBentoAPIServer(bento_service, port=self.port)
     return api_server.app
Exemple #8
0
def load():
    return bundler.load(__module_path)