Package: modalic
Python SDKPython SDK library for using theModalic Federated Learning Operations Platform.The SDK library serves as convenient interface for performing Federated Learning with the most common Machine Learning frameworks likePytorchorTensorflowwritten in the Python programming language.
As an additional software layer within a Machine Learning pipeline, the SKD enables an individual client application to take part within a Federated Learning setup.
The coordination of a distributed Machine Learning process solving a particular problem, is done by a central server or service provider which can be started via Python script using the SDK.As the main entrypoint to a production ready FLOps Platform, this software package aims for all developers and ML practitioners that want to run ML use cases in distributed fashion.UsageIn order to run a Federated Learning procedure two main entities have to instantiated. The client logic and the aggregation server application.
Both can be started via the SDK. Currently Pytorch & Tensorflow are supported as framework to construct the ML architecture.Run the Aggregation Server# (1) Run the aggregation server with configuration using .tomlcfg=toml.load("${configPATH}.toml")modalic.run_server(cfg)The.tomlfile can be used to control hyperparameters for the aggregation server.# -c configs/config.toml# REST API settings.[api]# The address to which the REST API of the server# will be bound. All requests should be sent to this address.server_address="127.0.0.1:8080"# Hyperparameter controlling the Federated Learning training process.[protocol]# Defines the number of training rounds (global epochs)# that will be performed.training_rounds=10# Sets the number of participants & local models# one global epoch should at least contain.participants=2For implementing the client logic a framework of choice can be used.Pytorch# (2) Construct the client logic.importmodalic# Define a FLClient object that implements all the ML logic and will# used as an input to an internal modalic client which enables the# program to connect to the server an perform training in distributed fashion.classFLClient(modalic.Client):def__init__(self,dataset,...):self.model=Net()self.dataset=torch.utils.data.DataLoader(dataset,batch_size=32)...deftrain(self):forepochinrange(0,self.epochs):forimages,labelsinself.trainloader:...returnself.modeldefserialize_local_model(self,model):returnmodalic.serialize_torch_model(model)defdeserialize_global_model(self,global_model):self.model=modalic.deserialize_torch_model(self.model,global_model,self._get_model_shape())defget_model_shape(self):returnmodalic.get_torch_model_shape(self.model)defget_model_dtype(self):...# Construct the client layer..client=FLClient(...)# (3) Run training for single client.modalic.run_client(client)Tensorflow# (2) Construct the client logic.classFLClient(modalic.Client):def__init__(self,dataset,...):# Initialize & compile the MobileNetV2 model.self.model=tf.keras.applications.MobileNetV2((32,32,3),classes=10,weights=None)# Load the CIFAR-10 dataset using tf.keras.(self.x_train,self.y_train),(_,_)=tf.keras.datasets.cifar10.load_data()...deftrain(self):...self.model.fit(self.x_train,self.y_train,batch_size=self.batch_size,epochs=self.epochs)...returnself.modeldefserialize_local_model(self,model):returnmodalic.serialize_tf_keras_model(model)defdeserialize_global_model(self,global_model):self.model=modalic.deserialize_tf_keras_model(self.model,global_model,self._get_model_shape())defget_model_shape(self):returnmodalic.get_tf_keras_model_shape(self.model)defget_model_dtype(self):...# Construct the client layer..client=FLClient(...)# (3) Run training for single client.modalic.run_client(client)Please keep in mind that this code snippet shows only the logic and the general idea. For more details, check out the/examplesfolder that contains more in-depth and complete instruction sets and examples that are actually actionable.InstallationThe latest release of Modalic Python SDK can be installed via pip:pipinstallmodalicDocumentationSee thePython SDK docsfor more information. Additionally, some examples for starting with Modalic are provided in this repository under the examples folder. Any Questions? Reach out to us onmodalic.ai.DevelopmentFind more information on contributing to the open source stack and the development process in generalhere.LicenseThe Modalic Python SDK is distributed under the terms of the Apache License Version 2.0. A complete version of the license is available inLICENSE.