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

[Draft] Github CI, DSL Builder, Seperate logging factory #251

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
57f0ffe
update gradle version
smallshen Oct 2, 2021
3c0b3ca
general fix and dependency version update
smallshen Oct 2, 2021
87d36b5
use implementation, gradle will help us to management
smallshen Oct 2, 2021
6073457
use implementation, gradle will help us to management
smallshen Oct 2, 2021
69c6305
github workflows ci
smallshen Oct 2, 2021
6fd9597
should use upload instead of download
smallshen Oct 2, 2021
bfcf3db
correct names
smallshen Oct 2, 2021
baffecf
Kotlin Dsl Builder for models
smallshen Oct 2, 2021
fa88f5f
Added gradle wrapper validation
V3lop5 Oct 7, 2021
2e65514
Merge pull request #1 from V3lop5/master
smallshen Oct 7, 2021
a65968b
add use for dsl
smallshen Oct 21, 2021
d50a92d
add annotation for dsl marker, idea will highlight
smallshen Oct 21, 2021
f8c51e3
rewrite in dsl
smallshen Oct 21, 2021
16ecc04
update gradle versions
smallshen Dec 2, 2021
8ce61dc
Merge branch 'master' into master
smallshen Dec 2, 2021
8ff91c1
Merge branch 'dsl-builder'
smallshen Dec 15, 2021
f68a285
Merge remote-tracking branch 'upstream/master'
smallshen Dec 15, 2021
54ce08f
add Logger factory, adapt all kind of log framework
smallshen Dec 15, 2021
bbc8273
add log4j support
smallshen Dec 15, 2021
2fcb82a
change description
smallshen Dec 15, 2021
85edc5e
change name
smallshen Dec 15, 2021
50e25a9
remove unused variable
smallshen Dec 15, 2021
71351ca
Upgraded log4j version to 2.16.0
smallshen Dec 15, 2021
2164e7c
Clean up
smallshen Dec 15, 2021
10c8bc8
Merge branch 'master' into master
smallshen Dec 16, 2021
73128a3
More documentation
smallshen Dec 16, 2021
5502fa6
Merge remote-tracking branch 'origin/master'
smallshen Dec 16, 2021
82fc597
Example usage of setup
smallshen Dec 16, 2021
ae9321e
Add jupyter compatible (simple) logger
smallshen Dec 16, 2021
2c05fe8
Merge remote-tracking branch 'upstream/master'
smallshen Dec 21, 2021
34ae338
replace logger
smallshen Dec 21, 2021
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
60 changes: 60 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Build

on: [ push, pull_request ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Set up JDK(16)
uses: actions/setup-java@v1
with:
java-version: 16

- name: CheckOut
uses: actions/checkout@v2

- name: Gradle wrapper validation
uses: gradle/wrapper-validation-action@v1


- name: Gradle cache
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-


- name: Gradle Build
# Test takes too long on ci with github, maybe manually trigger with teamcity?
run: ./gradlew build -x test


- name: 'Upload API artifacts'
uses: actions/upload-artifact@v2
with:
name: 'API Jars'
path: api/build/libs/*.jar

- name: 'Upload DataSet artifacts'
uses: actions/upload-artifact@v2
with:
name: 'DataSet Jars'
path: dataset/build/libs/*.jar

- name: 'Upload Example artifacts'
uses: actions/upload-artifact@v2
with:
name: 'Example Jars'
path: examples/build/libs/*.jar

- name: 'Upload ONNX artifacts'
uses: actions/upload-artifact@v2
with:
name: 'ONNX Jars'
path: onnx/build/libs/*.jar
8 changes: 6 additions & 2 deletions api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
project.setDescription("This module contains the Kotlin API for building, training, and evaluating the Deep Learning models.")

dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10'


api project(":dataset")
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0'
api group: 'org.tensorflow', name: 'tensorflow', version: '1.15.0'
api 'com.github.doyaaaaaken:kotlin-csv-jvm:0.7.3' // for csv parsing
api 'io.github.microutils:kotlin-logging:2.0.4' // for logging
api 'io.jhdf:jhdf:0.5.7' // for hdf5 parsing
api 'com.beust:klaxon:5.5'
api project(":logging:logging-api")


testImplementation 'ch.qos.logback:logback-classic:1.2.7'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.jetbrains.kotlinx.dl.api.core
import org.jetbrains.kotlinx.dl.api.core.layer.Layer
import org.jetbrains.kotlinx.dl.api.core.layer.core.Input
import org.jetbrains.kotlinx.dl.api.inference.keras.*
import org.jetbrains.kotlinx.dl.logging.api.debug
import org.tensorflow.Operand
import java.io.File
import java.io.FileNotFoundException
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.jetbrains.kotlinx.dl.api.inference.keras.deserializeSequentialModel
import org.jetbrains.kotlinx.dl.api.inference.keras.loadSequentialModelLayers
import org.jetbrains.kotlinx.dl.api.inference.keras.loadSerializedModel
import org.jetbrains.kotlinx.dl.api.inference.keras.serializeModel
import org.jetbrains.kotlinx.dl.logging.api.debug
import org.tensorflow.Operand
import org.tensorflow.Shape
import java.io.File
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package org.jetbrains.kotlinx.dl.api.core.callback

import org.jetbrains.kotlinx.dl.api.core.history.EpochTrainingEvent
import org.jetbrains.kotlinx.dl.api.core.history.TrainingHistory
import org.jetbrains.kotlinx.dl.logging.api.info
import org.jetbrains.kotlinx.dl.logging.api.warn
import java.util.function.BiFunction
import kotlin.reflect.KProperty1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package org.jetbrains.kotlinx.dl.api.core.callback

import org.jetbrains.kotlinx.dl.api.core.history.BatchTrainingEvent
import org.jetbrains.kotlinx.dl.api.core.history.TrainingHistory
import org.jetbrains.kotlinx.dl.logging.api.info

/**
* This callback is used to stop the training if loss is not a number (NaN or INFINITY).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package org.jetbrains.kotlinx.dl.api.core.callback

import org.jetbrains.kotlinx.dl.api.core.history.EpochTrainingEvent
import org.jetbrains.kotlinx.dl.api.core.history.TrainingHistory
import org.jetbrains.kotlinx.dl.logging.api.info

/**
* Callback for stopping training of a model when a specified amount of time has passed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public fun batchDot(scope: Scope?, x: Operand<Float>, y: Operand<Float>, axis: I
val xDim = x.asOutput().shape().numDimensions()
val yDim = y.asOutput().shape().numDimensions()
val diff: Int
var x2: Operand<Float> = x;
var x2: Operand<Float> = x
var y2: Operand<Float> = y
if (xDim > yDim) {
diff = xDim - yDim
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package org.jetbrains.kotlinx.dl.api.core.summary

import mu.KLogging

import org.jetbrains.kotlinx.dl.api.core.TrainableModel
import org.slf4j.Logger
import org.jetbrains.kotlinx.dl.logging.api.GlobalLogFactory
import org.jetbrains.kotlinx.dl.logging.api.Logger
import java.io.PrintStream

private data class SummaryRow(
val layerName: String,
val outputShape: String,
val paramsCount: String,
val inboundLayers: List<String>
val inboundLayers: List<String>,
)

/**
Expand All @@ -33,7 +34,7 @@ public fun ModelSummary.format(
columnSeparator: String = " ",
lineSeparator: Char = '_',
thickLineSeparator: Char = '=',
withConnectionsColumn: Boolean = layersSummaries.any { it.inboundLayers.size > 1 }
withConnectionsColumn: Boolean = layersSummaries.any { it.inboundLayers.size > 1 },
): List<String> {
// Prepare string data for resulting table
val table = layersSummaries.map { layer ->
Expand Down Expand Up @@ -121,7 +122,9 @@ public fun ModelSummary.print(out: PrintStream = System.out): Unit =
public fun TrainableModel.printSummary(out: PrintStream = System.out): Unit =
summary().print(out)

private object ModelSummaryLogger : KLogging()
private object ModelSummaryLogger {
val logger = GlobalLogFactory.newLogger(ModelSummaryLogger::class.java)
}

/**
* Formats and log model summary to logger
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.jetbrains.kotlinx.dl.api.extension.dsl

import org.jetbrains.kotlinx.dl.api.core.Functional
import org.jetbrains.kotlinx.dl.api.core.GraphTrainableModel
import org.jetbrains.kotlinx.dl.api.core.Sequential
import org.jetbrains.kotlinx.dl.api.core.layer.Layer

@DslMarker
@Retention(AnnotationRetention.SOURCE)
internal annotation class BuilderDsl

@DslMarker
@Retention(AnnotationRetention.SOURCE)
internal annotation class EntryDsl

public class GraphTrainableModelDsl<T : GraphTrainableModel>(private val initializer: (Array<Layer>) -> T) {

private var handler: T.() -> Unit = {}
private var layerProvider: LayerBuilder.() -> Unit = {}
private var use: ((T) -> Unit)? = null

@BuilderDsl
public fun model(builder: T.() -> Unit) {
this.handler = builder
}

@BuilderDsl
public fun layers(builder: LayerBuilder.() -> Unit) {
this.layerProvider = builder
}

@BuilderDsl
public fun use(builder: T.() -> Unit) {
use = builder
}

public fun build(): T = initializer.invoke(LayerBuilder().apply(layerProvider).toArray()).apply(handler).apply {
use?.let { use(it) }
}
}

@JvmInline
public value class LayerBuilder(private val list: MutableList<Layer> = mutableListOf()) {

public operator fun Layer.unaryPlus(): Layer {
list.add(this)
return this
}

public fun toArray(): Array<Layer> = list.toTypedArray()

public inline operator fun <T : Layer> T.invoke(builder: T.() -> Unit) {
this.apply(builder)
}
}


@EntryDsl
public fun sequential(builder: GraphTrainableModelDsl<Sequential>.() -> Unit): Sequential {
return GraphTrainableModelDsl(Sequential.Companion::of).apply(builder).build()
}

@EntryDsl
public fun functional(builder: GraphTrainableModelDsl<Functional>.() -> Unit): Functional {
return GraphTrainableModelDsl(Functional.Companion::of).apply(builder).build()
}

@EntryDsl
public operator fun <T : GraphTrainableModel> ((Array<Layer>) -> T).invoke(builder: GraphTrainableModelDsl<T>.() -> Unit): T {
return GraphTrainableModelDsl(this).apply(builder).build()
}
Loading