FLParameter
import com.mindspore.flclient.FLParameter
FLParameter is used to define parameters related to federated learning.
Public Member Functions
function |
---|
public static synchronized FLParameter getInstance() |
public String getDeployEnv() |
public void setDeployEnv(String env) |
public String getDomainName() |
public void setDomainName(String domainName) |
public String getClientID() |
public void setClientID(String clientID) |
public String getCertPath() |
public void setCertPath(String certPath) |
public SSLSocketFactory getSslSocketFactory() |
public void setSslSocketFactory(SSLSocketFactory sslSocketFactory) |
public X509TrustManager getX509TrustManager( |
public void setX509TrustManager(X509TrustManager x509TrustManager) |
public IFLJobResultCallback getIflJobResultCallback() |
public void setIflJobResultCallback(IFLJobResultCallback iflJobResultCallback) |
public String getFlName() |
public void setFlName(String flName) |
public String getTrainModelPath() |
public void setTrainModelPath(String trainModelPath) |
public String getInferModelPath() |
public void setInferModelPath(String inferModelPath) |
public String getSslProtocol() |
public void setSslProtocol(String sslProtocol) |
public int getTimeOut() |
public void setTimeOut(int timeOut) |
public int getSleepTime() |
public void setSleepTime(int sleepTime) |
public boolean isUseElb() |
public void setUseElb(boolean useElb) |
public int getServerNum() |
public void setServerNum(int serverNum) |
public boolean isPkiVerify() |
public void setPkiVerify(boolean ifPkiVerify) |
public String getEquipCrlPath() |
public void setEquipCrlPath(String certPath) |
public long getValidInterval() |
public void setValidInterval(long validInterval) |
public int getThreadNum() |
public void setThreadNum(int threadNum) |
public int getCpuBindMode( |
public void setCpuBindMode(BindMode cpuBindMode) |
public List |
public void setHybridWeightName(List |
public Map<RunType, List |
public void setDataMap(Map<RunType, List |
public ServerMod getServerMod() |
public void setServerMod(ServerMod serverMod) |
public int getBatchSize() |
public void setBatchSize(int batchSize) |
getInstance
public static synchronized FLParameter getInstance()
Obtains a single FLParameter instance.
Return value
Single object of the FLParameter type.
getDeployEnv
public String getDeployEnv()
Obtains the deployment environment for federated learning set by users.
Return value
The deployment environment for federated learning of the string type.
setDeployEnv
public void setDeployEnv(String env)
Used to set the deployment environment for federated learning, a whitelist is set, currently only “x86”, “android” are supported.
Parameter
env
: the deployment environment for federated learning.
getDomainName
public String getDomainName()
Obtains the domain name set by a user.
Return value
Domain name of the string type.
setDomainName
public void setDomainName(String domainName)
Used to set the url for device-cloud communication. Currently, https and http communication are supported, the corresponding formats are like: https://……, http://……, and when useElb
is set to true, the format must be: https://127.0.0.0 : 6666 or http://127.0.0.0 : 6666 , where 127.0.0.0
corresponds to the ip of the machine providing cloud-side services (corresponding to the cloud-side parameter --scheduler_ip
), and 6666
corresponds to the cloud-side parameter --fl_server_port
.
Parameter
domainName
: domain name.
getClientID
public String getClientID()
The method getClientID
is used to obtain the unique ID of the client, the ID also can be used to generate related certificates in the device-cloud security authentication scenario.
Return value
Unique ID of the client, which is of the string type.
setClientID
public void setClientID(String clientID)
Each time the federated learning task is started, a unique client ID will be automatically generated in the program, if the user needs to set the clientID by himself, he can set the ID by calling the method setClientID
before starting the federated learning training task.
Parameter
clientID
: unique ID of the client.
getCertPath
public String getCertPath()
Obtains the self-signed root certificate path used for device-cloud HTTPS communication.
Return value
The self-signed root certificate pat of the string type.
setCertPath
public void setCertPath(String certPath)
Sets the self-signed root certificate path used for device-cloud HTTPS communication. When the deployment environment is “x86” and the device-cloud uses a self-signed certificate for HTTPS communication authentication, this parameter needs to be set. The certificate must be consistent with the CA root certificate used to generate the cloud-side self-signed certificate to pass the verification. This parameter is used for non-Android scenarios.
Parameter
certPath
: the self-signed root certificate path used for device-cloud HTTPS communication.
getSslSocketFactory
public SSLSocketFactory getSslSocketFactory()
Obtains the ssl certificate authentication library sslSocketFactory
set by the user.
Return value
The ssl certificate authentication library
sslSocketFactory
, which is of the SSLSocketFactory type.
setSslSocketFactory
public void setSslSocketFactory(SSLSocketFactory sslSocketFactory)
Used to set the ssl certificate authentication library sslSocketFactory
.
Parameter
sslSocketFactory
: the ssl certificate authentication library.
getX509TrustManager
public X509TrustManager getX509TrustManager()
Obtains the ssl certificate authentication manager x509TrustManager
set by the user.
Return value
the ssl certificate authentication manager
x509TrustManager
, which is of the X509TrustManager type.
setX509TrustManager
public void setX509TrustManager(X509TrustManager x509TrustManager)
Used to set the ssl certificate authentication manager x509TrustManager
.
Parameter
x509TrustManager
: the ssl certificate authentication manager.
getIflJobResultCallback
public IFLJobResultCallback getIflJobResultCallback()
Obtains the federated learning callback function object iflJobResultCallback
set by the user.
Return value
The federated learning callback function object
iflJobResultCallback
, which is of the IFLJobResultCallback type.
setIflJobResultCallback
public void setIflJobResultCallback(IFLJobResultCallback iflJobResultCallback)
Used to set the federated learning callback function object iflJobResultCallback
, the user can implement the specific method of the interface class IFLJobResultCallback.java in the project according to the needs of the actual scene, and set it as a callback function object in the federated learning task.
Parameter
iflJobResultCallback
: the federated learning callback function object.
getFlName
public String getFlName()
Obtains the package path of model script set by a user.
Return value
Name of the package path of model script of the string type.
setFlName
public void setFlName(String flName)
Sets the package path of model script . We provide two types of model scripts for your reference (Supervised sentiment classification task, Lenet image classification task). For supervised sentiment classification tasks, this parameter can be set to the package path of the provided script file AlBertClient.java, like as com.mindspore.flclient.demo.albert.AlbertClient
; for Lenet image classification tasks, this parameter can be set to the package path of the provided script file LenetClient.java, like as com.mindspore.flclient.demo.lenet.LenetClient
. At the same time, users can refer to these two types of model scripts, define the model script by themselves, and then set the parameter to the package path of the customized model file ModelClient.java (which needs to inherit from the class Client.java).
Parameter
flName
: package path of model script.
getTrainModelPath
public String getTrainModelPath()
Obtains the path of the training model set by a user.
Return value
Path of the training model of the string type.
setTrainModelPath
public void setTrainModelPath(String trainModelPath)
Sets the path of the training model.
Parameter
trainModelPath
: training model path.
getInferModelPath
public String getInferModelPath()
Obtains the path of the inference model set by a user.
Return value
Path of the inference model of the string type.
setInferModelPath
public void setInferModelPath(String inferModelPath)
Sets the path of the inference model.
Parameter
inferModelPath
: path of the inference model.
getSslProtocol
public String getSslProtocol()
Obtains the TLS protocol version used by the device-cloud HTTPS communication.
Return value
The TLS protocol version used by the device-cloud HTTPS communication of the string type.
setSslProtocol
public void setSslProtocol(String sslProtocol)
Used to set the TLS protocol version used by the device-cloud HTTPS communication, a whitelist is set, and currently only “TLSv1.3” or “TLSv1.2” is supported. Only need to set it up in the HTTPS communication scenario.
Parameter
sslProtocol
: the TLS protocol version used by the device-cloud HTTPS communication.
getTimeOut
public int getTimeOut()
Obtains the timeout interval set by a user for device-side communication.
Return value
Timeout interval for communication on the device, which is an integer.
setTimeOut
public void setTimeOut(int timeOut)
Sets the timeout interval for communication on the device.
Parameter
timeOut
: timeout interval for communication on the device.
getSleepTime
public int getSleepTime()
Obtains the waiting time of repeated requests set by a user.
Return value
Waiting time of repeated requests, which is an integer.
setSleepTime
public void setSleepTime(int sleepTime)
Sets the waiting time of repeated requests.
Parameter
sleepTime
: waiting time for repeated requests.
isUseElb
public boolean isUseElb()
Determines whether the elastic load balancing is simulated, that is, whether a client randomly sends requests to a server address within a specified range.
Return value
The value is of the Boolean type. The value true indicates that the client sends requests to a random server address within a specified range. The value false indicates that the client sends a request to a fixed server address.
setUseElb
public void setUseElb(boolean useElb)
Determines whether to simulate the elastic load balancing, that is, whether a client randomly sends a request to a server address within a specified range.
Parameter
useElb
: determines whether to simulate the elastic load balancing. The default value is false.
getServerNum
public int getServerNum()
Obtains the number of servers that can send requests when simulating the elastic load balancing.
Return value
Number of servers that can send requests during elastic load balancing simulation, which is an integer.
setServerNum
public void setServerNum(int serverNum)
Sets the number of servers that can send requests during elastic load balancing simulation.
Parameter
serverNum
: number of servers that can send requests during elastic load balancing simulation. The default value is 1.
isPkiVerify
public boolean isPkiVerify()
Whether to perform device-cloud security authentication.
Return value
The value is of the Boolean type. The value true indicates that device-cloud security authentication is performed, and the value false indicates that device-cloud security authentication is not performed.
setPkiVerify
public void setPkiVerify(boolean pkiVerify)
Determines whether to perform device-cloud security authentication.
Parameter
pkiVerify
: whether to perform device-cloud security authentication.
getEquipCrlPath
public String getEquipCrlPath()
Obtains the CRL certification path equipCrlPath
of the device certificate set by the user. This parameter is used in the Android environment.
Return value
The certification path of the string type.
setEquipCrlPath
public void setEquipCrlPath(String certPath)
Used to set the CRL certification path of the device certificate. It is used to verify whether the digital certificate is revoked. This parameter is used in the Android environment.
Parameter
certPath
: the certification path.
getValidInterval
public long getValidInterval()
Obtains the valid iteration interval validIterInterval set by the user. This parameter is used in the Android environment.
Return value
The valid iteration interval validIterInterval of the long type.
setValidInterval
public void setValidInterval(long validInterval)
Used to set the valid iteration interval validIterInterval. The recommended duration is the duration of one training epoch between the device-cloud(unit: milliseconds). It is used to prevent replay attacks. This parameter is used in the Android environment.
Parameter
validInterval
: the valid iteration interval validIterInterval.
getThreadNum
public int getThreadNum()
Obtains the number of threads used in federated learning training and inference. The default value is 1.
Return value
The number of threads used in federated learning training and inference, which is of the int type.
setThreadNum
public void setThreadNum(int threadNum)
Used to set the number of threads used in federated learning training and inference.
Parameter
threadNum
: the number of threads used in federated learning training and inference.
getCpuBindMode
public int getCpuBindMode()
Obtains the cpu core that threads need to bind during federated learning training and inference.
Return value
Convert the enumerated type of cpu core to int type and return.
setCpuBindMode
public void setCpuBindMode(BindMode cpuBindMode)
Used to set the cpu core that threads need to bind during federated learning training and inference.
Parameter
cpuBindMode
: it is the enumeration typeBindMode
, where BindMode.NOT_BINDING_CORE represents the unbound core, which is automatically assigned by the system, BindMode.BIND_LARGE_CORE represents the bound large core, and BindMode.BIND_MIDDLE_CORE represents the bound middle core.
getHybridWeightName
public List<String> getHybridWeightName(RunType runType)
Used in hybrid training mode. Get the training weight name and inference weight name set by the user.
Parameter
runType
: RunType enumeration type, only supports to be set to RunType.TRAINMODE (representing the training weight name) , RunType.INFERMODE (representing the inference weight name).Return value
A list of corresponding weight names according to the parameter runType, which is of the List
type.
setHybridWeightName
public void setHybridWeightName(List<String> hybridWeightName, RunType runType)
Due to the hybrid training mode, part of the weights delivered by the server is imported into the training model, and part is imported into the inference model, but the framework itself cannot judge it, so the user needs to set the relevant training weight name and inference weight name by himself. This method is provided for the user to set.
Parameter
hybridWeightName
: a list of weight names of the Listtype. runType
: RunType enumeration type, only supports setting to RunType.TRAINMODE (representing setting training weight name), RunType.INFERMODE (representing setting reasoning weight name).
getDataMap
public Map<RunType, List<String>> getDataMap()
Obtains the federated learning dataset set by the user.
Return value
the federated learning dataset set of the Map<RunType, List
> type.
setDataMap
public void setDataMap(Map<RunType, List<String>> dataMap)
Used to set the federated learning dataset set by the user.
Parameter
dataMap
: the dataset of Map<RunType, List> type, the key in the map is the RunType enumeration type, the value is the corresponding dataset list, when the key is RunType.TRAINMODE, the corresponding value is the training-related dataset list, when the key is RunType.EVALMODE, it means that the corresponding value is a list of verification-related datasets, and when the key is RunType.INFERMODE, it means that the corresponding value is a list of inference-related datasets.
getServerMod
public ServerMod getServerMod()
Obtains the federated learning training mode.
Return value
The federated learning training mode of ServerMod enumeration type.
setServerMod
public void setServerMod(ServerMod serverMod)
Used to set the federated learning training mode.
Parameter
serverMod
: the federated learning training mode of ServerMod enumeration type, where ServerMod.FEDERATED_LEARNING represents the normal federated learning mode (training and inference use the same model) ServerMod.HYBRID_TRAINING represents the hybrid learning mode (training and inference use different models, and the server side also includes training process).
getBatchSize
public int getBatchSize()
Obtains the number of single-step training samples used in federated learning training and inference, that is, batch size.
Return value
BatchSize, the number of single-step training samples of int type.
setBatchSize
public void setBatchSize(int batchSize)
Used to set the number of single-step training samples used in federated learning training and inference, that is, batch size. It needs to be consistent with the batch size of the input data of the model.
Parameter
batchSize
: the number of single-step training samples of int type.