Skip to content

Remove torch._running_with_deploy() from fbcode, Fix exception handling for torch.ops.load_libraries #3213

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
353 changes: 180 additions & 173 deletions torchrec/distributed/comm_ops.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions torchrec/distributed/dist_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
torch.ops.load_library(
"//deeplearning/fbgemm/fbgemm_gpu:merge_pooled_embeddings_cpu"
)
except OSError:
pass
except (OSError, RuntimeError):
from fbgemm_gpu import sparse_ops # noqa: F401, E402

# OSS
try:
Expand Down
4 changes: 2 additions & 2 deletions torchrec/distributed/embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@
try:
torch.ops.load_library("//deeplearning/fbgemm/fbgemm_gpu:sparse_ops")
torch.ops.load_library("//deeplearning/fbgemm/fbgemm_gpu:sparse_ops_cpu")
except OSError:
pass
except (OSError, RuntimeError):
from fbgemm_gpu import sparse_ops # noqa: F401, E402


logger: logging.Logger = logging.getLogger(__name__)
Expand Down
4 changes: 2 additions & 2 deletions torchrec/distributed/embeddingbag.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
torch.ops.load_library("//deeplearning/fbgemm/fbgemm_gpu:sparse_ops")
torch.ops.load_library("//deeplearning/fbgemm/fbgemm_gpu:sparse_ops_cpu")
torch.ops.load_library("//deeplearning/fbgemm/fbgemm_gpu/codegen:index_select_ops")
except OSError:
pass
except (OSError, RuntimeError):
from fbgemm_gpu import sparse_ops # noqa: F401, E402


def _pin_and_move(tensor: torch.Tensor, device: torch.device) -> torch.Tensor:
Expand Down
4 changes: 2 additions & 2 deletions torchrec/distributed/model_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
try:
torch.ops.load_library("//deeplearning/fbgemm/fbgemm_gpu:sparse_ops")
torch.ops.load_library("//deeplearning/fbgemm/fbgemm_gpu:sparse_ops_cpu")
except OSError:
pass
except (OSError, RuntimeError):
from fbgemm_gpu import sparse_ops # noqa: F401, E402


_DDP_STATE_DICT_PREFIX = "module."
Expand Down
4 changes: 2 additions & 2 deletions torchrec/distributed/quant_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@
try:
torch.ops.load_library("//deeplearning/fbgemm/fbgemm_gpu:sparse_ops")
torch.ops.load_library("//deeplearning/fbgemm/fbgemm_gpu:sparse_ops_cpu")
except OSError:
pass
except (OSError, RuntimeError):
from fbgemm_gpu import sparse_ops # noqa: F401, E402


logger: logging.Logger = logging.getLogger(__name__)
Expand Down
7 changes: 2 additions & 5 deletions torchrec/distributed/train_pipeline/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@

import torch

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

class FSDP2:
pass
class FSDP2:
pass


from torch.distributed.fsdp import FullyShardedDataParallel as FSDP
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
2 changes: 1 addition & 1 deletion torchrec/modules/itep_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
torch.ops.load_library(
"//deeplearning/fbgemm/fbgemm_gpu:intraining_embedding_pruning_gpu"
)
except OSError:
except (OSError, RuntimeError):
pass

logger: logging.Logger = logging.getLogger(__name__)
Expand Down
4 changes: 2 additions & 2 deletions torchrec/quant/embedding_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
try:
torch.ops.load_library("//deeplearning/fbgemm/fbgemm_gpu:sparse_ops")
torch.ops.load_library("//deeplearning/fbgemm/fbgemm_gpu:sparse_ops_cpu")
except OSError:
pass
except (OSError, RuntimeError):
from fbgemm_gpu import sparse_ops # noqa: F401, E402

# OSS
try:
Expand Down
4 changes: 2 additions & 2 deletions torchrec/sparse/jagged_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
torch.ops.load_library(
"//deeplearning/fbgemm/fbgemm_gpu:permute_multi_embedding_ops_gpu"
)
except OSError:
pass
except (OSError, RuntimeError):
from fbgemm_gpu import sparse_ops # noqa: F401, E402


logger: logging.Logger = logging.getLogger()
Expand Down
Loading