Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6f780c7

Browse files
Sync scalar_type.fbs and extend test to check all copies (pytorch#17085)
Fixes pytorch#11572 This PR: 1. Extends the existing test in `devtools/bundled_program/schema/test/test_schema.py` to check all 4 copies of `scalar_type.fbs` 2. Syncs `extension/flat_tensor/serialize/scalar_type.fbs` which was out of date (missing FLOAT8E* and UINT* types) The test now validates that these 4 files remain in sync: - `schema/scalar_type.fbs` (canonical) - `devtools/bundled_program/schema/scalar_type.fbs` - `devtools/etdump/scalar_type.fbs` - `extension/flat_tensor/serialize/scalar_type.fbs` Uses `subTest()` for clearer error messages when files drift out of sync. --------- Co-authored-by: Copilot <[email protected]>
1 parent 8e99f3b commit 6f780c7

5 files changed

Lines changed: 64 additions & 38 deletions

File tree

devtools/bundled_program/schema/test/BUCK

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,3 @@ oncall("executorch")
77
# !!!! fbcode/executorch/devtools/bundled_program/schema/test/TARGETS was merged into this file, see https://fburl.com/workplace/xl8l9yuo for more info !!!!
88

99
load("@fbcode_macros//build_defs:python_unittest.bzl", "python_unittest")
10-
11-
12-
fbcode_target(_kind = python_unittest,
13-
name = "schema",
14-
srcs = [
15-
"test_schema.py",
16-
],
17-
)

devtools/bundled_program/schema/test/test_schema.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

extension/flat_tensor/serialize/scalar_type.fbs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// Copyright (c) Meta Platforms, Inc. and affiliates.
22

33
//
4-
// See executorch/schema/README.md before modifying this file.
4+
// See README.md before modifying this file.
55
//
66

7-
// TODO(T207893511): sync scalar_type.fbs copies across ExecuTorch repo.
87
namespace executorch_flatbuffer;
98

109
// The scalar data type.
@@ -19,14 +18,20 @@ enum ScalarType : byte {
1918
FLOAT = 6,
2019
DOUBLE = 7,
2120
BOOL = 11,
22-
// TODO(jakeszwe): Verify these are unused and then remove support
2321
QINT8 = 12,
2422
QUINT8 = 13,
2523
QINT32 = 14,
2624
BFLOAT16 = 15,
2725
QUINT4X2 = 16,
2826
QUINT2X4 = 17,
2927
BITS16 = 22,
28+
FLOAT8E5M2 = 23,
29+
FLOAT8E4M3FN = 24,
30+
FLOAT8E5M2FNUZ = 25,
31+
FLOAT8E4M3FNUZ = 26,
32+
UINT16 = 27,
33+
UINT32 = 28,
34+
UINT64 = 29,
3035
// Types currently not implemented.
3136
// COMPLEXHALF = 8,
3237
// COMPLEXFLOAT = 9,

pytest.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ addopts =
105105
runtime
106106
# Ignore tests with missing compiler dependencies
107107
--ignore=runtime/test/test_runtime_etdump_gen.py
108+
109+
# schema
110+
schema/
111+
108112
# test
109113
test/
110114
# Ignore tests with missing dependencies

schema/test/test_schema.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# pyre-strict
8+
9+
import filecmp
10+
import os
11+
import unittest
12+
13+
14+
class TestSchema(unittest.TestCase):
15+
def test_schema_sync(self) -> None:
16+
"""Test that all copies of scalar_type.fbs are in sync.
17+
18+
Flatbuffers expects all included files to be in the same directory.
19+
For example, program.fbs includes scalar_type.fbs, and must be in the
20+
same directory. As most of the schema files in executorch include
21+
scalar_type.fbs, it is copied in several places across the executorch
22+
repo. This test ensures they all remain in sync with the canonical
23+
version in schema/scalar_type.fbs.
24+
25+
See https://github.com/pytorch/executorch/issues/11572
26+
"""
27+
# make the test work in both internal and oss.
28+
prefix = (
29+
"executorch/" if os.path.exists("executorch/schema/scalar_type.fbs") else ""
30+
)
31+
32+
# The canonical source of truth
33+
canonical_path = prefix + "schema/scalar_type.fbs"
34+
35+
# All copies that must stay in sync with the canonical version
36+
copies = [
37+
prefix + "devtools/bundled_program/schema/scalar_type.fbs",
38+
prefix + "devtools/etdump/scalar_type.fbs",
39+
prefix + "extension/flat_tensor/serialize/scalar_type.fbs",
40+
]
41+
42+
for copy_path in copies:
43+
with self.subTest(copy=copy_path):
44+
self.assertTrue(
45+
filecmp.cmp(canonical_path, copy_path, shallow=False),
46+
f"scalar_type.fbs is out of sync: {copy_path} differs from {canonical_path}. "
47+
f"Please sync the schema by copying from {canonical_path}.",
48+
)
49+
50+
51+
if __name__ == "__main__":
52+
unittest.main()

0 commit comments

Comments
 (0)