Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d4edc92
Update the model.py for the msmlp example
gzrp Sep 14, 2024
69299bf
Update the data processing for the benchmark dataset
gzrp Sep 14, 2024
e0ebfe6
Merge pull request #1213 from gzrp/dev-postgresql
lzjpaul Sep 14, 2024
e5777da
Update the implementations of MSOptimizer and MSSGD
Sep 15, 2024
a547dd3
Add the implementations of native model
lemonviv Sep 15, 2024
42c5909
Merge pull request #1214 from gzrp/dev-postgresql-trans
chrishkchris Sep 15, 2024
1b7bcad
Merge pull request #1215 from zlheui/train_ms_model
lzjpaul Sep 16, 2024
d5ddd10
Merge pull request #1216 from lemonviv/native-model-impl
chrishkchris Sep 16, 2024
ddad8e3
Update the training script for the cnn ms example
solopku Sep 17, 2024
33218e1
Merge pull request #1220 from solopku/patch-7
chrishkchris Sep 17, 2024
f1973a4
add main file for malaria cnn training
liuchangshiye Oct 12, 2024
fdff2ba
Merge pull request #1221 from liuchangshiye/malaria-train-cnn
lzjpaul Oct 13, 2024
251269b
Create the healthcare folder for healthcare models
gzrp Oct 19, 2024
9d58ff1
Merge pull request #1222 from gzrp/dev-postgresql
lzjpaul Oct 20, 2024
9f5eebc
Add the implementation for the hematologic disease
npcmaci Oct 21, 2024
b3d9d06
Merge pull request #1223 from npcmaci/dev-postgresql
nudles Oct 22, 2024
ca7f46c
Add the readme file for the hematologic disease example
npcmaci Oct 29, 2024
1c0e4d7
Merge pull request #1224 from npcmaci/dev-postgresql
lzjpaul Oct 30, 2024
eadfb94
Add the transforms.py file for the hematologic disease example
gzrp Oct 31, 2024
cf7f55c
Merge pull request #1225 from gzrp/dev-postgresql
chrishkchris Nov 4, 2024
588d796
Create the data folder for the healthcare model zoo
calmdown539 Nov 7, 2024
6241ae2
Create the models folder for the healthcare model zoo
gzrp Nov 7, 2024
89dbc7c
Merge pull request #1227 from gzrp/dev-postgresql
nudles Nov 8, 2024
043b8ca
create the application folder for the healthcare model zoo
npcmaci Nov 8, 2024
f5f2abe
Merge pull request #1226 from L0FX/dev-postgresql
lzjpaul Nov 15, 2024
5482fe7
Merge pull request #1228 from npcmaci/dev-postgresql
chrishkchris Nov 15, 2024
572f3d2
Add the bloodmnist dataset to the healthcare model zoo
Nov 16, 2024
2fb3451
Create the folder for TED application in the healthcare model zoo
hugy718 Nov 16, 2024
c8c455b
Merge pull request #1229 from zlheui/add-bloodmnist-dataset
nudles Nov 19, 2024
9fac6c1
Merge pull request #1230 from hugy718/dev-postgresql
lzjpaul Nov 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions examples/cnn_ms/msmlp/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

singa_dtype = {"float16": tensor.float16, "float32": tensor.float32}


#### self-defined loss begin

### from autograd.py
Expand Down Expand Up @@ -62,11 +63,13 @@ def backward(self, dy=1.0):
dx *= dy
return dx


def se_loss(x):
# assert x.shape == t.shape, "input and target shape different: %s, %s" % (
# x.shape, t.shape)
return SumError()(x)[0]


### from layer.py
class SumErrorLayer(Layer):
"""
Expand All @@ -79,6 +82,7 @@ def __init__(self):
def forward(self, x):
return se_loss(x)


#### self-defined loss end

class MSMLP(model.Model):
Expand All @@ -92,7 +96,6 @@ def __init__(self, data_size=10, perceptron_size=100, num_classes=10):
self.linear1 = layer.Linear(perceptron_size)
self.linear2 = layer.Linear(num_classes)
self.softmax_cross_entropy = layer.SoftMaxCrossEntropy()

self.sum_error = SumErrorLayer()

def forward(self, inputs):
Expand All @@ -101,12 +104,24 @@ def forward(self, inputs):
y = self.linear2(y)
return y

def train_one_batch(self, x, y, synflow_flag, dist_option, spars):
def train_one_batch(self, x, y, dist_option, spars, synflow_flag):
# print ("in train_one_batch")
out = self.forward(x)
loss = self.softmax_cross_entropy(out, y)
# print ("train_one_batch x.data: \n", x.data)
# print ("train_one_batch y.data: \n", y.data)
# print ("train_one_batch out.data: \n", out.data)
if synflow_flag:
# print ("sum_error")
loss = self.sum_error(out)
else: # normal training
# print ("softmax_cross_entropy")
loss = self.softmax_cross_entropy(out, y)
# print ("train_one_batch loss.data: \n", loss.data)

if dist_option == 'plain':
# print ("before pn_p_g_list = self.optimizer(loss)")
pn_p_g_list = self.optimizer(loss)
# print ("after pn_p_g_list = self.optimizer(loss)")
elif dist_option == 'half':
self.optimizer.backward_and_update_half(loss)
elif dist_option == 'partialUpdate':
Expand All @@ -119,17 +134,24 @@ def train_one_batch(self, x, y, synflow_flag, dist_option, spars):
self.optimizer.backward_and_sparse_update(loss,
topK=False,
spars=spars)
# print ("len(pn_p_g_list): \n", len(pn_p_g_list))
# print ("len(pn_p_g_list[0]): \n", len(pn_p_g_list[0]))
# print ("pn_p_g_list[0][0]: \n", pn_p_g_list[0][0])
# print ("pn_p_g_list[0][1].data: \n", pn_p_g_list[0][1].data)
# print ("pn_p_g_list[0][2].data: \n", pn_p_g_list[0][2].data)
return pn_p_g_list, out, loss
# return pn_p_g_list[0], pn_p_g_list[1], pn_p_g_list[2], out, loss

def set_optimizer(self, optimizer):
self.optimizer = optimizer


def create_model(pretrained=False, **kwargs):
"""Constructs a CNN model.

Args:
pretrained (bool): If True, returns a pre-trained model.

Returns:
The created CNN model.
"""
Expand Down Expand Up @@ -196,4 +218,4 @@ def create_model(pretrained=False, **kwargs):
out, loss = model(tx, ty, 'fp32', spars=None)

if i % 100 == 0:
print("training loss = ", tensor.to_numpy(loss)[0])
print("training loss = ", tensor.to_numpy(loss)[0])
Loading
Loading