Skip to content

Instantly share code, notes, and snippets.

View w32zhong's full-sized avatar
⛹️
Trying to keep up.

Wei w32zhong

⛹️
Trying to keep up.
View GitHub Profile
@I.ir_module
class Module:
@T.prim_func
def main(var_A: T.handle, B: T.Buffer((768, 384), "int8"), Scale: T.Buffer((768, 3), "float16"), Zeros: T.Buffer((768, 3), "float16"), var_D: T.handle):
T.func_attr({"dequantize_info": {"B_decode": {"decode_block": "B_decode", "fast_decoding": T.bool(False), "group_size": 256, "source_format": {"bits": 4, "format": "uint"}, "storage_dtype": "int8", "target_format": "float16", "with_scaling": T.bool(True), "with_zeros": T.bool(True), "zeros_mode": "rescale"}}, "dlight.tensorcore_prenormlized": T.bool(True), "opt_shapes": {"m": [2, 12]}, "tir.is_scheduled": 1, "tir.noalias": T.bool(True)})
m = T.int32()
A = T.match_buffer(var_A, (m, 768), "float16")
D = T.match_buffer(var_D, (m, 768), "float16")
# with T.block("root"):
A_reindex_pad_shared_dyn = T.alloc_buffer((1, (m + 127) // 128 * 128, 768), "float16", scope="shared.dyn")
%pip install ipympl
%matplotlib ipympl
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
# draw initial triangle
triangle = np.array([
[1, 4, 1, 1],
@w32zhong
w32zhong / bark.py
Last active May 15, 2023 21:37
Bark
# pip install git+https://github.com/suno-ai/bark.git && pip uninstall -y torch torchvision torchaudio && pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu118
text_prompt = """
For all neural retrievers, we fine-tune them on top of a further-pretrained backbone using a batched triplets.
It contains a query q, and a pair of positive and negative passages, p plus and p minus.
we use passages of other training instances as additional negatives, which is a common practice to get more training samples for free, basically.
"""
from bark import SAMPLE_RATE, generate_audio, preload_models
@w32zhong
w32zhong / build.sh
Last active May 11, 2023 02:53
Build PyTorch 2.0
# clone pytorch at b004c0b3c6a1ee39ba0b512a00d95e7f83852556 with all submodules.
git clone -b main --recursive https://github.com/pytorch/pytorch
cd pytorch
inotifywait --event create -rm /home/tk/anaconda3/envs/pytorch-ref/
conda deactivate
conda env remove -n pytorch-src
conda create -n pytorch-src python=3.11
conda create --name llama -c conda-forge python=3.8
conda activate llama
pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu118
python -c 'import torch; print(torch.cuda.is_available())'
conda install -c conda-forge gxx_linux-64=10.4.0
conda install cuda -c nvidia/label/cuda-11.8.0
#pip install packaging flash-attn
@w32zhong
w32zhong / Treap.py
Created February 28, 2023 17:14 — forked from irachex/Treap.py
Treap (tree + heap) in Python
import random
class TreapNode(object):
def __init__(self, key, data):
self.key = key
self.ran = random.random()
self.size = 1
self.cnt = 1
self.data = data
self.left = None
import torch
from torch import nn
import transformers
from transformers import BertLayer
from transformers.models.bert.modeling_bert import BertOnlyMLMHead
from transformers import BertTokenizer
from transformers import BertForPreTraining
class CondensorPretraining(nn.Module):
def __init__(self, n_dec_layers=2, skip_from=0):
@w32zhong
w32zhong / k2pdfopt.sh
Last active June 12, 2023 04:20
Use k2pdfopt copy mode for Kindle view
# Download the binary from:
#
# and chmod +x.
k2pdfopt -ui- -mode copy -x ./eqEmb.pdf
k2pdfopt -ui- -mode copy -x -p 679-707 ./d2l-zh-pytorch.pdf
# sudo pacman -S pdftk
pdftk pml1_k2opt.pdf cat 1-338 output pml1_k2opt_chap1_Foundations.pdf
ps -up `nvidia-smi -q -x | grep -Po '(?<=<pid>)[0-9]+'`
@w32zhong
w32zhong / gist:143c2b912ce8c6630963fad488885e72
Last active April 17, 2022 10:46
Build Faiss-cpu on IBM Power9 CPU
# See https://github.com/facebookresearch/faiss/blob/main/INSTALL.md#step-1-invoking-cmake
PREFIX=/gpfs/fs1/home/j/jimmylin/w32zhong/.conda/envs/py38/powerpc64le-conda_cos7-linux-gnu
#MYLIB=/gpfs/fs1/home/j/jimmylin/w32zhong/OpenBLAS-0.3.17/libopenblas.a
MYLIB=/gpfs/fs1/home/j/jimmylin/w32zhong/faiss/flexiblas-3.0.3/build/lib/libflexiblas.so
module load cmake/3.19.8
cmake -B build . -DFAISS_ENABLE_GPU=OFF -DBLAS_LIBRARIES=$MYLIB -DLAPACK_LIBRARIES=$MYLIB -DBUILD_SHARED_LIBS=OFF
make -C build -j faiss VERBOSE=1