Skip to content

Instantly share code, notes, and snippets.

View itsAnanth's full-sized avatar
🧠
figuring out stuff

Ananth itsAnanth

🧠
figuring out stuff
View GitHub Profile
@itsAnanth
itsAnanth / pipeline_parallel.py
Created May 24, 2025 21:50 — forked from 3outeille/pipeline_parallel.py
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):
import numpy as np
class LogisticRegression:
def __init__(self, learning_rate=0.01, epochs=1000):
self.learning_rate = learning_rate
self.epochs = epochs
self.weights = None
self.bias = None
def sigmoid(self, z):
@itsAnanth
itsAnanth / bubbleSort.js
Last active November 28, 2021 17:29
Implementation of bubble sort in javascript
// bubble sort in javascript
Array.prototype.bubbleSort = function(callback = (a, b) => a > b) {
const array = this;
for (let i = 0; i < array.length; i++) {
let swaps = 0;
for (let j = 0; j < array.length - i - 1; j++) {
if (callback(array[j], array[j + 1])) {
let temp = array[j];
array[j] = array[j + 1];