Hello everyone!
It's been a while since our last update!
There's quite a lot to talk about. Over the last period we’ve been working on improving stability and performance, as well as adding support for more language features and platforms! For more details keep reading!
We now also have our own spot on the forums in the Differentiable Swift category. Please feel free to ask any questions there! Differentiable Swift - Swift Forums
New features as of Swift 6.3
We're very excited about the following features we've enabled for Swift 6.3
@_alwaysEmitIntoClient
This feature was mentioned in the last update. We can now define derivatives for functions marked with @_alwaysEmitIntoClient thanks to the work by @kovdan01 in:
- [AutoDiff] Support custom derivatives for @_alwaysEmitIntoClient functions by kovdan01 · Pull Request #78908 · swiftlang/swift · GitHub
- [AutoDiff] Define derivative for concrete SIMD.init(repeating:) by kovdan01 · Pull Request #81864 · swiftlang/swift · GitHub
Throwing functions
We can now define derivatives for functions that throw! (Either typed or untyped throws)
- Ensure we check for thrown error types when resolving custom derivatives by asl · Pull Request #86999 · swiftlang/swift · GitHub
- [AutoDiff] Add throwing versions of differential operators by asl · Pull Request #86393 · swiftlang/swift · GitHub
- [AutoDiff] Initial support for differentiation of throwing functions by asl · Pull Request #82653 · swiftlang/swift · GitHub
Wasm support
Thanks to help from Max Desiatov, Differentiable Swift is now available for Wasm as well!
- wasmstdlib.py: add SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING by MaxDesiatov · Pull Request #86552 · swiftlang/swift · GitHub
- [6.3] wasmstdlib.py: add SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING by MaxDesiatov · Pull Request #86656 · swiftlang/swift · GitHub
- wasmstdlib.py: add 'AutoDiff' to lit test paths by MaxDesiatov · Pull Request #86657 · swiftlang/swift · GitHub
- Fix two Wasm test harness issues and re-enable more autodiff tests by asl · Pull Request #86931 · swiftlang/swift · GitHub
performance improvements
- Improve differentiableMap vjp performance by JaapWijnen · Pull Request #83807 · swiftlang/swift · GitHub
- DRAFT: improve differentiable array.move performance by JaapWijnen · Pull Request #86320 · swiftlang/swift · GitHub
bugfixes
- Ensure we are adding T : Differentiable conformance from protocol conditional conformance by asl · Pull Request #77446 · swiftlang/swift · GitHub compiler crash
- Fix two issues related with emission of differentiability witnesses by asl · Pull Request #80983 · swiftlang/swift · GitHub compiler crash
- Correctly handle multiple semantic results for autodiff subset differential thunks by asl · Pull Request #84366 · swiftlang/swift · GitHub compiler crash
- [AutoDiff] Correct propagate adjoints for array literal values by asl · Pull Request #81676 · swiftlang/swift · GitHub compiler crash
- fix: make sure rhs is negated in all cases when subtracting two Array.TangentVectors by JaapWijnen · Pull Request #84731 · swiftlang/swift · GitHub correctness fix
- [AutoDiff] Use `LinkEntity::SecondaryPointer` for diff witness by kovdan01 · Pull Request #82412 · swiftlang/swift · GitHub correctness fix
- Run closure specialization only if ownership info is present in callee by kovdan01 · Pull Request #84956 · swiftlang/swift · GitHub compiler crash
- [AutoDiff][test] Enable some previously XFAIL'ed tests by kovdan01 · Pull Request #84915 · swiftlang/swift · GitHub reenable tests
Ongoing toolchain work
Differentiation for new accessors (read/modify)
This was also mentioned in the future work section of our previous update. We are still working towards completing this feature Check / implement automatic differentiation for new kinds of accessors · Issue #86405 · swiftlang/swift · GitHub
The latest progress/PR can be found here Add AST representation for coroutines by asl · Pull Request #85372 · swiftlang/swift · GitHub
Variadic differential operators
Currently we can only call valueWithPullback with 1 to 3 parameters. We can get around this by packing inputs together into structs but this is not always ideal.
We're working towards parameter pack based differential operators to enable using more parameters and reduce duplication. The relevant issue
Protocol default derivatives
We're working on being able to register default derivatives for protocols. This will allow us to add a lot more derivatives for standard library functions.
Differentiable curry
As described in the original issue: [SR-11882] [AutoDiff] Implement the differentiable curry · Issue #54297 · swiftlang/swift · GitHub
This enables currying differentiable functions without losing differentiability with respect to any function parameter. For more info check here and/or here
This will allow us to support @autoclosure but also differentiating w.r.t. captured values in closures.
[AutoDiff] Initial support for differentiable curry by kovdan01 · Pull Request #87004 · swiftlang/swift · GitHub
Differentiable closure specialization
We're working on a performance pass specifically aimed at closures produced by autodiff. The previously finished and ongoing work can be seen here:
- [AutoDiff] Implement the closure optimization that is specialized towards the linear map tuples / enums produced by autodiff. · Issue #68944 · swiftlang/swift · GitHub
- [AutoDiff] Closure specialization: specialize branch tracing enums by kovdan01 · Pull Request #85757 · swiftlang/swift · GitHub
- Bridging: Implement several optional- and enum-related bridges by kovdan01 · Pull Request #85756 · swiftlang/swift · GitHub
- Bridging: Implement bridges required for ongoing AutoDiff changes by kovdan01 · Pull Request #84648 · swiftlang/swift · GitHub
- [AutoDiff] Run AutoDiff closure spec pass for all VJPs by kovdan01 · Pull Request #81548 · swiftlang/swift · GitHub
Library updates
New library features
We've spent quite some time on unifying and improving working with Collections using differentiable Swift. The following is available in swift-differentiation as of today. But this is very much work in progress and more is planned to follow!
swift-differentiation (GitHub - differentiable-swift/swift-differentiation · GitHub)
- Differentiable conformance for
InlineArray - Differentiable conformance for
ContiguousArray - Differentiable conformance for
Repeated - Differentiable conformance for
ArraySlice - Added
differentiableZip - Added `runWithoutDerivative
Ongoing library work
With the added support for throwing functions in 6.3 we'll be implementing a few derivatives commonly used functions that throw. We're also continuing our work to improve the user experience of working with collections in differentiable code.
swift-differentiation (GitHub - differentiable-swift/swift-differentiation · GitHub)
- add throwing
differentiableMap - add throwing
differentiableReduce differentiableZipperformance improvements- more differentiable collection operators like
gather,permute,scatter
Thanks
A lot of thanks go out to the following people since our last update.
- @asl
- Daniil Kovalev (kovdan01)
- Maurits Kelder
- @Max_Desiatov
- @clackary
- @tmcdonell
- @_ck512
- @Dmitri