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

Angel-serving 加载模型NPE错误 #8

Open
xiaotiao opened this issue Jan 10, 2020 · 0 comments
Open

Angel-serving 加载模型NPE错误 #8

xiaotiao opened this issue Jan 10, 2020 · 0 comments

Comments

@xiaotiao
Copy link

xiaotiao commented Jan 10, 2020

Angel-Serving NPE错误

问题

  按官方文档加载了自己定义的模型,经测试模型无问题,然后调用angel-serving的predictAPI出现如下错误.

20/01/08 15:32:27 INFO common.ServiceImpl$ : modelSpec: fm, value: 6

20/01/08 15:32:27 INFO common.ServiceImpl$ : servableHandle {name: fm, version: 6}
java.lang.NullPointerException
	at com.tencent.angel.mlcore.variable.EmbedUtils$$anonfun$9.apply(EmbedUtils.scala:144)
	at com.tencent.angel.mlcore.variable.EmbedUtils$$anonfun$9.apply(EmbedUtils.scala:138)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
	at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
	at scala.collection.mutable.ArrayOps$ofInt.foreach(ArrayOps.scala:234)
	at scala.collection.TraversableLike$class.map(TraversableLike.scala:234)
	at scala.collection.mutable.ArrayOps$ofInt.map(ArrayOps.scala:234)
	at com.tencent.angel.mlcore.variable.EmbedUtils$.oneHotAssemble(EmbedUtils.scala:138)
	at com.tencent.angel.mlcore.variable.EmbedUtils$$anonfun$1.apply(EmbedUtils.scala:50)
	at com.tencent.angel.mlcore.variable.EmbedUtils$$anonfun$1.apply(EmbedUtils.scala:41)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
	at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
	at scala.collection.mutable.ArrayOps$ofInt.foreach(ArrayOps.scala:234)
	at scala.collection.TraversableLike$class.map(TraversableLike.scala:234)
	at scala.collection.mutable.ArrayOps$ofInt.map(ArrayOps.scala:234)
	at com.tencent.angel.mlcore.variable.EmbedUtils$.geneMatrix(EmbedUtils.scala:41)
	at com.tencent.angel.mlcore.local.variables.LocalEmbedVariable.doPull(LocalEmbedVariable.scala:60)
	at com.tencent.angel.mlcore.variable.Variable.pull(Variable.scala:232)
	at com.tencent.angel.mlcore.local.LocalVariableManager$$anonfun$pullALL$1.apply(LocalVariableManager.scala:43)
	at com.tencent.angel.mlcore.local.LocalVariableManager$$anonfun$pullALL$1.apply(LocalVariableManager.scala:41)
	at scala.collection.Iterator$class.foreach(Iterator.scala:893)
	at scala.collection.AbstractIterator.foreach(Iterator.scala:1336)
	at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
	at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
	at com.tencent.angel.mlcore.local.LocalVariableManager.pullALL(LocalVariableManager.scala:41)
	at com.tencent.angel.mlcore.MLModel.pullParams(MLModel.scala:116)
	at com.tencent.angel.mlcore.local.LocalModel.predict(LocalModel.scala:50)
	at com.tencent.angel.serving.servables.angel.AngelSavedModelBundle.runPredict(AngelSavedModelBundle.scala:67)
	at com.tencent.angel.serving.servables.common.ServiceImpl$.predict(ServiceImpl.scala:57)
	at com.tencent.angel.serving.service.jersey.resources.HttpRestApiHandler.processPredictRequest(HttpRestApiHandler.scala:152)
	at com.tencent.angel.serving.service.jersey.resources.HttpRestApiHandler.processPredictionServiceRequest(HttpRestApiHandler.scala:126)
	at sun.reflect.GeneratedMethodAccessor12.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
	at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
	at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
	at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
	at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
	at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
	at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
	at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
	at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
	at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
	at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
	at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
	at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
	at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
	at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:427)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
	at org.eclipse.jetty.server.Server.handle(Server.java:370)
	at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
	at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:984)
	at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1045)
	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:861)
	at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:236)
	at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
	at java.lang.Thread.run(Thread.java:748)

  经排查后,发现LocalEmbedVariable.scala下列代码存在问题.

  protected override def doPull(epoch: Int, indices: Vector = null): Unit = {
    embeddings.clear()

    if (indices != null) {
      indices.getStorage match {
        case s: IntIntDenseVectorStorage =>
          s.getValues.foreach { idx => embeddings.put(idx.toLong, storage.getRow(idx)) }
        case s: IntLongDenseVectorStorage =>
          s.getValues.foreach { idx => embeddings.put(idx, storage.getRow(idx.toInt)) }
      }
    } else {
      (0 until numRows).foreach { idx =>
        embeddings.put(idx.toLong, storage.getRow(idx))
      }
    }

    val matStats = EmbedUtils.geneMatrix(placeHolder, assembleHint, embeddings)
    matrix = matStats._1
    assembleStats = matStats._2
  }

  当storage 实例为MapMatrix时,其对应属性mapMatrix声明如下:

protected HashMap<Long, Vec> mapMatrix;

  而上述storage.getRow(idx) idx为Int时获取不到相关值,因为在Java中包装类型Long和Integer各自维护了缓存. 改为使用Long类型则能获取到,如下是改动后的代码.

   protected override def doPull(epoch: Int, indices: Vector = null): Unit = {
    embeddings.clear()

    if (indices != null) {
      indices.getStorage match {
        case s: IntIntDenseVectorStorage =>
          s.getValues.foreach { idx => embeddings.put(idx.toLong, storage.getRow(idx)) }
        case s: IntLongDenseVectorStorage =>
          s.getValues.foreach { idx => embeddings.put(idx, storage.getRow(idx.toInt)) }
      }
    } else {
      (0 until numRows).foreach { idx =>
      	if ( storage.isInstanceOf[MapMatrix[Vector]]) {
        	val mapStorage = storage.asInstanceOf[MapMatrix[Vector]]
	        embeddings.put(idx.toLong, mapStorage.getRow(idx.toLong))
      	}else{
          embeddings.put(idx.toLong, storage.getRow(idx))
        }

      }
    }
}
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

1 participant