Skip to content

Instantly share code, notes, and snippets.

View slmatrix's full-sized avatar
🏠
sleeping from home

Bilal Siddiqui slmatrix

🏠
sleeping from home
View GitHub Profile
@afspies
afspies / gpu_allocation.py
Last active September 5, 2024 16:14
Automatic GPU Allocation
# EDIT 10/04/2022 - This version was provided by @jayelm who fixed some bugs and made the function much more robust
import os
import subprocess
import time
def assign_free_gpus(threshold_vram_usage=1500, max_gpus=2, wait=False, sleep_time=10):
"""
Assigns free gpus to the current process via the CUDA_AVAILABLE_DEVICES env variable
This function should be called after all imports,
@amohant4
amohant4 / octave_conv_pytorch.py
Last active May 11, 2021 02:54
Implementation of octave convolution in pytorch
class OctConv(nn.Module):
def __init__(self, ch_in, ch_out, kernel_size, stride=1, alphas=[0.5,0.5]):
super(OctConv, self).__init__()
# Get layer parameters
self.alpha_in, self.alpha_out = alphas
assert 0 <= self.alpha_in <= 1 and 0 <= self.alpha_in <= 1, \
"Alphas must be in interval [0, 1]"
self.kernel_size = kernel_size
self.stride = stride
@weiaicunzai
weiaicunzai / accuracy.py
Created June 22, 2018 13:20
compute top1, top5 error using pytorch
from __future__ import print_function, absolute_import
__all__ = ['accuracy']
def accuracy(output, target, topk=(1,)):
"""Computes the precision@k for the specified values of k"""
maxk = max(topk)
batch_size = target.size(0)
_, pred = output.topk(maxk, 1, True, True)