torchrec 0.2.0.dev0__37-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- examples/__init__.py +0 -0
- examples/datasets/__init__.py +8 -0
- examples/datasets/criteo_dataframes.py +101 -0
- examples/ray/__init__.py +0 -0
- examples/ray/compute_world_size.py +51 -0
- examples/ray/train_torchrec.py +133 -0
- examples/retrieval/__init__.py +6 -0
- examples/retrieval/data/__init__.py +6 -0
- examples/retrieval/data/dataloader.py +44 -0
- examples/retrieval/knn_index.py +67 -0
- examples/retrieval/modules/__init__.py +6 -0
- examples/retrieval/modules/two_tower.py +229 -0
- examples/retrieval/two_tower_retrieval.py +192 -0
- examples/retrieval/two_tower_train.py +253 -0
- examples/torcharrow/__init__.py +8 -0
- examples/torcharrow/dataloader.py +116 -0
- examples/torcharrow/run.py +126 -0
- fbgemm_gpu/__init__.py +16 -0
- fbgemm_gpu/batched_unary_embeddings_ops.py +82 -0
- fbgemm_gpu/enums.py +21 -0
- fbgemm_gpu/fbgemm_gpu_py.so +0 -0
- fbgemm_gpu/permute_pooled_embedding_modules.py +73 -0
- fbgemm_gpu/permute_pooled_embedding_modules_split.py +76 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/__init__.py +19 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_adagrad.py +120 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_adam.py +149 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_approx_rowwise_adagrad.py +128 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_approx_rowwise_adagrad_with_counter.py +134 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_approx_rowwise_adagrad_with_weight_decay.py +128 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_approx_sgd.py +105 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_args.py +54 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_lamb.py +149 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_lars_sgd.py +128 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_partial_rowwise_adam.py +149 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_partial_rowwise_lamb.py +149 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_rowwise_adagrad.py +128 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_rowwise_adagrad_with_counter.py +134 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_rowwise_adagrad_with_weight_decay.py +128 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_rowwise_weighted_adagrad.py +130 -0
- fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_sgd.py +105 -0
- fbgemm_gpu/split_embedding_configs.py +182 -0
- fbgemm_gpu/split_embedding_inference_converter.py +208 -0
- fbgemm_gpu/split_table_batched_embeddings_ops.py +2503 -0
- fbgemm_gpu/uvm.py +35 -0
- torchrec/__init__.py +27 -0
- torchrec/datasets/__init__.py +31 -0
- torchrec/datasets/criteo.py +831 -0
- torchrec/datasets/movielens.py +140 -0
- torchrec/datasets/random.py +188 -0
- torchrec/datasets/scripts/__init__.py +0 -0
- torchrec/datasets/scripts/contiguous_preproc_criteo.py +75 -0
- torchrec/datasets/scripts/npy_preproc_criteo.py +73 -0
- torchrec/datasets/test_utils/__init__.py +0 -0
- torchrec/datasets/test_utils/criteo_test_utils.py +139 -0
- torchrec/datasets/utils.py +341 -0
- torchrec/distributed/__init__.py +55 -0
- torchrec/distributed/batched_embedding_kernel.py +697 -0
- torchrec/distributed/collective_utils.py +71 -0
- torchrec/distributed/comm.py +149 -0
- torchrec/distributed/comm_ops.py +930 -0
- torchrec/distributed/dist_data.py +949 -0
- torchrec/distributed/embedding.py +638 -0
- torchrec/distributed/embedding_kernel.py +326 -0
- torchrec/distributed/embedding_lookup.py +760 -0
- torchrec/distributed/embedding_sharding.py +660 -0
- torchrec/distributed/embedding_tower_sharding.py +992 -0
- torchrec/distributed/embedding_types.py +369 -0
- torchrec/distributed/embeddingbag.py +731 -0
- torchrec/distributed/fused_embeddingbag.py +148 -0
- torchrec/distributed/grouped_position_weighted.py +103 -0
- torchrec/distributed/model_parallel.py +555 -0
- torchrec/distributed/planner/__init__.py +24 -0
- torchrec/distributed/planner/constants.py +77 -0
- torchrec/distributed/planner/enumerators.py +353 -0
- torchrec/distributed/planner/parallelized_planners.py +307 -0
- torchrec/distributed/planner/partitioners.py +280 -0
- torchrec/distributed/planner/perf_models.py +24 -0
- torchrec/distributed/planner/planners.py +290 -0
- torchrec/distributed/planner/proposers.py +270 -0
- torchrec/distributed/planner/shard_estimators.py +971 -0
- torchrec/distributed/planner/stats.py +477 -0
- torchrec/distributed/planner/storage_reservations.py +168 -0
- torchrec/distributed/planner/types.py +423 -0
- torchrec/distributed/planner/utils.py +30 -0
- torchrec/distributed/quant_embedding.py +307 -0
- torchrec/distributed/quant_embedding_kernel.py +295 -0
- torchrec/distributed/quant_embeddingbag.py +288 -0
- torchrec/distributed/sharding/__init__.py +0 -0
- torchrec/distributed/sharding/cw_sequence_sharding.py +71 -0
- torchrec/distributed/sharding/cw_sharding.py +242 -0
- torchrec/distributed/sharding/dp_sequence_sharding.py +87 -0
- torchrec/distributed/sharding/dp_sharding.py +217 -0
- torchrec/distributed/sharding/rw_sequence_sharding.py +130 -0
- torchrec/distributed/sharding/rw_sharding.py +393 -0
- torchrec/distributed/sharding/sequence_sharding.py +69 -0
- torchrec/distributed/sharding/tw_sequence_sharding.py +211 -0
- torchrec/distributed/sharding/tw_sharding.py +469 -0
- torchrec/distributed/sharding/twcw_sharding.py +32 -0
- torchrec/distributed/sharding/twrw_sharding.py +543 -0
- torchrec/distributed/sharding/vb_cw_sharding.py +91 -0
- torchrec/distributed/sharding/vb_rw_sharding.py +250 -0
- torchrec/distributed/sharding/vb_sharding.py +54 -0
- torchrec/distributed/sharding/vb_tw_sharding.py +148 -0
- torchrec/distributed/sharding/vb_twrw_sharding.py +388 -0
- torchrec/distributed/test_utils/__init__.py +0 -0
- torchrec/distributed/test_utils/multi_process.py +132 -0
- torchrec/distributed/test_utils/test_model.py +818 -0
- torchrec/distributed/test_utils/test_model_parallel.py +74 -0
- torchrec/distributed/test_utils/test_model_parallel_base.py +117 -0
- torchrec/distributed/test_utils/test_sharding.py +280 -0
- torchrec/distributed/train_pipeline.py +531 -0
- torchrec/distributed/types.py +594 -0
- torchrec/distributed/utils.py +186 -0
- torchrec/fused_planner.py +57 -0
- torchrec/fx/__init__.py +15 -0
- torchrec/fx/tracer.py +78 -0
- torchrec/inference/__init__.py +25 -0
- torchrec/inference/client.py +127 -0
- torchrec/inference/model_packager.py +102 -0
- torchrec/inference/modules.py +155 -0
- torchrec/inference/state_dict_transform.py +103 -0
- torchrec/metrics/__init__.py +0 -0
- torchrec/metrics/auc.py +159 -0
- torchrec/metrics/calibration.py +108 -0
- torchrec/metrics/ctr.py +104 -0
- torchrec/metrics/metric_module.py +358 -0
- torchrec/metrics/metrics_config.py +152 -0
- torchrec/metrics/metrics_namespace.py +114 -0
- torchrec/metrics/model_utils.py +85 -0
- torchrec/metrics/mse.py +134 -0
- torchrec/metrics/ne.py +164 -0
- torchrec/metrics/rec_metric.py +686 -0
- torchrec/metrics/throughput.py +174 -0
- torchrec/models/__init__.py +27 -0
- torchrec/models/deepfm.py +346 -0
- torchrec/models/dlrm.py +708 -0
- torchrec/modules/__init__.py +34 -0
- torchrec/modules/activation.py +55 -0
- torchrec/modules/crossnet.py +446 -0
- torchrec/modules/deepfm.py +213 -0
- torchrec/modules/embedding_configs.py +148 -0
- torchrec/modules/embedding_modules.py +381 -0
- torchrec/modules/embedding_tower.py +150 -0
- torchrec/modules/feature_processor.py +74 -0
- torchrec/modules/fused_embedding_modules.py +625 -0
- torchrec/modules/lazy_extension.py +258 -0
- torchrec/modules/mlp.py +172 -0
- torchrec/modules/utils.py +117 -0
- torchrec/optim/__init__.py +35 -0
- torchrec/optim/clipping.py +53 -0
- torchrec/optim/fused.py +42 -0
- torchrec/optim/keyed.py +399 -0
- torchrec/optim/rowwise_adagrad.py +222 -0
- torchrec/optim/test_utils/__init__.py +19 -0
- torchrec/optim/warmup.py +147 -0
- torchrec/quant/__init__.py +34 -0
- torchrec/quant/embedding_modules.py +545 -0
- torchrec/sparse/__init__.py +33 -0
- torchrec/sparse/jagged_tensor.py +1281 -0
- torchrec/sparse/test_utils/__init__.py +45 -0
- torchrec/streamable.py +46 -0
- torchrec/test_utils/__init__.py +111 -0
- torchrec-0.2.dev0.dist-info/LICENSE +29 -0
- torchrec-0.2.dev0.dist-info/METADATA +175 -0
- torchrec-0.2.dev0.dist-info/RECORD +167 -0
- torchrec-0.2.dev0.dist-info/WHEEL +5 -0
- torchrec-0.2.dev0.dist-info/top_level.txt +2 -0
fbgemm_gpu/split_embedding_codegen_lookup_invokers/lookup_approx_rowwise_adagrad_with_counter.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
# This source code is licensed under the BSD-style license found in the
|
|
6
|
+
# LICENSE file in the root directory of this source tree.
|
|
7
|
+
|
|
8
|
+
import torch
|
|
9
|
+
from .lookup_args import *
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
#import os
|
|
14
|
+
#torch.ops.load_library(os.path.join(os.path.join(os.path.dirname(os.path.dirname(__file__)), "fbgemm_gpu_py.so")))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def invoke(
|
|
19
|
+
common_args: CommonArgs,
|
|
20
|
+
optimizer_args: OptimizerArgs,
|
|
21
|
+
|
|
22
|
+
momentum1: Momentum,
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
iter: int,
|
|
27
|
+
|
|
28
|
+
) -> torch.Tensor:
|
|
29
|
+
if (common_args.host_weights.numel() > 0):
|
|
30
|
+
return torch.ops.fbgemm.split_embedding_codegen_lookup_approx_rowwise_adagrad_with_counter_function_cpu(
|
|
31
|
+
# common_args
|
|
32
|
+
host_weights=common_args.host_weights,
|
|
33
|
+
weights_placements=common_args.weights_placements,
|
|
34
|
+
weights_offsets=common_args.weights_offsets,
|
|
35
|
+
D_offsets=common_args.D_offsets,
|
|
36
|
+
total_D=common_args.total_D,
|
|
37
|
+
max_D=common_args.max_D,
|
|
38
|
+
hash_size_cumsum=common_args.hash_size_cumsum,
|
|
39
|
+
total_hash_size_bits=common_args.total_hash_size_bits,
|
|
40
|
+
indices=common_args.indices,
|
|
41
|
+
offsets=common_args.offsets,
|
|
42
|
+
pooling_mode=common_args.pooling_mode,
|
|
43
|
+
indice_weights=common_args.indice_weights,
|
|
44
|
+
feature_requires_grad=common_args.feature_requires_grad,
|
|
45
|
+
# optimizer_args
|
|
46
|
+
gradient_clipping = optimizer_args.gradient_clipping,
|
|
47
|
+
max_gradient=optimizer_args.max_gradient,
|
|
48
|
+
stochastic_rounding=optimizer_args.stochastic_rounding,
|
|
49
|
+
|
|
50
|
+
learning_rate=optimizer_args.learning_rate,
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
eps=optimizer_args.eps,
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
weight_decay=optimizer_args.weight_decay,
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
weight_decay_mode=optimizer_args.weight_decay_mode,
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# momentum1
|
|
66
|
+
|
|
67
|
+
momentum1_host=momentum1.host,
|
|
68
|
+
momentum1_offsets=momentum1.offsets,
|
|
69
|
+
momentum1_placements=momentum1.placements,
|
|
70
|
+
|
|
71
|
+
# momentum2
|
|
72
|
+
|
|
73
|
+
# iter
|
|
74
|
+
|
|
75
|
+
iter=iter,
|
|
76
|
+
|
|
77
|
+
)
|
|
78
|
+
else:
|
|
79
|
+
return torch.ops.fbgemm.split_embedding_codegen_lookup_approx_rowwise_adagrad_with_counter_function(
|
|
80
|
+
# common_args
|
|
81
|
+
|
|
82
|
+
placeholder_autograd_tensor=common_args.placeholder_autograd_tensor,
|
|
83
|
+
|
|
84
|
+
dev_weights=common_args.dev_weights,
|
|
85
|
+
uvm_weights=common_args.uvm_weights,
|
|
86
|
+
lxu_cache_weights=common_args.lxu_cache_weights,
|
|
87
|
+
weights_placements=common_args.weights_placements,
|
|
88
|
+
weights_offsets=common_args.weights_offsets,
|
|
89
|
+
D_offsets=common_args.D_offsets,
|
|
90
|
+
total_D=common_args.total_D,
|
|
91
|
+
max_D=common_args.max_D,
|
|
92
|
+
hash_size_cumsum=common_args.hash_size_cumsum,
|
|
93
|
+
total_hash_size_bits=common_args.total_hash_size_bits,
|
|
94
|
+
indices=common_args.indices,
|
|
95
|
+
offsets=common_args.offsets,
|
|
96
|
+
pooling_mode=common_args.pooling_mode,
|
|
97
|
+
indice_weights=common_args.indice_weights,
|
|
98
|
+
feature_requires_grad=common_args.feature_requires_grad,
|
|
99
|
+
lxu_cache_locations=common_args.lxu_cache_locations,
|
|
100
|
+
# optimizer_args
|
|
101
|
+
gradient_clipping = optimizer_args.gradient_clipping,
|
|
102
|
+
max_gradient=optimizer_args.max_gradient,
|
|
103
|
+
stochastic_rounding=optimizer_args.stochastic_rounding,
|
|
104
|
+
|
|
105
|
+
learning_rate=optimizer_args.learning_rate,
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
eps=optimizer_args.eps,
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
weight_decay=optimizer_args.weight_decay,
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
weight_decay_mode=optimizer_args.weight_decay_mode,
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
# momentum1
|
|
121
|
+
|
|
122
|
+
momentum1_dev=momentum1.dev,
|
|
123
|
+
momentum1_uvm=momentum1.uvm,
|
|
124
|
+
momentum1_offsets=momentum1.offsets,
|
|
125
|
+
momentum1_placements=momentum1.placements,
|
|
126
|
+
|
|
127
|
+
# momentum2
|
|
128
|
+
|
|
129
|
+
# iter
|
|
130
|
+
|
|
131
|
+
iter=iter,
|
|
132
|
+
|
|
133
|
+
output_dtype=common_args.output_dtype,
|
|
134
|
+
)
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
# This source code is licensed under the BSD-style license found in the
|
|
6
|
+
# LICENSE file in the root directory of this source tree.
|
|
7
|
+
|
|
8
|
+
import torch
|
|
9
|
+
from .lookup_args import *
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
#import os
|
|
14
|
+
#torch.ops.load_library(os.path.join(os.path.join(os.path.dirname(os.path.dirname(__file__)), "fbgemm_gpu_py.so")))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def invoke(
|
|
19
|
+
common_args: CommonArgs,
|
|
20
|
+
optimizer_args: OptimizerArgs,
|
|
21
|
+
|
|
22
|
+
momentum1: Momentum,
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
) -> torch.Tensor:
|
|
27
|
+
if (common_args.host_weights.numel() > 0):
|
|
28
|
+
return torch.ops.fbgemm.split_embedding_codegen_lookup_approx_rowwise_adagrad_with_weight_decay_function_cpu(
|
|
29
|
+
# common_args
|
|
30
|
+
host_weights=common_args.host_weights,
|
|
31
|
+
weights_placements=common_args.weights_placements,
|
|
32
|
+
weights_offsets=common_args.weights_offsets,
|
|
33
|
+
D_offsets=common_args.D_offsets,
|
|
34
|
+
total_D=common_args.total_D,
|
|
35
|
+
max_D=common_args.max_D,
|
|
36
|
+
hash_size_cumsum=common_args.hash_size_cumsum,
|
|
37
|
+
total_hash_size_bits=common_args.total_hash_size_bits,
|
|
38
|
+
indices=common_args.indices,
|
|
39
|
+
offsets=common_args.offsets,
|
|
40
|
+
pooling_mode=common_args.pooling_mode,
|
|
41
|
+
indice_weights=common_args.indice_weights,
|
|
42
|
+
feature_requires_grad=common_args.feature_requires_grad,
|
|
43
|
+
# optimizer_args
|
|
44
|
+
gradient_clipping = optimizer_args.gradient_clipping,
|
|
45
|
+
max_gradient=optimizer_args.max_gradient,
|
|
46
|
+
stochastic_rounding=optimizer_args.stochastic_rounding,
|
|
47
|
+
|
|
48
|
+
learning_rate=optimizer_args.learning_rate,
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
eps=optimizer_args.eps,
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
weight_decay=optimizer_args.weight_decay,
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
weight_decay_mode=optimizer_args.weight_decay_mode,
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
# momentum1
|
|
64
|
+
|
|
65
|
+
momentum1_host=momentum1.host,
|
|
66
|
+
momentum1_offsets=momentum1.offsets,
|
|
67
|
+
momentum1_placements=momentum1.placements,
|
|
68
|
+
|
|
69
|
+
# momentum2
|
|
70
|
+
|
|
71
|
+
# iter
|
|
72
|
+
|
|
73
|
+
)
|
|
74
|
+
else:
|
|
75
|
+
return torch.ops.fbgemm.split_embedding_codegen_lookup_approx_rowwise_adagrad_with_weight_decay_function(
|
|
76
|
+
# common_args
|
|
77
|
+
|
|
78
|
+
placeholder_autograd_tensor=common_args.placeholder_autograd_tensor,
|
|
79
|
+
|
|
80
|
+
dev_weights=common_args.dev_weights,
|
|
81
|
+
uvm_weights=common_args.uvm_weights,
|
|
82
|
+
lxu_cache_weights=common_args.lxu_cache_weights,
|
|
83
|
+
weights_placements=common_args.weights_placements,
|
|
84
|
+
weights_offsets=common_args.weights_offsets,
|
|
85
|
+
D_offsets=common_args.D_offsets,
|
|
86
|
+
total_D=common_args.total_D,
|
|
87
|
+
max_D=common_args.max_D,
|
|
88
|
+
hash_size_cumsum=common_args.hash_size_cumsum,
|
|
89
|
+
total_hash_size_bits=common_args.total_hash_size_bits,
|
|
90
|
+
indices=common_args.indices,
|
|
91
|
+
offsets=common_args.offsets,
|
|
92
|
+
pooling_mode=common_args.pooling_mode,
|
|
93
|
+
indice_weights=common_args.indice_weights,
|
|
94
|
+
feature_requires_grad=common_args.feature_requires_grad,
|
|
95
|
+
lxu_cache_locations=common_args.lxu_cache_locations,
|
|
96
|
+
# optimizer_args
|
|
97
|
+
gradient_clipping = optimizer_args.gradient_clipping,
|
|
98
|
+
max_gradient=optimizer_args.max_gradient,
|
|
99
|
+
stochastic_rounding=optimizer_args.stochastic_rounding,
|
|
100
|
+
|
|
101
|
+
learning_rate=optimizer_args.learning_rate,
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
eps=optimizer_args.eps,
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
weight_decay=optimizer_args.weight_decay,
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
weight_decay_mode=optimizer_args.weight_decay_mode,
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
# momentum1
|
|
117
|
+
|
|
118
|
+
momentum1_dev=momentum1.dev,
|
|
119
|
+
momentum1_uvm=momentum1.uvm,
|
|
120
|
+
momentum1_offsets=momentum1.offsets,
|
|
121
|
+
momentum1_placements=momentum1.placements,
|
|
122
|
+
|
|
123
|
+
# momentum2
|
|
124
|
+
|
|
125
|
+
# iter
|
|
126
|
+
|
|
127
|
+
output_dtype=common_args.output_dtype,
|
|
128
|
+
)
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
# This source code is licensed under the BSD-style license found in the
|
|
6
|
+
# LICENSE file in the root directory of this source tree.
|
|
7
|
+
|
|
8
|
+
import torch
|
|
9
|
+
from .lookup_args import *
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
#import os
|
|
14
|
+
#torch.ops.load_library(os.path.join(os.path.join(os.path.dirname(os.path.dirname(__file__)), "fbgemm_gpu_py.so")))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def invoke(
|
|
19
|
+
common_args: CommonArgs,
|
|
20
|
+
optimizer_args: OptimizerArgs,
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
) -> torch.Tensor:
|
|
25
|
+
if (common_args.host_weights.numel() > 0):
|
|
26
|
+
return torch.ops.fbgemm.split_embedding_codegen_lookup_approx_sgd_function_cpu(
|
|
27
|
+
# common_args
|
|
28
|
+
host_weights=common_args.host_weights,
|
|
29
|
+
weights_placements=common_args.weights_placements,
|
|
30
|
+
weights_offsets=common_args.weights_offsets,
|
|
31
|
+
D_offsets=common_args.D_offsets,
|
|
32
|
+
total_D=common_args.total_D,
|
|
33
|
+
max_D=common_args.max_D,
|
|
34
|
+
hash_size_cumsum=common_args.hash_size_cumsum,
|
|
35
|
+
total_hash_size_bits=common_args.total_hash_size_bits,
|
|
36
|
+
indices=common_args.indices,
|
|
37
|
+
offsets=common_args.offsets,
|
|
38
|
+
pooling_mode=common_args.pooling_mode,
|
|
39
|
+
indice_weights=common_args.indice_weights,
|
|
40
|
+
feature_requires_grad=common_args.feature_requires_grad,
|
|
41
|
+
# optimizer_args
|
|
42
|
+
gradient_clipping = optimizer_args.gradient_clipping,
|
|
43
|
+
max_gradient=optimizer_args.max_gradient,
|
|
44
|
+
stochastic_rounding=optimizer_args.stochastic_rounding,
|
|
45
|
+
|
|
46
|
+
learning_rate=optimizer_args.learning_rate,
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# momentum1
|
|
56
|
+
|
|
57
|
+
# momentum2
|
|
58
|
+
|
|
59
|
+
# iter
|
|
60
|
+
|
|
61
|
+
)
|
|
62
|
+
else:
|
|
63
|
+
return torch.ops.fbgemm.split_embedding_codegen_lookup_approx_sgd_function(
|
|
64
|
+
# common_args
|
|
65
|
+
|
|
66
|
+
placeholder_autograd_tensor=common_args.placeholder_autograd_tensor,
|
|
67
|
+
|
|
68
|
+
dev_weights=common_args.dev_weights,
|
|
69
|
+
uvm_weights=common_args.uvm_weights,
|
|
70
|
+
lxu_cache_weights=common_args.lxu_cache_weights,
|
|
71
|
+
weights_placements=common_args.weights_placements,
|
|
72
|
+
weights_offsets=common_args.weights_offsets,
|
|
73
|
+
D_offsets=common_args.D_offsets,
|
|
74
|
+
total_D=common_args.total_D,
|
|
75
|
+
max_D=common_args.max_D,
|
|
76
|
+
hash_size_cumsum=common_args.hash_size_cumsum,
|
|
77
|
+
total_hash_size_bits=common_args.total_hash_size_bits,
|
|
78
|
+
indices=common_args.indices,
|
|
79
|
+
offsets=common_args.offsets,
|
|
80
|
+
pooling_mode=common_args.pooling_mode,
|
|
81
|
+
indice_weights=common_args.indice_weights,
|
|
82
|
+
feature_requires_grad=common_args.feature_requires_grad,
|
|
83
|
+
lxu_cache_locations=common_args.lxu_cache_locations,
|
|
84
|
+
# optimizer_args
|
|
85
|
+
gradient_clipping = optimizer_args.gradient_clipping,
|
|
86
|
+
max_gradient=optimizer_args.max_gradient,
|
|
87
|
+
stochastic_rounding=optimizer_args.stochastic_rounding,
|
|
88
|
+
|
|
89
|
+
learning_rate=optimizer_args.learning_rate,
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
# momentum1
|
|
99
|
+
|
|
100
|
+
# momentum2
|
|
101
|
+
|
|
102
|
+
# iter
|
|
103
|
+
|
|
104
|
+
output_dtype=common_args.output_dtype,
|
|
105
|
+
)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
# This source code is licensed under the BSD-style license found in the
|
|
6
|
+
# LICENSE file in the root directory of this source tree.
|
|
7
|
+
|
|
8
|
+
from typing import NamedTuple, Optional
|
|
9
|
+
|
|
10
|
+
import torch
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class CommonArgs(NamedTuple):
|
|
14
|
+
placeholder_autograd_tensor: torch.Tensor
|
|
15
|
+
dev_weights: torch.Tensor
|
|
16
|
+
host_weights: torch.Tensor
|
|
17
|
+
uvm_weights: torch.Tensor
|
|
18
|
+
lxu_cache_weights: torch.Tensor
|
|
19
|
+
weights_placements: torch.Tensor
|
|
20
|
+
weights_offsets: torch.Tensor
|
|
21
|
+
D_offsets: torch.Tensor
|
|
22
|
+
total_D: int
|
|
23
|
+
max_D: int
|
|
24
|
+
hash_size_cumsum: torch.Tensor
|
|
25
|
+
total_hash_size_bits: int
|
|
26
|
+
indices: torch.Tensor
|
|
27
|
+
offsets: torch.Tensor
|
|
28
|
+
pooling_mode: int
|
|
29
|
+
indice_weights: Optional[torch.Tensor]
|
|
30
|
+
feature_requires_grad: Optional[torch.Tensor]
|
|
31
|
+
lxu_cache_locations: torch.Tensor
|
|
32
|
+
output_dtype: int
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class OptimizerArgs(NamedTuple):
|
|
36
|
+
stochastic_rounding: bool
|
|
37
|
+
gradient_clipping: bool
|
|
38
|
+
max_gradient: float
|
|
39
|
+
learning_rate: float
|
|
40
|
+
eps: float
|
|
41
|
+
beta1: float
|
|
42
|
+
beta2: float
|
|
43
|
+
weight_decay: float
|
|
44
|
+
weight_decay_mode: int
|
|
45
|
+
eta: float
|
|
46
|
+
momentum: float
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class Momentum(NamedTuple):
|
|
50
|
+
dev: torch.Tensor
|
|
51
|
+
host: torch.Tensor
|
|
52
|
+
uvm: torch.Tensor
|
|
53
|
+
offsets: torch.Tensor
|
|
54
|
+
placements: torch.Tensor
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
# This source code is licensed under the BSD-style license found in the
|
|
6
|
+
# LICENSE file in the root directory of this source tree.
|
|
7
|
+
|
|
8
|
+
import torch
|
|
9
|
+
from .lookup_args import *
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
#import os
|
|
14
|
+
#torch.ops.load_library(os.path.join(os.path.join(os.path.dirname(os.path.dirname(__file__)), "fbgemm_gpu_py.so")))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def invoke(
|
|
19
|
+
common_args: CommonArgs,
|
|
20
|
+
optimizer_args: OptimizerArgs,
|
|
21
|
+
|
|
22
|
+
momentum1: Momentum,
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
momentum2: Momentum,
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
iter: int,
|
|
29
|
+
|
|
30
|
+
) -> torch.Tensor:
|
|
31
|
+
if (common_args.host_weights.numel() > 0):
|
|
32
|
+
return torch.ops.fbgemm.split_embedding_codegen_lookup_lamb_function_cpu(
|
|
33
|
+
# common_args
|
|
34
|
+
host_weights=common_args.host_weights,
|
|
35
|
+
weights_placements=common_args.weights_placements,
|
|
36
|
+
weights_offsets=common_args.weights_offsets,
|
|
37
|
+
D_offsets=common_args.D_offsets,
|
|
38
|
+
total_D=common_args.total_D,
|
|
39
|
+
max_D=common_args.max_D,
|
|
40
|
+
hash_size_cumsum=common_args.hash_size_cumsum,
|
|
41
|
+
total_hash_size_bits=common_args.total_hash_size_bits,
|
|
42
|
+
indices=common_args.indices,
|
|
43
|
+
offsets=common_args.offsets,
|
|
44
|
+
pooling_mode=common_args.pooling_mode,
|
|
45
|
+
indice_weights=common_args.indice_weights,
|
|
46
|
+
feature_requires_grad=common_args.feature_requires_grad,
|
|
47
|
+
# optimizer_args
|
|
48
|
+
gradient_clipping = optimizer_args.gradient_clipping,
|
|
49
|
+
max_gradient=optimizer_args.max_gradient,
|
|
50
|
+
stochastic_rounding=optimizer_args.stochastic_rounding,
|
|
51
|
+
|
|
52
|
+
learning_rate=optimizer_args.learning_rate,
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
eps=optimizer_args.eps,
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
beta1=optimizer_args.beta1,
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
beta2=optimizer_args.beta2,
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
weight_decay=optimizer_args.weight_decay,
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# momentum1
|
|
70
|
+
|
|
71
|
+
momentum1_host=momentum1.host,
|
|
72
|
+
momentum1_offsets=momentum1.offsets,
|
|
73
|
+
momentum1_placements=momentum1.placements,
|
|
74
|
+
|
|
75
|
+
# momentum2
|
|
76
|
+
|
|
77
|
+
momentum2_host=momentum2.host,
|
|
78
|
+
momentum2_offsets=momentum2.offsets,
|
|
79
|
+
momentum2_placements=momentum2.placements,
|
|
80
|
+
|
|
81
|
+
# iter
|
|
82
|
+
|
|
83
|
+
iter=iter,
|
|
84
|
+
|
|
85
|
+
)
|
|
86
|
+
else:
|
|
87
|
+
return torch.ops.fbgemm.split_embedding_codegen_lookup_lamb_function(
|
|
88
|
+
# common_args
|
|
89
|
+
|
|
90
|
+
placeholder_autograd_tensor=common_args.placeholder_autograd_tensor,
|
|
91
|
+
|
|
92
|
+
dev_weights=common_args.dev_weights,
|
|
93
|
+
uvm_weights=common_args.uvm_weights,
|
|
94
|
+
lxu_cache_weights=common_args.lxu_cache_weights,
|
|
95
|
+
weights_placements=common_args.weights_placements,
|
|
96
|
+
weights_offsets=common_args.weights_offsets,
|
|
97
|
+
D_offsets=common_args.D_offsets,
|
|
98
|
+
total_D=common_args.total_D,
|
|
99
|
+
max_D=common_args.max_D,
|
|
100
|
+
hash_size_cumsum=common_args.hash_size_cumsum,
|
|
101
|
+
total_hash_size_bits=common_args.total_hash_size_bits,
|
|
102
|
+
indices=common_args.indices,
|
|
103
|
+
offsets=common_args.offsets,
|
|
104
|
+
pooling_mode=common_args.pooling_mode,
|
|
105
|
+
indice_weights=common_args.indice_weights,
|
|
106
|
+
feature_requires_grad=common_args.feature_requires_grad,
|
|
107
|
+
lxu_cache_locations=common_args.lxu_cache_locations,
|
|
108
|
+
# optimizer_args
|
|
109
|
+
gradient_clipping = optimizer_args.gradient_clipping,
|
|
110
|
+
max_gradient=optimizer_args.max_gradient,
|
|
111
|
+
stochastic_rounding=optimizer_args.stochastic_rounding,
|
|
112
|
+
|
|
113
|
+
learning_rate=optimizer_args.learning_rate,
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
eps=optimizer_args.eps,
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
beta1=optimizer_args.beta1,
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
beta2=optimizer_args.beta2,
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
weight_decay=optimizer_args.weight_decay,
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
# momentum1
|
|
131
|
+
|
|
132
|
+
momentum1_dev=momentum1.dev,
|
|
133
|
+
momentum1_uvm=momentum1.uvm,
|
|
134
|
+
momentum1_offsets=momentum1.offsets,
|
|
135
|
+
momentum1_placements=momentum1.placements,
|
|
136
|
+
|
|
137
|
+
# momentum2
|
|
138
|
+
|
|
139
|
+
momentum2_dev=momentum2.dev,
|
|
140
|
+
momentum2_uvm=momentum2.uvm,
|
|
141
|
+
momentum2_offsets=momentum2.offsets,
|
|
142
|
+
momentum2_placements=momentum2.placements,
|
|
143
|
+
|
|
144
|
+
# iter
|
|
145
|
+
|
|
146
|
+
iter=iter,
|
|
147
|
+
|
|
148
|
+
output_dtype=common_args.output_dtype,
|
|
149
|
+
)
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
# This source code is licensed under the BSD-style license found in the
|
|
6
|
+
# LICENSE file in the root directory of this source tree.
|
|
7
|
+
|
|
8
|
+
import torch
|
|
9
|
+
from .lookup_args import *
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
#import os
|
|
14
|
+
#torch.ops.load_library(os.path.join(os.path.join(os.path.dirname(os.path.dirname(__file__)), "fbgemm_gpu_py.so")))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def invoke(
|
|
19
|
+
common_args: CommonArgs,
|
|
20
|
+
optimizer_args: OptimizerArgs,
|
|
21
|
+
|
|
22
|
+
momentum1: Momentum,
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
) -> torch.Tensor:
|
|
27
|
+
if (common_args.host_weights.numel() > 0):
|
|
28
|
+
return torch.ops.fbgemm.split_embedding_codegen_lookup_lars_sgd_function_cpu(
|
|
29
|
+
# common_args
|
|
30
|
+
host_weights=common_args.host_weights,
|
|
31
|
+
weights_placements=common_args.weights_placements,
|
|
32
|
+
weights_offsets=common_args.weights_offsets,
|
|
33
|
+
D_offsets=common_args.D_offsets,
|
|
34
|
+
total_D=common_args.total_D,
|
|
35
|
+
max_D=common_args.max_D,
|
|
36
|
+
hash_size_cumsum=common_args.hash_size_cumsum,
|
|
37
|
+
total_hash_size_bits=common_args.total_hash_size_bits,
|
|
38
|
+
indices=common_args.indices,
|
|
39
|
+
offsets=common_args.offsets,
|
|
40
|
+
pooling_mode=common_args.pooling_mode,
|
|
41
|
+
indice_weights=common_args.indice_weights,
|
|
42
|
+
feature_requires_grad=common_args.feature_requires_grad,
|
|
43
|
+
# optimizer_args
|
|
44
|
+
gradient_clipping = optimizer_args.gradient_clipping,
|
|
45
|
+
max_gradient=optimizer_args.max_gradient,
|
|
46
|
+
stochastic_rounding=optimizer_args.stochastic_rounding,
|
|
47
|
+
|
|
48
|
+
learning_rate=optimizer_args.learning_rate,
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
weight_decay=optimizer_args.weight_decay,
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
eta=optimizer_args.eta,
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
momentum=optimizer_args.momentum,
|
|
62
|
+
|
|
63
|
+
# momentum1
|
|
64
|
+
|
|
65
|
+
momentum1_host=momentum1.host,
|
|
66
|
+
momentum1_offsets=momentum1.offsets,
|
|
67
|
+
momentum1_placements=momentum1.placements,
|
|
68
|
+
|
|
69
|
+
# momentum2
|
|
70
|
+
|
|
71
|
+
# iter
|
|
72
|
+
|
|
73
|
+
)
|
|
74
|
+
else:
|
|
75
|
+
return torch.ops.fbgemm.split_embedding_codegen_lookup_lars_sgd_function(
|
|
76
|
+
# common_args
|
|
77
|
+
|
|
78
|
+
placeholder_autograd_tensor=common_args.placeholder_autograd_tensor,
|
|
79
|
+
|
|
80
|
+
dev_weights=common_args.dev_weights,
|
|
81
|
+
uvm_weights=common_args.uvm_weights,
|
|
82
|
+
lxu_cache_weights=common_args.lxu_cache_weights,
|
|
83
|
+
weights_placements=common_args.weights_placements,
|
|
84
|
+
weights_offsets=common_args.weights_offsets,
|
|
85
|
+
D_offsets=common_args.D_offsets,
|
|
86
|
+
total_D=common_args.total_D,
|
|
87
|
+
max_D=common_args.max_D,
|
|
88
|
+
hash_size_cumsum=common_args.hash_size_cumsum,
|
|
89
|
+
total_hash_size_bits=common_args.total_hash_size_bits,
|
|
90
|
+
indices=common_args.indices,
|
|
91
|
+
offsets=common_args.offsets,
|
|
92
|
+
pooling_mode=common_args.pooling_mode,
|
|
93
|
+
indice_weights=common_args.indice_weights,
|
|
94
|
+
feature_requires_grad=common_args.feature_requires_grad,
|
|
95
|
+
lxu_cache_locations=common_args.lxu_cache_locations,
|
|
96
|
+
# optimizer_args
|
|
97
|
+
gradient_clipping = optimizer_args.gradient_clipping,
|
|
98
|
+
max_gradient=optimizer_args.max_gradient,
|
|
99
|
+
stochastic_rounding=optimizer_args.stochastic_rounding,
|
|
100
|
+
|
|
101
|
+
learning_rate=optimizer_args.learning_rate,
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
weight_decay=optimizer_args.weight_decay,
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
eta=optimizer_args.eta,
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
momentum=optimizer_args.momentum,
|
|
115
|
+
|
|
116
|
+
# momentum1
|
|
117
|
+
|
|
118
|
+
momentum1_dev=momentum1.dev,
|
|
119
|
+
momentum1_uvm=momentum1.uvm,
|
|
120
|
+
momentum1_offsets=momentum1.offsets,
|
|
121
|
+
momentum1_placements=momentum1.placements,
|
|
122
|
+
|
|
123
|
+
# momentum2
|
|
124
|
+
|
|
125
|
+
# iter
|
|
126
|
+
|
|
127
|
+
output_dtype=common_args.output_dtype,
|
|
128
|
+
)
|