Skip to content

Instantly share code, notes, and snippets.

View Lyken17's full-sized avatar
🎯
Focusing

Ligeng Zhu Lyken17

🎯
Focusing
View GitHub Profile
import os, os.path as osp
import json
from copy import deepcopy
import numpy as np
from copy import deepcopy
import torch
import torch.nn as nn
@Lyken17
Lyken17 / sub-c-poc.py
Created May 4, 2022 13:13
training information
from tokenize import group
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.utils import _single, _pair, _triple
import warnings
from torch.nn.grad import _grad_input_padding
@torch.no_grad()
@Lyken17
Lyken17 / quantize.py
Created April 10, 2022 05:35
quick-quantize-impl
import torch
import torch.nn as nn
import torch.nn.functional as F
def serialize(raw_idx):
raw_idx = raw_idx.clone()
# put 3 int10 into one int32
d = raw_idx.view(-1, 3)
d[:, 0] = d[:, 0] << 20
import os
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
import tvm
from tvm import relay, autotvm, auto_scheduler
import tvm.relay.testing
@Lyken17
Lyken17 / cross_entropy.py
Last active March 14, 2022 22:05
pytorch cross entropy with logitis
import torch
import torch.nn as nn
import torch.nn.functional as F
# pytorch way
input = torch.randn(3, 5)
target = torch.randint(5, (3,), dtype=torch.int64)
loss1 = F.cross_entropy(input, target)
## equal with cross_entropy_with_logits
@Lyken17
Lyken17 / zmq_numpy.py
Created March 4, 2022 12:30
ZMQ numpy example
import pickle
import zlib
import sys
import numpy as np
import zmq
@Lyken17
Lyken17 / pth_override.py
Created February 25, 2022 16:35
override example
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch import autograd
net = nn.Sequential(
nn.Linear(20, 30),
nn.Linear(30, 40)
)
@Lyken17
Lyken17 / pth-tvm-mbv2.py
Last active January 24, 2022 17:46
test mbv2 numerical issue
import torch
import torch.nn as nn
import torchvision
from torchvision import models
import numpy as np
import tvm
from tvm import relay
from tvm.contrib import graph_executor
@Lyken17
Lyken17 / fuse-bn.py
Last active March 2, 2022 04:13
[pytorch] Fuse Conv2d and BatchNorm at module level
import torch
import torch.nn as nn
from torchvision import models
from torchvision.models.resnet import BasicBlock, ResNet
def remove_dropout(module):
module_output = module
if isinstance(module, (nn.Dropout)):
print("removing dropout")
@Lyken17
Lyken17 / satori.md
Last active November 29, 2021 12:17
Satori Use Tips

Launch an interactive Job

srun --gres=gpu:4 -N 1 --mem=1T --time 1:00:00 -I --pty /bin/bash

Submit a job

Cancel a job

scancel <jobnumber>

Check the job queue