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
|
@@ -0,0 +1,971 @@
|
|
|
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 math
|
|
9
|
+
from typing import cast, Dict, List, Optional, Tuple
|
|
10
|
+
|
|
11
|
+
import torch
|
|
12
|
+
from torch import nn
|
|
13
|
+
from torchrec.distributed.embedding_types import EmbeddingComputeKernel
|
|
14
|
+
from torchrec.distributed.planner.constants import (
|
|
15
|
+
BATCHED_COPY_PERF_FACTOR,
|
|
16
|
+
BIGINT_DTYPE,
|
|
17
|
+
BWD_COMPUTE_MULTIPLIER,
|
|
18
|
+
CROSS_NODE_BANDWIDTH,
|
|
19
|
+
DP_ELEMENTWISE_KERNELS_PERF_FACTOR,
|
|
20
|
+
FULL_BLOCK_EMB_DIM,
|
|
21
|
+
HALF_BLOCK_PENALTY,
|
|
22
|
+
INTRA_NODE_BANDWIDTH,
|
|
23
|
+
kernel_bw_lookup,
|
|
24
|
+
QUARTER_BLOCK_PENALTY,
|
|
25
|
+
UVM_CACHING_RATIO,
|
|
26
|
+
WEIGHTED_KERNEL_MULTIPLIER,
|
|
27
|
+
)
|
|
28
|
+
from torchrec.distributed.planner.types import (
|
|
29
|
+
ParameterConstraints,
|
|
30
|
+
PlannerError,
|
|
31
|
+
ShardEstimator,
|
|
32
|
+
ShardingOption,
|
|
33
|
+
Storage,
|
|
34
|
+
Topology,
|
|
35
|
+
)
|
|
36
|
+
from torchrec.distributed.planner.utils import prod, sharder_name
|
|
37
|
+
from torchrec.distributed.types import ModuleSharder, ShardingType
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class EmbeddingPerfEstimator(ShardEstimator):
|
|
41
|
+
"""
|
|
42
|
+
Embedding Wall Time Perf Estimator
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
def __init__(
|
|
46
|
+
self,
|
|
47
|
+
topology: Topology,
|
|
48
|
+
constraints: Optional[Dict[str, ParameterConstraints]] = None,
|
|
49
|
+
) -> None:
|
|
50
|
+
self._topology = topology
|
|
51
|
+
self._constraints = constraints
|
|
52
|
+
|
|
53
|
+
def estimate(
|
|
54
|
+
self,
|
|
55
|
+
sharding_options: List[ShardingOption],
|
|
56
|
+
sharder_map: Optional[Dict[str, ModuleSharder[nn.Module]]] = None,
|
|
57
|
+
) -> None:
|
|
58
|
+
for sharding_option in sharding_options:
|
|
59
|
+
caching_ratio = (
|
|
60
|
+
self._constraints[sharding_option.name].caching_ratio
|
|
61
|
+
if self._constraints and self._constraints.get(sharding_option.name)
|
|
62
|
+
else None
|
|
63
|
+
)
|
|
64
|
+
num_poolings = (
|
|
65
|
+
cast(List[float], self._constraints[sharding_option.name].num_poolings)
|
|
66
|
+
if self._constraints
|
|
67
|
+
and self._constraints.get(sharding_option.name)
|
|
68
|
+
and self._constraints[sharding_option.name].num_poolings
|
|
69
|
+
else [1.0] * sharding_option.num_inputs
|
|
70
|
+
)
|
|
71
|
+
batch_sizes = (
|
|
72
|
+
cast(List[int], self._constraints[sharding_option.name].batch_sizes)
|
|
73
|
+
if self._constraints
|
|
74
|
+
and self._constraints.get(sharding_option.name)
|
|
75
|
+
and self._constraints[sharding_option.name].batch_sizes
|
|
76
|
+
else [sharding_option.batch_size] * sharding_option.num_inputs
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
assert (
|
|
80
|
+
len(sharding_option.input_lengths)
|
|
81
|
+
== len(num_poolings)
|
|
82
|
+
== len(batch_sizes)
|
|
83
|
+
), "Provided `pooling_factors`, `num_poolings`, and `batch_sizes` constraints must match."
|
|
84
|
+
|
|
85
|
+
shard_perfs = perf_func_emb_wall_time(
|
|
86
|
+
shard_sizes=[shard.size for shard in sharding_option.shards],
|
|
87
|
+
compute_kernel=sharding_option.compute_kernel,
|
|
88
|
+
compute_device=self._topology.compute_device,
|
|
89
|
+
sharding_type=sharding_option.sharding_type,
|
|
90
|
+
batch_sizes=batch_sizes,
|
|
91
|
+
world_size=self._topology.world_size,
|
|
92
|
+
local_world_size=self._topology.local_world_size,
|
|
93
|
+
input_lengths=sharding_option.input_lengths,
|
|
94
|
+
input_data_type_size=BIGINT_DTYPE,
|
|
95
|
+
output_data_type_size=sharding_option.tensor.element_size(),
|
|
96
|
+
num_poolings=num_poolings,
|
|
97
|
+
bw_intra_host=getattr(
|
|
98
|
+
self._topology, "intra_host_bw", INTRA_NODE_BANDWIDTH
|
|
99
|
+
),
|
|
100
|
+
bw_inter_host=getattr(
|
|
101
|
+
self._topology, "inter_host_bw", CROSS_NODE_BANDWIDTH
|
|
102
|
+
),
|
|
103
|
+
is_pooled=sharding_option.is_pooled,
|
|
104
|
+
is_weighted=True
|
|
105
|
+
if getattr(sharding_option.module[1], "is_weighted", False)
|
|
106
|
+
else False,
|
|
107
|
+
has_feature_processor=True
|
|
108
|
+
if getattr(sharding_option.module[1], "feature_processor", None)
|
|
109
|
+
else False,
|
|
110
|
+
caching_ratio=caching_ratio,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
for shard, perf in zip(sharding_option.shards, shard_perfs):
|
|
114
|
+
shard.perf = perf
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def perf_func_emb_wall_time(
|
|
118
|
+
shard_sizes: List[List[int]],
|
|
119
|
+
compute_kernel: str,
|
|
120
|
+
compute_device: str,
|
|
121
|
+
sharding_type: str,
|
|
122
|
+
batch_sizes: List[int],
|
|
123
|
+
world_size: int,
|
|
124
|
+
local_world_size: int,
|
|
125
|
+
input_lengths: List[float],
|
|
126
|
+
input_data_type_size: float,
|
|
127
|
+
output_data_type_size: float,
|
|
128
|
+
num_poolings: List[float],
|
|
129
|
+
bw_intra_host: float,
|
|
130
|
+
bw_inter_host: float,
|
|
131
|
+
is_pooled: bool,
|
|
132
|
+
is_weighted: bool = False,
|
|
133
|
+
has_feature_processor: bool = False,
|
|
134
|
+
caching_ratio: Optional[float] = None,
|
|
135
|
+
) -> List[float]:
|
|
136
|
+
"""
|
|
137
|
+
Attempts to model perfs as a function of relative wall times.
|
|
138
|
+
|
|
139
|
+
Args:
|
|
140
|
+
shard_sizes (List[List[int]]): the list of (local_rows, local_cols) of each
|
|
141
|
+
shard.
|
|
142
|
+
compute_kernel (str): compute kernel.
|
|
143
|
+
compute_device (str): compute device.
|
|
144
|
+
sharding_type (str): tw, rw, cw, twrw, dp.
|
|
145
|
+
batch_sizes (List[int]): batch size for each input feature.
|
|
146
|
+
world_size (int): the number of devices for all hosts.
|
|
147
|
+
local_world_size (int): the number of the device for each host.
|
|
148
|
+
input_lengths (List[float]): the list of the average number of lookups of each
|
|
149
|
+
input query feature.
|
|
150
|
+
input_data_type_size (float): the data type size of the distributed
|
|
151
|
+
data_parallel input.
|
|
152
|
+
output_data_type_size (float): the data type size of the distributed
|
|
153
|
+
data_parallel output.
|
|
154
|
+
num_poolings (List[float]): number of poolings per sample, typically 1.0.
|
|
155
|
+
bw_intra_host (float): the bandwidth within a single host like multiple threads.
|
|
156
|
+
bw_inter_host (float): the bandwidth between two hosts like multiple machines.
|
|
157
|
+
is_pooled (bool): True if embedding output is pooled (ie. EmbeddingBag), False
|
|
158
|
+
if unpooled/sequential (ie. Embedding).
|
|
159
|
+
is_weighted (bool = False): if the module is an EBC and is weighted, typically
|
|
160
|
+
signifying an id score list feature.
|
|
161
|
+
has_feature_processor (bool = False): if the module has a feature processor.
|
|
162
|
+
caching_ratio (Optional[float] = None): cache ratio to determine the bandwidth
|
|
163
|
+
of device.
|
|
164
|
+
|
|
165
|
+
Returns:
|
|
166
|
+
List[float]: the list of perf for each shard.
|
|
167
|
+
"""
|
|
168
|
+
|
|
169
|
+
shard_perfs = []
|
|
170
|
+
device_bw = kernel_bw_lookup(compute_device, compute_kernel, caching_ratio)
|
|
171
|
+
if device_bw is None:
|
|
172
|
+
raise PlannerError(
|
|
173
|
+
f"No kernel bandwidth exists for this combo of compute device: {compute_device}, compute kernel: {compute_kernel}"
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
for hash_size, emb_dim in shard_sizes:
|
|
177
|
+
if (
|
|
178
|
+
sharding_type == ShardingType.TABLE_WISE.value
|
|
179
|
+
or sharding_type == ShardingType.COLUMN_WISE.value
|
|
180
|
+
or sharding_type == ShardingType.TABLE_COLUMN_WISE.value
|
|
181
|
+
):
|
|
182
|
+
shard_perf = _get_tw_sharding_perf(
|
|
183
|
+
batch_sizes=batch_sizes,
|
|
184
|
+
world_size=world_size,
|
|
185
|
+
local_world_size=local_world_size,
|
|
186
|
+
input_lengths=input_lengths,
|
|
187
|
+
emb_dim=emb_dim,
|
|
188
|
+
input_data_type_size=input_data_type_size,
|
|
189
|
+
output_data_type_size=output_data_type_size,
|
|
190
|
+
num_poolings=num_poolings,
|
|
191
|
+
device_bw=device_bw,
|
|
192
|
+
bw_inter_host=bw_inter_host,
|
|
193
|
+
bw_intra_host=bw_intra_host,
|
|
194
|
+
is_pooled=is_pooled,
|
|
195
|
+
is_weighted=is_weighted,
|
|
196
|
+
has_feature_processor=has_feature_processor,
|
|
197
|
+
)
|
|
198
|
+
elif sharding_type == ShardingType.ROW_WISE.value:
|
|
199
|
+
shard_perf = _get_rw_sharding_perf(
|
|
200
|
+
batch_sizes=batch_sizes,
|
|
201
|
+
world_size=world_size,
|
|
202
|
+
local_world_size=local_world_size,
|
|
203
|
+
input_lengths=input_lengths,
|
|
204
|
+
emb_dim=emb_dim,
|
|
205
|
+
input_data_type_size=input_data_type_size,
|
|
206
|
+
output_data_type_size=output_data_type_size,
|
|
207
|
+
num_poolings=num_poolings,
|
|
208
|
+
device_bw=device_bw,
|
|
209
|
+
bw_inter_host=bw_inter_host,
|
|
210
|
+
bw_intra_host=bw_intra_host,
|
|
211
|
+
is_pooled=is_pooled,
|
|
212
|
+
is_weighted=is_weighted,
|
|
213
|
+
has_feature_processor=has_feature_processor,
|
|
214
|
+
)
|
|
215
|
+
elif sharding_type == ShardingType.TABLE_ROW_WISE.value:
|
|
216
|
+
shard_perf = _get_twrw_sharding_perf(
|
|
217
|
+
batch_sizes=batch_sizes,
|
|
218
|
+
world_size=world_size,
|
|
219
|
+
local_world_size=local_world_size,
|
|
220
|
+
input_lengths=input_lengths,
|
|
221
|
+
emb_dim=emb_dim,
|
|
222
|
+
input_data_type_size=input_data_type_size,
|
|
223
|
+
output_data_type_size=output_data_type_size,
|
|
224
|
+
num_poolings=num_poolings,
|
|
225
|
+
device_bw=device_bw,
|
|
226
|
+
bw_inter_host=bw_inter_host,
|
|
227
|
+
bw_intra_host=bw_intra_host,
|
|
228
|
+
is_pooled=is_pooled,
|
|
229
|
+
is_weighted=is_weighted,
|
|
230
|
+
has_feature_processor=has_feature_processor,
|
|
231
|
+
)
|
|
232
|
+
elif sharding_type == ShardingType.DATA_PARALLEL.value:
|
|
233
|
+
shard_perf = _get_dp_sharding_perf(
|
|
234
|
+
batch_sizes=batch_sizes,
|
|
235
|
+
world_size=world_size,
|
|
236
|
+
local_world_size=local_world_size,
|
|
237
|
+
input_lengths=input_lengths,
|
|
238
|
+
grad_num_elem=hash_size * emb_dim,
|
|
239
|
+
emb_dim=emb_dim,
|
|
240
|
+
input_data_type_size=output_data_type_size,
|
|
241
|
+
output_data_type_size=output_data_type_size,
|
|
242
|
+
num_poolings=num_poolings,
|
|
243
|
+
device_bw=device_bw,
|
|
244
|
+
bw_inter_host=bw_inter_host,
|
|
245
|
+
is_pooled=is_pooled,
|
|
246
|
+
is_weighted=is_weighted,
|
|
247
|
+
has_feature_processor=has_feature_processor,
|
|
248
|
+
)
|
|
249
|
+
else:
|
|
250
|
+
raise ValueError(
|
|
251
|
+
f"Unrecognized or unsupported sharding type provided: {sharding_type}"
|
|
252
|
+
)
|
|
253
|
+
shard_perfs.append(shard_perf)
|
|
254
|
+
|
|
255
|
+
return shard_perfs
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def _get_tw_sharding_perf(
|
|
259
|
+
batch_sizes: List[int],
|
|
260
|
+
world_size: int,
|
|
261
|
+
local_world_size: int,
|
|
262
|
+
input_lengths: List[float],
|
|
263
|
+
emb_dim: int,
|
|
264
|
+
input_data_type_size: float,
|
|
265
|
+
output_data_type_size: float,
|
|
266
|
+
num_poolings: List[float],
|
|
267
|
+
device_bw: float,
|
|
268
|
+
bw_inter_host: float,
|
|
269
|
+
bw_intra_host: float,
|
|
270
|
+
is_pooled: bool,
|
|
271
|
+
is_weighted: bool = False,
|
|
272
|
+
has_feature_processor: bool = False,
|
|
273
|
+
) -> float:
|
|
274
|
+
batch_inputs = sum(
|
|
275
|
+
[x * y * z for x, y, z in zip(input_lengths, num_poolings, batch_sizes)]
|
|
276
|
+
)
|
|
277
|
+
batch_outputs = (
|
|
278
|
+
sum([x * y for x, y in zip(num_poolings, batch_sizes)])
|
|
279
|
+
if is_pooled
|
|
280
|
+
else batch_inputs
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
input_read_size = math.ceil(batch_inputs * world_size * input_data_type_size)
|
|
284
|
+
if is_weighted or has_feature_processor:
|
|
285
|
+
input_read_size *= 2
|
|
286
|
+
|
|
287
|
+
# minimum embedding dim is set to 32 due to kernel usage
|
|
288
|
+
embedding_lookup_size = (
|
|
289
|
+
batch_inputs * world_size * max(emb_dim, 32) * output_data_type_size
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
output_write_size = batch_outputs * world_size * emb_dim * output_data_type_size
|
|
293
|
+
|
|
294
|
+
# embedding dim below 128 will reduce kernel efficency
|
|
295
|
+
block_usage_penalty = 1
|
|
296
|
+
if emb_dim < FULL_BLOCK_EMB_DIM:
|
|
297
|
+
if emb_dim >= 64:
|
|
298
|
+
block_usage_penalty = HALF_BLOCK_PENALTY
|
|
299
|
+
else: # emb_dim >= 32
|
|
300
|
+
block_usage_penalty = QUARTER_BLOCK_PENALTY
|
|
301
|
+
|
|
302
|
+
comms_bw = bw_inter_host if world_size > local_world_size else bw_intra_host
|
|
303
|
+
fwd_comms = output_write_size / comms_bw
|
|
304
|
+
|
|
305
|
+
fwd_compute = (
|
|
306
|
+
(input_read_size + embedding_lookup_size + output_write_size)
|
|
307
|
+
* block_usage_penalty
|
|
308
|
+
/ device_bw
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
bwd_comms = fwd_comms
|
|
312
|
+
|
|
313
|
+
bwd_grad_indice_weights_kernel = (
|
|
314
|
+
fwd_compute * WEIGHTED_KERNEL_MULTIPLIER
|
|
315
|
+
if is_weighted or has_feature_processor
|
|
316
|
+
else 0
|
|
317
|
+
)
|
|
318
|
+
|
|
319
|
+
# includes fused optimizers
|
|
320
|
+
bwd_compute = fwd_compute * BWD_COMPUTE_MULTIPLIER
|
|
321
|
+
|
|
322
|
+
# in order of model parallel execution, starting with:
|
|
323
|
+
# BWD DP -> BWD MP ... FWD MP -> FWD DP
|
|
324
|
+
return (
|
|
325
|
+
bwd_comms
|
|
326
|
+
+ bwd_grad_indice_weights_kernel
|
|
327
|
+
+ bwd_compute
|
|
328
|
+
+ fwd_compute
|
|
329
|
+
+ fwd_comms
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
def _get_rw_sharding_perf(
|
|
334
|
+
batch_sizes: List[int],
|
|
335
|
+
world_size: int,
|
|
336
|
+
local_world_size: int,
|
|
337
|
+
input_lengths: List[float],
|
|
338
|
+
emb_dim: int,
|
|
339
|
+
input_data_type_size: float,
|
|
340
|
+
output_data_type_size: float,
|
|
341
|
+
num_poolings: List[float],
|
|
342
|
+
device_bw: float,
|
|
343
|
+
bw_inter_host: float,
|
|
344
|
+
bw_intra_host: float,
|
|
345
|
+
is_pooled: bool,
|
|
346
|
+
is_weighted: bool = False,
|
|
347
|
+
has_feature_processor: bool = False,
|
|
348
|
+
) -> float:
|
|
349
|
+
batch_inputs = (
|
|
350
|
+
sum([x * y * z for x, y, z in zip(input_lengths, num_poolings, batch_sizes)])
|
|
351
|
+
/ world_size
|
|
352
|
+
)
|
|
353
|
+
batch_outputs = (
|
|
354
|
+
sum([x * y for x, y in zip(num_poolings, batch_sizes)])
|
|
355
|
+
if is_pooled
|
|
356
|
+
else batch_inputs
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
input_read_size = math.ceil(batch_inputs * world_size * input_data_type_size)
|
|
360
|
+
if is_weighted or has_feature_processor:
|
|
361
|
+
input_read_size *= 2
|
|
362
|
+
|
|
363
|
+
embedding_lookup_size = batch_inputs * world_size * emb_dim * output_data_type_size
|
|
364
|
+
|
|
365
|
+
output_write_size = batch_outputs * world_size * emb_dim * output_data_type_size
|
|
366
|
+
|
|
367
|
+
comms_bw = bw_inter_host if world_size > local_world_size else bw_intra_host
|
|
368
|
+
fwd_comms = output_write_size / comms_bw
|
|
369
|
+
|
|
370
|
+
fwd_compute = (
|
|
371
|
+
input_read_size + embedding_lookup_size + output_write_size
|
|
372
|
+
) / device_bw
|
|
373
|
+
|
|
374
|
+
bwd_comms = fwd_comms
|
|
375
|
+
|
|
376
|
+
bwd_batched_copy = output_write_size * BATCHED_COPY_PERF_FACTOR / device_bw
|
|
377
|
+
|
|
378
|
+
bwd_grad_indice_weights_kernel = (
|
|
379
|
+
fwd_compute * WEIGHTED_KERNEL_MULTIPLIER
|
|
380
|
+
if is_weighted or has_feature_processor
|
|
381
|
+
else 0
|
|
382
|
+
)
|
|
383
|
+
|
|
384
|
+
bwd_compute = fwd_compute * BWD_COMPUTE_MULTIPLIER
|
|
385
|
+
|
|
386
|
+
return (
|
|
387
|
+
bwd_comms
|
|
388
|
+
+ bwd_batched_copy
|
|
389
|
+
+ bwd_grad_indice_weights_kernel
|
|
390
|
+
+ bwd_compute
|
|
391
|
+
+ fwd_compute
|
|
392
|
+
+ fwd_comms
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
def _get_twrw_sharding_perf(
|
|
397
|
+
batch_sizes: List[int],
|
|
398
|
+
world_size: int,
|
|
399
|
+
local_world_size: int,
|
|
400
|
+
input_lengths: List[float],
|
|
401
|
+
emb_dim: int,
|
|
402
|
+
input_data_type_size: float,
|
|
403
|
+
output_data_type_size: float,
|
|
404
|
+
num_poolings: List[float],
|
|
405
|
+
device_bw: float,
|
|
406
|
+
bw_inter_host: float,
|
|
407
|
+
bw_intra_host: float,
|
|
408
|
+
is_pooled: bool,
|
|
409
|
+
is_weighted: bool = False,
|
|
410
|
+
has_feature_processor: bool = False,
|
|
411
|
+
) -> float:
|
|
412
|
+
batch_inputs = (
|
|
413
|
+
sum([x * y * z for x, y, z in zip(input_lengths, num_poolings, batch_sizes)])
|
|
414
|
+
/ local_world_size
|
|
415
|
+
)
|
|
416
|
+
batch_outputs = (
|
|
417
|
+
sum([x * y for x, y in zip(num_poolings, batch_sizes)])
|
|
418
|
+
if is_pooled
|
|
419
|
+
else batch_inputs
|
|
420
|
+
)
|
|
421
|
+
|
|
422
|
+
input_read_size = math.ceil(batch_inputs * world_size * input_data_type_size)
|
|
423
|
+
if is_weighted or has_feature_processor:
|
|
424
|
+
input_read_size *= 2
|
|
425
|
+
|
|
426
|
+
embedding_lookup_size = batch_inputs * world_size * emb_dim * output_data_type_size
|
|
427
|
+
|
|
428
|
+
output_write_size = batch_outputs * world_size * emb_dim * output_data_type_size
|
|
429
|
+
|
|
430
|
+
fwd_comms = output_write_size / bw_intra_host
|
|
431
|
+
|
|
432
|
+
if world_size > local_world_size:
|
|
433
|
+
fwd_comms += output_write_size * (local_world_size / world_size) / bw_inter_host
|
|
434
|
+
|
|
435
|
+
fwd_compute = (
|
|
436
|
+
input_read_size + embedding_lookup_size + output_write_size
|
|
437
|
+
) / device_bw
|
|
438
|
+
|
|
439
|
+
bwd_comms = fwd_comms
|
|
440
|
+
|
|
441
|
+
bwd_grad_indice_weights_kernel = (
|
|
442
|
+
fwd_compute * WEIGHTED_KERNEL_MULTIPLIER
|
|
443
|
+
if is_weighted or has_feature_processor
|
|
444
|
+
else 0
|
|
445
|
+
)
|
|
446
|
+
|
|
447
|
+
bwd_batched_copy = output_write_size * BATCHED_COPY_PERF_FACTOR / device_bw
|
|
448
|
+
|
|
449
|
+
bwd_compute = fwd_compute * BWD_COMPUTE_MULTIPLIER
|
|
450
|
+
|
|
451
|
+
return (
|
|
452
|
+
bwd_comms
|
|
453
|
+
+ bwd_batched_copy
|
|
454
|
+
+ bwd_grad_indice_weights_kernel
|
|
455
|
+
+ bwd_compute
|
|
456
|
+
+ fwd_compute
|
|
457
|
+
+ fwd_comms
|
|
458
|
+
)
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
def _get_dp_sharding_perf(
|
|
462
|
+
batch_sizes: List[int],
|
|
463
|
+
world_size: int,
|
|
464
|
+
local_world_size: int,
|
|
465
|
+
input_lengths: List[float],
|
|
466
|
+
grad_num_elem: int,
|
|
467
|
+
emb_dim: int,
|
|
468
|
+
input_data_type_size: float,
|
|
469
|
+
output_data_type_size: float,
|
|
470
|
+
num_poolings: List[float],
|
|
471
|
+
device_bw: float,
|
|
472
|
+
bw_inter_host: float,
|
|
473
|
+
is_pooled: bool,
|
|
474
|
+
is_weighted: bool = False,
|
|
475
|
+
has_feature_processor: bool = False,
|
|
476
|
+
) -> float:
|
|
477
|
+
batch_inputs = sum(
|
|
478
|
+
[x * y * z for x, y, z in zip(input_lengths, num_poolings, batch_sizes)]
|
|
479
|
+
)
|
|
480
|
+
batch_outputs = (
|
|
481
|
+
sum([x * y for x, y in zip(num_poolings, batch_sizes)])
|
|
482
|
+
if is_pooled
|
|
483
|
+
else batch_inputs
|
|
484
|
+
)
|
|
485
|
+
|
|
486
|
+
input_read_size = math.ceil(batch_inputs * input_data_type_size)
|
|
487
|
+
if is_weighted or has_feature_processor:
|
|
488
|
+
input_read_size *= 2
|
|
489
|
+
|
|
490
|
+
embedding_lookup_size = batch_inputs * emb_dim * output_data_type_size
|
|
491
|
+
|
|
492
|
+
output_write_size = batch_outputs * emb_dim * output_data_type_size
|
|
493
|
+
table_size = grad_num_elem * output_data_type_size
|
|
494
|
+
|
|
495
|
+
fwd_compute = (
|
|
496
|
+
input_read_size + embedding_lookup_size + output_write_size
|
|
497
|
+
) / device_bw
|
|
498
|
+
|
|
499
|
+
num_nodes = min(world_size / local_world_size, 2)
|
|
500
|
+
|
|
501
|
+
# all-reduce data transfer: https://images.nvidia.com/events/sc15/pdfs/NCCL-Woolley.pdf
|
|
502
|
+
all_reduce = (
|
|
503
|
+
table_size
|
|
504
|
+
* (2 * num_nodes - 1)
|
|
505
|
+
/ num_nodes
|
|
506
|
+
/ (bw_inter_host * local_world_size) # 1 NIC per GPU
|
|
507
|
+
)
|
|
508
|
+
# inter host communication constraint
|
|
509
|
+
if world_size > 2 * local_world_size:
|
|
510
|
+
all_reduce *= 2
|
|
511
|
+
|
|
512
|
+
# SGD + Fill + BUnary
|
|
513
|
+
optimizer_kernels = table_size * DP_ELEMENTWISE_KERNELS_PERF_FACTOR / device_bw
|
|
514
|
+
|
|
515
|
+
bwd_compute = fwd_compute * BWD_COMPUTE_MULTIPLIER
|
|
516
|
+
|
|
517
|
+
bwd_grad_indice_weights_kernel = (
|
|
518
|
+
fwd_compute * WEIGHTED_KERNEL_MULTIPLIER
|
|
519
|
+
if is_weighted or has_feature_processor
|
|
520
|
+
else 0
|
|
521
|
+
)
|
|
522
|
+
|
|
523
|
+
return (
|
|
524
|
+
all_reduce
|
|
525
|
+
+ optimizer_kernels
|
|
526
|
+
+ bwd_grad_indice_weights_kernel
|
|
527
|
+
+ bwd_compute
|
|
528
|
+
+ fwd_compute
|
|
529
|
+
)
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
class EmbeddingStorageEstimator(ShardEstimator):
|
|
533
|
+
"""
|
|
534
|
+
Embedding Storage Usage Estimator
|
|
535
|
+
"""
|
|
536
|
+
|
|
537
|
+
def __init__(
|
|
538
|
+
self,
|
|
539
|
+
topology: Topology,
|
|
540
|
+
constraints: Optional[Dict[str, ParameterConstraints]] = None,
|
|
541
|
+
) -> None:
|
|
542
|
+
self._topology = topology
|
|
543
|
+
self._constraints = constraints
|
|
544
|
+
|
|
545
|
+
def estimate(
|
|
546
|
+
self,
|
|
547
|
+
sharding_options: List[ShardingOption],
|
|
548
|
+
sharder_map: Optional[Dict[str, ModuleSharder[nn.Module]]] = None,
|
|
549
|
+
) -> None:
|
|
550
|
+
if not sharder_map:
|
|
551
|
+
raise ValueError("sharder map not provided for storage estimator")
|
|
552
|
+
|
|
553
|
+
for sharding_option in sharding_options:
|
|
554
|
+
sharder_key = sharder_name(type(sharding_option.module[1]))
|
|
555
|
+
sharder = sharder_map[sharder_key]
|
|
556
|
+
caching_ratio = (
|
|
557
|
+
self._constraints[sharding_option.name].caching_ratio
|
|
558
|
+
if self._constraints and self._constraints.get(sharding_option.name)
|
|
559
|
+
else None
|
|
560
|
+
)
|
|
561
|
+
num_poolings = (
|
|
562
|
+
cast(List[float], self._constraints[sharding_option.name].num_poolings)
|
|
563
|
+
if self._constraints
|
|
564
|
+
and self._constraints.get(sharding_option.name)
|
|
565
|
+
and self._constraints[sharding_option.name].num_poolings
|
|
566
|
+
else [1.0] * sharding_option.num_inputs
|
|
567
|
+
)
|
|
568
|
+
assert len(num_poolings) == sharding_option.num_inputs
|
|
569
|
+
batch_sizes = (
|
|
570
|
+
cast(List[int], self._constraints[sharding_option.name].batch_sizes)
|
|
571
|
+
if self._constraints
|
|
572
|
+
and self._constraints.get(sharding_option.name)
|
|
573
|
+
and self._constraints[sharding_option.name].batch_sizes
|
|
574
|
+
else [sharding_option.batch_size] * sharding_option.num_inputs
|
|
575
|
+
)
|
|
576
|
+
|
|
577
|
+
shard_storages = calculate_shard_storages(
|
|
578
|
+
sharder=sharder,
|
|
579
|
+
sharding_type=sharding_option.sharding_type,
|
|
580
|
+
tensor=sharding_option.tensor,
|
|
581
|
+
compute_device=self._topology.compute_device,
|
|
582
|
+
compute_kernel=sharding_option.compute_kernel,
|
|
583
|
+
shard_sizes=[shard.size for shard in sharding_option.shards],
|
|
584
|
+
batch_sizes=batch_sizes,
|
|
585
|
+
world_size=self._topology.world_size,
|
|
586
|
+
local_world_size=self._topology.local_world_size,
|
|
587
|
+
input_lengths=sharding_option.input_lengths,
|
|
588
|
+
num_poolings=num_poolings,
|
|
589
|
+
caching_ratio=caching_ratio if caching_ratio else UVM_CACHING_RATIO,
|
|
590
|
+
is_pooled=sharding_option.is_pooled,
|
|
591
|
+
)
|
|
592
|
+
|
|
593
|
+
for shard, storage in zip(sharding_option.shards, shard_storages):
|
|
594
|
+
shard.storage = storage
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
def calculate_shard_storages(
|
|
598
|
+
sharder: ModuleSharder[nn.Module],
|
|
599
|
+
sharding_type: str,
|
|
600
|
+
tensor: torch.Tensor,
|
|
601
|
+
compute_device: str,
|
|
602
|
+
compute_kernel: str,
|
|
603
|
+
shard_sizes: List[List[int]],
|
|
604
|
+
batch_sizes: List[int],
|
|
605
|
+
world_size: int,
|
|
606
|
+
local_world_size: int,
|
|
607
|
+
input_lengths: List[float],
|
|
608
|
+
num_poolings: List[float],
|
|
609
|
+
caching_ratio: float,
|
|
610
|
+
is_pooled: bool,
|
|
611
|
+
) -> List[Storage]:
|
|
612
|
+
"""
|
|
613
|
+
Calculates estimated storage sizes for each sharded tensor, comprised of input,
|
|
614
|
+
output, tensor, gradient, and optimizer sizes.
|
|
615
|
+
|
|
616
|
+
Args:
|
|
617
|
+
sharder (ModuleSharder[nn.Module]): sharder for module that supports sharding.
|
|
618
|
+
sharding_type (str): provided ShardingType value.
|
|
619
|
+
tensor (torch.Tensor): tensor to be sharded.
|
|
620
|
+
compute_device (str): compute device to be used.
|
|
621
|
+
compute_kernel (str): compute kernel to be used.
|
|
622
|
+
shard_sizes (List[List[int]]): list of dimensions of each sharded tensor.
|
|
623
|
+
batch_sizes (List[int]): batch size for each input feature.
|
|
624
|
+
world_size (int): total number of devices in topology.
|
|
625
|
+
local_world_size (int): total number of devices in host group topology.
|
|
626
|
+
input_lengths (List[float]): average input lengths synonymous with pooling
|
|
627
|
+
factors.
|
|
628
|
+
num_poolings (List[float]): average number of poolings per sample
|
|
629
|
+
(typically 1.0).
|
|
630
|
+
caching_ratio (float): ratio of HBM to DDR memory for UVM caching.
|
|
631
|
+
is_pooled (bool): True if embedding output is pooled (ie. EmbeddingBag), False
|
|
632
|
+
if unpooled/sequential (ie. Embedding).
|
|
633
|
+
|
|
634
|
+
Returns:
|
|
635
|
+
List[Storage]: storage object for each device in topology.
|
|
636
|
+
"""
|
|
637
|
+
|
|
638
|
+
input_data_type_size = BIGINT_DTYPE
|
|
639
|
+
output_data_type_size = tensor.element_size()
|
|
640
|
+
|
|
641
|
+
input_sizes, output_sizes = _calculate_shard_io_sizes(
|
|
642
|
+
sharding_type=sharding_type,
|
|
643
|
+
batch_sizes=batch_sizes,
|
|
644
|
+
world_size=world_size,
|
|
645
|
+
local_world_size=local_world_size,
|
|
646
|
+
input_lengths=input_lengths,
|
|
647
|
+
emb_dim=tensor.shape[1],
|
|
648
|
+
shard_sizes=shard_sizes,
|
|
649
|
+
input_data_type_size=input_data_type_size,
|
|
650
|
+
output_data_type_size=output_data_type_size,
|
|
651
|
+
num_poolings=num_poolings,
|
|
652
|
+
is_pooled=is_pooled,
|
|
653
|
+
)
|
|
654
|
+
|
|
655
|
+
tensor_storage = sharder.storage_usage(tensor, compute_device, compute_kernel)
|
|
656
|
+
hbm_storage: int = tensor_storage.get("hbm", 0)
|
|
657
|
+
ddr_storage: int = tensor_storage.get("ddr", 0)
|
|
658
|
+
|
|
659
|
+
if compute_kernel in {
|
|
660
|
+
EmbeddingComputeKernel.FUSED_UVM_CACHING.value,
|
|
661
|
+
EmbeddingComputeKernel.QUANT_UVM_CACHING.value,
|
|
662
|
+
}:
|
|
663
|
+
hbm_storage = round(ddr_storage * caching_ratio)
|
|
664
|
+
|
|
665
|
+
hbm_specific_sizes: List[int] = _calculate_storage_specific_sizes(
|
|
666
|
+
storage=hbm_storage,
|
|
667
|
+
shape=tensor.shape,
|
|
668
|
+
shard_sizes=shard_sizes,
|
|
669
|
+
sharding_type=sharding_type,
|
|
670
|
+
compute_kernel=compute_kernel,
|
|
671
|
+
)
|
|
672
|
+
ddr_specific_sizes: List[int] = _calculate_storage_specific_sizes(
|
|
673
|
+
storage=ddr_storage,
|
|
674
|
+
shape=tensor.shape,
|
|
675
|
+
shard_sizes=shard_sizes,
|
|
676
|
+
sharding_type=sharding_type,
|
|
677
|
+
compute_kernel=compute_kernel,
|
|
678
|
+
)
|
|
679
|
+
|
|
680
|
+
hbm_sizes: List[int] = [
|
|
681
|
+
input_size + output_size + hbm_specific_size if compute_device == "cuda" else 0
|
|
682
|
+
for input_size, output_size, hbm_specific_size in zip(
|
|
683
|
+
input_sizes,
|
|
684
|
+
output_sizes,
|
|
685
|
+
hbm_specific_sizes,
|
|
686
|
+
)
|
|
687
|
+
]
|
|
688
|
+
ddr_sizes: List[int] = [
|
|
689
|
+
input_size + output_size + ddr_specific_size
|
|
690
|
+
if compute_device == "cpu"
|
|
691
|
+
else ddr_specific_size
|
|
692
|
+
for input_size, output_size, ddr_specific_size in zip(
|
|
693
|
+
input_sizes,
|
|
694
|
+
output_sizes,
|
|
695
|
+
ddr_specific_sizes,
|
|
696
|
+
)
|
|
697
|
+
]
|
|
698
|
+
|
|
699
|
+
return [
|
|
700
|
+
Storage(
|
|
701
|
+
hbm=hbm_size,
|
|
702
|
+
ddr=ddr_size,
|
|
703
|
+
)
|
|
704
|
+
for hbm_size, ddr_size in zip(hbm_sizes, ddr_sizes)
|
|
705
|
+
]
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
def _calculate_shard_io_sizes(
|
|
709
|
+
sharding_type: str,
|
|
710
|
+
batch_sizes: List[int],
|
|
711
|
+
world_size: int,
|
|
712
|
+
local_world_size: int,
|
|
713
|
+
input_lengths: List[float],
|
|
714
|
+
emb_dim: int,
|
|
715
|
+
shard_sizes: List[List[int]],
|
|
716
|
+
input_data_type_size: int,
|
|
717
|
+
output_data_type_size: int,
|
|
718
|
+
num_poolings: List[float],
|
|
719
|
+
is_pooled: bool,
|
|
720
|
+
) -> Tuple[List[int], List[int]]:
|
|
721
|
+
if sharding_type == ShardingType.DATA_PARALLEL.value:
|
|
722
|
+
return _calculate_dp_shard_io_sizes(
|
|
723
|
+
batch_sizes=batch_sizes,
|
|
724
|
+
input_lengths=input_lengths,
|
|
725
|
+
emb_dim=emb_dim,
|
|
726
|
+
num_shards=len(shard_sizes),
|
|
727
|
+
input_data_type_size=input_data_type_size,
|
|
728
|
+
output_data_type_size=output_data_type_size,
|
|
729
|
+
num_poolings=num_poolings,
|
|
730
|
+
is_pooled=is_pooled,
|
|
731
|
+
)
|
|
732
|
+
elif sharding_type == ShardingType.TABLE_WISE.value:
|
|
733
|
+
return _calculate_tw_shard_io_sizes(
|
|
734
|
+
batch_sizes=batch_sizes,
|
|
735
|
+
world_size=world_size,
|
|
736
|
+
input_lengths=input_lengths,
|
|
737
|
+
emb_dim=emb_dim,
|
|
738
|
+
input_data_type_size=input_data_type_size,
|
|
739
|
+
output_data_type_size=output_data_type_size,
|
|
740
|
+
num_poolings=num_poolings,
|
|
741
|
+
is_pooled=is_pooled,
|
|
742
|
+
)
|
|
743
|
+
elif sharding_type in {
|
|
744
|
+
ShardingType.COLUMN_WISE.value,
|
|
745
|
+
ShardingType.TABLE_COLUMN_WISE.value,
|
|
746
|
+
}:
|
|
747
|
+
return _calculate_cw_shard_io_sizes(
|
|
748
|
+
batch_sizes=batch_sizes,
|
|
749
|
+
world_size=world_size,
|
|
750
|
+
input_lengths=input_lengths,
|
|
751
|
+
shard_sizes=shard_sizes,
|
|
752
|
+
input_data_type_size=input_data_type_size,
|
|
753
|
+
output_data_type_size=output_data_type_size,
|
|
754
|
+
num_poolings=num_poolings,
|
|
755
|
+
is_pooled=is_pooled,
|
|
756
|
+
)
|
|
757
|
+
elif sharding_type == ShardingType.ROW_WISE.value:
|
|
758
|
+
return _calculate_rw_shard_io_sizes(
|
|
759
|
+
batch_sizes=batch_sizes,
|
|
760
|
+
world_size=world_size,
|
|
761
|
+
input_lengths=input_lengths,
|
|
762
|
+
shard_sizes=shard_sizes,
|
|
763
|
+
input_data_type_size=input_data_type_size,
|
|
764
|
+
output_data_type_size=output_data_type_size,
|
|
765
|
+
num_poolings=num_poolings,
|
|
766
|
+
is_pooled=is_pooled,
|
|
767
|
+
)
|
|
768
|
+
elif sharding_type == ShardingType.TABLE_ROW_WISE.value:
|
|
769
|
+
return _calculate_twrw_shard_io_sizes(
|
|
770
|
+
batch_sizes=batch_sizes,
|
|
771
|
+
world_size=world_size,
|
|
772
|
+
local_world_size=local_world_size,
|
|
773
|
+
input_lengths=input_lengths,
|
|
774
|
+
shard_sizes=shard_sizes,
|
|
775
|
+
input_data_type_size=input_data_type_size,
|
|
776
|
+
output_data_type_size=output_data_type_size,
|
|
777
|
+
num_poolings=num_poolings,
|
|
778
|
+
is_pooled=is_pooled,
|
|
779
|
+
)
|
|
780
|
+
else:
|
|
781
|
+
raise ValueError(
|
|
782
|
+
f"Unrecognized or unsupported sharding type provided: {sharding_type}"
|
|
783
|
+
)
|
|
784
|
+
|
|
785
|
+
|
|
786
|
+
def _calculate_dp_shard_io_sizes(
|
|
787
|
+
batch_sizes: List[int],
|
|
788
|
+
input_lengths: List[float],
|
|
789
|
+
emb_dim: int,
|
|
790
|
+
num_shards: int,
|
|
791
|
+
input_data_type_size: int,
|
|
792
|
+
output_data_type_size: int,
|
|
793
|
+
num_poolings: List[float],
|
|
794
|
+
is_pooled: bool,
|
|
795
|
+
) -> Tuple[List[int], List[int]]:
|
|
796
|
+
batch_inputs = sum(
|
|
797
|
+
[x * y * z for x, y, z in zip(input_lengths, num_poolings, batch_sizes)]
|
|
798
|
+
)
|
|
799
|
+
batch_outputs = (
|
|
800
|
+
sum([x * y for x, y in zip(num_poolings, batch_sizes)])
|
|
801
|
+
if is_pooled
|
|
802
|
+
else batch_inputs
|
|
803
|
+
)
|
|
804
|
+
|
|
805
|
+
input_sizes = [math.ceil(batch_inputs * input_data_type_size)] * num_shards
|
|
806
|
+
output_sizes = [
|
|
807
|
+
math.ceil(batch_outputs * emb_dim * output_data_type_size)
|
|
808
|
+
] * num_shards
|
|
809
|
+
|
|
810
|
+
return input_sizes, output_sizes
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
def _calculate_tw_shard_io_sizes(
|
|
814
|
+
batch_sizes: List[int],
|
|
815
|
+
world_size: int,
|
|
816
|
+
input_lengths: List[float],
|
|
817
|
+
emb_dim: int,
|
|
818
|
+
input_data_type_size: int,
|
|
819
|
+
output_data_type_size: int,
|
|
820
|
+
num_poolings: List[float],
|
|
821
|
+
is_pooled: bool,
|
|
822
|
+
) -> Tuple[List[int], List[int]]:
|
|
823
|
+
batch_inputs = sum(
|
|
824
|
+
[x * y * z for x, y, z in zip(input_lengths, num_poolings, batch_sizes)]
|
|
825
|
+
)
|
|
826
|
+
batch_outputs = (
|
|
827
|
+
sum([x * y for x, y in zip(num_poolings, batch_sizes)])
|
|
828
|
+
if is_pooled
|
|
829
|
+
else batch_inputs
|
|
830
|
+
)
|
|
831
|
+
|
|
832
|
+
input_sizes = [math.ceil(batch_inputs * world_size * input_data_type_size)]
|
|
833
|
+
output_sizes = [
|
|
834
|
+
math.ceil(batch_outputs * world_size * emb_dim * output_data_type_size)
|
|
835
|
+
]
|
|
836
|
+
|
|
837
|
+
return input_sizes, output_sizes
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
def _calculate_cw_shard_io_sizes(
|
|
841
|
+
batch_sizes: List[int],
|
|
842
|
+
world_size: int,
|
|
843
|
+
input_lengths: List[float],
|
|
844
|
+
shard_sizes: List[List[int]],
|
|
845
|
+
input_data_type_size: int,
|
|
846
|
+
output_data_type_size: int,
|
|
847
|
+
num_poolings: List[float],
|
|
848
|
+
is_pooled: bool,
|
|
849
|
+
) -> Tuple[List[int], List[int]]:
|
|
850
|
+
batch_inputs = sum(
|
|
851
|
+
[x * y * z for x, y, z in zip(input_lengths, num_poolings, batch_sizes)]
|
|
852
|
+
)
|
|
853
|
+
batch_outputs = (
|
|
854
|
+
sum([x * y for x, y in zip(num_poolings, batch_sizes)])
|
|
855
|
+
if is_pooled
|
|
856
|
+
else batch_inputs
|
|
857
|
+
)
|
|
858
|
+
|
|
859
|
+
input_sizes = [math.ceil(batch_inputs * world_size * input_data_type_size)] * len(
|
|
860
|
+
shard_sizes
|
|
861
|
+
)
|
|
862
|
+
output_sizes = [
|
|
863
|
+
math.ceil(
|
|
864
|
+
batch_outputs * world_size * shard_sizes[i][1] * output_data_type_size
|
|
865
|
+
)
|
|
866
|
+
for i in range(len(shard_sizes))
|
|
867
|
+
]
|
|
868
|
+
|
|
869
|
+
return input_sizes, output_sizes
|
|
870
|
+
|
|
871
|
+
|
|
872
|
+
def _calculate_rw_shard_io_sizes(
|
|
873
|
+
batch_sizes: List[int],
|
|
874
|
+
world_size: int,
|
|
875
|
+
input_lengths: List[float],
|
|
876
|
+
shard_sizes: List[List[int]],
|
|
877
|
+
input_data_type_size: int,
|
|
878
|
+
output_data_type_size: int,
|
|
879
|
+
num_poolings: List[float],
|
|
880
|
+
is_pooled: bool,
|
|
881
|
+
) -> Tuple[List[int], List[int]]:
|
|
882
|
+
batch_inputs = (
|
|
883
|
+
sum([x * y * z for x, y, z in zip(input_lengths, num_poolings, batch_sizes)])
|
|
884
|
+
/ world_size
|
|
885
|
+
)
|
|
886
|
+
batch_outputs = (
|
|
887
|
+
sum([x * y for x, y in zip(num_poolings, batch_sizes)])
|
|
888
|
+
if is_pooled
|
|
889
|
+
else batch_inputs
|
|
890
|
+
)
|
|
891
|
+
|
|
892
|
+
input_sizes = [
|
|
893
|
+
math.ceil(batch_inputs * world_size * input_data_type_size)
|
|
894
|
+
if prod(shard) != 0
|
|
895
|
+
else 0
|
|
896
|
+
for shard in shard_sizes
|
|
897
|
+
]
|
|
898
|
+
output_sizes = [
|
|
899
|
+
math.ceil(
|
|
900
|
+
batch_outputs * world_size * shard_sizes[i][1] * output_data_type_size
|
|
901
|
+
)
|
|
902
|
+
if prod(shard) != 0
|
|
903
|
+
else 0
|
|
904
|
+
for i, shard in enumerate(shard_sizes)
|
|
905
|
+
]
|
|
906
|
+
|
|
907
|
+
return input_sizes, output_sizes
|
|
908
|
+
|
|
909
|
+
|
|
910
|
+
def _calculate_twrw_shard_io_sizes(
|
|
911
|
+
batch_sizes: List[int],
|
|
912
|
+
world_size: int,
|
|
913
|
+
local_world_size: int,
|
|
914
|
+
input_lengths: List[float],
|
|
915
|
+
shard_sizes: List[List[int]],
|
|
916
|
+
input_data_type_size: int,
|
|
917
|
+
output_data_type_size: int,
|
|
918
|
+
num_poolings: List[float],
|
|
919
|
+
is_pooled: bool,
|
|
920
|
+
) -> Tuple[List[int], List[int]]:
|
|
921
|
+
batch_inputs = (
|
|
922
|
+
sum([x * y * z for x, y, z in zip(input_lengths, num_poolings, batch_sizes)])
|
|
923
|
+
/ local_world_size
|
|
924
|
+
)
|
|
925
|
+
batch_outputs = (
|
|
926
|
+
sum([x * y for x, y in zip(num_poolings, batch_sizes)])
|
|
927
|
+
if is_pooled
|
|
928
|
+
else batch_inputs
|
|
929
|
+
)
|
|
930
|
+
|
|
931
|
+
input_sizes = [
|
|
932
|
+
math.ceil(batch_inputs * world_size * input_data_type_size)
|
|
933
|
+
if prod(shard) != 0
|
|
934
|
+
else 0
|
|
935
|
+
for shard in shard_sizes
|
|
936
|
+
]
|
|
937
|
+
output_sizes = [
|
|
938
|
+
math.ceil(
|
|
939
|
+
batch_outputs * world_size * shard_sizes[i][1] * output_data_type_size
|
|
940
|
+
)
|
|
941
|
+
if prod(shard) != 0
|
|
942
|
+
else 0
|
|
943
|
+
for i, shard in enumerate(shard_sizes)
|
|
944
|
+
]
|
|
945
|
+
|
|
946
|
+
return input_sizes, output_sizes
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
def _calculate_storage_specific_sizes(
|
|
950
|
+
storage: int,
|
|
951
|
+
shape: torch.Size,
|
|
952
|
+
shard_sizes: List[List[int]],
|
|
953
|
+
sharding_type: str,
|
|
954
|
+
compute_kernel: str,
|
|
955
|
+
) -> List[int]:
|
|
956
|
+
tensor_sizes: List[int] = [
|
|
957
|
+
math.ceil(storage * prod(size) / prod(shape))
|
|
958
|
+
if sharding_type != ShardingType.DATA_PARALLEL.value
|
|
959
|
+
else storage
|
|
960
|
+
for size in shard_sizes
|
|
961
|
+
]
|
|
962
|
+
|
|
963
|
+
optimizer_sizes: List[int] = [
|
|
964
|
+
tensor_size * 2 if compute_kernel == EmbeddingComputeKernel.DENSE.value else 0
|
|
965
|
+
for tensor_size in tensor_sizes
|
|
966
|
+
]
|
|
967
|
+
|
|
968
|
+
return [
|
|
969
|
+
tensor_size + optimizer_size
|
|
970
|
+
for tensor_size, optimizer_size in zip(tensor_sizes, optimizer_sizes)
|
|
971
|
+
]
|