Bump protobuf version and refactor tensorboard tests (#154244)

In preparation for https://github.com/pytorch/pytorch/pull/153746, I am bumping protobuf to 5.29.4 and fixing the tensorboard tests first.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/154244
Approved by: https://github.com/malfet, https://github.com/cyyever
This commit is contained in:
Justin Chu
2025-05-25 00:50:07 +00:00
committed by PyTorch MergeBot
parent 53ecb8159a
commit 10c51b11ff
11 changed files with 155 additions and 195 deletions

View File

@ -166,9 +166,9 @@ pillow==11.0.0
#Pinned versions: 10.3.0
#test that import:
protobuf==3.20.2
#Description: Googles data interchange format
#Pinned versions: 3.20.1
protobuf==5.29.4
#Description: Google's data interchange format
#Pinned versions: 5.29.4
#test that import: test_tensorboard.py
psutil

View File

@ -38,7 +38,7 @@ if [[ "$BUILD_ENVIRONMENT" == *cuda* ]]; then
fi
# TODO: Move both of them to Windows AMI
python -m pip install pytest-rerunfailures==10.3 pytest-cpp==2.3.0 tensorboard==2.13.0 pytest-subtests==0.13.1
python -m pip install pytest-rerunfailures==10.3 pytest-cpp==2.3.0 tensorboard==2.13.0 protobuf==5.29.4 pytest-subtests==0.13.1
# Install Z3 optional dependency for Windows builds.
python -m pip install z3-solver==4.12.2.0

View File

@ -25,7 +25,5 @@ pytest-cpp==2.3.0
z3-solver==4.12.2.0
tensorboard==2.13.0
optree==0.13.0
# NB: test_hparams_* from test_tensorboard is failing with protobuf 5.26.0 in
# which the stringify metadata is wrong when escaping double quote
protobuf==3.20.2
protobuf==5.29.4
parameterized==0.8.1

View File

@ -157,7 +157,7 @@ init_command = [
'types-requests==2.27.25',
'types-PyYAML==6.0.7',
'types-tabulate==0.8.8',
'types-protobuf==3.19.18',
'types-protobuf==5.29.1.20250403',
'types-pkg-resources==0.1.3',
'types-Jinja2==2.11.9',
'types-colorama==0.4.6',

View File

@ -1,7 +1,7 @@
value {
tag: "dummy"
audio {
sample_rate: 44100.0
sample_rate: 44100
num_channels: 1
length_frames: 42
encoded_audio_string: "RIFFx\000\000\000WAVEfmt \020\000\000\000\001\000\001\000D\254\000\000\210X\001\000\002\000\020\000dataT\000\000\000\000\000\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177"

View File

@ -1,23 +1,23 @@
value {
tag: "dummy"
histo {
max: 1023.0
num: 1024.0
sum: 523776.0
sum_squares: 357389824.0
bucket_limit: 0.0
bucket_limit: 186.0
bucket_limit: 372.0
bucket_limit: 558.0
bucket_limit: 744.0
bucket_limit: 930.0
bucket_limit: 1023.0
bucket: 0.0
bucket: 186.0
bucket: 186.0
bucket: 186.0
bucket: 186.0
bucket: 186.0
bucket: 94.0
max: 1023
num: 1024
sum: 523776
sum_squares: 357389824
bucket_limit: 0
bucket_limit: 186
bucket_limit: 372
bucket_limit: 558
bucket_limit: 744
bucket_limit: 930
bucket_limit: 1023
bucket: 0
bucket: 186
bucket: 186
bucket: 186
bucket: 186
bucket: 186
bucket: 94
}
}

View File

@ -1,23 +1,23 @@
value {
tag: "dummy"
histo {
max: 1023.0
num: 1024.0
sum: 523776.0
sum_squares: 357389824.0
bucket_limit: 0.0
bucket_limit: 186.0
bucket_limit: 372.0
bucket_limit: 558.0
bucket_limit: 744.0
bucket_limit: 930.0
bucket_limit: 1023.0
bucket: 0.0
bucket: 186.0
bucket: 186.0
bucket: 186.0
bucket: 186.0
bucket: 186.0
bucket: 94.0
max: 1023
num: 1024
sum: 523776
sum_squares: 357389824
bucket_limit: 0
bucket_limit: 186
bucket_limit: 372
bucket_limit: 558
bucket_limit: 744
bucket_limit: 930
bucket_limit: 1023
bucket: 0
bucket: 186
bucket: 186
bucket: 186
bucket: 186
bucket: 186
bucket: 94
}
}

View File

@ -1,23 +1,23 @@
value {
tag: "dummy"
histo {
max: 1023.0
num: 1024.0
sum: 523776.0
sum_squares: 357389824.0
bucket_limit: 0.0
bucket_limit: 186.0
bucket_limit: 372.0
bucket_limit: 558.0
bucket_limit: 744.0
bucket_limit: 930.0
bucket_limit: 1023.0
bucket: 0.0
bucket: 186.0
bucket: 186.0
bucket: 186.0
bucket: 186.0
bucket: 186.0
bucket: 94.0
max: 1023
num: 1024
sum: 523776
sum_squares: 357389824
bucket_limit: 0
bucket_limit: 186
bucket_limit: 372
bucket_limit: 558
bucket_limit: 744
bucket_limit: 930
bucket_limit: 1023
bucket: 0
bucket: 186
bucket: 186
bucket: 186
bucket: 186
bucket: 186
bucket: 94
}
}

View File

@ -13,18 +13,18 @@ value {
size: 3
}
}
float_val: 1.0
float_val: 1.0
float_val: 1.0
float_val: -1.0
float_val: -1.0
float_val: 1.0
float_val: 1.0
float_val: -1.0
float_val: -1.0
float_val: -1.0
float_val: 1.0
float_val: -1.0
float_val: 1
float_val: 1
float_val: 1
float_val: -1
float_val: -1
float_val: 1
float_val: 1
float_val: -1
float_val: -1
float_val: -1
float_val: 1
float_val: -1
}
metadata {
plugin_data {
@ -48,18 +48,18 @@ value {
size: 3
}
}
float_val: 0.0
float_val: 2.0
float_val: 3.0
float_val: 0.0
float_val: 3.0
float_val: 1.0
float_val: 0.0
float_val: 1.0
float_val: 2.0
float_val: 1.0
float_val: 3.0
float_val: 2.0
float_val: 0
float_val: 2
float_val: 3
float_val: 0
float_val: 3
float_val: 1
float_val: 0
float_val: 1
float_val: 2
float_val: 1
float_val: 3
float_val: 2
}
metadata {
plugin_data {
@ -83,18 +83,18 @@ value {
size: 3
}
}
float_val: 255.0
float_val: 0.0
float_val: 0.0
float_val: 0.0
float_val: 255.0
float_val: 0.0
float_val: 0.0
float_val: 0.0
float_val: 255.0
float_val: 255.0
float_val: 0.0
float_val: 255.0
float_val: 255
float_val: 0
float_val: 0
float_val: 0
float_val: 255
float_val: 0
float_val: 0
float_val: 0
float_val: 255
float_val: 255
float_val: 0
float_val: 255
}
metadata {
plugin_data {

View File

@ -2,7 +2,7 @@ value {
tag: "test_scalar"
tensor {
dtype: DT_FLOAT
float_val: 1.0
float_val: 1
}
metadata {
plugin_data {

View File

@ -82,6 +82,34 @@ class BaseTestCase(TestCase):
if os.path.exists(temp_dir):
shutil.rmtree(temp_dir)
def assertProto(self, str_to_compare):
if expecttest.ACCEPT:
write_proto(str_to_compare, self)
return True
expected = read_expected_content(self)
str_to_compare = str(str_to_compare)
self.assertEqual(remove_whitespace(str_to_compare), remove_whitespace(expected))
def assertImageProto(self, actual_proto):
if expecttest.ACCEPT:
expected_file = get_expected_file(self)
with open(expected_file, "w") as f:
f.write(text_format.MessageToString(actual_proto))
return True
expected_str = read_expected_content(self)
expected_proto = Summary()
text_format.Parse(expected_str, expected_proto)
[actual, expected] = [actual_proto.value[0], expected_proto.value[0]]
actual_img = Image.open(io.BytesIO(actual.image.encoded_image_string))
expected_img = Image.open(io.BytesIO(expected.image.encoded_image_string))
self.assertEqual(actual.tag, expected.tag)
self.assertEqual(actual.image.height, expected.image.height)
self.assertEqual(actual.image.width, expected.image.width)
self.assertEqual(actual.image.colorspace, expected.image.colorspace)
self.assertEqual(actual_img, expected_img)
if TEST_TENSORBOARD:
from google.protobuf import text_format
@ -417,58 +445,40 @@ class TestTensorBoardSummary(BaseTestCase):
summary.histogram("dummy", np.ndarray(0), "tensorflow")
def test_image_with_boxes(self):
self.assertTrue(
compare_image_proto(
summary.image_boxes(
"dummy", tensor_N(shape=(3, 32, 32)), np.array([[10, 10, 40, 40]])
),
self,
self.assertImageProto(
summary.image_boxes(
"dummy", tensor_N(shape=(3, 32, 32)), np.array([[10, 10, 40, 40]])
)
)
def test_image_with_one_channel(self):
self.assertTrue(
compare_image_proto(
summary.image("dummy", tensor_N(shape=(1, 8, 8)), dataformats="CHW"),
self,
)
) # noqa: E131
self.assertImageProto(
summary.image("dummy", tensor_N(shape=(1, 8, 8)), dataformats="CHW")
)
def test_image_with_one_channel_batched(self):
self.assertTrue(
compare_image_proto(
summary.image(
"dummy", tensor_N(shape=(2, 1, 8, 8)), dataformats="NCHW"
),
self,
)
) # noqa: E131
self.assertImageProto(
summary.image("dummy", tensor_N(shape=(2, 1, 8, 8)), dataformats="NCHW")
)
def test_image_with_3_channel_batched(self):
self.assertTrue(
compare_image_proto(
summary.image(
"dummy", tensor_N(shape=(2, 3, 8, 8)), dataformats="NCHW"
),
self,
)
) # noqa: E131
self.assertImageProto(
summary.image("dummy", tensor_N(shape=(2, 3, 8, 8)), dataformats="NCHW")
)
def test_image_without_channel(self):
self.assertTrue(
compare_image_proto(
summary.image("dummy", tensor_N(shape=(8, 8)), dataformats="HW"), self
)
) # noqa: E131
self.assertImageProto(
summary.image("dummy", tensor_N(shape=(8, 8)), dataformats="HW")
)
def test_video(self):
try:
import moviepy # noqa: F401
except ImportError:
return
self.assertTrue(
compare_proto(summary.video("dummy", tensor_N(shape=(4, 3, 1, 8, 8))), self)
)
self.assertProto(summary.video("dummy", tensor_N(shape=(4, 3, 1, 8, 8))))
summary.video("dummy", np.random.rand(16, 48, 1, 28, 28))
summary.video("dummy", np.random.rand(20, 7, 1, 8, 8))
@ -477,52 +487,37 @@ class TestTensorBoardSummary(BaseTestCase):
)
@xfailIfS390X
def test_audio(self):
self.assertTrue(
compare_proto(summary.audio("dummy", tensor_N(shape=(42,))), self)
)
self.assertProto(summary.audio("dummy", tensor_N(shape=(42,))))
@unittest.skipIf(
IS_MACOS, "Skipping on mac, see https://github.com/pytorch/pytorch/pull/109349 "
)
def test_text(self):
self.assertTrue(compare_proto(summary.text("dummy", "text 123"), self))
self.assertProto(summary.text("dummy", "text 123"))
@unittest.skipIf(
IS_MACOS, "Skipping on mac, see https://github.com/pytorch/pytorch/pull/109349 "
)
def test_histogram_auto(self):
self.assertTrue(
compare_proto(
summary.histogram(
"dummy", tensor_N(shape=(1024,)), bins="auto", max_bins=5
),
self,
)
self.assertProto(
summary.histogram("dummy", tensor_N(shape=(1024,)), bins="auto", max_bins=5)
)
@unittest.skipIf(
IS_MACOS, "Skipping on mac, see https://github.com/pytorch/pytorch/pull/109349 "
)
def test_histogram_fd(self):
self.assertTrue(
compare_proto(
summary.histogram(
"dummy", tensor_N(shape=(1024,)), bins="fd", max_bins=5
),
self,
)
self.assertProto(
summary.histogram("dummy", tensor_N(shape=(1024,)), bins="fd", max_bins=5)
)
@unittest.skipIf(
IS_MACOS, "Skipping on mac, see https://github.com/pytorch/pytorch/pull/109349 "
)
def test_histogram_doane(self):
self.assertTrue(
compare_proto(
summary.histogram(
"dummy", tensor_N(shape=(1024,)), bins="doane", max_bins=5
),
self,
self.assertProto(
summary.histogram(
"dummy", tensor_N(shape=(1024,)), bins="doane", max_bins=5
)
)
@ -548,14 +543,14 @@ class TestTensorBoardSummary(BaseTestCase):
)
f = np.array([[[0, 2, 3], [0, 3, 1], [0, 1, 2], [1, 3, 2]]], dtype=int)
mesh = summary.mesh("my_mesh", vertices=v, colors=c, faces=f, config_dict=None)
self.assertTrue(compare_proto(mesh, self))
self.assertProto(mesh)
@unittest.skipIf(
IS_MACOS, "Skipping on mac, see https://github.com/pytorch/pytorch/pull/109349 "
)
def test_scalar_new_style(self):
scalar = summary.scalar("test_scalar", 1.0, new_style=True)
self.assertTrue(compare_proto(scalar, self))
self.assertProto(scalar)
with self.assertRaises(AssertionError):
summary.scalar("test_scalar2", torch.Tensor([1, 2, 3]), new_style=True)
@ -585,38 +580,6 @@ def read_expected_content(function_ptr):
return f.read()
def compare_image_proto(actual_proto, function_ptr):
if expecttest.ACCEPT:
expected_file = get_expected_file(function_ptr)
with open(expected_file, "w") as f:
f.write(text_format.MessageToString(actual_proto))
return True
expected_str = read_expected_content(function_ptr)
expected_proto = Summary()
text_format.Parse(expected_str, expected_proto)
[actual, expected] = [actual_proto.value[0], expected_proto.value[0]]
actual_img = Image.open(io.BytesIO(actual.image.encoded_image_string))
expected_img = Image.open(io.BytesIO(expected.image.encoded_image_string))
return (
actual.tag == expected.tag
and actual.image.height == expected.image.height
and actual.image.width == expected.image.width
and actual.image.colorspace == expected.image.colorspace
and actual_img == expected_img
)
def compare_proto(str_to_compare, function_ptr):
if expecttest.ACCEPT:
write_proto(str_to_compare, function_ptr)
return True
expected = read_expected_content(function_ptr)
str_to_compare = str(str_to_compare)
return remove_whitespace(str_to_compare) == remove_whitespace(expected)
def write_proto(str_to_compare, function_ptr):
expected_file = get_expected_file(function_ptr)
with open(expected_file, "w") as f:
@ -657,7 +620,6 @@ class TestTensorBoardPytorchGraph(BaseTestCase):
)
def test_nested_nn_squential(self):
dummy_input = torch.randn(2, 3)
class InnerNNSquential(torch.nn.Module):