We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Support .json and .ubj model format for XGBoost server image
/kind feature


**Description**
In the XGBoost image, the only supported model format is .bst: https://github.com/kserve/kserve/blob/56b8fe0d189fc0d557e9a8af07eab0c12852d5fd/python/xgbserver/xgbserver/model.py#L28

This format has been deprecated for a while and is not backwards compatible between xgboost framework versions. The recommended model format is .json or .ubj: https://xgboost.readthedocs.io/en/stable/tutorials/saving_model.html

Users that want to use the recommended model format for XGBoost models, are currently not able to do so.


**Proposed solution**
Support the recommended file formats, while also keeping support for the old .bst format. 






--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `python/xgbserver/xgbserver/model.py`
Content:
```
1 # Copyright 2021 The KServe Authors.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 
16 import os
17 from typing import Dict, Union
18 
19 import xgboost as xgb
20 from kserve.errors import InferenceError, ModelMissingError
21 from kserve.protocol.infer_type import InferRequest, InferResponse
22 from kserve.utils.utils import get_predict_input, get_predict_response
23 from xgboost import XGBModel
24 
25 from kserve import Model
26 from kserve.storage import Storage
27 
28 BOOSTER_FILE_EXTENSION = ".bst"
29 
30 
31 class XGBoostModel(Model):
32     def __init__(
33         self, name: str, model_dir: str, nthread: int, booster: XGBModel = None
34     ):
35         super().__init__(name)
36         self.name = name
37         self.model_dir = model_dir
38         self.nthread = nthread
39         if booster is not None:
40             self._booster = booster
41             self.ready = True
42 
43     def load(self) -> bool:
44         model_path = Storage.download(self.model_dir)
45         model_files = []
46         for file in os.listdir(model_path):
47             file_path = os.path.join(model_path, file)
48             if os.path.isfile(file_path) and file.endswith(BOOSTER_FILE_EXTENSION):
49                 model_files.append(file_path)
50         if len(model_files) == 0:
51             raise ModelMissingError(model_path)
52         elif len(model_files) > 1:
53             raise RuntimeError(
54                 "More than one model file is detected, "
55                 f"Only one is allowed within model_dir: {model_files}"
56             )
57 
58         self._booster = xgb.Booster(
59             params={"nthread": self.nthread}, model_file=model_files[0]
60         )
61         self.ready = True
62         return self.ready
63 
64     def predict(
65         self, payload: Union[Dict, InferRequest], headers: Dict[str, str] = None
66     ) -> Union[Dict, InferResponse]:
67         try:
68             # Use of list as input is deprecated see https://github.com/dmlc/xgboost/pull/3970
69             instances = get_predict_input(payload)
70             dmatrix = xgb.DMatrix(instances, nthread=self.nthread)
71             result = self._booster.predict(dmatrix)
72             return get_predict_response(payload, result, self.name)
73         except Exception as e:
74             raise InferenceError(str(e))
75
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/python/xgbserver/xgbserver/model.py b/python/xgbserver/xgbserver/model.py
--- a/python/xgbserver/xgbserver/model.py
+++ b/python/xgbserver/xgbserver/model.py
@@ -25,7 +25,7 @@
 from kserve import Model
 from kserve.storage import Storage
 
-BOOSTER_FILE_EXTENSION = ".bst"
+BOOSTER_FILE_EXTENSIONS = (".bst", ".json", ".ubj")
 
 
 class XGBoostModel(Model):
@@ -45,7 +45,7 @@
         model_files = []
         for file in os.listdir(model_path):
             file_path = os.path.join(model_path, file)
-            if os.path.isfile(file_path) and file.endswith(BOOSTER_FILE_EXTENSION):
+            if os.path.isfile(file_path) and file.endswith(BOOSTER_FILE_EXTENSIONS):
                 model_files.append(file_path)
         if len(model_files) == 0:
             raise ModelMissingError(model_path)

{"golden_diff": "diff --git a/python/xgbserver/xgbserver/model.py b/python/xgbserver/xgbserver/model.py\n--- a/python/xgbserver/xgbserver/model.py\n+++ b/python/xgbserver/xgbserver/model.py\n@@ -25,7 +25,7 @@\n from kserve import Model\n from kserve.storage import Storage\n \n-BOOSTER_FILE_EXTENSION = \".bst\"\n+BOOSTER_FILE_EXTENSIONS = (\".bst\", \".json\", \".ubj\")\n \n \n class XGBoostModel(Model):\n@@ -45,7 +45,7 @@\n         model_files = []\n         for file in os.listdir(model_path):\n             file_path = os.path.join(model_path, file)\n-            if os.path.isfile(file_path) and file.endswith(BOOSTER_FILE_EXTENSION):\n+            if os.path.isfile(file_path) and file.endswith(BOOSTER_FILE_EXTENSIONS):\n                 model_files.append(file_path)\n         if len(model_files) == 0:\n             raise ModelMissingError(model_path)\n", "issue": "Support .json and .ubj model format for XGBoost server image\n/kind feature\r\n\r\n\r\n**Description**\r\nIn the XGBoost image, the only supported model format is .bst: https://github.com/kserve/kserve/blob/56b8fe0d189fc0d557e9a8af07eab0c12852d5fd/python/xgbserver/xgbserver/model.py#L28\r\n\r\nThis format has been deprecated for a while and is not backwards compatible between xgboost framework versions. The recommended model format is .json or .ubj: https://xgboost.readthedocs.io/en/stable/tutorials/saving_model.html\r\n\r\nUsers that want to use the recommended model format for XGBoost models, are currently not able to do so.\r\n\r\n\r\n**Proposed solution**\r\nSupport the recommended file formats, while also keeping support for the old .bst format. \r\n\r\n\r\n\r\n\r\n\n", "before_files": [{"content": "# Copyright 2021 The KServe Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\nimport os\nfrom typing import Dict, Union\n\nimport xgboost as xgb\nfrom kserve.errors import InferenceError, ModelMissingError\nfrom kserve.protocol.infer_type import InferRequest, InferResponse\nfrom kserve.utils.utils import get_predict_input, get_predict_response\nfrom xgboost import XGBModel\n\nfrom kserve import Model\nfrom kserve.storage import Storage\n\nBOOSTER_FILE_EXTENSION = \".bst\"\n\n\nclass XGBoostModel(Model):\n    def __init__(\n        self, name: str, model_dir: str, nthread: int, booster: XGBModel = None\n    ):\n        super().__init__(name)\n        self.name = name\n        self.model_dir = model_dir\n        self.nthread = nthread\n        if booster is not None:\n            self._booster = booster\n            self.ready = True\n\n    def load(self) -> bool:\n        model_path = Storage.download(self.model_dir)\n        model_files = []\n        for file in os.listdir(model_path):\n            file_path = os.path.join(model_path, file)\n            if os.path.isfile(file_path) and file.endswith(BOOSTER_FILE_EXTENSION):\n                model_files.append(file_path)\n        if len(model_files) == 0:\n            raise ModelMissingError(model_path)\n        elif len(model_files) > 1:\n            raise RuntimeError(\n                \"More than one model file is detected, \"\n                f\"Only one is allowed within model_dir: {model_files}\"\n            )\n\n        self._booster = xgb.Booster(\n            params={\"nthread\": self.nthread}, model_file=model_files[0]\n        )\n        self.ready = True\n        return self.ready\n\n    def predict(\n        self, payload: Union[Dict, InferRequest], headers: Dict[str, str] = None\n    ) -> Union[Dict, InferResponse]:\n        try:\n            # Use of list as input is deprecated see https://github.com/dmlc/xgboost/pull/3970\n            instances = get_predict_input(payload)\n            dmatrix = xgb.DMatrix(instances, nthread=self.nthread)\n            result = self._booster.predict(dmatrix)\n            return get_predict_response(payload, result, self.name)\n        except Exception as e:\n            raise InferenceError(str(e))\n", "path": "python/xgbserver/xgbserver/model.py"}], "after_files": [{"content": "# Copyright 2021 The KServe Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\nimport os\nfrom typing import Dict, Union\n\nimport xgboost as xgb\nfrom kserve.errors import InferenceError, ModelMissingError\nfrom kserve.protocol.infer_type import InferRequest, InferResponse\nfrom kserve.utils.utils import get_predict_input, get_predict_response\nfrom xgboost import XGBModel\n\nfrom kserve import Model\nfrom kserve.storage import Storage\n\nBOOSTER_FILE_EXTENSIONS = (\".bst\", \".json\", \".ubj\")\n\n\nclass XGBoostModel(Model):\n    def __init__(\n        self, name: str, model_dir: str, nthread: int, booster: XGBModel = None\n    ):\n        super().__init__(name)\n        self.name = name\n        self.model_dir = model_dir\n        self.nthread = nthread\n        if booster is not None:\n            self._booster = booster\n            self.ready = True\n\n    def load(self) -> bool:\n        model_path = Storage.download(self.model_dir)\n        model_files = []\n        for file in os.listdir(model_path):\n            file_path = os.path.join(model_path, file)\n            if os.path.isfile(file_path) and file.endswith(BOOSTER_FILE_EXTENSIONS):\n                model_files.append(file_path)\n        if len(model_files) == 0:\n            raise ModelMissingError(model_path)\n        elif len(model_files) > 1:\n            raise RuntimeError(\n                \"More than one model file is detected, \"\n                f\"Only one is allowed within model_dir: {model_files}\"\n            )\n\n        self._booster = xgb.Booster(\n            params={\"nthread\": self.nthread}, model_file=model_files[0]\n        )\n        self.ready = True\n        return self.ready\n\n    def predict(\n        self, payload: Union[Dict, InferRequest], headers: Dict[str, str] = None\n    ) -> Union[Dict, InferResponse]:\n        try:\n            # Use of list as input is deprecated see https://github.com/dmlc/xgboost/pull/3970\n            instances = get_predict_input(payload)\n            dmatrix = xgb.DMatrix(instances, nthread=self.nthread)\n            result = self._booster.predict(dmatrix)\n            return get_predict_response(payload, result, self.name)\n        except Exception as e:\n            raise InferenceError(str(e))\n", "path": "python/xgbserver/xgbserver/model.py"}]}