Skip to content

mjun0812/hf-model-cleanup-experiment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

HuggingFace Model Memory Cleanup Experiment

HuggingFaceのモデルをメモリから解放する方法の調査。
このリポジトリはHuggingFaceモデルを対象としていますが、PyTorchモデルでも同じ方法が使えます。

This repository is for HuggingFace models, but you can also use PyTorch models.

CPU

cd cpu
./run.sh

1. del model; gc.collect();で削除

1

2. モデルのパラメータを手動で削除 + del model; gc.collect();

2

3. del model; gc.collect(); + ctypes.CDLL("libc.so.6")で削除

3

4. モデルのパラメータを手動で削除 + del model; gc.collect(); + ctypes.CDLL("libc.so.6")で削除

4

5. os.environ["MALLOC_TRIM_THRESHOLD_"] = "-1" + del model; gc.collect();で削除

5

6. export MALLOC_TRIM_THRESHOLD_=-1 + del model; gc.collect();で削除

6

All

all

GPU

cd gpu
./run.sh

C++ CUDA

cd gpu
nvcc main.cu
./a.out

1. del model; gc.collect();

1-gpu

2. del model; gc.collect(); + torch.cuda.empty_cache()

2-gpu

3. del model; gc.collect(); + torch.cuda.empty_cache() + torch.cuda.ipc_collect()

3-gpu

4. del model; gc.collect(); + torch.cuda.empty_cache() + torch.cuda.ipc_collect() + torch._C._cuda_clearCublasWorkspaces()

4-gpu

5. del model; gc.collect(); + torch.cuda.empty_cache() + torch.cuda.ipc_collect() + torch._C._cuda_clearCublasWorkspaces() + torch.backends.cuda.cufft_plan_cache.clear()

5-gpu

6. model.to("cpu") + del model; gc.collect(); + torch.cuda.empty_cache() + torch.cuda.ipc_collect() + torch._C._cuda_clearCublasWorkspaces() + torch.backends.cuda.cufft_plan_cache.clear()

6-gpu

7. model.to("cpu") + del model; gc.collect(); + torch.cuda.empty_cache() + torch.cuda.ipc_collect() + torch._C._cuda_clearCublasWorkspaces() + torch.backends.cuda.cufft_plan_cache.clear() + cudaDeviceReset()

Error

8. .to("cpu") + del model; gc.collect();

8-gpu

All

all-gpu

About

🧪 Hugging Face のモデルをCPU RAM/GPU VRAMから解放する方法を検証するリポジトリ | A verification repository for unloading Hugging Face models from CPU RAM/GPU VRAM memory

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors