Skip to content
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

[remove fluid.layers.cross_entropy] remove unit tests (part 6) #48922

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import paddle.utils as utils
from paddle.distributed import fleet
from paddle.distributed.fleet import auto
from paddle.fluid import layers

paddle.enable_static()
_global_parallel_strategy = None
Expand Down Expand Up @@ -93,7 +92,9 @@ def mlp_pretrain_forward(train_program, start_program):

predict = mlp(input)

cost = layers.cross_entropy(input=predict, label=label)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
avg_cost = paddle.mean(x=cost)

return avg_cost, train_program, start_program
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def get_model(self, batch_size=2):

# Train program
predict = cnn_model(images)
cost = fluid.layers.cross_entropy(input=predict, label=label)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
avg_cost = paddle.mean(x=cost)

# Evaluator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,9 @@ def run_one_loop(self, model, opt, data):

out = model(img)
softmax_out = paddle.nn.functional.softmax(out, use_cudnn=False)
loss = fluid.layers.cross_entropy(input=softmax_out, label=label)
loss = paddle.nn.functional.cross_entropy(
input=softmax_out, label=label, reduction='none', use_softmax=False
)
avg_loss = paddle.mean(x=loss)
return avg_loss

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ def get_model(self, batch_size=2, use_dgc=False, dist_strategy=None):
# Train program
predict = cnn_model(images)
with fluid.device_guard("gpu:1"):
cost = fluid.layers.cross_entropy(input=predict, label=label)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
avg_cost = paddle.mean(x=cost)

# Evaluator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ def get_model(self, batch_size=2, use_dgc=False, dist_strategy=None):
# Train program
predict = cnn_model(images)
with fluid.device_guard("gpu:1"):
cost = fluid.layers.cross_entropy(input=predict, label=label)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
avg_cost = paddle.mean(x=cost)

# Evaluator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def get_model(self, batch_size=2, use_dgc=False, dist_strategy=None):
# Train program
predict = cnn_model(images)
with fluid.device_guard("gpu:0"):
cost = fluid.layers.cross_entropy(input=predict, label=label)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
avg_cost = paddle.mean(x=cost)

# Evaluator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def _test_checkpoint(self, fs, dir_path):
feed_list=[image, label], place=fluid.CPUPlace()
)
predict = fluid.layers.fc(input=image, size=10, act='softmax')
loss = fluid.layers.cross_entropy(input=predict, label=label)
loss = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
avg_loss = paddle.mean(loss)
optimizer = fluid.optimizer.AdamOptimizer(learning_rate=0.001)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,9 @@ def train_resnet(self, enable_amp=True, level='O1'):
):
out = resnet(img)

loss = fluid.layers.cross_entropy(input=out, label=label)
loss = paddle.nn.functional.cross_entropy(
input=out, label=label, reduction='none', use_softmax=False
)
avg_loss = paddle.mean(x=loss)

dy_out = avg_loss.numpy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,9 @@ def train_resnet(self, enable_amp=True, level='O1'):
):
out = resnet(img)

loss = fluid.layers.cross_entropy(input=out, label=label)
loss = paddle.nn.functional.cross_entropy(
input=out, label=label, reduction='none', use_softmax=False
)
avg_loss = paddle.mean(x=loss)

dy_out = avg_loss.numpy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ def network():
elif self.conv_groups == 4:
cout = paddle.reshape(conv_out, shape=[1, 1, 10816])
result = fluid.layers.relu(cout)
loss = fluid.layers.cross_entropy(input=result, label=label_shape)
loss = paddle.nn.functional.cross_entropy(
input=result,
label=label_shape,
reduction='none',
use_softmax=False,
)
avg_loss = paddle.mean(loss)
return avg_loss, result

Expand Down Expand Up @@ -156,7 +161,12 @@ def network():
)
cout = paddle.reshape(conv_out, shape=[1, 1, 10816])
result = fluid.layers.relu(cout)
loss = fluid.layers.cross_entropy(input=result, label=label_shape)
loss = paddle.nn.functional.cross_entropy(
input=result,
label=label_shape,
reduction='none',
use_softmax=False,
)
avg_loss = paddle.mean(loss)
return avg_loss, result

Expand Down Expand Up @@ -257,7 +267,12 @@ def network():
elif self.conv_groups == 4:
cout = paddle.reshape(conv_out, shape=[1, 1, 10816])
result = fluid.layers.relu(cout)
loss = fluid.layers.cross_entropy(input=result, label=label_shape)
loss = paddle.nn.functional.cross_entropy(
input=result,
label=label_shape,
reduction='none',
use_softmax=False,
)
avg_loss = paddle.mean(loss)
return avg_loss, result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ def network():
act="relu",
)
result = fluid.layers.relu(fc_out)
loss = fluid.layers.cross_entropy(input=result, label=self.label)
loss = paddle.nn.functional.cross_entropy(
input=result,
label=self.label,
reduction='none',
use_softmax=False,
)
avg_loss = paddle.mean(loss)
return avg_loss, result

Expand Down Expand Up @@ -105,7 +110,12 @@ def network():
)
c_out = paddle.reshape(fc_out, shape=[0, 784])
result = fluid.layers.relu(c_out)
loss = fluid.layers.cross_entropy(input=result, label=self.label)
loss = paddle.nn.functional.cross_entropy(
input=result,
label=self.label,
reduction='none',
use_softmax=False,
)
avg_loss = paddle.mean(loss)
return avg_loss, result

Expand Down Expand Up @@ -174,7 +184,12 @@ def network():
)
c_out = paddle.reshape(fc_out, shape=[1, 1, 2744])
result = fluid.layers.relu(c_out)
loss = fluid.layers.cross_entropy(input=result, label=label_shape)
loss = paddle.nn.functional.cross_entropy(
input=result,
label=label_shape,
reduction='none',
use_softmax=False,
)
avg_loss = paddle.mean(loss)
return avg_loss, result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ def network():
act=None,
)
result = fluid.layers.relu(fc_out)
loss = fluid.layers.cross_entropy(input=result, label=self.label)
loss = paddle.nn.functional.cross_entropy(
input=result,
label=self.label,
reduction='none',
use_softmax=False,
)
avg_loss = paddle.mean(loss)
return avg_loss, result

Expand Down Expand Up @@ -144,7 +149,12 @@ def network():
act=None,
)
result = fluid.layers.relu(fc_out)
loss = fluid.layers.cross_entropy(input=result, label=self.label)
loss = paddle.nn.functional.cross_entropy(
input=result,
label=self.label,
reduction='none',
use_softmax=False,
)
avg_loss = paddle.mean(loss)
return avg_loss, result

Expand Down Expand Up @@ -240,7 +250,12 @@ def network():
act=None,
)
result = fluid.layers.relu(fc_out)
loss = fluid.layers.cross_entropy(input=result, label=self.label)
loss = paddle.nn.functional.cross_entropy(
input=result,
label=self.label,
reduction='none',
use_softmax=False,
)
avg_loss = paddle.mean(loss)
return avg_loss, result

Expand Down