Skip to content

SNOW-1967393: Snowflake ML Registry for Model Explainability: ValueError: Model type <class 'NoneType'> is not supported when logging a Pipeline #145

@Masoud-Ghodrati

Description

@Masoud-Ghodrati

I am training an XGBClassifier model using Snowflake ML and attempting to register it using Snowflake’s model registry. The training and evaluation steps complete successfully, but when I try to log the model using log_model(), I get the following error:

Training Accuracy: 0.9610
Evaluation Accuracy: 0.8730
Traceback (most recent call last):
  File "C:\Mas\rla_projects\Claims-AI--lodgement\code\python\src\explain\train_model.py", line 56, in <module>
    model_version = native_registry.log_model(
  File "C:\Mas\py39_sf_ml\lib\site-packages\snowflake\ml\_internal\telemetry.py", line 542, in wrap
    return ctx.run(execute_func_with_statement_params)
  ...
  File "C:\Mas\py39_sf_ml\lib\site-packages\snowflake\ml\model\_packager\model_task\model_task_utils.py", line 149, in _get_model_task    
    raise ValueError(f"Model type {type(model)} is not supported")
ValueError: Model type <class 'NoneType'> is not supported

Code Snippet:

from snowflake.snowpark import Session
from snowflake.ml.registry import registry
from snowflake.ml.modeling.preprocessing import StandardScaler
from snowflake.ml.modeling.impute import SimpleImputer
from snowflake.ml.modeling.pipeline import Pipeline
from snowflake.ml.modeling.xgboost import XGBClassifier

# Snowflake connection parameters
conn_params = {
    "user": "<...>",
    "account": "<...>",
    "warehouse": "<...>",
    "database": "<...>",
    "schema": "<...>",
    "role": "<...>",
    "authenticator": "externalbrowser",
}

# Create session
session = Session.builder.configs(conn_params).create()

# Load and prepare data
all_data = session.sql("SELECT *, IFF(CLASS = 'g', 1.0, 0.0) AS LABEL FROM Gamma_Telescope_Data").drop("CLASS")
train_data, test_data = all_data.random_split(weights=[0.9, 0.1], seed=0)

# Define feature and label columns
FEATURE_COLS = [c for c in train_data.columns if c != "LABEL"]
LABEL_COLS = ["LABEL"]

# Construct pipeline
pipeline = Pipeline(steps=[
    ("impute", SimpleImputer(input_cols=FEATURE_COLS, output_cols=FEATURE_COLS)),
    ("scaler", StandardScaler(input_cols=FEATURE_COLS, output_cols=FEATURE_COLS)),
    ("model", XGBClassifier(input_cols=FEATURE_COLS, label_cols=LABEL_COLS))
])

# Train the pipeline
pipeline.fit(train_data)

# Register model
native_registry = registry.Registry(
    session=session, 
    database_name=session.get_current_database(), 
    schema_name=session.get_current_schema()
)

model_name = "Gamma_test"
version = "V8"

model_version = native_registry.log_model(
    model=pipeline,  # <-- This line triggers the error
    model_name=model_name,
    version_name=version,
    sample_input_data=test_data,
    comment="Gamma test",
    conda_dependencies=["snowflake-ml-python==1.7.4", "snowflake-snowpark-python==1.28.0"],
    options={"enable_explainability": True}
)

Observations & Debugging Attempts:

  1. Pipeline Training Workspipeline.fit(train_data) runs without errors.
  2. Pipeline Predictions Work – Predictions on training and test data succeed.
  3. Model Explanation Works Without Pipeline – If I train an XGBClassifier without a pipeline, I can successfully generate predictions and explanations.
  4. Session is Activesession.get_current_database() and session.get_current_schema() return valid values.
  5. Feature & Label Columns Look CorrectFEATURE_COLS and LABEL_COLS contain expected values.

Additional Context:

Question:

Is it possible to register a pipeline with options={"enable_explainability": True}?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions