Skip to content

Instantly share code, notes, and snippets.

@enhuiz
enhuiz / 0.95-confidence-interval.py
Last active March 28, 2023 08:28
95% confidence interval with the Normal approximation
import numpy as np
from scipy import stats
n_samples = 1001
samples = np.random.randn(n_samples)
print("Example samples: ", samples[:10])
# Compute the mean and standard deviation of the samples
mean = np.mean(samples)
@enhuiz
enhuiz / cool_adam.py
Created February 24, 2023 12:13
Use Adam in a wrong way.
import matplotlib.pyplot as plt
import torch
from celluloid import Camera
from torch import nn
linear = nn.Linear(2, 1, bias=False)
camera = Camera(plt.figure())
optimizer = torch.optim.Adam(linear.parameters(), 1)
@enhuiz
enhuiz / mnist.py
Last active October 6, 2022 13:54
Low Resource MNIST
import argparse
import torch
import numpy as np
import torch.nn as nn
import torch.nn.functional as F
from tqdm import tqdm, trange
from torch.nn.utils.weight_norm import weight_norm
from collections import defaultdict
from torch.utils.data import DataLoader
from torchvision import transforms
function registerPlugin(plugin) {
function registerPluginForIFrame() {
iframe = $('iframe[id="speedgrader_iframe"]');
iframe.load(() => {
plugin(iframe.contents());
});
}
// as the iframe of speed grader reloads for each different student,
// we need to register the listener for each iframe
@enhuiz
enhuiz / multigpu-matrix-multiplication.py
Last active November 16, 2020 12:09
multigpu-matrix-multiplication
import torch
import torch.nn as nn
from einops import rearrange
class MatrixMultiplication(nn.Module):
def __init__(self):
super().__init__()
def forward(self, x, y):
@enhuiz
enhuiz / sgs.py
Last active November 16, 2020 12:10
sgs.py
import torch
import torch.nn as nn
from torchvision.models import resnet18
def sample_mask(xl, p):
mask = []
for l in xl:
idx = torch.randperm(l)
idx = idx[: int(l * p)]
@enhuiz
enhuiz / intel-nvidia.md
Created June 24, 2020 08:50 — forked from wangruohui/intel-nvidia.md
Intel for display, Nvidia for computing

Intel for display, NVIDIA for computing

This guide will show you how to use Intel graphics for rendering display and NVIDIA graphics for CUDA computing on Ubuntu 18.04 desktop.

I made this work on an ordinary gaming PC with two graphics devices, an Intel UHD Graphics 630 plus an NVIDIA GeForce GTX 1080 Ti. Both of them can be shown via lspci | grep VGA.

00:02.0 VGA compatible controller: Intel Corporation Device 3e92
01:00.0 VGA compatible controller: NVIDIA Corporation GP102 [GeForce GTX 1080 Ti] (rev a1)