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
# 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 |
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
find . -type f -print0 | xargs -0 perl -pi -e 's/ +$//' | |
https://stackoverflow.com/questions/149057/how-to-remove-trailing-whitespace-of-all-files-recursively |
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
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! |
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
# (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): |
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 | |
from torch.autograd import Function | |
class PassThrough(Function): | |
@staticmethod | |
def forward(ctx, *inputs): | |
return inputs |
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 | |
from torch.autograd import Function | |
class PassThrough(Function): | |
@staticmethod | |
def forward(ctx, *inputs): | |
return inputs |
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 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 |
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
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}") |
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
find . -name '*.cpp' -type f -print0 | xargs -0 sed -i 's/c10::static_intrusive_pointer_cast<c10::RRefInterface>/fromOwnerRRef/g' |
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 | |
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 |
NewerOlder