Skip to content

Instantly share code, notes, and snippets.

@rahulvigneswaran
rahulvigneswaran / GPU_selector.py
Created November 8, 2019 10:45
Select GPU in Pytorch
import os
parser = argparse.ArgumentParser()
parser.add_argument("--gpu", default="0", type=str)
args = parser.parse_args()
@rahulvigneswaran
rahulvigneswaran / gpu_with_username.txt
Created November 17, 2019 16:45
Gives you a list of GPUs on a SSH server with its Users' names.
Check this repo :
https://github.com/mseitzer/gpu-monitor
import os
import numpy as np
from scipy.stats import wasserstein_distance, energy_distance
from matplotlib import pyplot as plt
epoch_name = "epoch_1_"
epoch = 1
a = os.getcwd()
root, dirs, files = next(os.walk(a))
import os
import numpy as np
from scipy.stats import wasserstein_distance, energy_distance
from matplotlib import pyplot as plt
epoch_name = "epoch_1_"
epoch = 1
a = os.getcwd()
root, dirs, files = next(os.walk(a))
@rahulvigneswaran
rahulvigneswaran / print_nonzeros_table.py
Created October 1, 2019 06:17
The following function displays the count of zero and non-zero weights in a Pytorch model.
def print_nonzeros(model):
nonzero = total = 0
for name, p in model.named_parameters():
tensor = p.data.cpu().numpy()
nz_count = np.count_nonzero(tensor)
total_params = np.prod(tensor.shape)
nonzero += nz_count
total += total_params
print(f'{name:20} | nonzeros = {nz_count:7} / {total_params:7} ({100 * nz_count / total_params:6.2f}%) | total_pruned = {total_params - nz_count :7} | shape = {tensor.shape}')
print(f'alive: {nonzero}, pruned : {total - nonzero}, total: {total}, Compression rate : {total/nonzero:10.2f}x ({100 * (total-nonzero) / total:6.2f}% pruned)')
@rahulvigneswaran
rahulvigneswaran / custom_subset-pytorchforum.ipynb
Last active March 13, 2021 13:18
Custom_Subset [PyTorchForum].ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rahulvigneswaran
rahulvigneswaran / ImageNet2012_WordNet_SynsetID_To_ClassNames.txt
Created October 11, 2021 22:04
Instruction to get class names for the corresponding WordNet ID of ImageNet 2012 AKA ILSVRC2012 data set
# First run the following things
echo "Downloading..."
wget -c http://dl.caffe.berkeleyvision.org/caffe_ilsvrc12.tar.gz
echo "Unzipping..."
tar -xf caffe_ilsvrc12.tar.gz && rm -f caffe_ilsvrc12.tar.gz
echo "Done."
#!/bin/bash
#
# script to download and extract ImageNet dataset
# ILSVRC2012_img_train.tar (about 138 GB)
# ILSVRC2012_img_val.tar (about 6.3 GB)
#
# make sure ILSVRC2012_img_train.tar & ILSVRC2012_img_val.tar in your current directory
#
# https://github.com/facebook/fb.resnet.torch/blob/master/INSTALL.md
#
@rahulvigneswaran
rahulvigneswaran / welcome_to_DGX-IITH.md
Last active February 7, 2022 12:52
This gist is for newbies of server 93 (DGX) at IIT Hyderabad.

Table of Contents

CPU

  • Dont use CPUs to train. This will slow experiments of others drastically. Almost always try to run your exps on GPUs excluding certain edge cases.

GPU

  • Before you start a run on a GPU that someone else is already using, please do try and run first on an empty GPU, to check the GPU memory your experiment will occupy. If it exceeds the available memory (Use gpustat --watch to find the usage), PLEASE DONT RUN ON IT. This will crash the other person's runs.