Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(framework) Upgrade Flower NumPy version to 2.0 #4440

Merged
merged 26 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1f40642
Init
chongshenng Nov 6, 2024
7bbca13
Change np.float_ to np.float64
chongshenng Nov 6, 2024
9c60283
Update can_cast type
chongshenng Nov 6, 2024
6021a0f
Add flwr_datasets as known_first_party
chongshenng Nov 6, 2024
96572a6
Revert import sort
chongshenng Nov 6, 2024
d1faff9
Revert import sort
chongshenng Nov 6, 2024
0b2a3cf
Upgrade numpy to >=2.0.0 for examples and e2e
chongshenng Nov 6, 2024
24813a6
Fix deps
chongshenng Nov 6, 2024
a38443c
Use flwr_datasets for e2e scikit_learn
chongshenng Nov 6, 2024
4879170
Fix deps in e2e-scikit-learn
chongshenng Nov 6, 2024
e809904
Add flwr-datasets
chongshenng Nov 6, 2024
e288878
Merge branch 'main' into feat/upgrade-numpy
chongshenng Nov 6, 2024
08138cf
Restore openml
chongshenng Nov 6, 2024
1b97342
Use NDArrayFloat
chongshenng Nov 6, 2024
b4bcc6d
Add openml
chongshenng Nov 6, 2024
4eccee3
Remove flwr typing from flwr datasets
chongshenng Nov 6, 2024
f673674
Merge branch 'main' into feat/upgrade-numpy
chongshenng Nov 6, 2024
5d52b65
Temporary remove
chongshenng Nov 6, 2024
efba194
Rollback e2e-jax
chongshenng Nov 6, 2024
60571ca
Reinstate e2e-scikit-learn
chongshenng Nov 7, 2024
94972d3
Merge branch 'main' into feat/upgrade-numpy
chongshenng Nov 7, 2024
b385133
Add NumPy 1.26 CI test
chongshenng Nov 7, 2024
ff86b2b
Bump lower range of NumPy
chongshenng Nov 7, 2024
667549a
Bump tensorboard version with compatibility updates for NumPy 2.0
chongshenng Nov 7, 2024
ddca56e
Fix torch and torchvision range for flwr-datasets e2e test
chongshenng Nov 7, 2024
7cb208c
Merge branch 'main' into feat/upgrade-numpy
danieljanes Nov 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,59 @@ jobs:
cd tmp-${{ matrix.framework }}
flwr build
flwr install *.fab

numpy:
runs-on: ubuntu-22.04
timeout-minutes: 10
needs: wheel
strategy:
fail-fast: false
matrix:
numpy-version: ["1.26"]
python-version: ["3.11"]
directory: [e2e-bare-auth]
connection: [insecure]
engine: [deployment-engine, simulation-engine]
authentication: [no-auth]
name: |
NumPy ${{ matrix.numpy-version }} /
Python ${{ matrix.python-version }} /
${{ matrix.connection }} /
${{ matrix.authentication }} /
${{ matrix.engine }}
defaults:
run:
working-directory: e2e/${{ matrix.directory }}
steps:
- uses: actions/checkout@v4
- name: Bootstrap
uses: ./.github/actions/bootstrap
with:
python-version: ${{ matrix.python-version }}
poetry-skip: 'true'
- name: Install Flower from repo
if: ${{ github.repository != 'adap/flower' || github.event.pull_request.head.repo.fork || github.actor == 'dependabot[bot]' }}
working-directory: ./
run: |
if [[ "${{ matrix.engine }}" == "simulation-engine" ]]; then
python -m pip install ".[simulation]" "numpy>=${{ matrix.numpy-version }},<2.0"
else
python -m pip install . "numpy>=${{ matrix.numpy-version }},<2.0"
fi
- name: Download and install Flower wheel from artifact store
if: ${{ github.repository == 'adap/flower' && !github.event.pull_request.head.repo.fork && github.actor != 'dependabot[bot]' }}
run: |
# Define base URL for wheel file
WHEEL_URL="https://${{ env.ARTIFACT_BUCKET }}/py/${{ needs.wheel.outputs.dir }}/${{ needs.wheel.outputs.short_sha }}/${{ needs.wheel.outputs.whl_path }}"
if [[ "${{ matrix.engine }}" == "simulation-engine" ]]; then
python -m pip install "flwr[simulation] @ ${WHEEL_URL}" "numpy>=${{ matrix.numpy-version }},<2.0"
else
python -m pip install "${WHEEL_URL}" "numpy>=${{ matrix.numpy-version }},<2.0"
fi
- name: >
Run Flower - NumPy 1.26 test /
${{ matrix.connection }} /
${{ matrix.authentication }} /
${{ matrix.engine }}
working-directory: e2e/${{ matrix.directory }}
run: ./../test_exec_api.sh "${{ matrix.connection }}" "${{ matrix.authentication}}" "${{ matrix.engine }}"
2 changes: 1 addition & 1 deletion datasets/flwr_datasets/common/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@

NDArray = npt.NDArray[Any]
NDArrayInt = npt.NDArray[np.int_]
NDArrayFloat = npt.NDArray[np.float_]
NDArrayFloat = npt.NDArray[np.float64]
NDArrays = list[NDArray]
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

def _dummy_setup(
num_partitions: int,
alpha: Union[float, NDArray[np.float_]],
alpha: Union[float, NDArray[np.float64]],
num_rows: int,
partition_by: str,
self_balancing: bool = True,
Expand Down
2 changes: 1 addition & 1 deletion datasets/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ exclude = [

[tool.poetry.dependencies]
python = "^3.9"
numpy = "^1.21.0"
numpy = ">=1.26.0,<3.0.0"
datasets = ">=2.14.6 <=3.1.0"
pillow = { version = ">=6.2.1", optional = true }
soundfile = { version = ">=0.12.1", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2e-pandas/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ authors = [{ name = "Ragy Haddad", email = "ragy202@gmail.com" }]
maintainers = [{ name = "The Flower Authors", email = "hello@flower.ai" }]
dependencies = [
"flwr[simulation] @ {root:parent:parent:uri}",
"numpy>=1.21.0,<2.0.0",
"numpy>=2.0.0",
"pandas>=2.0.0,<3.0.0",
"scikit-learn>=1.1.1,<2.0.0",
]
Expand Down
4 changes: 2 additions & 2 deletions e2e/e2e-pytorch-lightning/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ description = "Federated Learning E2E test with Flower and PyTorch Lightning"
license = "Apache-2.0"
dependencies = [
"flwr[simulation] @ {root:parent:parent:uri}",
"pytorch-lightning==2.2.4",
"torchvision==0.14.1",
"pytorch-lightning==2.4.0",
"torchvision>=0.20.1,<0.21.0",
]

[tool.hatch.build.targets.wheel]
Expand Down
4 changes: 2 additions & 2 deletions e2e/e2e-pytorch/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ description = "PyTorch Federated Learning E2E test with Flower"
license = "Apache-2.0"
dependencies = [
"flwr[simulation] @ {root:parent:parent:uri}",
"torch>=1.12.0,<2.0.0",
"torchvision>=0.14.1,<0.15.0",
"torch>=2.5.0,<3.0.0",
"torchvision>=0.20.1,<0.21.0",
"tqdm>=4.63.0,<5.0.0",
]

Expand Down
1 change: 1 addition & 0 deletions e2e/e2e-scikit-learn/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies = [
"flwr[simulation,rest] @ {root:parent:parent:uri}",
"scikit-learn>=1.1.1,<2.0.0",
"openml>=0.14.0,<0.15.0",
"numpy<2.0.0",
]

[tool.hatch.build.targets.wheel]
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-mods/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ authors = ["The Flower Authors <hello@flower.ai>"]
[tool.poetry.dependencies]
python = ">=3.9,<3.11"
flwr = { path = "../../", develop = true, extras = ["simulation"] }
tensorboard = "2.16.2"
tensorboard = "2.18.0"
torch = "1.13.1"
torchvision = "0.14.1"
tqdm = "4.65.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/sklearn-logreg-mnist/pyproject.toml
jafermarq marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ authors = [
dependencies = [
"flwr[simulation]>=1.12.0",
"flwr-datasets[vision]>=0.3.0",
"numpy<2.0.0",
"numpy>=2.0.0",
"scikit-learn~=1.2.2",
]

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ flower-client-app = "flwr.client.supernode:run_client_app" # Deprecated
[tool.poetry.dependencies]
python = "^3.9"
# Mandatory dependencies
numpy = "^1.21.0"
numpy = ">=1.26.0,<3.0.0"
grpcio = "^1.60.0,!=1.64.2,!=1.65.1,!=1.65.2,!=1.65.4,!=1.65.5,!=1.66.0,!=1.66.1"
protobuf = "^4.25.2"
cryptography = "^42.0.4"
Expand Down
2 changes: 1 addition & 1 deletion src/py/flwr/common/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

NDArray = npt.NDArray[Any]
NDArrayInt = npt.NDArray[np.int_]
NDArrayFloat = npt.NDArray[np.float_]
NDArrayFloat = npt.NDArray[np.float64]
NDArrays = list[NDArray]

# The following union type contains Python types corresponding to ProtoBuf types that
Expand Down
8 changes: 4 additions & 4 deletions src/py/flwr/server/strategy/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ def aggregate_inplace(results: list[tuple[ClientProxy, FitRes]]) -> NDArrays:
num_examples_total = sum(fit_res.num_examples for (_, fit_res) in results)

# Compute scaling factors for each result
scaling_factors = [
fit_res.num_examples / num_examples_total for _, fit_res in results
]
scaling_factors = np.asarray(
[fit_res.num_examples / num_examples_total for _, fit_res in results]
)

def _try_inplace(
x: NDArray, y: Union[NDArray, float], np_binary_op: np.ufunc
x: NDArray, y: Union[NDArray, np.float64], np_binary_op: np.ufunc
) -> NDArray:
return ( # type: ignore[no-any-return]
np_binary_op(x, y, out=x)
Expand Down
Loading