You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduce the mark_deprecated decorator to map deprecated function to the new function. The reason is that existing deprecated function only maps to function with the same name. It's impossible to map function like xrt_world_size to world_size.
Instead of passing old function to the deprecation wrapper, I think use the decorator above the old function is the most straightward.
Example to use:
import torch_xla
from torch_xla.experimental.deprecation import mark_deprecated
@mark_deprecated(torch_xla.runtime.world_size)
def xrt_world_size(defval=1):
"""Retrieves the number of devices which is taking part of the replication.
Args:
defval (int, optional): The default value to be returned in case there is no
replication information available.
Default: 1
Returns:
The number of devices which is taking part of the replication.
"""
global _WORLD_SIZE
if _WORLD_SIZE is not None:
return _WORLD_SIZE
return runtime.world_size()
Output:
>>> import torch_xla
>>> torch_xla.core.xla_model.xrt_world_size()
WARNING:root:torch_xla.core.xla_model.xrt_world_size is deprecated. Use torch_xla.runtime.world_size instead.
1
The decorator makes sense here, but not because It's impossible to map function like xrt_world_size to world_size.. For example, see how these three functions in experimental.pjrt were renamed after being deprecated:
You would need the decorator if the implementation of the old function is actually different than the new one. In this case, the signatures of xrt_world_size ((int) -> int) and world_size (() -> int) differ.
Having said that, you can make mark_deprecatedDRY. Remember that a decorator is a function that takes one function as an argument and returns a function. If you use functools.partial to fill the first argument of deprecated ((module, fn) -> fn), the partial callable is (fn) -> fn (ie a decorator. For any module, you can create a decorator like this:
The decorator makes sense here, but not because It's impossible to map function like xrt_world_size to world_size.. For example, see how these three functions in experimental.pjrt were renamed after being deprecated:
You would need the decorator if the implementation of the old function is actually different than the new one. In this case, the signatures of xrt_world_size ((int) -> int) and world_size (() -> int) differ.
Having said that, you can make mark_deprecatedDRY. Remember that a decorator is a function that takes one function as an argument and returns a function. If you use functools.partial to fill the first argument of deprecated ((module, fn) -> fn), the partial callable is (fn) -> fn (ie a decorator. For any module, you can create a decorator like this:
It will warn like this_module.xla_rendezvous is deprecated with xm.xla_rendezvous, while there is no function named xla_rendezvous originally in this module.
It will warn like this_module.xla_rendezvous is deprecated with xm.xla_rendezvous, while there is no function named xla_rendezvous originally in this module.
I see, good catch. It looks like deprecated is missing a parameter to print the correct warning then. You can add something like this:
def deprecated(module, new_fn, old_name=None):
old_name = old_name or newfn.__name__
...
logging.warning(f'{module.__name__}.{old_name} is deprecated. Use {new.__module__}.{new.__name__} instead.)
...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce the
mark_deprecateddecorator to map deprecated function to the new function. The reason is that existing deprecated function only maps to function with the same name. It's impossible to map function likexrt_world_sizetoworld_size.Instead of passing old function to the deprecation wrapper, I think use the decorator above the old function is the most straightward.
Example to use:
Output: