File size: 1,590 Bytes
e5ef96b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import ml.combust.mleap.tensorflow.TensorflowModel
import ml.combust.mleap.core.types.TensorType
import ml.combust.mleap.tensor.{DenseTensor, Tensor}
import scala.util.{Try, Success, Failure}

println("=== Test A: does TensorflowModel construction/load itself parse the GraphDef eagerly? ===")
val garbage: Array[Byte] = Array.fill(64)(0x41.toByte) // 64 bytes of 'A', not a valid GraphDef
val modelA = TensorflowModel(
  inputs = Seq(),
  outputs = Seq(),
  nodes = None,
  format = Some("graph"),
  modelBytes = garbage
)
println(s"[Test A] TensorflowModel(...) constructed WITHOUT any exception at construction time (garbage modelBytes of ${garbage.length} bytes) -- confirms MLeap does zero eager validation at load/construction: $modelA")

println("\n=== Test B: what happens when apply() actually triggers GraphDef.parseFrom + importGraphDef on garbage bytes? ===")
val resultB = Try { modelA.apply() }
resultB match {
  case Success(v) => println(s"[Test B UNEXPECTED SUCCESS] $v")
  case Failure(e) => println(s"[Test B EXCEPTION] ${e.getClass.getName}: ${e.getMessage}")
}

println("\n=== Test C: same, but with a well-formed EMPTY protobuf (0 bytes) as modelBytes, to see baseline behavior ===")
val modelC = TensorflowModel(
  inputs = Seq(),
  outputs = Seq(),
  nodes = None,
  format = Some("graph"),
  modelBytes = Array.emptyByteArray
)
val resultC = Try { modelC.apply() }
resultC match {
  case Success(v) => println(s"[Test C UNEXPECTED SUCCESS] $v")
  case Failure(e) => println(s"[Test C EXCEPTION] ${e.getClass.getName}: ${e.getMessage}")
}

println("\n=== DONE ===")