Skip to content

Instantly share code, notes, and snippets.


Daniel Havir danielhavir

View GitHub Profile
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINhqM2fhXk0Qgl+6R9kPjJ/48ZrNcXjc/7zTn8oi88nH daniel@Daniels-MacBook-Pro.local
class LoRAConv1DWrapper(nn.Module):
"""SimpleWrapper class that implements LoRA: Low-Rank Adaptation of Large Language Models.
Arxiv link:"""
def __init__(self, conv1dmodule: transformers.pytorch_utils.Conv1D, lora_rank: int):
self.base_module = conv1dmodule
d1, d2 = self.base_module.weight.size()
self.A = nn.Parameter(
danielhavir /
Last active Jul 8, 2022
ε-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
# Full Example:
import os
from typing import Callable, List, Tuple, Generator, Dict
import torch
from PIL.Image import Image as ImageType
def list_items_local(path: str) -> List[str]:
View .vimrc
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 /
Last active Feb 23, 2022
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
import psutil
except ImportError:
logging.error("You must \"pip install psutil\"")
def style_loss(style_features, generated_features, J):
loss_style = 0.
for j in J:
gram_style = gram_matrix(style_features[j])
gram_gen = gram_matrix(generated_features[j])
loss_style += F.mse_loss(gram_gen, gram_style)
return loss_style
def content_loss(content_features, generated_features, j):
loss_content = F.mse_loss(generated_features[j], content_features[j])
return loss_content
def gram_matrix(feature_map):
C, H, W = feature_map.size()
reshaped_map = feature_map.view(C, H*W)
G = / (C * H * W)
return G
danielhavir / query.go
Last active Oct 1, 2019
Simple utility CLI interface for encryption, IP querying and some other functions. Build and move the binary to "~/.local/bin"
View query.go
package main
import (