Skip to content

Commit a530e12

Browse files
committed
[API-Compat] Largely cut down the decorator overhead
1 parent 6098be8 commit a530e12

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

python/paddle/utils/decorator_utils.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,6 @@ def wrapper(*args: _InputT.args, **kwargs: _InputT.kwargs) -> _RetT:
297297
class ForbidKeywordsDecorator(DecoratorBase):
298298
"""A decorator that hints users to use the correct `compat` functions, when erroneous keyword arguments are detected"""
299299

300-
_site_format = (
301-
"https://www.paddlepaddle.org.cn/documentation/docs/en/develop/"
302-
"guides/model_convert/convert_from_pytorch/api_difference/{url_suffix}.html"
303-
)
304-
305300
def __init__(
306301
self,
307302
illegal_keys: set[str],
@@ -326,7 +321,9 @@ def __init__(
326321
self.illegal_keys = illegal_keys
327322
self.func_name = func_name
328323
self.correct_name = correct_name
329-
self.url_suffix = url_suffix
324+
self.warn_msg = None
325+
if url_suffix:
326+
self.warn_msg = f"\nNon compatible API. Please refer to https://www.paddlepaddle.org.cn/documentation/docs/en/develop/guides/model_convert/convert_from_pytorch/api_difference/{url_suffix}.html first."
330327

331328
def process(
332329
self, args: tuple[Any, ...], kwargs: dict[str, Any]
@@ -342,10 +339,9 @@ def process(
342339
f"{self.func_name}() received unexpected keyword argument{plural} {keys_str}. "
343340
f"\nDid you mean to use {self.correct_name}() instead?"
344341
)
345-
if self.url_suffix:
342+
if self.warn_msg is not None:
346343
warnings.warn(
347-
f"\nThis is a non compatible API. Please refer to {self._site_format.format(url_suffix=self.url_suffix)} first."
348-
f"\nA compatible version of this API: `{self.correct_name}` can be also used, make sure the correct API is called.",
344+
self.warn_msg,
349345
category=Warning,
350346
)
351347
return args, kwargs

0 commit comments

Comments
 (0)