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
[AutoDiff] Temporarily disable non-varied result warning. (#26928)
Previously, a warning and fixit was generated for differentiable functions
with non-varied results.
```
tf-775.swift:3:3: warning: result does not depend on differentiation
arguments and will always have a zero derivative; do you want to use
'withoutDerivative(at:)'?
.zero
^
withoutDerivative(at: )
```
However, TF-775 exposes that the fixit does not work and the warning is
unsilenceable.
This patch temporarily disables the warning, as a robust fix requires
non-trivial activity analysis changes. A lack of warning is better
than an unsilenceable false positive.
TF-788 tracks re-enabling the warning.
Add regression test to ensure that unsilenceable warnings will not
happen again.
Copy file name to clipboardExpand all lines: test/AutoDiff/autodiff_diagnostics.swift
+15-3Lines changed: 15 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -50,11 +50,13 @@ _ = gradient(at: NoDerivativeProperty(x: 1, y: 1)) { s -> Float in
50
50
return tmp.x
51
51
}
52
52
_ =gradient(at:NoDerivativeProperty(x:1, y:1)){ s in
53
-
// expected-warning @+1 {{result does not depend on differentiation arguments and will always have a zero derivative; do you want to use 'withoutDerivative(at:)'?}} {{10-10=withoutDerivative(at:}} {{13-13=)}}
53
+
// TODO(TF-788): Re-enable non-varied result warning.
54
+
// xpected-warning @+1 {{result does not depend on differentiation arguments and will always have a zero derivative; do you want to use 'withoutDerivative(at:)'?}} {{10-10=withoutDerivative(at:}} {{13-13=)}}
54
55
return s.y
55
56
}
56
57
_ =gradient(at:NoDerivativeProperty(x:1, y:1)){
57
-
// expected-warning @+1 {{result does not depend on differentiation arguments and will always have a zero derivative; do you want to use 'withoutDerivative(at:)'?}} {{3-3=withoutDerivative(at:}} {{7-7=)}}
58
+
// TODO(TF-788): Re-enable non-varied result warning.
59
+
// xpected-warning @+1 {{result does not depend on differentiation arguments and will always have a zero derivative; do you want to use 'withoutDerivative(at:)'?}} {{3-3=withoutDerivative(at:}} {{7-7=)}}
58
60
$0.y
59
61
}
60
62
@@ -295,10 +297,20 @@ func one() -> Float {
295
297
}
296
298
@differentiable
297
299
func nonVariedResult(_ x:Float)->Float{
298
-
// expected-warning @+1 {{result does not depend on differentiation arguments and will always have a zero derivative; do you want to use 'withoutDerivative(at:)'?}} {{10-10=withoutDerivative(at:}} {{15-15=)}}
300
+
// TODO(TF-788): Re-enable non-varied result warning.
301
+
// xpected-warning @+1 {{result does not depend on differentiation arguments and will always have a zero derivative; do you want to use 'withoutDerivative(at:)'?}} {{10-10=withoutDerivative(at:}} {{15-15=)}}
299
302
returnone()
300
303
}
301
304
305
+
// Check that `withoutDerivative(at:)` silences the warning.
Copy file name to clipboardExpand all lines: test/AutoDiff/forward_mode_diagnostics.swift
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,8 @@ func one() -> Float {
80
80
}
81
81
@differentiable
82
82
func nonVariedResult(_ x:Float)->Float{
83
-
// expected-warning @+1 2 {{result does not depend on differentiation arguments and will always have a zero derivative; do you want to use 'withoutDerivative(at:)'?}} {{10-10=withoutDerivative(at:}}
83
+
// TODO(TF-788): Re-enable non-varied result warning.
84
+
// xpected-warning @+1 2 {{result does not depend on differentiation arguments and will always have a zero derivative; do you want to use 'withoutDerivative(at:)'?}} {{10-10=withoutDerivative(at:}}
0 commit comments