0 / 0
Go back to the English version of the documentation
连接到聚集器 (参与方)
Last updated: 2024年11月28日
连接到聚集器 (参与方)

每个参与方都遵循以下步骤来连接到已启动的聚集器。

  1. 打开项目,然后单击 Federated Learning 试验。

  2. 单击 查看设置信息 ,然后单击下载图标以下载参与方连接器脚本。 "视图设置信息" 的屏幕截图

  3. 每个参与方都必须配置参与方连接器脚本并提供有效凭证以运行该脚本。 以下是样本已完成的参与方连接器脚本的外观:

    from ibm_watsonx_ai 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)
    

    参数:

    • api_key:
      IAM API 密钥。 要创建新的 API 密钥,请访问IBM Cloud网站,然后单击 "管理">"访问(IAM)">"API 密钥 "下的 "创建IBM Cloud Pak for DataAPI 密钥"

    可选: 如果要复用其他项目中的脚本,那么可以从设置信息窗口复制更新后的 project_idaggregator_idexperiment_id ,并将它们复制到脚本中。

  4. 如果尚未安装watsonx.aiRuntime,请使用最新的 Federated Learning 软件包安装:

    • 如果要在 Mac 上使用 M-series ,请使用以下脚本安装最新软件包:
    #  -----------------------------------------------------------------------------------------
    #  (C) Copyright IBM Corp. 2023.
    #  https://opensource.org/licenses/BSD-3-Clause
    #  -----------------------------------------------------------------------------------------
    #
    #
    # Script to create a conda environment and install ibm_watsonx_ai 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_rt23.1_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_watsonx_ai
    
    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_watsonx_ai'
    extra   = 'fl-rt23.1-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
    
    • 否则,请使用以下命令进行安装:
      pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ 'ibm_watsonx_ai[fl-rt23.1-py3.10]'
  5. 完成配置并保存参与方连接器脚本后,请在命令行中输入以下命令以运行该脚本:

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

<

联合学习图书馆功能

父主题: 创建 Federated Learning 试验

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