Implementation:Kserve Kserve Alibi Parser
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Explainability, CLI Configuration |
| Last Updated | 2026-02-13 00:00 GMT |
Overview
Concrete tool for providing comprehensive command-line argument parsing for the Alibi explainer server with algorithm-specific configuration provided by the KServe sample code.
Description
This module defines the argument parsing infrastructure for the Alibi explainer server. It contains:
- GroupedAction -- A custom
argparse.Actionsubclass that groups arguments into namespaces using dot-separated destination names (e.g.,explainer.threshold), enabling hierarchical argument organization. - str2bool() -- A utility function that converts string values ("yes", "true", "1", etc.) to boolean values, used for boolean command-line arguments.
- addCommonParserArgs() -- A function that adds common anchor explainer parameters (threshold, delta, tau, batch_size, coverage_samples, beam_size, stop_on_first, max_anchor_size, max_samples_start, n_covered_ex, binary_cache_size, cache_margin, verbose, verbose_every) to any subparser.
- parse_args() -- The main parsing function that creates subparsers for each
ExplainerMethod(AnchorTabular, AnchorText, AnchorImages) with method-specific arguments (e.g., use_unk, sample_proba, temperature for text; p_sample for images), plus common arguments for model name, predictor host, and storage URI.
Usage
Use parse_args() as the entry point for configuring and launching the Alibi explainer container, passing in sys.argv to obtain the parsed arguments and extra explainer-specific configuration.
Code Reference
Source Location
- Repository: Kserve_Kserve
- File: docs/samples/explanation/alibi/alibiexplainer/alibiexplainer/parser.py
- Lines: 1-216
Signature
class GroupedAction(argparse.Action):
def __call__(self, theparser, namespace, values, option_string=None):
...
def str2bool(v):
...
def addCommonParserArgs(parser):
...
def parse_args(sys_args):
...
Import
from alibiexplainer.parser import parse_args, GroupedAction, str2bool
I/O Contract
Inputs
GroupedAction.__call__()
| Name | Type | Required | Description |
|---|---|---|---|
| theparser | argparse.ArgumentParser | Yes | The argument parser instance |
| namespace | argparse.Namespace | Yes | The current namespace being populated |
| values | Any | Yes | The parsed value for the argument |
| option_string | str | No | The option string that triggered this action |
str2bool()
| Name | Type | Required | Description |
|---|---|---|---|
| v | Union[bool, str] | Yes | A value to convert to boolean (accepts "yes", "true", "t", "y", "1" and their negatives) |
parse_args()
| Name | Type | Required | Description |
|---|---|---|---|
| sys_args | list | Yes | Command-line arguments list (typically sys.argv[1:]) |
Outputs
str2bool()
| Name | Type | Description |
|---|---|---|
| result | bool | The boolean interpretation of the input string |
parse_args()
| Name | Type | Description |
|---|---|---|
| args | argparse.Namespace | Parsed arguments including model_name, predictor_host, storage_uri, and command |
| extra | dict | Dictionary of explainer-specific parameters extracted from the grouped namespace |
Usage Examples
Basic Usage
from alibiexplainer.parser import parse_args
# Parse command-line arguments for an AnchorTabular explainer
args, extra = parse_args([
"--model_name", "income-explainer",
"--predictor_host", "income-predictor.default.svc.cluster.local",
"--storage_uri", "gs://my-bucket/explainer",
"AnchorTabular",
"--threshold", "0.95",
"--batch_size", "100",
])
print(args.model_name) # "income-explainer"
print(args.command) # "AnchorTabular"
print(extra) # {"threshold": 0.95, "batch_size": 100}
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment