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.
Files changed (167) hide show
  1. examples/__init__.py +0 -0
  2. examples/datasets/__init__.py +8 -0
  3. examples/datasets/criteo_dataframes.py +101 -0
  4. examples/ray/__init__.py +0 -0
  5. examples/ray/compute_world_size.py +51 -0
  6. examples/ray/train_torchrec.py +133 -0
  7. examples/retrieval/__init__.py +6 -0
  8. examples/retrieval/data/__init__.py +6 -0
  9. examples/retrieval/data/dataloader.py +44 -0
  10. examples/retrieval/knn_index.py +67 -0
  11. examples/retrieval/modules/__init__.py +6 -0
  12. examples/retrieval/modules/two_tower.py +229 -0
  13. examples/retrieval/two_tower_retrieval.py +192 -0
  14. examples/retrieval/two_tower_train.py +253 -0
  15. examples/torcharrow/__init__.py +8 -0
  16. examples/torcharrow/dataloader.py +116 -0
  17. examples/torcharrow/run.py +126 -0
  18. fbgemm_gpu/__init__.py +16 -0
  19. fbgemm_gpu/batched_unary_embeddings_ops.py +82 -0
  20. fbgemm_gpu/enums.py +21 -0
  21. fbgemm_gpu/fbgemm_gpu_py.so +0 -0
  22. fbgemm_gpu/permute_pooled_embedding_modules.py +73 -0
  23. fbgemm_gpu/permute_pooled_embedding_modules_split.py +76 -0
  24. fbgemm_gpu/split_embedding_codegen_lookup_invokers/__init__.py +19 -0
  25. fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_adagrad.py +120 -0
  26. fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_adam.py +149 -0
  27. fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_approx_rowwise_adagrad.py +128 -0
  28. fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_approx_rowwise_adagrad_with_counter.py +134 -0
  29. fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_approx_rowwise_adagrad_with_weight_decay.py +128 -0
  30. fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_approx_sgd.py +105 -0
  31. fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_args.py +54 -0
  32. fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_lamb.py +149 -0
  33. fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_lars_sgd.py +128 -0
  34. fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_partial_rowwise_adam.py +149 -0
  35. fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_partial_rowwise_lamb.py +149 -0
  36. fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_rowwise_adagrad.py +128 -0
  37. fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_rowwise_adagrad_with_counter.py +134 -0
  38. fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_rowwise_adagrad_with_weight_decay.py +128 -0
  39. fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_rowwise_weighted_adagrad.py +130 -0
  40. fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_sgd.py +105 -0
  41. fbgemm_gpu/split_embedding_configs.py +182 -0
  42. fbgemm_gpu/split_embedding_inference_converter.py +208 -0
  43. fbgemm_gpu/split_table_batched_embeddings_ops.py +2503 -0
  44. fbgemm_gpu/uvm.py +35 -0
  45. torchrec/__init__.py +27 -0
  46. torchrec/datasets/__init__.py +31 -0
  47. torchrec/datasets/criteo.py +831 -0
  48. torchrec/datasets/movielens.py +140 -0
  49. torchrec/datasets/random.py +188 -0
  50. torchrec/datasets/scripts/__init__.py +0 -0
  51. torchrec/datasets/scripts/contiguous_preproc_criteo.py +75 -0
  52. torchrec/datasets/scripts/npy_preproc_criteo.py +73 -0
  53. torchrec/datasets/test_utils/__init__.py +0 -0
  54. torchrec/datasets/test_utils/criteo_test_utils.py +139 -0
  55. torchrec/datasets/utils.py +341 -0
  56. torchrec/distributed/__init__.py +55 -0
  57. torchrec/distributed/batched_embedding_kernel.py +697 -0
  58. torchrec/distributed/collective_utils.py +71 -0
  59. torchrec/distributed/comm.py +149 -0
  60. torchrec/distributed/comm_ops.py +930 -0
  61. torchrec/distributed/dist_data.py +949 -0
  62. torchrec/distributed/embedding.py +638 -0
  63. torchrec/distributed/embedding_kernel.py +326 -0
  64. torchrec/distributed/embedding_lookup.py +760 -0
  65. torchrec/distributed/embedding_sharding.py +660 -0
  66. torchrec/distributed/embedding_tower_sharding.py +992 -0
  67. torchrec/distributed/embedding_types.py +369 -0
  68. torchrec/distributed/embeddingbag.py +731 -0
  69. torchrec/distributed/fused_embeddingbag.py +148 -0
  70. torchrec/distributed/grouped_position_weighted.py +103 -0
  71. torchrec/distributed/model_parallel.py +555 -0
  72. torchrec/distributed/planner/__init__.py +24 -0
  73. torchrec/distributed/planner/constants.py +77 -0
  74. torchrec/distributed/planner/enumerators.py +353 -0
  75. torchrec/distributed/planner/parallelized_planners.py +307 -0
  76. torchrec/distributed/planner/partitioners.py +280 -0
  77. torchrec/distributed/planner/perf_models.py +24 -0
  78. torchrec/distributed/planner/planners.py +290 -0
  79. torchrec/distributed/planner/proposers.py +270 -0
  80. torchrec/distributed/planner/shard_estimators.py +971 -0
  81. torchrec/distributed/planner/stats.py +477 -0
  82. torchrec/distributed/planner/storage_reservations.py +168 -0
  83. torchrec/distributed/planner/types.py +423 -0
  84. torchrec/distributed/planner/utils.py +30 -0
  85. torchrec/distributed/quant_embedding.py +307 -0
  86. torchrec/distributed/quant_embedding_kernel.py +295 -0
  87. torchrec/distributed/quant_embeddingbag.py +288 -0
  88. torchrec/distributed/sharding/__init__.py +0 -0
  89. torchrec/distributed/sharding/cw_sequence_sharding.py +71 -0
  90. torchrec/distributed/sharding/cw_sharding.py +242 -0
  91. torchrec/distributed/sharding/dp_sequence_sharding.py +87 -0
  92. torchrec/distributed/sharding/dp_sharding.py +217 -0
  93. torchrec/distributed/sharding/rw_sequence_sharding.py +130 -0
  94. torchrec/distributed/sharding/rw_sharding.py +393 -0
  95. torchrec/distributed/sharding/sequence_sharding.py +69 -0
  96. torchrec/distributed/sharding/tw_sequence_sharding.py +211 -0
  97. torchrec/distributed/sharding/tw_sharding.py +469 -0
  98. torchrec/distributed/sharding/twcw_sharding.py +32 -0
  99. torchrec/distributed/sharding/twrw_sharding.py +543 -0
  100. torchrec/distributed/sharding/vb_cw_sharding.py +91 -0
  101. torchrec/distributed/sharding/vb_rw_sharding.py +250 -0
  102. torchrec/distributed/sharding/vb_sharding.py +54 -0
  103. torchrec/distributed/sharding/vb_tw_sharding.py +148 -0
  104. torchrec/distributed/sharding/vb_twrw_sharding.py +388 -0
  105. torchrec/distributed/test_utils/__init__.py +0 -0
  106. torchrec/distributed/test_utils/multi_process.py +132 -0
  107. torchrec/distributed/test_utils/test_model.py +818 -0
  108. torchrec/distributed/test_utils/test_model_parallel.py +74 -0
  109. torchrec/distributed/test_utils/test_model_parallel_base.py +117 -0
  110. torchrec/distributed/test_utils/test_sharding.py +280 -0
  111. torchrec/distributed/train_pipeline.py +531 -0
  112. torchrec/distributed/types.py +594 -0
  113. torchrec/distributed/utils.py +186 -0
  114. torchrec/fused_planner.py +57 -0
  115. torchrec/fx/__init__.py +15 -0
  116. torchrec/fx/tracer.py +78 -0
  117. torchrec/inference/__init__.py +25 -0
  118. torchrec/inference/client.py +127 -0
  119. torchrec/inference/model_packager.py +102 -0
  120. torchrec/inference/modules.py +155 -0
  121. torchrec/inference/state_dict_transform.py +103 -0
  122. torchrec/metrics/__init__.py +0 -0
  123. torchrec/metrics/auc.py +159 -0
  124. torchrec/metrics/calibration.py +108 -0
  125. torchrec/metrics/ctr.py +104 -0
  126. torchrec/metrics/metric_module.py +358 -0
  127. torchrec/metrics/metrics_config.py +152 -0
  128. torchrec/metrics/metrics_namespace.py +114 -0
  129. torchrec/metrics/model_utils.py +85 -0
  130. torchrec/metrics/mse.py +134 -0
  131. torchrec/metrics/ne.py +164 -0
  132. torchrec/metrics/rec_metric.py +686 -0
  133. torchrec/metrics/throughput.py +174 -0
  134. torchrec/models/__init__.py +27 -0
  135. torchrec/models/deepfm.py +346 -0
  136. torchrec/models/dlrm.py +708 -0
  137. torchrec/modules/__init__.py +34 -0
  138. torchrec/modules/activation.py +55 -0
  139. torchrec/modules/crossnet.py +446 -0
  140. torchrec/modules/deepfm.py +213 -0
  141. torchrec/modules/embedding_configs.py +148 -0
  142. torchrec/modules/embedding_modules.py +381 -0
  143. torchrec/modules/embedding_tower.py +150 -0
  144. torchrec/modules/feature_processor.py +74 -0
  145. torchrec/modules/fused_embedding_modules.py +625 -0
  146. torchrec/modules/lazy_extension.py +258 -0
  147. torchrec/modules/mlp.py +172 -0
  148. torchrec/modules/utils.py +117 -0
  149. torchrec/optim/__init__.py +35 -0
  150. torchrec/optim/clipping.py +53 -0
  151. torchrec/optim/fused.py +42 -0
  152. torchrec/optim/keyed.py +399 -0
  153. torchrec/optim/rowwise_adagrad.py +222 -0
  154. torchrec/optim/test_utils/__init__.py +19 -0
  155. torchrec/optim/warmup.py +147 -0
  156. torchrec/quant/__init__.py +34 -0
  157. torchrec/quant/embedding_modules.py +545 -0
  158. torchrec/sparse/__init__.py +33 -0
  159. torchrec/sparse/jagged_tensor.py +1281 -0
  160. torchrec/sparse/test_utils/__init__.py +45 -0
  161. torchrec/streamable.py +46 -0
  162. torchrec/test_utils/__init__.py +111 -0
  163. torchrec-0.2.dev0.dist-info/LICENSE +29 -0
  164. torchrec-0.2.dev0.dist-info/METADATA +175 -0
  165. torchrec-0.2.dev0.dist-info/RECORD +167 -0
  166. torchrec-0.2.dev0.dist-info/WHEEL +5 -0
  167. torchrec-0.2.dev0.dist-info/top_level.txt +2 -0
@@ -0,0 +1,213 @@
1
+ #!/usr/bin/env python3
2
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ # All rights reserved.
4
+ #
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
+ """
9
+ Deep Factorization-Machine Modules
10
+
11
+ The following modules are based off the `Deep Factorization-Machine (DeepFM) paper
12
+ <https://arxiv.org/pdf/1703.04247.pdf>`_
13
+
14
+ * Class DeepFM implents the DeepFM Framework
15
+ * Class FactorizationMachine implements FM as noted in the above paper.
16
+
17
+ """
18
+
19
+ from typing import List
20
+
21
+ import torch
22
+ from torch import nn
23
+ from torch.fx import wrap
24
+
25
+
26
+ @wrap
27
+ def _get_flatten_input(inputs: List[torch.Tensor]) -> torch.Tensor:
28
+ return torch.cat(
29
+ [input.flatten(1) for input in inputs],
30
+ dim=1,
31
+ )
32
+
33
+
34
+ class DeepFM(nn.Module):
35
+ r"""
36
+ This is the `DeepFM module <https://arxiv.org/pdf/1703.04247.pdf>`_
37
+
38
+ This module does not cover the end-end functionality of the published paper.
39
+ Instead, it covers only the deep component of the publication. It is used to learn
40
+ high-order feature interactions. If low-order feature interactions should
41
+ be learnt, please use `FactorizationMachine` module instead, which will share
42
+ the same embedding input of this module.
43
+
44
+ To support modeling flexibility, we customize the key components as:
45
+
46
+ * Different from the public paper, we change the input from raw sparse features to
47
+ embeddings of the features. It allows flexibility in embedding dimensions and the
48
+ number of embeddings, as long as all embedding tensors have the same batch size.
49
+
50
+ * On top of the public paper, we allow users to customize the hidden layer to be any
51
+ module, not limited to just MLP.
52
+
53
+ The general architecture of the module is like::
54
+
55
+ 1 x 10 output
56
+ /|\
57
+ | pass into `dense_module`
58
+ |
59
+ 1 x 90
60
+ /|\
61
+ | concat
62
+ |
63
+ 1 x 20, 1 x 30, 1 x 40 list of embeddings
64
+
65
+ Args:
66
+ dense_module (nn.Module):
67
+ any customized module that can be used (such as MLP) in DeepFM. The
68
+ `in_features` of this module must be equal to the element counts. For
69
+ example, if the input embedding is `[randn(3, 2, 3), randn(3, 4, 5)]`, the
70
+ `in_features` should be: 2*3+4*5.
71
+
72
+ Example::
73
+
74
+ import torch
75
+ from torchrec.fb.modules.deepfm import DeepFM
76
+ from torchrec.fb.modules.mlp import LazyMLP
77
+ batch_size = 3
78
+ output_dim = 30
79
+ # the input embedding are a torch.Tensor of [batch_size, num_embeddings, embedding_dim]
80
+ input_embeddings = [
81
+ torch.randn(batch_size, 2, 64),
82
+ torch.randn(batch_size, 2, 32),
83
+ ]
84
+ dense_module = nn.Linear(192, output_dim)
85
+ deepfm = DeepFM(dense_module=dense_module)
86
+ deep_fm_output = deepfm(embeddings=input_embeddings)
87
+ """
88
+
89
+ def __init__(
90
+ self,
91
+ dense_module: nn.Module,
92
+ ) -> None:
93
+ super().__init__()
94
+ self.dense_module = dense_module
95
+
96
+ def forward(
97
+ self,
98
+ embeddings: List[torch.Tensor],
99
+ ) -> torch.Tensor:
100
+ """
101
+ Args:
102
+ embeddings (List[torch.Tensor]):
103
+ The list of all embeddings (e.g. dense, common_sparse,
104
+ specialized_sparse,
105
+ embedding_features, raw_embedding_features) in the shape of::
106
+
107
+ (batch_size, num_embeddings, embedding_dim)
108
+
109
+ For the ease of operation, embeddings that have the same embedding
110
+ dimension have the option to be stacked into a single tensor. For
111
+ example, when we have 1 trained embedding with dimension=32, 5 native
112
+ embeddings with dimension=64, and 3 dense features with dimension=16, we
113
+ can prepare the embeddings list to be the list of::
114
+
115
+ tensor(B, 1, 32) (trained_embedding with num_embeddings=1, embedding_dim=32)
116
+ tensor(B, 5, 64) (native_embedding with num_embeddings=5, embedding_dim=64)
117
+ tensor(B, 3, 16) (dense_features with num_embeddings=3, embedding_dim=32)
118
+
119
+ .. note::
120
+ `batch_size` of all input tensors need to be identical.
121
+
122
+ Returns:
123
+ torch.Tensor: output of `dense_module` with flattened and concatenated `embeddings` as input.
124
+ """
125
+
126
+ # flatten each embedding to be [B, N, D] -> [B, N*D], then cat them all on dim=1
127
+ deepfm_input = _get_flatten_input(embeddings)
128
+ deepfm_output = self.dense_module(deepfm_input)
129
+ return deepfm_output
130
+
131
+
132
+ class FactorizationMachine(nn.Module):
133
+ r"""
134
+ This is the Factorization Machine module, mentioned in the `DeepFM paper
135
+ <https://arxiv.org/pdf/1703.04247.pdf>`_:
136
+
137
+ This module does not cover the end-end functionality of the published paper.
138
+ Instead, it covers only the FM part of the publication, and is used to learn
139
+ 2nd-order feature interactions.
140
+
141
+ To support modeling flexibility, we customize the key components as different from
142
+ the public paper:
143
+ We change the input from raw sparse features to embeddings of the features.
144
+ This allows flexibility in embedding dimensions and the number of embeddings,
145
+ as long as all embedding tensors have the same batch size.
146
+
147
+ The general architecture of the module is like::
148
+
149
+ 1 x 10 output
150
+ /|\
151
+ | pass into `dense_module`
152
+ |
153
+ 1 x 90
154
+ /|\
155
+ | concat
156
+ |
157
+ 1 x 20, 1 x 30, 1 x 40 list of embeddings
158
+
159
+ Example::
160
+
161
+ batch_size = 3
162
+ # the input embedding are in torch.Tensor of [batch_size, num_embeddings, embedding_dim]
163
+ input_embeddings = [
164
+ torch.randn(batch_size, 2, 64),
165
+ torch.randn(batch_size, 2, 32),
166
+ ]
167
+ fm = FactorizationMachine()
168
+ output = fm(embeddings=input_embeddings)
169
+ """
170
+
171
+ def __init__(
172
+ self,
173
+ ) -> None:
174
+ super().__init__()
175
+
176
+ def forward(
177
+ self,
178
+ embeddings: List[torch.Tensor],
179
+ ) -> torch.Tensor:
180
+ """
181
+ Args:
182
+ embeddings (List[torch.Tensor]):
183
+ The list of all embeddings (e.g. dense, common_sparse,
184
+ specialized_sparse, embedding_features, raw_embedding_features) in the
185
+ shape of::
186
+
187
+ (batch_size, num_embeddings, embedding_dim)
188
+
189
+ For the ease of operation, embeddings that have the same embedding
190
+ dimension have the option to be stacked into a single tensor. For
191
+ example, when we have 1 trained embedding with dimension=32, 5 native
192
+ embeddings with dimension=64, and 3 dense features with dimension=16, we
193
+ can prepare the embeddings list to be the list of::
194
+
195
+ tensor(B, 1, 32) (trained_embedding with num_embeddings=1, embedding_dim=32)
196
+ tensor(B, 5, 64) (native_embedding with num_embeddings=5, embedding_dim=64)
197
+ tensor(B, 3, 16) (dense_features with num_embeddings=3, embedding_dim=32)
198
+
199
+ NOTE:
200
+ `batch_size` of all input tensors need to be identical.
201
+
202
+ Returns:
203
+ torch.Tensor: output of fm with flattened and concatenated `embeddings` as input. Expected to be [B, 1].
204
+ """
205
+
206
+ # flatten each embedding to be [B, N, D] -> [B, N*D], then cat them all on dim=1
207
+ fm_input = _get_flatten_input(embeddings)
208
+ sum_of_input = torch.sum(fm_input, dim=1, keepdim=True)
209
+ sum_of_square = torch.sum(fm_input * fm_input, dim=1, keepdim=True)
210
+ square_of_sum = sum_of_input * sum_of_input
211
+ cross_term = square_of_sum - sum_of_square
212
+ cross_term = torch.sum(cross_term, dim=1, keepdim=True) * 0.5 # [B, 1]
213
+ return cross_term
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/env python3
2
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ # All rights reserved.
4
+ #
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
+ from dataclasses import dataclass, field
9
+ from enum import Enum, unique
10
+ from math import sqrt
11
+ from typing import Dict, List, Optional
12
+
13
+ import torch
14
+ from fbgemm_gpu.split_embedding_configs import SparseType
15
+ from fbgemm_gpu.split_table_batched_embeddings_ops import PoolingMode
16
+
17
+
18
+ @unique
19
+ class PoolingType(Enum):
20
+ SUM = "SUM"
21
+ MEAN = "MEAN"
22
+ NONE = "NONE"
23
+
24
+
25
+ @unique
26
+ class DataType(Enum):
27
+ """
28
+ Our fusion implementation supports only certain types of data
29
+ so it makes sense to retrict in a non-fused version as well.
30
+ """
31
+
32
+ FP32 = "FP32"
33
+ FP16 = "FP16"
34
+ INT8 = "INT8"
35
+ INT4 = "INT4"
36
+ INT2 = "INT2"
37
+
38
+
39
+ DATA_TYPE_NUM_BITS: Dict[DataType, int] = {
40
+ DataType.FP32: 32,
41
+ DataType.FP16: 16,
42
+ DataType.INT8: 8,
43
+ DataType.INT4: 4,
44
+ DataType.INT2: 2,
45
+ }
46
+
47
+
48
+ def dtype_to_data_type(dtype: torch.dtype) -> DataType:
49
+ if dtype == torch.float:
50
+ return DataType.FP32
51
+ elif dtype == torch.float16 or dtype == torch.half:
52
+ return DataType.FP16
53
+ elif dtype == torch.quint8 or dtype == torch.qint8 or dtype == torch.int8:
54
+ return DataType.INT8
55
+ elif dtype == torch.quint4x2:
56
+ return DataType.INT4
57
+ elif dtype == torch.quint2x4:
58
+ return DataType.INT2
59
+ else:
60
+ raise Exception(f"Invalid data type {dtype}")
61
+
62
+
63
+ def pooling_type_to_pooling_mode(pooling_type: PoolingType) -> PoolingMode:
64
+ if pooling_type == PoolingType.SUM:
65
+ return PoolingMode.SUM
66
+ elif pooling_type == PoolingType.MEAN:
67
+ return PoolingMode.MEAN
68
+ else:
69
+ raise Exception(f"Invalid pooling type {pooling_type}")
70
+
71
+
72
+ def pooling_type_to_str(pooling_type: PoolingType) -> str:
73
+ if pooling_type == PoolingType.SUM:
74
+ return "sum"
75
+ elif pooling_type == PoolingType.MEAN:
76
+ return "mean"
77
+ else:
78
+ raise ValueError(f"Unsupported pooling type {pooling_type}")
79
+
80
+
81
+ def data_type_to_sparse_type(data_type: DataType) -> SparseType:
82
+ if data_type == DataType.FP32:
83
+ return SparseType.FP32
84
+ elif data_type == DataType.FP16:
85
+ return SparseType.FP16
86
+ elif data_type == DataType.INT8:
87
+ return SparseType.INT8
88
+ elif data_type == DataType.INT4:
89
+ return SparseType.INT4
90
+ elif data_type == DataType.INT2:
91
+ return SparseType.INT2
92
+ else:
93
+ raise ValueError(f"Invalid DataType {data_type}")
94
+
95
+
96
+ def data_type_to_dtype(data_type: DataType) -> torch.dtype:
97
+ if data_type == DataType.FP32:
98
+ return torch.float32
99
+ elif data_type == DataType.FP16:
100
+ return torch.float16
101
+ elif data_type == DataType.INT8:
102
+ return torch.int8
103
+ else:
104
+ raise ValueError(f"DataType {data_type} cannot be converted to dtype")
105
+
106
+
107
+ @dataclass
108
+ class BaseEmbeddingConfig:
109
+ num_embeddings: int
110
+ embedding_dim: int
111
+ name: str = ""
112
+ data_type: DataType = DataType.FP32
113
+ feature_names: List[str] = field(default_factory=list)
114
+ weight_init_max: Optional[float] = None
115
+ weight_init_min: Optional[float] = None
116
+
117
+ def get_weight_init_max(self) -> float:
118
+ if self.weight_init_max is None:
119
+ return sqrt(1 / self.num_embeddings)
120
+ else:
121
+ return self.weight_init_max
122
+
123
+ def get_weight_init_min(self) -> float:
124
+ if self.weight_init_min is None:
125
+ return -sqrt(1 / self.num_embeddings)
126
+ else:
127
+ return self.weight_init_min
128
+
129
+ def num_features(self) -> int:
130
+ return len(self.feature_names)
131
+
132
+
133
+ @dataclass
134
+ class EmbeddingTableConfig(BaseEmbeddingConfig):
135
+ pooling: PoolingType = PoolingType.SUM
136
+ is_weighted: bool = False
137
+ has_feature_processor: bool = False
138
+ embedding_names: List[str] = field(default_factory=list)
139
+
140
+
141
+ @dataclass
142
+ class EmbeddingBagConfig(BaseEmbeddingConfig):
143
+ pooling: PoolingType = PoolingType.SUM
144
+
145
+
146
+ @dataclass
147
+ class EmbeddingConfig(BaseEmbeddingConfig):
148
+ pass