Skip to content

Instantly share code, notes, and snippets.

@beaufortfrancois
Last active February 14, 2024 06:17
Show Gist options
  • Save beaufortfrancois/bd9752460d59a7d8ed54e444665c8ab9 to your computer and use it in GitHub Desktop.
Save beaufortfrancois/bd9752460d59a7d8ed54e444665c8ab9 to your computer and use it in GitHub Desktop.
Supercharge Web AI model testing: WebGPU, WebGL, and Headless Chrome
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"gpuType": "T4"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"source": [
"# Supercharge Web AI model testing: WebGPU, WebGL, and Headless Chrome\n",
"\n",
"[<img alt=\"Open in Colab\" src=\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='117' height='20'%3E%3ClinearGradient id='b' x2='0' y2='100%25'%3E%3Cstop offset='0' stop-color='%23bbb' stop-opacity='.1'/%3E%3Cstop offset='1' stop-opacity='.1'/%3E%3C/linearGradient%3E%3CclipPath id='a'%3E%3Crect width='117' height='20' fill='%23fff' rx='3'/%3E%3C/clipPath%3E%3Cg clip-path='url(%23a)'%3E%3Cpath fill='%23555' d='M0 0h30v20H0z'/%3E%3Cpath fill='%23007ec6' d='M30 0h87v20H30z'/%3E%3Cpath fill='url(%23b)' d='M0 0h117v20H0z'/%3E%3C/g%3E%3Cg fill='%23fff' font-family='DejaVu Sans,Verdana,Geneva,sans-serif' font-size='110' text-anchor='middle'%3E%3Csvg width='22' height='20' x='4' style='background-color:%23fff;border-radius:1px' viewBox='-2 0 28 24'%3E%3Cpath d='M1.977 16.77c-2.667-2.277-2.605-7.079 0-9.357.942.644 1.545 1.662 2.513 2.278-1.152 1.6-1.146 3.201-.004 4.803-.964.617-1.568 1.632-2.509 2.276z' style='fill:%23e8710a'/%3E%3Cpath d='M12.257 17.114c-1.767-1.633-2.485-3.658-2.118-6.02.451-2.91 2.139-4.893 4.946-5.678 2.565-.718 4.964-.217 6.878 1.819a17.975 17.975 0 0 0-2.434 2.446c-1.041-.854-2.21-1.246-3.529-.825-2.404.767-3.046 3.241-1.494 5.644-.241.275-.493.541-.721.826-.49.613-1.274.974-1.528 1.788z' style='fill:%23f9ab00'/%3E%3Cpath d='M19.529 9.682a17.975 17.975 0 0 1 2.434-2.446c2.703 2.783 2.701 7.031-.005 9.764-2.648 2.674-6.936 2.725-9.701.115.254-.814 1.038-1.175 1.528-1.788.228-.285.48-.552.721-.826 1.053.916 2.254 1.268 3.6.83 2.396-.78 3.045-3.404 1.423-5.649z' style='fill:%23e8710a'/%3E%3Cpath d='M4.49 9.691c-.968-.616-1.571-1.634-2.513-2.278 2.209-2.398 5.721-2.942 8.476-1.355.555.32.719.606.285 1.128-.157.188-.258.422-.391.631-.299.47-.509 1.067-.929 1.371-.485.351-.895-.341-1.397-.442-1.348-.271-2.512.041-3.531.945zM1.977 16.77c.941-.644 1.545-1.659 2.509-2.277 1.373 1.152 2.85 1.433 4.45.499.332-.194.503-.088.673.19.386.635.753 1.285 1.181 1.89.34.48.222.715-.253 1.006-2.697 1.652-6.332 1.11-8.56-1.308z' style='fill:%23f9ab00'/%3E%3C/svg%3E%3Ctext x='245' y='140' textLength='30' transform='scale(.1)'%3E%3C/text%3E%3Ctext x='725' y='150' fill='%23010101' fill-opacity='.3' textLength='770' transform='scale(.1)'%3EOpen in Colab%3C/text%3E%3Ctext x='725' y='140' textLength='770' transform='scale(.1)'%3EOpen in Colab%3C/text%3E%3C/g%3E%3C/svg%3E\">](https://colab.research.google.com/gist/beaufortfrancois/bd9752460d59a7d8ed54e444665c8ab9/webgpu-headless-chrome.ipynb)\n",
"\n",
"This notebook showcases how to consistently set up your testing environment for Web AI models. For comprehensive details, check out the accompanying [blog post](https://developer.chrome.com/blog/supercharge-web-ai-testing).\n",
"\n",
"# Requirements\n",
"\n",
"1. At the top right, click the **Connect** dropdown icon > select **Change runtime type**.\n",
"2. In the pop-up dialog, select **T4 GPU** as your hardware accelerator and click **Save**.\n",
"3. Click **Connect** and wait for the status to turn **green**. You'll see the word **T4** alongside **RAM** and **Disk** usage graphs.\n",
"4. Nice work! You've successfully created a Linux server with GPU attached!\n",
"5. Next, observe the scripts below and excute them step-by-step."
],
"metadata": {
"id": "Ksqxw0JzlefJ"
}
},
{
"cell_type": "code",
"source": [
"# Update GPU drivers\n",
"!apt install -qqq vulkan-tools libnvidia-gl-525\n",
"\n",
"# Verify that the NVIDIA drivers recognize the T4 GPU and Vulkan is functioning properly.\n",
"!nvidia-smi\n",
"!vulkaninfo --summary"
],
"metadata": {
"id": "J9TjRr3VjlBi",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "49ad8d91-ebb7-4983-cbeb-abb95c42147a"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Selecting previously unselected package libnvidia-common-525.\n",
"(Reading database ... 121654 files and directories currently installed.)\n",
"Preparing to unpack .../libnvidia-common-525_525.147.05-0ubuntu1_all.deb ...\n",
"Unpacking libnvidia-common-525 (525.147.05-0ubuntu1) ...\n",
"Selecting previously unselected package libnvidia-gl-525:amd64.\n",
"Preparing to unpack .../libnvidia-gl-525_525.147.05-0ubuntu1_amd64.deb ...\n",
"\u001b[1mdpkg-query:\u001b[0m no packages found matching libnvidia-gl-450\n",
"Unpacking libnvidia-gl-525:amd64 (525.147.05-0ubuntu1) ...\n",
"Selecting previously unselected package libvulkan1:amd64.\n",
"Preparing to unpack .../libvulkan1_1.3.204.1-2_amd64.deb ...\n",
"Unpacking libvulkan1:amd64 (1.3.204.1-2) ...\n",
"Selecting previously unselected package mesa-vulkan-drivers:amd64.\n",
"Preparing to unpack .../mesa-vulkan-drivers_23.0.4-0ubuntu1~22.04.1_amd64.deb ...\n",
"Unpacking mesa-vulkan-drivers:amd64 (23.0.4-0ubuntu1~22.04.1) ...\n",
"Selecting previously unselected package vulkan-tools.\n",
"Preparing to unpack .../vulkan-tools_1.3.204.0+dfsg1-1_amd64.deb ...\n",
"Unpacking vulkan-tools (1.3.204.0+dfsg1-1) ...\n",
"Setting up libvulkan1:amd64 (1.3.204.1-2) ...\n",
"Setting up libnvidia-common-525 (525.147.05-0ubuntu1) ...\n",
"Setting up mesa-vulkan-drivers:amd64 (23.0.4-0ubuntu1~22.04.1) ...\n",
"Setting up libnvidia-gl-525:amd64 (525.147.05-0ubuntu1) ...\n",
"Setting up vulkan-tools (1.3.204.0+dfsg1-1) ...\n",
"Processing triggers for libc-bin (2.35-0ubuntu3.4) ...\n",
"/sbin/ldconfig.real: /usr/local/lib/libtbbbind_2_0.so.3 is not a symbolic link\n",
"\n",
"/sbin/ldconfig.real: /usr/local/lib/libtbbbind.so.3 is not a symbolic link\n",
"\n",
"/sbin/ldconfig.real: /usr/local/lib/libtbbbind_2_5.so.3 is not a symbolic link\n",
"\n",
"/sbin/ldconfig.real: /usr/local/lib/libtbb.so.12 is not a symbolic link\n",
"\n",
"/sbin/ldconfig.real: /usr/local/lib/libtbbmalloc_proxy.so.2 is not a symbolic link\n",
"\n",
"/sbin/ldconfig.real: /usr/local/lib/libtbbmalloc.so.2 is not a symbolic link\n",
"\n",
"Processing triggers for man-db (2.10.2-1) ...\n",
"Sat Jan 6 07:50:43 2024 \n",
"+---------------------------------------------------------------------------------------+\n",
"| NVIDIA-SMI 535.104.05 Driver Version: 535.104.05 CUDA Version: 12.2 |\n",
"|-----------------------------------------+----------------------+----------------------+\n",
"| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |\n",
"| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |\n",
"| | | MIG M. |\n",
"|=========================================+======================+======================|\n",
"| 0 Tesla T4 Off | 00000000:00:04.0 Off | 0 |\n",
"| N/A 40C P8 9W / 70W | 0MiB / 15360MiB | 0% Default |\n",
"| | | N/A |\n",
"+-----------------------------------------+----------------------+----------------------+\n",
" \n",
"+---------------------------------------------------------------------------------------+\n",
"| Processes: |\n",
"| GPU GI CI PID Type Process name GPU Memory |\n",
"| ID ID Usage |\n",
"|=======================================================================================|\n",
"| No running processes found |\n",
"+---------------------------------------------------------------------------------------+\n",
"'DISPLAY' environment variable not set... skipping surface info\n",
"error: XDG_RUNTIME_DIR not set in the environment.\n",
"error: XDG_RUNTIME_DIR not set in the environment.\n",
"error: XDG_RUNTIME_DIR not set in the environment.\n",
"error: XDG_RUNTIME_DIR not set in the environment.\n",
"error: XDG_RUNTIME_DIR not set in the environment.\n",
"==========\n",
"VULKANINFO\n",
"==========\n",
"\n",
"Vulkan Instance Version: 1.3.204\n",
"\n",
"\n",
"Instance Extensions: count = 20\n",
"-------------------------------\n",
"VK_EXT_acquire_drm_display : extension revision 1\n",
"VK_EXT_acquire_xlib_display : extension revision 1\n",
"VK_EXT_debug_report : extension revision 10\n",
"VK_EXT_debug_utils : extension revision 2\n",
"VK_EXT_direct_mode_display : extension revision 1\n",
"VK_EXT_display_surface_counter : extension revision 1\n",
"VK_EXT_swapchain_colorspace : extension revision 4\n",
"VK_KHR_device_group_creation : extension revision 1\n",
"VK_KHR_display : extension revision 23\n",
"VK_KHR_external_fence_capabilities : extension revision 1\n",
"VK_KHR_external_memory_capabilities : extension revision 1\n",
"VK_KHR_external_semaphore_capabilities : extension revision 1\n",
"VK_KHR_get_display_properties2 : extension revision 1\n",
"VK_KHR_get_physical_device_properties2 : extension revision 2\n",
"VK_KHR_get_surface_capabilities2 : extension revision 1\n",
"VK_KHR_surface : extension revision 25\n",
"VK_KHR_surface_protected_capabilities : extension revision 1\n",
"VK_KHR_wayland_surface : extension revision 6\n",
"VK_KHR_xcb_surface : extension revision 6\n",
"VK_KHR_xlib_surface : extension revision 6\n",
"\n",
"Instance Layers: count = 3\n",
"--------------------------\n",
"VK_LAYER_INTEL_nullhw INTEL NULL HW 1.1.73 version 1\n",
"VK_LAYER_MESA_device_select Linux device selection layer 1.3.211 version 1\n",
"VK_LAYER_MESA_overlay Mesa Overlay layer 1.3.211 version 1\n",
"\n",
"Devices:\n",
"========\n",
"GPU0:\n",
"\tapiVersion = 4206834 (1.3.242)\n",
"\tdriverVersion = 2245656896 (0x85da0140)\n",
"\tvendorID = 0x10de\n",
"\tdeviceID = 0x1eb8\n",
"\tdeviceType = PHYSICAL_DEVICE_TYPE_DISCRETE_GPU\n",
"\tdeviceName = Tesla T4\n",
"\tdriverID = DRIVER_ID_NVIDIA_PROPRIETARY\n",
"\tdriverName = NVIDIA\n",
"\tdriverInfo = 535.104.05\n",
"\tconformanceVersion = 1.3.5.0\n",
"\tdeviceUUID = b67e87bf-df70-2ff6-929d-b37d53163182\n",
"\tdriverUUID = 0415fb4e-e904-5af7-8fad-a705dd68f35e\n",
"GPU1:\n",
"\tapiVersion = 4206830 (1.3.238)\n",
"\tdriverVersion = 1 (0x0001)\n",
"\tvendorID = 0x10005\n",
"\tdeviceID = 0x0000\n",
"\tdeviceType = PHYSICAL_DEVICE_TYPE_CPU\n",
"\tdeviceName = llvmpipe (LLVM 15.0.7, 256 bits)\n",
"\tdriverID = DRIVER_ID_MESA_LLVMPIPE\n",
"\tdriverName = llvmpipe\n",
"\tdriverInfo = Mesa 23.0.4-0ubuntu1~22.04.1 (LLVM 15.0.7)\n",
"\tconformanceVersion = 1.3.1.1\n",
"\tdeviceUUID = 6d657361-3233-2e30-2e34-2d3075627500\n",
"\tdriverUUID = 6c6c766d-7069-7065-5555-494400000000\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"Then you can pick betweeen Puppeteer, Chrome Browser, or Chrome Launcher (requires Chrome Browser install)."
],
"metadata": {
"id": "ZfRXX8OXjTFS"
}
},
{
"cell_type": "markdown",
"source": [
"# Puppeteer"
],
"metadata": {
"id": "vm1r1M0KiTIT"
}
},
{
"cell_type": "code",
"source": [
"# Install the latest Node.js\n",
"!npm install -g n\n",
"!n lts\n",
"\n",
"# Install Puppeteer\n",
"!npm install puppeteer"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "i7r9DeO2aGXs",
"outputId": "0eaaad82-302e-4f0d-e41f-eef04c44e23c"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"\u001b[K\u001b[?25h/tools/node/bin/n -> /tools/node/lib/node_modules/n/bin/n\n",
"+ n@9.2.0\n",
"added 1 package from 2 contributors in 0.452s\n",
" \u001b[36minstalling\u001b[0m : \u001b[2mnode-v20.10.0\u001b[0m\n",
" \u001b[36m mkdir\u001b[0m : \u001b[2m/usr/local/n/versions/node/20.10.0\u001b[0m\n",
" \u001b[36m fetch\u001b[0m : \u001b[2mhttps://nodejs.org/dist/v20.10.0/node-v20.10.0-linux-x64.tar.xz\u001b[0m\n",
"############################################################################################# 100.0%\n",
"\u001b[1A\u001b[2K \u001b[36m copying\u001b[0m : \u001b[2mnode/20.10.0\u001b[0m\n",
" \u001b[36m installed\u001b[0m : \u001b[2mv20.10.0 (with npm 10.2.3)\u001b[0m\n",
"\n",
"Note: the node command changed location and the old location may be remembered in your current shell.\n",
" \u001b[36m old\u001b[0m : \u001b[2m/tools/node/bin/node\u001b[0m\n",
" \u001b[36m new\u001b[0m : \u001b[2m/usr/local/bin/node\u001b[0m\n",
"If \"node --version\" shows the old version then start a new shell, or reset the location hash with:\n",
"hash -r (for bash, zsh, ash, dash, and ksh)\n",
"rehash (for csh and tcsh)\n",
"\u001b[K\u001b[?25h\n",
"added 111 packages in 22s\n",
"\n",
"9 packages are looking for funding\n",
" run `npm fund` for details\n",
"\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[36;40mnotice\u001b[0m\u001b[35m\u001b[0m \n",
"\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[36;40mnotice\u001b[0m\u001b[35m\u001b[0m New \u001b[32mpatch\u001b[39m version of npm available! \u001b[31m10.2.3\u001b[39m -> \u001b[32m10.2.5\u001b[39m\n",
"\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[36;40mnotice\u001b[0m\u001b[35m\u001b[0m Changelog: \u001b[36mhttps://github.com/npm/cli/releases/tag/v10.2.5\u001b[39m\n",
"\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[36;40mnotice\u001b[0m\u001b[35m\u001b[0m Run \u001b[32mnpm install -g npm@10.2.5\u001b[39m to update!\n",
"\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[36;40mnotice\u001b[0m\u001b[35m\u001b[0m \n",
"\u001b[0m"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Console log the WebGPU status\n",
"# Take a screenshot of chrome://gpu\n",
"from IPython.display import Javascript\n",
"\n",
"js = Javascript('''\n",
" import puppeteer from 'puppeteer';\n",
"\n",
" const browser = await puppeteer.launch({\n",
" headless: 'new',\n",
" args: [\n",
" '--no-sandbox',\n",
" '--headless=new',\n",
" '--use-angle=vulkan',\n",
" '--enable-features=Vulkan',\n",
" '--disable-vulkan-surface',\n",
" '--enable-unsafe-webgpu',\n",
" ],\n",
" });\n",
" console.log(await browser.version());\n",
"\n",
" const page = await browser.newPage();\n",
" await page.goto('chrome://gpu');\n",
"\n",
" const txt = await page.waitForSelector('text/WebGPU');\n",
" const status = await txt.evaluate(g => g.parentElement.textContent);\n",
" console.log(status);\n",
"\n",
" await page.screenshot({ path: '/content/puppeteer-page.png' });\n",
" await browser.close();\n",
" ''').data\n",
"\n",
"!node --input-type=module -e \"$js\""
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "EN1CYabBn9E-",
"outputId": "a7060c3e-c985-4a09-aeaf-995269528cc9"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Chrome/119.0.6045.105\n",
"* WebGPU: Hardware accelerated but at reduced performance\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Take a screenshot of a webpage\n",
"from IPython.display import Javascript\n",
"\n",
"js = Javascript('''\n",
" import puppeteer from 'puppeteer';\n",
"\n",
" const browser = await puppeteer.launch({\n",
" headless: 'new',\n",
" args: [\n",
" '--no-sandbox',\n",
" '--headless=new',\n",
" '--use-angle=vulkan',\n",
" '--enable-features=Vulkan',\n",
" '--disable-vulkan-surface',\n",
" '--enable-unsafe-webgpu',\n",
" ],\n",
" });\n",
" console.log(await browser.version());\n",
"\n",
" const page = await browser.newPage();\n",
" await page.goto('https://storage.googleapis.com/jmstore/kaggleweb/grader/index.html#webgpu|https://storage.googleapis.com/jmstore/TensorFlowJS/EdX/SavedModels/sqftToPropertyPrice/model.json|1');\n",
"\n",
" page.on('console', async (message) => {\n",
" console.log(message.text());\n",
" if (message.text() === 'captureAndEnd') {\n",
" await page.screenshot({ path: '/content/puppeteer-tf.png' });\n",
" await browser.close();\n",
" }\n",
" });\n",
" ''').data\n",
"\n",
"!node --input-type=module -e \"$js\""
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Ucrbcz5rYpAH",
"outputId": "45aa4d72-2ecb-4b9e-8674-6023129b6a82"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Chrome/119.0.6045.105\n",
"Backend: webgpu\n",
"Loaded TensorFlow.js - version: 4.15.0\n",
"Web AI Model loaded successfully!\n",
"Model warmed up\n",
"Backend: webgpu\n",
"1.599999999976717ms\n",
"The performance of synchronously reading data from GPU to CPU is poor on the webgpu backend, please use asynchronous APIs instead.\n",
"Tensor\n",
" [[0.7799996 ],\n",
" [997.2028198]]\n",
"\n",
"totalJSHeapSize: 12034371\n",
"usedJSHeapSize: 9845755\n",
"maxJSHeapSizeLimit: 2172649472\n",
"Testing completed\n",
"JSHandle@object\n",
"data of result tensor 'c': -0.04485602676868439,0.007791661191731691,0.06810081750154495,0.02999374084174633,-0.1264096349477768,0.14021874964237213,-0.055284902453422546,-0.04938381537795067,0.08432205021381378,-0.05454041436314583\n",
"captureAndEnd\n",
"[.WebGL-0x209401d82300]GL Driver Message (OpenGL, Performance, GL_CLOSE_PATH_NV, High): GPU stall due to ReadPixels\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"# Chrome Browser"
],
"metadata": {
"id": "3YDmZ5a-iw26"
}
},
{
"cell_type": "code",
"source": [
"# Install Google Chrome\n",
"!curl -fSsL https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmor | sudo tee /usr/share/keyrings/google-chrome.gpg >> /dev/null\n",
"!echo deb [arch=amd64 signed-by=/usr/share/keyrings/google-chrome.gpg] http://dl.google.com/linux/chrome/deb/ stable main | sudo tee /etc/apt/sources.list.d/google-chrome.list\n",
"!apt update\n",
"!apt install -qq google-chrome-stable\n",
"\n",
"# Start D-Bus to avoid Chrome warnings later\n",
"# D-Bus is a middleware for inter-process communication\n",
"!/etc/init.d/dbus start\n",
"%env DBUS_SESSION_BUS_ADDRESS=unix:path=/var/run/dbus/system_bus_socket"
],
"metadata": {
"id": "LGXD7lGYflVM",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "b42e00d0-228e-4df8-8ae7-f910008a6b18"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"deb [arch=amd64 signed-by=/usr/share/keyrings/google-chrome.gpg] http://dl.google.com/linux/chrome/deb/ stable main\n",
"Hit:1 http://dl.google.com/linux/chrome/deb stable InRelease\n",
"Hit:2 https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/ InRelease\n",
"Hit:3 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64 InRelease\n",
"Hit:4 http://archive.ubuntu.com/ubuntu jammy InRelease\n",
"Hit:5 http://security.ubuntu.com/ubuntu jammy-security InRelease\n",
"Hit:6 http://archive.ubuntu.com/ubuntu jammy-updates InRelease\n",
"Hit:7 http://archive.ubuntu.com/ubuntu jammy-backports InRelease\n",
"Hit:8 https://ppa.launchpadcontent.net/c2d4u.team/c2d4u4.0+/ubuntu jammy InRelease\n",
"Hit:9 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy InRelease\n",
"Hit:10 https://ppa.launchpadcontent.net/graphics-drivers/ppa/ubuntu jammy InRelease\n",
"Hit:11 https://ppa.launchpadcontent.net/ubuntugis/ppa/ubuntu jammy InRelease\n",
"Reading package lists... Done\n",
"Building dependency tree... Done\n",
"Reading state information... Done\n",
"23 packages can be upgraded. Run 'apt list --upgradable' to see them.\n",
"google-chrome-stable is already the newest version (120.0.6099.199-1).\n",
"0 upgraded, 0 newly installed, 0 to remove and 23 not upgraded.\n",
" * system message bus already started; not starting.\n",
"env: DBUS_SESSION_BUS_ADDRESS=unix:path=/var/run/dbus/system_bus_socket\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"!google-chrome-stable \\\n",
"--no-sandbox \\\n",
"--headless=new \\\n",
"--use-angle=vulkan \\\n",
"--enable-features=Vulkan \\\n",
"--disable-vulkan-surface \\\n",
"--enable-unsafe-webgpu \\\n",
"--enable-webgpu-developer-features \\\n",
"--enable-logging=stderr \\\n",
"--user-data-dir=/tmp/ \\\n",
"--virtual-time-budget=2000 \\\n",
"--screenshot=/content/webgpureport.png https://webgpureport.org"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Rov7CSBwbSev",
"outputId": "ed58d482-27af-401a-85a4-6f32b7579f00"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"[5023:5023:0105/111320.928415:WARNING:chrome_main_delegate.cc(667)] This is Chrome version 120.0.6099.199 (not a warning)\n",
"[5023:5023:0105/111321.039219:INFO:policy_logger.cc(144)] :components/enterprise/browser/controller/chrome_browser_cloud_management_controller.cc(168) Starting CBCM Controller Initialization\n",
"[5023:5023:0105/111321.039262:INFO:policy_logger.cc(144)] :components/enterprise/browser/controller/chrome_browser_cloud_management_controller.cc(196) No machine level policy manager exists.\n",
"[5023:5042:0105/111321.146413:WARNING:external_pref_loader.cc(294)] You are using an old-style extension deployment method (external_extensions.json), which will soon be deprecated. (see http://developer.chrome.com/extensions/external_extensions.html)\n",
"[5023:5023:0105/111321.207058:WARNING:bluez_dbus_manager.cc(248)] Floss manager not present, cannot set Floss enable/disable.\n",
"[5023:5076:0105/111321.238531:ERROR:object_proxy.cc(577)] Failed to call method: org.freedesktop.DBus.Properties.Get: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files\n",
"[5023:5076:0105/111321.238547:WARNING:property.cc(144)] DaemonVersion: GetAndBlock: failed.\n",
"[5023:5076:0105/111321.238746:ERROR:object_proxy.cc(577)] Failed to call method: org.freedesktop.UPower.GetDisplayDevice: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files\n",
"[5023:5076:0105/111321.238928:ERROR:object_proxy.cc(577)] Failed to call method: org.freedesktop.UPower.EnumerateDevices: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files\n",
"[5058:5058:0105/111321.665358:WARNING:sandbox_linux.cc(400)] InitializeSandbox() called with multiple threads in process gpu-process.\n",
"Warning: loader_parse_icd_manifest: Can not find 'ICD' object in ICD JSON file /usr/share/vulkan/icd.d/nvidia_layers.json. Skipping ICD JSON\n",
"error: XDG_RUNTIME_DIR not set in the environment.\n",
"error: XDG_RUNTIME_DIR not set in the environment.\n",
"Warning: loader_parse_icd_manifest: Can not find 'ICD' object in ICD JSON file /usr/share/vulkan/icd.d/nvidia_layers.json. Skipping ICD JSON\n",
"error: XDG_RUNTIME_DIR not set in the environment.\n",
"error: XDG_RUNTIME_DIR not set in the environment.\n",
"14010 bytes written to file /content/webgpureport.png\n",
"[5023:5023:0105/111322.260452:WARNING:pref_notifier_impl.cc(41)] Pref observer for media_router.cast_allow_all_ips found at shutdown.\n",
"[0105/111322.310932:ERROR:nacl_helper_linux.cc(354)] NaCl helper process running without a sandbox!\n",
"Most likely you need to configure your SUID sandbox correctly\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"# Chrome Launcher"
],
"metadata": {
"id": "xHXt3zG2idQQ"
}
},
{
"cell_type": "code",
"source": [
"# Install Chrome launcher\n",
"!npm install chrome-launcher chrome-remote-interface"
],
"metadata": {
"id": "f4aviFWC2NO3",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "b3a9639f-eb26-495c-808d-6e638344578c"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"\u001b[K\u001b[?25h\n",
"added 11 packages, and audited 123 packages in 838ms\n",
"\n",
"11 packages are looking for funding\n",
" run `npm fund` for details\n",
"\n",
"found \u001b[32m\u001b[1m0\u001b[22m\u001b[39m vulnerabilities\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Take a screenshot of chrome://gpu\n",
"from IPython.display import Javascript\n",
"\n",
"js = Javascript('''\n",
" import * as chromeLauncher from 'chrome-launcher';\n",
" import CDP from 'chrome-remote-interface';\n",
" import * as fs from 'fs';\n",
"\n",
" const chrome = await chromeLauncher.launch({\n",
" chromeFlags: [\n",
" '--no-sandbox',\n",
" '--headless=new',\n",
" '--use-angle=vulkan',\n",
" '--enable-features=Vulkan',\n",
" '--disable-vulkan-surface',\n",
" '--enable-unsafe-webgpu',\n",
" ],\n",
" });\n",
"\n",
" const protocol = await CDP({ port: chrome.port });\n",
"\n",
" const { Browser, Page, Runtime } = protocol;\n",
" console.log((await Browser.getVersion()).product);\n",
"\n",
" await Promise.all([ Page.enable(), Runtime.enable() ]);\n",
"\n",
" await Page.navigate({ url: 'chrome://gpu' });\n",
"\n",
" Page.loadEventFired(async () => {\n",
" const { data } = await Page.captureScreenshot();\n",
" fs.writeFileSync('/content/launcher-page.png', Buffer.from(data, 'base64'));\n",
" protocol.close();\n",
" chrome.kill();\n",
" });\n",
" ''').data\n",
"\n",
"!node --input-type=module -e \"$js\""
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "wEuooX7rlXTo",
"outputId": "80990cea-4ded-484f-fd71-b9c532b1d842"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Chrome/120.0.6099.199\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Take a screenshot of a webpage\n",
"from IPython.display import Javascript\n",
"\n",
"js = Javascript('''\n",
" import * as chromeLauncher from 'chrome-launcher';\n",
" import CDP from 'chrome-remote-interface';\n",
" import * as fs from 'fs';\n",
"\n",
" const chrome = await chromeLauncher.launch({\n",
" chromeFlags: [\n",
" '--no-sandbox',\n",
" '--headless=new',\n",
" '--use-angle=vulkan',\n",
" '--enable-features=Vulkan',\n",
" '--disable-vulkan-surface',\n",
" '--enable-unsafe-webgpu',\n",
" ],\n",
" });\n",
"\n",
" const protocol = await CDP({ port: chrome.port });\n",
"\n",
" const { Browser, DOM, Network, Page, Emulation, Runtime, Console } = protocol;\n",
" console.log((await Browser.getVersion()).product);\n",
"\n",
" await Promise.all([\n",
" Network.enable(),\n",
" Page.enable(),\n",
" Runtime.enable(),\n",
" DOM.enable(),\n",
" Console.enable(),\n",
" ]);\n",
"\n",
" Console.messageAdded(async ({ message }) => {\n",
" console.log(message.text);\n",
" if (message.text === 'captureAndEnd') {\n",
" const { data } = await Page.captureScreenshot();\n",
" fs.writeFileSync('/content/launcher-tf.png', Buffer.from(data, 'base64'));\n",
" protocol.close();\n",
" chrome.kill();\n",
" }\n",
" });\n",
"\n",
" await Page.navigate({ url: 'https://storage.googleapis.com/jmstore/kaggleweb/grader/index.html#webgpu|https://storage.googleapis.com/jmstore/TensorFlowJS/EdX/SavedModels/sqftToPropertyPrice/model.json|1' });\n",
" ''').data\n",
"\n",
"!node --input-type=module -e \"$js\""
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "-0ZbkmSiUGuN",
"outputId": "d4544940-bb44-4047-a1eb-61ef7c158f21"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Chrome/120.0.6099.199\n",
"Backend: webgpu\n",
"Loaded TensorFlow.js - version: 4.15.0\n",
"Web AI Model loaded successfully!\n",
"Model warmed up\n",
"Backend: webgpu\n",
"1.5ms\n",
"The performance of synchronously reading data from GPU to CPU is poor on the webgpu backend, please use asynchronous APIs instead.\n",
"Tensor\n",
" [[0.7799996 ],\n",
" [997.2028198]]\n",
"undefined\n",
"totalJSHeapSize: 11683484\n",
"usedJSHeapSize: 9349992\n",
"maxJSHeapSizeLimit: 2172649472\n",
"Testing completed\n",
"[object Object]\n",
"data of result tensor 'c': -0.04485602676868439,0.007791661191731691,0.06810081750154495,0.02999374084174633,-0.1264096349477768,0.14021874964237213,-0.055284902453422546,-0.04938381537795067,0.08432205021381378,-0.05454041436314583\n",
"captureAndEnd\n"
]
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment