Skip to content

Instantly share code, notes, and snippets.

View aredden's full-sized avatar
:octocat:
Building awesome things.

Alex Redden aredden

:octocat:
Building awesome things.
  • Remote
View GitHub Profile
@aredden
aredden / wrap_func_dtype.py
Created September 23, 2023 01:04
pytorch function to perform wrapped casting for functions which require specific dtypes (flash attention 2)
from functools import wraps
from typing import Any, Dict, Iterable, Optional, Tuple, TypeVar
import torch
T = TypeVar("T", bound=callable)
ref_map = {
torch.float64: [torch.float16,torch.float32,torch.bfloat16,torch.half],
torch.float32: [torch.float16,torch.bfloat16,torch.half],
torch.float16: [],
torch.bfloat16: [],
@aredden
aredden / image_rotate_into_gif.py
Last active November 22, 2023 04:59
Rotate an image and save as a gif using pytorch
import numpy as np
import torch
from torchvision.transforms import functional as F
from PIL import Image
image_path = "./117.webp"
num_images = 32
total_rot = 360
rot_step = total_rot / num_images
@aredden
aredden / cuda_python_cudart_types.py
Created March 12, 2024 22:07
NVIDIA cuda-python's cudart typings for their untyped cpp bound library.
from typing import List, Any
import enum
from cuda import cudart
CUDART_VERSION = 12020
CUDA_EGL_MAX_PLANES = 3
CUDA_IPC_HANDLE_SIZE = 64
@aredden
aredden / fp8_linear_quantile.py
Created August 24, 2024 15:57
quantize fp8 using quantile vs absmax for very ood values
import torch
torch.set_printoptions(precision=4, sci_mode=False)
import triton
import triton.language as tl
from torch import Tensor
def quanitze_fp8_tensorwise(x: torch.Tensor, dtype=torch.float8_e4m3fn):
scale = x.abs().max() / torch.finfo(dtype).max