Skip to content

Commit

Permalink
Scrub credentials from model_hyperparameters.json and description.json (
Browse files Browse the repository at this point in the history
#3866)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Infernaught and pre-commit-ci[bot] authored Jan 10, 2024
1 parent b0d11a0 commit 56e42c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ludwig/schema/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ludwig.modules.reduction_modules import reduce_mode_registry
from ludwig.schema.metadata import COMMON_METADATA
from ludwig.schema.metadata.parameter_metadata import convert_metadata_to_json, ParameterMetadata
from ludwig.utils.misc_utils import scrub_creds
from ludwig.utils.registry import Registry
from ludwig.utils.torch_utils import activations, initializer_registry

Expand Down Expand Up @@ -180,7 +181,7 @@ def to_dict(self):
Returns: dict for this dataclass
"""
return convert_submodules(self.__dict__)
return scrub_creds(convert_submodules(self.__dict__))

@pre_load
def log_deprecation_warnings_for_any_invalid_parameters(self, data, **kwargs):
Expand Down
10 changes: 9 additions & 1 deletion ludwig/utils/misc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import weakref
from collections import OrderedDict
from collections.abc import Mapping
from typing import TYPE_CHECKING
from typing import Any, Dict, TYPE_CHECKING

import numpy
import torch
Expand Down Expand Up @@ -212,3 +212,11 @@ def get_commit_hash():
except: # noqa: E722
pass
return None


@DeveloperAPI
def scrub_creds(config_dict: Dict[str, Any]) -> Dict[str, Any]:
"""Returns a copy of a config dict with all sensitive fields scrubbed."""
if config_dict.get("backend", {}) and "credentials" in config_dict.get("backend", {}):
config_dict["backend"]["credentials"] = {}
return config_dict

0 comments on commit 56e42c0

Please sign in to comment.