Skip to content
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

Refactor/execution mode compiled #2550

Merged
merged 8 commits into from
Nov 25, 2022
Merged

Conversation

jdcpni
Copy link
Collaborator

@jdcpni jdcpni commented Nov 24, 2022

• llvm/init.py

  • add ExecutionMode.COMPILED (~ Python | PyTorch).
    This was added both for clarity at decision points in the code (mainly, composition.py) and to be able to distinguish Python from PyTorch modes.
    Now enforces use of ExecutionMode.PyTorch or LLVM for AutdoffiComposition.learn() (to make it clear that execution learning in Autodiff uses one of these, and not Python).
    Added documentation in composition.py and autodiffcomposition.py regarding different modes and execution_mode specifications requirements.

• compositon.py, autodiffcomposition.py, compositionrunner.py:

  • modifed to sue ExecutionMode.COMPILED for condionals

• test_autodiffcomposition.py:

  • test_execution_mode_python_error() replaces test_execution_mode_python_warning()

  - learn(): add error for use of ExecutionMode.LLVM or ExecutionMode.PyTorch

• autodiffcomposition.py
  - learn(): add warning for use of ExecutionMode.Python

• test_learning.py:
  - add test_execution_mode_pytorch_and_LLVM_errors

• test_autodiffcomposition.py:
  - add test_execution_mode_python_warning
  - add ExecutionMode.COMPILED (~ Python | PyTorch).

• compositon.py, autodiffcomposition.py, compositionrunner.py:
  - modifed to sue ExecutionMode.COMPILED for condionals

• test_autodiffcomposition.py:
  - test_execution_mode_python_error() replaces test_execution_mode_python_warning()
@jdcpni jdcpni requested a review from jvesely November 24, 2022 16:21
@github-actions
Copy link

This PR causes the following changes to the html docs (ubuntu-latest-3.7-x64):

No differences!

...

See CI logs for the full diff.

@@ -10089,7 +10089,7 @@ def run(
elif execution_mode & pnlvm.ExecutionMode.PTX:
results += _comp_ex.cuda_run(inputs, num_trials, num_inputs_sets)
else:
assert False, "Unknown execution mode: {}".format(execution_mode)
assert False, f"Unknown execution mode: {execution_mode}."
Copy link
Collaborator

Choose a reason for hiding this comment

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

.format is preferred to f-strings at least in compilation related code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

reverted

@@ -10721,7 +10721,7 @@ def execute(
elif execution_mode & pnlvm.ExecutionMode.PTX:
_comp_ex.cuda_execute(llvm_inputs)
else:
assert False, "Unknown execution mode: {}".format(execution_mode)
assert False, f"Unknown execution mode: {execution_mode}."
Copy link
Collaborator

Choose a reason for hiding this comment

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

.format is preferred to f-string

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

reverted

@@ -10395,7 +10395,7 @@ def learn(
from psyneulink.library.compositions import AutodiffComposition
runner = CompositionRunner(self)

if (execution_mode in {pnlvm.ExecutionMode.PyTorch, pnlvm.ExecutionMode.LLVM}
if ((execution_mode is not pnlvm.ExecutionMode.Python)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this will complain about using is instead of ==.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Comparing enum member not its value.

context.execution_phase = ContextFlags.PROCESSING
self.controller.execute(context=context)

if execution_mode:
if execution_mode & pnlvm.ExecutionMode.COMPILED:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This (and all other checks before execute_node) can use an assertion:
assert execution_mode == pnlvm.ExecutionMode.LLVM or execution_mode & pnl.ExecutionMode._Fallback
Those two cases are the only way to reach the code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Applied assertion here, but other checks (at least on composition.py) seem to be part of legitimate branching conditions, not simple else's.

f"or a standard Composition for Python execution.)")
raise AutodiffCompositionError(f"{self.name} is an AutodiffComposition so its learn() "
f"cannot be called with execution_mode = ExecutionMode.Python; "
f"use ExecutionMode.PyTorch or ExecutionMode.LLVM.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the only compiled mode implemented for autodiff is LLVMRun.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks

@coveralls
Copy link

coveralls commented Nov 24, 2022

Coverage Status

Coverage decreased (-0.03%) to 84.145% when pulling cbb1a14 on refactor/execution_mode_COMPILED into 26bf706 on devel.

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Nov 24, 2022

This pull request introduces 1 alert when merging b5e882f into 26bf706 - view on LGTM.com

new alerts:

  • 1 for Unused import

Heads-up: LGTM.com's PR analysis will be disabled on the 5th of December, and LGTM.com will be shut down ⏻ completely on the 16th of December 2022. It looks like GitHub code scanning with CodeQL is already set up for this repo, so no further action is needed 🚀. For more information, please check out our post on the GitHub blog.

@github-actions
Copy link

This PR causes the following changes to the html docs (ubuntu-latest-3.7-x64):

No differences!

...

See CI logs for the full diff.

  - test_execution_mode_python_error(): fix bug
@github-actions
Copy link

This PR causes the following changes to the html docs (ubuntu-latest-3.7-x64):

No differences!

...

See CI logs for the full diff.

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Nov 25, 2022

This pull request introduces 1 alert when merging cbb1a14 into 26bf706 - view on LGTM.com

new alerts:

  • 1 for Unused import

Heads-up: LGTM.com's PR analysis will be disabled on the 5th of December, and LGTM.com will be shut down ⏻ completely on the 16th of December 2022. It looks like GitHub code scanning with CodeQL is already set up for this repo, so no further action is needed 🚀. For more information, please check out our post on the GitHub blog.

@jdcpni jdcpni merged commit 5d4ead3 into devel Nov 25, 2022
@jdcpni jdcpni deleted the refactor/execution_mode_COMPILED branch November 25, 2022 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants