Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions transformer_engine/jax/cpp_extensions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ def _warn_gspmd_deprecation_once():
global _gspmd_deprecation_warned
if not _gspmd_deprecation_warned:
warnings.warn(
"GSPMD sharding propagation is planned to be removed in June 2026."
" It is no longer maintained or tested. Use it at your own risk."
" Please use Shardy partitioner instead."
"GSPMD sharding propagation rules in TE-JAX are planned to be removed in June 2026."
" They are no longer maintained or tested. Use them at your own risk."
" Please use Shardy propagation instead."
" In case you cannot upgrade to a JAX version that supports Shardy, please reach out!",
DeprecationWarning,
stacklevel=3,
stacklevel=2,
)
_gspmd_deprecation_warned = True

Expand Down Expand Up @@ -234,12 +234,24 @@ def name_of_wrapper_p():
outer_p.def_abstract_eval(cls.outer_abstract)
batching.primitive_batchers[outer_p] = cls.batcher
outer_p_lower = custom_partitioning(cls.impl, static_argnums=cls.impl_static_args)

if _JAX_GSPMD_SUPPORTED:
if "infer_sharding_from_operands" in cls.__dict__:
_warn_gspmd_deprecation_once()
gspmd_kwargs = {"infer_sharding_from_operands": cls.infer_sharding_from_operands}
fn = cls.__dict__.get("infer_sharding_from_operands")
if fn is not None:
actual_fn = (
cls.infer_sharding_from_operands
) # Use descriptor protocol to unwrap staticmethod

def _gspmd_wrapper(*args, **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If JAX has issues internally with the signature here, you may need the functools.wraps decorator

_warn_gspmd_deprecation_once()
return actual_fn(*args, **kwargs)

gspmd_kwargs = {"infer_sharding_from_operands": _gspmd_wrapper}
else:
gspmd_kwargs = {"infer_sharding_from_operands": cls.infer_sharding_from_operands}
else:
gspmd_kwargs = {}

outer_p_lower.def_partition(
partition=cls.partition,
sharding_rule=cls.shardy_sharding_rule,
Expand Down
Loading