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

[SR-15891] [AutoDiff] Assertion failed with curried loop #58152

Closed
asl opened this issue Feb 21, 2022 · 2 comments
Closed

[SR-15891] [AutoDiff] Assertion failed with curried loop #58152

asl opened this issue Feb 21, 2022 · 2 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@asl
Copy link
Collaborator

asl commented Feb 21, 2022

Previous ID SR-15891
Radar None
Original Reporter @asl
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee @asl
Priority Medium

md5: 717a550c91a9b4d88b9a1b4a014b8a4a

Issue Description:

After fixing SR-15205 the following code triggers an assertion:

import _Differentiation

struct Foo {
  var bar : Float
  var baz : Float
  var name : String?
}

func outerFunc(doIterations : Int, value: inout Float) -> (Float, (Float) -> Float) {  
  @differentiable(reverse, wrt: param)
  func innerFunc1(param: Float, other: Foo) -> Float {
    value += param * other.bar
    return value * param * 2.0
  }
  
  @differentiable(reverse, wrt: param)
  func innerFunc2(param: Float, other: Foo) -> Float {
    value += param * other.baz
    return value * param * 3.0
  }

  @differentiable(reverse, wrt: (param1, param2))
  func loop(param1 : Float, param2: Float, other1: Foo, other2: Foo) -> Float {
    var res : Float;
    res = 0.0
    for _ in 0 ..< doIterations {
      res += innerFunc1(param: param1, other: other1)
      res += innerFunc2(param: param2, other: other2)
    }

    return res
  }
  
  @differentiable(reverse)
  func curriedFunc(param: Float) -> Float {
    let other = Foo(bar: 7, baz: 9)
    return loop(param1: param, param2: param, other1: other, other2: other)
  }
  
  let valAndPullback = valueWithPullback(at: value, of: curriedFunc)
  return (value + valAndPullback.value, valAndPullback.pullback)
}

Assertion is:

Assertion failed: (srcAddr->getType() == destAddr->getType()), function createCopyAddr, file SILBuilder.h, line 1022.
Stack dump:
0.  Program arguments: ./swift-frontend -frontend 3.swift -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -color-diagnostics -new-driver-path /Users/asl/Projects/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/bin/swift-driver -resource-dir /Users/asl/Projects/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/lib/swift -module-name main -target-sdk-version 12.1 -interpret
1.  Swift version 5.7-dev (LLVM fb1cb9b18897f6d, Swift 30d318a697a5b43)
2.  Compiling with the current language version
3.  While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for main)
4.  While running pass #&#8203;88 SILModuleTransform "Differentiation".
5.  While canonicalizing `differentiable_function` SIL node   %21 = differentiable_function [parameters 0 1 5] [results 0 1] %20 : $@convention(thin) (Float, Float, @guaranteed Foo, @guaranteed Foo, Int, @inout_aliasable Float) -> Float // user: %22
6.  While ...in SIL function "@$s4main9outerFunc12doIterations5valueSf_S2fctSi_SfztF07curriedC0L_5paramS2f_tFTJrSUUpSr".
 for 'curriedFunc(param:)' (at 3.swift:35:3)
7.  While processing // differentiability witness for loop #&#8203;1 (param1:param2:other1:other2:) in outerFunc(doIterations:value:)
sil_differentiability_witness private [reverse] [parameters 0 1 5] [results 0 1] @$s4main9outerFunc12doIterations5valueSf_S2fctSi_SfztF4loopL_6param16param26other16other2S2f_SfAA3FooVAKtF : $@convention(thin) (Float, Float, @guaranteed Foo, @guaranteed Foo, Int, @inout_aliasable Float) -> Float {
}

 on SIL function "@$s4main9outerFunc12doIterations5valueSf_S2fctSi_SfztF4loopL_6param16param26other16other2S2f_SfAA3FooVAKtF".
 for 'loop(param1:param2:other1:other2:)' (at 3.swift:23:3)
8.  While generating VJP for SIL function "@$s4main9outerFunc12doIterations5valueSf_S2fctSi_SfztF4loopL_6param16param26other16other2S2f_SfAA3FooVAKtF".
 for 'loop(param1:param2:other1:other2:)' (at 3.swift:23:3)
9.  While generating pullback for SIL function "@$s4main9outerFunc12doIterations5valueSf_S2fctSi_SfztF4loopL_6param16param26other16other2S2f_SfAA3FooVAKtF".
 for 'loop(param1:param2:other1:other2:)' (at 3.swift:23:3)
@asl
Copy link
Collaborator Author

asl commented Feb 21, 2022

Tagging @BradLarson @rxwei

@asl
Copy link
Collaborator Author

asl commented Mar 3, 2022

Fixed by #41559

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

No branches or pull requests

1 participant