From 408129bbdbfa73443a2f8ff75f887d9d5f2aba68 Mon Sep 17 00:00:00 2001 From: Javier Date: Sat, 1 Feb 2025 17:47:15 +0100 Subject: [PATCH] refactor(examples) Remove `tabnet` examples and 2e2 (#4879) --- .github/dependabot.yml | 6 -- .github/workflows/cache-cleanup.yml | 1 - dev/build-example-docs.py | 1 - examples/quickstart-tabnet/README.md | 76 ----------------- examples/quickstart-tabnet/client.py | 85 ------------------- examples/quickstart-tabnet/pyproject.toml | 17 ---- examples/quickstart-tabnet/requirements.txt | 5 -- examples/quickstart-tabnet/server.py | 7 -- ...run-quickstart-examples-docker-compose.rst | 2 - src/py/flwr/common/object_ref.py | 14 --- 10 files changed, 214 deletions(-) delete mode 100644 examples/quickstart-tabnet/README.md delete mode 100644 examples/quickstart-tabnet/client.py delete mode 100644 examples/quickstart-tabnet/pyproject.toml delete mode 100644 examples/quickstart-tabnet/requirements.txt delete mode 100644 examples/quickstart-tabnet/server.py diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 6add959f95fc..a14c7291e937 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -65,12 +65,6 @@ updates: interval: "daily" open-pull-requests-limit: 2 - - package-ecosystem: "pip" - directory: "/e2e/tabnet" - schedule: - interval: "daily" - open-pull-requests-limit: 2 - - package-ecosystem: "pip" directory: "/e2e/pytorch-lightning" schedule: diff --git a/.github/workflows/cache-cleanup.yml b/.github/workflows/cache-cleanup.yml index dca5505f7bf6..cb874175098c 100644 --- a/.github/workflows/cache-cleanup.yml +++ b/.github/workflows/cache-cleanup.yml @@ -18,7 +18,6 @@ jobs: - directory: jax - directory: pytorch - directory: tensorflow - - directory: tabnet - directory: opacus - directory: pytorch-lightning - directory: scikit-learn diff --git a/dev/build-example-docs.py b/dev/build-example-docs.py index 73ddeafc4e35..a1300759d1ea 100644 --- a/dev/build-example-docs.py +++ b/dev/build-example-docs.py @@ -83,7 +83,6 @@ "opacus": "https://opacus.ai/", "pandas": "https://pandas.pydata.org/", "scikit-learn": "https://scikit-learn.org/", - "tabnet": "https://github.com/titu1994/tf-TabNet", "tensorboard": "https://www.tensorflow.org/tensorboard", "tensorflow": "https://www.tensorflow.org/", "torch": "https://pytorch.org/", diff --git a/examples/quickstart-tabnet/README.md b/examples/quickstart-tabnet/README.md deleted file mode 100644 index e8be55eaacef..000000000000 --- a/examples/quickstart-tabnet/README.md +++ /dev/null @@ -1,76 +0,0 @@ ---- -tags: [quickstart, tabular] -dataset: [Iris] -framework: [tabnet] ---- - -# Flower TabNet Example using TensorFlow - -This introductory example to Flower uses Keras but deep knowledge of Keras is not necessarily required to run the example. However, it will help you understanding how to adapt Flower to your use-cases. You can learn more about TabNet from [paper](https://arxiv.org/abs/1908.07442) and its implementation using TensorFlow at [this repository](https://github.com/titu1994/tf-TabNet). Note also that the basis of this example using federated learning is the example from the repository above. - -## Project Setup - -Start by cloning the example project. We prepared a single-line command that you can copy into your shell which will checkout the example for you: - -```shell -git clone --depth=1 https://github.com/adap/flower.git && mv flower/examples/quickstart-tabnet . && rm -rf flower && cd quickstart-tabnet -``` - -This will create a new directory called `quickstart-tabnet` containing the following files: - -```shell --- pyproject.toml --- requirements.txt --- client.py --- server.py --- README.md -``` - -### Installing Dependencies - -Project dependencies (such as `tensorflow` and `flwr`) are defined in `pyproject.toml` and `requirements.txt`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)) or [pip](https://pip.pypa.io/en/latest/development/), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. - -#### Poetry - -```shell -poetry install -poetry shell -``` - -Poetry will install all your dependencies in a newly created virtual environment. To verify that everything works correctly you can run the following command: - -```shell -poetry run python3 -c "import flwr" -``` - -If you don't see any errors you're good to go! - -#### pip - -Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt. - -```shell -pip install -r requirements.txt -``` - -## Run Federated Learning with TensorFlow/Keras and Flower - -Afterwards you are ready to start the Flower server as well as the clients. You can simply start the server in a terminal as follows: - -```shell -poetry run python server.py -``` - -Now you are ready to start the Flower clients which will participate in the learning. To do so simply open two more terminals and run the following command in each: - -```shell -poetry run python client.py -``` - -Alternatively you can run all of it in one shell as follows: - -```shell -poetry run python server.py & -poetry run python client.py & -poetry run python client.py -``` diff --git a/examples/quickstart-tabnet/client.py b/examples/quickstart-tabnet/client.py deleted file mode 100644 index 4da5a394a199..000000000000 --- a/examples/quickstart-tabnet/client.py +++ /dev/null @@ -1,85 +0,0 @@ -import os - -import flwr as fl -import tabnet -import tensorflow as tf -import tensorflow_datasets as tfds - -train_size = 125 -BATCH_SIZE = 50 -col_names = ["sepal_length", "sepal_width", "petal_length", "petal_width"] - - -def transform(ds): - features = tf.unstack(ds["features"]) - labels = ds["label"] - - x = dict(zip(col_names, features)) - y = tf.one_hot(labels, 3) - return x, y - - -def prepare_iris_dataset(): - ds_full = tfds.load(name="iris", split=tfds.Split.TRAIN) - ds_full = ds_full.shuffle(150, seed=0) - - ds_train = ds_full.take(train_size) - ds_train = ds_train.map(transform) - ds_train = ds_train.batch(BATCH_SIZE) - - ds_test = ds_full.skip(train_size) - ds_test = ds_test.map(transform) - ds_test = ds_test.batch(BATCH_SIZE) - - feature_columns = [] - for col_name in col_names: - feature_columns.append(tf.feature_column.numeric_column(col_name)) - - return ds_train, ds_test, feature_columns - - -ds_train, ds_test, feature_columns = prepare_iris_dataset() -# Make TensorFlow log less verbose -os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" - -# Load TabNet model -model = tabnet.TabNetClassifier( - feature_columns, - num_classes=3, - feature_dim=8, - output_dim=4, - num_decision_steps=4, - relaxation_factor=1.0, - sparsity_coefficient=1e-5, - batch_momentum=0.98, - virtual_batch_size=None, - norm_type="group", - num_groups=1, -) -lr = tf.keras.optimizers.schedules.ExponentialDecay( - 0.01, decay_steps=100, decay_rate=0.9, staircase=False -) -optimizer = tf.keras.optimizers.Adam(lr) -model.compile(optimizer, loss="categorical_crossentropy", metrics=["accuracy"]) - - -# Define Flower client -class TabNetClient(fl.client.NumPyClient): - def get_parameters(self, config): - return model.get_weights() - - def fit(self, parameters, config): - model.set_weights(parameters) - model.fit(ds_train, epochs=25) - return model.get_weights(), len(ds_train), {} - - def evaluate(self, parameters, config): - model.set_weights(parameters) - loss, accuracy = model.evaluate(ds_test) - return loss, len(ds_train), {"accuracy": accuracy} - - -# Start Flower client -fl.client.start_client( - server_address="127.0.0.1:8080", client=TabNetClient().to_client() -) diff --git a/examples/quickstart-tabnet/pyproject.toml b/examples/quickstart-tabnet/pyproject.toml deleted file mode 100644 index 8345d6bd3da2..000000000000 --- a/examples/quickstart-tabnet/pyproject.toml +++ /dev/null @@ -1,17 +0,0 @@ -[build-system] -requires = ["poetry-core>=1.4.0"] -build-backend = "poetry.core.masonry.api" - -[tool.poetry] -name = "quickstart-tabnet" -version = "0.1.0" -description = "Tabnet Federated Learning Quickstart with Flower" -authors = ["The Flower Authors "] - -[tool.poetry.dependencies] -python = ">=3.9,<3.11" -flwr = ">=1.0,<2.0" -tensorflow-cpu = { version = ">=2.9.1,<2.11.1 || >2.11.1", markers = "platform_machine == \"x86_64\"" } -tensorflow-macos = { version = ">=2.9.1,<2.11.1 || >2.11.1", markers = "sys_platform == \"darwin\" and platform_machine == \"arm64\"" } -tensorflow_datasets = "4.9.2" -tabnet = "0.1.6" diff --git a/examples/quickstart-tabnet/requirements.txt b/examples/quickstart-tabnet/requirements.txt deleted file mode 100644 index 243613e267d0..000000000000 --- a/examples/quickstart-tabnet/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -flwr>=1.0, <2.0 -tensorflow-macos>=2.9.1, != 2.11.1 ; sys_platform == "darwin" and platform_machine == "arm64" -tensorflow-cpu>=2.9.1, != 2.11.1 ; platform_machine == "x86_64" -tabnet~=0.1.6 -tensorflow_datasets~=4.9.2 diff --git a/examples/quickstart-tabnet/server.py b/examples/quickstart-tabnet/server.py deleted file mode 100644 index a99eb48059bc..000000000000 --- a/examples/quickstart-tabnet/server.py +++ /dev/null @@ -1,7 +0,0 @@ -import flwr as fl - -# Start Flower server -fl.server.start_server( - server_address="0.0.0.0:8080", - config=fl.server.ServerConfig(num_rounds=3), -) diff --git a/framework/docs/source/docker/run-quickstart-examples-docker-compose.rst b/framework/docs/source/docker/run-quickstart-examples-docker-compose.rst index 609035b95876..951a092ca465 100644 --- a/framework/docs/source/docker/run-quickstart-examples-docker-compose.rst +++ b/framework/docs/source/docker/run-quickstart-examples-docker-compose.rst @@ -123,7 +123,5 @@ Limitations - None - - quickstart-sklearn-tabular - None - - - quickstart-tabnet - - The example has not yet been updated to work with the latest ``flwr`` version. - - quickstart-tensorflow - None diff --git a/src/py/flwr/common/object_ref.py b/src/py/flwr/common/object_ref.py index bf34bf5f639c..e449abcf2bb0 100644 --- a/src/py/flwr/common/object_ref.py +++ b/src/py/flwr/common/object_ref.py @@ -19,13 +19,10 @@ import importlib import sys from importlib.util import find_spec -from logging import WARN from pathlib import Path from threading import Lock from typing import Any, Optional, Union -from .logger import log - OBJECT_REF_HELP_STR = """ \n\nThe object reference string should have the form :. Valid examples include `client:app` and `project.package.module:wrapper.app`. It must @@ -171,17 +168,6 @@ def load_app( # pylint: disable= too-many-branches # Import the module if module_str not in sys.modules: module = importlib.import_module(module_str) - # Hack: `tabnet` does not work with `importlib.reload` - elif "tabnet" in sys.modules: - log( - WARN, - "Cannot reload module `%s` from disk due to compatibility issues " - "with the `tabnet` library. The module will be loaded from the " - "cache instead. If you experience issues, consider restarting " - "the application.", - module_str, - ) - module = sys.modules[module_str] else: module = sys.modules[module_str] _reload_modules(project_dir)