Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't assume env vars are set in model handler #29200

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/notebooks/beam-ml/run_custom_inference.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@
" model_name: The spaCy model name. Default is en_core_web_sm.\n",
" \"\"\"\n",
" self._model_name = model_name\n",
" self._env_vars = {}\n",
"\n",
" def load_model(self) -> Language:\n",
" \"\"\"Loads and initializes a model for processing.\"\"\"\n",
Expand Down
10 changes: 5 additions & 5 deletions sdks/python/apache_beam/ml/inference/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def __init__(
'postprocessing functions defined into a keyed model handler. All '
'pre/postprocessing functions must be defined on the outer model'
'handler.')
self._env_vars = unkeyed._env_vars
self._env_vars = getattr(unkeyed, '_env_vars', {})
self._unkeyed = unkeyed
return

Expand Down Expand Up @@ -553,7 +553,7 @@ def __init__(
'overriding the KeyedModelHandler.batch_elements_kwargs() method.',
hints,
batch_kwargs)
env_vars = mh._env_vars
env_vars = getattr(mh, '_env_vars', {})
if len(env_vars) > 0:
logging.warning(
'mh %s defines the following _env_vars which will be ignored %s. '
Expand Down Expand Up @@ -816,7 +816,7 @@ def __init__(self, unkeyed: ModelHandler[ExampleT, PredictionT, ModelT]):
'pre/postprocessing functions must be defined on the outer model'
'handler.')
self._unkeyed = unkeyed
self._env_vars = unkeyed._env_vars
self._env_vars = getattr(unkeyed, '_env_vars', {})

def load_model(self) -> ModelT:
return self._unkeyed.load_model()
Expand Down Expand Up @@ -895,7 +895,7 @@ def __init__(
preprocess_fn: the preprocessing function to use.
"""
self._base = base
self._env_vars = base._env_vars
self._env_vars = getattr(base, '_env_vars', {})
self._preprocess_fn = preprocess_fn

def load_model(self) -> ModelT:
Expand Down Expand Up @@ -951,7 +951,7 @@ def __init__(
postprocess_fn: the preprocessing function to use.
"""
self._base = base
self._env_vars = base._env_vars
self._env_vars = getattr(base, '_env_vars', {})
self._postprocess_fn = postprocess_fn

def load_model(self) -> ModelT:
Expand Down