Created
December 4, 2022 17:24
-
-
Save MrMarvel/3affb6aa298d2371b790b714211b5d75 to your computer and use it in GitHub Desktop.
HW1.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"provenance": [], | |
"toc_visible": true, | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
}, | |
"gpuClass": "standard", | |
"accelerator": "GPU" | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/MrMarvel/3affb6aa298d2371b790b714211b5d75/hw1.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"# Получение информации об оборудовании" | |
], | |
"metadata": { | |
"id": "SE_-SpH-mtFc" | |
} | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"**Windows** - GUI\\\n", | |
"**Linux** (Google colab) - terminal" | |
], | |
"metadata": { | |
"id": "lnGz2Eopm3ag" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# версия Linux\n", | |
"!cat /proc/version" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "vPDZJB92omAL", | |
"outputId": "bf9f92de-eb1a-4b2d-ab6f-c069041efbfa" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Linux version 5.10.133+ (builder@b1018906abc3) (Chromium OS 12.0_pre422132_p20210405-r10 clang version 13.0.0 (/var/tmp/portage/sys-devel/llvm-12.0_pre422132_p20210405-r10/work/llvm-12.0_pre422132_p20210405/clang cd442157cff4aad209ae532cbf031abbe10bc1df), LLD 13.0.0 (/var/tmp/portage/sys-devel/llvm-12.0_pre422132_p20210405-r10/work/llvm-12.0_pre422132_p20210405/lld cd442157cff4aad209ae532cbf031abbe10bc1df)) #1 SMP Fri Aug 26 08:44:51 UTC 2022\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# версия дистрибутива Linux\n", | |
"!lsb_release -a" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "ePuVTgneo0Rs", | |
"outputId": "24b71eb0-8339-4e78-9a5d-5dc490a588a8" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"No LSB modules are available.\n", | |
"Distributor ID:\tUbuntu\n", | |
"Description:\tUbuntu 18.04.6 LTS\n", | |
"Release:\t18.04\n", | |
"Codename:\tbionic\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"id": "eXAC5VIPiJl7", | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"outputId": "31b60351-1635-4f57-8659-4f307f02c939" | |
}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Sun Dec 4 04:15:36 2022 \n", | |
"+-----------------------------------------------------------------------------+\n", | |
"| NVIDIA-SMI 460.32.03 Driver Version: 460.32.03 CUDA Version: 11.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 76C P0 35W / 70W | 8288MiB / 15109MiB | 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", | |
"+-----------------------------------------------------------------------------+\n" | |
] | |
} | |
], | |
"source": [ | |
"# видеокарта\n", | |
"!nvidia-smi" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"CUDA Version в nvidia-smi - это не ваша текущая версия CUDA, а [максимально поддерживаемая версия](https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html) для текущего драйвера видеокарты." | |
], | |
"metadata": { | |
"id": "CPIo9i8Tx0aX" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# cuda compiler\n", | |
"!nvcc --version" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "TF2LKwK9wsiH", | |
"outputId": "9fddc05d-4659-4368-abc9-d1f8e5925229" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"nvcc: NVIDIA (R) Cuda compiler driver\n", | |
"Copyright (c) 2005-2021 NVIDIA Corporation\n", | |
"Built on Sun_Feb_14_21:12:58_PST_2021\n", | |
"Cuda compilation tools, release 11.2, V11.2.152\n", | |
"Build cuda_11.2.r11.2/compiler.29618528_0\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# процессор\n", | |
"!cat /proc/cpuinfo" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "W1vqoHiFnzCk", | |
"outputId": "77e08d28-0e3f-45c9-b202-16a12384368e" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"processor\t: 0\n", | |
"vendor_id\t: GenuineIntel\n", | |
"cpu family\t: 6\n", | |
"model\t\t: 85\n", | |
"model name\t: Intel(R) Xeon(R) CPU @ 2.00GHz\n", | |
"stepping\t: 3\n", | |
"microcode\t: 0x1\n", | |
"cpu MHz\t\t: 2000.162\n", | |
"cache size\t: 39424 KB\n", | |
"physical id\t: 0\n", | |
"siblings\t: 2\n", | |
"core id\t\t: 0\n", | |
"cpu cores\t: 1\n", | |
"apicid\t\t: 0\n", | |
"initial apicid\t: 0\n", | |
"fpu\t\t: yes\n", | |
"fpu_exception\t: yes\n", | |
"cpuid level\t: 13\n", | |
"wp\t\t: yes\n", | |
"flags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves arat md_clear arch_capabilities\n", | |
"bugs\t\t: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa mmio_stale_data retbleed\n", | |
"bogomips\t: 4000.32\n", | |
"clflush size\t: 64\n", | |
"cache_alignment\t: 64\n", | |
"address sizes\t: 46 bits physical, 48 bits virtual\n", | |
"power management:\n", | |
"\n", | |
"processor\t: 1\n", | |
"vendor_id\t: GenuineIntel\n", | |
"cpu family\t: 6\n", | |
"model\t\t: 85\n", | |
"model name\t: Intel(R) Xeon(R) CPU @ 2.00GHz\n", | |
"stepping\t: 3\n", | |
"microcode\t: 0x1\n", | |
"cpu MHz\t\t: 2000.162\n", | |
"cache size\t: 39424 KB\n", | |
"physical id\t: 0\n", | |
"siblings\t: 2\n", | |
"core id\t\t: 0\n", | |
"cpu cores\t: 1\n", | |
"apicid\t\t: 1\n", | |
"initial apicid\t: 1\n", | |
"fpu\t\t: yes\n", | |
"fpu_exception\t: yes\n", | |
"cpuid level\t: 13\n", | |
"wp\t\t: yes\n", | |
"flags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves arat md_clear arch_capabilities\n", | |
"bugs\t\t: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa mmio_stale_data retbleed\n", | |
"bogomips\t: 4000.32\n", | |
"clflush size\t: 64\n", | |
"cache_alignment\t: 64\n", | |
"address sizes\t: 46 bits physical, 48 bits virtual\n", | |
"power management:\n", | |
"\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# процессор\n", | |
"!lscpu" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "_q3ACTnJoMJU", | |
"outputId": "f4474860-0303-4c3d-8979-9b0806063b57" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Architecture: x86_64\n", | |
"CPU op-mode(s): 32-bit, 64-bit\n", | |
"Byte Order: Little Endian\n", | |
"CPU(s): 2\n", | |
"On-line CPU(s) list: 0,1\n", | |
"Thread(s) per core: 2\n", | |
"Core(s) per socket: 1\n", | |
"Socket(s): 1\n", | |
"NUMA node(s): 1\n", | |
"Vendor ID: GenuineIntel\n", | |
"CPU family: 6\n", | |
"Model: 85\n", | |
"Model name: Intel(R) Xeon(R) CPU @ 2.00GHz\n", | |
"Stepping: 3\n", | |
"CPU MHz: 2000.162\n", | |
"BogoMIPS: 4000.32\n", | |
"Hypervisor vendor: KVM\n", | |
"Virtualization type: full\n", | |
"L1d cache: 32K\n", | |
"L1i cache: 32K\n", | |
"L2 cache: 1024K\n", | |
"L3 cache: 39424K\n", | |
"NUMA node0 CPU(s): 0,1\n", | |
"Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves arat md_clear arch_capabilities\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# оперативная память\n", | |
"!grep MemTotal /proc/meminfo" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "e_AQVQQaoVFR", | |
"outputId": "8e998edb-71cd-498e-a8c9-1170f6ab200c" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"MemTotal: 13297228 kB\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# диск\n", | |
"!df -h" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "58uYqrEBqrqj", | |
"outputId": "bbff7a82-94b7-45a3-d780-ee83d5b4d0a1" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Filesystem Size Used Avail Use% Mounted on\n", | |
"overlay 79G 23G 56G 29% /\n", | |
"tmpfs 64M 0 64M 0% /dev\n", | |
"shm 5.7G 0 5.7G 0% /dev/shm\n", | |
"/dev/root 2.0G 1.1G 910M 54% /sbin/docker-init\n", | |
"tmpfs 6.4G 40K 6.4G 1% /var/colab\n", | |
"/dev/sda1 75G 41G 35G 55% /opt/bin/.nvidia\n", | |
"tmpfs 6.4G 0 6.4G 0% /proc/acpi\n", | |
"tmpfs 6.4G 0 6.4G 0% /proc/scsi\n", | |
"tmpfs 6.4G 0 6.4G 0% /sys/firmware\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"!du -h | sort -h" | |
], | |
"metadata": { | |
"id": "6AZaA5fOwXXC", | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"outputId": "e054bc0a-691d-4443-f365-bac6410e1133" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"8.0K\t./.config/configurations\n", | |
"72K\t./.config/logs/2022.12.01\n", | |
"76K\t./.config/logs\n", | |
"108K\t./.config\n", | |
"55M\t.\n", | |
"55M\t./sample_data\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# права в Google Colab\n", | |
"!whoami" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "gBYRJ67qqMJ2", | |
"outputId": "270e2a9c-4cd1-4d10-ff75-d0c03bea9a9c" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"root\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"# Библиотека Pytorch" | |
], | |
"metadata": { | |
"id": "xJef-8rXrMR2" | |
} | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"## Установка" | |
], | |
"metadata": { | |
"id": "mV8n8faxvOQO" | |
} | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"Ссылки для установки под ваше оборудование можно найти [тут](https://pytorch.org/get-started/locally/)." | |
], | |
"metadata": { | |
"id": "ZOyzr4Vp2vgZ" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"import torch" | |
], | |
"metadata": { | |
"id": "b_dqa87wrRMu" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"torch.cuda.is_available()" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "2vcNoQZ4zVJG", | |
"outputId": "a5ff9f0b-7803-45a0-f4f6-bfdf89764cba" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 90 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"!python -m pip list | grep torch" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "Fs_NS9SKzZeH", | |
"outputId": "46abd90e-2ca7-4dcc-a208-0cba42c66d51" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"torch 1.12.1+cu113\n", | |
"torchaudio 0.12.1+cu113\n", | |
"torchsummary 1.5.1\n", | |
"torchtext 0.13.1\n", | |
"torchvision 0.13.1+cu113\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"# Домашнее задание" | |
], | |
"metadata": { | |
"id": "DJ9Uxo7DEns4" | |
} | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"Дедлайн домашнего задания - текущее воскресенье 23:59. " | |
], | |
"metadata": { | |
"id": "3hbaklz_96EN" | |
} | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"**Домашнее задание 0:** Создайте репозиторий на Github. Вся дальнейшая домашка загружается туда. Чуть позже в телеграм чате будет выложена форма для сдачи." | |
], | |
"metadata": { | |
"id": "E7VzrzlHyyci" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#https://github.com/MrMarvel/PyTorchDeep2022" | |
], | |
"metadata": { | |
"id": "e5A8OELNGdpr" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"**Домашнее задание 1:** реализуйте XOR с помощью 3 нейронов. Запишите ответ в виде выражения, состоящего из объектов neuron() – моделей нейрона с пороговой функцией активации, внутри скобок может быть что угодно. Входы верхнего уровня называются x1 и x2. Пример фрагмента записи: neuron(1*x1 + 5*x2 - 0.1) + neuron(x1) (ответ будет выглядеть чуть сложнее, но других символов вроде && не потребуется)." | |
], | |
"metadata": { | |
"id": "me6riR-YEuYg" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# TODO" | |
], | |
"metadata": { | |
"id": "KZnZmqMlWzYO" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"**Домашнее задание 2:** нарисуйте backward граф для выражения `a*b+c*d`. [Теория и пример оформления](https://www.youtube.com/watch?v=MswxJw-8PvE). Сравните полученные теоретические значения с аттрибутами grad у исходных тензоров." | |
], | |
"metadata": { | |
"id": "UQmVNc2kEyQP" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# TODO" | |
], | |
"metadata": { | |
"id": "IlwVlc-_WvJv" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"a = torch.tensor([2.0], requires_grad=True)\n", | |
"b = torch.tensor([4.0], requires_grad=True)\n", | |
"c = torch.tensor([1.0], requires_grad=True)\n", | |
"d = torch.tensor([5.0], requires_grad=False)" | |
], | |
"metadata": { | |
"id": "rHAT-rNxnh-X" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"print(a.grad)" | |
], | |
"metadata": { | |
"id": "yQUF6a8rnjyF", | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"outputId": "6ed2bd81-89b7-4d30-924c-3b045889da5f" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"None\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"loss = a*b + c*d\n", | |
"loss.backward()" | |
], | |
"metadata": { | |
"id": "WQewq5DCnnPF" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"print(a.grad)" | |
], | |
"metadata": { | |
"id": "tDxWZCwQnojN", | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"outputId": "2be6561a-0dfe-49b7-c654-1fd7ff49e4af" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"tensor([4.])\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"**Домашнее задание 3:** Поэксперементируйте с размером тензоров, которые влезут на видеоркарту в Colab. Найдите максимальный размер тензора для типа данных float32, float64, float16, int32, int64. На сколько они отличаются." | |
], | |
"metadata": { | |
"id": "NxKEOwWDwv3Y" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# TODO" | |
], | |
"metadata": { | |
"id": "cCrGQpIdWoj3" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"**Домашнее задание 4:** Напишите хороший пример неэффективного кода для занятия памяти видеокарты, который вызовет ошибку out of memory" | |
], | |
"metadata": { | |
"id": "CBR5pWOlzOtl" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"\n", | |
"torch.cuda.empty_cache()\n", | |
"\n", | |
"def allocate_empty_tensor(dim_size):\n", | |
" a=torch.zeros(1024*1024*128,dim_size,dtype=torch.float32,device='cuda')\n", | |
" return a\n", | |
"\n", | |
"print(torch.cuda.memory_allocated()/1024/1024, \"MB\")\n", | |
"print(torch.cuda.memory_reserved()/1024/1024/1024, \"GB\")\n", | |
"print()\n", | |
"print(\"FILLING\")\n", | |
"try:\n", | |
" for i in range(13): # Trying to work with tensors from 1 GB to 13GB. GPU MAX 16GB\n", | |
" temp_working_tensor = allocate_empty_tensor(i)\n", | |
" print(torch.cuda.memory_allocated()/1024/1024, \"MB\")\n", | |
" print(torch.cuda.memory_reserved()/1024/1024/1024, \"GB\")\n", | |
" print()\n", | |
"except Exception as e:\n", | |
" print(e)\n", | |
" print()\n", | |
"\n", | |
"print(\"CLEARING\")\n", | |
"torch.cuda.empty_cache()\n", | |
"print(torch.cuda.memory_allocated()/1024/1024, \"MB\")\n", | |
"print(torch.cuda.memory_reserved()/1024/1024/1024, \"GB\")\n", | |
"print()" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "MpP1UciHPaj9", | |
"outputId": "1998c8a7-69e0-489f-d5f1-efcf15610bd5" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"4608.0 MB\n", | |
"4.5 GB\n", | |
"\n", | |
"FILLING\n", | |
"4608.0 MB\n", | |
"4.5 GB\n", | |
"\n", | |
"5120.0 MB\n", | |
"5.0 GB\n", | |
"\n", | |
"5632.0 MB\n", | |
"6.0 GB\n", | |
"\n", | |
"2560.0 MB\n", | |
"7.5 GB\n", | |
"\n", | |
"3072.0 MB\n", | |
"7.5 GB\n", | |
"\n", | |
"3584.0 MB\n", | |
"7.5 GB\n", | |
"\n", | |
"4096.0 MB\n", | |
"10.5 GB\n", | |
"\n", | |
"4608.0 MB\n", | |
"10.5 GB\n", | |
"\n", | |
"7680.0 MB\n", | |
"9.5 GB\n", | |
"\n", | |
"8192.0 MB\n", | |
"14.0 GB\n", | |
"\n", | |
"9728.0 MB\n", | |
"14.0 GB\n", | |
"\n", | |
"CUDA out of memory. Tried to allocate 5.50 GiB (GPU 0; 14.76 GiB total capacity; 9.50 GiB already allocated; 4.66 GiB free; 9.50 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF\n", | |
"\n", | |
"CLEARING\n", | |
"9728.0 MB\n", | |
"9.5 GB\n", | |
"\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"torch.cuda.empty_cache()\n", | |
"torch.cuda.memory_reserved()" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "6TR7m9TLRCVE", | |
"outputId": "3657ac3c-7365-4ef1-c2e2-2aef24903c68" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"11274289152" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 98 | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"**Домашнее задание 5:** Используя один линейный слой `nn.Linear` и один входной тензор `x` подберите подберите размерности так, чтобы занимать всю видеопамять.\n", | |
"Попробуйте применить линейный слой к тензору `x`. Что произойдет? Кратко опишите ваши эксперименты. Что вы поняли?" | |
], | |
"metadata": { | |
"id": "0_hOtvvR89jq" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# TODO" | |
], | |
"metadata": { | |
"id": "oKECp39TW1Lv" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"# Рекомендуемые ссылки" | |
], | |
"metadata": { | |
"id": "_Z2Ot37UODKM" | |
} | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"- [Нейронные сети и компьютерное зрение, Samsung AI Center, часть 1](https://stepik.org/course/50352/syllabus)\n", | |
"- [Cимулятор](https://playground.tensorflow.org/) нейронов и нейронных сетей" | |
], | |
"metadata": { | |
"id": "SnFY95T7kNji" | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment