Skip to content

Instantly share code, notes, and snippets.

View razhangwei's full-sized avatar

Wei Zhang razhangwei

  • Facebook
  • Bay Area
View GitHub Profile
@razhangwei
razhangwei / 0content.md
Last active August 2, 2020 21:15
A submodule for useful utility functions for ML research projects #Python #Utils
  • logging
  • misc
  • numpy
  • pandas
  • plotting
  • torch
@razhangwei
razhangwei / proximal.py
Created April 11, 2019 14:34
Several proximal operators implemented in #PyTorch
import torch
# > https://github.com/pmelchior/proxmin/blob/master/proxmin/operators.py
def _step_gamma(step, gamma):
"""Update gamma parameter for use inside of continuous proximal operator.
Every proximal operator for a function with a continuous parameter,
e.g. gamma ||x||_1, needs to update that parameter to account for the
stepsize of the algorithm.
Returns:
@razhangwei
razhangwei / search_remove_^M.sh
Created April 12, 2019 00:07
Search and remove ^M in all files in a directory #Unix
find . -type f | xargs -Ix sed -i.bak -r 's/\r//g' x
find . -type f -name '*.bak' | xargs -Ix rm x
@razhangwei
razhangwei / __init__.py
Created April 12, 2019 16:08
__init__.py example #Python
from .sccs import NeuralSCCS
from .log_linear_hawkes import LogLinearHawkes, StochasticLogAdditiveHawkes
__all__ = ["NeuralSCCS", "LogLinearHawkes", "StochasticLogLinearHawkes"]
def get_model(model, **kwargs):
if model == 'N-SCCS':
model = NeuralSCCS(**kwargs)
@razhangwei
razhangwei / sampler.py
Last active December 22, 2019 01:12
ByLengthBatchSampler; bucketing data loader #PyTorch
class ByLengthBatchSampler(torch.utils.data.Sampler):
"""Pseduo bucketed batch sampler.
Sample in a way that
Args:
lengths (list of int): the
batch_size (int):
drop_last (bool, optional): Defaults to False. [description]
"""
@razhangwei
razhangwei / 00README.md
Last active October 31, 2019 17:07
Parallel run wrapper with paramiko #Parallel

Usage:

printf {0..100} | ./ssh_wrapper.py echo --cpus 2 --gpus 1 --email -N 2
printf myscript.py" --foo "{0..100} | ./ssh_wrapper.py python --cpus 2 --gpus 1 --email -N 2
@razhangwei
razhangwei / colab.md
Last active August 15, 2024 02:51
Google Colab tips #Colab
  • Top features
    • Generate full cell of code with gemini
    • Expain error with gemini and Google search.
  • Local connection
    • Option 1: jupyter notebook (simpler than docker, but with limited functionalities)
jupyter notebook \
    --NotebookApp.allow_origin='https://colab.research.google.com' \
    --port=8888 \
    --NotebookApp.port_retries=0
@razhangwei
razhangwei / pytorch.md
Created April 28, 2019 18:42
pytorch cheatsheet #PyTorch

点赞收藏:PyTorch常用代码段整理合集

众所周知,程序猿在写代码时通常会在网上搜索大量资料,其中大部分是代码段。然而,这项工作常常令人心累身疲,耗费大量时间。所以,今天小编转载了知乎上的一篇文章,介绍了一些常用PyTorch代码段,希望能够为奋战在电脑桌前的众多程序猿们提供帮助!

@razhangwei
razhangwei / mail.sh
Created May 3, 2019 18:20
Send email from command line #Unix
mail -s "Subject" [email protected] << "Message"
@razhangwei
razhangwei / .Xmodmap
Last active May 8, 2019 18:54
remapped cmd to ctrl for all XQuartz apps #X11
! save to ~/.Xmodmap
clear Mod2
clear control
keycode 63 = Control_L
keycode 67 = Control_L
keycode 71 = Control_L
add control = Control_L