Skip to content

Remove torch deploy usage in torchrec #3217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
74 changes: 34 additions & 40 deletions torchrec/distributed/comm_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ def get_gradient_division() -> bool:


def set_use_sync_collectives(val: bool) -> None:
if val and torch._running_with_deploy():
raise RuntimeError(
"TorchRec sync_collectives are not supported in torch.deploy."
)

global USE_SYNC_COLLECTIVES
USE_SYNC_COLLECTIVES = val

Expand Down Expand Up @@ -2356,43 +2351,42 @@ def backward(ctx, grad_output: Tensor) -> Tuple[None, None, Tensor]:
return (None, None, myreq.dummy_tensor)


if not torch._running_with_deploy(): # noqa C901
# Torch Library op def can not be used in Deploy
class AllToAllSingle(torch.autograd.Function):
@staticmethod
# pyre-fixme[14]: `forward` overrides method defined in `Function` inconsistently.
def forward(
# pyre-fixme[2]: Parameter must be annotated.
ctx,
input: Tensor,
output_split_sizes: List[int],
input_split_sizes: List[int],
group_name: str,
group_size: int,
gradient_division: bool,
) -> Tensor:
ctx.output_split_sizes = input_split_sizes
ctx.input_split_sizes = output_split_sizes
ctx.group_name = group_name
ctx.group_size = group_size
ctx.gradient_division = gradient_division
return torch.distributed._functional_collectives.all_to_all_single(
input, output_split_sizes, input_split_sizes, group_name
)
# Torch Library op def
class AllToAllSingle(torch.autograd.Function):
@staticmethod
# pyre-fixme[14]: `forward` overrides method defined in `Function` inconsistently.
def forward(
# pyre-fixme[2]: Parameter must be annotated.
ctx,
input: Tensor,
output_split_sizes: List[int],
input_split_sizes: List[int],
group_name: str,
group_size: int,
gradient_division: bool,
) -> Tensor:
ctx.output_split_sizes = input_split_sizes
ctx.input_split_sizes = output_split_sizes
ctx.group_name = group_name
ctx.group_size = group_size
ctx.gradient_division = gradient_division
return torch.distributed._functional_collectives.all_to_all_single(
input, output_split_sizes, input_split_sizes, group_name
)

@staticmethod
# pyre-ignore
def backward(ctx, grad):
grad = torch.distributed._functional_collectives.all_to_all_single(
grad,
ctx.output_split_sizes,
ctx.input_split_sizes,
ctx.group_name,
)
if ctx.gradient_division:
grad.div_(ctx.group_size)
@staticmethod
# pyre-ignore
def backward(ctx, grad):
grad = torch.distributed._functional_collectives.all_to_all_single(
grad,
ctx.output_split_sizes,
ctx.input_split_sizes,
ctx.group_name,
)
if ctx.gradient_division:
grad.div_(ctx.group_size)

return grad, None, None, None, None, None
return grad, None, None, None, None, None

# torchrec::reduce_scatter_tensor
@torch.library.custom_op("torchrec::reduce_scatter_tensor", mutates_args=())
Expand Down
8 changes: 1 addition & 7 deletions torchrec/distributed/train_pipeline/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@

import torch

if not torch._running_with_deploy():
from torch.distributed._composable.fsdp.fully_shard import FSDPModule as FSDP2
else:

class FSDP2:
pass

from torch.distributed._composable.fsdp.fully_shard import FSDPModule as FSDP2

from torch.distributed.fsdp import FullyShardedDataParallel as FSDP
from torch.fx.immutable_collections import (
Expand Down
3 changes: 1 addition & 2 deletions torchrec/distributed/train_pipeline/train_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@
except ImportError:
logger.warning("torchrec_use_sync_collectives is not available")

if not torch._running_with_deploy():
torch.ops.import_module("fbgemm_gpu.sparse_ops")
torch.ops.import_module("fbgemm_gpu.sparse_ops")


# Note: doesn't make much sense but better than throwing.
Expand Down
Loading