Skip to content

Commit 9051a2f

Browse files
authored
Add better debug print for failed prepare (#3950)
Add better debug print for failed prepare (#3950) Summary: Pull Request resolved: #3950 If you pass a "raw" graph_module from an exported module, prepare will fail. It is not immediately clear why. This PR makes it more clear. Differential Revision: D94379595
1 parent 96a9cdf commit 9051a2f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

torchao/quantization/pt2e/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,13 @@ def _is_connected(source: torch.fx.Node, dest: torch.fx.Node) -> bool:
595595
def _get_tensor_constant_from_node(node, m):
596596
if node is None:
597597
return None
598-
assert node.op == "get_attr"
598+
if node.op == "placeholder":
599+
raise ValueError(
600+
"Expected get_attr node, got placeholder. "
601+
"If working with an ExportedProgram, make sure you are using .module()"
602+
)
603+
if node.op != "get_attr":
604+
raise ValueError(f"Expected get_attr node, got {node.op}")
599605
target_atoms = node.target.split(".")
600606
attr_itr = m
601607
for i, atom in enumerate(target_atoms):

0 commit comments

Comments
 (0)