You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe I stumbled upon a bug in the Array.DifferentiableView. The code chunk below causes a precondition fail during the backward pass.
Here's my "amateur astronomer" observations about why the precondition fails. Calculation involving lastFlat1 is inactive, i.e. it isn't used to produce the sum, but it is nevertheless stored in the `Flatter` struct during execution the `flatten(...)` call. When the backward pass runs, the Flatter.TangentVector.lastFlat1 is empty which triggers the failure.
I tried investigating the ArrayDifferentiation.swift file but, I don't have enough experience with the standard library to fix it.
The reproducer looks strangely useless because its taken from a more complex application that has an alternative lost function which uses both lastFlat0 and lastFlat1. But I believe this kind of behavior, where only a subset of differentiable attributes contribute to the cost function, will be common in bigger projects.
This is the exact runtime error produced when running:
_Differentiation/ArrayDifferentiation.swift:220: Precondition failed: Tangent vector with invalid count; expected to equal the sum of operand counts 2 and 2
2021-03-03 08:44:18.789757-0600 DifferentiableReduceTest[63658:1907302] _Differentiation/ArrayDifferentiation.swift:220: Precondition failed: Tangent vector with invalid count; expected to equal the sum of operand counts 2 and 2
The text was updated successfully, but these errors were encountered:
@vojtamolda Perhaps the tangent vector was a zero? In that case you just need to detect the zero case `base.isEmpty` in the stdlib code. I'm sorry but I don't have the bandwidth to look into it this week, but would be happy to answer your questions if you'd like to take a stab.
Thanks for all the answers. It's nice that all 3 of us agree that the value passed to the vjp pullback closure is an empty array. I wasn't sure if this was the correct and expected behavior.
I've got a question to make sure that my understanding is correct here. Passing empty arrays to vjp closures is a performance optimization? It avoids frequent creation of arrays full of zeros that are in the end added to something else and don't have a chance of affecting the result?
I'll try to submit a PR with a fix to the standard library with some tests. Please, keep your fingers crossed for me 😉 It's going to be a wild ride since I've never done that before!
Yes, the compiler always calls `.zero` to initialize a zero. It is not guaranteed to have the same shape as the corresponding original value. The custom derivatives should be checking for `.zero` values.
Environment
macOS 11.2.2 with Swift development snapshot 2021-02-24:
Additional Detail from JIRA
md5: a2e01f966545d298724b1a0508fa6c26
Issue Description:
Hello everyone,
I believe I stumbled upon a bug in the
Array.DifferentiableView
. The code chunk below causes a precondition fail during the backward pass.Here's my "amateur astronomer" observations about why the precondition fails. Calculation involving
lastFlat1
is inactive, i.e. it isn't used to produce the sum, but it is nevertheless stored in the `Flatter` struct during execution the `flatten(...)` call. When the backward pass runs, theFlatter.TangentVector.lastFlat1
is empty which triggers the failure.I tried investigating the
ArrayDifferentiation.swift
file but, I don't have enough experience with the standard library to fix it.The reproducer looks strangely useless because its taken from a more complex application that has an alternative lost function which uses both
lastFlat0
andlastFlat1
. But I believe this kind of behavior, where only a subset of differentiable attributes contribute to the cost function, will be common in bigger projects.This is the exact runtime error produced when running:
The text was updated successfully, but these errors were encountered: