Skip to content
Snippets Groups Projects
Commit 40fbe6f1 authored by Rishi Sharma's avatar Rishi Sharma
Browse files

Reformat

parent badc18b5
No related branches found
No related tags found
No related merge requests found
...@@ -4,8 +4,8 @@ import sys ...@@ -4,8 +4,8 @@ import sys
import numpy as np import numpy as np
import pandas as pd import pandas as pd
from matplotlib import pyplot as plt
import torch import torch
from matplotlib import pyplot as plt
def get_stats(l): def get_stats(l):
...@@ -238,4 +238,4 @@ def plot_parameters(path): ...@@ -238,4 +238,4 @@ def plot_parameters(path):
if __name__ == "__main__": if __name__ == "__main__":
assert len(sys.argv) == 2 assert len(sys.argv) == 2
plot_results(sys.argv[1]) plot_results(sys.argv[1])
# plot_parameters(sys.argv[1]) # plot_parameters(sys.argv[1])
\ No newline at end of file
...@@ -4,8 +4,8 @@ import sys ...@@ -4,8 +4,8 @@ import sys
import numpy as np import numpy as np
import pandas as pd import pandas as pd
from matplotlib import pyplot as plt
import torch import torch
from matplotlib import pyplot as plt
def get_stats(l): def get_stats(l):
...@@ -70,7 +70,7 @@ def plot_results(path): ...@@ -70,7 +70,7 @@ def plot_results(path):
for sp in shared_params: for sp in shared_params:
filepath = os.path.join(mf_path, sp) filepath = os.path.join(mf_path, sp)
with open(filepath, "r") as spf: with open(filepath, "r") as spf:
all_shared_params.append(np.array(json.load(spf), dtype = np.int32)) all_shared_params.append(np.array(json.load(spf), dtype=np.int32))
# Plot Training loss # Plot Training loss
plt.figure(1) plt.figure(1)
...@@ -78,19 +78,19 @@ def plot_results(path): ...@@ -78,19 +78,19 @@ def plot_results(path):
mean = np.mean(all_shared_params, axis=0) mean = np.mean(all_shared_params, axis=0)
std = np.std(all_shared_params, axis=0) std = np.std(all_shared_params, axis=0)
with open( with open(
os.path.join(path, "shared_params_avg_"+folder+".json"), "w" os.path.join(path, "shared_params_avg_" + folder + ".json"), "w"
) as mf: ) as mf:
json.dump(mean.tolist(), mf) json.dump(mean.tolist(), mf)
with open( with open(
os.path.join(path, "shared_params_std_"+folder+".json"), "w" os.path.join(path, "shared_params_std_" + folder + ".json"), "w"
) as sf: ) as sf:
json.dump(std.tolist(), sf) json.dump(std.tolist(), sf)
# copy jupyter notebook code # copy jupyter notebook code
percentile = np.percentile(mean, np.arange(0, 100, 1)) percentile = np.percentile(mean, np.arange(0, 100, 1))
plt.plot(np.arange(0, 100, 1), percentile, label=folder) plt.plot(np.arange(0, 100, 1), percentile, label=folder)
plt.title('Shared parameters Percentiles') plt.title("Shared parameters Percentiles")
# plt.ylabel("Absolute frequency value") # plt.ylabel("Absolute frequency value")
plt.xlabel("Percentiles") plt.xlabel("Percentiles")
plt.xticks(np.arange(0, 110, 10)) plt.xticks(np.arange(0, 110, 10))
...@@ -101,14 +101,15 @@ def plot_results(path): ...@@ -101,14 +101,15 @@ def plot_results(path):
print(sort) print(sort)
length = sort.shape[0] length = sort.shape[0]
length = int(length / 20) length = int(length / 20)
bins = [torch.sum(sort[length * i: length * (i + 1)]).item() for i in range(20)] bins = [
torch.sum(sort[length * i : length * (i + 1)]).item() for i in range(20)
]
total = np.sum(bins) total = np.sum(bins)
perc = bins / total #np.divide(bins, total) perc = bins / total # np.divide(bins, total)
print(perc) print(perc)
plt.bar(np.arange(0, 97.5, 5), perc, width=5, align='edge', plt.bar(np.arange(0, 97.5, 5), perc, width=5, align="edge", label=folder)
label=folder)
plt.title('Shared parameters Percentiles') plt.title("Shared parameters Percentiles")
# plt.ylabel("Absolute frequency value") # plt.ylabel("Absolute frequency value")
plt.xlabel("Percentiles") plt.xlabel("Percentiles")
plt.legend(loc="lower right") plt.legend(loc="lower right")
...@@ -122,4 +123,4 @@ def plot_results(path): ...@@ -122,4 +123,4 @@ def plot_results(path):
if __name__ == "__main__": if __name__ == "__main__":
assert len(sys.argv) == 2 assert len(sys.argv) == 2
plot_results(sys.argv[1]) plot_results(sys.argv[1])
\ No newline at end of file
...@@ -8,7 +8,6 @@ import numpy as np ...@@ -8,7 +8,6 @@ import numpy as np
import torch import torch
import torch.nn.functional as F import torch.nn.functional as F
from torch import nn from torch import nn
from torch.autograd import Variable
from torch.utils.data import DataLoader from torch.utils.data import DataLoader
from decentralizepy.datasets.Data import Data from decentralizepy.datasets.Data import Data
......
...@@ -422,7 +422,10 @@ class Node: ...@@ -422,7 +422,10 @@ class Node:
if self.model.shared_parameters_counter is not None: if self.model.shared_parameters_counter is not None:
logging.info("Saving the shared parameter counts") logging.info("Saving the shared parameter counts")
with open( with open(
os.path.join(self.log_dir, "{}_shared_parameters.json".format(self.rank)), "w" os.path.join(
self.log_dir, "{}_shared_parameters.json".format(self.rank)
),
"w",
) as of: ) as of:
json.dump(self.model.shared_parameters_counter.numpy().tolist(), of) json.dump(self.model.shared_parameters_counter.numpy().tolist(), of)
self.communication.disconnect_neighbors() self.communication.disconnect_neighbors()
......
...@@ -126,7 +126,9 @@ class PartialModel(Sharing): ...@@ -126,7 +126,9 @@ class PartialModel(Sharing):
) )
Path(self.folder_path).mkdir(parents=True, exist_ok=True) Path(self.folder_path).mkdir(parents=True, exist_ok=True)
self.model.shared_parameters_counter = torch.zeros(self.change_transformer(self.init_model).shape[0], dtype = torch.int32) self.model.shared_parameters_counter = torch.zeros(
self.change_transformer(self.init_model).shape[0], dtype=torch.int32
)
def extract_top_gradients(self): def extract_top_gradients(self):
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment