Skip to content

Instantly share code, notes, and snippets.

View xmfbit's full-sized avatar

xmfbit xmfbit

  • Bytedance
  • Beijing,China
View GitHub Profile
@xmfbit
xmfbit / model.py
Last active March 5, 2023 17:03
ResNet-164 training experiment on CIFAR10 using PyTorch, see the paper: Identity Mappings in Deep Residual Networks
import torch
import torch.nn as nn
import math
## the model definition
# see HeKaiming's implementation using torch:
# https://github.com/KaimingHe/resnet-1k-layers/blob/master/README.md
class Bottleneck(nn.Module):
expansion = 4 # # output cahnnels / # input channels
@xmfbit
xmfbit / model.py
Created September 27, 2017 02:25
A simple example of DCGAN on MNIST using PyTorch
import torch
import torch.nn as nn
import torch.nn.functional as F
def init_weight(m):
classname = m.__class__.__name__
if classname.find('Conv') != -1:
m.weight.data.normal_(0., 0.02)
elif classname.find('BatchNorm') != -1:
m.weight.data.normal_(1., 0.02)
@xmfbit
xmfbit / data.py
Created September 27, 2017 02:38
Char level RNN generator
import os
class CharDataset(object):
def __init__(self, path):
if not os.path.exists(path):
raise RuntimeError('Cannot open the file: {}'.format(path))
self.raw_data = open(path, 'r').read()
self.chars = list(set(self.raw_data))
self.data_size = len(self.raw_data)
print('There are {} characters in the file'.format(self.data_size))
@xmfbit
xmfbit / fuse_conv_bn_in_torch_module.py
Created October 18, 2021 18:25
example of torch.fx, showing how to fuse the conv-bn module groups
""" Fuse conv-bn pattern in torch.Module, an example for torch.fx
see: https://pytorch.org/tutorials/intermediate/fx_conv_bn_fuser.html
"""
import copy
from typing import Tuple, Dict, Any
import torch
import torch.fx as fx
import torch.nn as nn