This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os,requests,platform,json,subprocess | |
import tarfile | |
from zipfile import ZipFile | |
debug=False | |
os_type=platform.system().lower() | |
machine_type=platform.machine().lower() | |
if debug:print(f'Your OS and Machine Type is {os_type} and {machine_type}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
def consume_gpu_ram(n): return torch.ones((n, n)).cuda() | |
def consume_gpu_ram_256mb(): return consume_gpu_ram(2**13) | |
def b2mb(x): return int(x/2**20) | |
class TorchTracemalloc(): | |
def __enter__(self): | |
self.begin = torch.cuda.memory_allocated() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, re | |
from io import StringIO | |
# When any function contains print() calls that get overwritten, like progress bars, | |
# a special care needs to be applied, since under pytest -s captured output (capsys | |
# or contextlib.redirect_stdout) contains any temporary printed strings, followed by | |
# \r's. This helper function ensures that the buffer will contain the same output | |
# with and without -s in pytest, by turning: | |
# foo bar\r tar mar\r final message | |
# into: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tracemalloc, threading, torch, time, pynvml | |
from fastai.utils.mem import * | |
from fastai.vision import * | |
if not torch.cuda.is_available(): raise Exception("pytorch is required") | |
def preload_pytorch(): | |
torch.ones((1, 1)).cuda() | |
def gpu_mem_get_used_no_cache(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usage: | |
# pypi_module_version_is_available("Pillow", "5.4.0") | |
import subprocess | |
def pypi_module_version_is_available(module, version): | |
"Check whether module==version is available on pypi" | |
# returns True/False (or None if failed to execute the check) | |
# using a hack that when passing "module==" w/ no version number to pip | |
# it "fails" and returns all the available versions in stderr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pathlib, PIL, random, os, gzip | |
import numpy as np | |
def load_mnist(path, kind='train'): | |
"""Load MNIST data from `path`""" | |
labels_path = os.path.join(path, '%s-labels-idx1-ubyte.gz' % kind) | |
images_path = os.path.join(path, '%s-images-idx3-ubyte.gz' % kind) | |
with gzip.open(labels_path, 'rb') as lbpath: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#set -x | |
package="fastai" | |
ver="1.0.14" | |
# is_pip_ver_available "1.0.14" | |
# returns 1 if yes, 0 otherwise | |
function is_pip_ver_available() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from __future__ import print_function | |
# | |
# A simple CGI script useful for debugging GitHub web hooks | |
# https://developer.github.com/webhooks/ | |
# | |
import hashlib, hmac, json, os, sys, traceback | |
from subprocess import Popen, PIPE, STDOUT |
NewerOlder