diff --git a/coremltools/models/neural_network/builder.py b/coremltools/models/neural_network/builder.py index 93458ac59..5339b56ff 100644 --- a/coremltools/models/neural_network/builder.py +++ b/coremltools/models/neural_network/builder.py @@ -866,8 +866,9 @@ def _check_fp16_weight_param_exists(self, layers): # uniDirectionalLSTM Layers elif layer_type == "uniDirectionalLSTM": - return self._check_fp16_weight_params_lstms(lstm_wp=layer.uniDirectionalLSTM.weightParams, - has_peephole=layer.uniDirectionalLSTM.params.hasPeepholeVectors) + if self._check_fp16_weight_params_lstms(lstm_wp=layer.uniDirectionalLSTM.weightParams, + has_peephole=layer.uniDirectionalLSTM.params.hasPeepholeVectors): + return True # biDirectionalLSTM Layers elif layer_type == "biDirectionalLSTM": @@ -878,19 +879,19 @@ def _check_fp16_weight_param_exists(self, layers): # branch Layers elif layer_type == "branch": - if len(layer.branch.ifBranch.float16Value) > 0: + if self._check_fp16_weight_param_exists(layer.branch.ifBranch.layers): return True - if len(layer.branch.elseBranch.float16Value) > 0: + if self._check_fp16_weight_param_exists(layer.branch.elseBranch.layers): return True # loop Layers elif layer_type == "loop": - if len(layer.loop.conditionNetwork.float16Value) > 0: + if self._check_fp16_weight_param_exists(layer.loop.conditionNetwork.layers): return True - if len(layer.loop.bodyNetwork.float16Value) > 0: + if self._check_fp16_weight_param_exists(layer.loop.bodyNetwork.layers): return True - return False + return False def make_updatable(self, trainables): """ diff --git a/coremltools/test/pipeline/test_model_updatable.py b/coremltools/test/pipeline/test_model_updatable.py index 3406d37f5..c6d077fce 100644 --- a/coremltools/test/pipeline/test_model_updatable.py +++ b/coremltools/test/pipeline/test_model_updatable.py @@ -652,7 +652,7 @@ def test_nn_partial_fp16_make_updatable_quantized_layer_fail(self): with self.assertRaises(ValueError): q_nn_builder.make_updatable(["ip2"]) - def test_nn_partial_fp16_make_updatable_fail(self): + def test_nn_updatable_fp16_quantize_fail(self): nn_builder = self.create_base_builder() model_path = os.path.join(self.model_dir, "updatable_creation.mlmodel") print(model_path)