This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import time | |
import os | |
import sys | |
import openai | |
import tiktoken | |
from termcolor import colored | |
openai.api_key = open(os.path.expanduser('~/.openai')).read().strip() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\+$/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def content_loss(content_features, generated_features, j): | |
loss_content = F.mse_loss(generated_features[j], content_features[j]) | |
return loss_content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gram_matrix(feature_map): | |
C, H, W = feature_map.size() | |
reshaped_map = feature_map.view(C, H*W) | |
G = reshaped_map.mm(reshaped_map.t()) / (C * H * W) | |
return G |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/rand" | |
"flag" | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"os/exec" |
NewerOlder