can y'all remind be what is best practices around ...
# general
g
can y'all remind be what is best practices around UDFs. I have model in mlflow that I want to use. should I: 1. load the model from mlflow in
__init__
2. load the model from mlflow in my main script and pass as an argument like below
Copy code
@daft.cls
class ModelPredictor:
    """Model predictor for Daft DataFrames."""

    def __init__(self, model: lgb.Booster, train_config: TrainConfig) -> None:
        self.model = copy.deepcopy(model)
        self.train_config = train_config
k
Hi Garrett, you should load it in
__init__
!
🙌 1
g
@Kevin Wang one more question, what is the correct typing here (the docs have
Series
in the example)?
Argument 1 to "predict" of "ModelPredictor" has incompatible type "*list[Expression]"; expected "Series"
Copy code
@daft.method.batch(return_dtype=daft.DataType.float64())
    def predict(self, *features: daft.Series):  # type: ignore
        """Predict method for Daft Series."""
        feature_df = pd.DataFrame(
            {feature.name: feature.to_arrow() for feature in features}
        )

        return daft.Series.from_numpy(
            model_predict(self.model, feature_df, self.train_config).to_numpy()
        )
mypy also yells at me abou the return type hence the
# type: ignore
, maybe it's because we are on an older version most likely
k
This is a static type checking error and not a runtime error right?
g
yeah, static type checking error
I am using like this:
Copy code
return inference_features.with_column(
        "regression_output",
        model_predictor.predict(
            *[daft.col(col) for col in train_config.feature_cols]  # type: ignore
        ),
    )
I can type ignore, but wanted to make sure not user error
k
Yeah not user error. Just mypy not understanding the decorator I think
g
makes sense, not the first time mypy + decorators didn't play nicely
k
Curious if you write Ray code and have had similar issues with Ray as well. They do a similar thing for
@ray.remote
on classes to create Ray Actors. Wonder if they do anything different that plays nicer with mypy
g
Nothing that comes to mind immediately.
👍 1
ok, one last question, mlflow seems a bit mad at me spamming it for the model, should I push it to some intermediary that would handle the concurrent requests better?
k
Hm, that is one potential case where you may want to load it outside of
__init__
, if there is some issue with concurrent model weight loading.
But using an intermediary is a better solution in the long run
g
I think it's just the connection pool settings we have on our mlflow server are very low