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
Data and codes for ACL 2021 paper: Towards Emotional Support Dialog Systems

Emotional-Support-Conversation Copyright © 2021 CoAI Group, Tsinghua University. All rights reserved. Data and codes are for academic research use onl

126 Dec 21, 2022
CausalNLP is a practical toolkit for causal inference with text as treatment, outcome, or "controlled-for" variable.

CausalNLP CausalNLP is a practical toolkit for causal inference with text as treatment, outcome, or "controlled-for" variable. Install pip install -U

Arun S. Maiya 95 Jan 03, 2023
A Pythonic library for Nvidia Codec.

A Pythonic library for Nvidia Codec. The project is still in active development; expect breaking changes. Why another Python library for Nvidia Codec?

Zesen Qian 12 Dec 27, 2022
Adversarial Learning for Semi-supervised Semantic Segmentation, BMVC 2018

Adversarial Learning for Semi-supervised Semantic Segmentation This repo is the pytorch implementation of the following paper: Adversarial Learning fo

Wayne Hung 464 Dec 19, 2022
A minimalist tool to display a network graph.

A tool to get a minimalist view of any architecture This tool has only be tested with the models included in this repo. Therefore, I can't guarantee t

Thibault Castells 1 Feb 11, 2022
Clockwork Variational Autoencoder

Clockwork Variational Autoencoders (CW-VAE) Vaibhav Saxena, Jimmy Ba, Danijar Hafner If you find this code useful, please reference in your paper: @ar

Vaibhav Saxena 35 Nov 06, 2022
Social Distancing Detector

Computer vision has opened up a lot of opportunities to explore into AI domain that were earlier highly limited. Here is an application of haarcascade classifier and OpenCV to develop a social distan

Ashish Pandey 2 Jul 18, 2022
Official implementation of "Synthetic Temporal Anomaly Guided End-to-End Video Anomaly Detection" (ICCV Workshops 2021: RSL-CV).

Official PyTorch implementation of "Synthetic Temporal Anomaly Guided End-to-End Video Anomaly Detection" This is the implementation of the paper "Syn

Marcella Astrid 11 Oct 07, 2022
Improving Transferability of Representations via Augmentation-Aware Self-Supervision

Improving Transferability of Representations via Augmentation-Aware Self-Supervision Accepted to NeurIPS 2021 TL;DR: Learning augmentation-aware infor

hankook 38 Sep 16, 2022
Simulation code and tutorial for BBHnet training data

Simulation Dataset for BBHnet NOTE: OLD README, UPDATE IN PROGRESS We generate simulation dataset to train BBHnet, our deep learning framework for det

0 May 31, 2022
SatelliteNeRF - PyTorch-based Neural Radiance Fields adapted to satellite domain

SatelliteNeRF PyTorch-based Neural Radiance Fields adapted to satellite domain.

Kai Zhang 46 Nov 20, 2022
FLVIS: Feedback Loop Based Visual Initial SLAM

FLVIS Feedback Loop Based Visual Inertial SLAM 1-Video EuRoC DataSet MH_05 Handheld Test in Lab FlVIS on UAV Platform 2-Relevent Publication: Under Re

UAV Lab - HKPolyU 182 Dec 04, 2022
Multi-Task Learning as a Bargaining Game

Nash-MTL Official implementation of "Multi-Task Learning as a Bargaining Game". Setup environment conda create -n nashmtl python=3.9.7 conda activate

Aviv Navon 87 Dec 26, 2022
[ACL 20] Probing Linguistic Features of Sentence-level Representations in Neural Relation Extraction

REval Table of Contents Introduction Overview Requirements Installation Probing Usage Citation License 🎓 Introduction REval is a simple framework for

13 Jan 06, 2023
Barbershop: GAN-based Image Compositing using Segmentation Masks (SIGGRAPH Asia 2021)

Barbershop: GAN-based Image Compositing using Segmentation Masks Barbershop: GAN-based Image Compositing using Segmentation Masks Peihao Zhu, Rameen A

Peihao Zhu 928 Dec 30, 2022
Multistream CNN for Robust Acoustic Modeling

Multistream Convolutional Neural Network (CNN) A multistream CNN is a novel neural network architecture for robust acoustic modeling in speech recogni

ASAPP Research 37 Sep 21, 2022
PyTorch code for 'Efficient Single Image Super-Resolution Using Dual Path Connections with Multiple Scale Learning'

Efficient Single Image Super-Resolution Using Dual Path Connections with Multiple Scale Learning This repository is for EMSRDPN introduced in the foll

7 Feb 10, 2022
A modular, research-friendly framework for high-performance and inference of sequence models at many scales

T5X T5X is a modular, composable, research-friendly framework for high-performance, configurable, self-service training, evaluation, and inference of

Google Research 1.1k Jan 08, 2023
Interpretable and Generalizable Person Re-Identification with Query-Adaptive Convolution and Temporal Lifting

QAConv Interpretable and Generalizable Person Re-Identification with Query-Adaptive Convolution and Temporal Lifting This PyTorch code is proposed in

Shengcai Liao 166 Dec 28, 2022
a reimplementation of Optical Flow Estimation using a Spatial Pyramid Network in PyTorch

pytorch-spynet This is a personal reimplementation of SPyNet [1] using PyTorch. Should you be making use of this work, please cite the paper according

Simon Niklaus 269 Jan 02, 2023