-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update federator to work on K8s with Helm
- Loading branch information
1 parent
ffd2aed
commit 8605b71
Showing
10 changed files
with
91 additions
and
25 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +0,0 @@ | ||
venv | ||
data_loaders | ||
data/cifar-10-batches-py | ||
data/cifar-100-python.tar.gz | ||
data/FashionMNIST | ||
data/cifar-100-python | ||
data/cifar-10-python.tar.gz | ||
simple_example | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,5 @@ spec: | |
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 10Gi | ||
storage: 20Gi | ||
status: {} |
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.
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,9 @@ | ||
name: ../docker-compose-gcloud | ||
description: A generated Helm Chart for ../docker-compose-gcloud from Skippbox Kompose | ||
version: 0.0.1 | ||
apiVersion: v1 | ||
appVersion: 1.16.0 | ||
keywords: | ||
- ../docker-compose-gcloud | ||
sources: | ||
home: |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fltk: | ||
worldsize: 10 | ||
config: cloud_experiment.yaml | ||
port: 5001 | ||
worker: | ||
cpu: 500m | ||
memory: 1073742000 |
Empty file.
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,57 @@ | ||
from collections import OrderedDict | ||
from typing import Union | ||
|
||
import torch | ||
|
||
from fltk.util.base_config import BareConfig | ||
import os | ||
|
||
def flatten_params(model_description: Union[torch.nn.Module, OrderedDict]): | ||
""" | ||
flattens all parameters into a single column vector. Returns the dictionary to recover them | ||
:param: parameters: a generator or list of all the parameters | ||
:return: a dictionary: {"params": [#params, 1], | ||
"indices": [(start index, end index) for each param] **Note end index in uninclusive** | ||
""" | ||
if isinstance(model_description, torch.nn.Module): | ||
parameters = model_description.parameters() | ||
else: | ||
parameters = model_description.values() | ||
l = [torch.flatten(p) for p in parameters] | ||
flat = torch.cat(l).view(-1, 1) | ||
return flat | ||
|
||
|
||
def recover_flattened(flat_params, model): | ||
""" | ||
Gives a list of recovered parameters from their flattened form | ||
:param flat_params: [#params, 1] | ||
:param indices: a list detaling the start and end index of each param [(start, end) for param] | ||
:param model: the model that gives the params with correct shapes | ||
:return: the params, reshaped to the ones in the model, with the same order as those in the model | ||
""" | ||
indices = [] | ||
s = 0 | ||
for p in model.parameters(): | ||
size = p.shape[0] | ||
indices.append((s, s+size)) | ||
s += size | ||
l = [flat_params[s:e] for (s, e) in indices] | ||
for i, p in enumerate(model.parameters()): | ||
l[i] = l[i].view(*p.shape) | ||
return l | ||
|
||
def initialize_default_model(config: BareConfig, model_class) -> torch.nn.Module: | ||
""" | ||
Load a default model dictionary into a torch model. | ||
@param model: | ||
@type model: | ||
@param config: | ||
@type config: | ||
@return: | ||
@rtype: | ||
""" | ||
model = model_class() | ||
default_model_path = f"{config.get_default_model_folder_path()}/{model_class.__name__}.model" | ||
model.load_state_dict(torch.load(default_model_path)) | ||
return model |