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

Workaroun mixed device issue in multiple engine case #1123

Merged
merged 1 commit into from Jul 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -12,7 +12,6 @@
*/
package ai.djl.integration.tests.nn;

import ai.djl.Device;
import ai.djl.MalformedModelException;
import ai.djl.Model;
import ai.djl.engine.Engine;
Expand Down Expand Up @@ -57,6 +56,7 @@
import java.nio.file.Files;
import java.util.Arrays;
import org.testng.Assert;
import org.testng.SkipException;
import org.testng.annotations.Test;

public class BlockCoreTest {
Expand Down Expand Up @@ -207,12 +207,16 @@ public void testBatchNorm() throws IOException, MalformedModelException {
@SuppressWarnings("try")
@Test
public void testLayerNorm() throws IOException, MalformedModelException {
if (!"PyTorch".equals(Engine.getInstance().getEngineName())) {
throw new SkipException("Only works for PyTorch engine.");
}

TrainingConfig config =
new DefaultTrainingConfig(Loss.l2Loss())
.optInitializer(Initializer.ONES, Parameter.Type.WEIGHT);

Block block = LayerNorm.builder().build();
try (Model model = Model.newInstance("model", Device.cpu(), "PyTorch")) {
try (Model model = Model.newInstance("model")) {
model.setBlock(block);

try (Trainer trainer = model.newTrainer(config)) {
Expand All @@ -234,12 +238,16 @@ public void testLayerNorm() throws IOException, MalformedModelException {
@SuppressWarnings("try")
@Test
public void test2LayerNorm() throws IOException, MalformedModelException {
if (!"PyTorch".equals(Engine.getInstance().getEngineName())) {
throw new SkipException("Only works for PyTorch engine.");
}

TrainingConfig config =
new DefaultTrainingConfig(Loss.l2Loss())
.optInitializer(Initializer.ONES, Parameter.Type.WEIGHT);

Block block = LayerNorm.builder().axis(2, 3).build();
try (Model model = Model.newInstance("model", Device.cpu(), "PyTorch")) {
try (Model model = Model.newInstance("model")) {
model.setBlock(block);

try (Trainer trainer = model.newTrainer(config)) {
Expand Down