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

java tensorflow and maven version is org.tensorflow:libtensorflow:1.15.0 after session.runner.run() for many times, the memory grow higher and higher then oom #564

Open
hanfengatonline opened this issue Oct 28, 2024 · 1 comment

Comments

@hanfengatonline
Copy link

20241024-155157

my test code with language scala ,this is one predict, we will predict 100 QPS for a docker
val config = ConfigProto.newBuilder
.putDeviceCount("CPU", Runtime.getRuntime.availableProcessors)
.setInterOpParallelismThreads(8)
.setIntraOpParallelismThreads(8)
.setOperationTimeoutInMs(3000)
.build

val options = RunOptions.newBuilder
  .setTimeoutInMs(5000)
  .build 

val modelBundle = SavedModelBundle
  .loader(s"$path")
  .withTags("serve")
  .withConfigProto(config.toByteArray)
  .withRunOptions(options.toByteArray)
  .load

val kernel = modelBundle.session

val data = Map("tensor1" -> Seq(0.1f,0.122f),……)
val runner = kernel.runner()
val inputTensorList: util.ArrayList[Tensor[java.lang.Float]] = new util.ArrayList[Tensor[java.lang.Float]]()
data.map{
  case (tensorName, featureId) => {

    val dataInput:FloatBuffer = FloatBuffer.allocate(featureId.size)
    featureId.foreach(featureValue => {
      dataInput.put(featureValue)
    })
    dataInput.asInstanceOf[Buffer].flip()
    val tensorShape:Array[Long] = Array(1,featureId.size)
    val tensor = Tensor.create(tensorShape,dataInput)
    runner.feed(tensorName,tensor)
    inputTensorList.add(tensor)
  }
}

for(i <- 0 until 2 ){
  runner.fetch("StatefulPartitionedCall",i)
}

val output = runner.run.asScala
val scores:Array[Float] = output.map(ten => {
  val tensorData: Array[Array[Float]] = ten.copyTo(Array.ofDim[Float](ten.shape()(0).toInt, ten.shape()(1).toInt))
  tensorData(0).head
}).toArray
inputTensorList.asScala.foreach(_.close())
output.foreach(_.close())
@karllessard
Copy link
Collaborator

Hi @hanfengatonline , it looks like you are still using TensorFlow 1.x and an older version of TF Java. This version is no longer supported, please take a look at the new version based on TensorFlow 2.x in this repo instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants