Skip to content

Instantly share code, notes, and snippets.

View pcyin's full-sized avatar
🏠
Working from home

Pengcheng YIN pcyin

🏠
Working from home
View GitHub Profile
@dojoteef
dojoteef / profile.py
Last active April 8, 2025 07:50
A CUDA memory profiler for pytorch
'''
Memory profiling utilities
'''
import gc
import inspect
import linecache
import os.path
import sys
import time
import threading
@MInner
MInner / gpu_profile.py
Created September 12, 2017 16:11
A script to generate per-line GPU memory usage trace. For more meaningful results set `CUDA_LAUNCH_BLOCKING=1`.
import datetime
import linecache
import os
import pynvml3
import torch
print_tensor_sizes = True
last_tensor_sizes = set()
gpu_profile_fn = f'{datetime.datetime.now():%d-%b-%y-%H:%M:%S}-gpu_mem_prof.txt'
@norouzi
norouzi / edit_distance_marginal.py
Last active November 2, 2017 21:45
Reward Augmented Maximum Likelihood (RAML; https://arxiv.org/pdf/1609.00150.pdf) -- Python code snippet to compute marginal distribution of different #edits for a given sequence length, temperature, and vocab size.
import scipy.misc as misc
import numpy as np
len_target = 20
v = 60 # Vocabulary size
T = .9 # Temperature
max_edits = len_target
x = np.zeros(max_edits)
for n_edits in range(max_edits):
@alrojo
alrojo / rnn_decoder_attention.md
Last active February 19, 2018 06:25
rnn_decoder_attention.md
from tensorflow.python.ops import tensor_array_ops
from tensorflow.python.framework import dtypes
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import control_flow_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import variable_scope as vs
from tensorflow.python.ops import rnn
from tensorflow.python.ops import nn
from tensorflow.python.ops import init_ops
@acamino
acamino / README.md
Last active April 13, 2025 14:19
Shortcuts to Improve Your Bash & Zsh Productivity

Shortcut — Action

  • CTRL + A — Move to the beginning of the line
  • CTRL + E — Move to the end of the line
  • CTRL + [left arrow] — Move one word backward (on some systems this is ALT + B)
  • CTRL + [right arrow] — Move one word forward (on some systems this is ALT + F)
  • CTRL + U — (bash) Clear the characters on the line before the current cursor position
  • CTRL + U —(zsh) If you're using the zsh, this will clear the entire line
  • CTRL + K — Clear the characters on the line after the current cursor position
  • ESC + [backspace] — Delete the word in front of the cursor
anonymous
anonymous / gist:7d9a56b18a514adf125c
Created May 2, 2015 03:22
Deep RNN : using scan or unrolled expressions
import theano
import theano.tensor as T
import numpy as np
import time
use_scan = True # change this to use the unrolled expression
m = 2**10 # batch size
n = 2**12 # number of hidden units per layer
depth = 8
@Deathmonster
Deathmonster / LSTMLayer.py
Created September 8, 2014 20:43
Simple RNN Example with Scan / For Loop Comparison
import theano
import theano.tensor as T
import numpy
import numpy.random as rng
import math
class LSTMLayer:
def __init__(self, inputSize, controllerSize, memorySize, outputSize, initialScale, useReluReadGate = True):
@evolvedmicrobe
evolvedmicrobe / SimplePartitioner.cs
Last active December 31, 2015 14:08
How to implement a partitioner to avoid an OOM.
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Collections.Concurrent;
namespace YourNamespace
{
// Represent a chunk partitioner
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active May 7, 2025 23:53
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@reuben-sutton
reuben-sutton / CosineSimilarity.scala
Created June 14, 2012 21:10
Cosine Similarity Scala Object
/*
* Object in scala for calculating cosine similarity
* Reuben Sutton - 2012
* More information: http://en.wikipedia.org/wiki/Cosine_similarity
*/
object CosineSimilarity {
/*
* This method takes 2 equal length arrays of integers