Instantly share code, notes, and snippets.

🤖
backpropagating through memories

# Rishabh Anand rish-16

🤖
backpropagating through memories
Created August 30, 2022 04:00
MA2108 Note 1

# MA2108 Note 1

## Definitions

1. A set is an unordered collection of unique elements. Examples are natural numbers, integers, rational numbers, and real numbers
2. Cartesian product of $A$ and $B$ is $A \times B = \lbrace(a, b) : a \in A, b \in B\rbrace$
3. A function from set $A$ to set $B$ is a rule of correspondence that assigns each element $x \in A$ to uniquely determined element $f(x) \in B$
4. Set $A$ is called the domain of $f$
5. Set $B$ is the codomain of $f$
6. The set $f(A) = \lbrace(x) : x \in A\rbrace$ is called the range of $f$
7. Althought $D(f) = A$, we only have $R(f) \subseteq B$
Last active March 29, 2022 06:16
CS4243 PyTorch Snippets
This file contains 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
 import torch import torch.nn as nn import torch.nn.functional as F """ Creating tensors """ a = torch.rand(...) # returns a torch.Tensor b = torch.LongTensor(10).random_(0, 2) # 10-dim vector from [0, 1]
Last active August 3, 2021 17:03
A compilation of libraries that can be used on Leetcode (Python)

# Leetcode Libraries

Here's a tiny compilation of all the libraries and tools that can be used on Leetcode to make life simpler. This README covers the following:

1. requests
2. collections
3. itertools

Created July 5, 2021 05:30
TensorFlow Experiment Seeding for GPUs
This file contains 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
 import os import numpy as np import random import tensorflow as tf from tfdeterminism import patch def seed(s=42): random.seed(s) np.random.seed(s) tf.random.set_seed(s)
Last active December 22, 2021 06:39
Visualise selected patches from an image for comparison / sanity checks
This file contains 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
 import torch import torch.nn as nn import torch.nn.functional as F from torchvision import transforms import numpy as np from PIL import Image import matplotlib.pyplot as plt from patchify import patchify, unpatchify # pip install patchify
Created May 29, 2021 10:22
A guide on Colab TPU training using PyTorch XLA (Part 5.2)
This file contains 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
 !wget http://www.some_dataset_website.com/my_dataset.tar.gz !tar -xvzf my_dataset.tar.gz
Created May 29, 2021 07:09
A guide on Colab TPU training using PyTorch XLA (Part 5.1)
This file contains 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
 PATH = "./my_dataset/" # path to dataset on Colab instance TRAIN_PATH = PATH + "train/" VAL_PATH = PATH + "val/" # your custom augmentations T = transforms.Compose([ transforms.ToTensor(), ... ])
Created May 29, 2021 07:02
A guide on Colab TPU training using PyTorch XLA (Part 9)
This file contains 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
 ''' Configures some pipeline hyper-parameters. You can set them to whatever you please. You have the option of either mentioning it here or creating variables inside the map_fn function. This is entirely up to you. I do both for demonstration purposes. '''
Created May 29, 2021 06:46
A guide on Colab TPU training using PyTorch XLA (Part 8)
This file contains 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
 # hlper function to get the testing accuracy at the end of the epoch def get_test_stats(model, loader): total_samples = 0 correct = 0 model.eval() # switch to eval mode for (batch_idx, data) in enumerate(loader, 0): x, y = data logits = model(x) preds = torch.argmax(logits, 1)
Created May 29, 2021 06:31
A guide on Colab TPU training using PyTorch XLA (Part 7)
This file contains 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
 device = xm.xla_device() # define some hyper-params you'd feed into your model in_channels = ... random_param = ... # create model using appropriate hyper-params net = MyCustomNet(...) # seat it atop the TPU worker device and switch it to train mode