Skip to content

Allocate gradients only during training #3

Description

@michalharakal
fun expression():Value {
  val a = Value(-4.0)
  val b = Value(2.0)
  var c = a + b
  var d = a * b + b.pow(3.0)
  c += c + 1
  c += 1.0 + c + (-a)
  d += d * 2 + (b + a).relu()
  d += d * 3.0 + (b - a).relu()
  val e = c - d
  val f = e.pow(2.0)
  var g = f / 2
  g += 10.0 / f
  return g 
}

fun calc() {
   val start = getFreeMemory()
    expression()
    val end = getFreeMemory()
    return end - start
}

fun calcBack() {
   val start = getFreeMemory()
    val resul = expression()
     val result..backward()
    val end = getFreeMemory()
    return end - start
}

fun main() {
 assert ( calcBack()/ calc() == 2)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions