Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
XP-333 Replace numproto with xain-proto (#220)
Browse files Browse the repository at this point in the history
* XP-333 Replace numproto with xain-proto

* XP-333 Format setup.py

* XP-333 Update xain-proto

* XP-333 Update docs
  • Loading branch information
Robert-Steiner authored Jan 17, 2020
1 parent 19d6b51 commit ac8da29
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 22 deletions.
15 changes: 8 additions & 7 deletions docs/network_architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ models after they finished their training task.
In order to remain agnostic to the machine learning framework *Participants*
and *Coordinator* exchange models in the form of numpy arrays. How models are
converted from a particular machine learning framework model into numpy arrays
are outside the scope of this document. We do provide the `Numproto
<https://github.com/xainag/numproto>`_ python package that performs
are outside the scope of this document. We do provide the `xain-proto
<https://github.com/xainag/xain-proto>`_ python package that performs
serialization and deserialization of numpy arrays into and from protobuf.


Expand Down Expand Up @@ -350,24 +350,25 @@ where the request and response data are given as the following protobuf messages
message StartTrainingRoundRequest {}
message StartTrainingRoundResponse {
repeated numproto.protobuf.NDArray weights = 1;
repeated xain_proto.numproto.NDArray weights = 1;
int32 epochs = 2;
int32 epoch_base = 3;
}
message EndTrainingRoundRequest {
repeated numproto.protobuf.NDArray weights = 1;
repeated xain_proto.numproto.NDArray weights = 1;
int32 number_samples = 2;
map<string, numproto.protobuf.NDArray> metrics = 3;
map<string, xain_proto.numproto.NDArray> metrics = 3;
}
message EndTrainingRoundResponse {}
Note that while most of the Python data types to be exchanged can be
"protobuf-erized" (and back), :code:`ndarray` requires more work. Fortunately we
have the `numproto <https://github.com/xainag/numproto>`_ project to help with
this conversion.
have the
`xain_proto/numproto <https://github.com/xainag/xain-proto/tree/master/python/xain_proto/numproto>`_
project to help with this conversion.

Training Round Communication
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
install_requires = [
"numpy==1.15", # BSD
"grpcio==1.23", # Apache License 2.0
"numproto==0.3", # Apache License 2.0
"structlog==19.2.0", # Apache License 2.0
# TODO: change xain-proto requirement to "xain-proto==0.2.0" once it is released
"xain-proto @ git+https://github.com/xainag/xain-proto.git@c78e86584c205fb56b5c1f03f052e0b623dcd25d#egg=xain_proto-0.1.0&subdirectory=python", # Apache License 2.0
"xain-proto @ git+https://github.com/xainag/xain-proto.git@37fc05566da91d263c37d203c0ba70804960be9b#egg=xain_proto-0.1.0&subdirectory=python", # Apache License 2.0
"boto3==1.10.48", # Apache License 2.0
]

Expand Down
4 changes: 0 additions & 4 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
"""XAIN FL tests"""

import os

os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
2 changes: 1 addition & 1 deletion tests/test_coordinator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""XAIN FL tests for coordinator"""

from numproto import proto_to_ndarray
import numpy as np
import pytest
from xain_proto.fl.coordinator_pb2 import (
Expand All @@ -12,6 +11,7 @@
StartTrainingRoundRequest,
State,
)
from xain_proto.numproto import proto_to_ndarray

from xain_fl.coordinator.coordinator import Coordinator
from xain_fl.tools.exceptions import (
Expand Down
2 changes: 1 addition & 1 deletion tests/test_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from unittest import mock

import grpc
from numproto import ndarray_to_proto, proto_to_ndarray
import numpy as np
import pytest
from xain_proto.fl.coordinator_pb2 import (
Expand All @@ -22,6 +21,7 @@
from xain_proto.fl.coordinator_pb2_grpc import add_CoordinatorServicer_to_server
from xain_proto.fl.hellonumproto_pb2 import NumProtoRequest
from xain_proto.fl.hellonumproto_pb2_grpc import NumProtoServerStub
from xain_proto.numproto import ndarray_to_proto, proto_to_ndarray
from xain_sdk.participant_state_machine import (
StateRecord,
end_training_round,
Expand Down
4 changes: 0 additions & 4 deletions xain_fl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
"""XAIN FL init"""

import os

os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
2 changes: 1 addition & 1 deletion xain_fl/coordinator/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Dict, List, Optional, Tuple

from google.protobuf.internal.python_message import GeneratedProtocolMessageType
from numproto import ndarray_to_proto, proto_to_ndarray
from numpy import ndarray
from xain_proto.fl.coordinator_pb2 import (
EndTrainingRoundRequest,
Expand All @@ -17,6 +16,7 @@
StartTrainingRoundResponse,
State,
)
from xain_proto.numproto import ndarray_to_proto, proto_to_ndarray

from xain_fl.coordinator.participants import Participants
from xain_fl.coordinator.round import Round
Expand Down
2 changes: 1 addition & 1 deletion xain_fl/helloproto/numproto_client.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""XAIN FL numproto client"""

import grpc
from numproto import ndarray_to_proto, proto_to_ndarray
import numpy as np
from xain_proto.fl import hellonumproto_pb2, hellonumproto_pb2_grpc
from xain_proto.numproto import ndarray_to_proto, proto_to_ndarray

from xain_fl.logger import StructLogger, get_logger

Expand Down
2 changes: 1 addition & 1 deletion xain_fl/helloproto/numproto_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import time

import grpc
from numproto import ndarray_to_proto, proto_to_ndarray
from xain_proto.fl import hellonumproto_pb2, hellonumproto_pb2_grpc
from xain_proto.numproto import ndarray_to_proto, proto_to_ndarray

from xain_fl.coordinator import _ONE_DAY_IN_SECONDS
from xain_fl.logger import StructLogger, get_logger
Expand Down

0 comments on commit ac8da29

Please sign in to comment.