Skip to content

Instantly share code, notes, and snippets.

View rish-16's full-sized avatar
🤖
backpropagating through memories

Rishabh Anand rish-16

🤖
backpropagating through memories
View GitHub Profile
@rish-16
rish-16 / ma2108_note1.md
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$
@rish-16
rish-16 / cs4243.py
Last active March 29, 2022 06:16
CS4243 PyTorch Snippets
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]
@rish-16
rish-16 / leetcode.md
Last active August 3, 2024 01:38
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

@rish-16
rish-16 / tf_seed.py
Created July 5, 2021 05:30
TensorFlow Experiment Seeding for GPUs
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)
@rish-16
rish-16 / patch_viz.py
Last active December 22, 2021 06:39
Visualise selected patches from an image for comparison / sanity checks
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
@rish-16
rish-16 / download.py
Created May 29, 2021 10:22
A guide on Colab TPU training using PyTorch XLA (Part 5.2)
!wget http://www.some_dataset_website.com/my_dataset.tar.gz
!tar -xvzf my_dataset.tar.gz
@rish-16
rish-16 / dataset_dwnld_dir.py
Created May 29, 2021 07:09
A guide on Colab TPU training using PyTorch XLA (Part 5.1)
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(),
...
])
@rish-16
rish-16 / spawn.py
Created May 29, 2021 07:02
A guide on Colab TPU training using PyTorch XLA (Part 9)
'''
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.
'''
@rish-16
rish-16 / train.py
Created May 29, 2021 06:46
A guide on Colab TPU training using PyTorch XLA (Part 8)
# 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)
@rish-16
rish-16 / model.py
Created May 29, 2021 06:31
A guide on Colab TPU training using PyTorch XLA (Part 7)
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