Skip to content

Commit

Permalink
apply Black 2024 style in fbcode (8/16)
Browse files Browse the repository at this point in the history
Reviewed By: aleivag

Differential Revision: D54447737

fbshipit-source-id: 6c05d7941c6b4f1787b8da6cf810693f48a96c4e
  • Loading branch information
amyreese authored and facebook-github-bot committed Mar 3, 2024
1 parent f3cdb7a commit 9ecc93a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def devices_to_use_test_helper(self, input, num_replications):

self.assertEqual(type(g), type(t))
self.assertEqual(len(g), len(t))
for (gi, ti) in zip(g, t):
for gi, ti in zip(g, t):
self.assertTrue(torch.allclose(gi, ti))

def devices_to_use_test(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def tuple_test_helper(self, ModType):
self.assertEqual(type(g), type(t))
self.assertEqual(len(g), len(t))

for (gi, ti) in zip(g, t):
for gi, ti in zip(g, t):
self.assertTrue(torch.allclose(gi, ti))

# test module ser/de with tuple output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def lower_and_write_to_onnx_helper(self, ModType, onnx_prefix):
self.assertEqual(type(g), type(t))
self.assertEqual(len(g), len(t))

for (gi, ti) in zip(g, t):
for gi, ti in zip(g, t):
self.assertTrue(torch.allclose(gi, ti))

assert os.path.exists(onnx_prefix + ".onnxtxt")
Expand Down
16 changes: 10 additions & 6 deletions torch_glow/tests/nodes/embedding_bag_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ class TestQuantizedEmbeddingBag(utils.TorchGlowTestCase):
bits="_4bit" if is4bit else "_byte",
weighted="_weighted" if is_weighted else "",
fp16="_fp16" if use_fp16 else "",
sample_weights="_sample_weights_fp16"
if per_sample_weights_fp16 and is_weighted
else "",
sample_weights=(
"_sample_weights_fp16"
if per_sample_weights_fp16 and is_weighted
else ""
),
backend="_" + DEFAULT_BACKEND,
),
num_lengths,
Expand Down Expand Up @@ -157,9 +159,11 @@ def forward(self, indices, offsets):
indices,
offsets,
fusible_ops={
"quantized::embedding_bag_4bit_rowwise_offsets"
if is4bit
else "quantized::embedding_bag_byte_rowwise_offsets"
(
"quantized::embedding_bag_4bit_rowwise_offsets"
if is4bit
else "quantized::embedding_bag_byte_rowwise_offsets"
)
},
fp16=use_fp16,
# FP16 version is known to yeild different results, so our
Expand Down
18 changes: 15 additions & 3 deletions torch_glow/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,22 @@ def ephemeral_torchglow_settings(
torch_glow.setGlowBackend(backend)
yield
finally:
torch_glow.enable_convert_to_fp16() if old_fp16 else torch_glow.disable_convert_to_fp16()
(
torch_glow.enable_convert_to_fp16()
if old_fp16
else torch_glow.disable_convert_to_fp16()
)
torch_glow.enable_clip_fp16() if old_clip else torch_glow.disable_clip_fp16()
torch_glow.enable_convert_fused_to_fp16() if old_convert_fused else torch_glow.disable_convert_fused_to_fp16()
torch_glow.enableFusionPass_DO_NOT_USE_THIS() if old_fusion else torch_glow.disableFusionPass()
(
torch_glow.enable_convert_fused_to_fp16()
if old_convert_fused
else torch_glow.disable_convert_fused_to_fp16()
)
(
torch_glow.enableFusionPass_DO_NOT_USE_THIS()
if old_fusion
else torch_glow.disableFusionPass()
)
torch_glow.setGlowBackend(old_backend)
torch_glow.setFusionBlocklist(old_blocklist)

Expand Down
6 changes: 3 additions & 3 deletions utils/caffe2_pb_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ def mode_128to127(x):
for h in range(0, model_props[MODEL].image_size):
for c in range(0, model_props[MODEL].num_color_channels):
# WHC -> CWH, RGB -> BGR
transposed_image[0][model_props[MODEL].num_color_channels - c - 1][w][
h
] = model_props[MODEL].image_mode_op(img[w][h][c])
transposed_image[0][model_props[MODEL].num_color_channels - c - 1][w][h] = (
model_props[MODEL].image_mode_op(img[w][h][c])
)

final_image = transposed_image

Expand Down
4 changes: 2 additions & 2 deletions utils/trace_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ def dumpAccumulate(events, keyfunc, traceTime):
nameMap[name].append(ev.selfTime())

layers = []
for (name, times) in nameMap.items():
for name, times in nameMap.items():
layers.append(
(name, len(times), numpy.mean(times), numpy.std(times), numpy.sum(times))
)

# Iterate sorted by total time.
for (name, num, mean, stddev, total) in sorted(
for name, num, mean, stddev, total in sorted(
layers, key=itemgetter(4), reverse=True
):
mean = formatUs(mean)
Expand Down

0 comments on commit 9ecc93a

Please sign in to comment.