diff --git a/notebooks/Experimental/k8s.ipynb b/notebooks/Experimental/k8s.ipynb new file mode 100644 index 00000000000..d1fed0ff526 --- /dev/null +++ b/notebooks/Experimental/k8s.ipynb @@ -0,0 +1,377 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "e7da7ef7-09f2-431e-82f7-4e28d50488fa", + "metadata": {}, + "outputs": [], + "source": [ + "SYFT_VERSION = \">=0.8.2.b0,<0.9\"\n", + "package_string = f'\"syft{SYFT_VERSION}\"'\n", + "# %pip install {package_string} -q" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "74f04dcf-5fd9-4526-990e-91ffbc0df8c6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "✅ The installed version of syft==0.8.5b1 matches the requirement >=0.8.2b0 and the requirement <0.9\n" + ] + } + ], + "source": [ + "# syft absolute\n", + "import syft as sy\n", + "\n", + "sy.requires(SYFT_VERSION)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "fac2594c-b5e2-40ae-89c0-83c687225103", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Logged into as \n" + ] + }, + { + "data": { + "text/html": [ + "
SyftWarning: You are using a default password. Please change the password using `[your_client].me.set_password([new_password])`.

" + ], + "text/plain": [ + "SyftWarning: You are using a default password. Please change the password using `[your_client].me.set_password([new_password])`." + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "domain_client = sy.login(\n", + " url=\"http://localhost:8080\", email=\"info@openmined.org\", password=\"changethis\"\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "b0cc9c68-5314-4646-a985-f6a8593287eb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + "
\n", + " \"Logo\"\n",\n", + "

Welcome to mynode

\n", + "
\n", + " URL: http://localhost:8080
Node Type: Domain
Node Side Type: High Side
Syft Version: 0.8.5-beta.1
\n", + "
\n", + "
\n", + " ⓘ \n", + " This domain is run by the library PySyft to learn more about how it works visit\n", + " github.com/OpenMined/PySyft.\n", + "
\n", + "

Commands to Get Started

\n", + " \n", + "
    \n", + " \n", + "
  • <your_client>.projects - list projects
  • \n", + "
  • <your_client>.requests - list requests
  • \n", + "
  • <your_client>.users - list users
  • \n", + "
  • \n", + " <your_client>.requests.submit? - display function signature\n", + "
  • \n", + "
\n", + " \n", + "

\n", + " " + ], + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "domain_client" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "42455389-19e5-4815-a62b-867d2aaa952b", + "metadata": {}, + "outputs": [], + "source": [ + "@sy.api_endpoint(path=\"gemma.inference\")\n", + "def run_vertex(\n", + " context,\n", + " prompt: str,\n", + " max_tokens: int,\n", + " temperature: float,\n", + " top_p: float,\n", + " top_k: int,\n", + " raw_response: bool,\n", + ") -> str:\n", + " # import subprocess\n", + " # import sys\n", + " # subprocess.check_call([sys.executable, \"-m\", \"pip\", \"install\", \"-q\", \"google-cloud-aiplatform\"])\n", + "\n", + " # third party\n", + " from google.cloud import aiplatform\n", + " from google.oauth2 import service_account\n", + "\n", + " SERVICE_ACCOUNT = {}\n", + " credentials = service_account.Credentials.from_service_account_info(SERVICE_ACCOUNT)\n", + "\n", + " PROJECT_ID = \"project-enigma-415021\"\n", + " REGION = \"us-west1\"\n", + " ENDPOINT_ID = \"3213239169291649024\"\n", + " aip_endpoint_name = (\n", + " f\"projects/{PROJECT_ID}/locations/{REGION}/endpoints/{ENDPOINT_ID}\"\n", + " )\n", + " endpoint_vllm = aiplatform.Endpoint(aip_endpoint_name, credentials=credentials)\n", + " default_kwargs = {\n", + " \"prompt\": prompt,\n", + " \"max_tokens\": max_tokens,\n", + " \"temperature\": temperature,\n", + " \"top_p\": top_p,\n", + " \"top_k\": top_k,\n", + " \"raw_response\": raw_response,\n", + " }\n", + " instances = [\n", + " default_kwargs,\n", + " ]\n", + " response = endpoint_vllm.predict(instances=instances)\n", + " prediction = response.predictions[0]\n", + " return prediction" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "aa044bde-265b-4c28-b626-8f8ddf8c216a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
SyftSuccess: CustomAPIEndpoint added: syft.service.api.api.CustomAPIEndpoint

" + ], + "text/plain": [ + "SyftSuccess: CustomAPIEndpoint added: syft.service.api.api.CustomAPIEndpoint" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response = domain_client.api.services.api.set(endpoint=run_vertex)\n", + "response" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "10679327-d006-4140-b941-c93879a8ac87", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Logged into as GUEST\n" + ] + } + ], + "source": [ + "domain_guest = sy.login_as_guest(url=\"http://localhost:8080\")" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "172b496b-9dd7-42fa-943a-691a89c5ca86", + "metadata": {}, + "outputs": [], + "source": [ + "params = {\n", + " \"prompt\": \"What is PySyft from OpenMined?\",\n", + " \"max_tokens\": 50,\n", + " \"temperature\": 1.0,\n", + " \"top_p\": 1.0,\n", + " \"top_k\": 10,\n", + " \"raw_response\": False,\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "b5b03512-8bf9-4c76-b557-b0b2d8095bd6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Prompt:\n", + "What is PySyft from OpenMined?\n", + "Output:\n", + "PySyft is OpenMined’s Python implementation of TensorFlow. It provides an interface which is similar to that of TensorFlow with the addition of a set of Python utilities to work directly with tensors, such as PySyft. These utilities can\n" + ] + } + ], + "source": [ + "prediction = domain_guest.api.services.gemma.inference(**params)\n", + "print(prediction)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ed4b7199-9a2d-46e8-839e-df4c6f99f1df", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.6" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}