We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Deployment on remote Yatai server fails due to injection issue
**Describe the bug**

Attempting to deploy to SageMaker or Lambda fails with this error:

```
Error: sagemaker deploy failed: INTERNAL:<dependency_injector.wiring.Provide object at 0x11f748be0> has type Provide, but expected one of: bytes, unicode
```

**To Reproduce**

**This is based on the latest version of the code as of this writing**

- Start remote Yatai server
- Configure BentoML to use the remote Yatai server (e.g. by modifying `default_bentoml.yml`
- Start a deployment to SageMaker or Lambda (without specifying a namespace through the `--namespace` option
- The error message above is shown

**Expected behavior**
Deployment should proceed normally, and the error message should not be displayed.

**Environment:**
- BentoML version 0.12.1+24.g4019bac.dirty


**Additional context**

After some initial debugging, the error appears to originate from this line: https://github.com/bentoml/BentoML/blob/4019bac4af320bad73bf960f6bd2d617f3fd4a52/bentoml/yatai/yatai_service_impl.py#L106

`self.default_namespace` is not wired / injected properly, and will instead be a `Provide` object. This causes issues downstream as a string is expected. A workaround is to specify the environment when deploying via the CLI (`--namespace`).

My hunch is that `YataiServiceImpl` does not get properly wired/injected due to it being wrapped in the `get_yatai_service_impl` method here:https://github.com/bentoml/BentoML/blob/4019bac4af320bad73bf960f6bd2d617f3fd4a52/bentoml/yatai/yatai_service_impl.py#L74 

I have little experience with dependency injection so couldn't figure out _why_ it wouldn't get wired properly.




--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `bentoml/configuration/__init__.py`
Content:
```
1 # Copyright 2019 Atalaya Tech, Inc.
2 
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 
7 # http://www.apache.org/licenses/LICENSE-2.0
8 
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 import os
16 import logging
17 from functools import lru_cache
18 
19 from bentoml import __version__, _version as version_mod
20 
21 
22 # Note this file is loaded prior to logging being configured, thus logger is only
23 # used within functions in this file
24 logger = logging.getLogger(__name__)
25 
26 
27 DEBUG_ENV_VAR = "BENTOML_DEBUG"
28 
29 
30 def expand_env_var(env_var):
31     """Expands potentially nested env var by repeatedly applying `expandvars` and
32     `expanduser` until interpolation stops having any effect.
33     """
34     if not env_var:
35         return env_var
36     while True:
37         interpolated = os.path.expanduser(os.path.expandvars(str(env_var)))
38         if interpolated == env_var:
39             return interpolated
40         else:
41             env_var = interpolated
42 
43 
44 # This is used as default for config('core', 'bentoml_deploy_version') - which is used
45 # for getting the BentoML PyPI version string or the URL to a BentoML sdist, indicating
46 # the BentoML module to be used when loading and using a saved BentoService bundle.
47 # This is useful when using customized BentoML fork/branch or when working with
48 # development branches of BentoML
49 BENTOML_VERSION = __version__
50 # e.g. from '0.4.2+5.g6cac97f.dirty' to '0.4.2'
51 LAST_PYPI_RELEASE_VERSION = __version__.split('+')[0]
52 
53 
54 def _is_pip_installed_bentoml():
55     is_installed_package = hasattr(version_mod, 'version_json')
56     is_tagged = not __version__.startswith('0+untagged')
57     is_clean = not version_mod.get_versions()['dirty']
58     return is_installed_package and is_tagged and is_clean
59 
60 
61 def get_local_config_file():
62     if "BENTOML_CONFIG" in os.environ:
63         # User local config file for customizing bentoml
64         return expand_env_var(os.environ.get("BENTOML_CONFIG"))
65     return None
66 
67 
68 @lru_cache(maxsize=1)
69 def get_bentoml_deploy_version(bentoml_deploy_version: str):
70     """
71     BentoML version to use for generated docker image or serverless function bundle to
72     be deployed, this can be changed to an url to your fork of BentoML on github, or an
73     url to your custom BentoML build, for example:
74 
75     bentoml_deploy_version = git+https://github.com/{username}/bentoml.git@{branch}
76     """
77 
78     if bentoml_deploy_version != LAST_PYPI_RELEASE_VERSION:
79         logger.info(f"Setting BentoML deploy version to '{bentoml_deploy_version}'")
80 
81     if LAST_PYPI_RELEASE_VERSION != BENTOML_VERSION:
82         if _is_pip_installed_bentoml():
83             logger.warning(
84                 "Using BentoML not from official PyPI release. In order to find the "
85                 "same version of BentoML when deploying your BentoService, you must "
86                 "set the 'core/bentoml_deploy_version' config to a http/git location "
87                 "of your BentoML fork, e.g.: 'bentoml_deploy_version = "
88                 "git+https://github.com/{username}/bentoml.git@{branch}'"
89             )
90         else:
91             logger.warning(
92                 "Using BentoML installed in `editable` model, the local BentoML "
93                 "repository including all code changes will be packaged together with "
94                 "saved bundle created, under the './bundled_pip_dependencies' "
95                 "directory of the saved bundle."
96             )
97     return bentoml_deploy_version
98 
99 
100 def set_debug_mode(enabled: bool):
101     os.environ[DEBUG_ENV_VAR] = str(enabled)
102 
103     # reconfigure logging
104     from bentoml.utils.log import configure_logging
105 
106     configure_logging()
107 
108     logger.debug(
109         f"Setting debug mode: {'ON' if enabled else 'OFF'} for current session"
110     )
111 
112 
113 def get_debug_mode():
114     if DEBUG_ENV_VAR in os.environ:
115         return os.environ[DEBUG_ENV_VAR].lower() == "true"
116     return False
117 
118 
119 def inject_dependencies():
120     """Inject dependencies and configuration to BentoML packages"""
121 
122     from timeit import default_timer as timer
123 
124     start = timer()
125 
126     logger.debug("Start dependency injection")
127 
128     from bentoml.configuration.containers import BentoMLContainer, BentoMLConfiguration
129 
130     config_file = get_local_config_file()
131     if config_file and config_file.endswith(".yml"):
132         configuration = BentoMLConfiguration(override_config_file=config_file)
133     else:
134         configuration = BentoMLConfiguration()
135 
136     container = BentoMLContainer()
137     container.config.from_dict(configuration.as_dict())
138 
139     from bentoml import (
140         marshal,
141         server,
142         tracing,
143         cli,
144         adapters,
145         saved_bundle,
146         service,
147     )
148     from bentoml.yatai import yatai_service
149     from bentoml.yatai.repository import s3_repository, gcs_repository
150 
151     container.wire(
152         modules=[yatai_service, s3_repository, gcs_repository],
153         packages=[marshal, server, tracing, cli, adapters, saved_bundle, service],
154     )
155 
156     end = timer()
157 
158     logger.debug("Dependency injection completed in %.3f seconds", end - start)
159
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/bentoml/configuration/__init__.py b/bentoml/configuration/__init__.py
--- a/bentoml/configuration/__init__.py
+++ b/bentoml/configuration/__init__.py
@@ -146,10 +146,11 @@
         service,
     )
     from bentoml.yatai import yatai_service
+    from bentoml.yatai import yatai_service_impl
     from bentoml.yatai.repository import s3_repository, gcs_repository
 
     container.wire(
-        modules=[yatai_service, s3_repository, gcs_repository],
+        modules=[yatai_service, s3_repository, gcs_repository, yatai_service_impl],
         packages=[marshal, server, tracing, cli, adapters, saved_bundle, service],
     )

{"golden_diff": "diff --git a/bentoml/configuration/__init__.py b/bentoml/configuration/__init__.py\n--- a/bentoml/configuration/__init__.py\n+++ b/bentoml/configuration/__init__.py\n@@ -146,10 +146,11 @@\n         service,\n     )\n     from bentoml.yatai import yatai_service\n+    from bentoml.yatai import yatai_service_impl\n     from bentoml.yatai.repository import s3_repository, gcs_repository\n \n     container.wire(\n-        modules=[yatai_service, s3_repository, gcs_repository],\n+        modules=[yatai_service, s3_repository, gcs_repository, yatai_service_impl],\n         packages=[marshal, server, tracing, cli, adapters, saved_bundle, service],\n     )\n", "issue": "Deployment on remote Yatai server fails due to injection issue\n**Describe the bug**\r\n\r\nAttempting to deploy to SageMaker or Lambda fails with this error:\r\n\r\n```\r\nError: sagemaker deploy failed: INTERNAL:<dependency_injector.wiring.Provide object at 0x11f748be0> has type Provide, but expected one of: bytes, unicode\r\n```\r\n\r\n**To Reproduce**\r\n\r\n**This is based on the latest version of the code as of this writing**\r\n\r\n- Start remote Yatai server\r\n- Configure BentoML to use the remote Yatai server (e.g. by modifying `default_bentoml.yml`\r\n- Start a deployment to SageMaker or Lambda (without specifying a namespace through the `--namespace` option\r\n- The error message above is shown\r\n\r\n**Expected behavior**\r\nDeployment should proceed normally, and the error message should not be displayed.\r\n\r\n**Environment:**\r\n- BentoML version 0.12.1+24.g4019bac.dirty\r\n\r\n\r\n**Additional context**\r\n\r\nAfter some initial debugging, the error appears to originate from this line: https://github.com/bentoml/BentoML/blob/4019bac4af320bad73bf960f6bd2d617f3fd4a52/bentoml/yatai/yatai_service_impl.py#L106\r\n\r\n`self.default_namespace` is not wired / injected properly, and will instead be a `Provide` object. This causes issues downstream as a string is expected. A workaround is to specify the environment when deploying via the CLI (`--namespace`).\r\n\r\nMy hunch is that `YataiServiceImpl` does not get properly wired/injected due to it being wrapped in the `get_yatai_service_impl` method here:https://github.com/bentoml/BentoML/blob/4019bac4af320bad73bf960f6bd2d617f3fd4a52/bentoml/yatai/yatai_service_impl.py#L74 \r\n\r\nI have little experience with dependency injection so couldn't figure out _why_ it wouldn't get wired properly.\r\n\r\n\r\n\n", "before_files": [{"content": "# Copyright 2019 Atalaya Tech, Inc.\n\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n\n# http://www.apache.org/licenses/LICENSE-2.0\n\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport os\nimport logging\nfrom functools import lru_cache\n\nfrom bentoml import __version__, _version as version_mod\n\n\n# Note this file is loaded prior to logging being configured, thus logger is only\n# used within functions in this file\nlogger = logging.getLogger(__name__)\n\n\nDEBUG_ENV_VAR = \"BENTOML_DEBUG\"\n\n\ndef expand_env_var(env_var):\n    \"\"\"Expands potentially nested env var by repeatedly applying `expandvars` and\n    `expanduser` until interpolation stops having any effect.\n    \"\"\"\n    if not env_var:\n        return env_var\n    while True:\n        interpolated = os.path.expanduser(os.path.expandvars(str(env_var)))\n        if interpolated == env_var:\n            return interpolated\n        else:\n            env_var = interpolated\n\n\n# This is used as default for config('core', 'bentoml_deploy_version') - which is used\n# for getting the BentoML PyPI version string or the URL to a BentoML sdist, indicating\n# the BentoML module to be used when loading and using a saved BentoService bundle.\n# This is useful when using customized BentoML fork/branch or when working with\n# development branches of BentoML\nBENTOML_VERSION = __version__\n# e.g. from '0.4.2+5.g6cac97f.dirty' to '0.4.2'\nLAST_PYPI_RELEASE_VERSION = __version__.split('+')[0]\n\n\ndef _is_pip_installed_bentoml():\n    is_installed_package = hasattr(version_mod, 'version_json')\n    is_tagged = not __version__.startswith('0+untagged')\n    is_clean = not version_mod.get_versions()['dirty']\n    return is_installed_package and is_tagged and is_clean\n\n\ndef get_local_config_file():\n    if \"BENTOML_CONFIG\" in os.environ:\n        # User local config file for customizing bentoml\n        return expand_env_var(os.environ.get(\"BENTOML_CONFIG\"))\n    return None\n\n\n@lru_cache(maxsize=1)\ndef get_bentoml_deploy_version(bentoml_deploy_version: str):\n    \"\"\"\n    BentoML version to use for generated docker image or serverless function bundle to\n    be deployed, this can be changed to an url to your fork of BentoML on github, or an\n    url to your custom BentoML build, for example:\n\n    bentoml_deploy_version = git+https://github.com/{username}/bentoml.git@{branch}\n    \"\"\"\n\n    if bentoml_deploy_version != LAST_PYPI_RELEASE_VERSION:\n        logger.info(f\"Setting BentoML deploy version to '{bentoml_deploy_version}'\")\n\n    if LAST_PYPI_RELEASE_VERSION != BENTOML_VERSION:\n        if _is_pip_installed_bentoml():\n            logger.warning(\n                \"Using BentoML not from official PyPI release. In order to find the \"\n                \"same version of BentoML when deploying your BentoService, you must \"\n                \"set the 'core/bentoml_deploy_version' config to a http/git location \"\n                \"of your BentoML fork, e.g.: 'bentoml_deploy_version = \"\n                \"git+https://github.com/{username}/bentoml.git@{branch}'\"\n            )\n        else:\n            logger.warning(\n                \"Using BentoML installed in `editable` model, the local BentoML \"\n                \"repository including all code changes will be packaged together with \"\n                \"saved bundle created, under the './bundled_pip_dependencies' \"\n                \"directory of the saved bundle.\"\n            )\n    return bentoml_deploy_version\n\n\ndef set_debug_mode(enabled: bool):\n    os.environ[DEBUG_ENV_VAR] = str(enabled)\n\n    # reconfigure logging\n    from bentoml.utils.log import configure_logging\n\n    configure_logging()\n\n    logger.debug(\n        f\"Setting debug mode: {'ON' if enabled else 'OFF'} for current session\"\n    )\n\n\ndef get_debug_mode():\n    if DEBUG_ENV_VAR in os.environ:\n        return os.environ[DEBUG_ENV_VAR].lower() == \"true\"\n    return False\n\n\ndef inject_dependencies():\n    \"\"\"Inject dependencies and configuration to BentoML packages\"\"\"\n\n    from timeit import default_timer as timer\n\n    start = timer()\n\n    logger.debug(\"Start dependency injection\")\n\n    from bentoml.configuration.containers import BentoMLContainer, BentoMLConfiguration\n\n    config_file = get_local_config_file()\n    if config_file and config_file.endswith(\".yml\"):\n        configuration = BentoMLConfiguration(override_config_file=config_file)\n    else:\n        configuration = BentoMLConfiguration()\n\n    container = BentoMLContainer()\n    container.config.from_dict(configuration.as_dict())\n\n    from bentoml import (\n        marshal,\n        server,\n        tracing,\n        cli,\n        adapters,\n        saved_bundle,\n        service,\n    )\n    from bentoml.yatai import yatai_service\n    from bentoml.yatai.repository import s3_repository, gcs_repository\n\n    container.wire(\n        modules=[yatai_service, s3_repository, gcs_repository],\n        packages=[marshal, server, tracing, cli, adapters, saved_bundle, service],\n    )\n\n    end = timer()\n\n    logger.debug(\"Dependency injection completed in %.3f seconds\", end - start)\n", "path": "bentoml/configuration/__init__.py"}], "after_files": [{"content": "# Copyright 2019 Atalaya Tech, Inc.\n\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n\n# http://www.apache.org/licenses/LICENSE-2.0\n\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport os\nimport logging\nfrom functools import lru_cache\n\nfrom bentoml import __version__, _version as version_mod\n\n\n# Note this file is loaded prior to logging being configured, thus logger is only\n# used within functions in this file\nlogger = logging.getLogger(__name__)\n\n\nDEBUG_ENV_VAR = \"BENTOML_DEBUG\"\n\n\ndef expand_env_var(env_var):\n    \"\"\"Expands potentially nested env var by repeatedly applying `expandvars` and\n    `expanduser` until interpolation stops having any effect.\n    \"\"\"\n    if not env_var:\n        return env_var\n    while True:\n        interpolated = os.path.expanduser(os.path.expandvars(str(env_var)))\n        if interpolated == env_var:\n            return interpolated\n        else:\n            env_var = interpolated\n\n\n# This is used as default for config('core', 'bentoml_deploy_version') - which is used\n# for getting the BentoML PyPI version string or the URL to a BentoML sdist, indicating\n# the BentoML module to be used when loading and using a saved BentoService bundle.\n# This is useful when using customized BentoML fork/branch or when working with\n# development branches of BentoML\nBENTOML_VERSION = __version__\n# e.g. from '0.4.2+5.g6cac97f.dirty' to '0.4.2'\nLAST_PYPI_RELEASE_VERSION = __version__.split('+')[0]\n\n\ndef _is_pip_installed_bentoml():\n    is_installed_package = hasattr(version_mod, 'version_json')\n    is_tagged = not __version__.startswith('0+untagged')\n    is_clean = not version_mod.get_versions()['dirty']\n    return is_installed_package and is_tagged and is_clean\n\n\ndef get_local_config_file():\n    if \"BENTOML_CONFIG\" in os.environ:\n        # User local config file for customizing bentoml\n        return expand_env_var(os.environ.get(\"BENTOML_CONFIG\"))\n    return None\n\n\n@lru_cache(maxsize=1)\ndef get_bentoml_deploy_version(bentoml_deploy_version: str):\n    \"\"\"\n    BentoML version to use for generated docker image or serverless function bundle to\n    be deployed, this can be changed to an url to your fork of BentoML on github, or an\n    url to your custom BentoML build, for example:\n\n    bentoml_deploy_version = git+https://github.com/{username}/bentoml.git@{branch}\n    \"\"\"\n\n    if bentoml_deploy_version != LAST_PYPI_RELEASE_VERSION:\n        logger.info(f\"Setting BentoML deploy version to '{bentoml_deploy_version}'\")\n\n    if LAST_PYPI_RELEASE_VERSION != BENTOML_VERSION:\n        if _is_pip_installed_bentoml():\n            logger.warning(\n                \"Using BentoML not from official PyPI release. In order to find the \"\n                \"same version of BentoML when deploying your BentoService, you must \"\n                \"set the 'core/bentoml_deploy_version' config to a http/git location \"\n                \"of your BentoML fork, e.g.: 'bentoml_deploy_version = \"\n                \"git+https://github.com/{username}/bentoml.git@{branch}'\"\n            )\n        else:\n            logger.warning(\n                \"Using BentoML installed in `editable` model, the local BentoML \"\n                \"repository including all code changes will be packaged together with \"\n                \"saved bundle created, under the './bundled_pip_dependencies' \"\n                \"directory of the saved bundle.\"\n            )\n    return bentoml_deploy_version\n\n\ndef set_debug_mode(enabled: bool):\n    os.environ[DEBUG_ENV_VAR] = str(enabled)\n\n    # reconfigure logging\n    from bentoml.utils.log import configure_logging\n\n    configure_logging()\n\n    logger.debug(\n        f\"Setting debug mode: {'ON' if enabled else 'OFF'} for current session\"\n    )\n\n\ndef get_debug_mode():\n    if DEBUG_ENV_VAR in os.environ:\n        return os.environ[DEBUG_ENV_VAR].lower() == \"true\"\n    return False\n\n\ndef inject_dependencies():\n    \"\"\"Inject dependencies and configuration to BentoML packages\"\"\"\n\n    from timeit import default_timer as timer\n\n    start = timer()\n\n    logger.debug(\"Start dependency injection\")\n\n    from bentoml.configuration.containers import BentoMLContainer, BentoMLConfiguration\n\n    config_file = get_local_config_file()\n    if config_file and config_file.endswith(\".yml\"):\n        configuration = BentoMLConfiguration(override_config_file=config_file)\n    else:\n        configuration = BentoMLConfiguration()\n\n    container = BentoMLContainer()\n    container.config.from_dict(configuration.as_dict())\n\n    from bentoml import (\n        marshal,\n        server,\n        tracing,\n        cli,\n        adapters,\n        saved_bundle,\n        service,\n    )\n    from bentoml.yatai import yatai_service\n    from bentoml.yatai import yatai_service_impl\n    from bentoml.yatai.repository import s3_repository, gcs_repository\n\n    container.wire(\n        modules=[yatai_service, s3_repository, gcs_repository, yatai_service_impl],\n        packages=[marshal, server, tracing, cli, adapters, saved_bundle, service],\n    )\n\n    end = timer()\n\n    logger.debug(\"Dependency injection completed in %.3f seconds\", end - start)\n", "path": "bentoml/configuration/__init__.py"}]}