What does 'torch._C._log_api_usage_once' do?

For example it is used here,

def _log_api_usage(identifier: str):
    Internal function used to log the usage of different detectron2 components
    inside facebook's infra.
    torch._C._log_api_usage_once("detectron2." + identifier)

But why would I need to log these and where does it log and what is the usage of these logs?

This is strictly debugging and, as the comment indicates, quite likely most of the usage is inside facebook. If you set the environment variable


you can see that PyTorch records “which parts of PyTorch are involved”, quite likely to give you a rough idea where to look (and whom to have look) if something unexpected happens.
PyTorch has grown quite huge with lots of moving bits and sometimes unexpected interactions, so having a quick idea of how to narrow things down or compare high-level processing flow between versions is a debug help.

Bast regards


Thank you for the great answer!