Skip to content

Instantly share code, notes, and snippets.

View takuma104's full-sized avatar

Takuma Mori takuma104

  • Tokyo
View GitHub Profile
#import "YAJL.h" // YAJL ObjC
#import "NSString+SBJSON.h" // JSON Framework
// JSON Data: Twitter Home Timeline (count=200)
// iPod touch 3rd Gen -> test0:296ms test1:323ms test2:170ms test3:488ms
@implementation Test
- (void)test0:(NSData*)JSONData {
double st = CFAbsoluteTimeGetCurrent();
static void indentedMsg(int indent, NSString *str) {
NSMutableString *idt = [NSMutableString string];
for (int i = 0; i < indent; i++) {
[idt appendString:@" "];
}
NSLog(@"%@%@", idt, str);
}
- (void)parserDidStartDictionary:(YAJLParser *)parser {
indentedMsg(indent, @"dict>");
/*
PerfCheck: Stopwatch for Debugging (ObjC)
Usage:
PFBEGIN(@"hoge");
// some process
PFEND(@"hoge");
PFBEGIN(@"fuga");
// some process
#import "flalib.h"
@interface TestSprite : FLSprite {
}
@end
@implementation TestSprite
@takuma104
takuma104 / mem_eff_attention_jax_repro.py
Created January 10, 2023 01:58
memory_efficient_attention(jax) deterministic test
# SELF-ATTENTION DOES NOT NEED O(n2) MEMORY: https://arxiv.org/pdf/2112.05682.pdf
# https://github.com/google-research/google-research/blob/master/memory_efficient_attention/memory_efficient_attention.ipynb
# you may need to apply 'export XLA_PYTHON_CLIENT_PREALLOCATE=false'
# https://github.com/google/jax/issues/7118#issuecomment-950183972
import functools
import jax
import jax.numpy as jnp
import math
@takuma104
takuma104 / mem_eff_attention_deterministic_algorithms_warn.py
Created January 11, 2023 15:03
mem_eff_attention_deterministic_algorithms_warn.py
import xformers
import xformers.ops
import torch
device = 'cuda'
dtype = torch.float16
shape = (1, 1024, 16, 16)
torch.manual_seed(0)
@takuma104
takuma104 / diffusers_sd_xformers_flash_attention.py
Last active July 29, 2023 20:09
Generating (almost) reproducible pictures using Diffusers with xFormers
import torch
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
import matplotlib.pyplot as plt
from PIL import Image
import numpy as np
plt.rcParams["figure.figsize"] = (10,5)
plt.rcParams['figure.facecolor'] = 'white'
def generate_tuxedo_cat_picture(fn_prefix, seed=0):
@takuma104
takuma104 / diffusers_xformers_repro.py
Last active January 20, 2023 16:09
Generating (almost) reproducible pictures using Diffusers with xFormers
import torch
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler, EulerAncestralDiscreteScheduler
import matplotlib.pyplot as plt
from PIL import Image
import numpy as np
import xformers
import xformers.ops
plt.rcParams["figure.figsize"] = (10,5)
plt.rcParams['figure.facecolor'] = 'white'
@takuma104
takuma104 / readme.md
Last active January 21, 2023 09:35
Reproducible generation with xFormers for SD2.x or variant models
# from https://github.com/lllyasviel/ControlNet/blob/main/gradio_canny2image.py
from share import *
import config
import cv2
import einops
import gradio as gr
import numpy as np
import torch