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

MlflowException: The specified model does not contain any of the supported flavors for deployment. #52

Open
jaykishan-b opened this issue Sep 1, 2023 · 1 comment

Comments

@jaykishan-b
Copy link

While deploying the model generated with the regression example, getting below error: (In this case, the model has been created, but getting error while deploying the model on sagemaker)

MlflowException: The specified model does not contain any of the supported flavors for deployment. The model contains the following flavors: dict_keys(['sklearn']). Supported flavors: ['python_function', 'mleap']

Script for model deployment: https://github.com/aws-samples/amazon-sagemaker-mlflow-fargate/blob/main/lab/3_deploy_model.ipynb

Full traceback:

---------------------------------------------------------------------------
MlflowException                           Traceback (most recent call last)
Cell In[11], line 11
      1 config={
      2     'execution_role_arn': role,
      3     'image_url': image_uri,
   (...)
      6     'region_name': region
      7 }
      9 client = get_deploy_client("sagemaker")
---> 11 client.create_deployment(
     12     name=endpoint_name,
     13     model_uri=model_uri,
     14     # flavor='sklearn',
     15     config=config
     16 )

File ~/.local/share/virtualenvs/recipes-examples-49tQ2II3/lib/python3.10/site-packages/mlflow/sagemaker/__init__.py:2206, in SageMakerDeploymentClient.create_deployment(self, name, model_uri, flavor, config, endpoint)
   2203 if config:
   2204     self._apply_custom_config(final_config, config)
-> 2206 app_name, flavor = _deploy(
   2207     app_name=name,
   2208     model_uri=model_uri,
   2209     flavor=flavor,
   2210     execution_role_arn=final_config["execution_role_arn"],
   2211     assume_role_arn=final_config["assume_role_arn"],
   2212     bucket=final_config["bucket"],
   2213     image_url=final_config["image_url"],
   2214     region_name=final_config["region_name"],
   2215     mode=mlflow.sagemaker.DEPLOYMENT_MODE_CREATE,
   2216     archive=final_config["archive"],
   2217     instance_type=final_config["instance_type"],
   2218     instance_count=final_config["instance_count"],
   2219     vpc_config=final_config["vpc_config"],
   2220     data_capture_config=final_config["data_capture_config"],
   2221     synchronous=final_config["synchronous"],
   2222     timeout_seconds=final_config["timeout_seconds"],
   2223     variant_name=final_config["variant_name"],
   2224     async_inference_config=final_config["async_inference_config"],
   2225     env=final_config["env"],
   2226     tags=final_config["tags"],
   2227 )
   2229 return {"name": app_name, "flavor": flavor}

File ~/.local/share/virtualenvs/recipes-examples-49tQ2II3/lib/python3.10/site-packages/mlflow/sagemaker/__init__.py:365, in _deploy(app_name, model_uri, execution_role_arn, assume_role_arn, bucket, image_url, region_name, mode, archive, instance_type, instance_count, vpc_config, flavor, synchronous, timeout_seconds, data_capture_config, variant_name, async_inference_config, env, tags)
    362 model_config = Model.load(model_config_path)
    364 if flavor is None:
--> 365     flavor = _get_preferred_deployment_flavor(model_config)
    366 else:
    367     _validate_deployment_flavor(model_config, flavor)

File ~/.local/share/virtualenvs/recipes-examples-49tQ2II3/lib/python3.10/site-packages/mlflow/sagemaker/__init__.py:68, in _get_preferred_deployment_flavor(model_config)
     66     return pyfunc.FLAVOR_NAME
     67 else:
---> 68     raise MlflowException(
...
     76         ),
     77         error_code=RESOURCE_DOES_NOT_EXIST,
     78     )

	MlflowException: The specified model does not contain any of the supported flavors for deployment. The model contains the following flavors: dict_keys(['sklearn']). Supported flavors: ['python_function', 'mleap']

Below is the MLmodel file:

artifact_path: transform/transformer
flavors:
  sklearn:
    code: code
    pickled_model: model.pkl
    serialization_format: cloudpickle
    sklearn_version: 1.3.0
mlflow_version: 2.6.0
model_uuid: 4d185e028de7487db974b36311d37d87
run_id: 57eb75a5c4a74f12b33d6d2146bc3bce
utc_time_created: '2023-08-24 09:15:53.090506'

Tried modifying estimator function in train.py step as below to get python_function flavor in the MLmodel file:

Reference: https://github.com/mlflow/mlflow/blob/master/docs/source/models.rst#scikit-learn-sklearn

def estimator_fn(estimator_params: Dict[str, Any] = None):
    """
    Returns an *unfitted* estimator that defines ``fit()`` and ``predict()`` methods.
    The estimator's input and output signatures should be compatible with scikit-learn
    estimators.
    """
    if estimator_params is None:
        estimator_params = {}

    sgd_regressor = SGDRegressor(random_state=42, **estimator_params)
    
    model_info = mlflow.sklearn.log_model(
        sk_model=sgd_regressor, artifact_path="sklearn_pyfunc_model_artifact"
    )

    sklearn_pyfunc = mlflow.pyfunc.load_model(model_uri=model_info.model_uri)
    return sklearn_pyfunc`

With above modification, getting below error (In this case, getting error while running train step of the recipe):

MlflowException                           Traceback (most recent call last)
Cell In[17], line 1
----> 1 r.run("train")

File ~/.local/share/virtualenvs/recipes-examples-49tQ2II3/lib/python3.10/site-packages/mlflow/recipes/regression/v1/recipe.py:276, in RegressionRecipe.run(self, step)
    204 def run(self, step: str = None) -> None:
    205     """
    206     Runs the full recipe or a particular recipe step, producing outputs and displaying a
    207     summary of results upon completion. Step outputs are cached from previous executions, and
   (...)
    274         regression_recipe.run()
    275     """
--> 276     return super().run(step=step)

File ~/.local/share/virtualenvs/recipes-examples-49tQ2II3/lib/python3.10/site-packages/mlflow/recipes/recipe.py:98, in BaseRecipe.run(self, step)
     96 if last_executed_step_state.status != StepStatus.SUCCEEDED:
     97     if step is not None:
---> 98         raise MlflowException(
     99             f"Failed to run step '{step}' of recipe '{self.name}'."
    100             f" An error was encountered while running step '{last_executed_step.name}':"
    101             f" {last_executed_step_state.stack_trace}",
    102             error_code=BAD_REQUEST,
    103         )
    104     else:
    105         raise MlflowException(
    106             f"Failed to run recipe '{self.name}'."
    107             f" An error was encountered while running step '{last_executed_step.name}':"
    108             f" {last_executed_step_state.stack_trace}",
    109             error_code=BAD_REQUEST,
    110         )

MlflowException: Failed to run step 'train' of recipe 'regression'. An error was encountered while running step 'train': Traceback (most recent call last):
  File "/home/jaykishan/.local/share/virtualenvs/recipes-examples-49tQ2II3/lib/python3.10/site-packages/mlflow/recipes/step.py", line 129, in run
    self.step_card = self._run(output_directory=output_directory)
  File "/home/jaykishan/.local/share/virtualenvs/recipes-examples-49tQ2II3/lib/python3.10/site-packages/mlflow/recipes/steps/train.py", line 367, in _run
    estimator = self._resolve_estimator(
  File "/home/jaykishan/.local/share/virtualenvs/recipes-examples-49tQ2II3/lib/python3.10/site-packages/mlflow/recipes/steps/train.py", line 695, in _resolve_estimator
    return self._get_user_defined_estimator(
  File "/home/jaykishan/.local/share/virtualenvs/recipes-examples-49tQ2II3/lib/python3.10/site-packages/mlflow/recipes/steps/train.py", line 665, in _get_user_defined_estimator
    default_params = estimator.get_params()
AttributeError: 'PyFuncModel' object has no attribute 'get_params'

Any idea about this?

@benjaminbascary
Copy link

Any advance on this? I got stuck in the same part

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

No branches or pull requests

2 participants