Skip to content

Instantly share code, notes, and snippets.

View UmerHA's full-sized avatar

UmerHA

View GitHub Profile
@UmerHA
UmerHA / memsafety_triton.ipynb
Last active January 18, 2025 23:55
Memory safety in Triton
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@UmerHA
UmerHA / aoc_2024_6b_faster.py
Created December 6, 2024 22:38
aoc_2024_6b
dirs = ['^','>','v','<']
dir_map = {'^':0,'>':1,'v':2,'<':3}
delta = [(-1,0),(0,1),(1,0),(0,-1)]
def parse_grid(grid_str):
grid = [list(line) for line in grid_str.split('\n')]
rows, cols = len(grid), len(grid[0])
gpos, gdir = None, None
for r in range(rows):
for c in range(cols):
@UmerHA
UmerHA / patch.py
Last active December 6, 2024 20:56
Building a python class step by step via patching
class Snail:
def __init__(self):
self.speed = 0.001
self.pos = 0
def move(self):
self.pos += self.speed
print(f'moved to {self.pos}')
garry = Snail()
@UmerHA
UmerHA / map_dir_structure.py
Created October 31, 2023 00:38
Quickly get a flat or nested directory structure, and optionally save to yaml
import os
import yaml
from pprint import pprint
def dir_structure(dir_path, nested=False):
result = []
if nested:
# return directory structure as nested dict
for item in os.listdir(dir_path):
@UmerHA
UmerHA / prompt-to-prompt--show-attention-maps.py
Last active March 7, 2024 09:20
Show averaged attention maps for the Prompt2PromptPipeline in 🤗 diffusers
# based on github.com/weifeng-Chen/prompt2prompt/ - shoutout to Weifeng Cheng!
# Create pipeline and run it once
import torch
import numpy as np
import matplotlib.pyplot as plt
from diffusers.pipelines import Prompt2PromptPipeline
pipe = Prompt2PromptPipeline.from_pretrained("CompVis/stable-diffusion-v1-4").to("cuda")