如何识别链接器中的 GPU 内存瓶颈

How to identify GPU memory bottleneck in chainer

我有一个 chainer 模型,有时由于 cupy.cuda.memory.OutOfMemoryError 而崩溃。由于它发生的确切位置取决于批处理元素的大小,我想知道是否有一种方法可以识别链接器模型中的内存瓶颈?

您可以参考CupyMemoryProfileHook

    Code example::
        from chainer.function_hooks import CupyMemoryProfileHook
        hook = CupyMemoryProfileHook()
        with hook:
            trainer.run()
        hook.print_report()
    Output example::
               FunctionName  UsedBytes  AcquiredBytes  Occurrence
             LinearFunction     5.16GB       179.98MB        3900
                       ReLU   991.82MB       458.97MB        2600
        SoftmaxCrossEntropy     7.71MB         5.08MB        1300
                   Accuracy   617.97KB       351.00KB         700