Skip to content

Instantly share code, notes, and snippets.

@yzh119
yzh119 / quine.c
Created April 2, 2021 05:47
My solution to quine program in C
#include <stdio.h>
char str[] = "#include <stdio.h>%cchar str[] = %c%s%c;%cint main() {%c printf(str, 10, 34, str, 34, 10, 10, 10);%c}";
int main() {
printf(str, 10, 34, str, 34, 10, 10, 10);
}
@yzh119
yzh119 / st-gumbel.py
Created January 12, 2018 12:25
ST-Gumbel-Softmax-Pytorch
from __future__ import print_function
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
def sample_gumbel(shape, eps=1e-20):
U = torch.rand(shape).cuda()
return -Variable(torch.log(-torch.log(U + eps) + eps))
@yzh119
yzh119 / retro-sparsetir-artifact.md
Last active February 21, 2023 00:20
Retrospective on SparseTIR artifact

Retrospective on SparseTIR artifact

Once SparseTIR was accepted to ASPLOS 2023, we began constructing the sparsetir-artifact repository for artifact evaluation. Though we already have lots of benchmarking scripts, we found it still not a trivial job to put them together and evaluate in a unified manner. While preparing our artifact, we also found some problems with our profiler and bugs in existing implementations. We carefully addressed these issues and standardized the settings for all baselines. We are writing this post to document the challenges we faced and the lessons we learned from creating the artifact. We aim to provide insight that will benefit researchers and engineers working in related fields.

Notes on performance difference

If you previously read our manuscript on ArXiv, you may have noticed that there are some discrepancies in the reported performance between SparseTIRv3 and our [camera-ready ver

@yzh119
yzh119 / cite-formatter.py
Created January 26, 2023 18:30
Automatically add `~` before each appearance of `\cite`
import os
import sys
import glob
import logging
logging.basicConfig(level=logging.INFO)
def fix_cite_format(line_number: int, line: str):
out = ""
@yzh119
yzh119 / dgl-transformer.py
Created December 3, 2020 09:03
Efficient Sparse Transformer implementation with DGL's builtin operators
import dgl
import dgl.ops as ops
import numpy as np
import torch as th
import torch.nn as nn
class FFN(nn.Module):
def __init__(self, d_feat, d_ffn, dropout=0.1):
super().__init__()
self.linear_0 = nn.Linear(d_feat, d_ffn)
@yzh119
yzh119 / buggy.py
Created August 5, 2021 08:00
ell spmm with multi-level tiling
import tvm
from tvm import tir
from tvm.script import ty
from tvm.tir.schedule.schedule import Schedule
@tvm.script.tir
def ell_spmm(indices_: ty.handle, a_data: ty.handle, b: ty.handle, c: ty.handle) -> None:
mb = tir.var('int32')
n = tir.var('int32')
@yzh119
yzh119 / tir_sparse.py
Created July 30, 2021 14:53
sparse workloads in tir
import tvm
from tvm import tir
from tvm.script import ty
@tvm.script.tir
def csr_spmm(indptr_: ty.handle, indices_: ty.handle, a_data: ty.handle, b: ty.handle, c: ty.handle) -> None:
m = tir.var('int32')
n = tir.var('int32')
k = tir.var('int32')
nnz = tir.var('int32')
@yzh119
yzh119 / quine.py
Created April 2, 2021 05:50
My solution to quine program in Python
prog = "prog = {:c}{}{:c}{:c}print(prog.format(34, prog, 34, 10))"
print(prog.format(34, prog, 34, 10))
@yzh119
yzh119 / dgl_sage_fp16.py
Last active October 12, 2020 07:03
Training GraphSAGE w/ fp16 in DGL.
"""Training graphsage w/ fp16.
Usage:
python train_full.py --gpu 0 --fp16 --dataset
Note that GradScaler is not acitvated because the model successfully converges
without gradient scaling.
DGL's Message Passing APIs are not compatible with fp16 yet, hence we disabled
@yzh119
yzh119 / convert.py
Created November 12, 2018 04:29
Conver RST file to sphinx-gallery `.py` format
"""
Usage:
python convert.py xxx.rst xxx.py
To convert markdown to sphinx_gallery `.py`, use pandoc to generate a `.rst` text in advance:
pandoc xxx.md --output xxx.rst
python convert.py xxx.rst xxx.py