268 lines
15 KiB
Plaintext
268 lines
15 KiB
Plaintext
|
{
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 0,
|
||
|
"metadata": {
|
||
|
"accelerator": "GPU",
|
||
|
"colab": {
|
||
|
"name": "bug_report_model.ipynb",
|
||
|
"provenance": [],
|
||
|
"collapsed_sections": []
|
||
|
},
|
||
|
"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.9.7"
|
||
|
}
|
||
|
},
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"id": "rR4_BAUYs3Mb"
|
||
|
},
|
||
|
"source": [
|
||
|
"![image.png](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQYAAABSCAYAAAC2XXppAAAaWElEQVR4Ae2dh3dU1RbG3x/i0mXvoighgKgI2BtW7KKiSAcFFVBQmgqKil2UJzYUQXl2ERSRpoiIIJhMOiEQkpCQRup+63eSHS73zkxmkmFC2Wetm5m55ZTv7P3tcs5M/iNWDAFDwBDwIfAf32f7aAgYAoaAGDGYEBgChkAAASOGACR2whAwBIwYTAYMAUMggIARQwASO2EIGAJGDCYDhoAhEEDAiCEAiZ0wBAwBIwaTAUPAEAggYMQQgMROGAKGgBGDyYAhYAgEEDBiCEBiJwwBQ8CIwWTAEDAEAggYMQQgsROGgCFgxGAyYAgYAgEEjBgCkNgJQ8AQMGIwGTAEDIEAAkYMAUjshCFgCBgxmAwYAoZAAAEjhgAkdsIQMASMGEwGDAFDIIBAhxJDXW2j7NldL6WFdVJb0xjonJ0wBAyBjkGgQ4ih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6xfv162b98udXVtD8tyc3Pl999/d0dxcbGAd7RC27T722+/SX5+vjS0I1mUk5Pj6vnjjz86FE/w++uvv1xftm7dGm34B+21jiEGwocu6TKpX46sXFQqe6sbHTHMGrhNhpx3YImhvr5e1q1bJ7fddptce+217rj66qvlqquucsf1118vDz30kLz55pvyzz//SG1tbcyTh1LNmDFDrrzySqFOPWjnuuuuc8c111zTcp7rl19+uYwdO1Y2bdoUczuJvnHt2rUycOBAueKKK+T9999vEylqn+bMmeNwvOyyy2TFihWt4sdcgHmvXr1c21VVVVpV3K+vv/660C54o5CtkZK3AQhq586dcT3jfd77HsODfF188cXyyCOPeC8dMu+TTwyQQkq6TLo+R1YvLnOkQL4i79+9Mu7SrLg2Qbk8RJweA2yOwJ5//vnSqVMnOeecc+Tcc8+V8847z71y7owzzpAuXbrI4MGDBaWJ1Yrl5eXJ448/LmeffbZ07ty55aANDs7z6r125plnyr333uusZkdJzc8//+wU6rTTTpNXXnlFsPRtLS+88IIb31lnnSVLliwRvKhoZdWqVXLBBRfIKaecIm+88YZUVrY9VzR9+nShXeYSzy/WecO6z549W1577bVW+xttLHqtrKxMLrnkEjn11FPd3Or5Q+k1ucTQHD48dX2OrFpcJjXVTW4m34X44/ty912JuPMVbSQGhBEBuvHGG2XmzJnueO655+SJJ56Q/v37O+GGMEaMGCHbtm2LaU53794tixcvFgT02WeflWeeecYdDzzwgHTr1s21d8cdd8iUKVNark2dOlU++OADwQXvqAIx4OWcfvrp7SaGWbNmtRDsjz/+2KqiEUY9//zz8tRTT8ny5ctbvT8aRmAOsaekpDgPLFZieOyxx5wxGDRokLTHY9G+VVdXy0svveTGNG/ePD19SL0mlRj4evXUm3Nk9f/2kQJoVZc3yOezimTQOWnxJx/bQAy//vqrs1IIEESA61deXu4OrCUexX333eesT58+feSzzz6LycXEdUUoqM97fPzxx9K3b1/p2rWrU7yioqL9riOMhDhaeI9nE6tg63PRXqmPI1yBGAilIAasZklJiRsv98fjjlM3xADh4h3FQgy0AVZY2W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3X333U65yFeQRIQEcK3J+KPctIGwQgAQ1SeffOIIRImB8dIe93MvpMR4qIOxQQ7ecen4vK/xEoMSsD/5SJ9QLjCBFMjygwHEyTnGzfhRTi8xMAa9ritM1MN5xsHzeA4cKP/999/viJhrEAVtQIyMg7nBw0AeduzY4aw/JEV4CSkTeik2eCVasNxgT/KRkFQLcgJpUxc5CGRLQ0zqot+Mk7yLFpSdvBTXmDf6P2TIEDc3zBXj4mCeCJ8SVZJ
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"id": "i7XbLCXGkll9"
|
||
|
},
|
||
|
"source": [
|
||
|
"# The Boring Model\n",
|
||
|
"Replicate a bug you experience, using this model.\n",
|
||
|
"\n",
|
||
|
"[Remember! we're always available for support on Slack](https://join.slack.com/t/pytorch-lightning/shared_invite/zt-f6bl2l0l-JYMK3tbAgAmGRrlNr00f1A)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"id": "2LODD6w9ixlT"
|
||
|
},
|
||
|
"source": [
|
||
|
"---\n",
|
||
|
"## Setup env"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"metadata": {
|
||
|
"id": "zK7-Gg69kMnG"
|
||
|
},
|
||
|
"source": [
|
||
|
"%%capture\n",
|
||
|
"! pip install -qU pytorch-lightning"
|
||
|
],
|
||
|
"execution_count": null,
|
||
|
"outputs": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"id": "WvuSN5jEbY8P"
|
||
|
},
|
||
|
"source": [
|
||
|
"---\n",
|
||
|
"## Deps"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"metadata": {
|
||
|
"id": "w4_TYnt_keJi"
|
||
|
},
|
||
|
"source": [
|
||
|
"import os\n",
|
||
|
"\n",
|
||
|
"import torch\n",
|
||
|
"from torch.utils.data import DataLoader, Dataset\n",
|
||
|
"\n",
|
||
|
"from pytorch_lightning import LightningModule, Trainer"
|
||
|
],
|
||
|
"execution_count": null,
|
||
|
"outputs": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"id": "XrJDukwPtUnS"
|
||
|
},
|
||
|
"source": [
|
||
|
"---\n",
|
||
|
"## Data\n",
|
||
|
"Random data is best for debugging. If you needs special tensor shapes or batch compositions or dataloaders, modify as needed"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"metadata": {
|
||
|
"id": "hvgTiaZpkvwS"
|
||
|
},
|
||
|
"source": [
|
||
|
"class RandomDataset(Dataset):\n",
|
||
|
" def __init__(self, size, num_samples):\n",
|
||
|
" self.len = num_samples\n",
|
||
|
" self.data = torch.randn(num_samples, size)\n",
|
||
|
"\n",
|
||
|
" def __getitem__(self, index):\n",
|
||
|
" return self.data[index]\n",
|
||
|
"\n",
|
||
|
" def __len__(self):\n",
|
||
|
" return self.len"
|
||
|
],
|
||
|
"execution_count": null,
|
||
|
"outputs": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"metadata": {
|
||
|
"id": "sxVlWjGhl02D"
|
||
|
},
|
||
|
"source": [
|
||
|
"num_samples = 10000"
|
||
|
],
|
||
|
"execution_count": null,
|
||
|
"outputs": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"metadata": {
|
||
|
"id": "V7ELesz1kVQo"
|
||
|
},
|
||
|
"source": [
|
||
|
"class BoringModel(LightningModule):\n",
|
||
|
" def __init__(self):\n",
|
||
|
" super().__init__()\n",
|
||
|
" self.layer = torch.nn.Linear(32, 2)\n",
|
||
|
"\n",
|
||
|
" def forward(self, x):\n",
|
||
|
" return self.layer(x)\n",
|
||
|
"\n",
|
||
|
" def training_step(self, batch, batch_idx):\n",
|
||
|
" loss = self(batch).sum()\n",
|
||
|
" self.log(\"train_loss\", loss)\n",
|
||
|
" return {\"loss\": loss}\n",
|
||
|
"\n",
|
||
|
" def validation_step(self, batch, batch_idx):\n",
|
||
|
" loss = self(batch).sum()\n",
|
||
|
" self.log(\"valid_loss\", loss)\n",
|
||
|
"\n",
|
||
|
" def test_step(self, batch, batch_idx):\n",
|
||
|
" loss = self(batch).sum()\n",
|
||
|
" self.log(\"test_loss\", loss)\n",
|
||
|
"\n",
|
||
|
" def configure_optimizers(self):\n",
|
||
|
" return torch.optim.SGD(self.layer.parameters(), lr=0.1)"
|
||
|
],
|
||
|
"execution_count": null,
|
||
|
"outputs": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"id": "ubvW3LGSupmt"
|
||
|
},
|
||
|
"source": [
|
||
|
"---\n",
|
||
|
"## Define the test"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"metadata": {
|
||
|
"id": "4Dk6Ykv8lI7X"
|
||
|
},
|
||
|
"source": [
|
||
|
"def run():\n",
|
||
|
" train_data = DataLoader(RandomDataset(32, 64), batch_size=2)\n",
|
||
|
" val_data = DataLoader(RandomDataset(32, 64), batch_size=2)\n",
|
||
|
" test_data = DataLoader(RandomDataset(32, 64), batch_size=2)\n",
|
||
|
"\n",
|
||
|
" model = BoringModel()\n",
|
||
|
" trainer = Trainer(\n",
|
||
|
" default_root_dir=os.getcwd(),\n",
|
||
|
" limit_train_batches=1,\n",
|
||
|
" limit_val_batches=1,\n",
|
||
|
" limit_test_batches=1,\n",
|
||
|
" num_sanity_val_steps=0,\n",
|
||
|
" max_epochs=1,\n",
|
||
|
" enable_model_summary=False,\n",
|
||
|
" )\n",
|
||
|
" trainer.fit(model, train_dataloaders=train_data, val_dataloaders=val_data)\n",
|
||
|
" trainer.test(model, dataloaders=test_data)"
|
||
|
],
|
||
|
"execution_count": null,
|
||
|
"outputs": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"id": "4dPfTZVgmgxz"
|
||
|
},
|
||
|
"source": [
|
||
|
"---\n",
|
||
|
"## Run Test"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"metadata": {
|
||
|
"id": "AAtq1hwSmjKe"
|
||
|
},
|
||
|
"source": [
|
||
|
"run()"
|
||
|
],
|
||
|
"execution_count": null,
|
||
|
"outputs": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"id": "Flyi--SpvsJN"
|
||
|
},
|
||
|
"source": [
|
||
|
"---\n",
|
||
|
"## Environment\n",
|
||
|
"Run this to get the environment details"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"metadata": {
|
||
|
"id": "0-yvGFRoaDSi"
|
||
|
},
|
||
|
"source": [
|
||
|
"%%capture\n",
|
||
|
"! wget https://raw.githubusercontent.com/PyTorchLightning/pytorch-lightning/master/requirements/collect_env_details.py"
|
||
|
],
|
||
|
"execution_count": null,
|
||
|
"outputs": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"metadata": {
|
||
|
"id": "quj4LUDgmFvj"
|
||
|
},
|
||
|
"source": [
|
||
|
"! python collect_env_details.py"
|
||
|
],
|
||
|
"execution_count": null,
|
||
|
"outputs": []
|
||
|
}
|
||
|
]
|
||
|
}
|