From 81e18a5b2c6d53d7f72fe507cf2de968432ae258 Mon Sep 17 00:00:00 2001 From: sanchitintel Date: Fri, 25 Aug 2023 09:41:47 -0700 Subject: [PATCH 1/2] Update tuning guide to reflect folding conv-bn when oneDNN Graph is used with AMP By default, conv-bn folding isn't done with CNN based models when AMP is used with oneDNN Graph. `torch.fx.experimental.optimize.fuse` should be used for such models --- recipes_source/recipes/tuning_guide.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/recipes_source/recipes/tuning_guide.py b/recipes_source/recipes/tuning_guide.py index 0f82fb76d3d..6ed12ade6be 100644 --- a/recipes_source/recipes/tuning_guide.py +++ b/recipes_source/recipes/tuning_guide.py @@ -295,6 +295,10 @@ def fused_gelu(x): torch._C._jit_set_autocast_mode(False) with torch.no_grad(), torch.cpu.amp.autocast(cache_enabled=False, dtype=torch.bfloat16): + # Conv-BatchNorm folding for CNN-based Vision Models should be done with torch.fx.experimental.optimization.fuse when AMP is used + import torch.fx.experimental.optimization as optimization + # Please note that optimization.fuse need not be called when AMP is not used + model = optimization.fuse(model) model = torch.jit.trace(model, (example_input)) model = torch.jit.freeze(model) # a couple of warm-up runs From 812b863e892a4926c989272402ac7b7ef36a5625 Mon Sep 17 00:00:00 2001 From: sanchitintel Date: Fri, 25 Aug 2023 12:55:05 -0700 Subject: [PATCH 2/2] Fix spell-check Co-authored-by: Svetlana Karslioglu --- recipes_source/recipes/tuning_guide.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes_source/recipes/tuning_guide.py b/recipes_source/recipes/tuning_guide.py index 6ed12ade6be..dd615714a24 100644 --- a/recipes_source/recipes/tuning_guide.py +++ b/recipes_source/recipes/tuning_guide.py @@ -295,7 +295,7 @@ def fused_gelu(x): torch._C._jit_set_autocast_mode(False) with torch.no_grad(), torch.cpu.amp.autocast(cache_enabled=False, dtype=torch.bfloat16): - # Conv-BatchNorm folding for CNN-based Vision Models should be done with torch.fx.experimental.optimization.fuse when AMP is used + # Conv-BatchNorm folding for CNN-based Vision Models should be done with ``torch.fx.experimental.optimization.fuse`` when AMP is used import torch.fx.experimental.optimization as optimization # Please note that optimization.fuse need not be called when AMP is not used model = optimization.fuse(model)