Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Make derivatives of public functions be @usableFromInline. #929

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/TensorFlow/Core/MixedPrecision.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,13 @@ extension Tensor {
#endif

extension Tensor where Scalar: TensorFlowFloatingPoint {
@usableFromInline
@derivative(of: toReducedPrecision)
func _vjpToReducedPrecision() -> (value: Tensor, pullback: (Tensor) -> Tensor) {
(toReducedPrecision, { $0.toFullPrecision })
}

@usableFromInline
@derivative(of: toFullPrecision)
func _vjpToFullPrecision() -> (value: Tensor, pullback: (Tensor) -> Tensor) {
(toFullPrecision, { $0.toReducedPrecision })
Expand Down
2 changes: 1 addition & 1 deletion Sources/TensorFlow/Layer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ extension Layer {

// TODO(TF-433, SR-11882): Remove this custom derivative when
// differentiation supports `rethrows` functions and currying.
@derivative(of: inferring(from:))
@usableFromInline
@derivative(of: inferring(from:))
internal func _vjpInferring(from input: Input)
-> (
value: Output,
Expand Down
2 changes: 2 additions & 0 deletions Sources/TensorFlow/Operators/NN.swift
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ public func depthToSpace<Scalar>(_ input: Tensor<Scalar>, blockSize b: Int) -> T
return _Raw.depthToSpace(input, blockSize: Int64(b))
}

@usableFromInline
@derivative(of: depthToSpace)
func _vjpDepthToSpace<Scalar: TensorFlowFloatingPoint>(
_ input: Tensor<Scalar>,
Expand Down Expand Up @@ -1048,6 +1049,7 @@ public func spaceToDepth<Scalar>(_ input: Tensor<Scalar>, blockSize b: Int) -> T
return _Raw.spaceToDepth(input, blockSize: Int64(b))
}

@usableFromInline
@derivative(of: spaceToDepth)
func _vjpSpaceToDepth<Scalar: TensorFlowFloatingPoint>(
_ input: Tensor<Scalar>,
Expand Down