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,369 @@
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
+ import abc
9
+ from dataclasses import dataclass
10
+ from enum import Enum, unique
11
+ from typing import Any, Dict, Generic, Iterator, List, Optional, TypeVar
12
+
13
+ import torch
14
+ from fbgemm_gpu.split_table_batched_embeddings_ops import EmbeddingLocation
15
+ from torch import nn
16
+ from torchrec.distributed.types import (
17
+ ModuleSharder,
18
+ ParameterStorage,
19
+ ShardedTensorMetadata,
20
+ ShardingType,
21
+ ShardMetadata,
22
+ )
23
+ from torchrec.modules.embedding_configs import (
24
+ DataType,
25
+ EmbeddingTableConfig,
26
+ PoolingType,
27
+ )
28
+ from torchrec.sparse.jagged_tensor import KeyedJaggedTensor
29
+ from torchrec.streamable import Multistreamable
30
+
31
+
32
+ @unique
33
+ class OptimType(Enum):
34
+ SGD = "SGD"
35
+ LARS_SGD = "LARS_SGD"
36
+ LAMB = "LAMB"
37
+ PARTIAL_ROWWISE_LAMB = "PARTIAL_ROWWISE_LAMB"
38
+ ADAM = "ADAM"
39
+ PARTIAL_ROWWISE_ADAM = "PARTIAL_ROWWISE_ADAM"
40
+ ADAGRAD = "ADAGRAD"
41
+ ROWWISE_ADAGRAD = "ROWWISE_ADAGRAD"
42
+ SHAMPOO = "SHAMPOO"
43
+
44
+
45
+ @unique
46
+ class EmbeddingComputeKernel(Enum):
47
+ DENSE = "dense"
48
+ FUSED = "fused"
49
+ FUSED_UVM = "fused_uvm"
50
+ FUSED_UVM_CACHING = "fused_uvm_caching"
51
+ QUANT = "quant"
52
+ QUANT_UVM = "quant_uvm"
53
+ QUANT_UVM_CACHING = "quant_uvm_caching"
54
+
55
+
56
+ def compute_kernel_to_embedding_location(
57
+ compute_kernel: EmbeddingComputeKernel,
58
+ ) -> EmbeddingLocation:
59
+ if compute_kernel in [
60
+ EmbeddingComputeKernel.DENSE,
61
+ EmbeddingComputeKernel.FUSED,
62
+ EmbeddingComputeKernel.QUANT,
63
+ ]:
64
+ return EmbeddingLocation.DEVICE
65
+ elif compute_kernel in [
66
+ EmbeddingComputeKernel.FUSED_UVM,
67
+ EmbeddingComputeKernel.QUANT_UVM,
68
+ ]:
69
+ return EmbeddingLocation.MANAGED
70
+ elif compute_kernel in [
71
+ EmbeddingComputeKernel.FUSED_UVM_CACHING,
72
+ EmbeddingComputeKernel.QUANT_UVM_CACHING,
73
+ ]:
74
+ return EmbeddingLocation.MANAGED_CACHING
75
+ else:
76
+ raise ValueError(f"Invalid EmbeddingComputeKernel {compute_kernel}")
77
+
78
+
79
+ @dataclass
80
+ class SparseFeatures(Multistreamable):
81
+ id_list_features: Optional[KeyedJaggedTensor] = None
82
+ id_score_list_features: Optional[KeyedJaggedTensor] = None
83
+
84
+ def record_stream(self, stream: torch.cuda.streams.Stream) -> None:
85
+ if self.id_list_features is not None:
86
+ self.id_list_features.record_stream(stream)
87
+ if self.id_score_list_features is not None:
88
+ self.id_score_list_features.record_stream(stream)
89
+
90
+
91
+ class SparseFeaturesList(Multistreamable):
92
+ def __init__(self, features: List[SparseFeatures]) -> None:
93
+ self.features = features
94
+
95
+ def __len__(self) -> int:
96
+ return len(self.features)
97
+
98
+ def __setitem__(self, key: int, item: SparseFeatures) -> None:
99
+ self.features[key] = item
100
+
101
+ def __getitem__(self, key: int) -> SparseFeatures:
102
+ return self.features[key]
103
+
104
+ def __iter__(self) -> Iterator[SparseFeatures]:
105
+ return iter(self.features)
106
+
107
+ def record_stream(self, stream: torch.cuda.streams.Stream) -> None:
108
+ for feature in self.features:
109
+ feature.record_stream(stream)
110
+
111
+
112
+ class ListOfSparseFeaturesList(Multistreamable):
113
+ def __init__(self, features: List[SparseFeaturesList]) -> None:
114
+ self.features_list = features
115
+
116
+ def __len__(self) -> int:
117
+ return len(self.features_list)
118
+
119
+ def __setitem__(self, key: int, item: SparseFeaturesList) -> None:
120
+ self.features_list[key] = item
121
+
122
+ def __getitem__(self, key: int) -> SparseFeaturesList:
123
+ return self.features_list[key]
124
+
125
+ def __iter__(self) -> Iterator[SparseFeaturesList]:
126
+ return iter(self.features_list)
127
+
128
+ def record_stream(self, stream: torch.cuda.streams.Stream) -> None:
129
+ for feature in self.features_list:
130
+ feature.record_stream(stream)
131
+
132
+
133
+ @dataclass
134
+ class ShardedConfig:
135
+ local_rows: int = 0
136
+ local_cols: int = 0
137
+
138
+
139
+ @dataclass
140
+ class ShardedMetaConfig(ShardedConfig):
141
+ local_metadata: Optional[ShardMetadata] = None
142
+ global_metadata: Optional[ShardedTensorMetadata] = None
143
+
144
+
145
+ @dataclass
146
+ class EmbeddingAttributes:
147
+ compute_kernel: EmbeddingComputeKernel = EmbeddingComputeKernel.DENSE
148
+
149
+
150
+ @dataclass
151
+ class ShardedEmbeddingTable(
152
+ ShardedMetaConfig,
153
+ EmbeddingAttributes,
154
+ EmbeddingTableConfig,
155
+ ):
156
+ pass
157
+
158
+
159
+ @dataclass
160
+ class GroupedEmbeddingConfig:
161
+ data_type: DataType
162
+ pooling: PoolingType
163
+ is_weighted: bool
164
+ has_feature_processor: bool
165
+ compute_kernel: EmbeddingComputeKernel
166
+ embedding_tables: List[ShardedEmbeddingTable]
167
+
168
+ def feature_hash_sizes(self) -> List[int]:
169
+ feature_hash_sizes = []
170
+ for table in self.embedding_tables:
171
+ feature_hash_sizes.extend(table.num_features() * [table.num_embeddings])
172
+ return feature_hash_sizes
173
+
174
+ def num_features(self) -> int:
175
+ num_features = 0
176
+ for table in self.embedding_tables:
177
+ num_features += table.num_features()
178
+ return num_features
179
+
180
+ def dim_sum(self) -> int:
181
+ dim_sum = 0
182
+ for table in self.embedding_tables:
183
+ dim_sum += table.num_features() * table.local_cols
184
+ return dim_sum
185
+
186
+ def feature_names(self) -> List[str]:
187
+ feature_names = []
188
+ for table in self.embedding_tables:
189
+ feature_names.extend(table.feature_names)
190
+ return feature_names
191
+
192
+ def embedding_dims(self) -> List[int]:
193
+ embedding_dims = []
194
+ for table in self.embedding_tables:
195
+ embedding_dims.extend([table.local_cols] * table.num_features())
196
+ return embedding_dims
197
+
198
+ def embedding_names(self) -> List[str]:
199
+ embedding_names = []
200
+ for table in self.embedding_tables:
201
+ embedding_names.extend(table.embedding_names)
202
+ return embedding_names
203
+
204
+ def embedding_shard_metadata(self) -> List[Optional[ShardMetadata]]:
205
+ embedding_shard_metadata: List[Optional[ShardMetadata]] = []
206
+ for table in self.embedding_tables:
207
+ for _ in table.feature_names:
208
+ embedding_shard_metadata.append(table.local_metadata)
209
+ return embedding_shard_metadata
210
+
211
+
212
+ F = TypeVar("F", bound=Multistreamable)
213
+ T = TypeVar("T")
214
+
215
+
216
+ class BaseEmbeddingLookup(abc.ABC, nn.Module, Generic[F, T]):
217
+ """
218
+ Interface implemented by different embedding implementations:
219
+ e.g. one, which relies on `nn.EmbeddingBag` or table-batched one, etc.
220
+ """
221
+
222
+ @abc.abstractmethod
223
+ def forward(
224
+ self,
225
+ sparse_features: F,
226
+ ) -> T:
227
+ pass
228
+
229
+ def sparse_grad_parameter_names(
230
+ self, destination: Optional[List[str]] = None, prefix: str = ""
231
+ ) -> List[str]:
232
+ destination = [] if destination is None else destination
233
+ return destination
234
+
235
+
236
+ M = TypeVar("M", bound=nn.Module)
237
+
238
+
239
+ class BaseEmbeddingSharder(ModuleSharder[M]):
240
+ def __init__(self, fused_params: Optional[Dict[str, Any]] = None) -> None:
241
+ super().__init__()
242
+
243
+ self._fused_params = fused_params
244
+
245
+ def sharding_types(self, compute_device_type: str) -> List[str]:
246
+ types = [
247
+ ShardingType.DATA_PARALLEL.value,
248
+ ShardingType.TABLE_WISE.value,
249
+ ShardingType.COLUMN_WISE.value,
250
+ ShardingType.TABLE_COLUMN_WISE.value,
251
+ ]
252
+ if compute_device_type in {"cuda"}:
253
+ types += [
254
+ ShardingType.ROW_WISE.value,
255
+ ShardingType.TABLE_ROW_WISE.value,
256
+ ]
257
+
258
+ return types
259
+
260
+ def compute_kernels(
261
+ self, sharding_type: str, compute_device_type: str
262
+ ) -> List[str]:
263
+ ret = [
264
+ EmbeddingComputeKernel.DENSE.value,
265
+ ]
266
+ if sharding_type != ShardingType.DATA_PARALLEL.value:
267
+ ret += [
268
+ EmbeddingComputeKernel.FUSED.value,
269
+ ]
270
+ if compute_device_type in {"cuda"}:
271
+ ret += [
272
+ EmbeddingComputeKernel.FUSED_UVM.value,
273
+ EmbeddingComputeKernel.FUSED_UVM_CACHING.value,
274
+ ]
275
+ return ret
276
+
277
+ @property
278
+ def fused_params(self) -> Optional[Dict[str, Any]]:
279
+ return self._fused_params
280
+
281
+ def storage_usage(
282
+ self, tensor: torch.Tensor, compute_device_type: str, compute_kernel: str
283
+ ) -> Dict[str, int]:
284
+ """
285
+ List of system resources and corresponding usage given a compute device and
286
+ compute kernel
287
+ """
288
+ tensor_bytes = tensor.element_size() * tensor.nelement()
289
+ if compute_kernel in {
290
+ EmbeddingComputeKernel.FUSED_UVM.value,
291
+ EmbeddingComputeKernel.FUSED_UVM_CACHING.value,
292
+ }:
293
+ assert compute_device_type in {"cuda"}
294
+ return {ParameterStorage.DDR.value: tensor_bytes}
295
+ else:
296
+ assert compute_device_type in {"cuda", "cpu"}
297
+ storage_map = {"cuda": ParameterStorage.HBM, "cpu": ParameterStorage.DDR}
298
+ return {
299
+ storage_map[compute_device_type].value: tensor.element_size()
300
+ * tensor.nelement()
301
+ }
302
+
303
+
304
+ class BaseGroupedFeatureProcessor(nn.Module):
305
+ """
306
+ Abstract base class for grouped feature processor
307
+ """
308
+
309
+ @abc.abstractmethod
310
+ def forward(
311
+ self,
312
+ features: KeyedJaggedTensor,
313
+ ) -> KeyedJaggedTensor:
314
+ pass
315
+
316
+ def sparse_grad_parameter_names(
317
+ self, destination: Optional[List[str]] = None, prefix: str = ""
318
+ ) -> List[str]:
319
+ destination = [] if destination is None else destination
320
+ return destination
321
+
322
+
323
+ class BaseQuantEmbeddingSharder(ModuleSharder[M]):
324
+ def __init__(self, fused_params: Optional[Dict[str, Any]] = None) -> None:
325
+ super().__init__()
326
+ self._fused_params = fused_params
327
+
328
+ def sharding_types(self, compute_device_type: str) -> List[str]:
329
+ types = [
330
+ ShardingType.TABLE_WISE.value,
331
+ ]
332
+
333
+ return types
334
+
335
+ def compute_kernels(
336
+ self, sharding_type: str, compute_device_type: str
337
+ ) -> List[str]:
338
+ ret = [
339
+ EmbeddingComputeKernel.QUANT.value,
340
+ ]
341
+ if compute_device_type in {"cuda"}:
342
+ ret += [
343
+ EmbeddingComputeKernel.QUANT_UVM.value,
344
+ EmbeddingComputeKernel.QUANT_UVM_CACHING.value,
345
+ ]
346
+ return ret
347
+
348
+ @property
349
+ def fused_params(self) -> Optional[Dict[str, Any]]:
350
+ return self._fused_params
351
+
352
+ def storage_usage(
353
+ self, tensor: torch.Tensor, compute_device_type: str, compute_kernel: str
354
+ ) -> Dict[str, int]:
355
+ """
356
+ List of system resources and corresponding usage given a compute device and
357
+ compute kernel
358
+ """
359
+ tensor_bytes = tensor.element_size() * tensor.nelement() + tensor.shape[0] * 4
360
+ if compute_kernel in {
361
+ EmbeddingComputeKernel.QUANT_UVM.value,
362
+ EmbeddingComputeKernel.QUANT_UVM_CACHING.value,
363
+ }:
364
+ assert compute_device_type in {"cuda"}
365
+ return {ParameterStorage.DDR.value: tensor_bytes}
366
+ else:
367
+ assert compute_device_type in {"cuda", "cpu"}
368
+ storage_map = {"cuda": ParameterStorage.HBM, "cpu": ParameterStorage.DDR}
369
+ return {storage_map[compute_device_type].value: tensor_bytes}