Skip to content

Instantly share code, notes, and snippets.

View rohan-varma's full-sized avatar

Rohan Varma rohan-varma

View GitHub Profile
# Given r, real number in [0, inf)
# Return the sqrt of r without sqrt function
def _mid(left, right):
# Avoiding possible overflow that
# l + r / 2 could cause
return (right - left)/2 + left
def sqrt(r):
# Assumption: r is real and >= 0
find . -type f -print0 | xargs -0 perl -pi -e 's/ +$//'
https://stackoverflow.com/questions/149057/how-to-remove-trailing-whitespace-of-all-files-recursively
sed -i '1 i\#!/bin/bash' *.sh --> sed -i keep the change in file, don't write to stdout. 1: when sed is on the first line, i - insert following line, *.sh - files which to sed!
# (c) Facebook, Inc. and its affiliates. Confidential and proprietary.
import torch
import torch.nn as nn
from torch.autograd import Function
class PassThrough(Function):
@staticmethod
def forward(ctx, *inputs):
import torch
import torch.nn as nn
from torch.autograd import Function
class PassThrough(Function):
@staticmethod
def forward(ctx, *inputs):
return inputs
import torch
import torch.nn as nn
from torch.autograd import Function
class PassThrough(Function):
@staticmethod
def forward(ctx, *inputs):
return inputs
import argparse
import os
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
import torch
#print(torch.__file__) ; exit()
import torch.nn as nn
import torch.nn.parallel
import torch.distributed as dist
import torch.multiprocessing as mp
for mn, m in net.named_modules():
for param_name, param in m.named_parameters(recurse=False):
qualname = f"{mn}.{param_name}"
print(f"Got qualname {qualname}")
@rohan-varma
rohan-varma / sed.sh
Created February 12, 2021 03:34
Example sed command to sed for all cpp files
find . -name '*.cpp' -type f -print0 | xargs -0 sed -i 's/c10::static_intrusive_pointer_cast<c10::RRefInterface>/fromOwnerRRef/g'
import torch
import torch.nn as nn
def get_param_to_grad_accs(model):
param_to_grad_accs = {}
for param in model.parameters(recurse=True):
param_tmp = param.expand_as(param)
grad_acc = param_tmp.grad_fn.next_functions[0][0]
param_to_grad_accs[param] = grad_acc
return param_to_grad_accs