[FX] Fix python code generation for wrapped getattr() with default value (#64271)
authorPatrick Hu <patrickhu@fb.com>
Wed, 1 Sep 2021 17:49:39 +0000 (10:49 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Wed, 1 Sep 2021 18:30:27 +0000 (11:30 -0700)
commitc6505cc3837eb903f98163e40fad638a1cfeb502
treecd8d30c888c613d5cc27f3b71d79c71596ecb03b
parent87d8ab6e50314f72ea6730250904fe7ff073cc21
[FX] Fix python code generation for wrapped getattr() with default value (#64271)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/64271

Closes #60417

Modified emit_node() in fx/graph.py to generate getattr() call with default value when len(node.args) != 2 instead of accessing the attribute.
Added test_torch_fx_getattr() in test/test_fx.py.

Test Plan:
pytest test/test_fx.py

Imported from OSS

Reviewed By: jamesr66a

Differential Revision: D30671265

fbshipit-source-id: f2db9ea47e0cb247547e200684f715aab006c374
test/test_fx.py
torch/fx/graph.py