-
Notifications
You must be signed in to change notification settings - Fork 215
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
Workspaces for different backends of Keras #1242
Draft
tanwarsh
wants to merge
17
commits into
securefederatedai:develop
Choose a base branch
from
tanwarsh:JAX-PyTorch
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d47056a
code changes
tanwarsh 4850493
code changes
tanwarsh b1fdec5
Merge branch 'securefederatedai:develop' into JAX-PyTorch
tanwarsh f0268b9
Merge branch 'securefederatedai:develop' into JAX-PyTorch
tanwarsh 9cdbdf1
code changes
tanwarsh e526aeb
code changes
tanwarsh 858b783
formating issue fix
tanwarsh 4e77c38
code changes
tanwarsh b6acb6e
code changes
tanwarsh 1ae0b47
Merge branch 'develop' into JAX-PyTorch
tanwarsh b5eb73f
code changes
tanwarsh 036aeda
Merge branch 'JAX-PyTorch' of https://github.com/tanwarsh/openfl into…
tanwarsh 21b774a
code changes
tanwarsh c6405c8
code changes
tanwarsh 0a0981d
code changes
tanwarsh a460f41
code changes
tanwarsh afe07eb
code changes
tanwarsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
keras==3.6.0 | ||
tensorflow==2.18.0 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
current_plan_name: default | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
current_plan_name: default | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright (C) 2020-2021 Intel Corporation | ||
# Licensed subject to the terms of the separately executed evaluation license agreement between Intel Corporation and you. | ||
|
||
collaborators: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright (C) 2020-2021 Intel Corporation | ||
# Licensed subject to the terms of the separately executed evaluation license agreement between Intel Corporation and you. | ||
|
||
# collaborator_name,data_directory_path | ||
one,1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright (C) 2020-2021 Intel Corporation | ||
# Licensed subject to the terms of the separately executed evaluation license agreement between Intel Corporation and you. | ||
|
||
aggregator : | ||
defaults : plan/defaults/aggregator.yaml | ||
template : openfl.component.Aggregator | ||
settings : | ||
init_state_path : save/init.pbuf | ||
best_state_path : save/best.pbuf | ||
last_state_path : save/last.pbuf | ||
rounds_to_train : 10 | ||
|
||
collaborator : | ||
defaults : plan/defaults/collaborator.yaml | ||
template : openfl.component.Collaborator | ||
settings : | ||
db_store_rounds: 2 | ||
delta_updates : false | ||
opt_treatment : RESET | ||
|
||
data_loader : | ||
defaults : plan/defaults/data_loader.yaml | ||
template : src.dataloader.NLPDataLoader | ||
settings : | ||
collaborator_count : 2 | ||
batch_size : 64 | ||
split_ratio: 0.2 | ||
num_samples: 10000 | ||
|
||
task_runner : | ||
defaults : plan/defaults/task_runner.yaml | ||
template : src.taskrunner.KerasNLP | ||
settings : | ||
latent_dim : 256 | ||
|
||
network : | ||
defaults : plan/defaults/network.yaml | ||
|
||
assigner : | ||
defaults : plan/defaults/assigner.yaml | ||
|
||
tasks : | ||
defaults : plan/defaults/tasks_keras.yaml | ||
|
||
compression_pipeline : | ||
defaults : plan/defaults/compression_pipeline.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
keras==3.6.0 | ||
jax==0.4.38 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright (C) 2021-2022 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
"""openfl nlp keras template.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
"""Copyright (C) 2020-2021 Intel Corporation | ||
SPDX-License-Identifier: Apache-2.0 | ||
|
||
Licensed subject to the terms of the separately executed evaluation | ||
license agreement between Intel Corporation and you. | ||
""" | ||
from logging import getLogger | ||
from typing import Optional | ||
from typing import Iterator | ||
from typing import Tuple | ||
from typing import Union | ||
|
||
import numpy as np | ||
import src.dataloader_utils as dlu | ||
|
||
from openfl.federated import KerasDataLoader | ||
|
||
logger = getLogger(__name__) | ||
|
||
|
||
class NLPDataLoader(KerasDataLoader): | ||
"""NLP Dataloader template.""" | ||
|
||
def __init__(self, collaborator_count: int, split_ratio: float, | ||
num_samples: int, data_path: str, batch_size: int, **kwargs) -> None: | ||
"""Instantiate the data object. | ||
|
||
Args: | ||
data_path: The file path to the data Returns: | ||
batch_size: The batch size of the data loader tuple: shape of an example feature array | ||
**kwargs: Additional arguments, passed to super init and load_mnist_shard | ||
|
||
Returns: | ||
none | ||
""" | ||
self.shard_num = data_path | ||
self.data_path = dlu.download_data_() | ||
|
||
self.batch_size = batch_size | ||
|
||
train, valid, details = dlu.load_shard(collaborator_count, self.shard_num, | ||
self.data_path, num_samples, split_ratio) | ||
|
||
self.num_samples = details['num_samples'] | ||
self.num_encoder_tokens = details['num_encoder_tokens'] | ||
self.num_decoder_tokens = details['num_decoder_tokens'] | ||
self.max_encoder_seq_length = details['max_encoder_seq_length'] | ||
self.max_decoder_seq_length = details['max_decoder_seq_length'] | ||
|
||
self.X_train = [train[0], train[1]] | ||
self.y_train = train[2] | ||
self.X_valid = [valid[0], valid[1]] | ||
self.y_valid = valid[2] | ||
|
||
def get_feature_shape(self) -> Tuple[int, ...]: | ||
"""Get the shape of an example feature array.""" | ||
return self.X_train[0].shape | ||
|
||
def get_train_loader(self, batch_size: Optional[int] = None) -> Iterator[Tuple[np.ndarray]]: | ||
""" | ||
Get training data loader. | ||
|
||
Returns | ||
------- | ||
loader object | ||
""" | ||
return self._get_batch_generator(X1=self.X_train[0], X2=self.X_train[1], | ||
y=self.y_train, batch_size=batch_size) | ||
|
||
def get_valid_loader(self, batch_size: Optional[int] = None) -> Iterator[Tuple[np.ndarray]]: | ||
""" | ||
Get validation data loader. | ||
|
||
Returns: | ||
loader object | ||
""" | ||
return self._get_batch_generator(X1=self.X_valid[0], X2=self.X_valid[1], | ||
y=self.y_valid, batch_size=batch_size) | ||
|
||
def get_train_data_size(self) -> int: | ||
""" | ||
Get total number of training samples. | ||
|
||
Returns: | ||
int: number of training samples | ||
""" | ||
return self.X_train[0].shape[0] | ||
|
||
def get_valid_data_size(self) -> int: | ||
""" | ||
Get total number of validation samples. | ||
|
||
Returns: | ||
int: number of validation samples | ||
""" | ||
return self.X_valid[0].shape[0] | ||
|
||
@staticmethod | ||
def _batch_generator(X1: np.ndarray, X2: np.ndarray, | ||
y: np.ndarray, idxs: np.ndarray, | ||
batch_size: int, | ||
num_batches: int) -> Iterator[Tuple[np.ndarray]]: | ||
""" | ||
Generate batch of data. | ||
|
||
Args: | ||
X: input data | ||
y: label data | ||
idxs: The index of the dataset | ||
batch_size: The batch size for the data loader | ||
num_batches: The number of batches | ||
Yields: | ||
tuple: input data, label data | ||
""" | ||
for i in range(num_batches): | ||
a = i * batch_size | ||
b = a + batch_size | ||
yield (X1[idxs[a:b]], X2[idxs[a:b]]), y[idxs[a:b]] | ||
|
||
def _get_batch_generator(self, X1: np.ndarray, X2: np.ndarray, | ||
y: np.ndarray, | ||
batch_size: Union[int, None]): | ||
""" | ||
Return the dataset generator. | ||
|
||
Args: | ||
X1: input data (encoder) | ||
X2: input data (decoder) | ||
y: label data | ||
batch_size: The batch size for the data loader | ||
""" | ||
if batch_size is None: | ||
batch_size = self.batch_size | ||
# shuffle data indices | ||
idxs = np.random.permutation(np.arange(X1.shape[0])) | ||
# compute the number of batches | ||
num_batches = int(np.ceil(X1.shape[0] / batch_size)) | ||
# build the generator and return it | ||
# TODO: due to _batch_generator(X1, ...) has first param X1, all params here will be moved, | ||
# X1 -> X2, X2 -> y, y -> idxs, idxs -> batch_size, batch_size -> num_batches, | ||
# and num_batches -> should be unexpected in this function | ||
return self._batch_generator(X1, X2, y, idxs, batch_size, num_batches) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem like JAX is ever actually explicitly used throughout the experiment