Skip to content

Instantly share code, notes, and snippets.

lambda image: blur(color_jitter(random_crop(image))
// ChatGPT is going to take my job
package main
import (
"bufio"
"flag"
"fmt"
"os"
"regexp"
"sort"
@vedantroy
vedantroy / job_submission.bash
Created December 15, 2022 22:50
Some neat bash tricks
#! /bin/bash
set -euxo pipefail
job_file="cluster_jobs/${1}.py"
if [[ ! -f "${job_file}" ]]; then
echo "${job_file} not found"
exit 1
fi
RAY_ADDRESS=${RAY_ADDRESS:-""}
@vedantroy
vedantroy / rev_vit.py
Created September 12, 2022 10:24
Reversible VIT
from types import SimpleNamespace
import yahp as hp
import torch
from torch import nn
from torch.autograd import Function as Function
from einops import rearrange
from einops.layers.torch import Rearrange
# A one-file implementation of the reversible VIT architecture
"""run.py:"""
#!/usr/bin/env python
import os
import torch
import torch.distributed as dist
import torch.multiprocessing as mp
def run(rank, size):
""" Distributed function to be implemented later. """
pass
@vedantroy
vedantroy / einsum.py
Created July 17, 2022 23:57
Einsum examples
import numpy as np
def single_matrix():
x = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
I, J, K = x.shape
x_ein = np.einsum("ijk->ij", x)
x_loop = np.empty((I, J))
for i in range(I):
@vedantroy
vedantroy / model.py
Created June 29, 2022 07:18
Transformer
import torch
import torch.nn as nn
from params import params
# NOTATION:
# W_k = W (k as subscript)
# Wk = W (k as superscript)
class MultiHeadAttention(nn.Module):
@vedantroy
vedantroy / tailwind-styled.ts
Created June 10, 2022 18:00
Tailwind Styled Components-like API
import React from "react";
import { fromPairs } from "lodash-es";
import clsx from "clsx";
// This is my styled-components replacement
// Taken from:
// https://github.com/MathiasGilson/Tailwind-Styled-Component/blob/master/src/domElements.ts
const elementsArray: (keyof JSX.IntrinsicElements)[] = [
"a",
"abbr",
@vedantroy
vedantroy / run_sage.py
Created January 26, 2022 19:38
Run a Python file in Sage using Docker
#! /usr/bin/python3
import sys
import os.path
fpath = sys.argv[1]
assert os.path.isfile(fpath)
abs_path = os.path.abspath(fpath)
dirname = os.path.dirname(abs_path)
fname = os.path.basename(abs_path)
@vedantroy
vedantroy / lib.rs
Last active November 28, 2021 17:47
Creating singleton / global state for Solana program
use anchor_lang::prelude::*;
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
#[program]
pub mod auction {
use super::*;
pub fn create_game_state(ctx: Context<CreateGameState>) -> ProgramResult {
Ok(())
}