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

Fixing onnx saving path bug #13959

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
20 changes: 11 additions & 9 deletions src/main/scala/com/johnsnowlabs/ml/onnx/OnnxWrapper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ class OnnxWrapper(var onnxModel: Array[Byte]) extends Serializable {
.toString

// 2. Save onnx model
val onnxFile = Paths.get(tmpFolder, file).toString
maziyarpanahi marked this conversation as resolved.
Show resolved Hide resolved
FileUtils.writeByteArrayToFile(new File(onnxFile), onnxModel)
val onnxFile = Paths
.get(tmpFolder,
file.replace(":", ""))
.toString

FileUtils.writeByteArrayToFile(new File(onnxFile), onnxModel)
// 4. Zip folder
if (zip) ZipArchiveUtil.zip(tmpFolder, file)

Expand All @@ -76,8 +79,8 @@ object OnnxWrapper {

// TODO: make sure this.synchronized is needed or it's not a bottleneck
private def withSafeOnnxModelLoader(
onnxModel: Array[Byte],
sessionOptions: Option[SessionOptions] = None): (OrtSession, OrtEnvironment) =
onnxModel: Array[Byte],
sessionOptions: Option[SessionOptions] = None): (OrtSession, OrtEnvironment) =
this.synchronized {
val env = OrtEnvironment.getEnvironment()

Expand Down Expand Up @@ -160,8 +163,7 @@ object OnnxWrapper {
}

case class EncoderDecoderWrappers(
encoder: OnnxWrapper,
decoder: OnnxWrapper,
decoderWithPast: OnnxWrapper)

}
encoder: OnnxWrapper,
decoder: OnnxWrapper,
decoderWithPast: OnnxWrapper)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.johnsnowlabs.nlp.embeddings

import com.johnsnowlabs.nlp.base.DocumentAssembler
import com.johnsnowlabs.nlp.util.io.ResourceHelper
import com.johnsnowlabs.tags.{SlowTest, FastTest}
import com.johnsnowlabs.tags.{SlowTest}
import org.apache.spark.ml.Pipeline
import org.scalatest.flatspec.AnyFlatSpec

Expand Down