Skip to content

Instantly share code, notes, and snippets.

View keunwoochoi's full-sized avatar

Keunwoo Choi keunwoochoi

View GitHub Profile
@keunwoochoi
keunwoochoi / llama-home.md
Created May 25, 2023 20:11 — forked from rain-1/llama-home.md
How to run Llama 13B with a 6GB graphics card

This worked on 14/May/23. The instructions will probably require updating in the future.

llama is a text prediction model similar to GPT-2, and the version of GPT-3 that has not been fine tuned yet. It is also possible to run fine tuned versions (like alpaca or vicuna with this. I think. Those versions are more focused on answering questions)

Note: I have been told that this does not support multiple GPUs. It can only use a single GPU.

It is possible to run LLama 13B with a 6GB graphics card now! (e.g. a RTX 2060). Thanks to the amazing work involved in llama.cpp. The latest change is CUDA/cuBLAS which allows you pick an arbitrary number of the transformer layers to be run on the GPU. This is perfect for low VRAM.

  • Clone llama.cpp from git, I am on commit 08737ef720f0510c7ec2aa84d7f70c691073c35d.
@keunwoochoi
keunwoochoi / masked_loss_metric.py
Last active January 8, 2021 03:57
Masked loss and metric classes/functions for Tensorflow 2 (Keras)
import tensorflow as tf
import tensorflow.keras.metrics as tfkm
from tensorflow.keras import backend as K
MASKED_VALUE = -1
def get_1d_mask(y_true, masked_value):
"""Get 1D mask by comparing y_true with masked_value.
@keunwoochoi
keunwoochoi / grad_lib.py
Last active February 26, 2020 02:36 — forked from yang-song/grad_lib.py
L operator and R operator in Tensorflow2
"""This is a conversion of https://gist.github.com/yang-song/07392ed7d57a92a87968e774aef96762
to Tensorflow 2 using GradientTape
"""
import tensorflow as tf
@tf.function
def gradients(f, x, tape, grad_ys=None):
'''
An easier way of computing gradients in tensorflow. The difference from tf.gradients is
@keunwoochoi
keunwoochoi / fast_conv1d.py
Created December 12, 2019 23:01
"DIGITAL SIGNAL PROCESSING"
import torch
import pdb
def complex_mul(t1, t2):
"""t1, t2: complex representations of torch tensor
"""
assert (t1.dim() == t2.dim()), "dim mismatch in complex_mul, {} and {}".format(t1.dim(), t2.dim())
if t1.dim() == 2:
r1, i1 = t1[:, 0], t1[:, 1]
@keunwoochoi
keunwoochoi / .dockerignore
Last active October 16, 2019 17:37
Docker example
.git
.ipynb_checkpoints
.tox
*.ipynb
notebooks
*.egg-info
*.pyc
OLD-tf2-conversion
temp_data
a_really_large_folder_that_is_not_needed_to_be_in_the_docker_image
@keunwoochoi
keunwoochoi / MelgramLayer.py
Created October 7, 2019 18:19
melgram test code
import tensorflow as tf
class LogMelgramLayer(tf.keras.layers.Layer):
def __init__(
self, num_fft, hop_length, num_mels, sample_rate, f_min, f_max, eps, **kwargs
):
super(LogMelgramLayer, self).__init__(**kwargs)
self.num_fft = num_fft
self.hop_length = hop_length
@keunwoochoi
keunwoochoi / equal_loudness.py
Last active October 18, 2019 14:29
Equal loudness simulation
from scipy.signal import firls
import numpy as np
import torch
import torch.nn.functional as F
elc = np.array([[31.5, -29.9], # freq, response
[63, -23.9],
[100, -19.8],
[200, -13.8],
@keunwoochoi
keunwoochoi / log_melspectrogram.py
Last active May 17, 2021 23:05
example: log-melspectrogram layer in tensorflow.keras
# assuming num_fft = 512
NUM_FFT = 512
NUM_FREQS = 257
# some tentative constants
NUM_MEL = 60
SAMPLE_RATE = 44100
F_MIN = 0
F_MAX = 12000
@keunwoochoi
keunwoochoi / spectrogram_scrolling_video.sh
Created July 18, 2019 23:09
Generate a video with scrolling over the spectrogram of the input audio.
# This is a simplified script of https://gist.github.com/keunwoochoi/f0ea2c49355fc21e93dad88d210efcdd
# Usage: 1. Modify the font path in the line with [ss].
# In my case, I copied and pasted CircularSpAraTTBlack.ttf to the same folder.
# 2. Put the wav file in the same folder, say, audio_file.wav
# 3. run $./spectrogram_scrolling_video.sh audio_file.wav
# 4. You'll see audio_file.mkv in the same folder!
#
# Based on example here https://trac.ffmpeg.org/wiki/Encode/YouTube
text=$(basename $1 .wav)
ffmpeg -i $1 -filter_complex \
@keunwoochoi
keunwoochoi / fancy_youtube_encode.sh
Created July 18, 2019 21:50 — forked from kastnerkyle/fancy_youtube_encode.sh
Fancy encoding of a wav file (or possibly others in the future) to youtube format
# Based on example here https://trac.ffmpeg.org/wiki/Encode/YouTube
text=$(basename $1 .wav)
ffmpeg -i $1 -filter_complex \
"[0:a]avectorscope=s=640x518,pad=1280:720[vs]; \
[0:a]showspectrum=mode=separate:color=intensity:scale=cbrt:s=640x518[ss]; \
[0:a]showwaves=s=1280x202:mode=line[sw]; \
[vs][ss]overlay=w[bg]; \
[bg][sw]overlay=0:H-h,drawtext=fontfile=/usr/share/fonts/truetype/fonts-japanese-gothic.ttf:fontcolor=white:x=10:y=10:text=$text[out]" \
-map "[out]" -map 0:a -c:v libx264 -preset fast -crf 18 -c:a copy $text.mkv