def get_service(model_name: str, **config: Unpack[ServiceConfig]) -> Service[t.Any]:
    """
    Get a BentoML service instance from an XGBoost model.

    Args:
        model_name (``str``):
            The name of the model to get the service for.
        **config (``Unpack[ServiceConfig]``):
            Configuration options for the service.
    Returns:
        A BentoML service instance that wraps the XGBoost model.
    Example:

    .. code-block:: python

        import bentoml

        service = bentoml.xgboost.get_service("my_xgboost_model")
    """

    @bentoml.service(**config)
    class XGBoostService:
        bento_model = bentoml.models.get(model_name)

        def __init__(self) -> None:
            self.model = load_model(self.bento_model)
            self.booster = (
                self.model
                if isinstance(self.model, xgb.Booster)
                else self.model.get_booster()
            )

            # check for resources
            if os.getenv("CUDA_VISIBLE_DEVICES") not in (None, "", "-1"):
                self.booster.set_param({"predictor": "gpu_predictor", "gpu_id": 0})  # type: ignore (incomplete XGBoost types)
            else:
                nthreads = os.getenv("OMP_NUM_THREADS")
                if nthreads is not None and nthreads != "":
                    nthreads = max(int(nthreads), 1)
                else:
                    nthreads = 1
                self.booster.set_param(
                    {"predictor": "cpu_predictor", "nthread": nthreads}
                )  # type: ignore (incomplete XGBoost types)

        if bento_model.info.options.model_class == "Booster":

            @bentoml.api
            def predict(
                self,
                data: np.ndarray,
                output_margin: bool = False,
                pred_leaf: bool = False,
                pred_contribs: bool = False,
                approx_contribs: bool = False,
                pred_interactions: bool = False,
                validate_features: bool = True,
                training: bool = False,
                iteration_range: t.Tuple[int, int] = (0, 0),
                strict_shape: bool = False,
            ) -> np.ndarray:
                assert isinstance(self.model, xgb.Booster)
                return self.model.predict(
                    xgb.DMatrix(data),
                    output_margin=output_margin,
                    pred_leaf=pred_leaf,
                    pred_contribs=pred_contribs,
                    approx_contribs=approx_contribs,
                    pred_interactions=pred_interactions,
                    validate_features=validate_features,
                    training=training,
                    iteration_range=iteration_range,
                    strict_shape=strict_shape,
                )  # type: ignore (incomplete XGBoost types)
        else:

            @bentoml.api
            def predict(
                self,
                data: np.ndarray,
                output_margin: bool = False,
                validate_features: bool = True,
                base_margin: t.Optional[t.List[t.Any]] = None,
                iteration_range: t.Optional[t.Tuple[int, int]] = None,
            ) -> np.ndarray:
                assert isinstance(self.model, XGBModel)
                return self.model.predict(
                    data,
                    output_margin=output_margin,
                    validate_features=validate_features,
                    base_margin=base_margin,
                    iteration_range=iteration_range,
                )

    return XGBoostService
Get a BentoML service instance from an XGBoost model.

Args:
model_name (``str``):
The name of the model to get the service for.
**config (``Unpack[ServiceConfig]``):
Configuration options for the service.
Returns:
A BentoML service instance that wraps the XGBoost model.
Example:

.. code-block:: python

import bentoml

service = bentoml.xgboost.get_service("my_xgboost_model")
src/_bentoml_impl/frameworks/xgboost.py