|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "metadata": { |
| 5 | + "ExecuteTime": { |
| 6 | + "end_time": "2026-02-24T17:53:25.651209170Z", |
| 7 | + "start_time": "2026-02-24T17:53:21.331584938Z" |
| 8 | + } |
| 9 | + }, |
| 10 | + "cell_type": "code", |
| 11 | + "source": [ |
| 12 | + "import torch\n", |
| 13 | + "print(torch.version.cuda)" |
| 14 | + ], |
| 15 | + "id": "8effc7e6f58c9b21", |
| 16 | + "outputs": [ |
| 17 | + { |
| 18 | + "name": "stdout", |
| 19 | + "output_type": "stream", |
| 20 | + "text": [ |
| 21 | + "12.1\n" |
| 22 | + ] |
| 23 | + } |
| 24 | + ], |
| 25 | + "execution_count": 1 |
| 26 | + }, |
| 27 | + { |
| 28 | + "metadata": { |
| 29 | + "ExecuteTime": { |
| 30 | + "end_time": "2026-02-24T17:53:27.457104418Z", |
| 31 | + "start_time": "2026-02-24T17:53:27.375831476Z" |
| 32 | + } |
| 33 | + }, |
| 34 | + "cell_type": "code", |
| 35 | + "source": [ |
| 36 | + "x = torch.rand(3,3)\n", |
| 37 | + "x" |
| 38 | + ], |
| 39 | + "id": "7724c24d65443f73", |
| 40 | + "outputs": [ |
| 41 | + { |
| 42 | + "data": { |
| 43 | + "text/plain": [ |
| 44 | + "tensor([[0.2387, 0.0177, 0.6430],\n", |
| 45 | + " [0.9004, 0.2064, 0.3525],\n", |
| 46 | + " [0.9998, 0.0965, 0.6391]])" |
| 47 | + ] |
| 48 | + }, |
| 49 | + "execution_count": 2, |
| 50 | + "metadata": {}, |
| 51 | + "output_type": "execute_result" |
| 52 | + } |
| 53 | + ], |
| 54 | + "execution_count": 2 |
| 55 | + }, |
| 56 | + { |
| 57 | + "metadata": { |
| 58 | + "ExecuteTime": { |
| 59 | + "end_time": "2026-02-24T17:53:33.290072334Z", |
| 60 | + "start_time": "2026-02-24T17:53:31.135526425Z" |
| 61 | + } |
| 62 | + }, |
| 63 | + "cell_type": "code", |
| 64 | + "source": [ |
| 65 | + "\n", |
| 66 | + "print(f\"PyTorch version: {torch.__version__}\")\n", |
| 67 | + "print(f\"CUDA available: {torch.cuda.is_available()}\")\n", |
| 68 | + "print(f\"CUDA version: {torch.version.cuda}\")\n", |
| 69 | + "print(f\"cuDNN version: {torch.backends.cudnn.version()}\")\n", |
| 70 | + "print(f\"Device Name: {torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'None'}\")\n" |
| 71 | + ], |
| 72 | + "id": "479d22a19052b601", |
| 73 | + "outputs": [ |
| 74 | + { |
| 75 | + "name": "stdout", |
| 76 | + "output_type": "stream", |
| 77 | + "text": [ |
| 78 | + "PyTorch version: 2.5.1+cu121\n", |
| 79 | + "CUDA available: True\n", |
| 80 | + "CUDA version: 12.1\n", |
| 81 | + "cuDNN version: 90100\n", |
| 82 | + "Device Name: NVIDIA GeForce RTX 4050 Laptop GPU\n" |
| 83 | + ] |
| 84 | + } |
| 85 | + ], |
| 86 | + "execution_count": 3 |
| 87 | + }, |
| 88 | + { |
| 89 | + "metadata": { |
| 90 | + "ExecuteTime": { |
| 91 | + "end_time": "2026-02-24T17:53:40.898288652Z", |
| 92 | + "start_time": "2026-02-24T17:53:40.766527442Z" |
| 93 | + } |
| 94 | + }, |
| 95 | + "cell_type": "code", |
| 96 | + "source": [ |
| 97 | + "print(\"Torch:\", torch.__version__)\n", |
| 98 | + "print(\"CUDA available:\", torch.cuda.is_available())\n", |
| 99 | + "print(\"GPU:\", torch.cuda.get_device_name(0))" |
| 100 | + ], |
| 101 | + "id": "742ddba6863aba74", |
| 102 | + "outputs": [ |
| 103 | + { |
| 104 | + "name": "stdout", |
| 105 | + "output_type": "stream", |
| 106 | + "text": [ |
| 107 | + "Torch: 2.5.1+cu121\n", |
| 108 | + "CUDA available: True\n", |
| 109 | + "GPU: NVIDIA GeForce RTX 4050 Laptop GPU\n" |
| 110 | + ] |
| 111 | + } |
| 112 | + ], |
| 113 | + "execution_count": 4 |
| 114 | + }, |
| 115 | + { |
| 116 | + "metadata": { |
| 117 | + "ExecuteTime": { |
| 118 | + "end_time": "2026-02-24T17:53:43.745676614Z", |
| 119 | + "start_time": "2026-02-24T17:53:43.645100345Z" |
| 120 | + } |
| 121 | + }, |
| 122 | + "cell_type": "code", |
| 123 | + "source": [ |
| 124 | + "import sys\n", |
| 125 | + "print(sys.executable)" |
| 126 | + ], |
| 127 | + "id": "a1284b92a27174ee", |
| 128 | + "outputs": [ |
| 129 | + { |
| 130 | + "name": "stdout", |
| 131 | + "output_type": "stream", |
| 132 | + "text": [ |
| 133 | + "/home/kartik-agarwal/Documents/PytorchDemo/.venv/bin/python\n" |
| 134 | + ] |
| 135 | + } |
| 136 | + ], |
| 137 | + "execution_count": 5 |
| 138 | + }, |
| 139 | + { |
| 140 | + "metadata": { |
| 141 | + "ExecuteTime": { |
| 142 | + "end_time": "2026-02-24T17:53:46.811841062Z", |
| 143 | + "start_time": "2026-02-24T17:53:45.269999324Z" |
| 144 | + } |
| 145 | + }, |
| 146 | + "cell_type": "code", |
| 147 | + "source": [ |
| 148 | + "\n", |
| 149 | + "import time\n", |
| 150 | + "\n", |
| 151 | + "device = torch.device(\"cuda\")\n", |
| 152 | + "\n", |
| 153 | + "x = torch.randn(10000, 10000).to(device)\n", |
| 154 | + "\n", |
| 155 | + "start = time.time()\n", |
| 156 | + "y = torch.mm(x, x)\n", |
| 157 | + "torch.cuda.synchronize()\n", |
| 158 | + "print(\"Time:\", time.time() - start)\n", |
| 159 | + "\n", |
| 160 | + "\n", |
| 161 | + "# watch GPU spike by \"watch -n 1 nvidia-smi\"" |
| 162 | + ], |
| 163 | + "id": "876b55fcfa5ae0f1", |
| 164 | + "outputs": [ |
| 165 | + { |
| 166 | + "name": "stdout", |
| 167 | + "output_type": "stream", |
| 168 | + "text": [ |
| 169 | + "Time: 0.3460721969604492\n" |
| 170 | + ] |
| 171 | + } |
| 172 | + ], |
| 173 | + "execution_count": 6 |
| 174 | + }, |
| 175 | + { |
| 176 | + "metadata": {}, |
| 177 | + "cell_type": "code", |
| 178 | + "outputs": [], |
| 179 | + "execution_count": null, |
| 180 | + "source": "", |
| 181 | + "id": "957ec4831c67d3c5" |
| 182 | + }, |
| 183 | + { |
| 184 | + "metadata": { |
| 185 | + "ExecuteTime": { |
| 186 | + "end_time": "2026-02-24T18:59:32.139923224Z", |
| 187 | + "start_time": "2026-02-24T18:59:31.949651746Z" |
| 188 | + } |
| 189 | + }, |
| 190 | + "cell_type": "code", |
| 191 | + "source": [ |
| 192 | + "# Make sure we're using a NVIDIA GPU\n", |
| 193 | + "if torch.cuda.is_available():\n", |
| 194 | + " gpu_info = !nvidia-smi\n", |
| 195 | + " gpu_info = '\\n'.join(gpu_info)\n", |
| 196 | + " if gpu_info.find(\"failed\") >= 0:\n", |
| 197 | + " print(\"Not connected to a GPU, to leverage the best of PyTorch 2.0, you should connect to a GPU.\")\n", |
| 198 | + "\n", |
| 199 | + " # Get GPU name\n", |
| 200 | + " gpu_name = !nvidia-smi --query-gpu=gpu_name --format=csv\n", |
| 201 | + " gpu_name = gpu_name[1]\n", |
| 202 | + " GPU_NAME = gpu_name.replace(\" \", \"_\") # remove underscores for easier saving\n", |
| 203 | + " print(f'GPU name: {GPU_NAME}')\n", |
| 204 | + "\n", |
| 205 | + " # Get GPU capability score\n", |
| 206 | + " GPU_SCORE = torch.cuda.get_device_capability()\n", |
| 207 | + " print(f\"GPU capability score: {GPU_SCORE}\")\n", |
| 208 | + " if GPU_SCORE >= (8, 0):\n", |
| 209 | + " print(f\"GPU score higher than or equal to (8, 0), PyTorch 2.x speedup features available.\")\n", |
| 210 | + " else:\n", |
| 211 | + " print(f\"GPU score lower than (8, 0), PyTorch 2.x speedup features will be limited (PyTorch 2.x speedups happen most on newer GPUs).\")\n", |
| 212 | + "\n", |
| 213 | + " # Print GPU info\n", |
| 214 | + " print(f\"GPU information:\\n{gpu_info}\")\n", |
| 215 | + "\n", |
| 216 | + "else:\n", |
| 217 | + " print(\"PyTorch couldn't find a GPU, to leverage the best of PyTorch 2.0, you should connect to a GPU.\")" |
| 218 | + ], |
| 219 | + "id": "820858027c722588", |
| 220 | + "outputs": [ |
| 221 | + { |
| 222 | + "name": "stdout", |
| 223 | + "output_type": "stream", |
| 224 | + "text": [ |
| 225 | + "GPU name: NVIDIA_GeForce_RTX_4050_Laptop_GPU\n", |
| 226 | + "GPU capability score: (8, 9)\n", |
| 227 | + "GPU score higher than or equal to (8, 0), PyTorch 2.x speedup features available.\n", |
| 228 | + "GPU information:\n", |
| 229 | + "Wed Feb 25 00:29:31 2026 \n", |
| 230 | + "+-----------------------------------------------------------------------------------------+\n", |
| 231 | + "| NVIDIA-SMI 590.48.01 Driver Version: 590.48.01 CUDA Version: 13.1 |\n", |
| 232 | + "+-----------------------------------------+------------------------+----------------------+\n", |
| 233 | + "| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |\n", |
| 234 | + "| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |\n", |
| 235 | + "| | | MIG M. |\n", |
| 236 | + "|=========================================+========================+======================|\n", |
| 237 | + "| 0 NVIDIA GeForce RTX 4050 ... Off | 00000000:01:00.0 Off | N/A |\n", |
| 238 | + "| N/A 47C P8 1W / 100W | 997MiB / 6141MiB | 0% Default |\n", |
| 239 | + "| | | N/A |\n", |
| 240 | + "+-----------------------------------------+------------------------+----------------------+\n", |
| 241 | + "\n", |
| 242 | + "+-----------------------------------------------------------------------------------------+\n", |
| 243 | + "| Processes: |\n", |
| 244 | + "| GPU GI CI PID Type Process name GPU Memory |\n", |
| 245 | + "| ID ID Usage |\n", |
| 246 | + "|=========================================================================================|\n", |
| 247 | + "| 0 N/A N/A 5445 C .../PytorchDemo/.venv/bin/python 890MiB |\n", |
| 248 | + "| 0 N/A N/A 5945 C .../PytorchDemo/.venv/bin/python 96MiB |\n", |
| 249 | + "+-----------------------------------------------------------------------------------------+\n" |
| 250 | + ] |
| 251 | + } |
| 252 | + ], |
| 253 | + "execution_count": 7 |
| 254 | + }, |
| 255 | + { |
| 256 | + "metadata": { |
| 257 | + "ExecuteTime": { |
| 258 | + "end_time": "2026-02-24T19:00:17.073846383Z", |
| 259 | + "start_time": "2026-02-24T19:00:17.050400781Z" |
| 260 | + } |
| 261 | + }, |
| 262 | + "cell_type": "code", |
| 263 | + "source": [ |
| 264 | + "# Check available GPU memory and total GPU memory\n", |
| 265 | + "total_free_gpu_memory, total_gpu_memory = torch.cuda.mem_get_info()\n", |
| 266 | + "print(f\"Total free GPU memory: {round(total_free_gpu_memory * 1e-9, 3)} GB\")\n", |
| 267 | + "print(f\"Total GPU memory: {round(total_gpu_memory * 1e-9, 3)} GB\")" |
| 268 | + ], |
| 269 | + "id": "ea0d6667eedccfd0", |
| 270 | + "outputs": [ |
| 271 | + { |
| 272 | + "name": "stdout", |
| 273 | + "output_type": "stream", |
| 274 | + "text": [ |
| 275 | + "Total free GPU memory: 5.009 GB\n", |
| 276 | + "Total GPU memory: 6.053 GB\n" |
| 277 | + ] |
| 278 | + } |
| 279 | + ], |
| 280 | + "execution_count": 8 |
| 281 | + } |
| 282 | + ], |
| 283 | + "metadata": { |
| 284 | + "kernelspec": { |
| 285 | + "display_name": "Python 3", |
| 286 | + "language": "python", |
| 287 | + "name": "python3" |
| 288 | + }, |
| 289 | + "language_info": { |
| 290 | + "codemirror_mode": { |
| 291 | + "name": "ipython", |
| 292 | + "version": 2 |
| 293 | + }, |
| 294 | + "file_extension": ".py", |
| 295 | + "mimetype": "text/x-python", |
| 296 | + "name": "python", |
| 297 | + "nbconvert_exporter": "python", |
| 298 | + "pygments_lexer": "ipython2", |
| 299 | + "version": "2.7.6" |
| 300 | + } |
| 301 | + }, |
| 302 | + "nbformat": 4, |
| 303 | + "nbformat_minor": 5 |
| 304 | +} |
0 commit comments