pre-allocate gpu memory for training to avoid memory Fragmentation.
(cuda_device, mem_ratio=0.95)
| 29 | |
| 30 | |
| 31 | def occupy_mem(cuda_device, mem_ratio=0.95): |
| 32 | """ |
| 33 | pre-allocate gpu memory for training to avoid memory Fragmentation. |
| 34 | """ |
| 35 | total, used = get_total_and_free_memory_in_Mb(cuda_device) |
| 36 | max_mem = int(total * mem_ratio) |
| 37 | block_mem = max_mem - used |
| 38 | x = torch.cuda.FloatTensor(256, 1024, block_mem) |
| 39 | del x |
| 40 | time.sleep(5) |
| 41 | |
| 42 | |
| 43 | def gpu_mem_usage(): |
no test coverage detected