Skip to content

[TF-935] Replaces '-Xllvm -run-jvp-generation' by '-enable-experiment… #27861

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 3 commits into from
Oct 25, 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
5 changes: 5 additions & 0 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ namespace swift {
/// `@differentiable` declaration attribute, etc.
bool EnableExperimentalDifferentiableProgramming = false;

// SWIFT_ENABLE_TENSORFLOW
/// Whether to enable forward mode differentiation.
bool EnableExperimentalForwardModeDifferentiation = false;
// SWIFT_ENABLE_TENSORFLOW END

/// Whether to enable #quote, #unquote and @quoted.
bool EnableExperimentalQuasiquotes = false;

Expand Down
6 changes: 6 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,12 @@ def disable_bridging_pch : Flag<["-"], "disable-bridging-pch">,
def enable_experimental_differentiable_programming : Flag<["-"], "enable-experimental-differentiable-programming">,
Flags<[FrontendOption]>,
HelpText<"Enable experimental differentiable programming features">;
// SWIFT_ENABLE_TENSORFLOW
// NOTE: This flag will be removed when JVP/differential generation is robust.
def enable_experimental_forward_mode_differentiation : Flag<["-"], "enable-experimental-forward-mode-differentiation">,
Flags<[FrontendOption]>,
HelpText<"Enable experimental forward mode differentiation">;
// SWIFT_ENABLE_TENSORFLOW END

def enable_experimental_quasiquotes : Flag<["-"], "enable-experimental-quasiquotes">,
Flags<[FrontendOption]>,
Expand Down
4 changes: 4 additions & 0 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ static void addCommonFrontendArgs(const ToolChain &TC, const OutputInfo &OI,
options::OPT_enable_experimental_dependencies);
inputArgs.AddLastArg(arguments,
options::OPT_experimental_dependency_include_intrafile);
// SWIFT_ENABLE_TENSORFLOW
inputArgs.AddLastArg(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooo, is inputArgs.AddLastArg missing for options::OPT_enable_experimental_differentiable_programming? I'm not sure whether adding it is necessary, but it seems necessary.

Copy link
Contributor Author

@vguerra vguerra Oct 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed it is missing and it seems to be necessary but since the option is not used anywhere in the code yet (#27446). Honestly, I am not sure what the consequences are of not doing inputArgs.AddLastArg.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I am not sure what the consequences are of not doing inputArgs.AddLastArg.

Me neither 😮

arguments, options::OPT_enable_experimental_forward_mode_differentiation);
// SWIFT_ENABLE_TENSORFLOW END
inputArgs.AddLastArg(arguments,
options::OPT_enable_experimental_quasiquotes);
inputArgs.AddLastArg(arguments, options::OPT_package_description_version);
Expand Down
3 changes: 3 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
if (Args.hasArg(OPT_experimental_dependency_include_intrafile))
Opts.ExperimentalDependenciesIncludeIntrafileOnes = true;

// TODO: Ignore if enable-experimental-differentiable-programming is false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I've seen in the code {{-enable-experimental-differentiable-programming}} has been added as frontend option but is not really taken into account to enable/disable AutoDiff capabilities. As soon as the opt is taken into account, we can update this to disable {{EnableExperimentalForwardModeDifferentation}} accordingly.

Opts.EnableExperimentalForwardModeDifferentiation |=
Args.hasArg(OPT_enable_experimental_forward_mode_differentiation);
if (Args.hasArg(OPT_enable_experimental_quasiquotes))
Opts.EnableExperimentalQuasiquotes = true;

Expand Down
14 changes: 5 additions & 9 deletions lib/SILOptimizer/Mandatory/Differentiation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ static llvm::cl::opt<bool> SkipFoldingDifferentiableFunctionExtraction(
"differentiation-skip-folding-differentiable-function-extraction",
llvm::cl::init(true));

/// This flag is used to enable full JVP generation.
/// It will be removed when JVP/differential generation is robust.
static llvm::cl::opt<bool> RunJVPGeneration(
"run-jvp-generation",
llvm::cl::init(false));

//===----------------------------------------------------------------------===//
// Helpers
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -8030,8 +8024,9 @@ bool ADContext::processDifferentiableAttribute(
// Diagnose:
// - Functions with no return.
// - Functions with unsupported control flow.
if (RunJVPGeneration && (diagnoseNoReturn(*this, original, invoker) ||
diagnoseUnsupportedControlFlow(*this, original, invoker)))
if (getASTContext().LangOpts.EnableExperimentalForwardModeDifferentiation &&
(diagnoseNoReturn(*this, original, invoker) ||
diagnoseUnsupportedControlFlow(*this, original, invoker)))
return true;

jvp = createEmptyJVP(*this, original, attr, isDerivativeFnExported);
Expand All @@ -8041,7 +8036,8 @@ bool ADContext::processDifferentiableAttribute(
// does not exist. If custom VJP exists but custom JVP does not, skip JVP
// generation because generated JVP may not match semantics of custom VJP.
// Instead, create an empty JVP.
if (RunJVPGeneration && !vjp) {
if (getASTContext().LangOpts.EnableExperimentalForwardModeDifferentiation &&
!vjp) {
// JVP and differential generation do not currently support functions with
// multiple basic blocks.
if (original->getBlocks().size() > 1) {
Expand Down
2 changes: 1 addition & 1 deletion test/AutoDiff/forward_mode_diagnostics.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -Xllvm -run-jvp-generation -emit-sil -verify %s
// RUN: %target-swift-frontend -enable-experimental-forward-mode-differentiation -emit-sil -verify %s

// TODO: move these tests back into `autodiff_diagnostics.swift` once
// forward mode reaches feature parity with reverse mode.
Expand Down
4 changes: 2 additions & 2 deletions test/AutoDiff/forward_mode_sil.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %target-swift-frontend -emit-sil -verify -Xllvm -run-jvp-generation -Xllvm -debug-only=differentiation %s 2>&1 | %FileCheck %s -check-prefix=CHECK-DATA-STRUCTURES
// RUN: %target-swift-frontend -emit-sil -verify -Xllvm -sil-print-after=differentiation -Xllvm -run-jvp-generation -o /dev/null 2>&1 %s | %FileCheck %s -check-prefix=CHECK-SIL
// RUN: %target-swift-frontend -emit-sil -verify -enable-experimental-forward-mode-differentiation -Xllvm -debug-only=differentiation %s 2>&1 | %FileCheck %s -check-prefix=CHECK-DATA-STRUCTURES
// RUN: %target-swift-frontend -emit-sil -verify -Xllvm -sil-print-after=differentiation -enable-experimental-forward-mode-differentiation -o /dev/null 2>&1 %s | %FileCheck %s -check-prefix=CHECK-SIL
// REQUIRES: asserts


Expand Down
2 changes: 1 addition & 1 deletion test/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ if not getattr(config, 'target_run_simple_swift', None):
# TODO: Remove when forward mode AD support is robust.
config.target_run_simple_swift_forward_mode_differentiation = (
'%%empty-directory(%%t) && '
'%s %s %%s -Xllvm -run-jvp-generation -o %%t/a.out %s -module-name main && '
'%s %s %%s -enable-experimental-forward-mode-differentiation -o %%t/a.out %s -module-name main && '
'%s %%t/a.out &&'
'%s %%t/a.out'
% (config.target_build_swift, mcp_opt, swift_tensorflow_extra_options, config.target_codesign, config.target_run))
Expand Down