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 glob
import orjson
import os
import datasets
from itertools import islice
_DESCRIPTION = """
@yzhangcs
yzhangcs / rotary.py
Created January 15, 2025 19:40
Rotary with theta
# -*- coding: utf-8 -*-
# Copyright (c) 2023, Tri Dao.
# https://github.com/Dao-AILab/flash-attention/blob/main/flash_attn/ops/triton/rotary.py
from typing import Optional, Tuple, Union
import torch
import torch.nn as nn
import triton
@yzhangcs
yzhangcs / omz.sh
Created January 11, 2025 12:09
Scripts for initializing zsh environments
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
git clone https://github.com/Pilaton/OhMyZsh-full-autoupdate.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/ohmyzsh-full-autoupdate
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-completions
git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search
git clone https://github.com/zsh-users/zsh-syntax-highlighting ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
# -*- coding: utf-8 -*-
# Copyright (c) 2024, Songlin Yang, Yu Zhang
from typing import Optional, Tuple
import torch
import triton
import triton.language as tl
from fla.ops.common.chunk_h_split import chunk_bwd_dh, chunk_fwd_h
@yzhangcs
yzhangcs / chunk.py
Last active December 8, 2024 16:41
Parallel-then-reduction chunk implementations
# -*- coding: utf-8 -*-
# Copyright (c) 2024, Songlin Yang, Yu Zhang
from typing import Optional, Tuple
import torch
import triton
import triton.language as tl
# -*- 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'