HuggingFaceのモデルをメモリから解放する方法の調査。
このリポジトリはHuggingFaceモデルを対象としていますが、PyTorchモデルでも同じ方法が使えます。
This repository is for HuggingFace models, but you can also use PyTorch models.
cd cpu
./run.shcd gpu
./run.sh
C++ CUDA
cd gpu
nvcc main.cu
./a.out4. del model; gc.collect(); + torch.cuda.empty_cache() + torch.cuda.ipc_collect() + torch._C._cuda_clearCublasWorkspaces()
5. del model; gc.collect(); + torch.cuda.empty_cache() + torch.cuda.ipc_collect() + torch._C._cuda_clearCublasWorkspaces() + torch.backends.cuda.cufft_plan_cache.clear()
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()
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














