Skip to content

Commit c2c93e0

Browse files
committed
Rename ModuleLinear -> ModuleAddMul
In export_program, the `ModuleLinear` is a decomposed add mul. Renaming it to addmul, so that we can add a ModuleLinear that calls nn.Linear for backend program-data separation testing. Differential Revision: [D73679750](https://our.internmc.facebook.com/intern/diff/D73679750/) ghstack-source-id: 280754574 Pull Request resolved: #10529
1 parent af726cd commit c2c93e0

File tree

13 files changed

+44
-43
lines changed

13 files changed

+44
-43
lines changed

codegen/tools/targets.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def define_common_targets(is_fbcode = False):
179179
srcs = ["test/test_gen_oplist_real_model.py"],
180180
base_module = "",
181181
resources = {
182-
"//executorch/test/models:exported_programs[ModuleLinear.pte]": "test/ModuleLinear.pte",
182+
"//executorch/test/models:exported_programs[ModuleAddMul.pte]": "test/ModuleAddMul.pte",
183183
},
184184
visibility = [
185185
"//executorch/...",

codegen/tools/test/test_gen_oplist_real_model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from libfb.py import parutil # type: ignore[import-not-found]
1717

18-
MODEL_PATH: Final[str] = parutil.get_file_path("ModuleLinear.pte", pkg=__package__)
18+
MODEL_PATH: Final[str] = parutil.get_file_path("ModuleAddMul.pte", pkg=__package__)
1919

2020

2121
class TestGenOplistRealModel(unittest.TestCase):

extension/flat_tensor/flat_tensor_data_map.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ ET_NODISCARD Result<const char*> FlatTensorDataMap::get_key(
253253
index,
254254
num_keys);
255255

256-
if (flat_tensor_->named_data() != nullptr && index < flat_tensor_->named_data()->size()) {
256+
if (flat_tensor_->named_data() != nullptr &&
257+
index < flat_tensor_->named_data()->size()) {
257258
return flat_tensor_->named_data()->Get(index)->key()->c_str();
258259
} else {
259260
if (flat_tensor_->named_data() != nullptr) {

extension/flat_tensor/test/CMakeLists.txt

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
1919
include(${EXECUTORCH_ROOT}/tools/cmake/Test.cmake)
2020

2121
add_custom_command(
22-
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ModuleLinearProgram.pte"
23-
"${CMAKE_CURRENT_BINARY_DIR}/ModuleLinearProgram.ptd"
22+
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.pte"
23+
"${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.ptd"
2424
COMMAND
25-
python -m test.models.export_program --modules "ModuleLinear"
25+
python -m test.models.export_program --modules "ModuleAddMul"
2626
--external-constants --outdir "${CMAKE_CURRENT_BINARY_DIR}" 2> /dev/null
2727
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
2828
)
2929

3030
add_custom_target(
3131
extension_flat_tensor_test_resources
32-
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/ModuleLinearProgram.pte"
33-
"${CMAKE_CURRENT_BINARY_DIR}/ModuleLinearProgram.ptd"
32+
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.pte"
33+
"${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.ptd"
3434
)
3535

3636
set(test_env
37-
"ET_MODULE_LINEAR_PROGRAM_PATH=${CMAKE_CURRENT_BINARY_DIR}/ModuleLinearProgram.pte"
38-
"ET_MODULE_LINEAR_DATA_PATH=${CMAKE_CURRENT_BINARY_DIR}/ModuleLinearProgram.ptd"
37+
"ET_MODULE_ADD_MUL_PROGRAM_PATH=${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.pte"
38+
"ET_MODULE_ADD_MUL_DATA_PATH=${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.ptd"
3939
)
4040

4141
set(_test_srcs flat_tensor_data_map_test.cpp flat_tensor_header_test.cpp)

extension/flat_tensor/test/flat_tensor_data_map_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class FlatTensorDataMapTest : public ::testing::Test {
3535

3636
// Load data map. The eager linear model is defined at:
3737
// //executorch/test/models/linear_model.py
38-
const char* path = std::getenv("ET_MODULE_LINEAR_DATA_PATH");
38+
const char* path = std::getenv("ET_MODULE_ADD_MUL_DATA_PATH");
3939
Result<FileDataLoader> loader = FileDataLoader::from(path);
4040
ASSERT_EQ(loader.error(), Error::Ok);
4141

extension/flat_tensor/test/targets.bzl

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def define_common_targets(is_fbcode=False):
3535
# The tests use this var to find the program file to load. This uses
3636
# an fbcode target path because the authoring/export tools
3737
# intentionally don't work in xplat (since they're host-only tools).
38-
"ET_MODULE_LINEAR_PROGRAM_PATH": "$(location fbcode//executorch/test/models:exported_program_and_data[ModuleLinear.pte])",
39-
"ET_MODULE_LINEAR_DATA_PATH": "$(location fbcode//executorch/test/models:exported_program_and_data[ModuleLinear.ptd])",
38+
"ET_MODULE_ADD_MUL_PROGRAM_PATH": "$(location fbcode//executorch/test/models:exported_program_and_data[ModuleAddMul.pte])",
39+
"ET_MODULE_ADD_MUL_DATA_PATH": "$(location fbcode//executorch/test/models:exported_program_and_data[ModuleAddMul.ptd])",
4040
}
4141

4242
runtime.cxx_test(

extension/training/module/test/state_dict_util_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class LoadStateDictTest : public ::testing::Test {
3636
// Load data map.
3737
// The eager linear model is defined at:
3838
// //executorch/test/models/linear_model.py
39-
const char* path = std::getenv("ET_MODULE_LINEAR_DATA_PATH");
39+
const char* path = std::getenv("ET_MODULE_ADD_MUL_DATA_PATH");
4040
Result<FileDataLoader> loader = FileDataLoader::from(path);
4141
ASSERT_EQ(loader.error(), Error::Ok);
4242

extension/training/module/test/targets.bzl

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def define_common_targets(is_fbcode = False):
1616
# an fbcode target path because the authoring/export tools
1717
# intentionally don't work in xplat (since they're host-only tools).
1818
"ET_MODULE_ADD_PATH": "$(location fbcode//executorch/test/models:exported_programs[ModuleAdd.pte])",
19-
"ET_MODULE_LINEAR_DATA_PATH": "$(location fbcode//executorch/test/models:exported_program_and_data[ModuleLinear.ptd])",
20-
"ET_MODULE_LINEAR_PROGRAM_PATH": "$(location fbcode//executorch/test/models:exported_program_and_data[ModuleLinear.pte])",
19+
"ET_MODULE_ADD_MUL_DATA_PATH": "$(location fbcode//executorch/test/models:exported_program_and_data[ModuleAddMul.ptd])",
20+
"ET_MODULE_ADD_MUL_PROGRAM_PATH": "$(location fbcode//executorch/test/models:exported_program_and_data[ModuleAddMul.pte])",
2121
"ET_MODULE_TRAIN_DATA_PATH": "$(location fbcode//executorch/test/models:exported_program_and_data[ModuleSimpleTrain.ptd])",
2222
"ET_MODULE_TRAIN_PROGRAM_PATH": "$(location fbcode//executorch/test/models:exported_program_and_data[ModuleSimpleTrainProgram.pte])",
2323
"ET_MODULE_SIMPLE_TRAIN_PATH": "$(location fbcode//executorch/test/models:exported_programs[ModuleSimpleTrain.pte])",

runtime/executor/test/CMakeLists.txt

+16-16
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
1818
include(${EXECUTORCH_ROOT}/tools/cmake/Test.cmake)
1919

2020
add_custom_command(
21-
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ModuleAddHalf.pte"
22-
"${CMAKE_CURRENT_BINARY_DIR}/ModuleAdd.pte"
21+
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ModuleAdd.pte"
22+
"${CMAKE_CURRENT_BINARY_DIR}/ModuleAddHalf.pte"
23+
"${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMul.pte"
24+
"${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.pte"
25+
"${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.ptd"
2326
"${CMAKE_CURRENT_BINARY_DIR}/ModuleDynamicCatUnallocatedIO.pte"
2427
"${CMAKE_CURRENT_BINARY_DIR}/ModuleIndex.pte"
25-
"${CMAKE_CURRENT_BINARY_DIR}/ModuleLinear.pte"
26-
"${CMAKE_CURRENT_BINARY_DIR}/ModuleLinearProgram.pte"
27-
"${CMAKE_CURRENT_BINARY_DIR}/ModuleLinearProgram.ptd"
2828
"${CMAKE_CURRENT_BINARY_DIR}/ModuleMultipleEntry.pte"
2929
"${CMAKE_CURRENT_BINARY_DIR}/ModuleSimpleTrain.pte"
3030
"${CMAKE_CURRENT_BINARY_DIR}/ModuleStateful.pte"
3131
COMMAND
3232
python3 -m test.models.export_program --modules
33-
"ModuleAdd,ModuleAddHalf,ModuleDynamicCatUnallocatedIO,ModuleIndex,ModuleLinear,ModuleMultipleEntry,ModuleSimpleTrain,ModuleStateful"
33+
"ModuleAdd,ModuleAddHalf,ModuleAddMul,ModuleDynamicCatUnallocatedIO,ModuleIndex,ModuleMultipleEntry,ModuleSimpleTrain,ModuleStateful"
3434
--outdir "${CMAKE_CURRENT_BINARY_DIR}" 2> /dev/null
3535
COMMAND
36-
python3 -m test.models.export_program --modules "ModuleLinear"
36+
python3 -m test.models.export_program --modules "ModuleAddMul"
3737
--external-constants --outdir "${CMAKE_CURRENT_BINARY_DIR}" 2> /dev/null
3838
COMMAND
3939
python3 -m test.models.export_delegated_program --modules "ModuleAddMul"
@@ -43,27 +43,27 @@ add_custom_command(
4343

4444
add_custom_target(
4545
generated_pte_files
46-
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/ModuleAddHalf.pte"
47-
"${CMAKE_CURRENT_BINARY_DIR}/ModuleAdd.pte"
46+
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/ModuleAdd.pte"
47+
"${CMAKE_CURRENT_BINARY_DIR}/ModuleAddHalf.pte"
48+
"${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMul.pte"
49+
"${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.pte"
50+
"${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.ptd"
4851
"${CMAKE_CURRENT_BINARY_DIR}/ModuleDynamicCatUnallocatedIO.pte"
4952
"${CMAKE_CURRENT_BINARY_DIR}/ModuleIndex.pte"
50-
"${CMAKE_CURRENT_BINARY_DIR}/ModuleLinear.pte"
51-
"${CMAKE_CURRENT_BINARY_DIR}/ModuleLinearProgram.pte"
52-
"${CMAKE_CURRENT_BINARY_DIR}/ModuleLinearProgram.ptd"
5353
"${CMAKE_CURRENT_BINARY_DIR}/ModuleMultipleEntry.pte"
5454
"${CMAKE_CURRENT_BINARY_DIR}/ModuleSimpleTrain.pte"
5555
"${CMAKE_CURRENT_BINARY_DIR}/ModuleStateful.pte"
5656
)
5757

5858
set(test_env
5959
"DEPRECATED_ET_MODULE_LINEAR_CONSTANT_BUFFER_PATH=${EXECUTORCH_ROOT}/test/models/deprecated/ModuleLinear-no-constant-segment.pte"
60-
"ET_MODULE_ADD_HALF_PATH=${CMAKE_CURRENT_BINARY_DIR}/ModuleAddHalf.pte"
6160
"ET_MODULE_ADD_PATH=${CMAKE_CURRENT_BINARY_DIR}/ModuleAdd.pte"
61+
"ET_MODULE_ADD_HALF_PATH=${CMAKE_CURRENT_BINARY_DIR}/ModuleAddHalf.pte"
62+
"ET_MODULE_ADD_MUL_PATH=${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMul.pte"
63+
"ET_MODULE_ADD_MUL_PROGRAM_PATH=${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.pte"
64+
"ET_MODULE_ADD_MUL_DATA_PATH=${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.ptd"
6265
"ET_MODULE_DYNAMIC_CAT_UNALLOCATED_IO_PATH=${CMAKE_CURRENT_BINARY_DIR}/ModuleDynamicCatUnallocatedIO.pte"
6366
"ET_MODULE_INDEX_PATH=${CMAKE_CURRENT_BINARY_DIR}/ModuleIndex.pte"
64-
"ET_MODULE_LINEAR_PATH=${CMAKE_CURRENT_BINARY_DIR}/ModuleLinear.pte"
65-
"ET_MODULE_LINEAR_PROGRAM_PATH=${CMAKE_CURRENT_BINARY_DIR}/ModuleLinearProgram.pte"
66-
"ET_MODULE_LINEAR_DATA_PATH=${CMAKE_CURRENT_BINARY_DIR}/ModuleLinearProgram.ptd"
6767
"ET_MODULE_MULTI_ENTRY_PATH=${CMAKE_CURRENT_BINARY_DIR}/ModuleMultipleEntry.pte"
6868
"ET_MODULE_SIMPLE_TRAIN_PATH=${CMAKE_CURRENT_BINARY_DIR}/ModuleSimpleTrain.pte"
6969
"ET_MODULE_STATEFUL_PATH=${CMAKE_CURRENT_BINARY_DIR}/ModuleStateful.pte"

runtime/executor/test/program_test.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ TEST_F(ProgramTest, LoadConstantSegmentWithNoConstantSegment) {
415415
}
416416

417417
TEST_F(ProgramTest, LoadConstantSegment) {
418-
// Load the serialized ModuleLinear data, with constants in the segment.
419-
const char* linear_path = std::getenv("ET_MODULE_LINEAR_PATH");
418+
// Load the serialized ModuleAddMul data, with constants in the segment.
419+
const char* linear_path = std::getenv("ET_MODULE_ADD_MUL_PATH");
420420
Result<FileDataLoader> linear_loader = FileDataLoader::from(linear_path);
421421
ASSERT_EQ(linear_loader.error(), Error::Ok);
422422

@@ -458,7 +458,7 @@ TEST_F(ProgramTest, LoadConstantSegment) {
458458
}
459459

460460
TEST_F(ProgramTest, LoadConstantSegmentWhenConstantBufferExists) {
461-
// Load the serialized ModuleLinear data, with constants in the flatbuffer and
461+
// Load the serialized ModuleAddMul data, with constants in the flatbuffer and
462462
// no constants in the segment.
463463
const char* linear_path =
464464
std::getenv("DEPRECATED_ET_MODULE_LINEAR_CONSTANT_BUFFER_PATH");

runtime/executor/test/targets.bzl

+3-3
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ def define_common_targets(is_fbcode = False):
119119
"ET_MODULE_ADD_PATH": "$(location fbcode//executorch/test/models:exported_programs[ModuleAdd.pte])",
120120
"ET_MODULE_DYNAMIC_CAT_UNALLOCATED_IO_PATH": "$(location fbcode//executorch/test/models:exported_programs[ModuleDynamicCatUnallocatedIO.pte])",
121121
"ET_MODULE_INDEX_PATH": "$(location fbcode//executorch/test/models:exported_programs[ModuleIndex.pte])",
122-
"ET_MODULE_LINEAR_PATH": "$(location fbcode//executorch/test/models:exported_programs[ModuleLinear.pte])",
122+
"ET_MODULE_ADD_MUL_PATH": "$(location fbcode//executorch/test/models:exported_programs[ModuleLinear.pte])",
123123
"ET_MODULE_MULTI_ENTRY_PATH": "$(location fbcode//executorch/test/models:exported_programs[ModuleMultipleEntry.pte])",
124124
"ET_MODULE_SIMPLE_TRAIN_PATH": "$(location fbcode//executorch/test/models:exported_programs[ModuleSimpleTrain.pte])",
125125
"ET_MODULE_STATEFUL_PATH": "$(location fbcode//executorch/test/models:exported_programs[ModuleStateful.pte])",
126-
"ET_MODULE_LINEAR_PROGRAM_PATH": "$(location fbcode//executorch/test/models:exported_program_and_data[ModuleLinear.pte])",
127-
"ET_MODULE_LINEAR_DATA_PATH": "$(location fbcode//executorch/test/models:exported_program_and_data[ModuleLinear.ptd])",
126+
"ET_MODULE_ADD_MUL_PROGRAM_PATH": "$(location fbcode//executorch/test/models:exported_program_and_data[ModuleLinear.pte])",
127+
"ET_MODULE_ADD_MUL_DATA_PATH": "$(location fbcode//executorch/test/models:exported_program_and_data[ModuleLinear.ptd])",
128128
}
129129

130130
runtime.cxx_test(

test/models/export_program.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def get_export_kwargs():
131131
return {"capture_config": CaptureConfig(pt2_mode=True, enable_aot=True)}
132132

133133

134-
class ModuleLinear(torch.nn.Module):
134+
class ModuleAddMul(torch.nn.Module):
135135
def __init__(self):
136136
super().__init__()
137137
self.a = 3 * torch.ones(2, 2, dtype=torch.float)

test/models/targets.bzl

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def define_common_targets():
6161
MODULES_TO_EXPORT = [
6262
"ModuleAdd",
6363
"ModuleAddHalf",
64+
"ModuleAddMul",
6465
"ModuleBasic",
65-
"ModuleLinear",
6666
"ModuleMultipleEntry",
6767
"ModuleIndex",
6868
"ModuleDynamicCatUnallocatedIO",
@@ -94,16 +94,16 @@ def define_common_targets():
9494

9595
# Class names of nn.Modules for :exported_programs to export.
9696
MODULES_AND_DATA_TO_EXPORT = [
97-
"ModuleLinear",
97+
"ModuleAddMul",
9898
"ModuleSimpleTrain",
9999
]
100100

101101
runtime.genrule(
102102
name = "exported_program_and_data",
103103
cmd = "$(exe :export_program) --modules " + ",".join(MODULES_AND_DATA_TO_EXPORT) + " --external-constants --outdir $OUT",
104104
outs = {
105-
"ModuleLinear.pte": ["ModuleLinearProgram.pte"],
106-
"ModuleLinear.ptd": ["ModuleLinearProgram.ptd"],
105+
"ModuleAddMul.pte": ["ModuleAddMulProgram.pte"],
106+
"ModuleAddMul.ptd": ["ModuleAddMulProgram.ptd"],
107107
"ModuleSimpleTrainProgram.pte": ["ModuleSimpleTrainProgram.pte"],
108108
"ModuleSimpleTrain.ptd": ["ModuleSimpleTrainProgram.ptd"],
109109
},

0 commit comments

Comments
 (0)