@@ -47,6 +47,31 @@ def resolve_model_file_path_to_buck_target(model_file_path: str) -> str:
47
47
return real_path
48
48
49
49
50
+ def _raise_if_check_prim_ops_fail (options ):
51
+
52
+ # Error out if we have more than one targets registering prim ops.
53
+ if options .DEBUG_ONLY_check_prim_ops and len (options .DEBUG_ONLY_check_prim_ops ) > 1 :
54
+ assert (
55
+ options .DEBUG_ONLY_check_prim_ops [0 ] == "@"
56
+ ), "DEBUG_ONLY_check_prim_ops is not a valid file path, or it doesn't start with '@'. This is likely a BUCK issue."
57
+
58
+ prim_ops_targets_file = options .DEBUG_ONLY_check_prim_ops [1 :]
59
+ with open (prim_ops_targets_file , "r" ) as file :
60
+ prim_ops_targets = file .read ().split ()
61
+ if len (prim_ops_targets ) > 1 :
62
+ # Yellow bold: \033[33;1m
63
+ # Red bold: \033[31;1m
64
+ # Green bold: \033[32;1m
65
+ error = (
66
+ "It seems this target is depending on more than 1 `prim_ops_registry` targets: "
67
+ + f'\033 [33;1m\n { ", " .join (prim_ops_targets )} \033 [0m. \n This will likely cause errors such as: '
68
+ + "\n \033 [31;1mRe-registering aten::sym_size.int...\033 [0m"
69
+ + "\n To find out the dependency chain, run the following command: "
70
+ + f'\n \033 [32;1mbuck2 cquery <mode> "allpaths(<target>, { prim_ops_targets [0 ]} )"\033 [0m'
71
+ )
72
+ raise Exception (error )
73
+
74
+
50
75
def main (argv : List [Any ]) -> None :
51
76
"""This binary generates 3 files:
52
77
@@ -95,8 +120,18 @@ def main(argv: List[Any]) -> None:
95
120
default = False ,
96
121
required = False ,
97
122
)
123
+ parser .add_argument (
124
+ "--DEBUG-ONLY-check-prim-ops" ,
125
+ "--DEBUG_ONLY_check_prim_ops" ,
126
+ help = (
127
+ "Useful argument to take BUCK targets that registers prim ops and error out if we have more than 1."
128
+ ),
129
+ required = False ,
130
+ )
98
131
options = parser .parse_args (argv )
99
132
133
+ _raise_if_check_prim_ops_fail (options )
134
+
100
135
# Check if the build has any dependency on any selective build target. If we have a target, BUCK shold give us either:
101
136
# 1. a yaml file containing selected ops (could be empty), or
102
137
# 2. a non-empty list of yaml files in the `model_file_list_path` or
@@ -153,14 +188,17 @@ def main(argv: List[Any]) -> None:
153
188
debug_info_2 = "," .join (
154
189
model_dict ["operators" ][op_name ]["debug_info" ]
155
190
)
156
- error = f"Operator { op_name } is used in 2 models: { debug_info_1 } and { debug_info_2 } "
191
+ # Yellow bold: \033[33;1m
192
+ # Red bold: \033[31;1m
193
+ # Green bold: \033[32;1m
194
+ error = f"\033 [31;1mOperator { op_name } is used in 2 models: \033 [33;1m{ debug_info_1 } and { debug_info_2 } \033 [0m"
157
195
if "//" not in debug_info_1 and "//" not in debug_info_2 :
158
196
error += "\n We can't determine what BUCK targets these model files belong to."
159
197
tail = "."
160
198
else :
161
199
error += "\n Please run the following commands to find out where is the BUCK target being added as a dependency to your target:\n "
162
- error += f'\n buck2 cquery <mode> "allpaths(<target>, { debug_info_1 } )"'
163
- error += f'\n buck2 cquery <mode> "allpaths(<target>, { debug_info_2 } )"'
200
+ error += f'\n \033 [32;1mbuck2 cquery <mode> "allpaths(<target>, { debug_info_1 } )"\033 [0m '
201
+ error += f'\n \033 [32;1mbuck2 cquery <mode> "allpaths(<target>, { debug_info_2 } )"\033 [0m '
164
202
tail = "as well as results from BUCK commands listed above."
165
203
166
204
error += (
0 commit comments