Skip to content

Instantly share code, notes, and snippets.

@vincentqb
vincentqb / metric_logger.py
Last active December 9, 2024 16:54
Simple Metric Logger in Python
import socket
import pandas as pd
class MetricLogger:
def __init__(self, root="runs"):
self.metrics = {}
self.iteration = 0
@vincentqb
vincentqb / magic.md
Last active April 12, 2022 23:37
Comment out line and cell magic from jupyter notebook, see https://github.com/ipython/ipython/issues/3707#issuecomment-1097362068

Leaving a note here to adjust the solution above for cell magic (e.g. %%time), with nbconvert > 6.0.

In nbconvert_config.py:

def comment_magics(input, **kwargs):
    if input.startswith("%"):
        input = "# " + input
    return input
@vincentqb
vincentqb / flamegraphs
Created February 18, 2021 23:34
Performance visualization with flame graphs
perf record -F 320 --call-graph dwarf python some_script.py
perf script > out.perf
# Visualize as flame graphs: https://github.com/brendangregg/FlameGraph
~/FlameGraph/stackcollapse-perf.pl out.perf > out.folded
~/FlameGraph/flamegraph.pl out.folded > out.svg
google-chrome out.svg
import pandas as pd
import json
def read_json(filename):
with open(filename, "r") as f:
data = f.read()
# TODO remove characters before first "{" from log directly instead
#! /bin/bash
#SBATCH --job-name=torchaudiomodel
#SBATCH --output=/checkpoint/%u/jobs/audio-%j.out
#SBATCH --error=/checkpoint/%u/jobs/audio-%j.err
#SBATCH --signal=USR1@600
#SBATCH --open-mode=append
#SBATCH --partition=learnfair
#SBATCH --time=4320
#SBATCH --mem-per-cpu=5120
@vincentqb
vincentqb / rmsprop_tf.py
Created April 22, 2020 19:36
RMSProp closer to TF's implementation
import torch
from .optimizer import Optimizer
class RMSprop(Optimizer):
r"""Implements RMSprop algorithm.
Proposed by G. Hinton in his
`course <http://www.cs.toronto.edu/~tijmen/csc321/slides/lecture_slides_lec6.pdf>`_.
The centered version first appears in `Generating Sequences
With Recurrent Neural Networks <https://arxiv.org/pdf/1308.0850v5.pdf>`_.
import torch
from .optimizer import Optimizer
class RMSprop(Optimizer):
r"""Implements RMSprop algorithm.
Proposed by G. Hinton in his
`course <http://www.cs.toronto.edu/~tijmen/csc321/slides/lecture_slides_lec6.pdf>`_.
The centered version first appears in `Generating Sequences
With Recurrent Neural Networks <https://arxiv.org/pdf/1308.0850v5.pdf>`_.
@vincentqb
vincentqb / StridedBuffer.py
Last active March 16, 2020 14:17
Strided Buffer
from itertools import repeat
class StridedBuffer:
def __init__(self, generator, stride, length):
self._generator = generator
self._stride = stride
self._length = length
self._buffer = [[] for _ in repeat(None, stride)]