Skip to content

Instantly share code, notes, and snippets.

View yzhangcs's full-sized avatar
:octocat:
Focusing

Yu Zhang yzhangcs

:octocat:
Focusing
View GitHub Profile
# -*- coding: utf-8 -*-
import torch
import triton
import triton.language as tl
@triton.jit
def cumsum_matmul_kernel(
s,
@yzhangcs
yzhangcs / rmsnorm.py
Last active December 17, 2023 07:40
Fused RMSNorm written by triton, a drop in replacement for LLaMA version
# -*- coding: utf-8 -*-
import torch
import torch.nn as nn
import triton
import triton.language as tl
from transformers.models.llama.modeling_llama import LlamaRMSNorm
@triton.jit
# -*- coding: utf-8 -*-
from typing import Optional, Tuple
import torch
import torch.nn as nn
import triton
import triton.language as tl
from transformers.models.llama.modeling_llama import (LlamaAttention,
apply_rotary_pos_emb,
@yzhangcs
yzhangcs / transformer.py
Created August 22, 2022 10:00
Relation aware Transformer
# -*- coding: utf-8 -*-
from __future__ import annotations
import copy
from typing import Optional
import torch
import torch.nn as nn
import torch.nn.functional as F
@yzhangcs
yzhangcs / color.py
Created August 9, 2022 13:02 — forked from minism/color.py
python terminal colors
# Terminal color definitions
class fg:
BLACK = '\033[30m'
RED = '\033[31m'
GREEN = '\033[32m'
YELLOW = '\033[33m'
BLUE = '\033[34m'
MAGENTA = '\033[35m'
CYAN = '\033[36m'
@yzhangcs
yzhangcs / papers.py
Last active January 20, 2022 07:29
Script for crawling daily CL/ML/CV papers on arxiv
# -*- coding: utf-8 -*-
import re
from datetime import datetime, timedelta
import arxiv
KEYS = ['adversarial', 'algebraic', 'algebratic', 'amr', 'auto-encoding', 'autoencoder', 'autoencoding', 'autoregressive',
'backward', 'bayes', 'bayesian', 'bethe', 'bilexical', 'bipartite', 'bregman', 'carlo', 'chomsky', 'circuit', 'clique',
@yzhangcs
yzhangcs / semiring.py
Created May 15, 2021 15:20
Semirings
# -*- coding: utf-8 -*-
from functools import reduce
import torch
import torch.autograd as autograd
from supar.utils.common import MIN
from torch.autograd import Function
@yzhangcs
yzhangcs / translate.py
Created January 7, 2021 09:57
Script for translation
# -*- coding: utf-8 -*-
import argparse
from functools import partial
from multiprocessing.dummy import Pool
import nltk
from google_trans_new import google_translator
from tqdm import tqdm
@yzhangcs
yzhangcs / paraphrase.py
Last active December 2, 2022 12:54
Paraphrase data via back-translation using Google Translation
# -*- coding: utf-8 -*-
import argparse
from functools import partial
from multiprocessing.dummy import Pool
import nltk
from google_trans_new import google_translator
from tqdm import tqdm
@yzhangcs
yzhangcs / eval.py
Created October 29, 2020 14:36
Script for evaluating conll file
# -*- coding: utf-8 -*-
import argparse
from collections import Counter
def factorize(tags):
spans = []
for i, tag in enumerate(tags):
if tag.startswith(('B', 'S')):