Model Utilities
Examples
Examples of using the Model Utilities are listed at the bottom of this page Examples.
Model Utilities for Workbench models
cleanlab_model_local(model)
Create a CleanlabModels instance for detecting data quality issues in a Model's training data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The Model used to create the cleanlab models |
required |
Returns:
| Name | Type | Description |
|---|---|---|
CleanlabModels |
CleanlabModels
|
Label-quality analysis with helpers like label_issues(), epistemic_uncertainty(), and the native clean_learning()/datalab() objects. |
Source code in src/workbench/utils/model_utils.py
copy_model_artifacts(model, dst_name)
Stage a model copy's S3 artifacts under the destination's training dir.
Copies the frozen model.tar.gz and its sibling output.tar.gz (the training job's output channel, which carries the HPO audit trail) plus the top-level training-capture files (validation_predictions.csv, shap_*) into {models_s3_path}/{dst_name}/training/. The frozen artifact lives in the copy's own dir so it's immune to the source's delete-then-create churn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The source model being copied |
required |
dst_name
|
str
|
Name of the destination model group |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The frozen model.tar.gz S3 URL for the copy's container spec |
Source code in src/workbench/utils/model_utils.py
extracted_artifact(artifact_uri)
Download an S3 tarball and yield the temp directory it extracted into.
Yields None when the object can't be fetched — callers name a specific artifact and a
bundle need not contain it (only searched models write output.tar.gz). The directory
is removed on exit, so read what you need inside the with.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
artifact_uri
|
str
|
S3 URI of a .tar.gz artifact. |
required |
Yields:
| Type | Description |
|---|---|
Optional[str]
|
str | None: Path to the extracted directory, or None if the download failed. |
Source code in src/workbench/utils/model_utils.py
get_model_hyperparameters(workbench_model)
Get the hyperparameters used to train a Workbench model.
Reads from Workbench meta (a cheap tag read). Models predating meta storage fall back to the model artifact and are backfilled into meta on first read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workbench_model
|
Any
|
Workbench model object |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Optional[dict]
|
The hyperparameters used during training, or None if not found |
Source code in src/workbench/utils/model_utils.py
instance_architecture(instance_name)
Get the architecture for the given instance name
load_category_mappings_from_s3(model_artifact_uri)
Download and extract category mappings from a model artifact in S3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_artifact_uri
|
str
|
S3 URI of the model artifact. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Optional[dict]
|
The loaded category mappings or None if not found. |
Source code in src/workbench/utils/model_utils.py
load_hyperparameters_from_s3(model_artifact_uri)
Download and extract hyperparameters from a model artifact in S3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_artifact_uri
|
str
|
S3 URI of the model artifact (model.tar.gz). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Optional[dict]
|
The loaded hyperparameters or None if not found. |
Source code in src/workbench/utils/model_utils.py
model_instance_info()
Instance reference for the Model: hardware, us-east-1 on-demand price, and role.
Price per Hour is the rate for the instance's Usage — SageMaker charges a different
rate for the same instance hosting an endpoint versus running a training job. The
Training rows are the ladders in
workbench.core.transforms.features_to_model.INSTANCE_LADDERS.
Source code in src/workbench/utils/model_utils.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
noise_model_local(model)
Create a NoiseModel for detecting noisy/problematic samples in a Model's training data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The Model used to create the noise model |
required |
Returns:
| Name | Type | Description |
|---|---|---|
NoiseModel |
NoiseModel
|
The noise model with precomputed noise scores for all samples |
Source code in src/workbench/utils/model_utils.py
safe_extract_tarfile(tar_path, extract_path)
Extract a tarball safely, using data filter if available.
The filter parameter was backported to Python 3.8+, 3.9+, 3.10.13+, 3.11+ as a security patch, but may not be present in older patch versions.
Source code in src/workbench/utils/model_utils.py
supported_instance_types(arch='x86_64', usage='Hosting')
Get the supported instance types for the given architecture and usage (Hosting/Training)
Source code in src/workbench/utils/model_utils.py
uq_metrics(df, target_col)
Evaluate uncertainty quantification model with essential metrics. Args: df: DataFrame with predictions and uncertainty estimates. Must contain the target column, a "prediction" column, and a "prediction_std" column (required for CRPS and median_std). Quantile columns ("q_025", "q_975", "q_05", "q_95", "q_10", "q_90", "q_25", "q_75") are used for coverage/width when present; otherwise Gaussian bounds are derived from "prediction_std". target_col: Name of the true target column in the DataFrame. Returns: Dictionary of computed metrics.
Source code in src/workbench/utils/model_utils.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 | |
uq_model_local(model, version=None, refresh_proximity=False, radius=2, n_bits=4096)
Load the fitted UQModel (V0, V1, or V2) from this Model's artifact.
Pairs with the existing fp_prox_model() / proximity_model() factory pattern:
model = Model("my-model")
rm = model.uq_model()
out = rm.predict(test_df[["smiles"]], predictions, prediction_std)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The Workbench Model whose artifact contains a fitted UQModel. |
required |
version
|
Optional[str]
|
Which UQ version to load — |
None
|
refresh_proximity
|
bool
|
V1/V2 only. If False (default), use the proximity backend that was embedded in the model artifact at training time — exact reference set used to fit the residual estimator, reproducible, no fingerprint recomputation. If True, build a fresh FingerprintProximity from the current source FeatureSet. Ignored for V0 (no proximity). |
False
|
radius
|
int
|
Morgan fingerprint radius (only used for V1/V2 when refresh_proximity=True). |
2
|
n_bits
|
int
|
Morgan fingerprint bit width (only used for V1/V2 when refresh_proximity=True). |
4096
|
Returns:
| Type | Description |
|---|---|
'UQModelV0 | UQModelV1 | UQModelV2'
|
A ready-to-use UQModelV0, UQModelV1, or UQModelV2 instance. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the requested version's artifact is not in the bundle. |
Source code in src/workbench/utils/model_utils.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
Examples
Feature Importance
"""Example for using some Model Utilities"""
from workbench.utils.model_utils import feature_importance
model = Model("aqsol_classification")
feature_importance(model)
Output
[('mollogp', 469.0),
('minabsestateindex', 277.0),
('peoe_vsa8', 237.0),
('qed', 237.0),
('fpdensitymorgan1', 230.0),
('fpdensitymorgan3', 221.0),
('estate_vsa4', 220.0),
('bcut2d_logphi', 218.0),
('vsa_estate5', 218.0),
('vsa_estate4', 209.0),
Additional Resources

- Workbench API Classes: API Classes
- Consulting Available: SuperCowPowers LLC