Skip to content

Commit c71622f

Browse files
yiwen-songdatumbox
authored andcommitted
[fbsync] add docstring for _log_api_usage_once (#5273)
Summary: * add docstring for _log_api_usage_once * lint * rephrase Reviewed By: kazhang Differential Revision: D33927494 fbshipit-source-id: 95c33f2f0fb8b576ce5528cc98f33661556c4819 Co-authored-by: Vasilis Vryniotis <[email protected]>
1 parent a4cc60d commit c71622f

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

torchvision/utils.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import pathlib
33
import warnings
44
from types import FunctionType
5-
from typing import Any, Union, Optional, List, Tuple, BinaryIO
5+
from typing import Any, BinaryIO, List, Optional, Tuple, Union
66

77
import numpy as np
88
import torch
9-
from PIL import Image, ImageDraw, ImageFont, ImageColor
9+
from PIL import Image, ImageColor, ImageDraw, ImageFont
1010

1111
__all__ = ["make_grid", "save_image", "draw_bounding_boxes", "draw_segmentation_masks", "draw_keypoints"]
1212

@@ -388,6 +388,23 @@ def _generate_color_palette(num_masks: int):
388388

389389

390390
def _log_api_usage_once(obj: Any) -> None:
391+
392+
"""
393+
Logs API usage(module and name) within an organization.
394+
In a large ecosystem, it's often useful to track the PyTorch and
395+
TorchVision APIs usage. This API provides the similar functionality to the
396+
logging module in the Python stdlib. It can be used for debugging purpose
397+
to log which methods are used and by default it is inactive, unless the user
398+
manually subscribes a logger via the `SetAPIUsageLogger method <https://github.com/pytorch/pytorch/blob/eb3b9fe719b21fae13c7a7cf3253f970290a573e/c10/util/Logging.cpp#L114>`_.
399+
Please note it is triggered only once for the same API call within a process.
400+
It does not collect any data from open-source users since it is no-op by default.
401+
For more information, please refer to
402+
* PyTorch note: https://pytorch.org/docs/stable/notes/large_scale_deployments.html#api-usage-logging;
403+
* Logging policy: https://github.com/pytorch/vision/issues/5052;
404+
405+
Args:
406+
obj (class instance or method): an object to extract info from.
407+
"""
391408
if not obj.__module__.startswith("torchvision"):
392409
return
393410
name = obj.__class__.__name__

0 commit comments

Comments
 (0)