Skip to content

Instantly share code, notes, and snippets.

View kdcro101's full-sized avatar
💭
I may be slow to respond.

kdcro101

💭
I may be slow to respond.
View GitHub Profile
@kdcro101
kdcro101 / plot_grad_flow.py
Created February 5, 2024 20:02 — forked from Flova/plot_grad_flow.py
Plot the gradient flow (PyTorch)
# Based on https://discuss.pytorch.org/t/check-gradient-flow-in-network/15063/10
def plot_grad_flow(named_parameters):
'''Plots the gradients flowing through different layers in the net during training.
Can be used for checking for possible gradient vanishing / exploding problems.
Usage: Plug this function in Trainer class after loss.backwards() as
"plot_grad_flow(self.model.named_parameters())" to visualize the gradient flow'''
ave_grads = []
max_grads= []
@kdcro101
kdcro101 / reshard.py
Created December 30, 2023 17:09 — forked from benob/reshard.py
Script to decompose/recompose LLAMA LLM models with different number of shards.
# script to decompose/recompose llama model in different number of shards
# note that it loads the full model * 2 in cpu memory
import os
import json
import sys
import torch
import glob
if len(sys.argv) != 4:
@kdcro101
kdcro101 / finetune_llama2.py
Created December 30, 2023 16:04 — forked from mlabonne/finetune_llama2.py
Easy Llama 2 fine-tuning script (📝 Article: https://tinyurl.com/finetunellama2)
# Based on younesbelkada/finetune_llama_v2.py
# Install the following libraries:
# pip install accelerate==0.21.0 peft==0.4.0 bitsandbytes==0.40.2 transformers==4.31.0 trl==0.4.7 scipy
from dataclasses import dataclass, field
from typing import Optional
import torch
from datasets import load_dataset
from transformers import (
@kdcro101
kdcro101 / Pipfile
Created February 8, 2021 14:49 — forked from onecrayon/Pipfile
async/await FastAPI with SQLAlchemy test
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
pylint = "*"
[packages]
sqlalchemy = "*"
@kdcro101
kdcro101 / 00README.rst
Created December 19, 2020 17:46 — forked from phaustin/00README.rst
passing arrays to cython

Cython example of exposing C-computed arrays in Python without data copies

The goal of this example is to show how an existing C codebase for numerical computing (here c_code.c) can be wrapped in Cython to be exposed in Python.

The meat of the example is that the data is allocated in C, but exposed in Python without a copy using the PyArray_SimpleNewFromData numpy

@kdcro101
kdcro101 / build.sh
Created December 18, 2020 19:31 — forked from lucasea777/build.sh
Python C Extension Hello World
gcc -fpic --shared $(python3-config --includes) greetmodule.c -o greet.abi3.so
# can also use $(pkg-config --cflags python-3.5)
# or
# python3 setup.py install --record files.txt --user
@kdcro101
kdcro101 / build.sh
Created December 18, 2020 19:31 — forked from lucasea777/build.sh
Python C Extension Hello World
gcc -fpic --shared $(python3-config --includes) greetmodule.c -o greet.abi3.so
# can also use $(pkg-config --cflags python-3.5)
# or
# python3 setup.py install --record files.txt --user
@kdcro101
kdcro101 / curl.md
Created September 30, 2019 12:48 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@kdcro101
kdcro101 / Docker SSH.txt
Created September 25, 2019 13:30 — forked from ruo91/Docker SSH.txt
Docker - Running an SSH service
root@ruo91:~# nano Dockerfile
#------- Dockerfile start -------#
#
# Docker SSH Daemon
#
# 해당 Images를 선택
# docker pull images-name과 같다고 보면 됌.
# 이미 이미지가 있다면 docker images 명령어로 해당 Image ID를 적으면 된다.
#
# 예제1) 이미지가 없을 경우
import torch
from torch.autograd import Variable
import torch.nn.functional as F
import torch.utils.data as Data
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
import imageio