Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Scala Optimizers can cause seg faults #14498

@andrewfayres

Description

@andrewfayres

Description

In Scala, many of the optimizers cause a seg fault when used in conjunction with a FeedForward. Looked into this and it's because they are recreating native resources during execution which are getting disposed of by the jvm. This happens in the 1.4.0 release.

Minimum reproducible example

The following Scala code will reproduce this for the Adam optimizer.

object TestAdamBug {
  // Simple MLP network
  def mlpNetwork(): Symbol = {
    val input = Symbol.Variable("data")
    val label = Symbol.Variable("label")
    val fc1 = Symbol.FullyConnected(name = "fc1")()(Map("data" -> input, "num_hidden" -> 128))
    val act1 = Symbol.Activation(name = "relu")()(Map("data" -> fc1, "act_type" -> "relu"))
    val fc2 = Symbol.FullyConnected(name = "fc2")()(Map("data" -> act1, "num_hidden" -> 1))
    val loss = Symbol.LinearRegressionOutput(name="loss")()(Map("data" -> fc2, "label" -> label))
    loss
  }

  def getNDArrayIter(): NDArrayIter = {
    val f = NDArray.zeros(100, 20, 20)
    val l = NDArray.zeros(100, 1)
    val data = Array(f)
    val labels = Array(l)
    val batchSize = 10
    val iter = new NDArrayIter(data, labels, batchSize)
    iter
  }

  def main(args: Array[String]): Unit = {

    val net = mlpNetwork()
    val iter = getNDArrayIter()
    val optimizer = new Adam(0.001f, 0.9f, 0.999f, 1e-8f, 1 - 1e-8f, 0f, 10f, null);
    val init = new Normal(0.01f);

    val model = FeedForward.newBuilder(net)
      .setContext(Array(Context.cpu()))
      .setInitializer(init)
      .setNumEpoch(100000)
      .setOptimizer(optimizer)
      .setTrainData(iter)
      .setEvalData(iter)
      .build();
  }
}

@mxnet-label-bot add [Scala, bug]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions