Goals: Add links that are reasonable and good explanations of how stuff works. No hype and no vendor content if possible. Practical first-hand accounts of models in prod eagerly sought.
| #!/usr/bin/env python | |
| import math | |
| import matplotlib.pyplot as plt | |
| import torch | |
| import torch.nn as nn | |
| from sklearn.datasets import make_moons | |
| from torch import Tensor | |
| from tqdm import tqdm |
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| from argparse import ArgumentParser | |
| import torch | |
| import torch.distributed as dist | |
| from torch.nn.parallel import DistributedDataParallel as DDP | |
| from torch.utils.data import DataLoader, Dataset | |
| from torch.utils.data.distributed import DistributedSampler | |
| from transformers import BertForMaskedLM |
Typical closure invocation (without gradient scaling) looks like
for input, target in dataset:
def closure():
optimizer.zero_grad()
output = model(input)
loss = loss_fn(output, target)
loss.backward()
return loss
loss = optimizer.step(closure)| import torch | |
| from torch import nn | |
| from torch.autograd import Variable | |
| import torch.nn.functional as F | |
| import torch.optim as optim | |
| # toy feed-forward net | |
| class Net(nn.Module): | |
| def __init__(self): |
If you’ve tried recently to install matlab engine on a Python 3.6, you’ve seen a message saying that the platform is not supported. That doesn’t make any sense, since Python 3.5 is supported, right?
The problem is that Mathworks hardcodes a list with valid versions, I guess to reduce pressure on their customer service in case something goes wrong with untested versions. Well, that doesn’t mean that we shouldn’t be allowed to try it anyway, right?
| from scipy.spatial.distance import pdist, squareform | |
| import numpy as np | |
| from numbapro import jit, float32 | |
| def distcorr(X, Y): | |
| """ Compute the distance correlation function | |
| >>> a = [1,2,3,4,5] | |
| >>> b = np.array([1,2,9,4,4]) |
| """ Module to compute projections on the positive simplex or the L1-ball | |
| A positive simplex is a set X = { \mathbf{x} | \sum_i x_i = s, x_i \geq 0 } | |
| The (unit) L1-ball is the set X = { \mathbf{x} | || x ||_1 \leq 1 } | |
| Adrien Gaidon - INRIA - 2011 | |
| """ |