Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TorchFX] Export to torch.export.export_for_training #3075

Merged

Conversation

daniil-lyakhov
Copy link
Collaborator

@daniil-lyakhov daniil-lyakhov commented Nov 11, 2024

Changes

  • TorchFX Unit tests are moved from torch._export.capture_pre_autograd_graph to torch.export.export_for_training
    ALL REFERENCE GRAPHS WERE VALIDATED MANUALLY
  • BC types for fuse_bn_node are updated
  • NNCFGraphBuilder is updated to support a batch-norm type with only one output node (instead of three)
  • Model extractor does not traverse down from constans to prevent redundant nodes in the extracted model when the constant is shared
  • shared_constants_unification_transformation is removed
  • Tests which require capture_pre_autograd_graph are removed

Reason for changes

  • To migrate to the lates and recommended export method for TorchFX backend

Related tickets

#2766
#2987

Tests

test_shared_constants_unification_not_connected_const
post_training_quantization/540/ is finished successfully

@github-actions github-actions bot added NNCF PT Pull requests that updates NNCF PyTorch experimental labels Nov 11, 2024
@daniil-lyakhov daniil-lyakhov force-pushed the dl/fx/export_for_training branch 2 times, most recently from a33ce2e to 78f8588 Compare November 12, 2024 10:27
@daniil-lyakhov daniil-lyakhov force-pushed the dl/fx/export_for_training branch from 2d8f400 to 707d4cd Compare November 12, 2024 10:51
@daniil-lyakhov daniil-lyakhov marked this pull request as ready for review November 12, 2024 12:19
@daniil-lyakhov daniil-lyakhov requested a review from a team as a code owner November 12, 2024 12:19
@daniil-lyakhov daniil-lyakhov force-pushed the dl/fx/export_for_training branch from 84d4039 to 68bb7b6 Compare November 12, 2024 13:12
@@ -120,6 +128,10 @@ def pytest_configure(config: Config):
if regen_dot:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if I would like to update json files only?

Copy link
Contributor

@anzr299 anzr299 Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regen_dot was added there by mistake, I have updated the suggestion. https://github.com/openvinotoolkit/nncf/pull/3075/files/68bb7b6f09bba89935ae44a7aff6e8f3bee237ea#r1841827740

@@ -384,17 +380,53 @@ def count_constants(model: torch.fx.GraphModule) -> int:
return num_constant_nodes


@pytest.mark.skipif(sys.platform.startswith("win"), reason="capture_pre_autograd_graph is not supported on Windows")
def test_create_shared_constant_transformation():
model = MultiBranchesConnectedModel()
ex_inputs = torch.ones((1, 3, 3, 3))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you suggest we remove this transformation completely? Since, the shared nodes are taken care of now that we are using torch.export.export_for_training and we do not necessarily need to support torch._export.capture_pre_autograd

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

tests/torch/ptq/test_weights_compression.py Show resolved Hide resolved
Copy link
Contributor

@alexsu52 alexsu52 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove support for capture_pre_autograd form the tests.

@@ -384,17 +380,53 @@ def count_constants(model: torch.fx.GraphModule) -> int:
return num_constant_nodes


@pytest.mark.skipif(sys.platform.startswith("win"), reason="capture_pre_autograd_graph is not supported on Windows")
def test_create_shared_constant_transformation():
model = MultiBranchesConnectedModel()
ex_inputs = torch.ones((1, 3, 3, 3))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -120,6 +128,10 @@ def pytest_configure(config: Config):
if regen_dot:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if I would like to update json files only?

@daniil-lyakhov
Copy link
Collaborator Author

Please remove support for capture_pre_autograd form the tests.

capture_pre_autograd is completely removed from unit tests

Comment on lines 128 to 134
if regen_dot:
os.environ["NNCF_TEST_REGEN_DOT"] = "1"

regen_json = config.getoption("--regen-json", False)
if regen_json:
os.environ["NNCF_TEST_REGEN_JSON"] = "1"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if regen_dot:
os.environ["NNCF_TEST_REGEN_DOT"] = "1"
regen_json = config.getoption("--regen-json", False)
if regen_json:
os.environ["NNCF_TEST_REGEN_JSON"] = "1"
for option, var in [("--regen-dot", "NNCF_TEST_REGEN_DOT"), ("--regen-json", "NNCF_TEST_REGEN_JSON")]:
regen = config.getoption(option, False)
if regen:
os.environ[env_var] = "1"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, please check

@daniil-lyakhov daniil-lyakhov force-pushed the dl/fx/export_for_training branch from 9e946ee to 29f15e0 Compare November 14, 2024 09:30
@alexsu52 alexsu52 merged commit 90d15a6 into openvinotoolkit:develop Nov 14, 2024
14 checks passed
daniil-lyakhov added a commit to daniil-lyakhov/nncf that referenced this pull request Nov 14, 2024
…it#3075)

### Changes

* TorchFX Unit tests are moved from
`torch._export.capture_pre_autograd_graph` to
`torch.export.export_for_training`
ALL REFERENCE GRAPHS WERE VALIDATED MANUALLY 
* BC types for `fuse_bn_node` are updated
* NNCFGraphBuilder is updated to support a batch-norm type with only one
output node (instead of three)
* Model extractor does not traverse down from constans to prevent
redundant nodes in the extracted model when the constant is shared
* `shared_constants_unification_transformation` is removed
* Tests which require `capture_pre_autograd_graph` are removed

### Reason for changes

* To migrate to the lates and recommended export method for TorchFX
backend

### Related tickets

openvinotoolkit#2766 

### Tests

test_shared_constants_unification_not_connected_const
post_training_quantization/540/ is finished successfully
KodiaqQ pushed a commit that referenced this pull request Nov 14, 2024
PR #3075 to the release branch:

### Changes

* TorchFX Unit tests are moved from
`torch._export.capture_pre_autograd_graph` to
`torch.export.export_for_training`
ALL REFERENCE GRAPHS WERE VALIDATED MANUALLY 
* BC types for `fuse_bn_node` are updated
* NNCFGraphBuilder is updated to support a batch-norm type with only one
output node (instead of three)
* Model extractor does not traverse down from constans to prevent
redundant nodes in the extracted model when the constant is shared
* `shared_constants_unification_transformation` is removed
* Tests which require `capture_pre_autograd_graph` are removed

### Reason for changes

* To migrate to the lates and recommended export method for TorchFX
backend

### Related tickets

#2766 

### Tests

test_shared_constants_unification_not_connected_const
post_training_quantization/540/ is finished successfully
nikita-savelyevv pushed a commit to nikita-savelyevv/nncf that referenced this pull request Dec 11, 2024
…it#3075)

### Changes

* TorchFX Unit tests are moved from
`torch._export.capture_pre_autograd_graph` to
`torch.export.export_for_training`
ALL REFERENCE GRAPHS WERE VALIDATED MANUALLY 
* BC types for `fuse_bn_node` are updated
* NNCFGraphBuilder is updated to support a batch-norm type with only one
output node (instead of three)
* Model extractor does not traverse down from constans to prevent
redundant nodes in the extracted model when the constant is shared
* `shared_constants_unification_transformation` is removed
* Tests which require `capture_pre_autograd_graph` are removed

### Reason for changes

* To migrate to the lates and recommended export method for TorchFX
backend

### Related tickets

openvinotoolkit#2766 

### Tests

test_shared_constants_unification_not_connected_const
post_training_quantization/540/ is finished successfully
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
experimental NNCF PT Pull requests that updates NNCF PyTorch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants