Skip to content

Instantly share code, notes, and snippets.

View LiutongZhou's full-sized avatar
🏠
Working

Liutong Zhou LiutongZhou

🏠
Working
  • Apple
  • New York
View GitHub Profile
@LiutongZhou
LiutongZhou / flash_attention.py
Created November 21, 2025 21:18
FlashAttention
"""FlashAttention: reference implementation of the core logic"""
import math
import torch
from einops import einsum
from jaxtyping import Float, Int
from torch import nn, Tensor
@LiutongZhou
LiutongZhou / JAX Sharding Cheat Sheet (v0.8+).ipynb
Last active March 19, 2026 02:30
Jax Distributed Zero to Hero
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@LiutongZhou
LiutongZhou / moe.py
Created February 4, 2026 03:32
MOE Parallel with Token Dropping in Jax
"""Mixture of Experts (MoE) Layer with token dropping
Using Ragged All-to-All Communication and Ragged Dot in JAX.
"""
__author__ = "Liutong Zhou"
from __future__ import annotations
from dataclasses import dataclass, field
@LiutongZhou
LiutongZhou / Benchmark_Results.md
Last active February 27, 2026 16:09
Benchmarking Jax 0.7+ vs Pytorch 2.10+ Attention Speed

Benchmarking Jax 0.7+ vs Pytorch 2.10+ Attention Variants' Speed and Memory

torch.nn.attention.varlen.varlen_attn is the absolute winner on GPU

GPU: NVIDIA GeForce RTX 4090 Laptop GPU
PyTorch version: 2.10.0
JAX version: 0.7.2
Config: Config(batch_size=8, num_heads=32, head_dim=128, seq_min=128, seq_max=2048, dtype=<DType.BFLOAT16: 'bfloat16'>, is_causal=True, warmup=2, iters=30, seed=42, _seq_lens=(299, 1614, 1385, 971, 959, 1777, 293, 1467))
Seq lens: [299, 1614, 1385, 971, 959, 1777, 293, 1467]