Skip to content

Instantly share code, notes, and snippets.

View visualDust's full-sized avatar
:dependabot:
Wait... are you a robot?

Gavin Gong visualDust

:dependabot:
Wait... are you a robot?
View GitHub Profile
@visualDust
visualDust / convert llama2 weights to huggingface.md
Created April 3, 2024 08:30
convert downloaded llama2 weights to huggingface format so that you can load it with huggingface/transformers from_pretrained

Download and convert llama-7b model to huggingface format

This is a refined version of huggingface/LLaMA2 Usage tips.

Go to somewhere you want to put the original llama2 7b model weights, maybe in the download folder. Create a folder called LLaMA:

cd ~/downloads (or maybe somewhere else)
mkdir LLaMA
cd LLaMA
import time
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision.datasets as datasets
import neetbox
from torchvision import transforms
from torch.utils.data import DataLoader
from neetbox import logger
@visualDust
visualDust / one_hot_with_ignore_label.py
Last active November 19, 2023 12:24
One hot encoding that supports ignore label
def one_hot_encode(
mask: torch.Tensor,
num_classes: int,
ignored_label: Union[str, int] = "negative",
):
"""Convert the mask to a one-hot encoded representation by @visualDust
Args:
mask (torch.Tensor): indexed label image. Should types int
num_classes (int): number of classes
@visualDust
visualDust / 📊 Weekly development breakdown
Last active September 4, 2025 01:20
Weekly sleeping breakdown
LaTeX 33 hrs 5 mins ██████████████▎░░░░░░ 68.1%
Other 9 hrs 36 mins ████▏░░░░░░░░░░░░░░░░ 19.8%
Markdown 3 hrs 54 mins █▋░░░░░░░░░░░░░░░░░░░ 8.1%
Python 1 hr 23 mins ▌░░░░░░░░░░░░░░░░░░░░ 2.9%
Java 14 mins ░░░░░░░░░░░░░░░░░░░░░ 0.5%