Skip to content

Commit

Permalink
resolving Anish's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kenleejr committed Dec 6, 2023
1 parent e04329e commit 63155e2
Showing 1 changed file with 78 additions and 26 deletions.
104 changes: 78 additions & 26 deletions colabs/wandb-model-registry/New_Model_Logging_in_W&B.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"colab": {
"provenance": [],
"gpuType": "T4",
"authorship_tag": "ABX9TyMqvDDIo1WDFe0kuxoSgmq6",
"authorship_tag": "ABX9TyOlvkZjseUluPYEdqGH1TjK",
"include_colab_link": true
},
"kernelspec": {
Expand Down Expand Up @@ -43,6 +43,15 @@
"id": "saeQIrcF155i"
}
},
{
"cell_type": "markdown",
"source": [
"## Imports"
],
"metadata": {
"id": "_ewwM5T_OWTr"
}
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -51,13 +60,53 @@
},
"outputs": [],
"source": [
"!pip install wandb einops"
"!pip install -qqq wandb einops"
]
},
{
"cell_type": "code",
"source": [
"!wandb login"
"import torch\n",
"from torch import nn\n",
"from einops import rearrange, repeat\n",
"from einops.layers.torch import Rearrange\n",
"import torch\n",
"from torch.utils.data import DataLoader, Dataset\n",
"from torchvision import transforms\n",
"import torch\n",
"from torch import nn\n",
"from torch.optim import Adam\n",
"from torch.utils.data import DataLoader\n",
"from torchvision import datasets, transforms\n",
"\n",
"import wandb"
],
"metadata": {
"id": "6OsMa64TOacf"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Log in to W&B\n",
"- You can explicitly login using `wandb login` or `wandb.login()` (See below)\n",
"- Alternatively you can set environment variables. There are several env variables which you can set to change the behavior of W&B logging. The most important are:\n",
" - `WANDB_API_KEY` - find this in your \"Settings\" section under your profile\n",
" - `WANDB_BASE_URL` - this is the url of the W&B server\n",
"- Find your API Token in \"Profile\" -> \"Setttings\" in the W&B App\n",
"\n",
"![api_token](https://drive.google.com/uc?export=view&id=1Xn7hnn0rfPu_EW0A_-32oCXqDmpA0-kx)"
],
"metadata": {
"id": "m3Q_QG14Ovvz"
}
},
{
"cell_type": "code",
"source": [
"wandb.login()"
],
"metadata": {
"id": "5-r3O3gFwfcr"
Expand All @@ -69,24 +118,41 @@
"cell_type": "markdown",
"source": [
"# Define the Model and Dataset\n",
"This is a simple implementation of a Vision Transformer (ViT) and utilizes a random dataset for training.\n",
"- Credit to https://github.com/lucidrains/vit-pytorch"
],
"metadata": {
"id": "ZuL3yZ17qIGE"
}
},
{
"cell_type": "markdown",
"source": [
"## Define some config for the model and dataset"
],
"metadata": {
"id": "WE4j_CI7Tt9O"
}
},
{
"cell_type": "code",
"source": [
"# Define the number of samples, classes, and image size\n",
"num_samples = 100\n",
"num_classes = 10\n",
"image_size = 256\n",
"batch_size = 32"
],
"metadata": {
"id": "D7sVekyVTlxN"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import torch\n",
"from torch import nn\n",
"from einops import rearrange, repeat\n",
"from einops.layers.torch import Rearrange\n",
"import torch\n",
"from torch.utils.data import DataLoader, Dataset\n",
"\n",
"# helpers\n",
"\n",
"def pair(t):\n",
" return t if isinstance(t, tuple) else (t, t)\n",
"\n",
Expand Down Expand Up @@ -224,16 +290,12 @@
" label = torch.randint(0, self.num_classes, (1,)).item()\n",
" return image, label\n",
"\n",
"# Define the number of samples, classes, and image size\n",
"num_samples = 100\n",
"num_classes = 10\n",
"image_size = 256\n",
"\n",
"\n",
"# Create the dataset\n",
"dataset = RandomImageDataset(num_samples=num_samples, num_classes=num_classes, image_size=image_size)\n",
"\n",
"# Create a DataLoader\n",
"batch_size = 32\n",
"dataloader = DataLoader(dataset, batch_size=batch_size, shuffle=True)"
],
"metadata": {
Expand Down Expand Up @@ -262,17 +324,7 @@
{
"cell_type": "code",
"source": [
"from torchvision import transforms\n",
"import torch\n",
"from torch import nn\n",
"from torch.optim import Adam\n",
"from torch.utils.data import DataLoader\n",
"from torchvision import datasets, transforms\n",
"import wandb\n",
"\n",
"\n",
"run = wandb.init(project=\"new_model_logging\",\n",
" entity=\"wandb\",\n",
" job_type=\"training\")\n",
"\n",
"v = ViT(\n",
Expand Down

0 comments on commit 63155e2

Please sign in to comment.