prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Error in aggregating models
  I'm using NVFlare 2.0.6 and torchvision ResNet-50 model for training. The FL system (consisting 4 clients) had completed the training for the first round but when aggregating into the global model I faced this error. Please help me resolve this problem, thank you. 
  ```
  2022-01-27 18:08:14,731 - InTimeAccumulateWeightedAggregator - INFO - [run=1, wf=scatter_gather_ctl]: aggregating 4 update(s) at round 0
  Traceback (most recent call last):
    File "/home/jupyter-test/.conda/envs/fl/lib/python3.8/site-packages/nvflare/app_common/workflows/scatter_and_gather.py", line 202, in control_flow
      self._global_weights = self.shareable_gen.shareable_to_learnable(aggr_result, fl_ctx)
    File "/home/jupyter-test/.conda/envs/fl/lib/python3.8/site-packages/nvflare/app_common/shareablegenerators/full_model_shareable_generator.py", line 60, in shareable_to_learnable
      weights[v_name] += v_value
  numpy.core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'add' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'
  2022-01-27 18:08:14,813 - ScatterAndGather - ERROR - [run=1, wf=scatter_gather_ctl]: Exception in ScatterAndGather control_flow: Cannot cast ufunc 'add' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'
  Traceback (most recent call last):
    File "/home/jupyter-test/.conda/envs/fl/lib/python3.8/site-packages/nvflare/app_common/workflows/scatter_and_gather.py", line 202, in control_flow
      self._global_weights = self.shareable_gen.shareable_to_learnable(aggr_result, fl_ctx)
    File "/home/jupyter-test/.conda/envs/fl/lib/python3.8/site-packages/nvflare/app_common/shareablegenerators/full_model_shareable_generator.py", line 60, in shareable_to_learnable
      weights[v_name] += v_value
  numpy.core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'add' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'
  2022-01-27 18:08:14,813 - ServerRunner - ERROR - [run=1, wf=scatter_gather_ctl]: Aborting current RUN due to FATAL_SYSTEM_ERROR received: Cannot cast ufunc 'add' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'
  2022-01-27 18:08:14,813 - ServerRunner - INFO - [run=1, wf=scatter_gather_ctl]: asked to abort - triggered abort_signal to stop the RUN
  2022-01-27 18:08:14,813 - ServerRunner - INFO - [run=1, wf=scatter_gather_ctl]: Workflow: scatter_gather_ctl finalizing ...
  ```
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `nvflare/app_common/shareablegenerators/full_model_shareable_generator.py`
  Content:
  ```
  1 # Copyright (c) 2021-2022, NVIDIA CORPORATION.  All rights reserved.
  2 #
  3 # Licensed under the Apache License, Version 2.0 (the "License");
  4 # you may not use this file except in compliance with the License.
  5 # You may obtain a copy of the License at
  6 #
  7 #     http://www.apache.org/licenses/LICENSE-2.0
  8 #
  9 # Unless required by applicable law or agreed to in writing, software
  10 # distributed under the License is distributed on an "AS IS" BASIS,
  11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 # See the License for the specific language governing permissions and
  13 # limitations under the License.
  14 
  15 from nvflare.apis.dxo import DataKind, from_shareable
  16 from nvflare.apis.fl_context import FLContext
  17 from nvflare.apis.shareable import Shareable
  18 from nvflare.app_common.abstract.model import ModelLearnable, ModelLearnableKey, model_learnable_to_dxo
  19 from nvflare.app_common.abstract.shareable_generator import ShareableGenerator
  20 from nvflare.app_common.app_constant import AppConstants
  21 
  22 
  23 class FullModelShareableGenerator(ShareableGenerator):
  24     def learnable_to_shareable(self, ml: ModelLearnable, fl_ctx: FLContext) -> Shareable:
  25         """Convert Learnable to Shareable
  26 
  27         Args:
  28             model (Learnable): model to be converted
  29             fl_ctx (FLContext): FL context
  30 
  31         Returns:
  32             Shareable: a shareable containing a DXO object,
  33         """
  34         dxo = model_learnable_to_dxo(ml)
  35         return dxo.to_shareable()
  36 
  37     def shareable_to_learnable(self, shareable: Shareable, fl_ctx: FLContext) -> ModelLearnable:
  38         """Convert Shareable to Learnable
  39 
  40         Supporting TYPE == TYPE_WEIGHT_DIFF or TYPE_WEIGHTS
  41 
  42         Args:
  43             shareable (Shareable): Shareable that contains a DXO object
  44             fl_ctx (FLContext): FL context
  45 
  46         Returns: a ModelLearnable object
  47         """
  48         base_model = fl_ctx.get_prop(AppConstants.GLOBAL_MODEL)
  49         if not base_model:
  50             self.system_panic(reason="No global base model!", fl_ctx=fl_ctx)
  51             return base_model
  52 
  53         weights = base_model[ModelLearnableKey.WEIGHTS]
  54         dxo = from_shareable(shareable)
  55 
  56         if dxo.data_kind == DataKind.WEIGHT_DIFF:
  57             if dxo.data is not None:
  58                 model_diff = dxo.data
  59                 for v_name, v_value in model_diff.items():
  60                     weights[v_name] += v_value
  61         elif dxo.data_kind == DataKind.WEIGHTS:
  62             weights = dxo.data
  63             if not weights:
  64                 self.log_info(fl_ctx, "No model weights found. Model will not be updated.")
  65             else:
  66                 base_model[ModelLearnableKey.WEIGHTS] = weights
  67 
  68         base_model[ModelLearnableKey.META] = dxo.get_meta_props()
  69         return base_model
  70
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/nvflare/app_common/shareablegenerators/full_model_shareable_generator.py b/nvflare/app_common/shareablegenerators/full_model_shareable_generator.py
  --- a/nvflare/app_common/shareablegenerators/full_model_shareable_generator.py
  +++ b/nvflare/app_common/shareablegenerators/full_model_shareable_generator.py
  @@ -57,7 +57,7 @@
               if dxo.data is not None:
                   model_diff = dxo.data
                   for v_name, v_value in model_diff.items():
  -                    weights[v_name] += v_value
  +                    weights[v_name] = weights[v_name] + v_value
           elif dxo.data_kind == DataKind.WEIGHTS:
               weights = dxo.data
               if not weights:
  
verification_info: {"golden_diff": "diff --git a/nvflare/app_common/shareablegenerators/full_model_shareable_generator.py b/nvflare/app_common/shareablegenerators/full_model_shareable_generator.py\n--- a/nvflare/app_common/shareablegenerators/full_model_shareable_generator.py\n+++ b/nvflare/app_common/shareablegenerators/full_model_shareable_generator.py\n@@ -57,7 +57,7 @@\n             if dxo.data is not None:\n                 model_diff = dxo.data\n                 for v_name, v_value in model_diff.items():\n-                    weights[v_name] += v_value\n+                    weights[v_name] = weights[v_name] + v_value\n         elif dxo.data_kind == DataKind.WEIGHTS:\n             weights = dxo.data\n             if not weights:\n", "issue": "Error in aggregating models\nI'm using NVFlare 2.0.6 and torchvision ResNet-50 model for training. The FL system (consisting 4 clients) had completed the training for the first round but when aggregating into the global model I faced this error. Please help me resolve this problem, thank you. \r\n```\r\n2022-01-27 18:08:14,731 - InTimeAccumulateWeightedAggregator - INFO - [run=1, wf=scatter_gather_ctl]: aggregating 4 update(s) at round 0\r\nTraceback (most recent call last):\r\n  File \"/home/jupyter-test/.conda/envs/fl/lib/python3.8/site-packages/nvflare/app_common/workflows/scatter_and_gather.py\", line 202, in control_flow\r\n    self._global_weights = self.shareable_gen.shareable_to_learnable(aggr_result, fl_ctx)\r\n  File \"/home/jupyter-test/.conda/envs/fl/lib/python3.8/site-packages/nvflare/app_common/shareablegenerators/full_model_shareable_generator.py\", line 60, in shareable_to_learnable\r\n    weights[v_name] += v_value\r\nnumpy.core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'add' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'\r\n2022-01-27 18:08:14,813 - ScatterAndGather - ERROR - [run=1, wf=scatter_gather_ctl]: Exception in ScatterAndGather control_flow: Cannot cast ufunc 'add' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'\r\nTraceback (most recent call last):\r\n  File \"/home/jupyter-test/.conda/envs/fl/lib/python3.8/site-packages/nvflare/app_common/workflows/scatter_and_gather.py\", line 202, in control_flow\r\n    self._global_weights = self.shareable_gen.shareable_to_learnable(aggr_result, fl_ctx)\r\n  File \"/home/jupyter-test/.conda/envs/fl/lib/python3.8/site-packages/nvflare/app_common/shareablegenerators/full_model_shareable_generator.py\", line 60, in shareable_to_learnable\r\n    weights[v_name] += v_value\r\nnumpy.core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'add' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'\r\n2022-01-27 18:08:14,813 - ServerRunner - ERROR - [run=1, wf=scatter_gather_ctl]: Aborting current RUN due to FATAL_SYSTEM_ERROR received: Cannot cast ufunc 'add' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'\r\n2022-01-27 18:08:14,813 - ServerRunner - INFO - [run=1, wf=scatter_gather_ctl]: asked to abort - triggered abort_signal to stop the RUN\r\n2022-01-27 18:08:14,813 - ServerRunner - INFO - [run=1, wf=scatter_gather_ctl]: Workflow: scatter_gather_ctl finalizing ...\r\n```\n", "before_files": [{"content": "# Copyright (c) 2021-2022, NVIDIA CORPORATION.  All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom nvflare.apis.dxo import DataKind, from_shareable\nfrom nvflare.apis.fl_context import FLContext\nfrom nvflare.apis.shareable import Shareable\nfrom nvflare.app_common.abstract.model import ModelLearnable, ModelLearnableKey, model_learnable_to_dxo\nfrom nvflare.app_common.abstract.shareable_generator import ShareableGenerator\nfrom nvflare.app_common.app_constant import AppConstants\n\n\nclass FullModelShareableGenerator(ShareableGenerator):\n    def learnable_to_shareable(self, ml: ModelLearnable, fl_ctx: FLContext) -> Shareable:\n        \"\"\"Convert Learnable to Shareable\n\n        Args:\n            model (Learnable): model to be converted\n            fl_ctx (FLContext): FL context\n\n        Returns:\n            Shareable: a shareable containing a DXO object,\n        \"\"\"\n        dxo = model_learnable_to_dxo(ml)\n        return dxo.to_shareable()\n\n    def shareable_to_learnable(self, shareable: Shareable, fl_ctx: FLContext) -> ModelLearnable:\n        \"\"\"Convert Shareable to Learnable\n\n        Supporting TYPE == TYPE_WEIGHT_DIFF or TYPE_WEIGHTS\n\n        Args:\n            shareable (Shareable): Shareable that contains a DXO object\n            fl_ctx (FLContext): FL context\n\n        Returns: a ModelLearnable object\n        \"\"\"\n        base_model = fl_ctx.get_prop(AppConstants.GLOBAL_MODEL)\n        if not base_model:\n            self.system_panic(reason=\"No global base model!\", fl_ctx=fl_ctx)\n            return base_model\n\n        weights = base_model[ModelLearnableKey.WEIGHTS]\n        dxo = from_shareable(shareable)\n\n        if dxo.data_kind == DataKind.WEIGHT_DIFF:\n            if dxo.data is not None:\n                model_diff = dxo.data\n                for v_name, v_value in model_diff.items():\n                    weights[v_name] += v_value\n        elif dxo.data_kind == DataKind.WEIGHTS:\n            weights = dxo.data\n            if not weights:\n                self.log_info(fl_ctx, \"No model weights found. Model will not be updated.\")\n            else:\n                base_model[ModelLearnableKey.WEIGHTS] = weights\n\n        base_model[ModelLearnableKey.META] = dxo.get_meta_props()\n        return base_model\n", "path": "nvflare/app_common/shareablegenerators/full_model_shareable_generator.py"}], "after_files": [{"content": "# Copyright (c) 2021-2022, NVIDIA CORPORATION.  All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom nvflare.apis.dxo import DataKind, from_shareable\nfrom nvflare.apis.fl_context import FLContext\nfrom nvflare.apis.shareable import Shareable\nfrom nvflare.app_common.abstract.model import ModelLearnable, ModelLearnableKey, model_learnable_to_dxo\nfrom nvflare.app_common.abstract.shareable_generator import ShareableGenerator\nfrom nvflare.app_common.app_constant import AppConstants\n\n\nclass FullModelShareableGenerator(ShareableGenerator):\n    def learnable_to_shareable(self, ml: ModelLearnable, fl_ctx: FLContext) -> Shareable:\n        \"\"\"Convert Learnable to Shareable\n\n        Args:\n            model (Learnable): model to be converted\n            fl_ctx (FLContext): FL context\n\n        Returns:\n            Shareable: a shareable containing a DXO object,\n        \"\"\"\n        dxo = model_learnable_to_dxo(ml)\n        return dxo.to_shareable()\n\n    def shareable_to_learnable(self, shareable: Shareable, fl_ctx: FLContext) -> ModelLearnable:\n        \"\"\"Convert Shareable to Learnable\n\n        Supporting TYPE == TYPE_WEIGHT_DIFF or TYPE_WEIGHTS\n\n        Args:\n            shareable (Shareable): Shareable that contains a DXO object\n            fl_ctx (FLContext): FL context\n\n        Returns: a ModelLearnable object\n        \"\"\"\n        base_model = fl_ctx.get_prop(AppConstants.GLOBAL_MODEL)\n        if not base_model:\n            self.system_panic(reason=\"No global base model!\", fl_ctx=fl_ctx)\n            return base_model\n\n        weights = base_model[ModelLearnableKey.WEIGHTS]\n        dxo = from_shareable(shareable)\n\n        if dxo.data_kind == DataKind.WEIGHT_DIFF:\n            if dxo.data is not None:\n                model_diff = dxo.data\n                for v_name, v_value in model_diff.items():\n                    weights[v_name] = weights[v_name] + v_value\n        elif dxo.data_kind == DataKind.WEIGHTS:\n            weights = dxo.data\n            if not weights:\n                self.log_info(fl_ctx, \"No model weights found. Model will not be updated.\")\n            else:\n                base_model[ModelLearnableKey.WEIGHTS] = weights\n\n        base_model[ModelLearnableKey.META] = dxo.get_meta_props()\n        return base_model\n", "path": "nvflare/app_common/shareablegenerators/full_model_shareable_generator.py"}]}