Skip to content

Commit 5d0a3d9

Browse files
QuantumManiacmeta-codesync[bot]
authored andcommitted
Enable Pyrefly for deeplearning/fbgemm (#6099)
Summary: Pull Request resolved: #6099 X-link: https://github.com/facebookresearch/FBGEMM/pull/3003 Enables Pyrefly for `deeplearning/fbgemm` by setting `python.set_pyrefly(True)` in the subdirectory PACKAGE file and adding targeted `# pyrefly: ignore` annotations. Part of splitting D113608658 into a per-subdirectory stack; the final diff performs the directory-level flip. #buildall Reviewed By: maggiemoss Differential Revision: D113962589 fbshipit-source-id: aea111f522e6951bdac4abc0d5d28484326f6cb7
1 parent 6a03a17 commit 5d0a3d9

72 files changed

Lines changed: 303 additions & 14 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

fbgemm_gpu/bench/jagged_tensor_benchmark.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,7 @@ def keyed_jagged_index_select_dim1_ref(
10891089
)
10901090
if baseline:
10911091
time_ref, _ = benchmark_torch_function(
1092+
# pyrefly: ignore [unbound-name]
10921093
functools.partial(output_ref.backward, retain_graph=True),
10931094
(grad,),
10941095
iters=iters,

fbgemm_gpu/bench/merge_embeddings_benchmark.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def generate_requests(
9494
rs.append(
9595
get_table_batched_offsets_from_dense(all_indices.view(T, B, L), gpu_num)
9696
)
97+
# pyrefly: ignore [bad-return]
9798
return rs
9899

99100

fbgemm_gpu/bench/sparse_ops_benchmark.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,7 @@ def batch_group_index_select_bwd(
14021402
)
14031403

14041404
if timeline:
1405+
# pyrefly: ignore [missing-attribute]
14051406
prof.export_chrome_trace("index_select_fwd_trace.json")
14061407

14071408
grads = [torch.rand_like(out) for out in out_pyt]
@@ -1442,6 +1443,7 @@ def batch_group_index_select_bwd(
14421443
)
14431444

14441445
if timeline:
1446+
# pyrefly: ignore [missing-attribute]
14451447
prof.export_chrome_trace("index_select_bwd_trace.json")
14461448

14471449
logging.info(
@@ -1722,10 +1724,13 @@ def permute_1d_sparse_data_bench(
17221724
embedding tables.
17231725
"""
17241726
if index_dtype == "int":
1727+
# pyrefly: ignore [bad-assignment]
17251728
index_dtype = torch.int32
17261729
elif index_dtype == "int64":
1730+
# pyrefly: ignore [bad-assignment]
17271731
index_dtype = torch.int64
17281732
elif index_dtype == "float":
1733+
# pyrefly: ignore [bad-assignment]
17291734
index_dtype = torch.float32
17301735
else:
17311736
raise RuntimeError(f"Does not support data type {index_dtype}")
@@ -1744,8 +1749,10 @@ def permute_1d_sparse_data_bench(
17441749
total_indices = int(lengths.sum().item())
17451750
# Generate indices
17461751
if index_dtype == torch.float32:
1752+
# pyrefly: ignore [no-matching-overload]
17471753
indices = torch.rand(total_indices, dtype=index_dtype, device=device)
17481754
else:
1755+
# pyrefly: ignore [no-matching-overload]
17491756
indices = torch.randint(
17501757
low=0,
17511758
high=2**31 - 1,
@@ -1881,14 +1888,19 @@ def permute_2d_sparse_data_bench(
18811888
systems to reorder embedding tables.
18821889
"""
18831890
if index_dtype == "int":
1891+
# pyrefly: ignore [bad-assignment]
18841892
index_dtype = torch.int32
18851893
elif index_dtype == "int64":
1894+
# pyrefly: ignore [bad-assignment]
18861895
index_dtype = torch.int64
18871896
elif index_dtype == "float":
1897+
# pyrefly: ignore [bad-assignment]
18881898
index_dtype = torch.float32
18891899
elif index_dtype == "bf16":
1900+
# pyrefly: ignore [bad-assignment]
18901901
index_dtype = torch.bfloat16
18911902
elif index_dtype == "fp16":
1903+
# pyrefly: ignore [bad-assignment]
18921904
index_dtype = torch.float16
18931905
else:
18941906
raise RuntimeError(f"Does not support data type {index_dtype}")
@@ -1909,9 +1921,12 @@ def permute_2d_sparse_data_bench(
19091921
* emb_dim
19101922
)
19111923
total_indices = int(lengths.sum().item())
1924+
# pyrefly: ignore [missing-attribute]
19121925
if index_dtype.is_floating_point:
1926+
# pyrefly: ignore [no-matching-overload]
19131927
indices = torch.rand(total_indices, dtype=index_dtype, device=device)
19141928
else:
1929+
# pyrefly: ignore [no-matching-overload]
19151930
indices = torch.randint(
19161931
low=0,
19171932
high=2**31 - 1,

fbgemm_gpu/bench/tbe/split_table_batched_embeddings_benchmark.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,7 @@ def device_from_files( # noqa C901
20472047
_Ds: list[int]
20482048
emb_loc: list[EmbeddingLocation]
20492049
compute_device: list[ComputeDevice]
2050+
# pyrefly: ignore [bad-assignment]
20502051
_Es, _Ds, emb_loc, compute_device = zip(*embedding_specs)
20512052

20522053
# Determine location suffix for trace URL based on embedding locations

fbgemm_gpu/bench/tbe/tbe_cache_benchmark.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,14 @@ def lxu_cache_lookup(
272272
tbe: nn.Module = IntNBitTableBatchedEmbeddingBagsCodegen(
273273
embedding_specs, cache_load_factor=cache_load_factor
274274
)
275+
# pyrefly: ignore [not-callable]
275276
tbe.fill_random_weights()
276277

277278
# Imitate execution flow by performing prefetching once.
278279
indices, offsets = create_request(
279280
num_tables, num_embeddings, batch, avg_pooling_factor
280281
)
282+
# pyrefly: ignore [not-callable]
281283
tbe.prefetch(indices, offsets)
282284

283285
linearized_indices = torch.ops.fbgemm.linearize_cache_indices(
@@ -333,6 +335,7 @@ def lru_cache_populate_byte(
333335
cc: nn.Module = IntNBitTableBatchedEmbeddingBagsCodegen(
334336
embedding_specs, cache_load_factor=cache_load_factor
335337
)
338+
# pyrefly: ignore [not-callable]
336339
cc.fill_random_weights()
337340

338341
warm_up_requests = []
@@ -389,6 +392,7 @@ def populate(linear_indices: Tensor) -> None:
389392
replay_cc: nn.Module = IntNBitTableBatchedEmbeddingBagsCodegen(
390393
embedding_specs, cache_load_factor=cache_load_factor
391394
)
395+
# pyrefly: ignore [not-callable]
392396
replay_cc.fill_random_weights()
393397

394398
replay_timestep: int = 1
@@ -464,6 +468,7 @@ def lfu_cache_populate_byte(
464468
cache_load_factor=cache_load_factor,
465469
cache_algorithm=CacheAlgorithm.LFU,
466470
)
471+
# pyrefly: ignore [not-callable]
467472
cc.fill_random_weights()
468473

469474
warm_up_requests = []
@@ -517,6 +522,7 @@ def populate(linear_indices: Tensor) -> None:
517522
cache_load_factor=cache_load_factor,
518523
cache_algorithm=CacheAlgorithm.LFU,
519524
)
525+
# pyrefly: ignore [not-callable]
520526
replay_cc.fill_random_weights()
521527

522528
def replay_populate(linear_indices: Tensor) -> None:

fbgemm_gpu/bench/tbe/tbe_inference_benchmark.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ def nbit_device_with_spec( # noqa C901
874874
TBERequest(
875875
req.indices.cpu().int(),
876876
req.offsets.cpu().int(),
877+
# pyrefly: ignore [missing-attribute]
877878
req.per_sample_weigths.cpu() if req.per_sample_weights else None,
878879
)
879880
for req in requests
@@ -1197,6 +1198,7 @@ def nbit_uvm(
11971198
)
11981199

11991200
if T_gpu > 0:
1201+
# pyrefly: ignore [unbound-name]
12001202
nparams_byte = sum(w.numel() for (w, _) in emb_mixed.split_embedding_weights())
12011203
logging.info(
12021204
f"{weights_precision} Embedding tables: {E * T_gpu + E_uvm * T_uvm} rows, {nparams_byte / param_size_multiplier / 1.0e9: .2f} GParam, "
@@ -1647,6 +1649,7 @@ def nbit_cache( # noqa C901
16471649
)
16481650
for d in Ds
16491651
],
1652+
# pyrefly: ignore [not-callable]
16501653
record_cache_metrics=RecordCacheMetrics(
16511654
record_cache_miss_counter, record_tablewise_cache_miss
16521655
),

fbgemm_gpu/bench/tbe/tbe_training_benchmark.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ def device_with_speclist( # noqa C901
639639
# pyre-ignore[53]
640640
def _kineto_trace_handler(p: profile, phase: str) -> None:
641641
p.export_chrome_trace(
642+
# pyrefly: ignore [missing-attribute]
642643
benchconfig.trace_url.format(
643644
emb_op_type=emb_op_type, phase=phase, ospid=os.getpid()
644645
)

fbgemm_gpu/codegen/genscript/generate_backward_split.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from .optimizer_args import annotation_dict, OptimizerArgsSet
2727
from .scripts_argsparse import args
2828
except ImportError:
29+
# pyrefly: ignore [missing-import]
2930
from optimizers import *
3031

3132
# pyre-ignore[21]
@@ -118,6 +119,7 @@ def generate_backward_split_gpu(**kwargs: Any) -> None:
118119
]:
119120
BackwardSplitGenerator.render_backward_templates(
120121
template_filepath,
122+
# pyrefly: ignore [bad-argument-type]
121123
optimizer,
122124
filename_format,
123125
kwargs,
@@ -141,6 +143,7 @@ def generate_backward_split_gpu(**kwargs: Any) -> None:
141143
]:
142144
BackwardSplitGenerator.render_backward_templates(
143145
template_filepath,
146+
# pyrefly: ignore [bad-argument-type]
144147
optimizer,
145148
filename_format,
146149
kwargs,
@@ -241,7 +244,7 @@ def generate_backward_split_cpu(**kwargs: Any) -> None:
241244
if kwargs.get("has_cpu_support"):
242245
CodeTemplate.load(
243246
"training/backward/embedding_backward_split_cpu_approx_template.cpp"
244-
if "approx" in optimizer
247+
if "approx" in optimizer # pyrefly: ignore [not-iterable]
245248
else "training/backward/embedding_backward_split_cpu_template.cpp"
246249
).write(f"gen_embedding_backward_{optimizer}_split_cpu.cpp", **kwargs)
247250

fbgemm_gpu/codegen/genscript/generate_embedding_optimizer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def generate_embedding_optimizer(**kwargs: Any) -> None:
3636

3737
optimizer = kwargs.get("optimizer")
3838
kwargs["optimizer_class_name"] = "".join(
39+
# pyrefly: ignore [missing-attribute]
3940
[optim.capitalize() for optim in optimizer.split("_")]
4041
)
4142
kwargs["args"] = kwargs["args"].cuda

fbgemm_gpu/codegen/genscript/jinja_environment.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,26 @@
5858
# BT_block_size * 4 * 4 * 32 * (max_D // 128) <= 64 * 1024 (V100) or 96 * 1024 (A100)
5959
# Since BT_block_size >= 1, max_D <= 16K (V100) or 24K (A100).
6060
# Note that if we increase max_D, it will increase the compilation time significantly.
61+
# pyrefly: ignore [unsupported-operation]
6162
env.globals["max_embedding_dim"] = 2048
6263

6364
# Max embedding dimension for legacy embedding kernels. TBE v2 can support
6465
# larger max embedding dimension.
66+
# pyrefly: ignore [unsupported-operation]
6567
env.globals["legacy_max_embedding_dim"] = 1024
6668

6769
# An optimization for ROCm
70+
# pyrefly: ignore [unsupported-operation]
6871
env.globals["items_per_warp"] = 128 if args.is_rocm is False else 256
6972

7073
# The fixed max vectors per thread for different kernels. The numbers were
7174
# derived from empirical studies
75+
# pyrefly: ignore [unsupported-operation]
7276
env.globals["fixed_max_vecs_per_thread"] = {"backward": 2, "backward_indice_weights": 6}
7377

78+
# pyrefly: ignore [unsupported-operation]
7479
env.globals["dense"] = False
80+
# pyrefly: ignore [unsupported-operation]
7581
env.globals["is_rocm"] = args.is_rocm
7682

7783

@@ -343,15 +349,24 @@ def compute_global_weight_decay(is_global_weight_decay_kernel: bool) -> str:
343349
################################################################################
344350

345351
env.globals["generate_optimized_grad_sum_loop_access"] = (
352+
# pyrefly: ignore [unsupported-operation]
346353
generate_optimized_grad_sum_loop_access
347354
)
355+
# pyrefly: ignore [unsupported-operation]
348356
env.globals["get_max_vecs_template_configs"] = get_max_vecs_template_configs
357+
# pyrefly: ignore [unsupported-operation]
349358
env.globals["dispatch_optimal_kernel"] = dispatch_optimal_kernel
359+
# pyrefly: ignore [unsupported-operation]
350360
env.globals["dispatch_non_vec_blocking_kernel"] = dispatch_non_vec_blocking_kernel
361+
# pyrefly: ignore [unsupported-operation]
351362
env.globals["dispatch_vec_blocking_kernel"] = dispatch_vec_blocking_kernel
363+
# pyrefly: ignore [unsupported-operation]
352364
env.globals["is_valid_forward_config"] = is_valid_forward_config
365+
# pyrefly: ignore [unsupported-operation]
353366
env.globals["has_experimental_support"] = has_experimental_support
367+
# pyrefly: ignore [unsupported-operation]
354368
env.globals["is_valid_gwd_config"] = is_valid_gwd_config
369+
# pyrefly: ignore [unsupported-operation]
355370
env.globals["compute_global_weight_decay"] = compute_global_weight_decay
356371

357372
################################################################################

0 commit comments

Comments
 (0)