Skip to content

Instantly share code, notes, and snippets.

@3outeille
3outeille / pipeline_parallel.py
Last active November 15, 2024 19:37
Self contained example of how pipeline parallel works (AFAB and 1F1B) in 200 LOC
#VERBOSE=0 torchrun --nproc_per_node 3 self_contained_pp_LOC.py
import os, random, numpy as np, torch, torch.nn as nn, torch.distributed as dist, torch.nn.functional as F
from torch.optim import AdamW
from torch.utils.data import DataLoader, DistributedSampler
from datasets import load_dataset
from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
STEP, local_rank, world_size, verbose = 0, int(os.environ["LOCAL_RANK"]), int(os.environ["WORLD_SIZE"]), os.environ.get("VERBOSE", "0") == "1"
def set_all_seed(seed):
@cloneofsimo
cloneofsimo / prompt_rewight.py
Last active September 13, 2023 11:01
Prompt Reweighting
from diffusers import DiffusionPipeline
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
import torch
import re
MODEL_CACHE = "./cache"
def split_by_emphasis(text, tokenizer, normalize = True):