Skip to content

Instantly share code, notes, and snippets.

#https://pytorch.org/TensorRT/tutorials/_rendered_examples/dynamo/torch_compile_stable_diffusion.html
from diffusers import DiffusionPipeline
model_id = "CompVis/stable-diffusion-v1-4"
# Instantiate Stable Diffusion Pipeline with FP16 weights (use float32 on CPU)
pipe = DiffusionPipeline.from_pretrained(
model_id, revision="fp16", torch_dtype=torch.float32
)
@hatmer
hatmer / check.sh
Last active September 23, 2022 18:10
Valgrind check for memory errors
valgrind --leak-check=full \
--show-leak-kinds=all \
--track-origins=yes \
--verbose \
--log-file=valgrind-out.txt \
./executable arg1 arg2
@hatmer
hatmer / install.sh
Last active November 15, 2021 13:20
vim plugins
git clone https://github.com/vim-airline/vim-airline ~/.vim/pack/dist/start/vim-airline
mkdir -p ~/.vim/pack/tpope/start
cd ~/.vim/pack/tpope/start
git clone https://tpope.io/vim/fugitive.git
vim -u NONE -c "helptags fugitive/doc" -c q
mkdir -p ~/.vim/pack/git-plugins/start
git clone --depth 1 https://github.com/dense-analysis/ale.git ~/.vim/pack/git-plugins/start/ale
@hatmer
hatmer / pi.py
Last active November 8, 2021 15:11
Estimate Pi using darts
import random
import math
darts = 1000000
darts_in_circle = 1.0
# for each dart
for i in range(0, darts):
# give it a random continuous location
x = random.uniform(0,1)
@hatmer
hatmer / mpi_test.c
Last active December 2, 2021 16:44
Simple MPI program for testing MPI setup
// mpic++ test.cpp
// /home/atmerhannah/openmpi/bin/mpirun --mca osc rdma --hostfile hosts ./a.out
#include <stdio.h>
#include "mpi.h"
int main(int argc, char* argv[])
{
int rank, size;
@hatmer
hatmer / easteregg.c
Created April 7, 2021 14:19
Easter Egg
float s=1944,x[5],y[5],z[5],r[5],j,h,a,b,d,e;int i=33,c,l,f=1;int g(){return f=(f*6478+1)%65346;}m(){x[i]=g()-l;y[i]=(g()-l)/4;r[i]=g()>>4;}main(){char t[1948]=" `MYmtw%FFlj%Jqig~%`jqig~Etsqnsj3stb",*p=t+3,*k="3tjlq9TX";l=s*20;while(i<s)p[i++]='\n'+5;for(i=0;i<5;i++)z[i]=(i?z[i-1]:0)+l/3+!m();while(1){for(c=33;c<s;c++){c+=!((c+1)%81);j=c/s-.5;h=c%81/40.0-1;p[c]=37;for(i=4;i+1;i--)if((b=(a=h*x[i]+j*y[i]+z[i])*a-(d=1+j*j+h*h)*(-r[i]*r[i]+x[i]*x[i]+y[i]*y[i]+z[i]*z[i]))>0){for(e=b;e*e>b*1.01||e*e<b*.99;e-=.5*(e*e-b)/e);p[c]=k[(int)(8*e/d/r[i])];}}for(i=4;i+1;z[i]-=s/2,i--)z[i]=z[i]<0?l*2+!m():z[i];while(i<s)putchar(t[i++]-5);}}
@hatmer
hatmer / binary_search.cpp
Created April 2, 2020 17:09
Binary Search
#include <iostream>
// precondition: array a is sorted
int binarySearch(int key, int* a) {
int lo = 0;
int hi = sizeof(*a) / sizeof(a[0]);
while (lo <= hi) {
int mid = lo + (hi - lo) / 2;
if (key < a[mid]) { hi = mid - 1; }
else if (key > a[mid]) { lo = mid + 1; }
@hatmer
hatmer / newtons_method.cpp
Last active April 2, 2020 17:09
Newtons Method for calculating square roots
#include <iostream>
// Calculate the square root via successively better approximations
int main()
{
int N = 10; // iterations
double x = 2.0; // derive root of x
double arr[N];
arr[0] = 2.0;
@hatmer
hatmer / quicksort.cpp
Last active March 29, 2020 14:53
Quicksort implementation in C++
void exch(int* a, int x, int y) {
int tmp = a[x];
a[x] = a[y];
a[y] = tmp;
}
int partition(int* a, int lo, int hi) {
int i = lo;
int j = hi+1;
while (true) {
@hatmer
hatmer / ascii.cpp
Last active March 26, 2020 11:00
Print ASCII Text
#include <iostream>
#include <string>
using namespace std;
int main()
{
int L = 4;
int H = 5;
string T = "Hello";