Skip to content

Instantly share code, notes, and snippets.

View krishvishal's full-sized avatar
💭
🦀

Krishna Vishal krishvishal

💭
🦀
View GitHub Profile
@krishvishal
krishvishal / rdiff_test.jl
Created August 11, 2020 11:01
This file has a function f(x) and I use ReverseDiff to calculate gradient of that function. If ReveseDiff is really the problem, this shouldn't run successfully.
using ReverseDiff
f(x) = maximum(x;dims=1)
if abspath(PROGRAM_FILE) == @__FILE__
x = rand(3, 3)
println(x)
println(ReverseDiff.gradient(sum∘f, x))
end
@krishvishal
krishvishal / getsize.py
Created November 14, 2019 09:40
Size of a python object even with recursive encapsulation
def getsize(obj_0):
"""Recursively iterate to sum size of object & members."""
_seen_ids = set()
def inner(obj):
obj_id = id(obj)
if obj_id in _seen_ids:
return 0
_seen_ids.add(obj_id)
size = sys.getsizeof(obj)
if isinstance(obj, zero_depth_bases):
@krishvishal
krishvishal / plot_kernels.py
Last active October 22, 2022 18:27
Visualize weights in pytorch
from model import Net
from trainer import Trainer
import torch
from torch import nn
from matplotlib import pyplot as plt
model = Net()
ckpt = torch.load('path_to_checkpoint')
model.load_state_dict(ckpt['state_dict'])
filter = model.conv1.weight.data.numpy()