From a340f45a9dfb597b6036fa856d8dc8294b4a4950 Mon Sep 17 00:00:00 2001 From: jin-xiulang Date: Mon, 10 Jan 2022 16:40:03 +0800 Subject: [PATCH] Fix an issue of federated learning --- .../com/mindspore/flclient/FLLiteClient.java | 54 +------------------ .../mindspore/flclient/cipher/CertVerify.java | 2 +- 2 files changed, 2 insertions(+), 54 deletions(-) diff --git a/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/FLLiteClient.java b/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/FLLiteClient.java index 8f232162c8..574c865464 100644 --- a/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/FLLiteClient.java +++ b/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/FLLiteClient.java @@ -441,53 +441,6 @@ public class FLLiteClient { return featureMap; } - /** - * Obtain the weight of the model before training. - * - * @param map a map to store the weight of the model. - * @return the weight. - */ - public static synchronized Map getOldMapCopy(Map map) { - if (mapBeforeTrain == null) { - Map copyMap = new TreeMap<>(); - for (String key : map.keySet()) { - float[] data = map.get(key); - int dataLen = data.length; - float[] weights = new float[dataLen]; - if ((key.indexOf("Default") < 0) && (key.indexOf("nhwc") < 0) && (key.indexOf("moment") < 0) && - (key.indexOf("learning") < 0)) { - for (int j = 0; j < dataLen; j++) { - float weight = data[j]; - weights[j] = weight; - } - copyMap.put(key, weights); - } - } - mapBeforeTrain = copyMap; - } else { - for (String key : map.keySet()) { - float[] data = map.get(key); - float[] copyData = mapBeforeTrain.get(key); - int dataLen = data.length; - if ((key.indexOf("Default") < 0) && (key.indexOf("nhwc") < 0) && (key.indexOf("moment") < 0) && - (key.indexOf("learning") < 0)) { - for (int j = 0; j < dataLen; j++) { - copyData[j] = data[j]; - } - } - } - } - return mapBeforeTrain; - } - - private void getOldFeatureMap() { - EncryptLevel encryptLevel = localFLParameter.getEncryptLevel(); - if (encryptLevel == EncryptLevel.DP_ENCRYPT) { - Map featureMap = getFeatureMap(); - oldFeatureMap = getOldMapCopy(featureMap); - } - } - public void updateDpNormClip() { EncryptLevel encryptLevel = localFLParameter.getEncryptLevel(); if (encryptLevel == EncryptLevel.DP_ENCRYPT) { @@ -554,12 +507,7 @@ public class FLLiteClient { return curStatus; case DP_ENCRYPT: // get the feature map before train - getOldFeatureMap(); - if (oldFeatureMap.isEmpty()) { - LOGGER.severe(Common.addTag("[Encrypt] the return map in getOldFeatureMapis empty ")); - retCode = ResponseCode.RequestError; - return FLClientStatus.FAILED; - } + oldFeatureMap = getFeatureMap(); curStatus = secureProtocol.setDPParameter(iteration, dpEps, dpDelta, dpNormClipAdapt, oldFeatureMap); retCode = ResponseCode.SUCCEED; if (curStatus != FLClientStatus.SUCCESS) { diff --git a/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/cipher/CertVerify.java b/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/cipher/CertVerify.java index 067a018bc7..205d7f9205 100644 --- a/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/cipher/CertVerify.java +++ b/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/cipher/CertVerify.java @@ -154,7 +154,7 @@ public class CertVerify { LOGGER.severe(Common.addTag("[verifyChain] catch Exception: " + e.getMessage())); return false; } - LOGGER.severe(Common.addTag("verifyChain success!")); + LOGGER.info(Common.addTag("verifyChain success!")); return true; }