Skip to content

Instantly share code, notes, and snippets.

@robieta
Created March 17, 2024 23:56
Show Gist options
  • Save robieta/4c6e94f25a2ab87330bb6bd8026074a6 to your computer and use it in GitHub Desktop.
Save robieta/4c6e94f25a2ab87330bb6bd8026074a6 to your computer and use it in GitHub Desktop.
Untitled3.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"gpuType": "T4",
"authorship_tag": "ABX9TyOxMh6mZeREUgvzLyBlhHLD",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/robieta/4c6e94f25a2ab87330bb6bd8026074a6/untitled3.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "QnR_dwfNy8GS",
"outputId": "b8556a1c-b3f1-4946-f8b3-4ea6c10d3dae"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Sun Mar 17 23:51:02 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 55C P8 10W / 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"
]
}
],
"source": [
"!nvidia-smi"
]
},
{
"cell_type": "code",
"source": [
"import tensorflow as tf"
],
"metadata": {
"id": "vZgr5G3xzHbD"
},
"execution_count": 2,
"outputs": []
},
{
"cell_type": "code",
"source": [
"def test_fn():\n",
" with tf.device(\"cpu:0\"):\n",
" x = tf.ones((1,))\n",
"\n",
" print(x, x.device)\n",
"\n",
" with tf.device(\"gpu:0\"):\n",
" y = tf.ones((1,))\n",
" print(y, y.device)\n",
"\n",
" z = x + y\n",
" print(z, z.device)\n",
"\n",
"test_fn()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Uf-ivOPvzKVe",
"outputId": "080974fc-a775-43cc-e0b9-d1593b70b2c2"
},
"execution_count": 9,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"tf.Tensor([1.], shape=(1,), dtype=float32) /job:localhost/replica:0/task:0/device:CPU:0\n",
"tf.Tensor([1.], shape=(1,), dtype=float32) /job:localhost/replica:0/task:0/device:GPU:0\n",
"tf.Tensor([2.], shape=(1,), dtype=float32) /job:localhost/replica:0/task:0/device:GPU:0\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"with tf.profiler.experimental.Profile('logdir'):\n",
" test_fn()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "knKnDMrZzTcj",
"outputId": "aed488ab-c1ba-47ff-beb6-bdc84ed6fecc"
},
"execution_count": 10,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"tf.Tensor([1.], shape=(1,), dtype=float32) /job:localhost/replica:0/task:0/device:CPU:0\n",
"tf.Tensor([1.], shape=(1,), dtype=float32) /job:localhost/replica:0/task:0/device:GPU:0\n",
"tf.Tensor([2.], shape=(1,), dtype=float32) /job:localhost/replica:0/task:0/device:GPU:0\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"!pip install -U tensorboard-plugin-profile"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "HCcTP9SU0ErN",
"outputId": "6f63887a-ee7e-40a6-eb63-89bb2176878f"
},
"execution_count": 5,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Requirement already satisfied: tensorboard-plugin-profile in /usr/local/lib/python3.10/dist-packages (2.15.1)\n",
"Requirement already satisfied: gviz-api>=1.9.0 in /usr/local/lib/python3.10/dist-packages (from tensorboard-plugin-profile) (1.10.0)\n",
"Requirement already satisfied: protobuf<5.0.0dev,>=3.19.6 in /usr/local/lib/python3.10/dist-packages (from tensorboard-plugin-profile) (3.20.3)\n",
"Requirement already satisfied: setuptools>=41.0.0 in /usr/local/lib/python3.10/dist-packages (from tensorboard-plugin-profile) (67.7.2)\n",
"Requirement already satisfied: six>=1.10.0 in /usr/local/lib/python3.10/dist-packages (from tensorboard-plugin-profile) (1.16.0)\n",
"Requirement already satisfied: werkzeug>=0.11.15 in /usr/local/lib/python3.10/dist-packages (from tensorboard-plugin-profile) (3.0.1)\n",
"Requirement already satisfied: MarkupSafe>=2.1.1 in /usr/local/lib/python3.10/dist-packages (from werkzeug>=0.11.15->tensorboard-plugin-profile) (2.1.5)\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"%load_ext tensorboard"
],
"metadata": {
"id": "MgZKYPgD0H7U"
},
"execution_count": 6,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#%tensorboard --logdir logdir"
],
"metadata": {
"id": "GuV5a_2E0hhe"
},
"execution_count": 11,
"outputs": []
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "tWU9MKUJ0kii"
},
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment