Skip to content

Instantly share code, notes, and snippets.

View joshlk's full-sized avatar

Josh Levy-Kramer joshlk

  • London, UK
View GitHub Profile
@joshlk
joshlk / convolution_matrix_multiplication_equivalence.ipynb
Created April 30, 2024 13:23
Demonstration in PyTorch how convolutions can implemented using matrix multiplication
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@joshlk
joshlk / 0_nvidia_benchmark.md
Last active March 29, 2024 06:06
Benchmark bandwidth and latency of P2P NVIDIA GPUs (NVLINK vs PCI)

NVIDIA GPU P2P Benchmark bandwidth/throughput and latency

Using https://github.com/NVIDIA/cuda-samples

You can also view the GPU topology using nvidia-smi topo -m

  1. Download repo git clone https://github.com/NVIDIA/cuda-samples.git
  2. Checkout the tag that corresponds with the right CUDA version: git checkout tags/v11.1
  3. You might need to install some additional packages sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev libglfw3-dev libgles2-mesa-dev
  4. Either build everything by just execting make in root dir. Or cd Samples/p2pBandwidthLatencyTest; make
@joshlk
joshlk / inference_pretraining_data.ipynb
Last active January 9, 2024 16:47
Inference with pretraining style data for LLM
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@joshlk
joshlk / vocab_sharding.py
Created October 24, 2023 09:29
Vocab sharding using DTensors
from math import ceil
from typing import Optional, Tuple, Union
import torch
from torch import Tensor, nn
from torch.distributed._tensor import DTensor, Replicate, Shard, distribute_module, distribute_tensor
from torch.distributed._tensor.op_schema import OpSchema, OutputSharding
from torch.distributed._tensor.ops.embedding_ops import embedding_rules
from torch.distributed._tensor.ops.utils import register_prop_rule
from torch.distributed._tensor.placement_types import DTensorSpec, _Partial
@joshlk
joshlk / sentence-segmentation-benchmark.ipynb
Last active October 23, 2023 18:24
A comparison of different sentence segmentation models for the English language. The Brown corpus is used to benchmark the models.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@joshlk
joshlk / peak_memory.bash
Last active July 25, 2023 12:49
Measure the peak memory of the system while a command is running (this only includes physical memory and not virtual memory)
#!/usr/bin/env bash
# peak_memory [command ...]
# Run the given command line in the background and kill if script exits
trap 'kill $(jobs -p) 2&> /dev/null' EXIT
"$@" &
pid=$! phys_peak=0 not_avail_peak=0
# while command still running
while ps -p $pid &>/dev/null; do
sleep 1
mem_total="$(cat /proc/meminfo | grep 'MemTotal:' | grep -oe '\([0-9.]*\)')"
@joshlk
joshlk / trio_progress_bar.py
Created May 31, 2019 13:58
Progress bar for Python Trio tasks using tqdm
import trio
import tqdm
class TrioProgress(trio.abc.Instrument):
def __init__(self, total, notebook_mode=False, **kwargs):
if notebook_mode:
from tqdm import tqdm_notebook as tqdm
else:
from tqdm import tqdm
@joshlk
joshlk / faster_toPandas.py
Last active May 15, 2023 13:48
PySpark faster toPandas using mapPartitions
import pandas as pd
def _map_to_pandas(rdds):
""" Needs to be here due to pickling issues """
return [pd.DataFrame(list(rdds))]
def toPandas(df, n_partitions=None):
"""
Returns the contents of `df` as a local `pandas.DataFrame` in a speedy fashion. The DataFrame is
repartitioned if `n_partitions` is passed.
@joshlk
joshlk / CANNON_MP490_RaspberryPi_CUPS.md
Last active March 24, 2023 13:13
How to add Cannon MP490 printer to RaspberryPi CUPS server
  1. Install Cannon printer drivers sudo apt update; sudo apt install software-properties-common cups-backend-bjnp
  2. Make sure user has password (add password using sudo passwd $user)
  3. Follow instructions to install server https://pimylifeup.com/raspberry-pi-print-server/
  4. Chrome doesn't work to add a printer - worked on Safari
@joshlk
joshlk / graph_tool_jupyter_notebook_inline_draw.ipynb
Created April 20, 2018 14:01
Inline graph-tool figures in Jupyter notebook (graph_draw)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.