Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Update TensorPoolAllocator doc and add vmem doc #26

Merged
merged 1 commit into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/CPU-Memory-Optimization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# CPU Memory Optimization

## 功能介绍

在 CPU 端,高性能 malloc 库存在大内存分配时带来的 minor pagefault 严重导致的性能问题。该功能能够降低内存的使用量以及 minor pagefault,提升运行性能。
该功能运行时收集信息然后进行优化,所以在运行一定 step 数之后才能观测到性能提升。

## 用户接口

在 CPU 端,目前的 DeepRec 版本支持单机和分布式的内存优化,该优化默认开启,可以使用 `export ENABLE_MEMORY_OPTIMIZATION=0` 命令关闭该优化。
存在两个环境变量:`START_STATISTIC_STEP` 和 `STOP_STATISTIC_STEP`,配置开始收集stats的step和结束收集开始优化的step,默认是1000到1100。可以按以下设置减少一开始的冷启动时间。

```bash
export START_STATISTIC_STEP=100
export STOP_STATISTIC_STEP=200
```

一般最少设置开始 step 为100以去除一开始的初始化图。注意这里的 step 和训练的 step 并不一致。
如果初始化图较多,需要相对应提高相应的 start 和 stop step。
大致运行 `STOP_STATISTIC_STEP` 个step之后可以看到运行时间明显变短。

### 使用 jemalloc
CPU 端可以搭配 jemalloc 库使用内存优化。设置 `MALLOC` 环境变量后在 python 命令前添加` LD_PRELOAD` jemalloc 的动态库即可,比如:

```bash
export MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:20000,muzzy_decay_ms:20000"
LD_PRELOAD=./libjemalloc.so.2 python ...
```

13 changes: 13 additions & 0 deletions docs/GPU-Memory-Optimization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# GPU Memory Optimization

## 功能简介

在 GPU 端,TensorFlow 原生 BFCAllocator 存在显存碎片过多的问题,导致显存浪费。该功能能够减少显存碎片,获得比 BFCAllocator 更少的显存占用。该功能在开始运行的前 K 个 step 收集运行信息并使用 cudaMalloc 分配显存,所以会造成性能下降,在收集信息结束后,开启优化,这时的性能会有所提升。

## 用户接口

在 GPU 端,目前的 DeepRec 版本支持单机版本的显存优化,且只针对训练场景。该优化默认关闭,可以使用 `export TF_GPU_ALLOCATOR=tensorpool` 命令开启该优化。注意该优化目前的性能略差于 BFCAllocator,但显存占用比 BFCAllocator 少。比如推荐模型 DBMTL-MMOE 的性能会下降 1% 左右(从 4.72 global_step/sec 降低到 4.67 global_step/sec),但是显存会减少 23% (从 1509.12 MB 减少到 1155.12 MB)。
存在两个环境变量:`START_STATISTIC_STEP` 和 `STOP_STATISTIC_STEP`,配置开始收集stats的step和结束收集开始优化的step,默认是10到110,可以适当调整。



9 changes: 9 additions & 0 deletions docs/GPU-Virtual-Memory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# GPU虚拟显存

## 功能介绍

使用 GPU 进行训练时通常会遇到显存不足的问题,该优化在显存不足时使用 cuda 的统一内存地址的 cuMemAllocManaged API 来分配显存,可以使用 CPU 内存来增加显存使用,注意这会造成性能下降。

## 用户接口

该优化默认开启,且只在显存不足时使用,可以使用 `export TF_GPU_VMEM=0` 关闭该优化。注意目前的 GPU Memory Optimization 与GPU虚拟显存优化不兼容,开启 GPU Memory Optimization 时会关闭GPU虚拟显存优化。
21 changes: 0 additions & 21 deletions docs/TensorPoolAllocator.md

This file was deleted.

4 changes: 3 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ Smart-Stage
:maxdepth: 2
:caption: Runtime优化

TensorPoolAllocator
CPU-Memory-Optimization
GPU-Memory-Optimization
GPU-Virtual-Memory
```

```{toctree}
Expand Down