This message was deleted.
# ask-for-help
s
This message was deleted.
a
what framework do you train your model with?
s
sklearn
a
then you should use
bentoml.sklearn
Currently, we don’t directly support azure ml, but you can always download the artifact locally, then use bentoml.sklearn to save it
s
Can you please elaborate on artifacts to be downloaded? Is it packages to be installed before loading the pickle file trained in azure ml environment?
a
Not sure how you setup your environment, Afaik, if you have access to the artifact that you trained you should able to save it with
bentoml.sklearn
a
Just make sure the sklearn and python version matches while serving using bentoml, I do it using a custom runner as such
Copy code
def convert_model_to_runner(model: BaseEstimator):
    """Function to convert sklearn model to a bentoml.Runner instance to be used for serving.

    Args:
        model: Any sklearn model stored locally with serve code.
            Types allowed are BaseEstimator

    Returns:
        Bentoml.Runner instance which can be used to create a service.

    Raises:
        UnableToConvertModel: When conversion of model to Bentoml.Runner fails
    """
    try:
        prediction_runner = bentoml.Runner(
            ScikitLearnModelRunnable,
            name="prediction_runner",
            runnable_init_params={"model": model},
        )
        return cast(ScikitLearnModelRunner, prediction_runner)
    except TypeError as error:
        logger.error("Could not save model into a bentoml.Runner.", exc_info=True)
        raise UnableToConvertModel("Error mapping model to Bentoml.Runner") from error
You can load a pickle file as such, I use joblib
Copy code
def load_pickle_file(path: str):
    """Function to load pickle file."""
    try:
        return joblib.load(path)
    except (OSError, ValueError, AssertionError) as exception:  # invalid pickle raises Assertion
        log_error_and_raise_exception(ModelNotFound("Model file not found"), exception)
after loading the function just call the convert to runner function as such
Copy code
convert_model_to_runner(model),
Hope these snippets help @Sarthak Verma 🙏
1