Commit ac7be4fa authored by Yanghan Wang's avatar Yanghan Wang Committed by Facebook GitHub Bot
Browse files

set is_qat properly when fusing model

Summary:
Pull Request resolved: https://github.com/facebookresearch/d2go/pull/175

D33833203 adds `is_qat` argument to the fuser method, more details in https://fb.workplace.com/groups/2322282031156145/permalink/5026297484087906/. As results, MV's `fuse_utils.fuse_model` then becomes two functions: the original one is for non-qat; a new one `fuse_utils.fuse_model_qat` is for qat.

For D2 (https://github.com/facebookresearch/d2go/commit/7992f91324aee6ae59795063a007c6837e60cdb8)Go in most cases, `is_qat` can be inferred from `cfg.QUANTIZATION.QAT.ENABLED`, therefore we can extend the `fuse_model` to also take `is_qat` as parameter, and set it accordingly.

This diff updates all the call sites which is covered by unit tests. Those call sites include:
- default quantization APIs in d2go/modeling/quantization.py
- customized quantization APIs from individual meta-arch
- unit test itself

Reviewed By: tglik, jerryzh168

Differential Revision: D34112650

fbshipit-source-id: 026c309f603bee71d887e39aa4efee6477db731b
parent 5aadaaa4
......@@ -264,7 +264,11 @@ def default_rcnn_prepare_for_quant(self, cfg):
# Modify the model for eager mode
if cfg.QUANTIZATION.EAGER_MODE:
model = _apply_eager_mode_quant(cfg, model)
model = fuse_utils.fuse_model(model, inplace=True)
model = fuse_utils.fuse_model(
model,
is_qat=cfg.QUANTIZATION.QAT.ENABLED,
inplace=True,
)
else:
_fx_quant_prepare(model, cfg)
......
......@@ -251,7 +251,11 @@ def default_prepare_for_quant(cfg, model):
)
if cfg.QUANTIZATION.EAGER_MODE:
model = fuse_utils.fuse_model(model, inplace=True)
model = fuse_utils.fuse_model(
model,
is_qat=cfg.QUANTIZATION.QAT.ENABLED,
inplace=True,
)
torch.backends.quantized.engine = cfg.QUANTIZATION.BACKEND
model.qconfig = qconfig
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment