From 5d30d072482a0f8ec815d833d18e66d4e3991cde Mon Sep 17 00:00:00 2001 From: Bai Yifan Date: Thu, 14 Jan 2021 13:08:09 +0800 Subject: [PATCH] cherry-pick 30354 (#30407) --- .../contrib/slim/quantization/imperative/qat.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/python/paddle/fluid/contrib/slim/quantization/imperative/qat.py b/python/paddle/fluid/contrib/slim/quantization/imperative/qat.py index b543a91372..6526cf11f0 100644 --- a/python/paddle/fluid/contrib/slim/quantization/imperative/qat.py +++ b/python/paddle/fluid/contrib/slim/quantization/imperative/qat.py @@ -255,13 +255,19 @@ class ImperativeQuantAware(object): if hasattr(layer, "skip_quant") and layer.skip_quant == True: continue - scopes = name.split('.') - target = scopes[-1] + last_idx = 0 + idx = 0 obj = model parent = model - for i in range(len(scopes) - 1): - obj = getattr(parent, scopes[i]) - parent = obj + + while idx < len(name): + if (name[idx] == '.'): + if hasattr(parent, name[last_idx:idx]): + obj = getattr(obj, name[last_idx:idx]) + parent = obj + last_idx = idx + 1 + idx += 1 + target = name[last_idx:idx] quant_layer = self._get_quantized_counterpart(layer) setattr(quant_layer, "layer_name", layer.full_name()) -- GitLab