0 / 0
Connecting to the aggregator (Party)

Connecting to the aggregator (Party)

Each party follows these steps to connect to a started aggregator.

  1. Open the project and click the Federated Learning experiment.

  2. Click View setup information and click the download icon to download the party connector script. Screen capture of View Setup Information

  3. Each party must configure the party connector script and provide valid credentials to run the script. This is what a sample completed party connector script looks like:

    from ibm_watson_machine_learning import APIClient
    
    wml_credentials = {
    "url": "https://us-south.ml.cloud.ibm.com",
    "apikey": "<API KEY>"
    }
    
    wml_client = APIClient(wml_credentials)
    
    wml_client.set.default_project("XXX-XXX-XXX-XXX-XXX")
    
    party_metadata = {
    
            wml_client.remote_training_systems.ConfigurationMetaNames.DATA_HANDLER: {
    
            "name": "MnistSklearnDataHandler",
    
            "path": "example.mnist_sklearn_data_handler",
    
            "info": {
    
            "npz_file":"./example_data/example_data.npz"
    
    }
    
    party = wml_client.remote_training_systems.create_party("XXX-XXX-XXX-XXX-XXX", party_metadata)
    
    party.monitor_logs()
    party.run(aggregator_id="XXX-XXX-XXX-XXX-XXX", asynchronous=False)
    

    Parameters:

    • api_key:
      Your IAM API key. To create a new API key, go to the IBM Cloud website, and click Create an IBM Cloud Pak for Data API key under Manage > Access(IAM) > API keys.

    Optional: If you're reusing a script from a different project, you can copy the updated project_id, aggregator_id and experiment_id from the setup information window and copy them into the script.

  4. Install Watson Machine Learning with the latest Federated Learning package if you have not yet done so:

    • If you are using M-series on a Mac, install the latest package with the following script:
    #  -----------------------------------------------------------------------------------------
    #  (C) Copyright IBM Corp. 2023.
    #  https://opensource.org/licenses/BSD-3-Clause
    #  -----------------------------------------------------------------------------------------
    #
    #
    # Script to create a conda environment and install ibm-watson-machine-learning with
    # the dependencies required for Federated Learning on MacOS.
    # The name of the conda environment to be created is passed as the first argument.
    #
    # Note: This script requires miniforge to be installed for conda.
    #
    
    usage=". install_fl_rt22.2_macos.sh conda_env_name"
    
    arch=$(uname -m)
    os=$(uname -s)
    
    if (($# < 1))
    then
    echo $usage
    exit
    fi
    
    ENAME=$1
    
    conda create -y -n ${ENAME} python=3.10
    conda activate ${ENAME}
    pip install ibm-watson-machine-learning
    
    if [ "$os" == "Darwin" -a "$arch" == "arm64" ]
    then
    conda install -y -c apple tensorflow-deps
    fi
    
    python - <<EOF
    import pkg_resources
    import platform
    import subprocess
    
    package = 'ibm-watson-machine-learning'
    extra   = 'fl-rt22.2-py3.10'
    extra_  = extra.replace('.','-')
    extra_s = '; extra == "{}"'
    remove  = None
    add     = []
    
    if platform.system() == "Darwin" and platform.processor() == "arm":
        remove  = 'tensorflow'
        add     = ['tensorflow-macos==2.9.2']
    
    pkgs = pkg_resources.working_set.by_key[package].requires(extras=[extra])
    pkgs = [ p.__str__().removesuffix(extra_s.format(extra)).removesuffix(extra_s.format(extra_)) for p in pkgs if ( extra in p.__str__() or extra_ in p.__str__() ) and ( not remove or remove not in p.__str__() )]
    
    print( "Installing standard packages for {}[{}]:{}".format(package,extra,pkgs) )
    print( "Installing additional packages:{}".format(add) )
    
    cmd = [ 'pip', 'install'] + add + pkgs
    
    subprocess.run( cmd )
    EOF
    
    • Otherwise install with the following command:
      pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ 'ibm-watson-machine-learning[fl-rt22.2-py3.10]'
  5. When your configuration is complete and you save the party connector script, enter this command in a command line to run the script:

    python3 rts_<RTS Name>_<RTS ID>.py
    

More resources

Federated Learning library functions

Parent topic: Creating a Federated Learning experiment

Generative AI search and answer
These answers are generated by a large language model in watsonx.ai based on content from the product documentation. Learn more