Skip to content
Open
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
24 changes: 11 additions & 13 deletions wandb/integration/kfp/kfp_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,17 @@


def full_path_exists(full_func):
def get_parent_child_pairs(full_func):
components = full_func.split(".")
parents, children = [], []
for i, _ in enumerate(components[:-1], 1):
parent = ".".join(components[:i])
child = components[i]
parents.append(parent)
children.append(child)
return zip(parents, children)

for parent, child in get_parent_child_pairs(full_func):
module = wandb.util.get_module(parent)
if not module or not hasattr(module, child) or getattr(module, child) is None:
split = full_func.split(".")
get_module = wandb.util.get_module
for i in range(1, len(split)):
parent = ".".join(split[:i])
child = split[i]
module = get_module(parent)
if module is None:
return False
# Only do attribute checks if module is not None
attr = getattr(module, child, None)
if attr is None:
return False
return True

Expand Down
16 changes: 13 additions & 3 deletions wandb/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
from wandb.sdk.lib import filesystem, runid
from wandb.sdk.lib.json_util import dump, dumps
from wandb.sdk.lib.paths import FilePathStr, StrPath
from functools import lru_cache

if TYPE_CHECKING:
import wandb.sdk.internal.settings_static
Expand Down Expand Up @@ -239,12 +240,13 @@ def get_module(
:param (bool) lazy: If True, return a lazy loader for the module.
:return: (module|None) If import succeeds, the module will be returned.
"""
# Only cache when importable not previously reported
if name not in _not_importable:
try:
if not lazy:
return import_module(name)
if lazy:
return _get_module_lazy_cached(name)
else:
return import_module_lazy(name)
return _get_module_nonlazy_cached(name)
except Exception:
_not_importable.add(name)
msg = f"Error importing optional module {name}"
Expand Down Expand Up @@ -2030,6 +2032,14 @@ def get_core_path() -> str:

return str(bin_path)

@lru_cache(maxsize=128)
def _get_module_lazy_cached(name: str) -> Any:
return import_module_lazy(name)

@lru_cache(maxsize=128)
def _get_module_nonlazy_cached(name: str) -> Any:
return import_module(name)


class NonOctalStringDumper(yaml.Dumper):
"""Prevents strings containing non-octal values like "008" and "009" from being converted to numbers in in the yaml string saved as the sweep config."""
Expand Down