Skip to content

Instantly share code, notes, and snippets.

View Ryu1845's full-sized avatar
🎯
Focusing

Sofian Mejjoute Ryu1845

🎯
Focusing
View GitHub Profile
@secemp9
secemp9 / reset_gpu.sh
Created June 29, 2024 10:30
Resetting gpu
#!/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
}
import numpy as np
from openai import OpenAI
import plotly
import plotly.graph_objs as go
import umap
url = "http://localhost:80"
client = OpenAI(
@crowsonkb
crowsonkb / mos.py
Last active April 11, 2024 21:23
Mixture of Softmaxes
"""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):
@aredden
aredden / cuda_python_cudart_types.py
Created March 12, 2024 22:07
NVIDIA cuda-python's cudart typings for their untyped cpp bound library.
from typing import List, Any
import enum
from cuda import cudart
CUDART_VERSION = 12020
CUDA_EGL_MAX_PLANES = 3
CUDA_IPC_HANDLE_SIZE = 64
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__()
@euclaise
euclaise / scan.py
Created February 9, 2024 00:08
Prefix-sum scan in PyTorch
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):
@tysam-code
tysam-code / hlb-cifar10-ternary-train-initial-working-prototype.py
Last active December 29, 2023 07:47
Trains a network to ~>91.5% on CIFAR10 in less than 10 seconds on an A100 with ternary weights, should fit uncompressed w/ correct storage dtypes in just over half of a floppy drive. <3 :'))))
# 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
"""
@norabelrose
norabelrose / dpo.py
Created November 8, 2023 07:04
Training quirky models with DPO
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()
@rtkclouds
rtkclouds / ccore_layer.py
Created November 7, 2023 03:58
ccore layer
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):
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.