Skip to content

Instantly share code, notes, and snippets.

View mfkasim1's full-sized avatar

Muhammad Firmansyah Kasim mfkasim1

View GitHub Profile
@mfkasim1
mfkasim1 / nvidia-checking-commands.md
Last active August 3, 2020 09:47
NVIDIA GPU checking commands

Check available NVIDIA

lspci | grep -i nvidia

Check NVIDIA driver version

cat /proc/driver/nvidia/version

Display log for drivers

@mfkasim1
mfkasim1 / jacobian.py
Created December 27, 2019 18:08
Calculate Jacobian matrix in PyTorch
def bjac(gy, y):
"""
Get the batched Jacobian matrix for vector-valued output, gy, with respect to the input, y.
The Jacobian output will take shape of (nbatch, *gy.shape[1:], *y.shape[1:])
"""
# reshape gy to be batched 1D vector
ggy = gy.view(gy.shape[0], -1)
outshape = (gy.shape[0], *gy.shape[1:], *y.shape[1:])
nbatch, nfout = ggy.shape
@mfkasim1
mfkasim1 / eig.py
Created January 23, 2020 14:11
Differentiable torch.eig() for real eigenvalues
import torch
class eig(torch.autograd.Function):
@staticmethod
def forward(ctx, A):
# normalize the shape to be batched
Ashape = A.shape
if A.ndim == 2:
A = A.unsqueeze(0)
elif A.ndim > 3:
@mfkasim1
mfkasim1 / guide.md
Last active July 26, 2020 10:58
Step by step in starting a deep learning project (pytorch)

Supervised learning

  • Create the Dataset object and test if it can load the data correctly
  • Create the transformation (in DataLoader) for the Dataset
  • Create a model and test if the DataLoader can feed the data to the model
  • Create the training procedure

Tips

Datasets
@mfkasim1
mfkasim1 / python_numpy_tricks.py
Last active July 7, 2020 14:56
Various python/numpy/matplotlib/scipy tricks
# plot histogram with logscale in the x-axis
import numpy as np
import matplotlib.pyplot as plt
def plot_loghist(x, bins=30, **hist_kwargs):
hist, bins = np.histogram(x, bins=bins)
logbins = np.logspace(np.log10(bins[0]),np.log10(bins[-1]),len(bins))
plt.hist(x, bins=logbins, **hist_kwargs)
plt.xscale('log')
# silencing loud third-party library
@mfkasim1
mfkasim1 / debug_multilevel_grad.py
Created August 21, 2020 17:37
Debugging multilevel autograd for anomaly detection
"""
Gradph object can be used to debug multi-level autograd for anomaly detection.
To see an example on how to use this, see the bottom of this script.
"""
import torch
class GradphNode(object):
def __init__(self, gfn, parent_node):
self._gfn = gfn
@mfkasim1
mfkasim1 / useful_git_commands.md
Created December 12, 2022 14:41
Useful git commands

These are the git commands I usually use (for self-reminder), sorted from the most-used ones:

  1. git status: to see the states
  2. git log --oneline: to see which commit I'm at
  3. git add <filename(s)>: to stage a file(s)
  4. git commit -m "<Some message>": to make a commit
  5. git push: push the latest update to the remote
  6. git pull: pull the latest states from the remote
  7. git clone <repo_url>: clone a new repository
  8. git diff : to see which lines in the file that haven't been staged
// g++ -O2 div-avx.cc -I/home/muhammad/libs/sleef/include/ -mavx -L/home/muhammad/libs/sleef/lib/ -lsleef
#include <immintrin.h>
#include <sleef.h>
#include <chrono>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <complex>