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,71 @@
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
+ This file contains utilities for constructing collective based control flows.
10
+ """
11
+
12
+ from functools import wraps
13
+ from typing import Any, Callable, cast, Optional, TypeVar
14
+
15
+ import torch.distributed as dist
16
+
17
+
18
+ def is_leader(pg: Optional[dist.ProcessGroup], leader_rank: int = 0) -> bool:
19
+ """
20
+ Checks if the current processs is the leader.
21
+
22
+ Args:
23
+ pg (Optional[dist.ProcessGroup]): the process's rank within the pg is used to
24
+ determine if the process is the leader. pg being None implies that the
25
+ process is the only member in the group (e.g. a single process program).
26
+ leader_rank (int): the definition of leader (defaults to 0). The caller can
27
+ override it with a context-specific definition.
28
+ """
29
+ if pg is None:
30
+ return leader_rank == 0
31
+ return pg.rank() == leader_rank
32
+
33
+
34
+ T = TypeVar("T")
35
+
36
+
37
+ def invoke_on_rank_and_broadcast_result(
38
+ pg: dist.ProcessGroup,
39
+ rank: int,
40
+ func: Callable[..., T],
41
+ *args: Any,
42
+ **kwargs: Any,
43
+ ) -> T:
44
+ """
45
+ Invokes a function on the designated rank and broadcasts the result to all
46
+ members within the group.
47
+
48
+ Example::
49
+
50
+ id = invoke_on_rank_and_broadcast_result(pg, 0, allocate_id)
51
+ """
52
+ if pg.rank() == rank:
53
+ res = func(*args, **kwargs)
54
+ object_list = [res]
55
+ else:
56
+ object_list = [None]
57
+ if pg.size() > 1:
58
+ dist.broadcast_object_list(object_list, rank, group=pg)
59
+ return cast(T, object_list[0])
60
+
61
+
62
+ # pyre-ignore Missing return annotation [3]
63
+ def run_on_leader(pg: dist.ProcessGroup, rank: int):
64
+ def callable(func: Callable[..., T]) -> T:
65
+ @wraps(func)
66
+ def wrapped(*args: Any, **kwargs: Any) -> T:
67
+ return invoke_on_rank_and_broadcast_result(pg, rank, func, *args, **kwargs)
68
+
69
+ return wrapped
70
+
71
+ return callable
@@ -0,0 +1,149 @@
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 logging
9
+ import os
10
+ from typing import List, Optional, Tuple
11
+
12
+ import torch
13
+ import torch.distributed as dist
14
+
15
+ logger: logging.Logger = logging.getLogger(__name__)
16
+
17
+ # Global, only should be accessed via intra_and_cross_node_pg()
18
+ _INTRA_PG: Optional[dist.ProcessGroup] = None
19
+ _CROSS_PG: Optional[dist.ProcessGroup] = None
20
+
21
+
22
+ def _env2int(env_list: List[str], default: int = -1) -> int:
23
+ for e in env_list:
24
+ val = int(os.environ.get(e, -1))
25
+ if val >= 0:
26
+ return val
27
+ return default
28
+
29
+
30
+ def get_local_size(world_size: Optional[int] = None) -> int:
31
+ if world_size is None:
32
+ world_size = dist.get_world_size()
33
+ """
34
+ Gets the local world size (see https://pytorch.org/docs/stable/elastic/run.html)
35
+ This is usually the size of workers on each node, or nproc_per_node
36
+ """
37
+ local_size = _env2int(
38
+ [
39
+ "LOCAL_WORLD_SIZE",
40
+ "MPI_LOCALNRANKS",
41
+ "OMPI_COMM_WORLD_LOCAL_SIZE",
42
+ "MV2_COMM_WORLD_LOCAL_SIZE",
43
+ ],
44
+ 8,
45
+ )
46
+
47
+ if local_size == -1 or world_size % local_size != 0:
48
+ logging.warning(
49
+ "Could not determine LOCAL_WORLD_SIZE from environment, falling back to WORLD_SIZE."
50
+ )
51
+ local_size = world_size
52
+ return local_size
53
+
54
+
55
+ def get_local_rank(world_size: Optional[int] = None, rank: Optional[int] = None) -> int:
56
+ """
57
+ Gets the local rank of the local processes (see https://pytorch.org/docs/stable/elastic/run.html)
58
+ This is usually the rank of the worker on its node
59
+ """
60
+ my_local_rank = _env2int(
61
+ [
62
+ "LOCAL_RANK",
63
+ "MPI_LOCALRANKID",
64
+ "OMPI_COMM_WORLD_LOCAL_RANK",
65
+ "MV2_COMM_WORLD_LOCAL_RANK",
66
+ ],
67
+ -1,
68
+ )
69
+ local_size = get_local_size(world_size)
70
+
71
+ if my_local_rank == -1 or my_local_rank >= local_size:
72
+ logging.warning(
73
+ "Could not determine LOCAL_RANK from environment, falling back to GLOBAL_RANK % LOCAL_SIZE."
74
+ )
75
+ if rank is None:
76
+ rank = dist.get_rank()
77
+ my_local_rank = rank % local_size
78
+ return my_local_rank
79
+
80
+
81
+ def get_group_rank(world_size: Optional[int] = None, rank: Optional[int] = None) -> int:
82
+ """
83
+ Gets the group rank of the worker group. Also available with GROUP_RANK environment varible
84
+ A number between 0 and get_num_groups() (See https://pytorch.org/docs/stable/elastic/run.html)
85
+ """
86
+ if rank is None:
87
+ rank = dist.get_rank()
88
+ return rank // get_local_size(world_size)
89
+
90
+
91
+ def get_num_groups(world_size: Optional[int] = None) -> int:
92
+ """
93
+ Gets the number of worker groups.
94
+ Usually equivalent to max_nnodes (See https://pytorch.org/docs/stable/elastic/run.html)
95
+ """
96
+ if world_size is None:
97
+ world_size = dist.get_world_size()
98
+ return world_size // get_local_size(world_size)
99
+
100
+
101
+ def intra_and_cross_node_pg(
102
+ device: Optional[torch.device] = None,
103
+ backend: str = "nccl",
104
+ ) -> Tuple[Optional[dist.ProcessGroup], Optional[dist.ProcessGroup]]:
105
+ """
106
+ Creates sub process groups (intra and cross node)
107
+ """
108
+ if device is not None and device.type == "meta":
109
+ return None, None
110
+
111
+ global _INTRA_PG # intra node process group
112
+ global _CROSS_PG # cross node process group
113
+
114
+ my_size = dist.get_world_size()
115
+ my_rank = dist.get_rank()
116
+ my_local_rank = get_local_rank(my_size, my_rank)
117
+ local_size = get_local_size(my_size)
118
+ my_group_rank = get_group_rank(my_size, my_rank)
119
+ group_count = get_num_groups(my_size)
120
+
121
+ logger.info(
122
+ f"[{my_rank}] my_local_rank = {my_local_rank}, local_size = {local_size},"
123
+ f"my_group_rank = {my_group_rank}, group_count = {group_count}"
124
+ )
125
+ if _INTRA_PG is None:
126
+ for group_rank in range(group_count):
127
+ peers = [group_rank * local_size + r for r in range(local_size)]
128
+ curr_intra_group_pg = dist.new_group(backend=backend, ranks=peers)
129
+ if my_group_rank == group_rank:
130
+ logger.warning(
131
+ "[Connection] intra_group: [%d] -> [%s]" % (my_rank, peers)
132
+ )
133
+ _INTRA_PG = curr_intra_group_pg
134
+
135
+ dist.barrier()
136
+
137
+ if _CROSS_PG is None:
138
+ for l_rank in range(local_size):
139
+ peers = [l_rank + g * local_size for g in range(group_count)]
140
+ curr_cross_group_pg = dist.new_group(backend=backend, ranks=peers)
141
+ if l_rank == my_local_rank:
142
+ logger.warning(
143
+ "[Connection] cross_group: [%d] -> [%s]" % (my_rank, peers)
144
+ )
145
+ _CROSS_PG = curr_cross_group_pg
146
+
147
+ dist.barrier()
148
+
149
+ return _INTRA_PG, _CROSS_PG