Skip to content

[AutoDiff] Temporarily disable non-varied result warning. #26928

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

Merged
merged 1 commit into from
Aug 29, 2019
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
15 changes: 10 additions & 5 deletions lib/SILOptimizer/Mandatory/Differentiation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4594,12 +4594,13 @@ class JVPEmitter final
attr->getIndices().parameters->getNumIndices());
auto origParamArgs = original->getArgumentsWithoutIndirectResults();

// Check if result is not varied.
// TODO(TF-788): Re-enable non-varied result warning.
/*
// Emit a warning and fixit if original result is not varied, because it
// will always have a zero derivative.
SmallVector<SILValue, 8> origFormalResults;
collectAllFormalResultsInTypeOrder(*original, origFormalResults);
auto origResult = origFormalResults[getIndices().source];
// Emit warning if original result is not varied, because it will always
// have a zero derivative.
if (!activityInfo.isVaried(origResult, getIndices().parameters)) {
// Emit fixit if original result has a valid source location.
auto startLoc = origResult.getLoc().getStartSourceLoc();
Expand All @@ -4610,6 +4611,7 @@ class JVPEmitter final
.fixItInsertAfter(endLoc, ")");
}
}
*/

auto *diffEntry = getDifferential().getEntryBlock();
diffBuilder.setInsertionPoint(
Expand Down Expand Up @@ -5624,8 +5626,10 @@ class PullbackEmitter final : public SILInstructionVisitor<PullbackEmitter> {
SmallVector<SILValue, 8> origFormalResults;
collectAllFormalResultsInTypeOrder(original, origFormalResults);
auto origResult = origFormalResults[getIndices().source];
// Emit warning if original result is not varied, because it will always
// have a zero derivative.
// TODO(TF-788): Re-enable non-varied result warning.
/*
// Emit a warning and fixit if original result is not varied, because it
// will always have a zero derivative.
if (!getActivityInfo().isVaried(origResult, getIndices().parameters)) {
// Emit fixit if original result has a valid source location.
auto startLoc = origResult.getLoc().getStartSourceLoc();
Expand All @@ -5636,6 +5640,7 @@ class PullbackEmitter final : public SILInstructionVisitor<PullbackEmitter> {
.fixItInsertAfter(endLoc, ")");
}
}
*/
builder.setInsertionPoint(
pullbackEntry, getNextFunctionLocalAllocationInsertionPoint());
if (seed->getType().isAddress()) {
Expand Down
18 changes: 15 additions & 3 deletions test/AutoDiff/autodiff_diagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ _ = gradient(at: NoDerivativeProperty(x: 1, y: 1)) { s -> Float in
return tmp.x
}
_ = gradient(at: NoDerivativeProperty(x: 1, y: 1)) { s in
// 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=)}}
// TODO(TF-788): Re-enable non-varied result warning.
// 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=)}}
return s.y
}
_ = gradient(at: NoDerivativeProperty(x: 1, y: 1)) {
// 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=)}}
// TODO(TF-788): Re-enable non-varied result warning.
// 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=)}}
$0.y
}

Expand Down Expand Up @@ -295,10 +297,20 @@ func one() -> Float {
}
@differentiable
func nonVariedResult(_ x: Float) -> Float {
// 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=)}}
// TODO(TF-788): Re-enable non-varied result warning.
// 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=)}}
return one()
}

// Check that `withoutDerivative(at:)` silences the warning.

struct TF_775: Differentiable {
@differentiable(wrt: (self))
func nonVariedResult(_ input: Float) -> Float {
withoutDerivative(at: input)
}
}

//===----------------------------------------------------------------------===//
// Subset parameters
//===----------------------------------------------------------------------===//
Expand Down
3 changes: 2 additions & 1 deletion test/AutoDiff/forward_mode_diagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ func one() -> Float {
}
@differentiable
func nonVariedResult(_ x: Float) -> Float {
// 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:}}
// TODO(TF-788): Re-enable non-varied result warning.
// 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:}}
return one()
}

Expand Down