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
#!/bin/bash | |
unbind_gpu() { | |
echo "Unbinding NVIDIA driver..." | |
GPU_PCI=$(lspci | grep -i nvidia | cut -d ' ' -f 1) | |
for gpu in $GPU_PCI; do | |
echo -n "0000:$gpu" > /sys/bus/pci/drivers/nvidia/unbind | |
done | |
} |
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 numpy as np | |
from openai import OpenAI | |
import plotly | |
import plotly.graph_objs as go | |
import umap | |
url = "http://localhost:80" | |
client = OpenAI( |
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
"""Mixture of Softmaxes""" | |
import torch | |
from torch.nn import functional as F | |
class MixtureOfSoftmaxes(torch.autograd.Function): | |
@staticmethod | |
def forward(ctx, x, p): | |
with torch.cuda.amp.autocast(enabled=False): |
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 typing import List, Any | |
import enum | |
from cuda import cudart | |
CUDART_VERSION = 12020 | |
CUDA_EGL_MAX_PLANES = 3 | |
CUDA_IPC_HANDLE_SIZE = 64 |
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 torch | |
import torch.nn as nn | |
import torch.nn.init as init | |
import torch.nn.functional as F | |
# This layer is dropped into your pre-trained PyTorch model where nn.Linear is used | |
class DoRALayer(nn.Module): | |
def __init__(self, d_in, d_out, rank=4): | |
super().__init__() |
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 torch | |
from torch.nn import functional as F | |
import math | |
from typing import Callable | |
def split(xs): | |
xs = [x.view(x.shape[0], x.shape[-1]//2, 2) for x in xs] | |
return [x[: , :, 0] for x in xs], [x[:, :, 1] for x in xs] | |
def merge1(l, r): |
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
# Note: The one change we need to make if we're in Colab is to uncomment this below block. | |
# If we are in an ipython session or a notebook, clear the state to avoid bugs | |
""" | |
try: | |
_ = get_ipython().__class__.__name__ | |
## we set -f below to avoid prompting the user before clearing the notebook state | |
%reset -f | |
except NameError: | |
pass ## we're still good | |
""" |
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 os | |
import random | |
import math, warnings | |
from copy import deepcopy | |
import numpy as np | |
import lightning | |
import torch | |
import torch.nn as nn | |
import torch.nn.functional as F |
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 argparse import ArgumentParser | |
from datasets import load_dataset | |
from peft import LoraConfig | |
from trl import DPOTrainer | |
from transformers import AutoModelForCausalLM, AutoTokenizer, TrainingArguments | |
if __name__ == "__main__": | |
parser = ArgumentParser() |
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 Rezero(layers.Layer): | |
def __init__(self): | |
super().__init__() | |
self.alpha1 = tf.Variable(0.0, trainable=True) | |
def call(self, inputs, training): | |
return self.alpha1*inputs | |
class CustomRezero(tf.keras.layers.Layer): |