Skip to content

Instantly share code, notes, and snippets.

View ay27's full-sized avatar
:octocat:

Jinmian Ye ay27

:octocat:
  • Tencent
  • Shenzhen, China
View GitHub Profile
@ay27
ay27 / choose_best_gpu.py
Last active December 22, 2019 12:36
[Auto Choose Best GPUs] choose and set the best gpus used in machine learning task, avoid setting CUDA_VISIBLE_DEVICES in every script. #python #cuda
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by ay27 at 2018/4/8
import os
def set_best_gpu(top_k=1):
best_gpu = _scan(top_k)
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = ','.join(map(str, best_gpu))
@ay27
ay27 / TF-cuda_opt.py
Last active September 17, 2021 09:32
[TF CUDA Optimization Options] All the tensorflow with cuda optimization you need! Will speedup at least 1.3 times in Volta and Turing architecture! Only works with the tensorflow gpu version build from source with cuda/cudnn support, or use the docker image from nvidia gpu cloud <ngc.nvidia.com>. #tensorflow #cuda
# mainly from:
# 1. https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#env-vars
# 2. https://github.com/NVIDIA/DeepLearningExamples/issues/57
# 3. https://docs.nvidia.com/deeplearning/frameworks/tensorflow-user-guide/index.html#variablesaddtf
def is_using_hvd():
env_vars = ["OMPI_COMM_WORLD_RANK", "OMPI_COMM_WORLD_SIZE"]
if all([var in os.environ for var in env_vars]):
return True
@ay27
ay27 / logger.py
Created July 31, 2019 02:48
[Fancy Logger] my logger
import datetime
import tensorflow as tf
from tensorflow.contrib.tensorboard.plugins import projector
import numpy as np
import time
try:
import scipy.misc
except ImportError:
@ay27
ay27 / utils.py
Created August 1, 2019 02:04
[Increase matplotlib DPI] increase matplotlib dpi in jupyter and anywhere. #jupyter
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['figure.dpi'] = 300
@ay27
ay27 / some.h
Created October 5, 2019 02:52
[Any implementation in cpp] #any #cpp
class Some {
template <typename T> struct type {
static void id() {}
};
template <typename T> static size_t type_id() {
return reinterpret_cast<size_t>(&type<T>::id);
}