federated learning service · parameter freezing: compression algorithm, which adjusts the...

109
NAIE V200R020C20 Federated Learning Service Issue 01 Date 2019-12-30 HUAWEI TECHNOLOGIES CO., LTD.

Upload: others

Post on 15-Mar-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

NAIEV200R020C20

Federated Learning Service

Issue 01

Date 2019-12-30

HUAWEI TECHNOLOGIES CO., LTD.

Copyright © Huawei Technologies Co., Ltd. 2020. All rights reserved.

No part of this document may be reproduced or transmitted in any form or by any means without priorwritten consent of Huawei Technologies Co., Ltd. Trademarks and Permissions

and other Huawei trademarks are trademarks of Huawei Technologies Co., Ltd.All other trademarks and trade names mentioned in this document are the property of their respectiveholders. NoticeThe purchased products, services and features are stipulated by the contract made between Huawei andthe customer. All or part of the products, services and features described in this document may not bewithin the purchase scope or the usage scope. Unless otherwise specified in the contract, all statements,information, and recommendations in this document are provided "AS IS" without warranties, guaranteesor representations of any kind, either express or implied.

The information in this document is subject to change without notice. Every effort has been made in thepreparation of this document to ensure accuracy of the contents, but all statements, information, andrecommendations in this document do not constitute a warranty of any kind, express or implied.

Huawei Technologies Co., Ltd.Address: Huawei Industrial Base

Bantian, LonggangShenzhen 518129People's Republic of China

Website: https://e.huawei.com

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. i

Contents

1 Documentation Guide............................................................................................................ 1

2 Product Overview.................................................................................................................... 22.1 What Is Federated Learning?.............................................................................................................................................. 22.2 Advantages................................................................................................................................................................................ 22.3 Functions.................................................................................................................................................................................... 32.4 Product Architecture............................................................................................................................................................... 32.5 Networking Mode................................................................................................................................................................... 42.6 Service Dependencies.............................................................................................................................................................52.7 How to Access the Federated Learning Service............................................................................................................ 6

3 Quick Start................................................................................................................................ 83.1 General Introduction to Federated Learning................................................................................................................. 83.1.1 Overview................................................................................................................................................................................. 83.1.2 Basic Networking................................................................................................................................................................. 83.2 Federation Instance Management.................................................................................................................................... 93.2.1 Accessing the Federated Learning Service.................................................................................................................. 93.2.2 Creating Federation Instances.......................................................................................................................................103.2.3 Publishing Federation Instances................................................................................................................................... 153.2.4 Creating Multiple Versions of a Federation Instance............................................................................................ 163.2.5 Viewing Multiple Versions of a Federation Instance............................................................................................. 173.2.6 Deleting Federation Instances.......................................................................................................................................183.3 Edge Node Management................................................................................................................................................... 183.3.1 Edge Node Description.................................................................................................................................................... 183.3.2 Registering Edge Nodes.................................................................................................................................................. 193.3.3 Deregistering Edge Nodes.............................................................................................................................................. 193.4 Running Federation Instances.......................................................................................................................................... 203.4.1 Running Federation Instances....................................................................................................................................... 203.4.2 Checking Results................................................................................................................................................................ 203.4.3 Viewing the Progress........................................................................................................................................................ 213.5 Appendix.................................................................................................................................................................................. 223.5.1 Metadata Definition......................................................................................................................................................... 22

4 FAQs..........................................................................................................................................244.1 How Do I Return to the Homepage of the Federated Learning Service Platform?.......................................24

NAIEFederated Learning Service Contents

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. ii

4.2 What Does the Public or Not Parameter Mean During Instance Creation? ................................................... 244.3 What Is the Difference Between Random Parameter Selection and Server-side Parameter FreezingAmong Compression Algorithms?.......................................................................................................................................... 244.4 How Do I Set the Center Model Evaluation Interval Parameter?........................................................................ 254.5 How Do I Configure Learning Rate Decay?................................................................................................................. 254.6 What Are the Format Requirements for Model Packages that Meet the Trial Run Conditions?..............264.7 Why Is the Model Size Is the Largest During the First Download?.....................................................................264.8 How Do I Use the Federation Restoration Function?...............................................................................................26

5 Glossary................................................................................................................................... 27

6 Client Deployment Guide.................................................................................................... 306.1 Installation Precautions...................................................................................................................................................... 306.2 Installation Planning............................................................................................................................................................ 326.3 Installing the FLC.................................................................................................................................................................. 326.4 Appendix.................................................................................................................................................................................. 39

7 Federated Learning Model Package Specifications.......................................................417.1 Application Scenarios.......................................................................................................................................................... 417.2 Model Package Structure................................................................................................................................................... 427.2.1 Model Package Restrictions........................................................................................................................................... 437.2.2 Model Package Metadata.............................................................................................................................................. 437.3 Algorithm Interfaces............................................................................................................................................................ 537.3.1 Input Parameter Parsing................................................................................................................................................. 537.3.2 Initialization Interface...................................................................................................................................................... 547.3.3 Model Training Interface.................................................................................................................................................547.3.4 Model Evaluation Interface............................................................................................................................................ 547.4 Appendix.................................................................................................................................................................................. 54

8 API Reference (FL-Server)................................................................................................... 568.1 Before You Start.................................................................................................................................................................... 568.2 Overview.................................................................................................................................................................................. 568.3 Environment Preparation................................................................................................................................................... 578.3.1 Obtaining Request Authentication .............................................................................................................................578.3.2 Obtaining the Project ID/Tenant ID............................................................................................................................ 588.4 Methods of Using Interfaces............................................................................................................................................. 598.5 Federation Instance Service............................................................................................................................................... 638.5.1 Creating Federation Instances.......................................................................................................................................638.5.2 Updating Federation Instances..................................................................................................................................... 668.5.3 Deleting Federation Instances.......................................................................................................................................678.5.4 Operating Federation Instances................................................................................................................................... 688.5.5 Querying a Single Federation Instance...................................................................................................................... 698.5.6 Querying Multiple Versions of a Federation Instance.......................................................................................... 718.5.7 Querying the Running Progress of Federation Instances.................................................................................... 738.5.8 Querying Monitoring Information About Federation Instances........................................................................76

NAIEFederated Learning Service Contents

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. iii

8.6 Federated Client Service..................................................................................................................................................... 778.6.1 Registering Federated Clients........................................................................................................................................778.6.2 Deregistering Federated Clients................................................................................................................................... 798.6.3 Downloading Federated Models to Clients.............................................................................................................. 808.6.4 Uploading Local Models from Clients........................................................................................................................ 818.6.5 Uploading KPIs from Clients.......................................................................................................................................... 838.6.6 Sending Heartbeat Information from Clients.......................................................................................................... 848.7 Common Error Codes.......................................................................................................................................................... 878.7.1 Common HTTP Request Status Codes....................................................................................................................... 878.7.2 Federated Error Codes..................................................................................................................................................... 88

9 API Reference (FL-Client).................................................................................................... 909.1 Before You Start.................................................................................................................................................................... 909.2 Overview.................................................................................................................................................................................. 909.3 Environment Preparation................................................................................................................................................... 919.3.1 Obtaining IAM User Information of the Public Cloud.......................................................................................... 919.3.2 Obtaining the ID and Version of a Federated Learning Instance..................................................................... 919.3.3 Preparing Algorithm Metadata Files.......................................................................................................................... 919.4 Methods of Using Interfaces............................................................................................................................................. 929.5 APIs............................................................................................................................................................................................ 949.5.1 Registration..........................................................................................................................................................................959.5.2 Deregistration..................................................................................................................................................................... 969.5.3 Heartbeat............................................................................................................................................................................. 979.5.4 Task Query........................................................................................................................................................................... 999.5.5 Data Reporting.................................................................................................................................................................1009.6 Common Parameters........................................................................................................................................................ 1029.6.1 Error Codes........................................................................................................................................................................ 102

NAIEFederated Learning Service Contents

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. iv

1 Documentation Guide

The federated learning service provides Product Overview, Quick Start, FAQs,Glossary, Client Deployment Guide, and two API reference manuals to help usersquickly understand and use the service.

Table 1-1 Document guide

Document Description

ProductOverview

This document describes the concept, advantages, functions,and networking modes of the federated learning service.

Quick Start This document describes how to use the federated learningservice, create federation instances, register edge nodes, andrun federation instances, enabling users to quickly getfamiliar with and use the federated learning service.

FAQs This document provides answers to frequently askedquestions about the federated learning service.

Glossary This document describes the terms related to the federatedlearning service.

ClientDeploymentGuide

This document describes how to install federated learningclients (FLCs).

FederatedLearning ModelPackageSpecifications

This document describes the specifications of the federatedlearning model package.

API Reference(FLS)

This document describes the APIs, syntax, parameters, andexamples of the federated learning server (FLS).

API Reference(FLC)

This document describes the APIs, syntax, parameters, andexamples of the federated learning client (FLC).

NAIEFederated Learning Service 1 Documentation Guide

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 1

2 Product Overview

2.1 What Is Federated Learning?Federated learning is an encrypted distributed machine learning technology. Withthis technology, users participating in federated learning jointly build AI modelswithout sharing local data. During federated learning, participants train modelslocally, encrypt the updated models, and upload them to the cloud. Then, theparticipants aggregate and integrate the updated models of other participants toform a public model, which is delivered by the cloud to all participants. Localtraining and cloud integration are performed repeatedly to create a better AImodel.

NAIE federated learning is based on HUAWEI CLOUD computing resources. Itintegrates the development environment in the cloud federated center andprovides a federated learning environment for terminals, edge devices, and localdata centers (DCs).

2.2 Advantages● Data not transmitted out of a site

Due to data security and privacy protection, data cannot be exported fromthe local host, resulting in data silos. Traditional machine learning cannotaggregate complete training data, and therefore cannot train a better model.

Federated learning uses only local data for training and does not exchangedata. Instead, it exchanges updated model parameters in encryption mode.

● Improved model effect

Since data samples are unevenly distributed in different regions, AI modelstrained at sites with few data samples are unsatisfactory. Generalizationperformance of these models cannot be guaranteed.

Federated learning uses device data obtained in different environments formodel training. Models are aggregated and updated before being delivered todevices, improving model generalization.

● Higher model training efficiency

NAIEFederated Learning Service 2 Product Overview

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 2

As the edge computing capability improves, distributed training can improvethe AI model generation efficiency and fully leverage computing resourcesand capabilities of edge nodes in a way better than central training.Federated learning uses idle computing capabilities of terminals or edgedevices for training, improving the training efficiency of personalized modeladaptation without affecting core service experience.

2.3 Functions● Support for multiple edge computing frameworks

Client nodes can use the models generated by the Tensorflow, Caffe, andPytorch deep learning frameworks for federated learning. Model fileadaptation is not required.

● Support for multiple federated aggregation algorithmsFederated aggregation: federated weighted average algorithm, which isapplicable to all gradient descent algorithmsLearning rate decay: The learning rate decay algorithm smooths federatedconvergence and provides an optimal solution.Gradient bifurcation: Enabling the adaptive algorithm (also called gradientbifurcation algorithm) can effectively reduce the local training duration withthe same precision requirements.

● Support for multiple security and privacy algorithmsSecure multi-party computing: In scenarios with high security requirements,enabling the secure multi-party algorithm prevents the service from obtaininginformation about the local model and does not reduce the model precision.Differential privacy: In secure scenarios, noise is added in different phases tomaximize data query accuracy and minimize chances that data can beidentified.

● Support for multiple model compression algorithmsParameter freezing: compression algorithm, which adjusts the parametersettings for each round of federated aggregation based on the model changetrend to reduce the communication bandwidthRandom parameter selection: In multi-node scenarios, each client randomlyuploads some parameters to reduce the communication bandwidth.

● Support for Visualized FederationsReal-time and historical edge node statuses (including offline, idle, training,and evaluation) and training information (for example, the number ofsamples, training duration, accuracy, and bandwidth usage) are visualized.

2.4 Product ArchitectureFigure 2-1 shows the functional architecture of federated learning.

NAIEFederated Learning Service 2 Product Overview

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 3

Figure 2-1 Functional architecture

Table 2-1 describes the functional architecture of federated learning.

Table 2-1 Function description

System Description

Federatedlearningconsole

This console provides online federated learning IDE capabilitiesfor users to monitor and manage instances and edge nodestatuses.

Federatedlearningserver (FLS)

The FLS provides federated APIs for FLCs and the federatedlearning console.

Federatedlearning client(FLC)

An FLC provides APIs for the service training system.

Servicetrainingsystem

This system is a running environment on the user side, whichprovides result feedback, inference, and other functions.

2.5 Networking Mode● Cloud-ground coordination deployment mode● FLS on the cloud: This mode is recommended. Users can create federated

learning instances on the FLS in the cloud-based NAIE to access a wider rangeof federated learning clients and acquire new NAIE training algorithms andmodels and support from NAIE federated experts.

NAIEFederated Learning Service 2 Product Overview

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 4

● FLC and service training system: deployed on the ground side The FLC isresponsible for the communication between the edge compute node and theFLS, downloading global models, and uploading updated model parameters.

Table 2-2 describes the modules of the NAIE federated learning service.

Table 2-2 Function description

System Description

Trainingservice

Provides algorithms and common models based on projectrequirements.

FLS The FLS aggregates models, combines them into common models,and uploads them to the AI marketplace.

AImarketplace

NAIE operation platform. You can purchase the AI service and candownload published public models from the AI marketplace.

Frontagent

Cloud gateway on the ground side, which provides secureconnections for NAIE cloud services.

FLC An FLC performs federated learning on the device side.

2.6 Service Dependencies

Model Training ServiceModel training service of the NAIE platform. Common models and algorithms canbe created on the training platform and imported to the federated learningservice.

NAIEFederated Learning Service 2 Product Overview

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 5

AI MarketplaceNAIE operation platform. The AI market supports model version management,public model download, subscription, and other functions of federated learning.

IAMThe NAIE platform uses the Identity and Access Management (IAM) serviceprovided by the Huawei public cloud system to implement unified identityauthentication and permission management.

API GatewayThe NAIE platform must interconnect with the unified API gateway provided bythe Huawei public cloud system. The API gateway provides a unified entrance forusers to invoke NAIE cloud service APIs. APIs provided by the NAIE cloud servicefor tenants must be registered with the API gateway before being released.

OBSThe NAIE platform uses the Object Storage Service (OBS) to store data, backupmodels, and model snapshots, achieving secure, reliable, and low-cost storage.

ModelArtsUsed by the NAIE federated learning service. The ModelArts service converts thealgorithms submitted by users to the initial model. During a federated trial run,the ModelArts service can be used to run user models and algorithms on the FLS.

2.7 How to Access the Federated Learning ServiceStep 1 Enter https://www.hwtelcloud.com in the address box of a browser on a user PC

and press Enter to access the AI marketplace.

Step 2 Click Sign In in the upper right corner to access the login page.

Step 3 Select IAM User Login and enter the account name, IAM user name, andpassword, as shown in Figure 2-2.

You can also log in using an account. Change the password after the firstsuccessful login and change the password periodically.

NAIEFederated Learning Service 2 Product Overview

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 6

Figure 2-2 Logging in as an IAM user

Step 4 Click Log In to access the AI marketplace.

Step 5 Choose AI Service > Training Platform > Federated Learning Service to enterthe federated learning service page.

Step 6 Click Enter Service. The federated learning service page is displayed.

----End

NAIEFederated Learning Service 2 Product Overview

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 7

3 Quick Start

3.1 General Introduction to Federated Learning

3.1.1 OverviewFederated learning is a new basic artificial intelligence (AI) technology that cancreate a machine learning system without directly accessing training data. Data isstored in the original location, which helps to ensure privacy and reducecommunication costs. Federated learning is designed to perform efficient machinelearning among multiple participants or compute nodes while ensuringinformation security during big data exchange, protecting terminal data andpersonal data privacy, and ensuring legal and regulatory compliance.

The system framework of federated learning includes edge nodes and a centralnode. Edge nodes are users who need to participate in a federation. Edge nodesstore training algorithms and data. Data of each edge node is encrypted andshared only on the central node. The central node is also referred to as acoordinating node, which aggregates training results of edge nodes.

This document describes how to complete a federated learning process, includingcreating federation instances, registering edge nodes, and running federationinstances, helping users rapidly understand and perform federated learning.

3.1.2 Basic NetworkingFigure 3-1 shows the networking of federated learning.

NAIEFederated Learning Service 3 Quick Start

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 8

Figure 3-1 Networking diagram of federated learning

3.2 Federation Instance Management

3.2.1 Accessing the Federated Learning ServiceStep 1 Enter https://www.hwtelcloud.com in the address box of a browser on a user PC

and press Enter to access the AI marketplace.

Step 2 Click Login in the upper right corner. The login page is displayed.

Step 3 Select IAM User Login and enter the account name, IAM user name, andpassword, as shown in Figure 3-2.

NAIEFederated Learning Service 3 Quick Start

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 9

Figure 3-2 Logging in as an IAM user

Step 4 Click Log In to access the AI marketplace.

Step 5 Choose AI Service > Training Platform > Federated Learning to enter thefederated learning page.

Step 6 Click Enter Service. The federated learning service page is displayed.

----End

3.2.2 Creating Federation InstancesAfter logging in to the federation homepage, you can perform operations byfollowing the instructions on the page or create a federation instance byperforming the following steps:

Step 1 Click Create Instance, as shown in Figure 3-3.

NAIEFederated Learning Service 3 Quick Start

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 10

Figure 3-3 Creating a federation instance

Step 2 Set parameters on the instance creation page, as shown in Figure 3-4. Table 3-1describes the parameters.

The imported model package must meet the requirements in the FederatedLearning Model Package Specifications.

Figure 3-4 Parameter settings

Table 3-1 Parameter settings

Area Name Description

BasicInformation

InstanceName

Federation instance name, which is also the federationinstance ID. Different instances are distinguished byinstance IDs.The name must start with a letter (A–z), can containonly letters, digits (0–9), underscores (_), hyphens (-),and cannot end with an underscore (_) or hyphen (-).

NAIEFederated Learning Service 3 Quick Start

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 11

Area Name Description

Description

Federation instance description, which is used todescribe the instance creation or application scenario.

Public orNot

Whether a federated instance is open to all users. Thedefault value is No.

BasicModelConfiguration

Importfrom theNAIEplatform

Basic algorithm selected from the training items onthe NAIE training platformThe system automatically imports existing trainingprojects from the NAIE training platform, including theproject name, description, project type, domain,creator, creation time, and other information. You canquickly search for a project by project name. You canalso access the training platform from the Operationcolumn to view project details.If no suitable project is found in the current list, youcan create a project on the NAIE training platform.

Import Basic algorithm imported locally by the user.Open the local basic algorithm package path in theExternal Basic Algorithm Path area and import basicalgorithms.Algorithm package requirements are as follows:1. The package file must be a .zip file and the package

file name contains only English letters.2. The size of the package file cannot exceed 100 MB.3. The root directory of the compressed file must

contain the meta.json file, and the metadata of thealgorithm package in the meta.json file must becorrect.

ModelEvaluationIndicator

Model evaluation KPI used by the basic algorithm. Thevalues are as follows:● Accuracy● Precision● Recall rate● F1 Score↵● F2 Score↵Select Accuracy in general scenarios, which indicatesthe accuracy of the created cooperation model.

Edge NodeRuntimeEnvironment

Running environment for the basic algorithm● TensorFlow Lite↵● Caffe↵● PyTorch↵

NAIEFederated Learning Service 3 Quick Start

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 12

Area Name Description

FederatedLearningAggregationAlgorithmConfiguration

FederatedLearningAggregationAlgorithmType-Weightedaverage

The weighted average algorithm is used as thefederated aggregation algorithm. Configure thefollowing parameters for the weighted averagealgorithm:● Enable gradient bifurcation● Enable multi-party computing● Enable Compression Algorithm

Enablegradientbifurcation

The default value is No.If the gradient bifurcation method is enabled, thenumber of iterations of the edge model is dynamicallyadjusted, improving the learning efficiency.

Enablemulti-partycomputing

The default value is No.If multi-party computing is enabled, noise is added toan edge model before the model is transferred. Theserver cannot restore the edge model. This ensuresfederated trust and improves security.

EnableCompressionAlgorithm

The default value is No.Model parameter settings that do not change greatlyare not transferred, reducing network traffic.

EdgeModelLearningRate

Learning rate for updating edge model parametersThe default value is 0.01.A too large value leads to underfitting. A too smallvalue leads to overfitting.

EdgeModelIterationTimes

Number of iterations on an edge node in each traininground. The value must be an integer greater than orequal to 1.The more iterations in each round, the better thetraining effect. However, if the value is too large, thetraining time is too long and meaningless.

Minimumnumber ofedgenodes

Number of edge nodes participating in an iteration ina federated learning iteration task. The value must bean integer greater than or equal to 2.The value of this parameter is equal to the number ofusers in the current federation.Note: The value of this parameter must be the sameas the number of registered edge nodes.

CenterModelAggregation RoundThreshold

The default value is 100.Total number of iteration steps in the federatedlearning task, which is the number of iterations foraggregation on the central node each time

NAIEFederated Learning Service 3 Quick Start

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 13

Area Name Description

CenterModelEvaluationInterval

Iteration interval of center model precision evaluation

CenterModelChangeThreshold

Model convergence thresholdIf the model variation is less than this threshold, thefederated learning iteration process is stopped.

Learningrateattenuationcoefficient

The default value is 1, indicating that the learning rateremains unchanged.If the attenuation step is reached, the learning rateequals the learning rate multiplied by the attenuationcoefficient.

Learningrateattenuation step

Number of aggregation roundsThis parameter is valid only when the value ofLearning rate attenuation coefficient is not set to 1.

Step 3 Click OK. The instance is created, as shown in Figure 3-5.

Figure 3-5 Creating a federation instance

Step 4 View instance information on the main page, as shown in Figure 3-6.

After the instance is created, you can view the instance information on the mainpage, including the instance name test278841, instance type, unique ID (used foredge node registration), version number 0.0.1 (the version number is 0.0.1 whenthe first instance is created), and status. The default version is 0.0.1. You cancreate instances of other versions based on this version. The initial instances are inthe Draft state.

NAIEFederated Learning Service 3 Quick Start

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 14

Figure 3-6 Main page of federated learning

----End

3.2.3 Publishing Federation InstancesAfter a federation instance is created, it is in the draft state and can be used onlyafter being published.

On the My Instances page, locate the created instance and click the arrow in thered box on the right to publish the instance, as shown in Figure 3-7 and Figure3-8.

Figure 3-7 Federation instance page

NAIEFederated Learning Service 3 Quick Start

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 15

Figure 3-8 Publishing a federation instance

3.2.4 Creating Multiple Versions of a Federation InstanceThe default version of the federation instance created for the first time is 0.0.1.You can create other versions based on the default version. The method is asfollows:

Step 1 On the instance viewing page, click New Version on the right of the instance, asshown in Figure 3-9.

Figure 3-9 Instance version creation page

Step 2 In the displayed page, use the default version number 0.0.2 or change the versionnumber. Other configuration items can also be modified. Different versions of thesame instance support different configurations. Save the settings.

NAIEFederated Learning Service 3 Quick Start

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 16

Figure 3-10 Setting federation parameters

----End

3.2.5 Viewing Multiple Versions of a Federation InstanceIf a federation instance has multiple versions, only the latest version is displayedon the federation main page. You can view all versions using the followingmethod:

On the federation home page, click View More Version on the right of theinstance.

Figure 3-11 Federation instance version page

Figure 3-12 Viewing multiple versions of a federated instance

NAIEFederated Learning Service 3 Quick Start

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 17

3.2.6 Deleting Federation InstancesAfter the federated learning process is completed and desired models are trained,the federation instances can be deleted. Before deleting the instances, you need toderegister edge nodes.

Step 1 Deregister the edge node by referring to Deregistering Edge Nodes.

Step 2 Delete federation instances.

On the federation main page, click Delete on the right of an instance to delete it.

Figure 3-13 Deleting a federation instance

----End

3.3 Edge Node Management

3.3.1 Edge Node DescriptionThe overall framework of federated learning includes edge nodes and a centralnode. A federation instance is created on the central node, which is a server. Localalgorithms and data of a user are on the edge node. To perform federatedlearning, the edge node must be registered with a federation instance on thecentral node. A central node (a federation instance) can register multiple edgenodes. One edge node can be registered with only one version of a federationinstance at a time.

For how to deploy an edge node client, see the Client Deployment Guide.

During the registration of an edge node, a multi-party computation key for secure featuresis generated. Therefore, you are advised to update the key periodically (once a year or asrequired) when performing multi-party computation for secure features. Otherwise, the keyinformation may be leaked. To update the key, deregister the edge node first, and thenregister the edge node again.

NAIEFederated Learning Service 3 Quick Start

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 18

3.3.2 Registering Edge NodesTo perform federated learning after creating a federation instance, you need toregister edge nodes in the federation with the instance. The registration procedureis described as follows. For details, see the client interface document.

Step 1 Log in to the edge node and switch to the service user.

su - service

Step 2 Run the following commands to register the edge node:

cd /opt/cloud/Federated-Edge/bin

./register.sh dgh4p7b9 /opt/cloud/Federated-Edge/metadata.json 0.0.1

register.sh indicates the registration script. dgh4p7b9 indicates the ID of thefederated instance to be registered. You can query the ID on the federationinstance page.

/opt/cloud/Federated-Edge/metadata.json 0.0.1 indicates the data structure of theclient, which exists on the edge node.

Figure 3-14 Federation instance page

If the following information is displayed, the registration is successful.

Figure 3-15 Registration success information

----End

3.3.3 Deregistering Edge NodesTo unbind an edge node from a federation instance or delete a federationinstance, you need to deregister the edge node first. The deregistration procedureis described as follows. For details, see the client interface document.

NAIEFederated Learning Service 3 Quick Start

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 19

Step 1 Log in to the edge node and switch to the service user.

su - service

Step 2 Run the following commands to register the edge node:

cd /opt/cloud/Federated-Edge/bin

./unregister.sh

----End

3.4 Running Federation Instances

3.4.1 Running Federation InstancesAfter the registration is complete, the federation instance needs to be run fortraining to obtain a desired training model.

On the federated learning service homepage, click in the row correspondingto the instance. After algorithm parameters are configured, the instance is in theRunning state.

Figure 3-16 Federation instance running page

3.4.2 Checking Results

On the federated learning service homepage, click on the right of theinstance to go to the federated instance details page.

Figure 3-17 Federation instance result check

NAIEFederated Learning Service 3 Quick Start

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 20

On the result details page, you can view the federation details and effect.

● The federation details tab page displays the training status and KPI values ofeach edge node.

● The federation effect page displays the model training accuracy or precisionchange trend.

Figure 3-18 Federated training details page

Figure 3-19 Running result of federated instances

3.4.3 Viewing the ProgressClick the central node in the red box in the following figure to view the progress.

NAIEFederated Learning Service 3 Quick Start

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 21

Figure 3-20 Viewing federated learning progress

Figure 3-21 Viewing federated learning progress

3.5 Appendix

3.5.1 Metadata Definition{ "schemas": [ { "id": "0", "name": "attr0", "index": 0, "dataType": "real", "roleType": "feature", "description": "" }, { "id": "1",

NAIEFederated Learning Service 3 Quick Start

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 22

"name": "attr1", "index": 1, "dataType": "real", "roleType": "feature", "description": "" }, { "id": "2", "name": "attr2", "index": 2, "dataType": "text", "roleType": "label", "description": "", "range": "1,2,3", } ], "statistics": { "rowCount": "3", "columnCount": "150" }}

Each data file corresponds to a metadata file. The metadata definition format isshown above. Each metadata file consists of the schemas and statistics parts.statistics indicates the statistics of the data file. This part is optional. schemasdefines the metadata of each feature, as described in Table 3-2.

Table 3-2 Metadata schemas description

Name Description

id Feature ID

name Feature name, which is usually the service name

index Index of a feature in a file, which starts from 0

dataType Feature data type, including real, text, and integer

roleType ● The value feature indicates a feature column.● The value label indicates a label column.

description Feature description

range Value range, separated by commas (,). Only the labelcolumn needs to provide related information.

NAIEFederated Learning Service 3 Quick Start

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 23

4 FAQs

4.1 How Do I Return to the Homepage of theFederated Learning Service Platform?

To return to the federation instance homepage from the federation instancedetails page, click the federated learning service icon in the upper left corner. Toreturn to the application market page, click the iMaster NAIE icon in the upper leftcorner of the page.

4.2 What Does the Public or Not Parameter MeanDuring Instance Creation?

The homepage of the federated learning service platform has two tabs: MyInstances and Other Instances.

● My Instances: federation instances created by a tenant or a user of a tenantIf this parameter is set to No, only the current user can view the instance.

● Other Instances: public federation instances created by other users If thisparameter is set to Yes, any other user can view the instance in OtherInstances on the homepage of the federated learning service platform, butcannot operate the instance.

A user has full operation permissions on instances created by this user, includingviewing details, editing, deleting, adding other local edge nodes to the instances,and running instances. If an instance is not created by this user, this user can onlyview instance details and apply for adding other edge nodes to this instance, butcannot edit, run, or delete the instance.

4.3 What Is the Difference Between RandomParameter Selection and Server-side ParameterFreezing Among Compression Algorithms?

The Enable Compression Algorithm parameter has three values:

NAIEFederated Learning Service 4 FAQs

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 24

● No: No compression algorithm is used.● Random parameter selection: All parameters are involved in edge node

training. However, some parameter values are randomly discarded beforebeing reported to the FLS to reduce the model size and communication costof model upload.

● Service parameter freezing: The FLS delivers a message to the FLC to freezesome parameters that do not participate in edge node training. This reducesthe model size and communication cost of model upload.

4.4 How Do I Set the Center Model Evaluation IntervalParameter?

The central model evaluation interval is used to set the number of aggregationrounds between evaluation of model indicators, such as the accuracy, precision,and recall rate.

For example, if the Center Model Aggregation Round Threshold parameter isset to 50 and the Center Model Evaluation Interval parameter is set to 2 in aninstance, the instance performs model evaluation every two aggregation rounds.The execution progress is as follows:

● Round 1: Training the model, Uploading the model, and Aggregating themodel

● Round 2: Training the model, Uploading the model, Aggregating themodel, Evaluating the model, and Uploading KPIs

● More

Aggregation is performed for 50 times in total, including 50 times of modeltraining and 25 times of model evaluation.

Recommended configurations: The value of Center Model Evaluation Intervalmust be exactly divided by the value of Center Model Aggregation RoundThreshold.

4.5 How Do I Configure Learning Rate Decay?The parameters Learning rate attenuation coefficient and Learning rateattenuation step are used together.

For example, if the Edge Model Learning Rate is set to 0.01, Learning rateattenuation coefficient is set to 0.8, and Learning rate attenuation step is setto 10, the edge model learning rate gradually decreases by a multiple of 0.8 after10 rounds of aggregation. The values of the edge model learning rate are asfollows:

● Round 1: 0.01● Round 2 to round 9: gradually decreasing from 0.01 to 0.008 (0.01 x 0.8)● Round 10: 0.008● Round 11 to round 19: gradually decreasing from 0.008 to 0.0064 (0.08 x 0.8)● Round 20: 0.0064

NAIEFederated Learning Service 4 FAQs

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 25

● More

4.6 What Are the Format Requirements for ModelPackages that Meet the Trial Run Conditions?

The trial run function simulates the entire process of instance running. The modelpackage must meet the trial run conditions.

● Import: The imported model package must contain basic algorithm files andsample data. If only model files are provided, the function cannot be used.

● Import from the NAIE platform: Trial running is not supported.

4.7 Why Is the Model Size Is the Largest During theFirst Download?

A round of aggregation during instance running consists of the following fivephases: model training, model upload, model aggregation, model evaluation, andKPI upload.

● During model training and model evaluation, models need to be downloadedfrom the FLS.

● During model upload, models need to be uploaded to the FLS.

When the instance runs for the first time, a full model is downloaded forfederation restoration. Federation restoration allows users to restore a federationwhen a federation instance is abnormal and stopped.

4.8 How Do I Use the Federation Restoration Function?This function is applicable to the following scenarios:

● If an exception occurs during the running of a federation instance and theproblem is solved, you can use this function to complete the running of theinstance.

● After a federation instance is run, the effect is not ideal. You need to adjustthe parameters based on this model to continue the federation instance.

NAIEFederated Learning Service 4 FAQs

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 26

5 Glossary

ASecure Multi-party Computing

Secure multi-party computing is a security algorithm used to protect privacy whenno trusted third party exists. In the federation, secure multi-party computing canbe performed to update and encrypt local models. This prevents the server fromobtaining information about edge training data by restoring a model.

BEdge Model Learning Rate

The edge model learning rate is the supervised learning rate and deep learningrate. It is an important hyperparameter and is used to adjust the network weightbased on the gradient of the loss function. A low learning rate leads to slowconvergence of the loss function. A high learning leads to oscillation of the lossfunction. A suitable learning rate can enable the target function to converge tothe local minimum value within a suitable period.

During federated learning, the learning rate is controlled by FLS to achieve theoptimal effect.

Number of Edge Model Iterations

Number of iterations on the edge node in each training round. The number ofmodel training times is calculated by multiplying the number of iterations on theedge node with the number of aggregation rounds on the central node.

Edge Node

Devices in the federation must have the training capability and interact with theFLS using the FLC.

CParameter Freezing Method

Parameter freezing is a compression algorithm, which adjusts the parametersettings for each round of federated aggregation based on the model changetrend to reduce the communication bandwidth

NAIEFederated Learning Service 5 Glossary

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 27

F

Federated Learning Client

Federated learning clients include terminals (clients), edge devices (edges), andlocal data centers (servers). A federated learning client communicates with theFLS, downloads global models, and uploads updated model parameters. Afederated learning client can use local data to perform local training. Theintegration modes include the closed-loop mode and agent mode. In the closed-loop mode, the FLC is responsible for model training, and interconnection dataand a machine learning framework are required. In the agent mode, the servicesystem is responsible for model training, and the FLC only delivers tasks andreport task results.

Federated Learning Server

A federated learning server communicates with the FLC, calculates the modelupdate parameters uploaded by the FLC based on the federated aggregationalgorithm, and delivers global models to the FLC.

L

Federated Console

Frontend page of the federated learning service. You can create federationinstances, configure instance parameters, and publish and start the instances inthis console.

Federated Learning

Federated learning is an encrypted distributed machine learning technology. Withthis technology, local nodes participating in federated learning jointly build AImodels without sharing local data. During federated learning, participants trainmodels locally, encrypt, and upload the updated parts in models to the cloud.Then, the participants aggregate and integrate the updated parts to form a publicmodel, which is delivered by the cloud to all participants. Local training and cloudintegration are performed repeatedly to create an AI model that has betterprediction performance than the initial model.

M

Model Variation

The model variation is a ratio of the sum of the change amount of the centralmodel parameters to the sum of the model parameters. It is an indicator formeasuring how much a model changes. The closer the model variation is to 0, themore the model converged. Theoretically, if the model variation is 0, the optimalsolution is achieved.

Model Evaluation Interval

The model evaluation interval indicates the number of model aggregation timesbetween model evaluation. A shorter interval facilitates the observation of themodel training trend but leads to extra calculation overhead. A longer intervalimpedes the observation of model accuracy.

NAIEFederated Learning Service 5 Glossary

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 28

TGradient Bifurcation Method

This is an adaptive algorithm, which can automatically adjust the number of edgemodel iterations and reduce the local training duration effectively with the sameprecision.

SRandom Parameter Selection

Random parameter selection is a compression algorithm. In a multi-node scenario,each client randomly uploads some parameters to reduce the communicationbandwidth.

XLearning Rate

This is an important hyperparameter in supervised learning and deep learning. It isused to adjust the network weight using the gradient of the loss function. A lowlearning rate leads to slow convergence of the loss function. A high learning leadsto oscillation of the loss function. A suitable learning rate can enable the targetfunction to converge to the local minimum value within a suitable period.

Learning Rate Attenuation

Learning rate attenuation is an adaptive algorithm for reducing the learning ratedynamically. This algorithm smooths federated convergence and achieves anoptimal solution.

Training Platform

The NAIE model training service provides developers with one-stop modeldevelopment services in the communications domain, including datapreprocessing, feature extraction, model training, and model validation. Thisservice provides developers with development environments, simulated validationenvironments, APIs, and a series of development tools, helping developers quicklyand efficiently develop models for the communications domain.

NAIEFederated Learning Service 5 Glossary

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 29

6 Client Deployment Guide

6.1 Installation Precautions

Installation Scenario

The NAIE federated learning service is deployed on the HUAWEI CLOUD. On thecustomer side, a federated learning client (FLC) is deployed to connect to the NAIEfederated learning service on the HUAWEI CLOUD. This document describes howto install the FLC. For details about the networking of NAIE federated learning, seeProduct Introduction > Application Scenarios.

Figure 6-1 Typical networking of NAIE federated learning

Table 6-1 describes the modules in the typical networking of NAIE federatedlearning.

NAIEFederated Learning Service 6 Client Deployment Guide

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 30

Table 6-1 Function description

Function Description

Trainingservice

Provides algorithms and common models based on projectrequirements.

FLS Federated learning service, which aggregates models, combinesthem into common models, and uploads them to the AImarketplace.

GaussDB GaussDB used by FLS

AImarketplace

NAIE operation platform. You can purchase the AI service and candownload published public models from the AI marketplace.

Frontagent

Cloud gateway on the ground side, which ensure security of theconnection with the NAIE cloud service.

FLC Federated learning client, which performs federated learning onthe device side.

Servicetrainingsystem

Performs local training tasks on the device.

Installation Preparation

Download the FLC installation package from the HUAWEI CLOUD FLC console.

Step 1 Log in to the federated learning console.

Step 2 Create a federation instance.

Step 3 Click How to join the federation? to download the FLC installation package.

Figure 6-2 Downloading the FLC installation package

----End

NAIEFederated Learning Service 6 Client Deployment Guide

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 31

6.2 Installation Planning

Configuration PlanningThe following table lists the recommended configurations of the machine wherethe FLC is installed.

Table 6-2 Recommended machine configurations

Service Specifications Data Disk (GB) OperatingSystem

FLC 8C16G 100 EulerOS 2.0(SP2x86_64)

The data disk is mounted to /opt/cloud.

User PlanningThe following table lists the installation user plan for the FLC.

Table 6-3 Installation user

Service UserName

Password OwnerGroup

HomeDirectory

Remarks

FLC service There is nodefaultpassword.You can setapassword.

servicegroup

/home/service

User forinstallingandrunningthe FLC.

6.3 Installing the FLC

Prerequisites● The FLC installation package has been obtained.● The SFTP service has been enabled and Python has been installed on the

machine where the FLC is to be installed.

ContextThe FLC supports two types of users.

NAIEFederated Learning Service 6 Client Deployment Guide

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 32

● Public cloud user: The FLC uses the public cloud user ID, ak/sk, user name,password, and domain name to apply to HUAWEI CLOUD FLS for registration.

● Cloud channel user: The FLC obtains the user token from the cloud channelusing the cloud channel user appid and applies to the HUAWEI CLOUD FLSfor registration.

Procedure

Step 1 Upload and decompress the installation package.

Upload the downloaded FL-Client_x.x.x.xxx.tar.gz package to the "/root" directoryand decompress the package.

[root@EulerOS-BaseTemplate ~]# tar -xzvf FL-Client_x.x.x.xxx.tar.gz

In the package name, x.x.x.xxx indicates the package version number and packagingtimestamp.

After the file is decompressed, a folder named FL-Client_x.x.x.xxx is generated inthe "/root" directory. The folder contains the following files:

● action: Stores installation scripts.● config: Stores the rpm package.● repo: Stores the RPM packages of the JRE and clients.● vars: Stores configuration variable files.● manifest.yml: Basic attribute file of the description package.

Step 2 Run the following command:

Go to the action folder in the decompressed folder and run the sh appctl.shinstall command.

[root@EulerOS-BaseTemplate ~]# cd FL-Client_x.x.x.xxx[root@EulerOS-BaseTemplate FL-Client_x.x.x.xxx]# cd action[root@EulerOS-BaseTemplate action]# sh appctl.sh install

If the message "Install Federated-Client success." is displayed, the FLC issuccessfully installed.

Step 3 Set parameters.

After the FLC is successfully installed, the deployment directory is "/opt/cloud/Federated-Client/". You need to switch to this directory and change the values ofthe configuration parameters in the conf/config.properties file.[root@EulerOS-BaseTemplate ~]# cd /opt/cloud/Federated-Client [root@EulerOS-BaseTemplate Federated-Client]# cd conf[root@EulerOS-BaseTemplate conf]# vi config.properties

NAIEFederated Learning Service 6 Client Deployment Guide

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 33

Table 6-4 Parameter settings

Parameter Description Configuration Example

federalServer.address

URL of the HUAWEICLOUD FLS serviceconnected to the FLC.Contact Huawei federatedlearning service to confirmthe value.

10.10.10.1:7443

client.user Public cloud userregistration information.AK/SK authentication isperformed for registration.● id: User ID.● ak/sk: User access key.

Set sk to a plaintextvalue. The value isautomatically encryptedafter the service isstarted.

● domainName: Name ofthe tenant (account) towhich the user belongs.

You can use vertical bars (|)to configure informationabout multiple users at atime. The user informationis about Huawei publiccloud users and can beobtained on the MyCredentials page.This parameter needs to beset only when a publiccloud user is used forregistration.

{"id":"*******","ak":"*******","sk":"*******","domainName":"*******""}|{"id":"*******","ak":"*******","sk":"*******","domainName":"*******""}

NAIEFederated Learning Service 6 Client Deployment Guide

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 34

Parameter Description Configuration Example

client.user.pwd Public cloud userregistration information.User name and passwordauthentication isperformed for registration.● id: user ID● name: user name● pwd: User password. Set

this parameter to aplaintext value. Thevalue is automaticallyencrypted after theservice is started.

● domainName: Name ofthe tenant (account) towhich the user belongs.

You can use vertical bars (|)to configure informationabout multiple users at atime. The user informationis about Huawei publiccloud users and can beobtained on the MyCredentials page.This parameter needs to beset only when a publiccloud user is used forregistration.

{"id":"*******","name":"*******","pwd":"*******","domainName":"*******""}

client.model.global.path

Global model storage path.It is recommended that youuse the default value.

/opt/cloud/Federated-Client/model/global/

client.model.local.path

Local model storage path.It is recommended that youuse the default value.

/opt/cloud/Federated-Client/model/local/

client.apppackage.path

Path for storing theapplication package.It is recommended that youuse the default value.

/opt/cloud/Federated-Client/apppackage/

NAIEFederated Learning Service 6 Client Deployment Guide

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 35

Parameter Description Configuration Example

client.model.keep.num

Maximum number ofmodel files stored on theFLC. The systemautomatically deletes themodel files in the"client.model.global.path"and"client.model.local.path"configuration paths at01:00 a.m. and retains onlythe maximum number oflatest files.

100

client.policy Type of the interconnectedfederated FLS service.● online: FLS is on the

HUAWEI CLOUD.● offline: FLS on the

client.Set this parameter toonline.

online

client.offline.sftp.host

IP address of the offlineSFTP server. This parameteris valid only whenclient.policy is set tooffline.You do not need to set thisparameter.

10.10.10.12

client.offline.sftp.port

Port of the offline SFTPserver. This parameter isvalid only whenclient.policy is set tooffline.You do not need to set thisparameter.

22

client.offline.sftp.username

Login user of the offlineSFTP server. This parameteris valid only whenclient.policy is set tooffline.You do not need to set thisparameter.

root

NAIEFederated Learning Service 6 Client Deployment Guide

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 36

Parameter Description Configuration Example

client.offline.sftp.password

Password for the login userof the offline SFTP server.This parameter is valid onlywhen client.policy is set tooffline.You do not need to set thisparameter.

-

cloud.region FLS deployment zone. Thisparameter is valid onlywhen client.policy is set toonline.Contact Huawei federatedlearning service to confirmthe value.

cn-north-1

iam.global.endpoint Address provided by IAMfor external access to theglobal zone. Thisparameter is valid onlywhen client.policy is set toonline.Contact Huawei federatedlearning service to confirmthe value.

iam.huaweicloud.com:31943

obs.endpoint Address provided by theOBS for external access.This parameter is valid onlywhen client.policy is set toonline.Contact Huawei federatedlearning service to confirmthe value.

obs.cn-north-1.myhwclouds.com

obs.location OBS deployment zone. Thisparameter is valid onlywhen client.policy is set toonline.Contact Huawei federatedlearning service to confirmthe value.

cn-north-1

client.csb Whether to use a cloudchannel user forregistration.● on: Use a cloud channel

user for registration.● off: Use a public cloud

user for registration.

off

NAIEFederated Learning Service 6 Client Deployment Guide

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 37

Parameter Description Configuration Example

client.csb.app Contact Huawei federatedlearning service to confirmthe application ID andregion for a cloud channeluser.You can use vertical bars (|)to separate informationabout multipleapplications.This parameter needs to beset only when a cloudchannel user is used forregistration.

{"id":"*******","region":"*******","gray":"no"}

client.csb.adapter.address

Contact Huawei federatedlearning service to confirmthe service address of theintegrated adapter.This parameter needs to beset only when a cloudchannel user is used forregistration.

https://10.10.10.10:8080

client.python Local python path /opt/python/envs/tf/bin/python

business.model.in.type

Input of the service trainingsystem on the edge node● model: model● model_change: model

change amount

model

business.model.out.type

Output of the servicetraining system on theedge node● model: model● model_change: model

change amount

model_change

NAIEFederated Learning Service 6 Client Deployment Guide

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 38

Parameter Description Configuration Example

model.env Model frameworkinformation supported bythe system● id: model framework ID● env: model framework

name● in_name: name of the

input model or modelchange of the FLC onthe edge node

● out_name: name of theoutput model or modelchange of the FLC onthe edge node

Only the values ofin_name and out_namecan be changed. The valuesof id and env cannot bechanged.For example, if the modelframework used by the FLCon the edge node istensorflow, the inputmodel name is model, andthe output model name isalso model, theconfigurations are asfollows:{"id":"1","env":"tensorflow","in_name":"model","out_name":"model"}

{"id":"1","env":"tensorflow","in_name":"model","out_name":"model"}|{"id":"2","env":"caffe","in_name":"new.caffemodel","out_name":"common.caffemodel"}|{"id":"3","env":"pytorch","in_name":"net.pth","out_name":"net.pth"}

Step 4 Start the service.

Switch to the service user, go to the "/opt/cloud/Federated-Client/bin" directory,and run the start.sh command to start the service.[root@EulerOS-BaseTemplate conf]# su - service[service@EulerOS-BaseTemplate conf]$ cd /opt/cloud/Federated-Client/bin[service@EulerOS-BaseTemplate bin]$ sh start.sh

If the message "Start Federated-Client success" is displayed, the service is startedsuccessfully.

----End

6.4 AppendixThe following table lists common FLC operation commands.

NAIEFederated Learning Service 6 Client Deployment Guide

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 39

Table 6-5 Common commands

Command

Path Function

checkStatus.sh

/opt/cloud/Federated-Client/bin

Check whether the FLC process and port arestarted normally.

startall.sh /opt/cloud/Federated-Client/bin

Start the FLC service and deploy a periodicmonitoring task in the crontab to check theFLC process status. If the FLC process isabnormal, the process is automatically starts.

start.sh /opt/cloud/Federated-Client/bin

Start the FLC service.

stopall.sh /opt/cloud/Federated-Client/bin

Stop the FLC service and delete the periodicmonitoring task deployed in the crontab tocheck the FLC process status.

stop.sh /opt/cloud/Federated-Client/bin

Stop the FLC service.

NAIEFederated Learning Service 6 Client Deployment Guide

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 40

7 Federated Learning Model PackageSpecifications

7.1 Application Scenarios

Figure 7-1 Model package application scenarios

Model package application scenarios are as follows:

NAIEFederated Learning Service 7 Federated Learning Model Package Specifications

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 41

● Service personnel import model packages from the training platform.Algorithm personnel can develop algorithms on the training platform. Servicepersonnel import developed model packages from the training platform usingthe federated service console. The imported model packages meet thefederated learning package specifications.

● Service personnel import model packages from the external system.Algorithm personnel can develop algorithms in a third-party environment,package the algorithms in compliance with the federated learning packagespecifications, and import the model packages using the federated serviceconsole.

● Service personnel run model packages on the federated server. They can runmodel initialization, model training, and model evaluation algorithms inmodel packages using the federated service console.

● Service personnel publish model packages on the federated server. They canpublish model packages using the federated service console. During modelpackage publishment, the model initialization algorithm can be implementedto generate the initial model for federated learning

After being published, a model package can be used by edge nodes. Theapplication scenarios of a model package on an edge node are as follows:

● Model package download: The edge node execution environment downloadsmodel packages from the federated server for local training.

● Local model package running: After downloading model packages from thefederated server, the edge node execution environment parses the modelpackages according to the NAIE specifications, runs the model training andevaluation algorithms in the packages, generates local models for thefederation, and participates in federated training.

7.2 Model Package StructureThe model package format used for federated learning complies with the NAIEunified model package specifications. The following figure shows the directorystructure of NAIE model packages.

● metadata.json is a metadata file that describes a model package. It complieswith the NAIE model package specifications and is extended based onfederation requirements.

● "model" is the directory that stores the initial model. The NAIE specificationsdo not specify the model directory name. According to federated model

NAIEFederated Learning Service 7 Federated Learning Model Package Specifications

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 42

package specifications, the model directory name is model. If an initial modelis not provided, the model directory can be empty.

● "retrain" is the directory that stores retraining algorithms. The content in the"retrain" directory can be customized, except the "data" directory. The "data"directory stores retraining sample data, which is used for the federated serverto perform a trial run for model packages. The "retrain" directory can also beempty. However, the "model" and "retrain" directories cannot be empty at thesame time.

7.2.1 Model Package RestrictionsThe restrictions on model packages are as follows:

1. A model package must be in .zip format.2. The model package name can contain only letters (from A to Z or a to z).3. The size of a compressed model package must be less than 100 MB.4. The root directory of a model package must contain the metadata.json file,

which is the metadata description file of the package. For details about thedefinition of the description file, see Model Package Metadata.

7.2.2 Model Package Metadatametadata.json is a metadata file that describes a model package. It complies withthe NAIE model package specifications and is extended based on federationrequirements. The file contains four parts, as shown in the following figure.

Figure 7-2 Metadata description

The metadata.json file is in standard JSON format

The following is an example of the metadata.json file format:

{ "basicinfo":{ "name": "minist_model", "type": "model", "id": "minist_model", "version": "1.0", "model_file_type": "others", "description": "handwriting recognition model package"

NAIEFederated Learning Service 7 Federated Learning Model Package Specifications

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 43

}, "runtime":[ { "runtime_type": "retrain", "env":{ "env_name": "TensorFlow", "env_type": "system_defined", "env_version": "TF-1.13.1-python3.6", "env_dependencies":{ "enable_gpu": "True", "software_dependencies":{ "installer": "pip", "python_requirements": "./requirements.txt"

} } } } ],

"methods": [ { "name": "init", "entry": "retrain/init.py:init_model", "type": "retrain", "input_params": [ { "name": "model_path", "type": "string", "not_null": "True", "default_value": "model" } ] }, { "name": "train", "entry": "retrain/minist_train.py:fit", "type": "retrain", "input_datameta":{ "name": "minist_data", "min_size": 10000, "label_dataset": "minist_data", "label_index": 20, "datasets":"minist_data"

}, "input_params": [ { "name": "data_url", "type": "string", "not_null": "True" }, { "name": "batch_size", "type": "int", "not_null": "True", "default_value": "256" }, { "name": "keep_prob", "type": "float", "not_null": "True", "default_value": "0.5" }

] }, { "name": "test",

NAIEFederated Learning Service 7 Federated Learning Model Package Specifications

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 44

"entry": "retrain/minist_test.py:evaluate", "type": "retrain", "input_params": [ { "name": "data_url", "type": "string", "not_null": "True" } ] } ], "datasets": [ { "name": "minist_data", "features": [ { "name": "f1", "type": "int", "index": 0

}, { "name": "f2", "type": "int", "index": 1

}, { "name": "f3", "type": "int", "index": 2

}, { "name": "f4", "type": "int", "index": 3

} ] } ]}

Figure 7-2 describes the fields in the metadata.

Table 7-1 Basic model package information (basicInfo)

Name Type Cardinality Description

name String 1 Name

type String 1 Service catalogtype. For afederated modelpackage, thisvalue is fixed tomodel.

version String 1 Version

NAIEFederated Learning Service 7 Federated Learning Model Package Specifications

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 45

Name Type Cardinality Description

id String 1 ID. This parameteris for internal useonly. The defaultvalue is the sameas the value ofname.

NAIEFederated Learning Service 7 Federated Learning Model Package Specifications

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 46

Name Type Cardinality Description

model_file_type String 1 Model file typeThe followingmodel file typesare supported:tf-pb: TensorFlowpb model filesklean: sklearntraining model filetf-ck: TensorFlowcheckpoint modelfilecaffe: Caffe modelfilepytorch: PyTorchmodel fileothers: othertypesNone: no modelfileThe trainingplatform does notsupport tf-ck,caffe, or pytorchmodel packages.The three types ofpackages aredisplayed asothers on theplatform.If the value ofmodel_file_typeis not None, thefederated serveruses the model inthe modelpackage as theinitial model.Otherwise, thefederated serverneeds to generatean initial modelby retraining.

creation_time String 1 Creation time

description String 1 Model description

NAIEFederated Learning Service 7 Federated Learning Model Package Specifications

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 47

Table 7-2 Running environment of a federated model package (runtime)

Name Type Cardinality Description

env Object 1 Runningenvironment onwhich the servicecatalog depends

runtime_type String 1 Runtime type,which can beretraining orinferenceFor a federatedmodel package,this value is fixedto retrain.

Table 7-3 System running environment (env)

Name Type Cardinality Description

env_name String 1 Runningenvironmentname

env_type String 1 Runningenvironment type.The runningenvironmentincludes the built-in and user-defined runningenvironments. Fordetails about thebuilt-in runningenvironment, seeTable 7-4.user_defined:user-definedrunningenvironmentsystem_defined:built-in runningenvironment

env_version String 1 Version of therunningenvironment

NAIEFederated Learning Service 7 Federated Learning Model Package Specifications

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 48

Name Type Cardinality Description

env_dependencies

Object 1 Dependency ofthe runningenvironment

Table 7-4 Supported built-in running environments

Environment Name Environment Type Description

TensorFlow ● TF-1.13.1-python2.7● TF-1.13.1-python3.6● TF-1.8.0-python2.7● TF-1.8.0-python3.6

● TensorFlow1.13.1+python2.7

● TensorFlow1.13.1+python3.6

● TensorFlow1.8.0+python2.7

● TensorFlow1.8.0+python3.6

Caffe ● Caffe-1.0- python2.7● Caffe-1.0- python3.6

● Caffe 1.0+python2.7● Caffe 1.0+python3.6

PyTorch ● PyTorch-1.3-python2.7● PyTorch-1.3-python3.6

● PyTorch1.3+python2.7

● PyTorch1.3+python3.6

Python3.7 ● python3.7

Table 7-5 Software and hardware dependencies (env_dependencies)

Name Type Cardinality Description

enable_gpu Boolean 1 Whether GPU issupported. Thedefault value isfalse.

software_dependencies

Object 0..1 Required softwarepackage

NAIEFederated Learning Service 7 Federated Learning Model Package Specifications

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 49

Table 7-6 Third-party software dependencies (software_dependencies)

Name Type

Cardinality

Description

installer String

1 Installation mode. Only pip is supported.

python_requirments

string

0..1 Path of the Python-dependent file requirements.txt,which is available only when the pip installationmode is used. The value of this parameter takesprecedence over the value of the packagesparameter.

packages Array

0..1 Dependent third-party software package, which is anarray whose elements are package names.

Table 7-7 Third-party software package dependencies (packages) (array)

Name Type Cardinality

Description

name String

1 Software package name

version String

1 Software package version

restrain String

0..1 Version restriction. This parameter is mandatory onlywhen the version parameter is set. The value can beEXACT, ATLEAST, or ATMOST.EXACT indicates that the specified version isinstalled.ATLEAST indicates that the version to be installed isnot earlier than the specified version.ATMOST indicates that the version to be installed isnot later than the specified version.

Table 7-8 Federated model package publishing methods (methods)

Name Type Cardinality

Description

name String

1 For a federated model package, the value can be init(model initiation), train (model training), or test(evaluation method).

NAIEFederated Learning Service 7 Federated Learning Model Package Specifications

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 50

Name Type Cardinality

Description

entry String

1 Method entry, which consists of two parts: {filepath}and {funName}filepath: entry file path, which is a relative file pathin the model package. An example is retrain/init.py.funName: function name in the file, which isoptional. If the python file contains the main startupmethod, use the default value.An example is retrain/init.py: init_model.NOTE

If a path contains a directory, use a slash (/) instead of abackslash (\) as the path separator.

type String

1 Method type. The value is fixed to retrain.

input_datameta

Object

0..1 Input dataset set. For details about the definition ofa single object, see the metadata format description.

description

String

0..1 Method description

input_params

array 0..1 Input parameter. For the definition of a singleparameter, see the parameter format definition.

output_params

Array

0..1 Output parameter. For the definition of a singleparameter, see the parameter format definition.

Table 7-9 Input dataset (DataMeta)

Name Type Cardinality

Description

name String

1 Dataset set name

min_size Numeric

0..1 Minimum number of dataset records for startingretraining

label_dataset

String

0..1 Name of the dataset where the tag is

label_index

Numeric

0..1 Index position of a tag in a file. The index starts from0. If there is no tag, the value is -1.

NAIEFederated Learning Service 7 Federated Learning Model Package Specifications

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 51

Name Type Cardinality

Description

datasets String

1 Set of dataset names. Separate multiple values withcommas (,).An example is {Dataset name 1},{Dataset Name 2},{Dataset name 3}.Currently, only one dataset is supported.

Table 7-10 Method input and output parameter types (Param)

Name Type Cardinality

Description

name String

1 Parameter name

type String

1 Parameter type, which can be int, float, bool, bytes,or string

not_null String

1 Whether the value can be nulltrue: The value cannot be null.false: The value can be null.

length String

0..1 Parameter length. This parameter is valid when thetype parameter is set to bytes or string.

default_value

String

0..1 Default value

Table 7-11 Input dataset (datasets)

Name Type Cardinality

Description

name String

1 Dataset name

features Array 1 Feature description, which is an array. For detailsabout the definition of a single object, see thefeature format definition.

description

String

0..1 Dataset description

NAIEFederated Learning Service 7 Federated Learning Model Package Specifications

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 52

Table 7-12 Data features (Feature)

Name Type Cardinality

Description

name String 1 Feature name

type String 1 Feature type, which can be integer, real, text, ordatetime

index Numeric

1 Index position of a feature in a file. The value startsfrom 0.

description

String 0 Feature description

All information in the metadata.json file, including the field name, valid enumerated value,and path, is case sensitive.

7.3 Algorithm InterfacesThe parameters described in the following interfaces are algorithm parametersrequired for a federation. You can add parameter definitions based on thealgorithm parameters.

7.3.1 Input Parameter ParsingThe code must be able to receive the following parameters delivered by the server:

● type: task type, which can be training or evaluation. training indicates atraining task. evaluation indicates an evaluation task.

● train_url: training model output path● data_url: dataset path● model_path: common model path● subModelLearningRate: learning rate● subModelIterateTimes: number of iterationsdef parse_args() -> argparse.Namespace: """ Parsing args :return: args -- parsed args in argparse.Namespace format """ parser = argparse.ArgumentParser(description='Fedetated Learning', formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('--type', type=str, choices=[training, evaluation]) parser.add_argument('--train_url', type=str) parser.add_argument('--data_url', type=str) parser.add_argument('--model_path', type=str) parser.add_argument('--subModelLearningRate', type=float) parser.add_argument('--subModelIterateTimes', type=int)

NAIEFederated Learning Service 7 Federated Learning Model Package Specifications

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 53

args, _ = parser.parse_known_args()

return args

7.3.2 Initialization Interfacedef init_model(train_url: str) -> Tuple[int, str]: """ init model and save model to train url :param train_url: the path to store init model :return: Tuple(code,reason) -- 0 indicates that the model was succsessfully initialized and failed in other cases

====================== YOUR CODE HERE ====================== you can write your init model function here. ============================================================ """ pass

7.3.3 Model Training Interfacedef train(data_url: str, train_url: str, subModelLearningRate: float, subModelIterateTimes: int, model_path: str) -> Tuple[int, str]: """ train local model :param data_url: the path of training data :param train_url: the path to store model after training :param subModelLearningRate: learning rate in training process :param subModelIterateTimes: iterate times in training process :param model_path: the path of common model :return Tuple(code,reason) -- 0 indicates that training was successful, otherwise failed

====================== YOUR CODE HERE ====================== you can write your train function here. ============================================================ """ pass

7.3.4 Model Evaluation Interfacedef evaluate(model_path: str, data_url: str) -> Tuple(str, str): """ evaluate common model :param model_path: the path of common model :param data_url: the path of evaluating data :return: Tuple(KPI,value) KPI in: "accuracy", "precision", "recallrate", "flscore"

====================== YOUR CODE HERE ====================== you can write your evaluate function here. ============================================================ """ pass

7.4 AppendixObtain the sample model package from https://bbs.huaweicloud.com/forum/thread-33720-1-1.html.

You can download attachments only after logging in to the system using aHUAWEI CLOUD account.

NAIEFederated Learning Service 7 Federated Learning Model Package Specifications

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 54

The sample model package is DemoPackage.zip. The sample code isDemoCode.zip.

The sample code contains the following files:

● init.py: script for initializing a federated model● main.py: script corresponding to federated models and evaluation● build_data.py, local_train.py, and tf_adapter: dependency scripts

NAIEFederated Learning Service 7 Federated Learning Model Package Specifications

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 55

8 API Reference (FL-Server)

8.1 Before You StartThis document provides guidance for NAIE service development and test personnelto subscribe to AI services or manage service resources using NAIE federatedlearning APIs.

Table 8-1 About This Document

Phase Link

Understand the API components andinterface list.

● Overview

Prepare for using interfaces. ● Environment Preparation

Understand the representational statetransfer (REST) message body and usage.

● Methods of UsingInterfaces

Understand interface usage. ● Federation Instance Service● Federated Client Service

Understand common parameters. ● Common Error Codes

8.2 OverviewThe following table lists the external APIs of federated learning.

Type Interface Description

Federationinstanceservice

Create federation instances. Create federation instances.

Update federation instances. Update federation instances.

Delete federation instances. Delete federation instances.

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 56

Type Interface Description

Operate federation instances. Operate federation instances.

Query a single federationinstance.

Query a single federationinstance.

Query multiple versions of afederation instance.

Query multiple versions of afederation instance.

Query the running progress offederation instances.

Query the running progress offederation instances.

Query monitoring informationabout federation instances.

Query monitoring informationabout federation instances.

Federated clientservice

Register federated clients. Register federated clients.

Deregister federated clients. Deregister federated clients.

Download federated models toclients.

Download federated models toclients.

Upload local models fromclients.

Upload local models from clients.

Upload KPIs from clients. Upload KPIs from clients.

Send heartbeat information fromclients.

Send heartbeat information fromclients.

8.3 Environment PreparationObtaining Request Authentication

Obtaining the Project ID/Tenant ID

8.3.1 Obtaining Request AuthenticationThere are two authentication methods for interface invocation. You can use eitherof the methods to perform the authentication. AK/SK authentication isrecommended because it is more secure than token authentication.

● Token authentication: Requests are authenticated using tokens.

Token AuthenticationIf you use a token for authentication, you must obtain the user's token and add X-Auth-Token to the request message header of the service API when invoking anAPI.

Step 1 Send POST https://Endpoint of IAM/v3/auth/tokens to obtain the endpoint of IAMand the region name in the message body.

For details, see Regions and Terminal Nodes.

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 57

If the service area name is All, select the IAM cn-north-1 endpoint.

The following is a request example.

Replace contents in italic in the sample codes with actual contents. For details, see theIdentity and Access Management API Reference.

{ "auth": { "identity": { "methods": [ "password" ], "password": { "user": { "name": "username", "password": "password", "domain": { "name": "domainname" } } } }, "scope": { "project": { "name": "cn-north-1aaa" //Assume that the project name is cn-north-1aaa. } } } }

Step 2 Obtain the token. For details, see section "Obtaining User Token" in Identity andAccess Management API Reference. The value of X-Subject-Token in the responseheader is the token value.

Step 3 Invoke a service API, add X-Auth-Token to the message header, and set the valueof X-Auth-Token to the token obtained in step 2.

----End

8.3.2 Obtaining the Project ID/Tenant IDA project ID (project_id or tenant_id because both of them have the samemeaning in this document) is required for some URLs when invoking an API.Therefore, you need to obtain a project ID on the console before invoking an API.To obtain the project ID, perform the following steps:

1. Register and log in to the management console.2. Click the username and select Basic Information from the drop-down list.3. On the Basic Information page, click Manage.

On the My Credential page, view project IDs in the project list.

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 58

Figure 8-1 Viewing the project ID

8.4 Methods of Using InterfacesPublic cloud APIs comply with the RESTful API design principles. REST allocatesURIs to distributed resources so that the resources can be located. Applications onclients use URLs to obtain the resources. The URL format is https://Endpoint/uri.uri indicates the resource path, which is the API access path.

Public cloud APIs use HTTPS as the transmission protocol. Requests/Responses aretransmitted by using JSON messages, with media type represented byApplication/json.

The ModelArts provides REST APIs.

REST observes the entire network from a resource perspective and provides serviceresource operations, such as creation, query, update, and deletion.

A REST API request/response consists of the following parts:

● Request URI

● Request header

● Request body

● Response header

● Response body

Request URI● URI format

{URI-scheme} :// {Endpoint} / {resource-path} ? {query-string}

Most languages or frameworks require that a request URL be sent in arequest message.

● URI parameters

Parameter Description

URI-scheme Protocol used to transmit requests.

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 59

Parameter Description

Endpoint Domain name or IP address of the server that carries theREST service endpoint. Set this parameter based onRegions and Terminal Nodes.

resource-path Resource path, that is, API access path, which is obtainedfrom the URI of a specified API, for example, v3/auth/tokens.

Query string Optional, which can be set to API version or resourceselection criterion.

Request HeaderA request header contains the following parts:

● HTTP method (or operation), which informs the service of the operation type

The following table describes this method.

Method Description

GET Requests a server to return a specified resource.

PUT Requests a server to update a specified resource.

POST Requests a server to add resources or perform a specialoperation.

DELETE Requests a server to delete specified resources, for example, anobject.

HEAD Requests a server resource header.

PATCH Requests a server to update a part of a resource.If a target resource does not exist, PATCH may create a resource.

● Optional additional request header field, such as the field required by aspecified URI and HTTP method. The following table describes the fields in acommon request header.

Name Description Mandatory or Not Example

Content-Type

Message bodytype (format)

Yes application/json

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 60

Name Description Mandatory or Not Example

X-Auth-Token

Tokenauthenticationinformation,which is obtainedthrough tokenauthentication.

This parameter ismandatory whenthe tokenauthenticationmode is used.

-

X-Sdk-Date

Time when arequest is sent

This parameter ismandatory whenthe AK/SKauthenticationmode is used.

20151222T034042Z

Authorization

Signatureauthenticationinformation. Thevalue is from therequest signatureresult.

This parameter ismandatory whenthe AK/SKauthenticationmode is used.

SDK-HMACSHA256Credential=ZIRRKMTWPTQFQI1WKNKB/20151222/cnnorth-1/ec2/sdk_request,SignedHeaders=connection;contenttype;host;x-sdk-date,Signature=7972cc9145876d174b3862188a0f61819431fa71c8a8a060809ea8b898e3eaa9Host:www.myhwclouds.com

Request Body

A request body is generally sent in a structured format (for example, JSON),corresponding to Content-type in the request header, and is used to transfercontent except the request header.

If a request body contains a parameter in Chinese, the parameter must be codedin UTF-8 mode.

Response Header

A response header contains the following parts:

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 61

● HTTP status code, including success codes 2xx and error codes 4xx or 5xx.Alternatively, the status code defined by the service can be returned, as shownin the API document.

● Additional response header field, such as the field required by the responsesupporting a request (the field in the Content-type response header). Thefollowing table describes the fields in a common response header.

Name Description Example

Date Standard HTTPS header. The fieldindicates the time when a responseis sent. The time format follows RFC822.

Mon, 12 Nov 200715:55:01 GMT

Server Standard HTTPS header, whichcontains information about thesoftware used by the server toprocess requests.

Apache

Content-Length Standard HTTPS header, whichspecifies the length of the entity textand is stored as bytes in decimalnumber.

xxx

Content-Type Standard HTTPS header, whichspecifies the media type of the entitytext sent to the recipient.

application/json

Response Body

A response body is generally sent in a structured format (for example, JSON),corresponding to Content-type in the response header, and is used to transfercontent except the response header.

Request Initiation

There are three methods to initiate constructed requests:

● cURLcURL is a command line tool, which can be used to perform URL operationsand transfer information. cURL functions as an HTTP client to send HTTPrequests to the server and receive responses. cURL is applicable to APIdebugging. For details about cURL, see https://curl.haxx.se/.

● CodingYou can invoke APIs by coding to assemble, send, and process requests.

● RESTful clientMozilla and Google provide graphical browser plug-ins for RESTful APIs tosend and process requests. For Firefox, see FirefoxREST Client. For Chrome,see Chrome RESTClient.

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 62

8.5 Federation Instance ServiceCreating Federation Instances

Updating Federation Instances

Deleting Federation Instances

Operating Federation Instances

Querying a Single Federation Instance

Querying Multiple Versions of a Federation Instance

Querying the Running Progress of Federation Instances

Querying Monitoring Information About Federation Instances

8.5.1 Creating Federation Instances

Function

Create federation instances.

URI● URI format:POST https://{{Federal-Address}}/federated/v1/instance

● Parameter description

Parameter Mandatory orNot

Type Description

name Yes String Federation instance name

version Yes String Federation instance version

type Yes String Federation type

creator Yes String Creator

description No String Description

baseAlgorithm

Y BaseAlgorithm Basic algorithm information

aggregateAlgorithm

Yes AggregateAlgorithm

Aggregation algorithmconfiguration

The following table describes aggregation algorithm types.

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 63

Parameter

Mandatory orNot

Type Description

type Yes String Set this parameter to AVG.

superArgs

Yes Map<String,String>

Model hyperparameterThe following hyperparameter keys aresupported:useBifurcation: The value can be true orfalse. The default value is false.multipartCalc: The value can be true orfalse. The default value is false.COMPRESS_FREEZE_PARAM_CLIENT: Thevalue can be true or false. The defaultvalue is false.COMPRESS_FREEZE_PARAM_SERVER: Thevalue can be true or false. The defaultvalue is false.COMPRESS_RANDOM_PARAM: The valuecan be true or false. The default value isfalse.subModelLearningRate: client learning ratesubModelIterateTimes: number of clienttraining roundsmodelUpdateCompressionRatio: modelupdate compression rate, which is set to 1by default.nodeNumPerIteration: minimum number ofaggregation nodesmaxIterateSteps: maximum number ofaggregation roundsiterateSteps: aggregation roundmodelChangemodelChange: modelvariation threshold. If the value is less thanthe threshold, the federation stops.decayRate: decay rate. The value 1indicates that the decay algorithm isdisabled.decaySteps: triggering conditions for thedecay algorithmgeneralModelTestInterval: number ofrounds between aggregation evaluation

The following table describes basic algorithm types.

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 64

Parameter MandatoryorNot

Type Description

remote No RemoteBaseAlgor-ithm

Algorithm package informationobtained from the trainingplatform. Either this or the localparameter must be set.

local No LocalBaseAlgorithm

Algorithm package informationuploaded from the local PC.Either this or the remoteparameter must be set.

modelEvaluationIndex

Yes String[] Model evaluation methodThe enumerated values are asfollows:accuracyprecisionrecallRate

localRunEnv Y String Local environment type1: TF2: CAFFE

The following table describes local basic algorithm types.

Parameter Mandatory orNot

Type Description

packageId No String ID of an uploadedpackage.

The following table describes remote basic algorithm types.

Parameter Mandatory orNot

Type Description

projectId Yes String Project ID

projectName No String Project name

modelId Yes String Model ID

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 65

8.5.2 Updating Federation Instances

Function

Update federation instances.

URI● URI format:

PUT https://{{Federal-Address}}/federated/v1/instance

● Parameter description (same as that for creating federation instances)

Request● The following is a request example:

PUT https://{{Federal-Address}}/federated/v1/instance{"name": "demo","creator": "qianlihai","type": "resourceEfficiency","description": null,"version": "0.0.1","baseAlgorithm": {"remote": {"projectId": "fd9d055e57274a529284d9176"},"modelEvaluationIndex": ["accuracy"],"localRunEnv": 1},"aggregateAlgorithm": {"type": "SGD","superArgs": {"subModelLearningRate": "0.01","subModelIterateTimes": "1","modelUpdateCompressionRatio": "1","nodeNumPerIteration": "2","generalModelLearningRate": "0.001","maxIterateSteps": "3","generalModelTestInterval": "1","modelChange": "0.0000001","COMPRESS_FREEZE_PARAM_SERVER":"false","COMPRESS_FREEZE_PARAM_CLIENT":"false","COMPRESS_RANDOM_PARAM":"false"}}}

ResponseSame as that for creating federation instances.

Return Value

For details, see the return values of common requests.

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 66

8.5.3 Deleting Federation Instances

FunctionDelete federation instances.

URI● URI format:DELETE https://{{Federal-Address}}/federated/v1/instance/{instanceId}?version={version}

● Parameter description

Parameter

Mandatory orNot

Type Description

instanceId

Yes String Federation instance ID

version N String Federation instance version. If thisparameter is not set, all versions ofthe instance are deleted.

Request● The following is a request example:DELETE https://{{Federal-Address}}/federated/v1/instance/fflq5ro9?version=0.0.1

Response● The following is an example of a successful response:{ "success": true, "code": "0", "msg": "success", "ext": null}

● The following is an example of a failed response:{ "success": false, "code": "23469334.14010.10001", "msg": "you have not right to operator this instance!", "ext": null}

● Parameter description

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 67

Parameter

MandatoryorNot

Type Description

code No String Status code. The value 0 indicatessuccess. A non-zero value indicatesfailure.

msg No String Returned message. If the operationfails, an error message is returned.

success No Boolean Whether the operation is successful

ext No Map Extended information

Return Value

For details, see the return values of common requests.

8.5.4 Operating Federation Instances

Function

Operate federation instances.

URI● URI format:POST https://{{Federal-Address}}/federated/v1/instance/{instanceId}/action

● Parameter description

Parameter

MandatoryorNot

Type Description

instanceId

Yes String Federation instance ID

version Y String Federation instance version

type Y String Supported operation type. The values are asfollows:publish: Publish.start: Start.stop: Stop.resumeStart: Restore the federation.tryDo: Perform a trial run.

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 68

Request● The following is a request example:POST https://{{Federal-Address}}/federated/v1/instance/{instanceId}/action{ "type": "publish", "version": "0.0.1"}

Response● The following is an example of a successful response:{ "success": true, "code": "0", "msg": "fflq5ro9", "ext": null}

● The following is an example of a failed response:{ "success": false, "code": "23469334.14010.10001", "msg": "you have not right to operator this instance!", "ext": null}

● Parameter description

Parameter Mandatory orNot

Type Description

code No String Status code. The value0 indicates success. Anon-zero valueindicates failure.

msg No String Returned message. Ifthe operation fails, anerror message isreturned.

success No Boolean Whether the operationis successful

ext No Map Extended information

Return ValueFor details, see the return values of common requests.

8.5.5 Querying a Single Federation Instance

FunctionQuery a single federation instance.

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 69

URI● URI format:GET https://{{Federal-IP}}/federated/v1/instance/{instanceId}?verssion={version}

● Parameter description

Parameter Mandatory orNot

Type Description

instanceId Yes String Federation instance ID

version No String Federation instance version.If this parameter is not set,all versions of the instanceare deleted.

Request● The following is a request example:GET https://{{Federal-IP}}/federated/v1/instance/a3qy1h0m?version=0.0.1

Response● The following is an example of a successful response (the instance object is

returned; for the definition, see the section of creating federation instances):

{ "version": "0.0.1", "name": "SA_Case4", "description": null, "type": "experience", "serverType": "cloud", "status": "READY", "consoleStatus": "Ready", "baseAlgorithm": { "remote": { "projectId": "c708c4f3083948648c4d9a9c879ee9e6", "projectName": "ServiceAwareness_FL", "modelId": null }, "local": null, "modelEvaluationIndex": [ "accuracy" ], "localRunEnv": 2 }, "aggregateAlgorithm": { "type": "AVG", "superArgs": { "generalModelLearningRate": "1", "COMPRESS_FREEZE_PARAM_CLIENT": "false", "generalModelTestInterval": "10", "decayRate": "1", "nodeNumPerIteration": "3", "decaySteps": "1", "modelUpdateCompressionRatio": "1", "useBifurcation": "false",

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 70

"maxIterateSteps": "300", "COMPRESS_RANDOM_PARAM": "false", "multipartCalc": "false", "iterateSteps": "500", "subModelIterateTimes": "20", "subModelLearningRate": "0.0005", "COMPRESS_FREEZE_PARAM_SERVER": "false", "modelChange": "0.0000001" } }, "taskId": "taskId-2jaf13eo", "federatedTimes": null, "currentSubTaskId": "taskId-g1sy1lhf", "creator": "ai_train_s00453560", "createTime": "2019-11-09 11:43:10", "updateTime": "2019-11-09 11:43:10", "projectId": "050698b9de00d5e82f1dc0057ca15e62", "operationResult": "failed", "accuracy": null, "recallRate": null, "precision": null, "f1Score": null, "csbUserId": null, "csbAppId": null, "isPublic": false, "clients": [], "owner": true, "id": "a3qy1h0m"}

Return ValueFor details, see the return values of common requests.

8.5.6 Querying Multiple Versions of a Federation Instance

FunctionQuery multiple versions of a federation instance.

URI● URI format:GET https://{{Federal-IP}}/federated/v1/instances/{instanceId}? version={version}

● Parameter description

Parameter Mandatory orNot

Type Description

instanceId Yes String Federation instanceID

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 71

Parameter Mandatory orNot

Type Description

version No String Federation instanceversion. If thisparameter is not set,all versions of theinstance are deleted.

Request● The following is a request example:GET https://{{Federal-IP}}/federated/v1/instances/lfzad3kl

Response● The following is an example of a successful response (the instance object is

returned; for the definition, see the section of creating federation instances):

[ { "version": "0.0.2", "name": "test1129", "description": null, "type": "fault", "serverType": "cloud", "status": "DRAFT", "consoleStatus": "Draft", "baseAlgorithm": { "remote": { "projectId": "3c93079c85174014a969b94a04d35a4b", "projectName": "fl_z00511000", "modelId": null }, "local": null, "modelEvaluationIndex": [ "accuracy" ], "localRunEnv": 1 }, "aggregateAlgorithm": { "type": "AVG", "superArgs": {} }, "taskId": null, "federatedTimes": null, "currentSubTaskId": null, "creator": "ai_train_s00453560", "createTime": "2019-11-29 09:09:42", "updateTime": "2019-11-29 09:09:42", "projectId": "050698b9de00d5e82f1dc0057ca15e62", "operationResult": null, "accuracy": null, "recallRate": null, "precision": null, "f1Score": null,

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 72

"csbUserId": null, "csbAppId": null, "isPublic": false, "clients": [], "owner": true, "id": "lfzad3kl" }, { "version": "0.0.1", "name": "test1129", "description": null, "type": "fault", "serverType": "cloud", "status": "DRAFT", "consoleStatus": "Draft", "baseAlgorithm": { "remote": { "projectId": "3c93079c85174014a969b94a04d35a4b", "projectName": "fl_z00511000", "modelId": null }, "local": null, "modelEvaluationIndex": [ "accuracy" ], "localRunEnv": 1 }, "aggregateAlgorithm": { "type": "AVG", "superArgs": {} }, "taskId": null, "federatedTimes": null, "currentSubTaskId": null, "creator": "ai_train_s00453560", "createTime": "2019-11-29 09:05:50", "updateTime": "2019-11-29 09:05:50", "projectId": "050698b9de00d5e82f1dc0057ca15e62", "operationResult": null, "accuracy": null, "recallRate": null, "precision": null, "f1Score": null, "csbUserId": null, "csbAppId": null, "isPublic": false, "clients": [], "owner": true, "id": "lfzad3kl" }]

Return ValueFor details, see the return values of common requests.

8.5.7 Querying the Running Progress of Federation Instances

FunctionQuery the running progress of federation instances.

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 73

URI● URI format:GET https://{{Federal-IP}}/federated/v1/instance/progress/{instanceId}?version={verison}

● Parameter description

Parameter Mandatory orNot

Type Description

instanceId Yes String Federation instanceID

version Y String Federation instanceversion

Request● The following is a request example:GET https://{{Federal-IP}}/federated/v1/instance/progress/0an1uie5?version=0.0.1

Response● The following is an example of a successful response:{ "instanceId": "0an1uie5", "stage": "TRAINING", "success": false, "progressItemsInfos": [ { "name": "AGGREGATING", "errorCode": "23469334.14010.10005", "errorMessage": "force stop instance by operator, because run instance failed, run local algorithm failed ,instanceId is 0an1uie5", "status": "AGGREGATING", "beginTime": "2019-09-20 16:14:33", "endTime": "2019-09-20 16:14:39", "timeout": 240000, "iterationNumber": 1 }, { "name": "AGGREGATE", "errorCode": "0", "errorMessage": "success", "status": "AGGREGATE", "beginTime": "2019-09-20 16:14:03", "endTime": "2019-09-20 16:14:33", "timeout": 300000, "iterationNumber": 1 }, { "name": "MODEL_UPDATE_TRAIN", "errorCode": "0", "errorMessage": "success", "status": "MODEL_UPDATE_TRAIN", "beginTime": "2019-09-20 16:12:55", "endTime": "2019-09-20 16:14:03",

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 74

"timeout": 36000000, "iterationNumber": 1 } ], "toDoList": [ "MODEL_UPDATE_TEST", "KPI_ASSESS" ]}

● Parameter description

Parameter Mandatory orNot

Type Description

instanceId No String Instance ID

stage No String StatusThe valuePUBLISHINGindicates beingpublished.The valueTRYINGindicates undertrial run.The valueTRAININGindicates undertraining.

success No Boolean Whether theoperation issuccessfulThe value can befalse or true.

progressItemsIn-fos

No List<ProgressItemsIn-fo>

Project progressinformation

toDoList No List<String> List of operationsto be performed

The following table describes progress item information.

Parameter Mandatory orNot

Type Description

name No String Progress name

errorCode No String Error code. Thevalue 0 indicatessuccess.

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 75

Parameter Mandatory orNot

Type Description

errorMessage No Boolean Error information

status No List<ProgressItemsInfo>

Statusinformation list

beginTime No List<String> Start time

endTime No String End time

iterationNumber No Integer Number ofiterations

timeout No Integer Timeout interval

Return Value

For details, see the return values of common requests.

8.5.8 Querying Monitoring Information About FederationInstances

Function

Query monitoring information about federation instances.

URI● URI format:GET https://{{Federal-IP}}/federated/v1/monitoring/{instanceId}?version={version}

● Parameter description

Parameter Mandatory orNot

Type Description

instanceId Yes String Federation instanceID

version Y String Federation instanceversion

Request● The following is a request example:GET https://{{Federal-IP}}/federated/v1/monitoring/a3qy1h0m?version=0.0.1

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 76

Response● The following is an example of a successful response (the instance object is

returned; for the definition, see the section of creating federation instances):

[ { "agentId": "agentId-hag2vb6r", "agentName": "SA_98", "monitorItems": [ "accuracy" ], "monitoringInfoList": [ { "trainTimes": 10, "accuracy": 0.62207, "recallRate": 0, "precision": 0, "f1Score": null, "modelChangeValue": null }, { "trainTimes": 20, "accuracy": 0.719727, "recallRate": 0, "precision": 0, "f1Score": null, "modelChangeValue": null }, *******}

Return Value

For details, see the return values of common requests.

8.6 Federated Client ServiceRegistering Federated Clients

Deregistering Federated Clients

Downloading Federated Models to Clients

Uploading Local Models from Clients

Uploading KPIs from Clients

Sending Heartbeat Information from Clients

8.6.1 Registering Federated Clients

Function

Register federated clients.

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 77

URI● URI format:POST https://{{Federal-IP}}/federated/v1/client

● Parameter description

Parameter Mandatory orNot

Type Description

instanceId Yes String Federation instance ID

version Yes String Federation instance version

name Yes String Client name

publicKey No String Multi-party public key, whichis required only in multi-partyscenarios

Request● The following is a request example:POST https://{{Federal-Address}}/federated/v1/client{ "instanceId": "xxxx", "version": "0.0.1", "name": "clientA"}

Response● The following is an example of a successful response:{ "agentId": "agentId-xxxxxx", "code": "0", "msg": "success", "ext": null}

● The following is an example of a failed response:{ "success": false, "code": "23469334.14010.10001", "msg": "you have not right to operator this instance!", "ext": null}

● Parameter description

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 78

Parameter Mandatory orNot

Type Description

code No String Status code. The value 0 indicatessuccess. A non-zero value indicatesfailure.

msg No String Returned message. If the operationfails, an error message is returned.

ext No Map Extended information

Return Value

For details, see the return values of common requests.

8.6.2 Deregistering Federated Clients

Function

Deregister federated clients.

URI● URI format:DELETE https://{{Federal-IP}}/federated/v1/client

● Parameter description

Parameter Mandatory orNot

Type Description

agentId Yes String Client ID

Request● The following is a request example:DELETE https://{{Federal-Address}}/federated/v1/client{ "agentId": "agentId-2fder3yu"}

Response● The following is an example of a successful response:{ "success": true, "code": "0", "msg": "success"}

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 79

● The following is an example of a failed response:{ "success": false, "code": "23469334.14010.10001", "msg": "you have not right to operator this instance!"}

● Parameter description

Parameter Mandatory orNot

Type Description

code No String Status code. Thevalue 0 indicatessuccess. A non-zero valueindicates failure.

msg No String Returnedmessage. If theoperation fails,an error messageis returned.

success No Boolean Whether theoperation issuccessful

Return Value

For details, see the return values of common requests.

8.6.3 Downloading Federated Models to Clients

Function

Download federated models to clients.

URI● URI format:POST https://{{Federal-IP}}/federated/v1/model/global

● Parameter description

Parameter Mandatory orNot

Type Description

agentId Yes String Client ID

taskId Yes String Task ID

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 80

Request● The following is a request example:POST https://{{Federal-IP}}/federated/v1/model/global{ "agentId": "xxxx", "taskId ": "zzzz" }

Response● The following is an example of a successful response:{ "success": true, "code": "0", "msg": "success"}

● The following is an example of a failed response:{ "success": false, "code": "23469334.14010.10001", "msg": "you have not right to operator this instance!"}

● Parameter description

Parameter Mandatory orNot

Type Description

code No String Status code. Thevalue 0 indicatessuccess. A non-zero valueindicates failure.

msg No String Returnedmessage. If theoperation fails,an error messageis returned.

success No Boolean Whether theoperation issuccessful

Return ValueFor details, see the return values of common requests.

8.6.4 Uploading Local Models from Clients

FunctionUpload local models from clients.

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 81

URI● URI format:POST https://{{Federal-IP}}/federated/v1/model/local

● Parameter description

Parameter Mandatory orNot

Type Description

agentId Yes String Client ID

taskId Yes String Task ID

Request● The following is a request example:POST https://{{Federal-IP}}/federated/v1/model/global{ "agentId": "xxxx", "taskId ": "zzzz" }

Response● The following is an example of a successful response:{ "success": true, "code": "0", "msg": "success"}

● The following is an example of a failed response:{ "success": false, "code": "23469334.14010.10001", "msg": "you have not right to operator this instance!"}

● Parameter description

Parameter Mandatory orNot

Type Description

code No String Status code. Thevalue 0 indicatessuccess. A non-zero valueindicates failure.

msg No String Returnedmessage. If theoperation fails,an error messageis returned.

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 82

Parameter Mandatory orNot

Type Description

success No Boolean Whether theoperation issuccessful

Return ValueFor details, see the return values of common requests.

8.6.5 Uploading KPIs from Clients

FunctionUpload KPIs from clients.

URI● URI format:POST https://{{Federal-IP}}/federated/v1/model/kpi

● Parameter description

Parameter Mandatory orNot

Type Description

agentId Yes String Client ID

taskId Yes String Task ID

kpiInfo Yes Map KPI information. The followingkeys are supported:spendTime: duration (unit:second)totalNumber: total datavolumeaccuracy: accuracyprecision: precisionrecallRate: recall rate

Request● The following is a request example:POST https://{{Federal-IP}}/federated/v1/model/kpi{ "agentId": "xxxx", "taskId": "zzzz", "kpiInfo": { "spendTime": "200",

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 83

"totalNumber": "10000" }}

Response● The following is an example of a successful response:{ "success": true, "code": "0", "msg": "success"}

● The following is an example of a failed response:{ "success": false, "code": "23469334.14010.10001", "msg": "you have not right to operator this instance!"}

● Parameter description

Parameter

Mandatory or Not

Type Description

code No String Status code. The value 0 indicatessuccess. A non-zero value indicatesfailure.

msg No String Returned message. If the operationfails, an error message is returned.

success No Boolean Whether the operation is successful

Return ValueFor details, see the return values of common requests.

8.6.6 Sending Heartbeat Information from Clients

FunctionSend heartbeat information from clients.

URI● URI format:POST https://{{Federal-IP}}/federated/v1/heartbeat

● Parameter description

Parameter

Mandatory orNot

Type Description

agentId Yes String Client ID

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 84

Parameter

Mandatory orNot

Type Description

taskId No String Task ID, which is generated by the server andsent back to the server.

clientStatus

Yes String Client status. The values are as follows:OFFLINE: offlineTO_BE_APPROVED: to be approvedINIT: initial stateABNORMAL: abnormalIDLE: idle, which indicates that the federationcan be enabledMODEL_DOWNLOADING: model beingdownloadedMODEL_DOWNLOADED: model downloadedMODEL_DOWNLOAD_FAILED: modeldownload failureMODEL_TRAINING: local trainingMODEL_TRAINED: local training completedMODEL_TRAIN_FAILED: training failureMODEL_UPLOADING: model being uploadedMODEL_UPLOADED: model uploadedMODEL_UPLOAD_FAILED: model uploadfailureMODEL_TESTING: model being testedMODEL_TESTED: model testedMODEL_TEST_FAILED : model test failureMODEL_KPI_UPLOADING: model KPI databeing uploadedMODEL_KPI_UPLOADED: model KPI datauploadedMODEL_KPI_UPLOAD_FAILED: model KPIupload failure

Request● The following is a request example:POST https://{{Federal-IP}}/federated/v1/heartbeat{ "agentId": "xxxx", "taskId ": "zzzz", "clientStatus": "MODEL_TRAINING"}

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 85

Response● The following is an example of a successful response:{ "success": true, "code": "0", "msg": "success", "serverStatus": "READY", "task": { "taskId": "xxx", "type": "STOP" }}

● The following is an example of a failed response:{ "success": false, "code": "23469334.14010.10001", "msg": "you have not right to operator this instance!"}

● Parameter description

Parameter Mandatory orNot

Type Description

code No String Status code. Thevalue 0 indicatessuccess. A non-zero valueindicates failure.

msg N String Returnedmessage. If theoperation fails,an error messageis returned.

success N Boolean Whether theoperation issuccessful

serverStatus No String Server status

task No Task Task

The following table describes task objects.

Parameter Mandatory orNot

Type Description

taskId No String Task ID, which is containedin the message reportedby the client

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 86

Parameter Mandatory orNot

Type Description

type No String Task typeSupported task types areas follows:NONE: no taskINIT: Perform initialization.MODEL_DOWNLOAD:Download the model.MODEL_TRAIN: Performmodel training.MODEL_UPLOAD: Uploadthe model.MODEL_TEST: Test themodel.KPI_UPLOAD: Upload KPIs.STOP: Stop training.

Return Value

For details, see the return values of common requests.

8.7 Common Error CodesCommon HTTP Request Status Codes

Federated Error Codes

8.7.1 Common HTTP Request Status Codes● Normal

Return Value Description

200 OK Successful request.

202 Accepted Request accepted.

● Abnormal

Return Value Description

400 Bad Request Request error.

401 Unauthorized Authentication failed.

403 Forbidden No operation rights.

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 87

Return Value Description

404 Not Found No resource found.

500 Internal Server Error Internal service error.

503 Service Unavailable Unavailable service.

8.7.2 Federated Error Codes

Error Code Type Description Recommended Solution

23469334.14010.10001

Invalidparameters

Theparameters inthe request donot meet thespecifiedrequirements.

Check whether theparameters meet therequirements in thedocument.

23469334.14010.10002

Invalidparameters

The user isinvalid.

The user is not in thewhitelist.

23469334.14010.10003

Invalidparameters

The user hasnot subscribedto the service.

The user has notsubscribed to the service.Subscribe to the federatedservice first.

23469334.14010.10004

Serviceexception

The client fails. Check the client. If thefault persists, contactHuawei technical support.

23469334.14010.10005

Serviceexception

Localaggregationfails.

Local aggregation fails.

23469334.14010.10006

Invalidparameters

The algorithmor modelpackage filedoes not meetthe formatrequirements.

The algorithm or modelpackage file does not meetthe format requirements.

23469334.14010.10080

Invalidparameters

Metadata isduplicated.

Check whether themetadata is suitable.

23469334.14010.10081

Invalidparameters

The servermetadata doesnot exist.

Check whether themetadata is suitable.

23469334.14010.10082

Invalidparameters

The clientmetadata doesnot exist.

Check whether themetadata is suitable.

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 88

Error Code Type Description Recommended Solution

23469334.14010.10083

Serviceexception

Metadata isnot aligned.

Align metadata on thefederated console.

23469334.14010.99999

Serviceexception

An unknownerror occurs.

Contact Huawei technicalsupport.

23469334.14010.99998

Serviceexception

An internalerror occurs.

Contact Huawei technicalsupport.

NAIEFederated Learning Service 8 API Reference (FL-Server)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 89

9 API Reference (FL-Client)

9.1 Before You StartThis document is intended for the federated learning client (FLC) developmentand test personnel of NAIE federated learning service and describes how to useFLC APIs of the NAIE federated learning service to interconnect service systemswith the federated learning service.

Table 9-1 About This Document

Phase Link

Understand the API components andinterface list.

● Overview

Prepare for using interfaces. ● Environment Preparation

Understand the representational statetransfer (REST) message body and usage.

● Methods of UsingInterfaces

Understand interface usage. ● APIs

Understand common parameters. ● Common Parameters

9.2 OverviewThe following table describes FLC APIs.

Type Interface Description

API Registration API Register the client for servermanagement.

Deregistration API Deregister the client to bring theclient offline on the server.

NAIEFederated Learning Service 9 API Reference (FL-Client)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 90

Type Interface Description

Heartbeat API Heartbeat API, which is invokedby the service system duringpolling. The service system isinformed of new tasks over thisAPI.

Task query API If the service system detects newtasks based on heartbeats, it usesthis API to obtain taskinformation.

Data reporting API The service system reports taskexecution results or other KPIinformation through this API.

9.3 Environment PreparationObtaining IAM User Information of the Public Cloud

Obtaining the ID and Version of a Federated Learning Instance

Preparing Algorithm Metadata Files

9.3.1 Obtaining IAM User Information of the Public CloudTo invoke the registration API, you need to enter the user ID, which is obtainedfrom the management console. The user ID must be the same as the userinformation configured in the configuration file. For details, see the FLCdeployment guide.

9.3.2 Obtaining the ID and Version of a Federated LearningInstance

To invoke the registration API, you need to enter the instance ID and versioninformation (optional, the latest version is used by default), which are obtainedfrom federated learning page, as indicated by the red box in the following figure.

Figure 9-1 Information location

9.3.3 Preparing Algorithm Metadata FilesTo invoke the registration API, you need to enter the path of the algorithmmetadata file in .json format. Prepare the file in advance.

NAIEFederated Learning Service 9 API Reference (FL-Client)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 91

9.4 Methods of Using InterfacesThe methods of using interfaces are as follows:

FLC APIs use HTTPS as the transmission protocol. Requests/Responses aretransmitted by using JSON messages, with media type represented byApplication/json.

An FLC API request/response consists of the following parts:

● Request URI● Request header● Request body● Response header● Response body

Request URI● URI format:

{URI-scheme} :// {Endpoint} / {resource-path} ? {query-string}Most languages or frameworks require that a request URL be sent in arequest message.

● URI parameters

Parameter Description

URI-scheme Protocol used to transmit requests.

Endpoint Domain name or IP address of the server of the APIservice endpoint

resource-path Resource path, that is, API access path, which is obtainedfrom the URI of a specified API, for example, v3/auth/tokens.

Query string Optional, which can be set to API version or resourceselection criterion

Request HeaderA request header contains the following parts:

● HTTP method (or operation), which informs the service of the operation type

Table 9-2 HTTP method

Method Description

GET Requests a server to return a specified resource.

PUT Requests a server to update a specified resource.

NAIEFederated Learning Service 9 API Reference (FL-Client)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 92

Method Description

POST Requests a server to add resources or perform a specialoperation.

DELETE Requests a server to delete specified resources, for example,an object.

HEAD Requests a server resource header.

PATCH Requests a server to update a part of a resource.If a target resource does not exist, PATCH may create aresource.

● Optional additional request header field, such as the field required by aspecified URI and HTTP method. The following table describes the fields in acommon request header.

Table 9-3 Common request header

Name Description Mandatoryor Not

Example

Content-Type

Message body type(format)

Yes application/json

Request BodyA request body is generally sent in a structured format (for example, JSON),corresponding to Content-type in the request header, and is used to transfercontent except the request header.

If a request body contains a parameter in Chinese, the parameter must be codedin UTF-8 mode.

Response HeaderA response header contains the following parts:

● Additional response header field, such as the field required by the responsesupporting a request (the field in the Content-type response header). Fordetails about the fields in a common response header, see the following table.

NAIEFederated Learning Service 9 API Reference (FL-Client)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 93

Table 9-4 Response headers

Name Description Example

Date Standard HTTPS header. The fieldindicates the time when a responseis sent. The time format followsRFC 822.

Mon, 12 Nov 200715:55:01 GMT

Server Standard HTTPS header, whichcontains information about thesoftware used by the server toprocess requests.

Apache

Content-Length

Standard HTTPS header, whichspecifies the length of the entitytext and is stored as bytes indecimal number.

xxx

Content-Type Standard HTTPS header, whichspecifies the media type of theentity text sent to the recipient.

application/json

Response BodyA response body is generally sent in a structured format (for example, JSON),corresponding to Content-type in the response header, and is used to transfercontent except the response header.

Request InitiationThere are three methods to initiate constructed requests:

● cURLcURL is a command line tool, which can be used to perform URL operationsand transfer information. cURL functions as an HTTP client to send HTTPrequests to the server and receive responses. cURL is applicable to APIdebugging. For details about cURL, see https://curl.haxx.se/.

● CodingYou can invoke APIs by coding to assemble, send, and process requests.

● RESTful client

Mozilla and Google provide graphical browser plug-ins for RESTful APIs to sendand process requests. For Firefox, see FirefoxREST Client. For Chrome, seeChrome RESTClient.

9.5 APIsRegistration

Deregistration

NAIEFederated Learning Service 9 API Reference (FL-Client)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 94

Heartbeat

Task Query

Data Reporting

9.5.1 Registration

FunctionRegister the client for server management.

URI● URI format:/federated/v1/agent/register

● Parameter description

Parameter Mandatory orNot

Type Description

instanceId Yes string Federation instance ID

userId Yes string User ID

name Yes string Name of the client tobe registered

metadataFilePath

Yes string Full path of themetadata file

instanceVersion No string Instance version. If thisparameter is leftempty, the latestversion is used bydefault.

Request● The following is a request example:post https://endpoint/federated/v1/agent/register { "instanceId": "xxxxxxx", "userId": "xxxxxxxxx","name": "testName","metadataFilePath": "/xxx/xxx/xxx/x.json"}

Response● The following is an example of a successful response: {

NAIEFederated Learning Service 9 API Reference (FL-Client)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 95

"success": true, "agentId": "agentId-xxx"}

● The following is an example of a failed response:{ "success": false, "msg": "Invalid param!" }

● Parameter description

Parameter Mandatory orNot

Type Description

success Yes boolean Whetherregistration issuccessful

msg No String Failure message

agentId N String Unique ID of theregisteredfederation

9.5.2 Deregistration

Function

Deregister the client to bring the client offline on the server.

URI● URI format:/federated/v1/agent/deregister

● Parameter description

Parameter Mandatory orNot

Type Description

agentId Y String Unique ID of theregisteredfederation

Request● The following is a request example:post https://endpoint/federated/v1/agent/deregister { "agentId": "agentId-xxx"

NAIEFederated Learning Service 9 API Reference (FL-Client)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 96

}

Response● The following is an example of a successful response:{ "success": true}

● The following is an example of a failed response:{ "success": false, "msg": "Invalid param!" }

● Parameter description

Parameter Mandatory orNot

Type Description

success Yes boolean Whetherderegistration issuccessful

msg No String Failure message

9.5.3 Heartbeat

FunctionThe heartbeat API is invoked by the service system during polling. The servicesystem is informed of new tasks over this API.

URI● URI format:/federated/v1/agent/heartbeat

● Parameter description

Parameter Mandatory orNot

Type Description

agentId Yes String Unique ID of theregistered federation

taskId No String Task ID

NAIEFederated Learning Service 9 API Reference (FL-Client)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 97

Parameter Mandatory orNot

Type Description

taskStatus No String Task status. The valuesare as follows:Accepted: receivedRunning: runningFinished: completedFailed: failed

Request● The following is a request example:post https://endpoint/federated/v1/agent/heartbeat { "agentId": "agentId-xxx"}

Response● The following is an example of a successful response: { "success": true, "newTask": true}

● The following is an example of a failed response: { "success": false, "newTask": false}

● Parameter description

Parameter

Mandatory orNot

Type Description

success

Yes boolean Whether the heartbeat is successful

newTask

Yes boolean Whether there are new tasks. The value trueindicates that there are new tasks. The servicesystem invokes the queryTask interface toquery and process the information about thenew tasks.

NAIEFederated Learning Service 9 API Reference (FL-Client)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 98

9.5.4 Task Query

FunctionIf the service system detects new tasks based on heartbeats, it uses this API toobtain task information.

URI● URI format:/federated/v1/agent/queryTask

● Parameter description

Parameter Mandatory orNot

Type Description

agentId Y String Unique ID of theregistered federation

Request● The following is a request example:post https://endpoint/federated/v1/agent/queryTask { "agentId": "agentId-xxx"}

Response● The following is an example of a successful response: { "success": true, "taskId": "training_taskId-xxx","taskType": "training","taskParams": "{"subModelIterateTimes":"20","subModelLearningRate":"0.05","xxx":"xxx"}"}

● The following is an example of a failed response: { "success": false }

● Parameter description

NAIEFederated Learning Service 9 API Reference (FL-Client)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 99

Parameter

MandatoryorNot

Type

Description

success

Yes boolean

Whether the query task is successful

taskId No String

Task ID

taskType

No String

Task typenone: no tasktraining: training taskevaluation: evaluation taskstop: The service system forcibly stops all currentfederated tasks and waits for the service to delivernew tasks.

taskParams

No String

Task parameter (in JSON format) The service needs toobtain the task parameters, for example, modeltraining hyperparameters provided during the deliveryof training tasks.

9.5.5 Data Reporting

FunctionVerify models.

URI● URI format:/federated/v1/agent/report

● Parameter description

Parameter

Mandatory orNot

Type Description

agentId Yes String Unique ID of the registered federation

taskId No String ID of the current federated task. If thisparameter is left blank, KPI data before thefederated task is reported, for example,accuracy.

NAIEFederated Learning Service 9 API Reference (FL-Client)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 100

Parameter

Mandatory orNot

Type Description

taskStatus

N String Task status. The values are as follows:Accepted: receivedRunning: runningFinished: completedFailed: failed

reportData

Yes String Uploaded KPI data in JSON format, such asthe data volume, training duration, andaccuracy

Request● The following is a request example:post https://endpoint/federated/v1/agent/report { "agentId": "agentId-xxx","taskId": "training_taskId-xxx","taskStatus": "Finished","reportData": "{"spendTime":"6000","dataNumber":"10000","xxx":"xxx"}",}

Response● The following is an example of a successful response:{ "success": true}

● The following is an example of a failed response:{ "success": false, "msg": "Invalid param!" }

● Parameter description

Parameter Mandatory orNot

Type Description

success Yes boolean Whether thedata issuccessfullyreported

msg No String Failure message

NAIEFederated Learning Service 9 API Reference (FL-Client)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 101

9.6 Common Parameters6.1 Error Codes

9.6.1 Error CodesError Code Type Description Recommended Solution

23469334.14020.10010

An exceptionoccurredduring APIregistration.

Metadata uploadfails, or the serverreturns a failuremessage.

Check the metadata fileand analyze the returnedexception information.

23469334.14020.10020

An exceptionoccurredwhen APIderegistration.

The server instancedoes not exist, orthe agent ID isincorrect.

Check whether the serverinstance and agent IDexist and analyze thereturned exceptioninformation.

23469334.14020.10030

An exceptionoccurredduringheartbeat APIprocessing.

The agent ID doesnot exist, or theserver service isunavailable.

Check whether the serverservice is normal andanalyze the returnedexception information.

23469334.14020.10040

An exceptionoccurredduring theprocessing ofthe taskquery API.

An exceptionoccurred duringinternal processing.

Analyze the returnedexception information.

23469334.14020.10050

An exceptionoccurredduring theprocessing ofthe KPIinformationreporting API.

An exceptionoccurred duringinternal processing.

Analyze the returnedexception information.

23469334.14020.10100

Failed todownload themodel to thelocal PC.

The OBS or SFTP filecannot be obtained,the local disk spaceis full, or the localscript fails to beexecuted.

Check the OBS or SFTPconnection configurations,analyze the returnedexception information,and check logs.

NAIEFederated Learning Service 9 API Reference (FL-Client)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 102

23469334.14020.10200

Failed toupload thelocal model.

A local model is notgenerated, the localscript fails to beexecuted, or the OBSor SFTP path isunreachable.

Check the OBS or SFTPconnection configurations,analyze the returnedexception information,and check logs.

23469334.14020.10300

An exceptionoccurredduring KPIinformationreporting.

Internal KPIinformationprocessing isabnormal, or theserver returns anerror message.

Analyze the returnedexception information.

23469334.14020.10400

An exceptionoccurredduring userinformationverification.

The agent ID isincorrect. Thetemporaryregistrationinformation cachedlocally is lost.

Check the inputparameters, check thetemporally cached files,and analyze logs.

23469334.14020.10500

An exceptionoccurredduringmetadataupload.

The metadata filepath is incorrect, orthe file format andsize do not meetrequirements.

Check the file path andcheck whether the file isin the .json format.Analyze and return theexception information.

23469334.14020.10001

The serverreturns amessageindicatingthat aheartbeatexceptionoccurred.

The server does notrespond, or anexception occursduring processing.

Analyze the returnedexception information.

23469334.14020.10002

The serverreturns amessageindicatingthat anexceptionoccurredduring modeldownload.

The server does notrespond, or anexception occursduring processing.

Analyze the returnedexception information.

NAIEFederated Learning Service 9 API Reference (FL-Client)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 103

23469334.14020.10003

The serverreturns amessageindicatingthat anexceptionoccurredduring modelupload.

The server does notrespond, or anexception occursduring processing.

Analyze the returnedexception information.

23469334.14020.10004

The serverreturns amessageindicatingthat anexceptionabout taskqueryparametersoccurred.

The server does notrespond, or anexception occursduring processing.

Analyze the returnedexception information.

23469334.14020.10005

The serverreturns amessageindicatingthat anexceptionoccurredduring dataupload.

The server does notrespond, or anexception occursduring processing.

Analyze the returnedexception information.

23469334.14020.10006

The serverreturns amessageindicatingthat anexceptionoccurredduringmetadataupload.

The server does notrespond, or anexception occursduring processing.

Analyze the returnedexception information.

23469334.14020.11000

Invalidparameters.

Invalid interfaceparameters.

Check the inputparameters by referring tothe interface document.

23469334.14020.19999

Unknownerror.

Unknown exception. View the logs and analyzethe problem.

NAIEFederated Learning Service 9 API Reference (FL-Client)

Issue 01 (2019-12-30) Copyright © Huawei Technologies Co., Ltd. 104