Skip to content

Commit c0a1b79

Browse files
committed
Restore eager behavior on the JVM side, eliminating redundant op invocations in case user code refers to Tensors more than once
1 parent 74e91f2 commit c0a1b79

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

backends/.js/src/main/scala/ORTOperatorBackend.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ trait ORTOperatorBackend extends OpToONNXBytesConverter {
178178
opName,
179179
attrs
180180
)
181+
// unsafeRunSync is not avaible in the JS context
182+
// so behavior on the JS side remains lazy
183+
// and thus inefficient in case user code refers to Tensors more than once
181184
result //.flatMap(x => IO.println("opName = " + opName).as(x))
182185
}
183186

backends/.jvm/src/main/scala/ORTOperatorBackend.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,10 @@ trait ORTOperatorBackend extends OpToONNXBytesConverter with AutoCloseable {
206206
opName,
207207
attrs
208208
)
209-
//TODO: now that this is otherwise working, try memoizing here
210-
result.flatMap(IO.println("Real call opName => " + opName).as(_))
209+
//Using unsafeRunSync here to restore eager evaluation
210+
//and avoid redundant op invocations in case user code refers to Tensors more than once
211+
result.memoize.unsafeRunSync()
212+
//.flatMap(IO.println("Real call opName => " + opName).as(_))
211213
}
212214

213215
def modelToPersist(mod: ModelProto, outName: String) = {

0 commit comments

Comments
 (0)