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)
# The CNN takes partitioned input as well as the input with lower resolution, and no communication is made between each VM
'''VGG11/13/16/19 in Pytorch.'''
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.backends.cudnn as cudnn
import random
import numpy as np
from input_activation import Lossy_Linear, Lossy_Quant_Linear, Masked_Linear
# coding:utf-8
from turtle import *
def nose(x,y):#鼻子
pu()
goto(x,y)
pd()
seth(-30)
begin_fill()
a=0.4
import tensorflow as tf
import matplotlib as mpl
import matplotlib.pyplot as plt
from math import sqrt
%matplotlib inline
import seaborn as sns
#sns.set_palette(sns.color_palette("cubehelix"))
sns.set_palette(sns.color_palette("coolwarm",9))
config = tf.ConfigProto(
device_count = {'GPU': 0}
class FoldedConv2d(torch.nn.Module):
def __init__(self, in_channels, out_channels, kernel_size, stride=1,
padding=1, affine=True, bias=True, use_running=False):
super(FoldedConv2d, self).__init__()
self.use_running = use_running
self.bn = torch.nn.BatchNorm2d(out_channels, affine=affine)
self._weight = nn.Parameter(torch.Tensor(out_channels, in_channels, kernel_size, kernel_size))
n = kernel_size * kernel_size * out_channels
self._weight.data.normal_(0, math.sqrt(2. / n))
self._bias = nn.Parameter(torch.Tensor(out_channels))
@XinDongol
XinDongol / fold_bn.py
Last active October 17, 2018 03:47
fold bn
import torch
import torchvision
import numpy as np
class Fold_BN_v1(torch.nn.Module):
'''
Do fold bn with conv.
You can change conv with any other layers
we assume that:
@XinDongol
XinDongol / HWGQ-TF.py
Created October 8, 2018 23:44
HWGQ-TF
def get_hwgq(bitA):
def quantize(x, k):
# in order of
assert k in [2,3,4,5], 'Does not support %d bits' % k
code_book={
'2':[0.5380, 0., 0.5380*(2**2-1)],
'3':[0.3218, 0., 0.3218*(2**3-1)],
'4':[0.1813, 0., 0.1813*(2**4-1)],
'5':[0.1029, 0., 0.1029*(2**5-1)]
1.认为要准备好了再做
持续地觉得自己还没准备好,遇到新的挑战(同时也是机会),本能的想自己还没学过(就像学校里读书时突然遇到了一个还没学到的内容),回避,总觉得要自己准备好了才行,但是却因此错过了机会。很多时候,是你有了责任,有了目标,才会让自己更强大,而不是自己强大了再做某事。永远让事情推些自己走才好。
2.被动接受,而不是主动获取
习惯了老师留作业,但工作了,很多地方的工作并没有那么确切和严丝合缝,需要自己发挥。等待着被布置任务,也没有错,但是这就是泯然众人的做法。那些在职场上有突破的人,往往都更主动,他们不会羞涩于请教、不会因为担心麻烦人而影响工作,他们只是聚焦在如何让工作更好,所以积极主动。不要小看主动的力量。
3.不愿意面对不可预期的逆境
很多人习惯了学生时代的感觉,习惯了确定性的事物,却不知道,工作中有很多非确定性。你总是在面对各种未知的问题,有问题,就要解决问题。有些人面对这样的逆境时,不够坚韧,更喜欢逃避,很难承担更大的责任,职场的发展就会受限。
4.小孩子脾气
不要把无知当个性,不要把口无遮拦当做直爽。其他人没有那么多时间了解你丰富的内心,大家更想配合好尽快把事情做完。有个性和脾气不是不可以,是建立在你自身的本事和成绩的基础上。恃才傲物其实还可以接受,但没有足够的能力和成果支撑还自我中心,就是会被嫌弃的节奏。
5.过于放大自己的价值
自信心不强经常容易遇到,但是还有另一种极端的情况,就是过于放大自己的价值。其实一个新人在组织里,既有自己的努力,也要依赖组织提供的机会。我们常常说,要从小事做起,其实就是在攒人品,让别人逐步信任你。其实我们往往没有想象中那么重要,只是大家已经积累起来的信任链条。不卑不亢,才是合适的风格。
name: "LeNet-HWGQ"
layer {
name: "mnist"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
# coding: utf-8
import numpy as np
import torch
import torch.nn as nn
from torch.nn import Module
from torch.autograd import Function
class Hwhq(Module):