mlflow/mlflow · error · Exception

This container only supports models with the PyFunc flavors.

Error message

This container only supports models with the PyFunc flavors.

What it means

_serve loads the MLmodel file baked into the container and checks that the pyfunc flavor is present before serving. Containers built for pyfunc serving can only execute models exposing the python_function flavor; otherwise it raises an Exception stating the container only supports PyFunc flavors.

Source

Thrown at mlflow/models/container/__init__.py:73

    elif cmd == "train":
        _train()
    else:
        raise Exception(f"Unrecognized command {cmd}, full args = {sys.argv}")


def _serve(env_manager):
    """
    Serve the model.

    Read the MLmodel config, initialize the Conda environment if needed and start python server.
    """
    model_config_path = os.path.join(MODEL_PATH, MLMODEL_FILE_NAME)
    m = Model.load(model_config_path)

    if pyfunc.FLAVOR_NAME in m.flavors:
        _serve_pyfunc(m, env_manager)
    else:
        raise Exception("This container only supports models with the PyFunc flavors.")


def _install_pyfunc_deps(model_path=None, install_mlflow=False, env_manager=em.VIRTUALENV):
    """
    Creates a conda env for serving the model at the specified path and installs almost all serving
    dependencies into the environment - MLflow is not installed as it's not available via conda.
    """
    activate_cmd = _install_model_dependencies_to_env(model_path, env_manager) if model_path else []

    # NB: install gunicorn[gevent] from pip rather than from conda because gunicorn is already
    # dependency of mlflow on pip and we expect mlflow to be part of the environment.
    server_deps = ["gunicorn[gevent]"]

    install_server_deps = [f"pip install {' '.join(server_deps)}"]
    if Popen(["bash", "-c", " && ".join(activate_cmd + install_server_deps)]).wait() != 0:
        raise Exception("Failed to install serving dependencies into the model environment.")

    # NB: If we don't use virtualenv or conda env, we don't need to install mlflow here as

View on GitHub (pinned to 6a27f2decc)

Solutions

  1. Re-log/save the model so it includes the python_function flavor (use mlflow.pyfunc.log_model or a flavor that produces pyfunc, e.g. sklearn/tensorflow log_model).
  2. Check the MLmodel file in the container (cat /opt/ml/model/MLmodel) and confirm a 'python_function' flavors entry exists.
  3. For non-Python models, use a serving path appropriate to that flavor rather than the pyfunc container.
  4. If using a custom pyfunc, ensure python_function flavor registration via mlflow.pyfunc.model/PythonModel and re-build the image.

Example fix

// before
mlflow.sklearn.save_model(sk_model, path)  # missing pyfunc if custom loader pruned flavors
// after
import mlflow
mlflow.pyfunc.log_model(artifact_path="model", python_model=my_model)  # ensures python_function flavor, then rebuild image
Defensive patterns

Strategy: validation

Validate before calling

import mlflow.models
def validate_pyfunc_flavor(model_uri: str):
    m = mlflow.models.get_model_info(model_uri)
    if "python_function" not in m.flavors:
        raise ValueError(f"Model {model_uri} lacks python_function flavor; container serving requires it")

Type guard

def has_pyfunc_flavor(model_info) -> bool:
    return "python_function" in model_info.flavors

Try / catch

import subprocess
p = subprocess.run(["docker", "run", image, "serve"], capture_output=True)
if p.returncode != 0 and b"only supports models with the PyFunc flavors" in p.stdout + p.stderr:
    raise RuntimeError("Rebuild the image from a model with a python_function flavor")

Prevention

When it happens

Trigger: docker run ... serve on a container built from a model whose MLmodel lacks the 'python_function' flavor — e.g. models saved with mlflow.<flavor>.save_model that don't produce pyfunc, or an MLmodel manually edited/pruned to drop pyfunc.

Common situations: Serving R or Java-flavored-only models in the pyfunc container; building images from MLflow 1.x artifacts loaded by newer tooling; models saved with only 'loader_module' pyfunc removed; mistakenly generating a dockerfile for a non-pyfunc-able model.

Related errors


AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29). Data as JSON: /api/errors/f477d7e81e8298c3. Report an issue: GitHub.