[quant][pt2] Fix and rename move_model_to_eval
(#108891)
#109027
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
This commit fixes two silent correctness problems with the current implementation of
move_model_to_eval
:(1) Previously the user had to manually call
eliminate_dead_code
before callingmove_model_to_eval
, otherwise the dropout pattern won't actually get eliminated. This is because subgraph rewriter complains the match is not self-contained, and so silently does not do the replacement.(2) We wish to error when the user calls
model.train()
ormodel.eval()
on an exported model. This error is raised correctly immediately after export today, but no longer raised after the user calls prepare or convert.We fix (1) by moving the
eliminate_dead_code
call intomove_model_to_eval
, and fix (2) by ensuring the respective errors are thrown after prepare and convert as well.Additionally, this commit renames
move_model_to_eval
tomove_exported_model_to_eval
to be more explicit.Test Plan:
python test/test_quantization.py TestQuantizePT2E.test_disallow_eval_train
python test/test_quantization.py TestQuantizePT2E.test_move_exported_model_to_eval
Imported from OSS
Differential Revision: D49097293
Pull Request resolved: #108891
Approved by: https://github.com/jerryzh168
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @ngimel @yf225 @chenyang78 @kadeng @muchulee8 @aakhundov