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

Config driven detectors - part 2 #462

Merged
merged 5 commits into from
Mar 18, 2022
Merged

Config driven detectors - part 2 #462

merged 5 commits into from
Mar 18, 2022

Conversation

ascillitoe
Copy link
Contributor

@ascillitoe ascillitoe commented Mar 16, 2022

This is the second of a series of PR's for the config-driven detector functionality. The original PR (#389) has been split into a number of smaller PR's to aid the review process.

Summary of PR

This PR introduces validation of the detector config files using pydantic. Pydantic models are defined for each detector in alibi_detect.utils.schemas. These are then used in alibi_detect.utils.loading.validate_config; a public function to validate a detector's config dictionary.

Use cases

The validate_config function will be used in a number of ways. Consider the load_detector workflow` (functionality to be introduced in part III):

image

validate_config will be used:

  • On the unresolved config (where artefacts are still strings), e.g. validate_config(cfg).
  • After resolve_config has been called (so artefacts are now runtime objects such as ndarray's) e.g. validate_config(cfg, resolved=True).
  • On raw config dictionaries (when an advanced user has parsed a config.toml themselves with read_config, and perhaps has manipulated the config dict). For this use case, the validate_config has been made public.

Validate config return

A small (but important!) detail -> The validate_config returns a dict, which is the output of the pydantic model's .dict() method. This is the same config dict that was passed in, but with missing fields populated by their default values. This is a somewhat philosophical design choice (I think), in that it means we internally we always deal with fully populated config dicts. We can set additional metadata etc in schemas.py at a later date, and can set defaults for artefact dictionaries etc (see below). A downside is that we will have to ensure the kwarg defaults set in schemas.py are kept in sync with the detector kwargs themself (this could also be a positive if we wanted divergence in some cases).

Pydantic models for artefacts

Artefacts are specified in a config with dictionaries, which may then have further artefact dictionaries within them (see preprocess_fn, modeletc in theconfig.tomlexample in schematic above). These artefact dictionaries are also validated e.g. seePreprocessConfigandPreprocessConfigResolvedinschemas.py`.

Example

Example notebook:
https://gist.github.com/ascillitoe/8ea123776151368a7a6a91688a1809cb

@ascillitoe ascillitoe marked this pull request as ready for review March 16, 2022 00:22
This was referenced Mar 16, 2022
setup.py Outdated Show resolved Hide resolved
Copy link
Contributor

@jklaise jklaise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, just wanted some clarification on the conventions for the pydantic models, specifically wrt to Optional values and None defaults.

I also saw a few TODOs wrt to conditional checking of required parameters given some other parameters. Is this fairly easy to add (I'm assuming pydantic validators)?

@ascillitoe
Copy link
Contributor Author

I also saw a few TODOs wrt to conditional checking of required parameters given some other parameters. Is this fairly easy to add (I'm assuming pydantic validators)?

I believe this is possible. But tbh I haven't looked into it too deeply as wanted to get the basic functionality in first.

@ascillitoe
Copy link
Contributor Author

ascillitoe commented Mar 16, 2022

@jklaise I've resolved a few of your comments, feel free to unresolve if you disagree. I've responded to the remaining larger comments, would you be able to take a look and mark as resolved (or not) please?

Copy link
Collaborator

@mauicv mauicv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

alibi_detect/utils/loading.py Outdated Show resolved Hide resolved
alibi_detect/utils/loading.py Outdated Show resolved Hide resolved
@ascillitoe ascillitoe merged commit 56935ce into SeldonIO:config_driven_detectors Mar 18, 2022
@ascillitoe ascillitoe mentioned this pull request Mar 23, 2022
5 tasks
ascillitoe added a commit that referenced this pull request May 3, 2022
Addition of pydantic validation of detector configs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants