Skip to content

Instantly share code, notes, and snippets.

@talesa
talesa / model.py
Created December 3, 2020 19:01
simple requeueable slurm job
import argparse
from pathlib import Path
import shutil
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import torch.utils.tensorboard
import torchvision
@talesa
talesa / command.sh
Created October 28, 2020 12:04
playing with zizgpu slurm
sbatch --gres=gpu:1 --partition=ziz-gpu-small slurm.sh
@talesa
talesa / average_bitrate.py
Created February 1, 2020 09:17
average_bitrate.py
import audioread as ar
import os
rootdir = '.'
audio_file_formats = ['wav', 'mp3', 'm4a']
for root, subdirs, files in os.walk(rootdir):
for filename in files:
if filename[-3:] in audio_file_formats:
filepath = os.path.join(root, filename)
@talesa
talesa / various.sh
Last active January 9, 2020 00:15
Various useful bash commands
# lsf bkill all pending jobs
bkill `bjobs -p -o jobid | grep -v ^JOBID | tr '\n' ' '`
# lsf bkill jobs matching pattern
bkill `bjobs -w | grep MultipleGRUs2 | awk '{print $1}' | tr '\n' ' '`
# something to do with the largest snapshots in the directory
du -sh * | sort -rh | head -n 5 | awk '{print $2"/*.pt"}' | xargs -I@ sh -c 'ls @'
class OrthogonalLinear(nn.Module):
""" Implements a non-square linear with orthogonal colums """
def __init__(self, input_size, output_size, lr_factor=0.1):
super(OrthogonalLinear, self).__init__()
self.input_size = input_size
self.output_size = output_size
self.max_size = max(self.input_size, self.output_size)
self.log_orthogonal_kernel = nn.Parameter(torch.Tensor(self.max_size, self.max_size))
self.log_orthogonal_kernel.register_hook(lambda: print("This should not be executed"))
t = (1, 2, [30, 40])
t[2] += [50, 60]
print(t)
# Options:
# a) t becomes (1, 2, [30, 40, 50, 60]).
# b) TypeError is raised with the message 'tuple' object does not support item assignment.
# c) Neither.
# d) Both a and b.
@talesa
talesa / run_experiments.py
Created April 9, 2019 23:12
runs experiments when the previous one is finished
import multiprocessing
import subprocess
import os
def init(queue):
global gpuid
gpuid = queue.get()
gpus_list = list(range(8))
num_gpus = len(gpus_list)
@talesa
talesa / author_list_to_pairs.py
Last active April 4, 2019 22:21
Code for Ewa Siwicka 04/04/2019
filename = 'Network-publishing-database2_short2.csv'
import csv
import itertools
import numpy as np
with open(filename, newline='') as csvfile:
rows = csv.reader(csvfile)
rows = [[i for i in row if i!=''] for row in rows]
@talesa
talesa / online_mean_variance.py
Created January 14, 2019 14:54
online mean & variance estimators
class OnlineStats:
# https://www.johndcook.com/blog/standard_deviation/
# Knuth TAOCP vol 2, 3rd edition, page 232
def __init__(self):
self.n = 0
def push(self, x):
self.n += 1