Skip to content

Commit 4b4dad4

Browse files
q10facebook-github-bot
authored andcommitted
Redefine FBGEMM targets with gpu_cpp_library [8/N] (pytorch#194)
Summary: X-link: pytorch#3105 Pull Request resolved: facebookresearch/FBGEMM#194 - Rename `embedding_ops_training` and `embedding_ops_inference` CPU targets and move `embedding_ops_common_cpu` into its own target Reviewed By: sryap Differential Revision: D62415798 fbshipit-source-id: 6d3a8977fb4622100051f706197f21e510ee0ddc
1 parent 50b5b37 commit 4b4dad4

File tree

5 files changed

+36
-24
lines changed

5 files changed

+36
-24
lines changed

fbgemm_gpu/codegen/training/python/split_embedding_codegen_lookup_invoker.template

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,18 @@ from .lookup_args{{ sdesc }} import *
1818

1919
{%- if is_fbcode %}
2020

21+
from fbgemm_gpu.utils.loader import load_torch_module, load_torch_module_bc
2122
# Provide compatibility to downstream packages for eventual migration to the split training / inference packages
2223
try:
23-
try:
24-
torch.ops.load_library("//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_training_gpu")
25-
except Exception:
26-
if torch.version.hip:
27-
torch.ops.load_library(
28-
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_hip_training"
29-
)
30-
else:
31-
torch.ops.load_library(
32-
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_cuda_training"
33-
)
34-
torch.ops.load_library("//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_cpu_training")
35-
24+
load_torch_module(
25+
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_training_gpu",
26+
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_cuda_training",
27+
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_hip_training",
28+
)
29+
load_torch_module_bc(
30+
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_training_cpu",
31+
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_cpu_training",
32+
)
3633
except Exception:
3734
torch.ops.load_library("//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops")
3835
torch.ops.load_library("//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_cpu")

fbgemm_gpu/codegen/training/python/split_embedding_optimizer_codegen.template

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import logging
2222

2323
{%- if is_fbcode %}
2424

25+
from fbgemm_gpu.utils.loader import load_torch_module, load_torch_module_bc
26+
2527
def _load_library(unified_path: str, cuda_path: str, hip_path: str) -> None:
2628
try:
2729
torch.ops.load_library(unified_path)
@@ -32,17 +34,18 @@ def _load_library(unified_path: str, cuda_path: str, hip_path: str) -> None:
3234
else:
3335
torch.ops.load_library(cuda_path)
3436

35-
torch.ops.load_library(
36-
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_cpu_training"
37+
load_torch_module_bc(
38+
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_training_cpu",
39+
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_cpu_training",
3740
)
3841

39-
_load_library(
42+
load_torch_module(
4043
"//deeplearning/fbgemm/fbgemm_gpu/codegen:optimizer_ops",
4144
"//deeplearning/fbgemm/fbgemm_gpu/codegen:optimizer_ops_cuda",
4245
"//deeplearning/fbgemm/fbgemm_gpu/codegen:optimizer_ops_hip",
4346
)
4447

45-
_load_library(
48+
load_torch_module(
4649
"//deeplearning/fbgemm/fbgemm_gpu:split_table_batched_embeddings",
4750
"//deeplearning/fbgemm/fbgemm_gpu:split_table_batched_embeddings",
4851
"//deeplearning/fbgemm/fbgemm_gpu:split_table_batched_embeddings_hip",

fbgemm_gpu/fbgemm_gpu/split_table_batched_embeddings_ops_inference.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,21 @@
3131
round_up,
3232
SplitState,
3333
)
34-
from fbgemm_gpu.utils.loader import load_torch_module
34+
from fbgemm_gpu.utils.loader import load_torch_module, load_torch_module_bc
3535

3636
try:
3737
load_torch_module(
3838
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_inference_gpu",
3939
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_cuda_inference",
4040
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_hip_inference",
4141
)
42-
torch.ops.load_library(
43-
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_cpu_inference"
42+
except Exception:
43+
pass
44+
45+
try:
46+
load_torch_module_bc(
47+
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_inference_cpu",
48+
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_cpu_inference",
4449
)
4550
except Exception:
4651
pass

fbgemm_gpu/fbgemm_gpu/split_table_batched_embeddings_ops_training.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@
5050
is_torchdynamo_compiling,
5151
)
5252

53-
from fbgemm_gpu.utils.loader import load_torch_module
53+
from fbgemm_gpu.utils.loader import load_torch_module, load_torch_module_bc
5454

5555
try:
5656
load_torch_module(
5757
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_training_gpu",
5858
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_cuda_training",
5959
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_hip_training",
6060
)
61-
62-
torch.ops.load_library(
63-
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_cpu_training"
61+
load_torch_module_bc(
62+
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_training_cpu",
63+
"//deeplearning/fbgemm/fbgemm_gpu/codegen:embedding_ops_cpu_training",
6464
)
6565
except Exception:
6666
pass

fbgemm_gpu/fbgemm_gpu/utils/loader.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ def load_torch_module(
2727
if not cuda_path:
2828
cuda_path = f"{unified_path}_cuda"
2929
torch.ops.load_library(cuda_path)
30+
31+
32+
def load_torch_module_bc(new_path: str, old_path: str) -> None:
33+
try:
34+
torch.ops.load_library(new_path)
35+
except Exception:
36+
torch.ops.load_library(old_path)

0 commit comments

Comments
 (0)