Skip to content

Instantly share code, notes, and snippets.

View sksq96's full-sized avatar

Shubham Chandel sksq96

View GitHub Profile
fairseq-train qa_en_small-bin \
--log-interval=10 \
--log-format=json \
--tensorboard-logdir=/users/tom/ed/sp/pretrain/tests/fairseq/bart_en_small/logs \
--seed=1 \
--cpu \
--min-loss-scale=0.0001 \
--model-parallel-size=1 \
--criterion=cross_entropy \
@eddex
eddex / Install CUDA 10.1 on Ubuntu 18.04.md
Last active November 22, 2023 16:12
How to install CUDA 10.1 on Ubuntu 18.04

How to install CUDA 10.1 on Ubuntu 18.04

A clean installation of Ubuntu 18.04.02 LTS was used.

This gist is an extension to the official docs, adding missing parts and instructions.

2 pre-install actions

follow the pre-installation actions on:

@thomwolf
thomwolf / AdamW.py
Created July 3, 2018 21:20
Implements Adam algorithm with weight decay fix in PyTorch (paper: https://arxiv.org/abs/1711.05101)
from torch.optim import Optimizer
class AdamW(Optimizer):
"""
Implements Adam algorithm with weight decay fix in PyTorch
Paper: Fixing Weight Decay Regularization in Adam by Ilya Loshchilov, Frank Hutter
https://arxiv.org/abs/1711.05101
"""
def __init__(self, params, lr, b1=0.9, b2=0.999, e=1e-8, l2=0,
vector_l2=False, max_grad_norm=-1, **kwargs):
@yuzeh
yuzeh / masked_softmax.py
Last active September 14, 2020 15:17
A PyTorch implementation of a softmax function where support of the underlying categorical distribution is given as input. Useful for, e.g., learning discrete policies where certain actions are known a-priori to be invalid.
# MIT License
#
# Copyright (c) 2018 Yuze Huang (hi@yuzeh.com)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@ahmedhosny
ahmedhosny / nrrd_to_nifti.py
Created December 12, 2017 15:49
nrrd to nifti
import nrrd # pip install pynrrd
import nibabel as nib # pip install nibabel
import numpy as np
# load nrrd
_nrrd = nrrd.read('/path/to/nrrd.nrrd')
data = _nrrd[0]
header = _nrrd[1]
print data.shape, header
@jihunchoi
jihunchoi / masked_cross_entropy.py
Last active January 22, 2024 19:20
PyTorch workaround for masking cross entropy loss
def _sequence_mask(sequence_length, max_len=None):
if max_len is None:
max_len = sequence_length.data.max()
batch_size = sequence_length.size(0)
seq_range = torch.range(0, max_len - 1).long()
seq_range_expand = seq_range.unsqueeze(0).expand(batch_size, max_len)
seq_range_expand = Variable(seq_range_expand)
if sequence_length.is_cuda:
seq_range_expand = seq_range_expand.cuda()
seq_length_expand = (sequence_length.unsqueeze(1)
@yossorion
yossorion / what-i-wish-id-known-about-equity-before-joining-a-unicorn.md
Last active April 7, 2024 22:55
What I Wish I'd Known About Equity Before Joining A Unicorn

What I Wish I'd Known About Equity Before Joining A Unicorn

Disclaimer: This piece is written anonymously. The names of a few particular companies are mentioned, but as common examples only.

This is a short write-up on things that I wish I'd known and considered before joining a private company (aka startup, aka unicorn in some cases). I'm not trying to make the case that you should never join a private company, but the power imbalance between founder and employee is extreme, and that potential candidates would

@sunskyhsh
sunskyhsh / algorithm.py
Created December 29, 2016 13:22
qlearning algorithm to solve CartPole on openAI gym.
def qlearning(env, policy, num_iter1, alpha, gamma):
actions = policy.actions
for i in xrange(len(policy.theta)):
policy.theta[i] = 0.1
for iter1 in xrange(num_iter1):
s_f = env.reset()
a = policy.epsilon_greedy(s_f)
count = 0
t = False
@brotherofken
brotherofken / qlearning.py
Last active December 30, 2016 22:20
First attempt to implement qlearning using function approximation. Mountain car environment.
# In[]
import gym
import numpy as np
import theano
import theano.tensor as T
import lasagne
import sklearn.preprocessing
np.set_printoptions(precision=2)
@pylover
pylover / a2dp.py
Last active March 11, 2024 03:06
Fixing bluetooth stereo headphone/headset problem in ubuntu 16.04, 16.10 and also debian jessie, with bluez5.
#! /usr/bin/env python3
"""Fixing bluetooth stereo headphone/headset problem in debian distros.
Workaround for bug: https://bugs.launchpad.net/ubuntu/+source/indicator-sound/+bug/1577197
Run it with python3.5 or higher after pairing/connecting the bluetooth stereo headphone.
This will be only fixes the bluez5 problem mentioned above .
Licence: Freeware