Skip to content

Instantly share code, notes, and snippets.

View parajain's full-sized avatar
:octocat:

Parag Jain parajain

:octocat:
View GitHub Profile
@parajain
parajain / latency.txt
Created February 6, 2024 11:08 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@neubig
neubig / dispatch_openai_requests.py
Last active February 19, 2024 17:55
A simple script to get results from the OpenAI Asynchronous API
# NOTE:
# You can find an updated, more robust and feature-rich implementation
# in Zeno Build
# - Zeno Build: https://github.com/zeno-ml/zeno-build/
# - Implementation: https://github.com/zeno-ml/zeno-build/blob/main/zeno_build/models/providers/openai_utils.py
import openai
import asyncio
from typing import Any
@parajain
parajain / log_softmax.py
Created October 26, 2018 09:44
numpy log normalization and log softmax implementation
import numpy as np
def log_softmax(x):
e_x = np.exp(x - np.max(x))
return np.log(e_x / e_x.sum())
def lognormalize(x):
a = np.logaddexp.reduce(x)
return np.exp(x - a)
@ejmg
ejmg / two-figures.tex
Created October 19, 2017 23:37
how to put two figures, side by side proportionally, in a latex file
\usepackage{multirow,array}
\usepackage{floatrow}
% in combination with floatrow for properly adjusted figures, placeins ensures said figures appear
% where they are declared within the latex code, i.e. in subsection Part I of this paper. For proper
% usage with subsections, MUST use \FloatBarrier command after done with a figure
\usepackage[section]{placeins}
% ensures captions are properly centered under their respective figures
\usepackage[justification=centering]{caption}
% special command for table captions
\newfloatcommand{capbtabbox}{table}[][\FBwidth]
@jboner
jboner / latency.txt
Last active July 25, 2024 11:30
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD