Skip to content

Commit

Permalink
Added working model-parallel tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
Jethro Gaglione committed Dec 23, 2023
1 parent dfb208d commit 7a15c87
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 6 deletions.
Binary file added .train_pytorch_modelParallel.py.swp
Binary file not shown.
Binary file added data/FashionMNIST/raw/t10k-images-idx3-ubyte
Binary file not shown.
Binary file added data/FashionMNIST/raw/t10k-images-idx3-ubyte.gz
Binary file not shown.
Binary file added data/FashionMNIST/raw/t10k-labels-idx1-ubyte
Binary file not shown.
Binary file added data/FashionMNIST/raw/t10k-labels-idx1-ubyte.gz
Binary file not shown.
Binary file added data/FashionMNIST/raw/train-images-idx3-ubyte
Binary file not shown.
Binary file added data/FashionMNIST/raw/train-images-idx3-ubyte.gz
Binary file not shown.
Binary file added data/FashionMNIST/raw/train-labels-idx1-ubyte
Binary file not shown.
Binary file added data/FashionMNIST/raw/train-labels-idx1-ubyte.gz
Binary file not shown.
9 changes: 5 additions & 4 deletions train_pytorch_modelParallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def train(model, train_loader, loss_function, optimizer, num_epochs):

for i ,(images,labels) in enumerate(train_loader):
images = torch.div(images, 255.)
images, labels = images.to(device), labels.to(device)
# images, labels = images.to(device), labels.to(device)

optimizer.zero_grad()
outputs = model(images)
Expand Down Expand Up @@ -70,9 +70,9 @@ def train(model, train_loader, loss_function, optimizer, num_epochs):
if not torch.cuda.is_available():
sys.exit("A minimum of 2 GPUs must be available to train this model.")

print("Training on device: ", device)
#print("Training on device: ", device)
my_net = SeqNet(input_size, hidden_size1, output_size)
my_net = my_net.to(device)
#my_net = my_net.to(device)


optimizer = torch.optim.Adam( my_net.parameters(), lr=lr)
Expand All @@ -86,6 +86,7 @@ def train(model, train_loader, loss_function, optimizer, num_epochs):

train(my_net, fmnist_train_loader, loss_function, optimizer, num_epochs)

"""
correct = 0
total = 0
for images,labels in fmnist_test_loader:
Expand All @@ -96,5 +97,5 @@ def train(model, train_loader, loss_function, optimizer, num_epochs):
_, predicted = torch.max(output,1)
correct += (predicted == labels).sum()
total += labels.size(0)

print('Accuracy of the model: %.3f %%' %((100*correct)/(total+1)))
"""
2 changes: 0 additions & 2 deletions tutorials/model-parallel.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def train(model, train_loader, loss_function, optimizer, num_epochs):

for i ,(images,labels) in enumerate(train_loader):
images = torch.div(images, 255.)
images, labels = images.to(device), labels.to(device)

optimizer.zero_grad()
outputs = model(images)
Expand Down Expand Up @@ -81,7 +80,6 @@ lr = 0.01
if not torch.cuda.is_available():
sys.exit("A minimum of 2 GPUs must be available to train this model.")

print("Training on device: ", device)
my_net = SeqNet(input_size, hidden_size1, output_size)

optimizer = torch.optim.Adam( my_net.parameters(), lr=lr)
Expand Down

0 comments on commit 7a15c87

Please sign in to comment.