torchrec 0.2.0.dev0__37-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- examples/__init__.py +0 -0
- examples/datasets/__init__.py +8 -0
- examples/datasets/criteo_dataframes.py +101 -0
- examples/ray/__init__.py +0 -0
- examples/ray/compute_world_size.py +51 -0
- examples/ray/train_torchrec.py +133 -0
- examples/retrieval/__init__.py +6 -0
- examples/retrieval/data/__init__.py +6 -0
- examples/retrieval/data/dataloader.py +44 -0
- examples/retrieval/knn_index.py +67 -0
- examples/retrieval/modules/__init__.py +6 -0
- examples/retrieval/modules/two_tower.py +229 -0
- examples/retrieval/two_tower_retrieval.py +192 -0
- examples/retrieval/two_tower_train.py +253 -0
- examples/torcharrow/__init__.py +8 -0
- examples/torcharrow/dataloader.py +116 -0
- examples/torcharrow/run.py +126 -0
- fbgemm_gpu/__init__.py +16 -0
- fbgemm_gpu/batched_unary_embeddings_ops.py +82 -0
- fbgemm_gpu/enums.py +21 -0
- fbgemm_gpu/fbgemm_gpu_py.so +0 -0
- fbgemm_gpu/permute_pooled_embedding_modules.py +73 -0
- fbgemm_gpu/permute_pooled_embedding_modules_split.py +76 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/__init__.py +19 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_adagrad.py +120 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_adam.py +149 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_approx_rowwise_adagrad.py +128 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_approx_rowwise_adagrad_with_counter.py +134 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_approx_rowwise_adagrad_with_weight_decay.py +128 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_approx_sgd.py +105 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_args.py +54 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_lamb.py +149 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_lars_sgd.py +128 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_partial_rowwise_adam.py +149 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_partial_rowwise_lamb.py +149 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_rowwise_adagrad.py +128 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_rowwise_adagrad_with_counter.py +134 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_rowwise_adagrad_with_weight_decay.py +128 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_rowwise_weighted_adagrad.py +130 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_sgd.py +105 -0
- fbgemm_gpu/split_embedding_configs.py +182 -0
- fbgemm_gpu/split_embedding_inference_converter.py +208 -0
- fbgemm_gpu/split_table_batched_embeddings_ops.py +2503 -0
- fbgemm_gpu/uvm.py +35 -0
- torchrec/__init__.py +27 -0
- torchrec/datasets/__init__.py +31 -0
- torchrec/datasets/criteo.py +831 -0
- torchrec/datasets/movielens.py +140 -0
- torchrec/datasets/random.py +188 -0
- torchrec/datasets/scripts/__init__.py +0 -0
- torchrec/datasets/scripts/contiguous_preproc_criteo.py +75 -0
- torchrec/datasets/scripts/npy_preproc_criteo.py +73 -0
- torchrec/datasets/test_utils/__init__.py +0 -0
- torchrec/datasets/test_utils/criteo_test_utils.py +139 -0
- torchrec/datasets/utils.py +341 -0
- torchrec/distributed/__init__.py +55 -0
- torchrec/distributed/batched_embedding_kernel.py +697 -0
- torchrec/distributed/collective_utils.py +71 -0
- torchrec/distributed/comm.py +149 -0
- torchrec/distributed/comm_ops.py +930 -0
- torchrec/distributed/dist_data.py +949 -0
- torchrec/distributed/embedding.py +638 -0
- torchrec/distributed/embedding_kernel.py +326 -0
- torchrec/distributed/embedding_lookup.py +760 -0
- torchrec/distributed/embedding_sharding.py +660 -0
- torchrec/distributed/embedding_tower_sharding.py +992 -0
- torchrec/distributed/embedding_types.py +369 -0
- torchrec/distributed/embeddingbag.py +731 -0
- torchrec/distributed/fused_embeddingbag.py +148 -0
- torchrec/distributed/grouped_position_weighted.py +103 -0
- torchrec/distributed/model_parallel.py +555 -0
- torchrec/distributed/planner/__init__.py +24 -0
- torchrec/distributed/planner/constants.py +77 -0
- torchrec/distributed/planner/enumerators.py +353 -0
- torchrec/distributed/planner/parallelized_planners.py +307 -0
- torchrec/distributed/planner/partitioners.py +280 -0
- torchrec/distributed/planner/perf_models.py +24 -0
- torchrec/distributed/planner/planners.py +290 -0
- torchrec/distributed/planner/proposers.py +270 -0
- torchrec/distributed/planner/shard_estimators.py +971 -0
- torchrec/distributed/planner/stats.py +477 -0
- torchrec/distributed/planner/storage_reservations.py +168 -0
- torchrec/distributed/planner/types.py +423 -0
- torchrec/distributed/planner/utils.py +30 -0
- torchrec/distributed/quant_embedding.py +307 -0
- torchrec/distributed/quant_embedding_kernel.py +295 -0
- torchrec/distributed/quant_embeddingbag.py +288 -0
- torchrec/distributed/sharding/__init__.py +0 -0
- torchrec/distributed/sharding/cw_sequence_sharding.py +71 -0
- torchrec/distributed/sharding/cw_sharding.py +242 -0
- torchrec/distributed/sharding/dp_sequence_sharding.py +87 -0
- torchrec/distributed/sharding/dp_sharding.py +217 -0
- torchrec/distributed/sharding/rw_sequence_sharding.py +130 -0
- torchrec/distributed/sharding/rw_sharding.py +393 -0
- torchrec/distributed/sharding/sequence_sharding.py +69 -0
- torchrec/distributed/sharding/tw_sequence_sharding.py +211 -0
- torchrec/distributed/sharding/tw_sharding.py +469 -0
- torchrec/distributed/sharding/twcw_sharding.py +32 -0
- torchrec/distributed/sharding/twrw_sharding.py +543 -0
- torchrec/distributed/sharding/vb_cw_sharding.py +91 -0
- torchrec/distributed/sharding/vb_rw_sharding.py +250 -0
- torchrec/distributed/sharding/vb_sharding.py +54 -0
- torchrec/distributed/sharding/vb_tw_sharding.py +148 -0
- torchrec/distributed/sharding/vb_twrw_sharding.py +388 -0
- torchrec/distributed/test_utils/__init__.py +0 -0
- torchrec/distributed/test_utils/multi_process.py +132 -0
- torchrec/distributed/test_utils/test_model.py +818 -0
- torchrec/distributed/test_utils/test_model_parallel.py +74 -0
- torchrec/distributed/test_utils/test_model_parallel_base.py +117 -0
- torchrec/distributed/test_utils/test_sharding.py +280 -0
- torchrec/distributed/train_pipeline.py +531 -0
- torchrec/distributed/types.py +594 -0
- torchrec/distributed/utils.py +186 -0
- torchrec/fused_planner.py +57 -0
- torchrec/fx/__init__.py +15 -0
- torchrec/fx/tracer.py +78 -0
- torchrec/inference/__init__.py +25 -0
- torchrec/inference/client.py +127 -0
- torchrec/inference/model_packager.py +102 -0
- torchrec/inference/modules.py +155 -0
- torchrec/inference/state_dict_transform.py +103 -0
- torchrec/metrics/__init__.py +0 -0
- torchrec/metrics/auc.py +159 -0
- torchrec/metrics/calibration.py +108 -0
- torchrec/metrics/ctr.py +104 -0
- torchrec/metrics/metric_module.py +358 -0
- torchrec/metrics/metrics_config.py +152 -0
- torchrec/metrics/metrics_namespace.py +114 -0
- torchrec/metrics/model_utils.py +85 -0
- torchrec/metrics/mse.py +134 -0
- torchrec/metrics/ne.py +164 -0
- torchrec/metrics/rec_metric.py +686 -0
- torchrec/metrics/throughput.py +174 -0
- torchrec/models/__init__.py +27 -0
- torchrec/models/deepfm.py +346 -0
- torchrec/models/dlrm.py +708 -0
- torchrec/modules/__init__.py +34 -0
- torchrec/modules/activation.py +55 -0
- torchrec/modules/crossnet.py +446 -0
- torchrec/modules/deepfm.py +213 -0
- torchrec/modules/embedding_configs.py +148 -0
- torchrec/modules/embedding_modules.py +381 -0
- torchrec/modules/embedding_tower.py +150 -0
- torchrec/modules/feature_processor.py +74 -0
- torchrec/modules/fused_embedding_modules.py +625 -0
- torchrec/modules/lazy_extension.py +258 -0
- torchrec/modules/mlp.py +172 -0
- torchrec/modules/utils.py +117 -0
- torchrec/optim/__init__.py +35 -0
- torchrec/optim/clipping.py +53 -0
- torchrec/optim/fused.py +42 -0
- torchrec/optim/keyed.py +399 -0
- torchrec/optim/rowwise_adagrad.py +222 -0
- torchrec/optim/test_utils/__init__.py +19 -0
- torchrec/optim/warmup.py +147 -0
- torchrec/quant/__init__.py +34 -0
- torchrec/quant/embedding_modules.py +545 -0
- torchrec/sparse/__init__.py +33 -0
- torchrec/sparse/jagged_tensor.py +1281 -0
- torchrec/sparse/test_utils/__init__.py +45 -0
- torchrec/streamable.py +46 -0
- torchrec/test_utils/__init__.py +111 -0
- torchrec-0.2.dev0.dist-info/LICENSE +29 -0
- torchrec-0.2.dev0.dist-info/METADATA +175 -0
- torchrec-0.2.dev0.dist-info/RECORD +167 -0
- torchrec-0.2.dev0.dist-info/WHEEL +5 -0
- torchrec-0.2.dev0.dist-info/top_level.txt +2 -0
fbgemm_gpu/__init__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
# This source code is licensed under the BSD-style license found in the
|
|
6
|
+
# LICENSE file in the root directory of this source tree.
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
|
|
10
|
+
import torch
|
|
11
|
+
|
|
12
|
+
torch.ops.load_library(os.path.join(os.path.dirname(__file__), "fbgemm_gpu_py.so"))
|
|
13
|
+
|
|
14
|
+
# __init__.py is only used in OSS
|
|
15
|
+
# Use existence to check if fbgemm_gpu_py.so has already been loaded
|
|
16
|
+
open_source: bool = True
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
# This source code is licensed under the BSD-style license found in the
|
|
6
|
+
# LICENSE file in the root directory of this source tree.
|
|
7
|
+
|
|
8
|
+
# pyre-unsafe
|
|
9
|
+
|
|
10
|
+
from math import sqrt
|
|
11
|
+
from typing import List
|
|
12
|
+
|
|
13
|
+
import torch
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
# pyre-ignore[21]
|
|
17
|
+
from fbgemm_gpu import open_source # noqa: F401
|
|
18
|
+
except Exception:
|
|
19
|
+
torch.ops.load_library("//deeplearning/fbgemm/fbgemm_gpu:sparse_ops")
|
|
20
|
+
torch.ops.load_library("//deeplearning/fbgemm/fbgemm_gpu:sparse_ops_cpu")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def wrap_weight_to_parameter(weights: List[torch.Tensor]) -> List[torch.Tensor]:
|
|
24
|
+
for i, v in enumerate(weights):
|
|
25
|
+
if not isinstance(v, torch.nn.Parameter):
|
|
26
|
+
weights[i] = torch.nn.Parameter(v)
|
|
27
|
+
return weights
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class BatchedUnaryEmbeddingBag(torch.nn.Module):
|
|
31
|
+
def __init__(self, num_tasks: int, hash_sizes: List[int], long_index: bool = False):
|
|
32
|
+
super().__init__()
|
|
33
|
+
self.num_tasks = num_tasks
|
|
34
|
+
self.hash_sizes = hash_sizes
|
|
35
|
+
# [N][sum(E)][1]
|
|
36
|
+
embedding_data = torch.randn(size=(num_tasks, sum(self.hash_sizes), 1))
|
|
37
|
+
self.weight = torch.nn.Parameter(embedding_data)
|
|
38
|
+
index_dtype = torch.int64 if long_index else torch.int32
|
|
39
|
+
table_offsets_tensor = torch.cat(
|
|
40
|
+
[
|
|
41
|
+
torch.tensor([0], dtype=index_dtype),
|
|
42
|
+
torch.cumsum(
|
|
43
|
+
torch.tensor(hash_sizes),
|
|
44
|
+
dim=0,
|
|
45
|
+
dtype=index_dtype,
|
|
46
|
+
),
|
|
47
|
+
]
|
|
48
|
+
)
|
|
49
|
+
self.register_buffer("table_offsets_tensor", table_offsets_tensor)
|
|
50
|
+
self.init_parameters()
|
|
51
|
+
|
|
52
|
+
def forward(self, offsets: torch.Tensor, input: torch.Tensor):
|
|
53
|
+
# output is [N][B][T]
|
|
54
|
+
return torch.ops.fbgemm.batched_unary_embeddings(
|
|
55
|
+
self.weight,
|
|
56
|
+
self.table_offsets_tensor,
|
|
57
|
+
offsets,
|
|
58
|
+
input,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
@torch.jit.export
|
|
62
|
+
def split_embedding_weights(self):
|
|
63
|
+
embedding_weights = []
|
|
64
|
+
for n in range(self.num_tasks):
|
|
65
|
+
for t in range(len(self.hash_sizes)):
|
|
66
|
+
embedding_weights.append(
|
|
67
|
+
self.weight.detach()[
|
|
68
|
+
n,
|
|
69
|
+
self.table_offsets_tensor[t] : self.table_offsets_tensor[t + 1],
|
|
70
|
+
:,
|
|
71
|
+
]
|
|
72
|
+
)
|
|
73
|
+
return embedding_weights
|
|
74
|
+
|
|
75
|
+
@torch.jit.export
|
|
76
|
+
def init_parameters(self):
|
|
77
|
+
for (num_emb, param) in zip(
|
|
78
|
+
self.hash_sizes * self.num_tasks,
|
|
79
|
+
wrap_weight_to_parameter(self.split_embedding_weights()),
|
|
80
|
+
):
|
|
81
|
+
assert param.shape == (num_emb, 1)
|
|
82
|
+
param.data.uniform_(-sqrt(1 / num_emb), sqrt(1 / num_emb))
|
fbgemm_gpu/enums.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
# This source code is licensed under the BSD-style license found in the
|
|
6
|
+
# LICENSE file in the root directory of this source tree.
|
|
7
|
+
|
|
8
|
+
import enum
|
|
9
|
+
import typing
|
|
10
|
+
from typing import Any, Callable, List, Tuple
|
|
11
|
+
|
|
12
|
+
# Create enums in given namespace with information from query_op
|
|
13
|
+
def create_enums(
|
|
14
|
+
namespace: typing.Dict[str, Any],
|
|
15
|
+
query_op: Callable[[], List[Tuple[str, List[Tuple[str, int]]]]],
|
|
16
|
+
) -> None:
|
|
17
|
+
for enum_name, items in query_op():
|
|
18
|
+
# Create matching python enumeration
|
|
19
|
+
new_enum = enum.Enum(enum_name, items)
|
|
20
|
+
# and store it in the module
|
|
21
|
+
namespace[enum_name] = new_enum
|
|
Binary file
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
# This source code is licensed under the BSD-style license found in the
|
|
6
|
+
# LICENSE file in the root directory of this source tree.
|
|
7
|
+
|
|
8
|
+
import logging
|
|
9
|
+
from itertools import accumulate
|
|
10
|
+
from typing import List, Optional
|
|
11
|
+
|
|
12
|
+
import torch
|
|
13
|
+
from torch import nn
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
# pyre-ignore[21]
|
|
17
|
+
from fbgemm_gpu import open_source # noqa: F401
|
|
18
|
+
except Exception:
|
|
19
|
+
torch.ops.load_library(
|
|
20
|
+
"//deeplearning/fbgemm/fbgemm_gpu:permute_pooled_embedding_ops_gpu"
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class PermutePooledEmbeddings(nn.Module):
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
embs_dims: List[int],
|
|
28
|
+
permute: List[int],
|
|
29
|
+
device: Optional[torch.device] = None,
|
|
30
|
+
) -> None:
|
|
31
|
+
super(PermutePooledEmbeddings, self).__init__()
|
|
32
|
+
logging.info("Using Permute Pooled Embeddings")
|
|
33
|
+
|
|
34
|
+
self.register_buffer(
|
|
35
|
+
"_offset_dim_list",
|
|
36
|
+
torch.tensor(
|
|
37
|
+
[0] + list(accumulate(embs_dims)), device=device, dtype=torch.int64
|
|
38
|
+
),
|
|
39
|
+
)
|
|
40
|
+
self.register_buffer(
|
|
41
|
+
"_permute", torch.tensor(permute, device=device, dtype=torch.int64)
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
inv_permute: List[int] = [0] * len(permute)
|
|
45
|
+
for i, p in enumerate(permute):
|
|
46
|
+
inv_permute[p] = i
|
|
47
|
+
|
|
48
|
+
self.register_buffer(
|
|
49
|
+
"_inv_permute", torch.tensor(inv_permute, device=device, dtype=torch.int64)
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
# `Union[BoundMethod[typing.Callable(torch.Tensor.tolist)[[Named(self,
|
|
53
|
+
# torch.Tensor)], List[typing.Any]], torch.Tensor], nn.Module, torch.Tensor]`
|
|
54
|
+
# is not a function.
|
|
55
|
+
|
|
56
|
+
inv_embs_dims = [embs_dims[i] for i in permute]
|
|
57
|
+
|
|
58
|
+
self.register_buffer(
|
|
59
|
+
"_inv_offset_dim_list",
|
|
60
|
+
torch.tensor(
|
|
61
|
+
[0] + list(accumulate(inv_embs_dims)), device=device, dtype=torch.int64
|
|
62
|
+
),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
def forward(self, pooled_embs: torch.Tensor) -> torch.Tensor:
|
|
66
|
+
result = torch.ops.fbgemm.permute_pooled_embs_auto_grad(
|
|
67
|
+
pooled_embs,
|
|
68
|
+
self._offset_dim_list.to(device=pooled_embs.device),
|
|
69
|
+
self._permute.to(device=pooled_embs.device),
|
|
70
|
+
self._inv_offset_dim_list.to(device=pooled_embs.device),
|
|
71
|
+
self._inv_permute.to(device=pooled_embs.device),
|
|
72
|
+
)
|
|
73
|
+
return result
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
# This source code is licensed under the BSD-style license found in the
|
|
6
|
+
# LICENSE file in the root directory of this source tree.
|
|
7
|
+
|
|
8
|
+
import logging
|
|
9
|
+
from itertools import accumulate
|
|
10
|
+
from typing import List, Optional
|
|
11
|
+
|
|
12
|
+
import torch
|
|
13
|
+
from torch import nn
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
# pyre-ignore[21]
|
|
17
|
+
from fbgemm_gpu import open_source # noqa: F401
|
|
18
|
+
except Exception:
|
|
19
|
+
torch.ops.load_library(
|
|
20
|
+
"//deeplearning/fbgemm/fbgemm_gpu:permute_pooled_embedding_ops_split_gpu"
|
|
21
|
+
)
|
|
22
|
+
torch.ops.load_library(
|
|
23
|
+
"//deeplearning/fbgemm/fbgemm_gpu:permute_pooled_embedding_ops_split_cpu"
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class PermutePooledEmbeddingsSplit(nn.Module):
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
embs_dims: List[int],
|
|
31
|
+
permute: List[int],
|
|
32
|
+
device: Optional[torch.device] = None,
|
|
33
|
+
) -> None:
|
|
34
|
+
super(PermutePooledEmbeddingsSplit, self).__init__()
|
|
35
|
+
logging.info("Using Permute Pooled Embeddings")
|
|
36
|
+
|
|
37
|
+
self.register_buffer(
|
|
38
|
+
"_offset_dim_list",
|
|
39
|
+
torch.tensor(
|
|
40
|
+
[0] + list(accumulate(embs_dims)), device=device, dtype=torch.int64
|
|
41
|
+
),
|
|
42
|
+
)
|
|
43
|
+
self.register_buffer(
|
|
44
|
+
"_permute", torch.tensor(permute, device=device, dtype=torch.int64)
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
inv_permute: List[int] = [0] * len(permute)
|
|
48
|
+
for i, p in enumerate(permute):
|
|
49
|
+
inv_permute[p] = i
|
|
50
|
+
|
|
51
|
+
self.register_buffer(
|
|
52
|
+
"_inv_permute", torch.tensor(inv_permute, device=device, dtype=torch.int64)
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
# `Union[BoundMethod[typing.Callable(torch.Tensor.tolist)[[Named(self,
|
|
56
|
+
# torch.Tensor)], List[typing.Any]], torch.Tensor], nn.Module, torch.Tensor]`
|
|
57
|
+
# is not a function.
|
|
58
|
+
|
|
59
|
+
inv_embs_dims = [embs_dims[i] for i in permute]
|
|
60
|
+
|
|
61
|
+
self.register_buffer(
|
|
62
|
+
"_inv_offset_dim_list",
|
|
63
|
+
torch.tensor(
|
|
64
|
+
[0] + list(accumulate(inv_embs_dims)), device=device, dtype=torch.int64
|
|
65
|
+
),
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
def forward(self, pooled_embs: torch.Tensor) -> torch.Tensor:
|
|
69
|
+
result = torch.ops.fbgemm.permute_pooled_embs_auto_grad_split(
|
|
70
|
+
pooled_embs,
|
|
71
|
+
self._offset_dim_list.to(device=pooled_embs.device),
|
|
72
|
+
self._permute.to(device=pooled_embs.device),
|
|
73
|
+
self._inv_offset_dim_list.to(device=pooled_embs.device),
|
|
74
|
+
self._inv_permute.to(device=pooled_embs.device),
|
|
75
|
+
)
|
|
76
|
+
return result
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
# This source code is licensed under the BSD-style license found in the
|
|
6
|
+
# LICENSE file in the root directory of this source tree.
|
|
7
|
+
|
|
8
|
+
import fbgemm_gpu.split_embedding_codegen_lookup_invokers.lookup_adagrad as lookup_adagrad # noqa: F401
|
|
9
|
+
import fbgemm_gpu.split_embedding_codegen_lookup_invokers.lookup_adam as lookup_adam # noqa: F401
|
|
10
|
+
import fbgemm_gpu.split_embedding_codegen_lookup_invokers.lookup_args as lookup_args # noqa: F401
|
|
11
|
+
import fbgemm_gpu.split_embedding_codegen_lookup_invokers.lookup_lamb as lookup_lamb # noqa: F401
|
|
12
|
+
import fbgemm_gpu.split_embedding_codegen_lookup_invokers.lookup_lars_sgd as lookup_lars_sgd # noqa: F401
|
|
13
|
+
import fbgemm_gpu.split_embedding_codegen_lookup_invokers.lookup_partial_rowwise_adam as lookup_partial_rowwise_adam # noqa: F401
|
|
14
|
+
import fbgemm_gpu.split_embedding_codegen_lookup_invokers.lookup_partial_rowwise_lamb as lookup_partial_rowwise_lamb # noqa: F401
|
|
15
|
+
import fbgemm_gpu.split_embedding_codegen_lookup_invokers.lookup_rowwise_adagrad as lookup_rowwise_adagrad # noqa: F401
|
|
16
|
+
import fbgemm_gpu.split_embedding_codegen_lookup_invokers.lookup_sgd as lookup_sgd # noqa: F401
|
|
17
|
+
import fbgemm_gpu.split_embedding_codegen_lookup_invokers.lookup_approx_sgd as lookup_approx_sgd # noqa: F401
|
|
18
|
+
import fbgemm_gpu.split_embedding_codegen_lookup_invokers.lookup_approx_rowwise_adagrad as lookup_approx_rowwise_adagrad # noqa: F401
|
|
19
|
+
import fbgemm_gpu.split_embedding_codegen_lookup_invokers.lookup_rowwise_weighted_adagrad as lookup_rowwise_weighted_adagrad # noqa: F401
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
# This source code is licensed under the BSD-style license found in the
|
|
6
|
+
# LICENSE file in the root directory of this source tree.
|
|
7
|
+
|
|
8
|
+
import torch
|
|
9
|
+
from .lookup_args import *
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
#import os
|
|
14
|
+
#torch.ops.load_library(os.path.join(os.path.join(os.path.dirname(os.path.dirname(__file__)), "fbgemm_gpu_py.so")))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def invoke(
|
|
19
|
+
common_args: CommonArgs,
|
|
20
|
+
optimizer_args: OptimizerArgs,
|
|
21
|
+
|
|
22
|
+
momentum1: Momentum,
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
) -> torch.Tensor:
|
|
27
|
+
if (common_args.host_weights.numel() > 0):
|
|
28
|
+
return torch.ops.fbgemm.split_embedding_codegen_lookup_adagrad_function_cpu(
|
|
29
|
+
# common_args
|
|
30
|
+
host_weights=common_args.host_weights,
|
|
31
|
+
weights_placements=common_args.weights_placements,
|
|
32
|
+
weights_offsets=common_args.weights_offsets,
|
|
33
|
+
D_offsets=common_args.D_offsets,
|
|
34
|
+
total_D=common_args.total_D,
|
|
35
|
+
max_D=common_args.max_D,
|
|
36
|
+
hash_size_cumsum=common_args.hash_size_cumsum,
|
|
37
|
+
total_hash_size_bits=common_args.total_hash_size_bits,
|
|
38
|
+
indices=common_args.indices,
|
|
39
|
+
offsets=common_args.offsets,
|
|
40
|
+
pooling_mode=common_args.pooling_mode,
|
|
41
|
+
indice_weights=common_args.indice_weights,
|
|
42
|
+
feature_requires_grad=common_args.feature_requires_grad,
|
|
43
|
+
# optimizer_args
|
|
44
|
+
gradient_clipping = optimizer_args.gradient_clipping,
|
|
45
|
+
max_gradient=optimizer_args.max_gradient,
|
|
46
|
+
stochastic_rounding=optimizer_args.stochastic_rounding,
|
|
47
|
+
|
|
48
|
+
learning_rate=optimizer_args.learning_rate,
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
eps=optimizer_args.eps,
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# momentum1
|
|
60
|
+
|
|
61
|
+
momentum1_host=momentum1.host,
|
|
62
|
+
momentum1_offsets=momentum1.offsets,
|
|
63
|
+
momentum1_placements=momentum1.placements,
|
|
64
|
+
|
|
65
|
+
# momentum2
|
|
66
|
+
|
|
67
|
+
# iter
|
|
68
|
+
|
|
69
|
+
)
|
|
70
|
+
else:
|
|
71
|
+
return torch.ops.fbgemm.split_embedding_codegen_lookup_adagrad_function(
|
|
72
|
+
# common_args
|
|
73
|
+
|
|
74
|
+
placeholder_autograd_tensor=common_args.placeholder_autograd_tensor,
|
|
75
|
+
|
|
76
|
+
dev_weights=common_args.dev_weights,
|
|
77
|
+
uvm_weights=common_args.uvm_weights,
|
|
78
|
+
lxu_cache_weights=common_args.lxu_cache_weights,
|
|
79
|
+
weights_placements=common_args.weights_placements,
|
|
80
|
+
weights_offsets=common_args.weights_offsets,
|
|
81
|
+
D_offsets=common_args.D_offsets,
|
|
82
|
+
total_D=common_args.total_D,
|
|
83
|
+
max_D=common_args.max_D,
|
|
84
|
+
hash_size_cumsum=common_args.hash_size_cumsum,
|
|
85
|
+
total_hash_size_bits=common_args.total_hash_size_bits,
|
|
86
|
+
indices=common_args.indices,
|
|
87
|
+
offsets=common_args.offsets,
|
|
88
|
+
pooling_mode=common_args.pooling_mode,
|
|
89
|
+
indice_weights=common_args.indice_weights,
|
|
90
|
+
feature_requires_grad=common_args.feature_requires_grad,
|
|
91
|
+
lxu_cache_locations=common_args.lxu_cache_locations,
|
|
92
|
+
# optimizer_args
|
|
93
|
+
gradient_clipping = optimizer_args.gradient_clipping,
|
|
94
|
+
max_gradient=optimizer_args.max_gradient,
|
|
95
|
+
stochastic_rounding=optimizer_args.stochastic_rounding,
|
|
96
|
+
|
|
97
|
+
learning_rate=optimizer_args.learning_rate,
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
eps=optimizer_args.eps,
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
# momentum1
|
|
109
|
+
|
|
110
|
+
momentum1_dev=momentum1.dev,
|
|
111
|
+
momentum1_uvm=momentum1.uvm,
|
|
112
|
+
momentum1_offsets=momentum1.offsets,
|
|
113
|
+
momentum1_placements=momentum1.placements,
|
|
114
|
+
|
|
115
|
+
# momentum2
|
|
116
|
+
|
|
117
|
+
# iter
|
|
118
|
+
|
|
119
|
+
output_dtype=common_args.output_dtype,
|
|
120
|
+
)
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
# This source code is licensed under the BSD-style license found in the
|
|
6
|
+
# LICENSE file in the root directory of this source tree.
|
|
7
|
+
|
|
8
|
+
import torch
|
|
9
|
+
from .lookup_args import *
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
#import os
|
|
14
|
+
#torch.ops.load_library(os.path.join(os.path.join(os.path.dirname(os.path.dirname(__file__)), "fbgemm_gpu_py.so")))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def invoke(
|
|
19
|
+
common_args: CommonArgs,
|
|
20
|
+
optimizer_args: OptimizerArgs,
|
|
21
|
+
|
|
22
|
+
momentum1: Momentum,
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
momentum2: Momentum,
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
iter: int,
|
|
29
|
+
|
|
30
|
+
) -> torch.Tensor:
|
|
31
|
+
if (common_args.host_weights.numel() > 0):
|
|
32
|
+
return torch.ops.fbgemm.split_embedding_codegen_lookup_adam_function_cpu(
|
|
33
|
+
# common_args
|
|
34
|
+
host_weights=common_args.host_weights,
|
|
35
|
+
weights_placements=common_args.weights_placements,
|
|
36
|
+
weights_offsets=common_args.weights_offsets,
|
|
37
|
+
D_offsets=common_args.D_offsets,
|
|
38
|
+
total_D=common_args.total_D,
|
|
39
|
+
max_D=common_args.max_D,
|
|
40
|
+
hash_size_cumsum=common_args.hash_size_cumsum,
|
|
41
|
+
total_hash_size_bits=common_args.total_hash_size_bits,
|
|
42
|
+
indices=common_args.indices,
|
|
43
|
+
offsets=common_args.offsets,
|
|
44
|
+
pooling_mode=common_args.pooling_mode,
|
|
45
|
+
indice_weights=common_args.indice_weights,
|
|
46
|
+
feature_requires_grad=common_args.feature_requires_grad,
|
|
47
|
+
# optimizer_args
|
|
48
|
+
gradient_clipping = optimizer_args.gradient_clipping,
|
|
49
|
+
max_gradient=optimizer_args.max_gradient,
|
|
50
|
+
stochastic_rounding=optimizer_args.stochastic_rounding,
|
|
51
|
+
|
|
52
|
+
learning_rate=optimizer_args.learning_rate,
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
eps=optimizer_args.eps,
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
beta1=optimizer_args.beta1,
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
beta2=optimizer_args.beta2,
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
weight_decay=optimizer_args.weight_decay,
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# momentum1
|
|
70
|
+
|
|
71
|
+
momentum1_host=momentum1.host,
|
|
72
|
+
momentum1_offsets=momentum1.offsets,
|
|
73
|
+
momentum1_placements=momentum1.placements,
|
|
74
|
+
|
|
75
|
+
# momentum2
|
|
76
|
+
|
|
77
|
+
momentum2_host=momentum2.host,
|
|
78
|
+
momentum2_offsets=momentum2.offsets,
|
|
79
|
+
momentum2_placements=momentum2.placements,
|
|
80
|
+
|
|
81
|
+
# iter
|
|
82
|
+
|
|
83
|
+
iter=iter,
|
|
84
|
+
|
|
85
|
+
)
|
|
86
|
+
else:
|
|
87
|
+
return torch.ops.fbgemm.split_embedding_codegen_lookup_adam_function(
|
|
88
|
+
# common_args
|
|
89
|
+
|
|
90
|
+
placeholder_autograd_tensor=common_args.placeholder_autograd_tensor,
|
|
91
|
+
|
|
92
|
+
dev_weights=common_args.dev_weights,
|
|
93
|
+
uvm_weights=common_args.uvm_weights,
|
|
94
|
+
lxu_cache_weights=common_args.lxu_cache_weights,
|
|
95
|
+
weights_placements=common_args.weights_placements,
|
|
96
|
+
weights_offsets=common_args.weights_offsets,
|
|
97
|
+
D_offsets=common_args.D_offsets,
|
|
98
|
+
total_D=common_args.total_D,
|
|
99
|
+
max_D=common_args.max_D,
|
|
100
|
+
hash_size_cumsum=common_args.hash_size_cumsum,
|
|
101
|
+
total_hash_size_bits=common_args.total_hash_size_bits,
|
|
102
|
+
indices=common_args.indices,
|
|
103
|
+
offsets=common_args.offsets,
|
|
104
|
+
pooling_mode=common_args.pooling_mode,
|
|
105
|
+
indice_weights=common_args.indice_weights,
|
|
106
|
+
feature_requires_grad=common_args.feature_requires_grad,
|
|
107
|
+
lxu_cache_locations=common_args.lxu_cache_locations,
|
|
108
|
+
# optimizer_args
|
|
109
|
+
gradient_clipping = optimizer_args.gradient_clipping,
|
|
110
|
+
max_gradient=optimizer_args.max_gradient,
|
|
111
|
+
stochastic_rounding=optimizer_args.stochastic_rounding,
|
|
112
|
+
|
|
113
|
+
learning_rate=optimizer_args.learning_rate,
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
eps=optimizer_args.eps,
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
beta1=optimizer_args.beta1,
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
beta2=optimizer_args.beta2,
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
weight_decay=optimizer_args.weight_decay,
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
# momentum1
|
|
131
|
+
|
|
132
|
+
momentum1_dev=momentum1.dev,
|
|
133
|
+
momentum1_uvm=momentum1.uvm,
|
|
134
|
+
momentum1_offsets=momentum1.offsets,
|
|
135
|
+
momentum1_placements=momentum1.placements,
|
|
136
|
+
|
|
137
|
+
# momentum2
|
|
138
|
+
|
|
139
|
+
momentum2_dev=momentum2.dev,
|
|
140
|
+
momentum2_uvm=momentum2.uvm,
|
|
141
|
+
momentum2_offsets=momentum2.offsets,
|
|
142
|
+
momentum2_placements=momentum2.placements,
|
|
143
|
+
|
|
144
|
+
# iter
|
|
145
|
+
|
|
146
|
+
iter=iter,
|
|
147
|
+
|
|
148
|
+
output_dtype=common_args.output_dtype,
|
|
149
|
+
)
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
# This source code is licensed under the BSD-style license found in the
|
|
6
|
+
# LICENSE file in the root directory of this source tree.
|
|
7
|
+
|
|
8
|
+
import torch
|
|
9
|
+
from .lookup_args import *
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
#import os
|
|
14
|
+
#torch.ops.load_library(os.path.join(os.path.join(os.path.dirname(os.path.dirname(__file__)), "fbgemm_gpu_py.so")))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def invoke(
|
|
19
|
+
common_args: CommonArgs,
|
|
20
|
+
optimizer_args: OptimizerArgs,
|
|
21
|
+
|
|
22
|
+
momentum1: Momentum,
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
) -> torch.Tensor:
|
|
27
|
+
if (common_args.host_weights.numel() > 0):
|
|
28
|
+
return torch.ops.fbgemm.split_embedding_codegen_lookup_approx_rowwise_adagrad_function_cpu(
|
|
29
|
+
# common_args
|
|
30
|
+
host_weights=common_args.host_weights,
|
|
31
|
+
weights_placements=common_args.weights_placements,
|
|
32
|
+
weights_offsets=common_args.weights_offsets,
|
|
33
|
+
D_offsets=common_args.D_offsets,
|
|
34
|
+
total_D=common_args.total_D,
|
|
35
|
+
max_D=common_args.max_D,
|
|
36
|
+
hash_size_cumsum=common_args.hash_size_cumsum,
|
|
37
|
+
total_hash_size_bits=common_args.total_hash_size_bits,
|
|
38
|
+
indices=common_args.indices,
|
|
39
|
+
offsets=common_args.offsets,
|
|
40
|
+
pooling_mode=common_args.pooling_mode,
|
|
41
|
+
indice_weights=common_args.indice_weights,
|
|
42
|
+
feature_requires_grad=common_args.feature_requires_grad,
|
|
43
|
+
# optimizer_args
|
|
44
|
+
gradient_clipping = optimizer_args.gradient_clipping,
|
|
45
|
+
max_gradient=optimizer_args.max_gradient,
|
|
46
|
+
stochastic_rounding=optimizer_args.stochastic_rounding,
|
|
47
|
+
|
|
48
|
+
learning_rate=optimizer_args.learning_rate,
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
eps=optimizer_args.eps,
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
weight_decay=optimizer_args.weight_decay,
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
weight_decay_mode=optimizer_args.weight_decay_mode,
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
# momentum1
|
|
64
|
+
|
|
65
|
+
momentum1_host=momentum1.host,
|
|
66
|
+
momentum1_offsets=momentum1.offsets,
|
|
67
|
+
momentum1_placements=momentum1.placements,
|
|
68
|
+
|
|
69
|
+
# momentum2
|
|
70
|
+
|
|
71
|
+
# iter
|
|
72
|
+
|
|
73
|
+
)
|
|
74
|
+
else:
|
|
75
|
+
return torch.ops.fbgemm.split_embedding_codegen_lookup_approx_rowwise_adagrad_function(
|
|
76
|
+
# common_args
|
|
77
|
+
|
|
78
|
+
placeholder_autograd_tensor=common_args.placeholder_autograd_tensor,
|
|
79
|
+
|
|
80
|
+
dev_weights=common_args.dev_weights,
|
|
81
|
+
uvm_weights=common_args.uvm_weights,
|
|
82
|
+
lxu_cache_weights=common_args.lxu_cache_weights,
|
|
83
|
+
weights_placements=common_args.weights_placements,
|
|
84
|
+
weights_offsets=common_args.weights_offsets,
|
|
85
|
+
D_offsets=common_args.D_offsets,
|
|
86
|
+
total_D=common_args.total_D,
|
|
87
|
+
max_D=common_args.max_D,
|
|
88
|
+
hash_size_cumsum=common_args.hash_size_cumsum,
|
|
89
|
+
total_hash_size_bits=common_args.total_hash_size_bits,
|
|
90
|
+
indices=common_args.indices,
|
|
91
|
+
offsets=common_args.offsets,
|
|
92
|
+
pooling_mode=common_args.pooling_mode,
|
|
93
|
+
indice_weights=common_args.indice_weights,
|
|
94
|
+
feature_requires_grad=common_args.feature_requires_grad,
|
|
95
|
+
lxu_cache_locations=common_args.lxu_cache_locations,
|
|
96
|
+
# optimizer_args
|
|
97
|
+
gradient_clipping = optimizer_args.gradient_clipping,
|
|
98
|
+
max_gradient=optimizer_args.max_gradient,
|
|
99
|
+
stochastic_rounding=optimizer_args.stochastic_rounding,
|
|
100
|
+
|
|
101
|
+
learning_rate=optimizer_args.learning_rate,
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
eps=optimizer_args.eps,
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
weight_decay=optimizer_args.weight_decay,
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
weight_decay_mode=optimizer_args.weight_decay_mode,
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
# momentum1
|
|
117
|
+
|
|
118
|
+
momentum1_dev=momentum1.dev,
|
|
119
|
+
momentum1_uvm=momentum1.uvm,
|
|
120
|
+
momentum1_offsets=momentum1.offsets,
|
|
121
|
+
momentum1_placements=momentum1.placements,
|
|
122
|
+
|
|
123
|
+
# momentum2
|
|
124
|
+
|
|
125
|
+
# iter
|
|
126
|
+
|
|
127
|
+
output_dtype=common_args.output_dtype,
|
|
128
|
+
)
|