|
1115 | 1115 | "\n", |
1116 | 1116 | "### Upload Model to Workspace\n", |
1117 | 1117 | "\n", |
1118 | | - "Uploads a ML Model to a Wallaroo workspace via POST with `Content-Type: multipart/form-data`.\n", |
| 1118 | + "ML Models are uploaded to Wallaroo through the following endpoint:\n", |
1119 | 1119 | "\n", |
1120 | | - "* **Parameters**\n", |
1121 | | - " * **name** - (*REQUIRED string*): Name of the model\n", |
1122 | | - " * **visibility** - (*OPTIONAL string*): The visibility of the model as either `public` or `private`.\n", |
1123 | | - " * **workspace_id** - (*REQUIRED int*): The numerical id of the workspace to upload the model to.\n", |
1124 | | - " \n", |
1125 | | - "Example: This example will upload the sample file `ccfraud.onnx` to the workspace created in the [Create Workspace](#create-workspace) step as `apitestmodel`. The model name will be saved as `exampleModelName` for use in other examples. The id of the uploaded model will be saved as `example_model_id` for use in later examples." |
| 1120 | + "Models uploaded through this method that are not native runtimes are containerized within the Wallaroo instance then run by the Wallaroo engine. See [Wallaroo MLOps API Essentials Guide: Pipeline Management]({{<ref \"wallaroo-mlops-api-essential-guide-pipelines\">}}) for details on pipeline configurations and deployments.\n", |
| 1121 | + "\n", |
| 1122 | + "For these models, the following inputs are required.\n", |
| 1123 | + "\n", |
| 1124 | + "* Endpoint:\n", |
| 1125 | + " * `/v1/api/models/upload_and_convert`\n", |
| 1126 | + "* Headers:\n", |
| 1127 | + " * **Content-Type**: `multipart/form-data`\n", |
| 1128 | + "* Parameters\n", |
| 1129 | + " * **name** (*String* *Required*): The model name.\n", |
| 1130 | + " * **visibility** (*String* *Required*): Either `public` or `private`.\n", |
| 1131 | + " * **workspace_id** (*String* *Required*): The numerical ID of the workspace to upload the model to.\n", |
| 1132 | + " * **conversion** (*String* *Required*): The conversion parameters that include the following:\n", |
| 1133 | + " * **framework** (*String* *Required*): The framework of the model being uploaded. See the list of supported models for more details.\n", |
| 1134 | + " * **python_version** (*String* *Required*): The version of Python required for model.\n", |
| 1135 | + " * **requirements** (*String* *Required*): Required libraries. Can be `[]` if the requirements are default Wallaroo JupyterHub libraries.\n", |
| 1136 | + " * **input_schema** (*String* *Optional*): The input schema from the Apache Arrow `pyarrow.lib.Schema` format, encoded with `base64.b64encode`. Only required for non-native runtime models.\n", |
| 1137 | + " * **output_schema** (*String* *Optional*): The output schema from the Apache Arrow `pyarrow.lib.Schema` format, encoded with `base64.b64encode`. Only required for non-native runtime models.\n", |
| 1138 | + "\n", |
| 1139 | + "#### Upload Native Runtime Model Example\n", |
| 1140 | + "\n", |
| 1141 | + "ONNX are always native runtimes. The following example shows uploading an ONNX model to a Wallaroo instance using the `requests` library. Note that the `input_schema` and `output_schema` encoded details are not required." |
1126 | 1142 | ] |
1127 | 1143 | }, |
1128 | 1144 | { |
|
1160 | 1176 | } |
1161 | 1177 | ], |
1162 | 1178 | "source": [ |
1163 | | - "## upload model\n", |
1164 | | - "\n", |
1165 | | - "# Retrieve the token\n", |
1166 | | - "headers = wl.auth.auth_header()\n", |
| 1179 | + " authorization header\n", |
| 1180 | + "headers = {'Authorization': 'Bearer abcdefg'}\n", |
1167 | 1181 | "\n", |
1168 | | - "apiRequest = f\"{APIURL}/v1/api/models/upload\"\n", |
| 1182 | + "apiRequest = f\"{APIURL}/v1/api/models/upload_and_convert\"\n", |
1169 | 1183 | "\n", |
1170 | | - "# Model name and file to use\n", |
1171 | | - "display(f\"Sample model name: {model_name}\")\n", |
1172 | | - "display(f\"Sample model file: {model_file_name}\")\n", |
| 1184 | + "framework='onnx'\n", |
1173 | 1185 | "\n", |
| 1186 | + "model_name = f\"{suffix}ccfraud\"\n", |
1174 | 1187 | "\n", |
1175 | 1188 | "data = {\n", |
1176 | | - " \"name\":model_name,\n", |
| 1189 | + " \"name\": model_name,\n", |
1177 | 1190 | " \"visibility\": \"public\",\n", |
1178 | | - " \"workspace_id\": example_workspace_id\n", |
| 1191 | + " \"workspace_id\": workspaceId,\n", |
| 1192 | + " \"conversion\": {\n", |
| 1193 | + " \"framework\": framework,\n", |
| 1194 | + " \"python_version\": \"3.8\",\n", |
| 1195 | + " \"requirements\": []\n", |
| 1196 | + " }\n", |
1179 | 1197 | "}\n", |
1180 | 1198 | "\n", |
1181 | 1199 | "files = {\n", |
1182 | | - " 'file': (model_name, open(model_file_name, 'rb'))\n", |
| 1200 | + " \"metadata\": (None, json.dumps(data), \"application/json\"),\n", |
| 1201 | + " 'file': (model_name, open('./ccfraud.onnx', 'rb'), \"application/octet-stream\")\n", |
1183 | 1202 | " }\n", |
1184 | 1203 | "\n", |
1185 | 1204 | "\n", |
1186 | | - "response = requests.post(apiRequest, files=files, data=data, headers=headers).json()\n", |
1187 | | - "display(response)" |
| 1205 | + "response = requests.post(apiRequest, files=files, headers=headers).json()" |
| 1206 | + ] |
| 1207 | + }, |
| 1208 | + { |
| 1209 | + "cell_type": "markdown", |
| 1210 | + "id": "861a91ae", |
| 1211 | + "metadata": {}, |
| 1212 | + "source": [ |
| 1213 | + "#### Upload Converted Model Examples\n", |
| 1214 | + "\n", |
| 1215 | + "The following example shows uploading a Hugging Face model to a Wallaroo instance using the `requests` library. Note that the `input_schema` and `output_schema` encoded details are required." |
| 1216 | + ] |
| 1217 | + }, |
| 1218 | + { |
| 1219 | + "cell_type": "code", |
| 1220 | + "execution_count": null, |
| 1221 | + "id": "c20c5ba5", |
| 1222 | + "metadata": {}, |
| 1223 | + "outputs": [], |
| 1224 | + "source": [ |
| 1225 | + "input_schema = pa.schema([\n", |
| 1226 | + " pa.field('inputs', pa.string()), # required\n", |
| 1227 | + " pa.field('candidate_labels', pa.list_(pa.string(), list_size=2)), # required\n", |
| 1228 | + " pa.field('hypothesis_template', pa.string()), # optional\n", |
| 1229 | + " pa.field('multi_label', pa.bool_()), # optional\n", |
| 1230 | + "])\n", |
| 1231 | + "\n", |
| 1232 | + "output_schema = pa.schema([\n", |
| 1233 | + " pa.field('sequence', pa.string()),\n", |
| 1234 | + " pa.field('scores', pa.list_(pa.float64(), list_size=2)), # same as number of candidate labels, list_size can be skipped by may result in slightly worse performance\n", |
| 1235 | + " pa.field('labels', pa.list_(pa.string(), list_size=2)), # same as number of candidate labels, list_size can be skipped by may result in slightly worse performance\n", |
| 1236 | + "])\n", |
| 1237 | + "\n", |
| 1238 | + "encoded_input_schema = base64.b64encode(\n", |
| 1239 | + " bytes(input_schema.serialize())\n", |
| 1240 | + " ).decode(\"utf8\")\n", |
| 1241 | + "\n", |
| 1242 | + "encoded_output_schema = base64.b64encode(\n", |
| 1243 | + " bytes(output_schema.serialize())\n", |
| 1244 | + " ).decode(\"utf8\")\n", |
| 1245 | + "\n", |
| 1246 | + "metadata = {\n", |
| 1247 | + " \"name\": model_name,\n", |
| 1248 | + " \"visibility\": \"private\",\n", |
| 1249 | + " \"workspace_id\": workspace_id,\n", |
| 1250 | + " \"conversion\": {\n", |
| 1251 | + " \"framework\": framework,\n", |
| 1252 | + " \"python_version\": \"3.8\",\n", |
| 1253 | + " \"requirements\": []\n", |
| 1254 | + " },\n", |
| 1255 | + " \"input_schema\": encoded_input_schema,\n", |
| 1256 | + " \"output_schema\": encoded_output_schema,\n", |
| 1257 | + "}\n", |
| 1258 | + "\n", |
| 1259 | + "headers = wl.auth.auth_header()\n", |
| 1260 | + "\n", |
| 1261 | + "files = {\n", |
| 1262 | + " 'metadata': (None, json.dumps(metadata), \"application/json\"),\n", |
| 1263 | + " 'file': (model_name, open(model_path,'rb'),'application/octet-stream')\n", |
| 1264 | + "}\n", |
| 1265 | + "\n", |
| 1266 | + "response = requests.post('https://{APIURL}/v1/api/models/upload_and_convert', \n", |
| 1267 | + " headers=headers, \n", |
| 1268 | + " files=files).json()" |
1188 | 1269 | ] |
1189 | 1270 | }, |
1190 | 1271 | { |
|
0 commit comments