Skip to content

[AutoDiff] Reproducer for BatchNorm compiler crasher #41437

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

Closed
wants to merge 681 commits into from

Conversation

philipturner
Copy link
Contributor

@philipturner philipturner commented Feb 17, 2022

Reports SR-15849.

import _Differentiation

// Declare `Tensor`

class TensorHandle {} // Crash requires `class` and not `struct`

struct Tensor<Scalar> {
  let handle: TensorHandle
}

extension Tensor: Differentiable {
  typealias TangentVector = Tensor
}

extension Tensor: AdditiveArithmetic  {
  static func == (lhs: Tensor, rhs: Tensor) -> Bool { fatalError() }
  static func != (lhs: Tensor, rhs: Tensor) -> Bool { fatalError() }

  static var zero: Tensor { fatalError() }

  @differentiable(reverse)
  static func + (lhs: Tensor, rhs: Tensor) -> Tensor { fatalError() }
  static func - (lhs: Tensor, rhs: Tensor) -> Tensor { fatalError() }
}

// Make `+=` differentiable

extension Tensor {
  @derivative(of: +)
  static func _vjpAdd(lhs: Tensor, rhs: Tensor) -> (
    value: Tensor, pullback: (Tensor) -> (Tensor, Tensor)
  ) {
    fatalError()
  }

  static func += (lhs: inout Tensor, rhs: Tensor) {
    lhs = lhs + rhs
  }
}

// Declare `BatchNorm`

protocol Layer: Differentiable {
  associatedtype Input
  associatedtype Output: Differentiable

  @differentiable(reverse)
  func callAsFunction(_ input: Input) -> Output
}

struct BatchNorm<Scalar>: Layer { // Crash requires conformance to `Layer`
  @noDerivative let momentum: Scalar // Crash requires `@noDerivative`
  var offset: Tensor<Scalar>

  @differentiable(reverse)
  func callAsFunction(_ input: Tensor<Scalar>) -> Tensor<Scalar> {
    var offset = self.offset
    if true { // Crash requires `if true`
      offset += offset // Using `offset = offset + offset` stops the crash
    }
    return offset
  }
}

etcwilde and others added 29 commits February 28, 2022 08:20
…main-resolution

Revert async-main lookup resolution
…-failure

[cxx interop] Fix issue where const overloaded disambiguated methods were not in the lookup table
When emitting a symbol graph file for a module that import modules via
`@_exported import`, emits those modules' symbols as well.

SR-15753

rdar://89547374
…ng-to-solver

[ConstraintSystem] Add support for expression patterns
[Linux] Re-enable Driver/static-stdlib-autolink-linux.swift
…n-opt-for-foreign-convention

SILGen: Add missing processing to reabstraction fast-path.
Clang has a new `redirecting-with` property in the VFS overlay files.
While this could be added to Swift's features as well, it is generally
the case that features provided by Clang can also be useful to know for
clients of Swift. Merge the features from Clang into Swift's features
file with the "clang-" prefix to differentiate them.
We now schedule conformance emissions in basically the same way
we do for types and declarations, which means that we'll emit them
uniquely in the module file instead of redundantly at every use.
This should produce substantially smaller module files overall,
especially for modules that heavily use generics.  It also means
that we can remove all the unfortunate code to support using
different abbrev codes for them in different bitcode blocks.

Requirement lists are now emitted inline in the records that need
them instead of as trailing records.  I think this will improve
space usage, but mostly it assists in eliminating the problem
where abbrev codes are shared between blocks.
…xDistance

[stdlib] Mark String.IndexDistance as deprecated and stop mentioning it in method signatures
…ngeCheck

[stdlib] Collection: simplify default _failEarlyRangeCheck implementations
…ions-is-hard

|| has higher precedence than the ternary operator
…achine invariants

We can't feed resolved DependentMemberTypes into the Requirement Machine
since that will trigger an assertion if there is a missing conformance.

Instead, copy and paste some logic from GenericSignatureBuilder.cpp to
'erase' resolved DependentMemberTypes into unresolved DependentMemberTypes.
…arations must:

- have public visibility
- have at most one back deployment version per-platform
- specify an introduced version for each platform with a back deployment version using @available
- have a back deployment version that is greater than the introduced version
- not have conflicting attributes like @_alwaysEmitIntoClient

Refactor to share code with type checking for @_originallyDefinedIn which has overlapping diagnostics.
…seInvalidFunctionType()

Fixes rdar://problem/89583624.
…gnoseclosure

[SwiftCompiler] Fix DiagnosticEngine.diagnose()
- The test did not properly test the intent of the change from 82fa4b0
…call to `~=` operator

Augment the constraint solver to fallback to implicit `~=` application
when member couldn't be found for `EnumElement` patterns because
`case` statement should be able to match enum member directly, as well
as through an implicit `~=` operator application.
`String.index(before:)` (and methods that rely on it, such as `Substring.index(before:)`, `.distance(from:to:)` etc.) does not currently verify that the given index falls before the `endIndex` before aligning it to a scalar boundary. This allows an out-of-bounds memory access when the provided index points to a position beyond the end of `self`’s storage.

Additionally, the `i > startIndex` check needs to be done after scalar alignment, not before, as alignment can round the index down to `startIndex`.

rdar://89497074&89495373
nkcsgexi and others added 24 commits March 6, 2022 12:40
Explicitly invoke the script executor rather than the script as running a script is meaningless.  Shebangs are not a portable manner of indicating the script executor and worse yet do not guarantee portability on such systems either.  Ideally the shebang line would be removed from the script.

Thanks to @pcbeard for reporting the issue!
Concurrency: clean up a log message (NFC)
[OSLog] Remove the dependency on `_Concurrency`
Create a benchmark to test the
performance of synthesized read
accessors generated to interop
with C++ [] operators.
Windows ARM64 is a LLP64 platform, which means that `unsigned long` is a
32-bit value.  This was already mapped properly for x86_64, but somehow
had missed ARM64.  This repairs that which is required for building the
standard library.
…rdar88728047

[SourceKit] Report comment tags in 'indexsource' request
…y-fix

[OSLog] Conditionally remove the dependency on `_Concurrency`
…it x86 macOS

It sometimes fails in different configurations which are not very important for this
test, so let's restrict it to a 64-bit x86 macOS which is covered by a smoke test.

Resolves: rdar://89908188
The legacy driver doesn't fully support cross module incremental builds.
Some of these tests were disabled, but in general they have been
mirrored to the swift-driver test suite. https://github.com/apple/swift-driver/tree/f6fde8c30a0a01bfbf83fe4e0f2d7994a0c0ac32/Tests/IncrementalImportTests
…ction_88709422

Add missing word & slightly clarify.
Clean up the submodules in visualc to not export all imported modules.
The one special case is `vcruntime` which re-exports `SAL` due to a
dependency in the headers.  The import of `visualc` however will
re-export all submodules to keep the current behaviour.  This is
required to get the ARM64 SDK building on newer MSVC toolsets.
Add a comment about lexical lifetimes to CompilerInvocation.
…s-module-incremental-tests

Delete cross module incremental tests
[TypeChecker] NFC: Restrict type inference from defaults test to 64-b…
…armv5-trunk

[stdlib] Added Armv5 support
…ppc32

[stdlib] Added PowerPC 32-bit support
NFC: Fix a number of warnings emitted when building swift-frontend
@philipturner
Copy link
Contributor Author

Likely fixed by #41294

@philipturner
Copy link
Contributor Author

My bad. I messed up a rebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.