Skip to content

Commit

Permalink
Merge pull request #825 from Teradata/modelfactory-notebook-issue
Browse files Browse the repository at this point in the history
ModelOps ModelFactory notebook fix
  • Loading branch information
DallasBowden authored Feb 5, 2025
2 parents 9feffbf + 9db2b60 commit 1c9fb8a
Showing 1 changed file with 71 additions and 43 deletions.
114 changes: 71 additions & 43 deletions ModelOps/12_ModelOps_Model_Factory_REST_Python.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -86,27 +86,27 @@
"source": [
"<p style = 'font-size:18px;font-family:Arial;color:#00233C'><b>1.1 Libraries installation</b></p>\n",
"\n",
"<p style = 'font-size:16px;font-family:Arial;color:#00233C'><b>A restart of the Kernel is needed to confirm changes</b>. We use -q parameter for a non-verbose log of the installation command, you may remove this parameter if you want to know all the steps of the pip installation.</p>"
"<p style = 'font-size:16px;font-family:Arial;color:#00233C'>We use <b>%%capture</b> to supress the installation details of the installation command. You can remove this magic command if you want to know all the steps of the pip installation.</p>"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "f79b2e2f-a7d3-4cab-a447-8d61e4009b93",
"metadata": {},
"outputs": [],
"source": [
"#%pip install -q teradataml==17.20.0.6 teradatamodelops==7.0.3 matplotlib==3.8.2"
"%%capture\n",
"!pip install -q teradataml==20.0.0.2 teradatamodelops==7.0.6 matplotlib==3.8.2"
]
},
{
"cell_type": "markdown",
"id": "d5149df7-a95f-43cc-846c-ec7b47e8d8e3",
"id": "07ce8839-3cd5-45e9-af6f-6920010e34fa",
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-info\">\n",
"<p style = 'font-size:16px;font-family:Arial;color:#00233C'><b>Note: </b><i>The above statements may need to be uncommented if you run the notebooks on a platform other than ClearScape Analytics Experience that does not have the mentioned versions of the libraries installed. If you uncomment those installs, be sure to restart the kernel after executing those lines to bring the installed libraries into memory. The simplest way to restart the Kernel is by typing zero zero: <b> 0 0</b></i></p>\n",
"</div>"
"<p style = 'font-size:16px;font-family:Arial;color:#00233C'><b>A restart of the Kernel is needed to bring these libraries into the session</b>.</p>\n",
"<p style = 'font-size:16px;font-family:Arial;color:#00233C'><b>Hint:</b><i>An easy way to restart the kernel is to type zero zero (<b> 0 0 </b> and then press <b>Enter</b>). </i></p>"
]
},
{
Expand All @@ -120,7 +120,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "5dbc3d39-4f2b-4765-9d49-abc5c26b1a22",
"metadata": {
"tags": []
Expand All @@ -136,7 +136,7 @@
"from getpass import getpass\n",
"\n",
"logging.basicConfig(encoding=\"utf-8\", level=logging.INFO)\n",
"requests.packages.urllib3.disable_warnings()\n"
"requests.packages.urllib3.disable_warnings()"
]
},
{
Expand All @@ -162,32 +162,48 @@
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-warning\">\n",
"<p style = 'font-size:16px;font-family:Arial;color:#00233C'><b>Important Note: </b>Replace to use your ModelOps URL. You can copy the HOST address from the Connection details on your dashboard for the url</p>\n",
"<p style = 'font-size:16px;font-family:Arial;color:#00233C'><b>Important Note: </b>Use the HOST string for this environment. You can copy the name from the Connection details on your dashboard.</p>\n",
"</div>"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "90c06ba6-22b7-431a-9c48-89a38070123a",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Host NAME of the machine for ModelOps: dallas47-88vgt0b5i55ikpx7.env.ci.clearscape.teradata.com\n"
]
}
],
"source": [
"# Example modelops-apr24-ver20-63z6fpyuh8lhkz39.env.clearscape.teradata.com\n",
"hostname = input(\"Host NAME of the machine for ModelOps:\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "fc95baff-ccb9-4650-aa13-b15d919e6f78",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"https://web-dallas47-88vgt0b5i55ikpx7.env.ci.clearscape.teradata.com/modelops\n"
]
}
],
"source": [
"# base domain for ModelOps\n",
"url = \"https://\" + hostname + \"/modelops\"\n",
"url = \"https://\" + \"web-\"+ hostname + \"/modelops\"\n",
"print(url)"
]
},
Expand All @@ -209,33 +225,41 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "a65ffe4b-3be1-4ffb-815d-5c5abdf563c3",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter user's password: ········································\n"
]
}
],
"source": [
"# secret for account \"service-account-modelops-cli\"\n",
"#secret = \"\"\n",
"# or user's password\n",
"password = getpass(\"Enter user's password: \")\n",
"# project id\n",
"project = \"23e1df4b-b630-47a1-ab80-7ad5385fcd8d\"\n",
"project = \"70d4659b-92a2-4723-841a-9ba5629b5f27\"\n",
"# model id\n",
"model = \"f937b5d8-02c6-5150-80c7-1e4ff07fea31\"\n",
"model = \"55b3662b-302c-5b5b-b668-84929a5c6f99\"\n",
"# dataset connection id\n",
"dataset_connection = \"151abf05-1914-4d38-a90d-272d850f212c\"\n",
"# dataset training id\n",
"dataset_train = \"ba39e766-2fdf-426f-ba5c-4ca3e90955fc\"\n",
"dataset_train = \"2335c9ca-ce34-400d-820e-2a3cd7bb57bc\"\n",
"# dataset evaluation id\n",
"dataset_eval = \"74489d62-2af5-4402-b264-715e151a420a\"\n",
"dataset_eval = \"3f2792b1-fcb6-4b58-851e-2b79382861c9\"\n",
"# dataset template id, useful for batch deployment\n",
"dataset_template = \"d8a35d98-21ce-47d0-b9f2-00d355777de1\"\n",
"dataset_template = \"4053c309-2811-4f03-9fb4-e99c728ecdfb\"\n",
"# Docker image for training\n",
"training_image = \"artifacts.td.teradata.com/tdproduct-docker-snapshot/avmo/aoa-python-base:3.9.13-1\"\n",
"training_image = \"artifacts.td.teradata.com/tdproduct-docker-snapshot/avmo/vmo-python-base:3.9.4\"\n",
"# Docker image for deployment\n",
"deployment_image = \"artifacts.td.teradata.com/tdproduct-docker-snapshot/avmo/aoa-python-base:3.9.13-1\"\n",
"deployment_image = \"artifacts.td.teradata.com/tdproduct-docker-snapshot/avmo/vmo-python-base:3.9.4\"\n",
"# hyperparameters for training, set to empty dictionary if none\n",
"hyper_params = {\"eta\": 0.2, \"max_depth\": 6}\n",
"# performance settings\n",
Expand Down Expand Up @@ -270,7 +294,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "08cfb70b-2b86-49c8-8c40-44558ac4ba2f",
"metadata": {
"tags": []
Expand Down Expand Up @@ -302,7 +326,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "3ddb2589-b2e5-4a96-b8a4-3ce00f9d3ea2",
"metadata": {
"tags": []
Expand Down Expand Up @@ -344,12 +368,12 @@
"id": "1aa69d39-56e6-409c-b3c7-25a653a050a2",
"metadata": {},
"source": [
"<p style = 'font-size:18px;font-family:Arial;color:#00233C'><b>3.1 Get a token from Keycloak through the secret credential</b></p>"
"<p style = 'font-size:18px;font-family:Arial;color:#00233C'><b>3.1 Functions to get a token from Keycloak through the secret credential</b></p>"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"id": "5fe18031-abe9-4ed1-94f8-b92d9b761f3f",
"metadata": {
"tags": []
Expand Down Expand Up @@ -441,7 +465,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "3eb059a8-f2ac-4999-9046-920b74134bbf",
"metadata": {
"tags": []
Expand All @@ -450,7 +474,7 @@
"source": [
"def train(url, token, project, model, dataset_connection, dataset_train, train_memory, train_cpu, hyper_params, training_image):\n",
" headers = {\n",
" \"AOA-Project-ID\": project,\n",
" \"VMO-Project-ID\": project,\n",
" \"Authorization\": f\"Bearer {token}\",\n",
" \"Content-Type\": \"application/json\",\n",
" }\n",
Expand Down Expand Up @@ -510,7 +534,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"id": "ebedfc24-cb4b-467e-832a-1f6bf8d954ff",
"metadata": {
"tags": []
Expand All @@ -519,7 +543,7 @@
"source": [
"def evaluate(url, token, project, version_id, dataset_connection, dataset_eval, eval_memory, eval_cpu, hyper_params, deployment_image):\n",
" headers = {\n",
" \"AOA-Project-ID\": project,\n",
" \"VMO-PROJECT-ID\": project,\n",
" \"Authorization\": f\"Bearer {token}\",\n",
" \"Content-Type\": \"application/json\",\n",
" }\n",
Expand Down Expand Up @@ -575,7 +599,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"id": "4fa390bf-c3c4-48ec-b088-667addbf26d2",
"metadata": {
"tags": []
Expand All @@ -587,7 +611,7 @@
"\n",
" comment = b6(b\"Approved\").decode().strip()\n",
" headers = {\n",
" \"AOA-Project-ID\": project,\n",
" \"VMO-PROJECT-ID\": project,\n",
" \"Authorization\": f\"Bearer {token}\",\n",
" \"Content-Type\": \"application/json\",\n",
" }\n",
Expand Down Expand Up @@ -632,7 +656,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"id": "a7585e7b-88a1-42f9-aba5-e562a7857975",
"metadata": {
"tags": []
Expand Down Expand Up @@ -677,7 +701,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"id": "c295c4c0-94e6-491c-b8dd-ff0c7f39da16",
"metadata": {
"tags": []
Expand All @@ -686,7 +710,7 @@
"source": [
"def deploy(url, token, project, version_id, deploy_memory, deploy_cpu, dataset_connection, dataset_template, deployment_image):\n",
" headers = {\n",
" \"AOA-Project-ID\": project,\n",
" \"VMO-PROJECT-ID\": project,\n",
" \"Authorization\": f\"Bearer {token}\",\n",
" \"Content-Type\": \"application/json\",\n",
" }\n",
Expand Down Expand Up @@ -763,7 +787,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"id": "4b6d9aa2-d178-423b-ae67-5f58f5b59ff7",
"metadata": {
"tags": []
Expand All @@ -773,7 +797,7 @@
"def retire_others(url, token, project, model, version_id):\n",
" deployments = []\n",
" headers = {\n",
" \"AOA-Project-ID\": project,\n",
" \"VMO-PROJECT-ID\": project,\n",
" \"Authorization\": f\"Bearer {token}\",\n",
" \"Content-Type\": \"application/json\",\n",
" }\n",
Expand Down Expand Up @@ -837,7 +861,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"id": "5a27e50d-c136-411d-9b61-2c20ca71ef24",
"metadata": {
"tags": []
Expand All @@ -847,7 +871,7 @@
"def get_job_status(url, token, project, job_id):\n",
" status = \"RUNNING\"\n",
" headers = {\n",
" \"AOA-Project-ID\": project,\n",
" \"VMO-PROJECT-ID\": project,\n",
" \"Authorization\": f\"Bearer {token}\",\n",
" \"Content-Type\": \"application/json\",\n",
" }\n",
Expand Down Expand Up @@ -911,7 +935,10 @@
"id": "0c040a31-16be-4276-bc34-93cd8c193546",
"metadata": {},
"source": [
"[![image](images/launchModelOps.png)](/modelops)"
"<a href=\"/modelops\" style=\"display: inline-flex; align-items: center; justify-content: center; background-color: #017373; color: #FFFFFF; font-family: Arial, sans-serif; font-size: 16px; font-weight: bold; text-decoration: none; padding: 12px 24px; border: none; border-radius: 8px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); cursor: pointer; transition: all 0.3s ease;\">\n",
" LAUNCH MODELOPS\n",
" <img src=\"https://img.icons8.com/ios-filled/50/ffffff/external-link.png\" alt=\"External Link Icon\" style=\"margin-left: 8px; width: 20px; height: 20px;\">\n",
"</a>"
]
},
{
Expand All @@ -927,6 +954,7 @@
"execution_count": null,
"id": "f8ae5862-ae90-40fc-9e77-7d736ef7dfdd",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
Expand Down Expand Up @@ -983,7 +1011,7 @@
"outputs": [],
"source": [
"logging.info(\"Getting training status\")\n",
"version_id = get_job_status(url, token, project, train_job)\n"
"version_id = get_job_status(url, token, project, train_job)"
]
},
{
Expand Down

0 comments on commit 1c9fb8a

Please sign in to comment.