Skip to content

Commit 146a297

Browse files
committed
use log api from #5424
1 parent b78e5d6 commit 146a297

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

torchvision/utils.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import warnings
44
from functools import wraps
55
from types import FunctionType
6-
from typing import Any, BinaryIO, List, Optional, Tuple, Union
6+
from typing import Any, BinaryIO, List, Optional, Tuple, Union, TypeVar, Callable, cast
77

88
import numpy as np
99
import torch
@@ -549,16 +549,14 @@ def _log_api_usage_once(obj: Any) -> None:
549549
name = obj.__name__
550550
torch._C._log_api_usage_once(f"{obj.__module__}.{name}")
551551

552-
def log_api_usage_once_dec(f):
553-
@wraps(f)
552+
553+
F = TypeVar("F", bound=Callable[..., Any])
554+
555+
556+
def log_api_usage_once_dec(fn: F) -> F:
557+
@wraps(fn)
554558
def wrapper(*args, **kwargs):
555-
event = f.__module__
556-
if f.__name__.endswith("__init__"):
557-
# inside module instantiation
558-
event += args[0].__class__.__name__
559-
else:
560-
event += f.__name__
561-
torch._C._log_api_usage_once(event)
562-
return f(*args, **kwargs)
559+
_log_api_usage_once(fn)
560+
return fn(*args, **kwargs)
563561

564-
return wrapper
562+
return cast(F, wrapper)

0 commit comments

Comments
 (0)