Skip to content

Instantly share code, notes, and snippets.

@harisankarh
harisankarh / gpu_check.py
Created April 13, 2021 05:11
python program to check the status of gpus in a server
import os
if 'CUDA_VISIBLE_DEVICES' in os.environ:
print('CUDA_VISIBLE_DEVICES:', os.environ['CUDA_VISIBLE_DEVICES'])
if torch.cuda.is_available() is False:
print('no gpu available')
total_devices = torch.cuda.device_count()
print(f'{total_devices} gpus available')
@harisankarh
harisankarh / install-tmux.sh
Last active September 1, 2020 13:33 — forked from pokev25/install-tmux.sh
Install tmux 2.8 on centos 7
# Install tmux 2.8 on Centos
# install deps
yum install -y gcc kernel-devel make ncurses-devel
# DOWNLOAD SOURCES FOR LIBEVENT AND MAKE AND INSTALL
curl -LOk https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz
tar -xf libevent-2.1.8-stable.tar.gz
cd libevent-2.1.8-stable
./configure --prefix=/usr/local
@harisankarh
harisankarh / vw_test.py
Last active September 28, 2018 21:15
vowpal wabbit test
import os
import random as rand
iters = 1000
actual_threshold = 70
for i in range(iters):
score_sampled = rand.randint(0,100)
get_prob_command = " echo \" | f1:{} \" | netcat localhost 26542".format(score_sampled)
SELECT x1,
x2,
y,
w_00 — (2.0)*(dw_00+(1e-3)*w_00) AS w_00,
w_01 — (2.0)*(dw_01+(1e-3)*w_01) AS w_01,
w_10 — (2.0)*(dw_10+(1e-3)*w_10) AS w_10,
w_11 — (2.0)*(dw_11+(1e-3)*w_11) AS w_11,
SELECT *,
SUM(x1*dhidden_0) OVER () AS dw_00,
SUM(x1*dhidden_1) OVER () AS dw_01,
SUM(x2*dhidden_0) OVER () AS dw_10,
SUM(x2*dhidden_1) OVER () AS dw_11,
SUM(dhidden_0) OVER () AS db_0,
SUM(dhidden_1) OVER () AS db_1
FROM {inner subquery}
SELECT *,
SUM(d0*dscores_0) OVER () AS dw2_00,
SUM(d0*dscores_1) OVER () AS dw2_01,
SUM(d1*dscores_0) OVER () AS dw2_10,
SUM(d1*dscores_1) OVER () AS dw2_11,
SUM(dscores_0) OVER () AS db2_0,
SUM(dscores_1) OVER () AS db2_1,
CASE
SELECT *,
(CASE
WHEN y = 0 THEN (probs_0–1)/num_examples
ELSE probs_0/num_examples
END) AS dscores_0,
(CASE
WHEN y = 1 THEN (probs_1–1)/num_examples
ELSE probs_1/num_examples
END) AS dscores_1
FROM {inner subquery}
SELECT *,
(sum_correct_logprobs/num_examples) + 1e-3*(0.5*(w_00*w_00 + w_01*w_01 + w_10*w_10 + w_11*w_11) + 0.5*(w2_00*w2_00 + w2_01*w2_01 + w2_10*w2_10 + w2_11*w2_11)) AS loss
FROM
(SELECT *,
SUM(correct_logprobs) OVER () sum_correct_logprobs,
COUNT(1) OVER () num_examples
FROM
(SELECT *,
(CASE
WHEN y = 0 THEN -1*LOG(probs_0)
SELECT *,
EXP(scores_0)/(EXP(scores_0) + EXP(scores_1)) AS probs_0,
EXP(scores_1)/(EXP(scores_0) + EXP(scores_1)) AS probs_1
FROM
( SELECT *,
((d0*w2_00 + d1*w2_10) + b2_0) AS scores_0,
((d0*w2_01 + d1*w2_11) + b2_1) AS scores_1
FROM {INNER sub-query})
SELECT *,
(CASE
WHEN ((x1*w_00 + x2*w_10) + b_0) > 0.0 THEN ((x1*w_00 + x2*w_10) + b_0)
ELSE 0.0
END) AS d0,
(CASE
WHEN ((x1*w_01 + x2*w_11) + b_0) > 0.0 THEN ((x1*w_01 + x2*w_11) + b_1)
ELSE 0.0
END) AS d1
FROM {inner subquery}