Tf alloc - Simplication of GPU allocation for Tensorflow2

Related tags

Deep Learningtf_alloc
Overview

tf_alloc

Simpliying GPU allocation for Tensorflow

  • Developer: korkite (Junseo Ko)

Installation

pip install tf-alloc

⭐️ Why tf_alloc? Problems?

  • Compare to pytorch, tensorflow allocate all GPU memory to single training.
  • However, it is too much waste because, some training does not use whole GPU memory.
  • To solve this problem, TF engineers use two methods.
  1. Limit to use only single GPU
  2. Limit the use of only a certain percentage of GPUs.
  • However, these methods require complex code and memory management.

⭐️ Why tf_alloc? How to solve?

tf_alloc simplfy and automate GPU allocation using two methods.

⭐️ How to allocate?

  • Before using tf_alloc, you have to install tensorflow fits for your environment.
  • This library does not install specific tensorflow version.
# On the top of the code
from tf_alloc import allocate as talloc
talloc(gpu=1, percentage=0.5)

import tensorflow as tf
""" your code"""

It is only code for allocating GPU in certain percentage.

Parameters:

  • gpu = which gpu you want to use (if you have two gpu than [0, 1] is possible)
  • percentage = the percentage of memory usage on single gpu. 1.0 for maximum use.

⭐️ Additional Function.

GET GPU Objects

gpu_objs = get_gpu_objects()
  • To use this code, you can get gpu objects that contains gpu information.
  • You can set GPU backend by using this function.

GET CURRENT STATE

Defualt
current(
    gpu_id = False, 
    total_memory=False, 
    used = False, 
    free = False, 
    percentage_of_use = False,
    percentage_of_free = False,
)
  • You can use this functions to see current GPU state and possible maximum allocation percentage.
  • Without any parameters, than it only visualize possible maximum allocation percentage.
  • It is cmd line visualizer. It doesn't return values.

Parameters

  • gpu_id = visualize the gpu id number
  • total_memory = visualize the total memory of GPU
  • used = visualize the used memory of GPU
  • free = visualize the free memory of GPU
  • percentage_of_used = visualize the percentage of used memory of GPU
  • percentage_of_free = visualize the percentage of free memory of GPU

한국어는 간단하게!

설치

pip install tf-alloc

문제정의:

  • 텐서플로우는 파이토치와 다르게 훈련시 GPU를 전부 할당해버립니다.
  • 그러나 실제로 GPU를 모두 사용하지 않기 때문에 큰 낭비가 발생합니다.
  • 이를 막기 위해 두가지 방법이 사용되는데
  1. GPU를 1개만 쓰도록 제한하기
  2. GPU에서 특정 메모리만큼만 사용하도록 제한하기
  • 이 두가지 입니다. 그러나 이 방법을 위해선 복잡한 코드와 메모리 관리가 필요합니다.

해결책:

  • 이것을 해결하기 위해 자동으로 몇번 GPU를 얼만큼만 할당할지 정해주는 코드를 만들었습니다.
  • 함수 하나만 사용하면 됩니다.
# On the top of the code
from tf_alloc import allocate as talloc
talloc(gpu=1, percentage=0.5)

import tensorflow as tf
""" your code"""
  • 맨위에 tf_alloc에서 allocate함수를 불러다가 gpu파라미터와 percentage 파라미터를 주어 호출합니다.
  • 그러면 자동으로 몇번의 GPU를 얼만큼의 비율로 사용할지 정해서 할당합니다.
  • 매우 쉽습니다.

파라미터 설명

  • gpu = 몇범 GPU를 쓸 것인지 GPU의 아이디를 넣어줍니다. (만약 gpu가 2개 있다면 0, 1 이 아이디가 됩니다.)

  • percentage = 선택한 GPU를 몇의 비율로 쓸건지 정해줍니다. (1.0을 넣으면 해당 GPU를 전부 씁니다)

  • 만약 percentage가 몇인지 모른다면 0에서 1 사이의 값을 넣어서 할당해보면 최대 사용가능량이 얼만큼이라고 에러를 출력하니까 걱정없이 사용하시면 됩니다. 다른 훈련에 방해를 주지 않기 때문에, nvidia-smi를 쳐가면서 할당을 하는 것보다 매우 안정적입니다.

  • 핵심기능만 한국어로 써 놓았고, 다른 기능은 영문버전을 확인해보시면 감사하겠습니다.

Owner
Junseo Ko
🙃 AI Engineer 😊
Junseo Ko
A Python wrapper for Google Tesseract

Python Tesseract Python-tesseract is an optical character recognition (OCR) tool for python. That is, it will recognize and "read" the text embedded i

Matthias A Lee 4.6k Jan 05, 2023
Using Streamlit to host a multi-page tool with model specs and classification metrics, while also accepting user input values for prediction.

Predicitng_viability Using Streamlit to host a multi-page tool with model specs and classification metrics, while also accepting user input values for

Gopalika Sharma 1 Nov 08, 2021
BC3407-Group-5-Project - BC3407 Group Project With Python

BC3407-Group-5-Project As the world struggles to contain the ever-changing varia

1 Jan 26, 2022
Reproducing-BowNet: Learning Representations by Predicting Bags of Visual Words

Reproducing-BowNet Our reproducibility effort based on the 2020 ML Reproducibility Challenge. We are reproducing the results of this CVPR 2020 paper:

6 Mar 16, 2022
"NAS-Bench-301 and the Case for Surrogate Benchmarks for Neural Architecture Search".

NAS-Bench-301 This repository containts code for the paper: "NAS-Bench-301 and the Case for Surrogate Benchmarks for Neural Architecture Search". The

AutoML-Freiburg-Hannover 57 Nov 30, 2022
Official PyTorch implementation of "IntegralAction: Pose-driven Feature Integration for Robust Human Action Recognition in Videos", CVPRW 2021

IntegralAction: Pose-driven Feature Integration for Robust Human Action Recognition in Videos Introduction This repo is official PyTorch implementatio

Gyeongsik Moon 29 Sep 24, 2022
[ECCV 2020] Reimplementation of 3DDFAv2, including face mesh, head pose, landmarks, and more.

Stable Head Pose Estimation and Landmark Regression via 3D Dense Face Reconstruction Reimplementation of (ECCV 2020) Towards Fast, Accurate and Stable

Remilia Scarlet 221 Dec 30, 2022
Towards Interpretable Deep Metric Learning with Structural Matching

DIML Created by Wenliang Zhao*, Yongming Rao*, Ziyi Wang, Jiwen Lu, Jie Zhou This repository contains PyTorch implementation for paper Towards Interpr

Wenliang Zhao 75 Nov 11, 2022
Epidemiology analysis package

zEpid zEpid is an epidemiology analysis package, providing easy to use tools for epidemiologists coding in Python 3.5+. The purpose of this library is

Paul Zivich 111 Jan 08, 2023
Gated-Shape CNN for Semantic Segmentation (ICCV 2019)

GSCNN This is the official code for: Gated-SCNN: Gated Shape CNNs for Semantic Segmentation Towaki Takikawa, David Acuna, Varun Jampani, Sanja Fidler

859 Dec 26, 2022
code from "Tensor decomposition of higher-order correlations by nonlinear Hebbian plasticity"

Code associated with the paper "Tensor decomposition of higher-order correlations by nonlinear Hebbian learning," Ocker & Buice, Neurips 2021. "plot_f

Gabriel Koch Ocker 4 Oct 16, 2022
CVPR2021 Workshop - HDRUNet: Single Image HDR Reconstruction with Denoising and Dequantization.

HDRUNet [Paper Link] HDRUNet: Single Image HDR Reconstruction with Denoising and Dequantization By Xiangyu Chen, Yihao Liu, Zhengwen Zhang, Yu Qiao an

XyChen 105 Dec 20, 2022
Detection of drones using their thermal signatures from thermal camera through YOLO-V3 based CNN with modifications to encapsulate drone motion

Drone Detection using Thermal Signature This repository highlights the work for night-time drone detection using a using an Optris PI Lightweight ther

Chong Yu Quan 6 Dec 31, 2022
ROS support for Velodyne 3D LIDARs

Overview Velodyne1 is a collection of ROS2 packages supporting Velodyne high definition 3D LIDARs3. Warning: The master branch normally contains code

ROS device drivers 543 Dec 30, 2022
Commonality in Natural Images Rescues GANs: Pretraining GANs with Generic and Privacy-free Synthetic Data - Official PyTorch Implementation (CVPR 2022)

Commonality in Natural Images Rescues GANs: Pretraining GANs with Generic and Privacy-free Synthetic Data (CVPR 2022) Potentials of primitive shapes f

31 Sep 27, 2022
Transformer part of 12th place solution in Riiid! Answer Correctness Prediction

kaggle_riiid Transformer part of 12th place solution in Riiid! Answer Correctness Prediction. Please see here for more information. Execution You need

Sakami Kosuke 2 Apr 23, 2022
A large-scale face dataset for face parsing, recognition, generation and editing.

CelebAMask-HQ [Paper] [Demo] CelebAMask-HQ is a large-scale face image dataset that has 30,000 high-resolution face images selected from the CelebA da

switchnorm 1.7k Dec 26, 2022
Combining Automatic Labelers and Expert Annotations for Accurate Radiology Report Labeling Using BERT

CheXbert: Combining Automatic Labelers and Expert Annotations for Accurate Radiology Report Labeling Using BERT CheXbert is an accurate, automated dee

Stanford Machine Learning Group 51 Dec 08, 2022
Code used for the results in the paper "ClassMix: Segmentation-Based Data Augmentation for Semi-Supervised Learning"

Code used for the results in the paper "ClassMix: Segmentation-Based Data Augmentation for Semi-Supervised Learning" Getting started Prerequisites CUD

70 Dec 02, 2022
Code to go with the paper "Decentralized Bayesian Learning with Metropolis-Adjusted Hamiltonian Monte Carlo"

dblmahmc Code to go with the paper "Decentralized Bayesian Learning with Metropolis-Adjusted Hamiltonian Monte Carlo" Requirements: https://github.com

1 Dec 17, 2021