A context was still active when the context stack was being cleaned up. At this point in our execution, CUDA may already have been deinitialized, so there is no way we can finish cleanly. The program will be aborted now. Use Context.pop() to avoid this problem.
时间: 2023-12-06 15:43:36 浏览: 367
这个错误通常发生在使用PyTorch和CUDA时,它表示您的程序在清理上下文堆栈时仍然具有活动上下文。这通常是由于没有正确释放CUDA资源所致。您可以尝试在程序结束时手动调用`torch.cuda.empty_cache()`来清理GPU缓存,或者使用`with torch.no_grad():`语句块来避免在计算梯度时创建不必要的计算图。此外,确保您的代码中没有未清理的上下文,如正在运行的线程或未关闭的文件。
阅读全文