Skip to content

Instantly share code, notes, and snippets.

View danielhavir's full-sized avatar

Daniel Havir danielhavir

View GitHub Profile
au BufNewFile,BufRead *.py set tabstop=4
au BufNewFile,BufRead *.py set softtabstop=4
au BufNewFile,BufRead *.py set shiftwidth=4
au BufNewFile,BufRead *.py set textwidth=79
au BufNewFile,BufRead *.py set expandtab
au BufNewFile,BufRead *.py set autoindent
au BufNewFile,BufRead *.py set fileformat=unix
highlight BadWhitespace ctermbg=red guibg=red
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/
@danielhavir
danielhavir / query.go
Last active October 1, 2019 06:51
Simple utility CLI interface for encryption, IP querying and some other functions. Build and move the binary to "~/.local/bin"
package main
import (
"crypto/rand"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"os/exec"
# Full Example: https://gist.github.com/danielhavir/407a6cfd592dfc2ad1e23a1ed3539e07
import os
from typing import Callable, List, Tuple, Generator, Dict
import torch
import torch.utils.data
from PIL.Image import Image as ImageType
def list_items_local(path: str) -> List[str]:
tput setaf 6; echo '#### Downloading and installing CUDA ####'; tput sgr0;
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget http://developer.download.nvidia.com/compute/cuda/11.0.2/local_installers/cuda-repo-ubuntu2004-11-0-local_11.0.2-450.51.05-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2004-11-0-local_11.0.2-450.51.05-1_amd64.deb
sudo apt-key add /var/cuda-repo-ubuntu2004-11-0-local/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda
@danielhavir
danielhavir / install-go.sh
Last active March 29, 2021 23:53
Install/Uninstall Golang (https://golang.org/)
#!/bin/bash
# Resource 1: https://golang.org/doc/install#install
# Resource 2: https://alexatnet.com/install-go-on-raspberry-pi/
version="1.12"
machine=`uname -m`
bold=$(tput bold)
yellow=$(tput setaf 3)
green=$(tput setaf 2)
@danielhavir
danielhavir / cpu_monitor.py
Last active February 23, 2022 11:08
Monitor GPU usage, memory and temperature in Visdom during training
from visdom import Visdom
import numpy as np
from time import sleep
import logging
from threading import Event
try:
import psutil
except ImportError:
logging.error("You must \"pip install psutil\"")
raise
@danielhavir
danielhavir / install_cudnn.sh
Created March 12, 2018 15:30
Extract CuDNN, copy files to CUDA directory and create symbolic links
### CuDNN Installation Script ###
### Download CuDNN from: https://developer.nvidia.com/cudnn ###
### Reference 1: http://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html ###
### Reference 2: https://stackoverflow.com/questions/42013316/after-building-tensorflow-from-source-seeing-libcudart-so-and-libcudnn-errors/44147506#44147506 ###
## Create variables
### CHANGE THESE ###
export cudnn_version=cudnn-8.0-linux-x64-v7.1
export version=7.1.1
export cuda_dir=/usr/local/cuda
@danielhavir
danielhavir / k_armed_bandit.py
Last active July 8, 2022 18:25
ε-greedy action selection, sample-average action-value estimates
import argparse
import multiprocessing as mp
from functools import partial
import numpy as np
from scipy.stats import norm
import matplotlib.pyplot as plt
STEPS = 10000
class LoRAConv1DWrapper(nn.Module):
"""SimpleWrapper class that implements LoRA: Low-Rank Adaptation of Large Language Models.
Arxiv link: https://arxiv.org/abs/2106.09685"""
def __init__(self, conv1dmodule: transformers.pytorch_utils.Conv1D, lora_rank: int):
super().__init__()
self.base_module = conv1dmodule
d1, d2 = self.base_module.weight.size()
self.A = nn.Parameter(
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINhqM2fhXk0Qgl+6R9kPjJ/48ZrNcXjc/7zTn8oi88nH daniel@Daniels-MacBook-Pro.local