Skip to content

Commit 5a11f6d

Browse files
Modularized the post-promotion code; [skip ci]
Modularized both inference and monitoring logic; added some docstrings; removed unused imports.
1 parent cfb0ef7 commit 5a11f6d

47 files changed

Lines changed: 1281 additions & 831 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""A package for post-promotion metadata schemas."""
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Models for inference metadata."""
2+
from typing import Literal
3+
4+
from pydantic import BaseModel
5+
6+
from ml.modeling.models.feature_lineage import FeatureLineage
7+
8+
9+
class InferenceMetadata(BaseModel):
10+
problem_type: str
11+
segment: str
12+
model_version: str
13+
model_stage: str
14+
run_id: str
15+
timestamp: str
16+
columns: list[str]
17+
snapshot_bindings_id: str
18+
feature_lineage: list[FeatureLineage]
19+
artifact_type: Literal["pipeline", "model"]
20+
artifact_hash: str
21+
inference_latency_seconds: float
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""A package for post-promotion metadata validation."""
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""A module for validating inference metadata in the inference pipeline."""
2+
import logging
3+
4+
from ml.exceptions import RuntimeMLError
5+
from ml.metadata.schemas.post_promotion.infer import InferenceMetadata
6+
7+
logger = logging.getLogger(__name__)
8+
9+
def validate_inference_metadata(metadata: dict) -> InferenceMetadata:
10+
"""
11+
Validate the inference metadata against the InferenceMetadata schema.
12+
13+
Args:
14+
metadata (dict): The metadata dictionary to validate.
15+
16+
Returns:
17+
InferenceMetadata: The validated metadata object.
18+
"""
19+
try:
20+
validated_metadata = InferenceMetadata.model_validate(metadata)
21+
logger.debug("Successfully validated inference metadata.")
22+
return validated_metadata
23+
except Exception as e:
24+
msg = "Error validating inference metadata."
25+
logger.exception(msg)
26+
raise RuntimeMLError(msg) from e

ml/metadata/validation/promotion/promote.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""A module for validating promotion metadata against Pydantic models for staging and production."""
12
import logging
23
from typing import Literal
34

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""A package for inference-related code."""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""A package for classes in the inference pipeline."""
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""A module for defining function return types in the inference pipeline."""
2+
from dataclasses import dataclass
3+
from pathlib import Path
4+
from typing import Any, Literal
5+
6+
7+
@dataclass
8+
class ArtifactLoadingReturn:
9+
"""Return type for the artifact loading function."""
10+
artifact: Any
11+
artifact_hash: str
12+
artifact_type: Literal["pipeline", "model"]
13+
14+
@dataclass
15+
class PredictionStoringReturn:
16+
"""Return type for the prediction storing function."""
17+
file_path: Path
18+
cols: list[str]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""A module for defining the schema of predictions in the inference pipeline."""
2+
3+
# Hardcoded, since these are not expected to change very often.
4+
# If changes become common, consider a refactor to make these configurable.
5+
# For now, simply update this file when changes are needed, and ensure that
6+
# all components of the pipeline are updated accordingly.
7+
SCHEMA_VERSION = "V1"
8+
9+
BASE_EXPECTED_COLUMNS = [
10+
"run_id",
11+
"prediction_id",
12+
"timestamp",
13+
"model_stage",
14+
"model_version",
15+
"entity_id",
16+
"input_hash",
17+
"prediction",
18+
"schema_version"
19+
]
20+
21+
PROBA_PREFIX = "proba_"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""A package for the execution code of the inference pipeline."""

0 commit comments

Comments
 (0)