Skip to content

Instantly share code, notes, and snippets.

View XinDongol's full-sized avatar
🏁
Loading...

Xin (Simon) Dong XinDongol

🏁
Loading...
View GitHub Profile
@XinDongol
XinDongol / profile_pyt.md
Last active March 28, 2022 11:26
How to profile your pytorch codes

Inside profiler

import torch
import torchvision.models as models

model = models.densenet121(pretrained=True)
x = torch.randn((1, 3, 224, 224), requires_grad=True)

with torch.autograd.profiler.profile(use_cuda=True) as prof:
    model(x)
from torch.autograd import Variable
import torch
from torch import nn
from collections import OrderedDict
from IPython import embed
from torch.autograd.function import InplaceFunction, Function
import torch.nn.functional as F
import math

GPU

GeForce GTX 1080 Ti Mem: 12GB

CPU

processor : 15 vendor_id : GenuineIntel cpu family : 6 model : 63 model name : Intel(R) Core(TM) i7-5960X CPU @ 3.00GHz stepping : 2 microcode : 0x3d

%% parameters
delta = 0.5;
a2 = 0.1;
a1 = 100;
number_of_pieces = 100; % number of pieces we want to divide
%%
b2 = delta/tanh(a2*delta);
b1 = delta/tanh(a1*delta);
thres_min = zeros(1,number_of_pieces)+1000;
amin = zeros(1,number_of_pieces);
\usepackage{soul}
\newcommand{\xinc}[1]{\textcolor{blue}{[Xin:$\rightarrow$#1]}}
\newcommand{\xina}[1]{\textcolor{blue}{[Xin:$+$#1]}}
\newcommand{\xin}[1]{\textcolor{blue}{[Xin:#1]}}
\newcommand{\xind}[1]{\textcolor{blue}{[Xin:\st{#1}]}}
https://repl.it/
# coding:utf-8
from turtle import *
def nose(x,y):#鼻子
pu()
goto(x,y)
pd()
seth(-30)
import torch.nn as nn
import torch.nn.functional as F
import torch
class DeepInversionFeatureHook():
'''
Implementation of the forward hook to track feature statistics and compute a loss on them.
Will compute mean and variance, and will use l2 as a loss
'''
def __init__(self, module):
self.hook = module.register_forward_hook(self.hook_fn)
from graphviz import Digraph
from torch.autograd import Variable
import torch
def make_dot(var, params=None):
if params is not None:
assert isinstance(params.values()[0], Variable)
param_map = {id(v): k for k, v in params.items()}