Skip to content

Commit

Permalink
Update README; rename io.kjaer.compiletime package to fix error impor…
Browse files Browse the repository at this point in the history
…ting from sbt console
  • Loading branch information
EmergentOrder committed Dec 22, 2022
1 parent a50a2e3 commit 4a24d1d
Show file tree
Hide file tree
Showing 23 changed files with 41 additions and 29 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ First we create an "image" tensor composed entirely of pixel value [42](https://
```scala
import java.nio.file.{Files, Paths}
import org.emergentorder.onnx.Tensors._
import org.emergentorder.onnx.Tensors.Tensor._
import org.emergentorder.onnx.backends._
import org.emergentorder.compiletime._
import io.kjaer.compiletime._
import org.emergentorder.io.kjaer.compiletime._

val squeezenetBytes = Files.readAllBytes(Paths.get("squeezenet1.0-12.onnx"))
val squeezenet = new ORTModelBackend(squeezenetBytes)
Expand Down Expand Up @@ -57,16 +58,18 @@ val out = squeezenet.fullModel[Float,
// val out:
// Tensor[Float,("ImageNetClassification",
// "Batch" ##: "Class" ##: TSNil,
// 1 #: 1000 #: SNil)] = (Array(0.8230729,
// 1 #: 1000 #: 1 #: 1 SNil)] = IO(...)
// ...

//The output shape
out.shape
// val res0: Array[Int] = Array(1, 1000)
out.shape.unsafeRunSync()
// val res0: Array[Int] = Array(1, 1000, 1, 1)

val data = out.data.unsafeRunSync()
// val data: Array[Float] = Array(1.786191E-4, ...)

//The highest scoring and thus highest probability (predicted) class
out.data.indices.maxBy(out.data)
data.indices.maxBy(data)
// val res1: Int = 549
```

Expand Down
2 changes: 1 addition & 1 deletion backends/.js/src/main/scala/ORTOperatorBackend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.emergentorder.onnx.Tensors._
import org.emergentorder.onnx.Tensors.Tensor._
import org.emergentorder.compiletime._
import onnxruntimeCommon.inferenceSessionMod.InferenceSession
import io.kjaer.compiletime._
import org.emergentorder.io.kjaer.compiletime._

//TODO: fix redundant computation due to cats-effect on the JS side
//Still happening, though partially fixed by changes in core
Expand Down
2 changes: 1 addition & 1 deletion backends/.js/src/main/scala/ORTWebModelBackend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.emergentorder.onnx._
import org.emergentorder.onnx.Tensors._
import org.emergentorder.onnx.Tensors.Tensor._
import org.emergentorder.compiletime._
import io.kjaer.compiletime._
import org.emergentorder.io.kjaer.compiletime._

import ORTTensorUtils._

Expand Down
2 changes: 1 addition & 1 deletion backends/.js/src/test/scala/SqueezeNetTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.emergentorder.onnx.Tensors._
import org.emergentorder.onnx.Tensors.Tensor._
import org.emergentorder.onnx.backends._
import org.emergentorder.compiletime._
import io.kjaer.compiletime._
import org.emergentorder.io.kjaer.compiletime._
import org.emergentorder.onnx.onnxruntimeWeb.mod.{InferenceSession => OrtSession}
import cats.effect.IO

Expand Down
2 changes: 1 addition & 1 deletion backends/.jvm/src/main/scala/NCF.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import spire.math.Numeric
import scala.language.higherKinds
import scala.io.Source
import org.emergentorder.compiletime.*
import io.kjaer.compiletime.*
import org.emergentorder.io.kjaer.compiletime.*
import cats.effect.IO

//TODO: Add changes to generator; Generate both full model and layerwise programs each time
Expand Down
2 changes: 1 addition & 1 deletion backends/.jvm/src/main/scala/ORTModelBackend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.emergentorder.onnx.*
import org.emergentorder.onnx.Tensors.*
import org.emergentorder.onnx.Tensors.Tensor.*
import org.emergentorder.compiletime.*
import io.kjaer.compiletime.*
import org.emergentorder.io.kjaer.compiletime.*

import ORTTensorUtils.*

Expand Down
2 changes: 1 addition & 1 deletion backends/.jvm/src/main/scala/ORTOperatorBackend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.emergentorder.onnx.*
import org.emergentorder.onnx.Tensors.*
import org.emergentorder.onnx.Tensors.Tensor.*
import org.emergentorder.compiletime.*
import io.kjaer.compiletime.*
import org.emergentorder.io.kjaer.compiletime.*
import onnx.onnx.*

import cats.implicits.*
Expand Down
2 changes: 1 addition & 1 deletion backends/.jvm/src/test/scala/BertTokenizerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.emergentorder.onnx.Tensors.*
import org.emergentorder.onnx.Tensors.Tensor.*
import org.emergentorder.onnx.backends.*
import org.emergentorder.compiletime.*
import io.kjaer.compiletime.*
import org.emergentorder.io.kjaer.compiletime.*

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.freespec.AsyncFreeSpec
Expand Down
4 changes: 2 additions & 2 deletions backends/.jvm/src/test/scala/SqueezeNetTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.emergentorder.onnx.Tensors.*
import org.emergentorder.onnx.Tensors.Tensor.*
import org.emergentorder.onnx.backends.*
import org.emergentorder.compiletime.*
import io.kjaer.compiletime.*
import org.emergentorder.io.kjaer.compiletime.*

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.freespec.AsyncFreeSpec
Expand All @@ -23,7 +23,7 @@ class ONNXScalaSpec extends AsyncFreeSpec with AsyncIOSpec with Matchers {
) #> new File("squeezenet1.0-12.onnx") !!

"SqueezeNet ONNX-Scala model should predict dummy image class" in {
val squeezenetBytes = Files.readAllBytes(Paths.get("squeezenet1.0-12.onnx"))
val squeezenetBytes = Files.readAllBytes(Paths.get("squeezenet1.0-12.onnx")) //.quant.onnx"))
val squeezenet = new ORTModelBackend(squeezenetBytes)
val data = Array.fill(1 * 3 * 224 * 224) { 42f }
// In NCHW tensor image format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.emergentorder.onnx._
import org.emergentorder.onnx.Tensors._
import org.emergentorder.onnx.Tensors.Tensor._
import org.emergentorder.compiletime._
import io.kjaer.compiletime._
import org.emergentorder.io.kjaer.compiletime._

trait ORTNativeOperatorBackend {

Expand Down
3 changes: 3 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,14 @@ lazy val backends = (crossProject(JSPlatform, JVMPlatform, NativePlatform)
startWebpackDevServer / version := "4.11.1",
scalaJSUseMainModuleInitializer := true, // , //Testing
Compile / npmDependencies += "onnxruntime-web" -> "1.13.1",
//ORT web and node are interchangeable, given minor package name changes, and node offers a significant speed-up (at the cost of working on the web)
// Compile / npmDependencies += "onnxruntime-node" -> "1.13.1",
Compile / npmDependencies += "onnxruntime-common" -> "1.13.1",
Compile / npmDependencies += "typescript" -> "4.8.4",
libraryDependencies += "org.typelevel" %%% "cats-effect-testing-scalatest" % "1.5.0" % Test,
stOutputPackage := "org.emergentorder.onnx",
stShortModuleNames := true,
Compile /packageDoc / publishArtifact := false, //This is inordinately slow, only publish doc on release
scalaJSStage := FullOptStage,
scalaJSLinkerConfig ~= (_.withESFeatures(
_.withESVersion(org.scalajs.linker.interface.ESVersion.ES2021)
Expand Down
6 changes: 3 additions & 3 deletions common/src/main/scala/TensorShapeDenotation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ package org.emergentorder.compiletime

import scala.compiletime.ops.int.{S, +, <, <=, *}
import scala.compiletime.ops.boolean.&&
import io.kjaer.compiletime.Index
import io.kjaer.compiletime.Indices
import io.kjaer.compiletime.INil
import org.emergentorder.io.kjaer.compiletime.Index
import org.emergentorder.io.kjaer.compiletime.Indices
import org.emergentorder.io.kjaer.compiletime.INil

type DimensionDenotation = String & Singleton

Expand Down
4 changes: 2 additions & 2 deletions common/src/main/scala/io/kjaer/compiletime/Indices.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//Author: Maxime Kjaer, taken from tf-dotty
package io.kjaer.compiletime
package org.emergentorder.io.kjaer.compiletime

import scala.compiletime.ops.string.+
import scala.compiletime.ops.int
Expand All @@ -8,7 +8,7 @@ type Index = Int & Singleton

sealed trait Indices {
def :::[H <: Index, This >: this.type <: Indices](head: H): H ::: This =
io.kjaer.compiletime.:::(head, this)
org.emergentorder.io.kjaer.compiletime.:::(head, this)

def indices: Seq[Int] = this match {
case INil => Nil
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/scala/io/kjaer/compiletime/IndicesOf.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//Author: Maxime Kjaer, taken from tf-dotty
package io.kjaer.compiletime
package org.emergentorder.io.kjaer.compiletime

/** Type-class used to materialize the singleton type of an [[Indices]].
*
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/scala/io/kjaer/compiletime/Shape.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//Author: Maxime Kjaer, taken from tf-dotty
package io.kjaer.compiletime
package org.emergentorder.io.kjaer.compiletime

import scala.compiletime.ops.int.{S, +, <, <=, *}
import scala.compiletime.ops.boolean.&&
Expand All @@ -11,7 +11,7 @@ sealed trait Shape extends Product with Serializable {

/** Prepend the head to this */
def #:[H <: Dimension, This >: this.type <: Shape](head: H): H #: This =
io.kjaer.compiletime.#:(head, this)
org.emergentorder.io.kjaer.compiletime.#:(head, this)

/** Concat with another shape * */
def ++(that: Shape): this.type `Concat` that.type = Shape.concat(this, that)
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/scala/io/kjaer/compiletime/ShapeOf.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//Author: Maxime Kjaer, taken from tf-dotty
package io.kjaer.compiletime
package org.emergentorder.io.kjaer.compiletime

/** Type-class used to materialize the singleton type of a [[Shape]].
*
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/scala/io/kjaer/compiletime/dependent.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//Author: Maxime Kjaer, taken from tf-dotty
package io.kjaer.compiletime
package org.emergentorder.io.kjaer.compiletime

import scala.compiletime.ops.int.*

Expand Down
3 changes: 3 additions & 0 deletions core/src/main/scala/ONNX.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,9 @@ package object onnx {
}
}

//TODO: move "axes" from attributes to inputs on the rest of the Reduce ops,
//as done below with ReduceSum (when updating to opset 18)
//
// TODO: new attr : noop_with_empty_axes
trait ReduceSumV13 extends Operator {
def ReduceSumV13[
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/ONNXBytesDataSource.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import spire.math.Numeric
import org.emergentorder.onnx.*
import org.emergentorder.onnx.Tensors.*
import org.emergentorder.compiletime.*
import io.kjaer.compiletime.*
import org.emergentorder.io.kjaer.compiletime.*

class ONNXBytesDataSource(onnxBytes: Array[Byte]) extends DataSource {

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/OpToONNXBytesConverter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import onnx.onnx.TensorProto.DataType.*

import cats.effect.IO
import cats.implicits.*
import io.kjaer.compiletime.Shape
import org.emergentorder.io.kjaer.compiletime.Shape
import org.emergentorder.compiletime.*
import org.emergentorder.onnx.Tensors.*
import org.emergentorder.onnx.Tensors.Tensor.*
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/Tensors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import spire.math.UInt
import spire.math.ULong
import spire.math.Complex
import spire.math.Numeric
import io.kjaer.compiletime.*
import io.kjaer.compiletime.Shape.*
import org.emergentorder.io.kjaer.compiletime.*
import org.emergentorder.io.kjaer.compiletime.Shape.*
import scala.compiletime.ops.int.*

import cats.effect.IO
Expand Down
2 changes: 2 additions & 0 deletions get_models.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
curl -O "https://media.githubusercontent.com/media/onnx/models/main/vision/classification/squeezenet/model/squeezenet1.0-12.onnx"
curl -o absnet.onnx "https://raw.githubusercontent.com/onnx/onnx/master/onnx/backend/test/data/node/test_abs/model.onnx"

#TODO: add bert tokenizer here
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
addDependencyTreePlugin
addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % "2.1.0")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.2.0")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.2.0")
Expand Down

0 comments on commit 4a24d1d

Please sign in to comment.