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
# ---------------------- | |
# Git Aliases | |
# ---------------------- | |
alias ga='git add' | |
alias gaa='git add .' | |
alias gaaa='git add --all' | |
alias gau='git add --update' | |
alias gb='git branch' | |
alias gbd='git branch --delete ' | |
alias gc='git commit' |
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
def test_function(test_case): | |
move_zeros_to_left(test_case[0]) | |
if test_case[0] == test_case[1]: | |
print("Pass") | |
else: | |
print("Fail") |
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
def move_zeros_to_left(array): | |
i = len(array) - 1 | |
j = len(array) - 1 | |
while i >= 0: | |
if array[i] != 0: | |
array[j] = array[i] | |
j -= 1 | |
i -= 1 | |
while j >= 0: | |
array[j] = 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
# Save checkpoint | |
checkpoint = { | |
'model': model.state_dict(), | |
'optimizer': optimizer.state_dict(), | |
'amp': amp.state_dict() | |
} | |
torch.save(checkpoint, 'amp_checkpoint.pt') | |
... | |
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
rank = args.nr * args.gpus + gpu | |
dist.init_process_group( | |
backend='nccl', | |
init_method='env://', | |
world_size=args.world_size, | |
rank=rank) | |
torch.manual_seed(0) | |
model = ConvNet() | |
torch.cuda.set_device(gpu) |
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
python src/mnist-distributed.py -n 4 -g 8 -nr i |
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
python src/mnist-distributed.py -n 4 -g 8 -nr 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
def train(gpu, args): | |
############################################################ | |
rank = args.nr * args.gpus + gpu | |
dist.init_process_group( | |
backend='nccl', | |
init_method='env://', | |
world_size=args.world_size, | |
rank=rank | |
) | |
############################################################ |
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
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-n', '--nodes', default=1, | |
type=int, metavar='N') | |
parser.add_argument('-g', '--gpus', default=1, type=int, | |
help='number of gpus per node') | |
parser.add_argument('-nr', '--nr', default=0, type=int, | |
help='ranking within the nodes') | |
parser.add_argument('--epochs', default=2, type=int, | |
metavar='N', |
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
def train(gpu, args): | |
torch.manual_seed(0) | |
model = ConvNet() | |
model = nn.DataParallel(model) | |
torch.cuda.set_device(gpu) | |
model.cuda(gpu) | |
batch_size = 100 | |
# define loss function (criterion) and optimizer | |
criterion = nn.CrossEntropyLoss().cuda(gpu) | |
optimizer = torch.optim.SGD(model.parameters(), 1e-4) |
NewerOlder