Skip to content

Commit

Permalink
Merge branch 'main' into add-llm-code-eval
Browse files Browse the repository at this point in the history
  • Loading branch information
jafermarq authored Sep 10, 2024
2 parents ba507dc + c71a73c commit a69656a
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 22 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/docker-build-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Build Docker Images Main Branch

on:
push:
branches:
- 'main'

jobs:
parameters:
if: github.repository == 'adap/flower'
name: Collect docker build parameters
runs-on: ubuntu-22.04
timeout-minutes: 10
outputs:
pip-version: ${{ steps.versions.outputs.pip-version }}
setuptools-version: ${{ steps.versions.outputs.setuptools-version }}
flwr-version-ref: ${{ steps.versions.outputs.flwr-version-ref }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- uses: ./.github/actions/bootstrap
id: bootstrap

- id: versions
run: |
echo "pip-version=${{ steps.bootstrap.outputs.pip-version }}" >> "$GITHUB_OUTPUT"
echo "setuptools-version=${{ steps.bootstrap.outputs.setuptools-version }}" >> "$GITHUB_OUTPUT"
echo "flwr-version-ref=git+${{ github.server_url }}/${{ github.repository }}.git@${{ github.sha }}" >> "$GITHUB_OUTPUT"
build-docker-base-images:
name: Build base images
if: github.repository == 'adap/flower'
uses: ./.github/workflows/_docker-build.yml
needs: parameters
with:
namespace-repository: flwr/base
file-dir: src/docker/base/ubuntu
build-args: |
PIP_VERSION=${{ needs.parameters.outputs.pip-version }}
SETUPTOOLS_VERSION=${{ needs.parameters.outputs.setuptools-version }}
FLWR_VERSION_REF=${{ needs.parameters.outputs.flwr-version-ref }}
tags: unstable
secrets:
dockerhub-user: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub-token: ${{ secrets.DOCKERHUB_TOKEN }}

build-docker-binary-images:
name: Build binary images
if: github.repository == 'adap/flower'
uses: ./.github/workflows/_docker-build.yml
needs: build-docker-base-images
strategy:
fail-fast: false
matrix:
images: [
{ repository: "flwr/superlink", file_dir: "src/docker/superlink" },
{ repository: "flwr/supernode", file_dir: "src/docker/supernode" },
{ repository: "flwr/serverapp", file_dir: "src/docker/serverapp" },
{ repository: "flwr/superexec", file_dir: "src/docker/superexec" },
{ repository: "flwr/clientapp", file_dir: "src/docker/clientapp" }
]
with:
namespace-repository: ${{ matrix.images.repository }}
file-dir: ${{ matrix.images.file_dir }}
build-args: BASE_IMAGE=unstable
tags: unstable
secrets:
dockerhub-user: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub-token: ${{ secrets.DOCKERHUB_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ class FlowerClient(NumPyClient):
self.batch_size = batch_size
self.verbose = verbose

def get_parameters(self, config):
return self.model.get_weights()

def fit(self, parameters, config):
self.model.set_weights(parameters)
self.model.fit(
Expand Down
2 changes: 1 addition & 1 deletion src/py/flwr/client/client_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def _registration_error(fn_name: str) -> ValueError:
>>> class FlowerClient(NumPyClient):
>>> # ...
>>>
>>> def client_fn(cid) -> Client:
>>> def client_fn(context: Context):
>>> return FlowerClient().to_client()
>>>
>>> app = ClientApp(
Expand Down
5 changes: 2 additions & 3 deletions src/py/flwr/client/grpc_rere_client/client_interceptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,12 @@ def intercept_unary_unary(
if self.shared_secret is None:
raise RuntimeError("Failure to compute hmac")

message_bytes = request.SerializeToString(deterministic=True)
metadata.append(
(
_AUTH_TOKEN_HEADER,
base64.urlsafe_b64encode(
compute_hmac(
self.shared_secret, request.SerializeToString(True)
)
compute_hmac(self.shared_secret, message_bytes)
),
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def unary_unary(
"""Handle unary call."""
with self._lock:
self._received_client_metadata = context.invocation_metadata()
self._received_message_bytes = request.SerializeToString(True)
self._received_message_bytes = request.SerializeToString(deterministic=True)

if isinstance(request, CreateNodeRequest):
context.send_initial_metadata(
Expand Down
2 changes: 1 addition & 1 deletion src/py/flwr/common/record/recordset.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class RecordSet:
Let's see an example.
>>> from flwr.common import RecordSet
>>> from flwr.common import ConfigsRecords, MetricsRecords, ParametersRecord
>>> from flwr.common import ConfigsRecord, MetricsRecord, ParametersRecord
>>>
>>> # Let's begin with an empty record
>>> my_recordset = RecordSet()
Expand Down
25 changes: 24 additions & 1 deletion src/py/flwr/common/record/typeddict.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,18 @@
"""Typed dict base class for *Records."""


from typing import Callable, Dict, Generic, Iterator, MutableMapping, TypeVar, cast
from typing import (
Callable,
Dict,
Generic,
ItemsView,
Iterator,
KeysView,
MutableMapping,
TypeVar,
ValuesView,
cast,
)

K = TypeVar("K") # Key type
V = TypeVar("V") # Value type
Expand Down Expand Up @@ -73,3 +84,15 @@ def __eq__(self, other: object) -> bool:
if isinstance(other, dict):
return data == other
return NotImplemented

def keys(self) -> KeysView[K]:
"""D.keys() -> a set-like object providing a view on D's keys."""
return cast(Dict[K, V], self.__dict__["_data"]).keys()

def values(self) -> ValuesView[V]:
"""D.values() -> an object providing a view on D's values."""
return cast(Dict[K, V], self.__dict__["_data"]).values()

def items(self) -> ItemsView[K, V]:
"""D.items() -> a set-like object providing a view on D's items."""
return cast(Dict[K, V], self.__dict__["_data"]).items()
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def _verify_hmac(
self, public_key: ec.EllipticCurvePublicKey, request: Request, hmac_value: bytes
) -> bool:
shared_secret = generate_shared_key(self.server_private_key, public_key)
return verify_hmac(shared_secret, request.SerializeToString(True), hmac_value)
message_bytes = request.SerializeToString(deterministic=True)
return verify_hmac(shared_secret, message_bytes, hmac_value)

def _create_authenticated_node(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_successful_delete_node_with_metadata(self) -> None:
self._node_private_key, self._server_public_key
)
hmac_value = base64.urlsafe_b64encode(
compute_hmac(shared_secret, request.SerializeToString(True))
compute_hmac(shared_secret, request.SerializeToString(deterministic=True))
)
public_key_bytes = base64.urlsafe_b64encode(
public_key_to_bytes(self._node_public_key)
Expand Down Expand Up @@ -195,7 +195,7 @@ def test_unsuccessful_delete_node_with_metadata(self) -> None:
node_private_key, _ = generate_key_pairs()
shared_secret = generate_shared_key(node_private_key, self._server_public_key)
hmac_value = base64.urlsafe_b64encode(
compute_hmac(shared_secret, request.SerializeToString(True))
compute_hmac(shared_secret, request.SerializeToString(deterministic=True))
)
public_key_bytes = base64.urlsafe_b64encode(
public_key_to_bytes(self._node_public_key)
Expand All @@ -222,7 +222,7 @@ def test_successful_pull_task_ins_with_metadata(self) -> None:
self._node_private_key, self._server_public_key
)
hmac_value = base64.urlsafe_b64encode(
compute_hmac(shared_secret, request.SerializeToString(True))
compute_hmac(shared_secret, request.SerializeToString(deterministic=True))
)
public_key_bytes = base64.urlsafe_b64encode(
public_key_to_bytes(self._node_public_key)
Expand Down Expand Up @@ -251,7 +251,7 @@ def test_unsuccessful_pull_task_ins_with_metadata(self) -> None:
node_private_key, _ = generate_key_pairs()
shared_secret = generate_shared_key(node_private_key, self._server_public_key)
hmac_value = base64.urlsafe_b64encode(
compute_hmac(shared_secret, request.SerializeToString(True))
compute_hmac(shared_secret, request.SerializeToString(deterministic=True))
)
public_key_bytes = base64.urlsafe_b64encode(
public_key_to_bytes(self._node_public_key)
Expand Down Expand Up @@ -280,7 +280,7 @@ def test_successful_push_task_res_with_metadata(self) -> None:
self._node_private_key, self._server_public_key
)
hmac_value = base64.urlsafe_b64encode(
compute_hmac(shared_secret, request.SerializeToString(True))
compute_hmac(shared_secret, request.SerializeToString(deterministic=True))
)
public_key_bytes = base64.urlsafe_b64encode(
public_key_to_bytes(self._node_public_key)
Expand Down Expand Up @@ -311,7 +311,7 @@ def test_unsuccessful_push_task_res_with_metadata(self) -> None:
node_private_key, _ = generate_key_pairs()
shared_secret = generate_shared_key(node_private_key, self._server_public_key)
hmac_value = base64.urlsafe_b64encode(
compute_hmac(shared_secret, request.SerializeToString(True))
compute_hmac(shared_secret, request.SerializeToString(deterministic=True))
)
public_key_bytes = base64.urlsafe_b64encode(
public_key_to_bytes(self._node_public_key)
Expand Down Expand Up @@ -339,7 +339,7 @@ def test_successful_get_run_with_metadata(self) -> None:
self._node_private_key, self._server_public_key
)
hmac_value = base64.urlsafe_b64encode(
compute_hmac(shared_secret, request.SerializeToString(True))
compute_hmac(shared_secret, request.SerializeToString(deterministic=True))
)
public_key_bytes = base64.urlsafe_b64encode(
public_key_to_bytes(self._node_public_key)
Expand Down Expand Up @@ -369,7 +369,7 @@ def test_unsuccessful_get_run_with_metadata(self) -> None:
node_private_key, _ = generate_key_pairs()
shared_secret = generate_shared_key(node_private_key, self._server_public_key)
hmac_value = base64.urlsafe_b64encode(
compute_hmac(shared_secret, request.SerializeToString(True))
compute_hmac(shared_secret, request.SerializeToString(deterministic=True))
)
public_key_bytes = base64.urlsafe_b64encode(
public_key_to_bytes(self._node_public_key)
Expand All @@ -396,7 +396,7 @@ def test_successful_ping_with_metadata(self) -> None:
self._node_private_key, self._server_public_key
)
hmac_value = base64.urlsafe_b64encode(
compute_hmac(shared_secret, request.SerializeToString(True))
compute_hmac(shared_secret, request.SerializeToString(deterministic=True))
)
public_key_bytes = base64.urlsafe_b64encode(
public_key_to_bytes(self._node_public_key)
Expand Down Expand Up @@ -425,7 +425,7 @@ def test_unsuccessful_ping_with_metadata(self) -> None:
node_private_key, _ = generate_key_pairs()
shared_secret = generate_shared_key(node_private_key, self._server_public_key)
hmac_value = base64.urlsafe_b64encode(
compute_hmac(shared_secret, request.SerializeToString(True))
compute_hmac(shared_secret, request.SerializeToString(deterministic=True))
)
public_key_bytes = base64.urlsafe_b64encode(
public_key_to_bytes(self._node_public_key)
Expand Down Expand Up @@ -469,7 +469,7 @@ def test_successful_restore_node(self) -> None:
self._node_private_key, self._server_public_key
)
hmac_value = base64.urlsafe_b64encode(
compute_hmac(shared_secret, request.SerializeToString(True))
compute_hmac(shared_secret, request.SerializeToString(deterministic=True))
)
public_key_bytes = base64.urlsafe_b64encode(
public_key_to_bytes(self._node_public_key)
Expand Down

0 comments on commit a69656a

Please sign in to comment.