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

Devel #3211

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open

Devel #3211

wants to merge 53 commits into from

Conversation

kmantel
Copy link
Collaborator

@kmantel kmantel commented Feb 22, 2025

No description provided.

kmantel and others added 30 commits January 30, 2025 03:40
Parameter getters may not be valid when called on a Parameter owned by a
type. In this case, use the default value to determine if the
Parameter can be associated with a ParameterPort.

Do not catch exceptions on instantiated classes.
Numpy 1.25.0 moved warnings and errors to a submodule[0].
Moreover, they are removed from the top-level namespace in Numpy 2.0.0 [1].

Add and use exception import that either points to the new exception submodule,
or the global namespace depending on whether the former is available.

[0] https://numpy.org/doc/2.1/release/1.25.0-notes.html#numpy-now-has-an-np-exceptions-namespace
[1] https://numpy.org/doc/2.1/release/2.0.0-notes.html#numpy-2-0-python-api-removals

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
This mode is not supposed to be used outside of its combination
in PTXRun.

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
…e test instances

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
This mode should not be used outside development or testing.

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
It does not support non-trivial scheduling.

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Explicitly list composition compilation mode.
Make the new mode private. Only used by developers and tests.

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Use them instead of the COMPILED mask.

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Move compiled execution of output_CIM to the same place as Python
execution.
Do not report end of trial twice in _LLVMPerNode execution mode.

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Enum members are singletons.

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Make most compiled modes private for test/development use only.
Introduce a new _LLVMPerNode execution mode.
Do not fall back to per-node mode in automatic fallback.
Use ExecutionMode helper methods rather than COMPILED mask to determine compiled mode.
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
• transferfunctions.py:
  * Add bounds to Linear (docs are wrong and code doesn't implement them)
  * Refactor bounds to use getter, and to list dependencies on scale and offset, and to use "natural bounds" or the like
  - rename bounds -> range
  - add DeterministicTransferFunction subclass of TransferFunction:
    - scale and offset Parameters used by all subclasses
    - add _range_setter() that adjusts range based on scale and/or offset
---------

Co-authored-by: jdcpni <pniintel55>
Fixes: 7cacab6
	("refactor/transferfunction/scale_and_offset")

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
The necessary OneHot implementation is available since:
c0f73e2
	("llvm/OneHot: Implement all modes (#3124)")

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Enable MAX_VAL and MAX_INDICATOR in compiled SoftMax function.
…#3187)

Use nullcontext for cases that do not emit warning.
Add missing warning messages for cases that do.
Turn expected messages into regular expressions and pass
them in "match" parameter to pytest.warns.

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
…ments

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
…eIntegrator

Increased tolerance is now only needed for fp32 execution.

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Match Python implementations.

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
The "reset" variants of functions now return a value.

Add tests for reset behaviour of:
 * ProcessingMechanism using an integrator function
 * DDM mechanism using DriftDiffusionIntegrator function
 * TransferMechanism in integrator mode

The reproducer from
#3142 was added
as a test of mechanism reset in composition.

Fixes: #3142
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
…tion variants (#3188)

Return the value of "previous_value" Parameter in Function "reset" variant for Functions that don't have other Parameters with initializers.
Return the values of "previous_value" and "previous_time" in DriftDiffusionIntegrator "reset" variant".
Update output ports in Mechanism "reset" execution variants, using the value returned from the Function's "reset" variant.

Update compiled test helpers to allow the selection of execution variants for Mechanisms and Functions.
Add reproducer from #3142 as a regression test.

Closes: #3142
Fixes: 41b254d
	("ga: Move wheel/sdist creation to install-pnl action (#3085)")

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Itertools classes won't support copy or pickle starting in Python 3.14.
Filter the associated DeprecationWarning.

Fixes ~5000 warnings in a full test run using Python 3.12.

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
kmantel and others added 22 commits February 14, 2025 00:33
Only explicitly specified FEEDBACK projections are known to
Composition.graph. FLEXIBLE projections are determined to be FEEDBACK or
NON_FEEDBACK in Composition.graph_processing.
- fix bug in assignment of memory_template when first entry of a field is non-zero
- other Components generally set in their execute methods
- setting only in Composition.run fails to set when a Composition is
nested, because only execute gets called
- must still be set in Composition.run in case Composition is empty
…26 (#3198)

Updates the requirements on [pycuda](https://github.com/inducer/pycuda) to permit the latest version.
- [Release notes](https://github.com/inducer/pycuda/releases)
- [Commits](inducer/pycuda@v2024.1...v2025.1)

---
updated-dependencies:
- dependency-name: pycuda
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Provides similar functionality to the skip_file_prefixes argument of
warnings.warn in python 3.12+
Override more verbose graph-scheduler strings for
GraphStructureCondition parent classes:

- _GSCWithOperations - exclude attributes other than nodes
- _GSCReposition - remove str of graph for already before/after warnings
condition: simplify output for GraphStructureConditions
would otherwise just fail less clearly later in init
…sition-show-graph-jupyter

add return value to show_graph
standard_deviation=1.0, \
bias=0.0, \
scale=1.0, \
offset=0.0, \

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error as implicit returns always return None.
@@ -374,7 +374,7 @@

from psyneulink._typing import Optional

from psyneulink.core.components.component import Component, parameter_keywords
from psyneulink.core.components.component import Component, ComponentsMeta, parameter_keywords

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
psyneulink.core.components.component
begins an import cycle.
Comment on lines +25 to +29
from psyneulink.core.globals.utilities import (
get_stacklevel_skip_file_prefixes,
parse_valid_identifier,
toposort_key,
)

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
psyneulink.core.globals.utilities
begins an import cycle.
Copy link

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

diff -r docs-base/AutodiffComposition.html docs-head/AutodiffComposition.html
364c364
< <li><p>Specifying <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVM" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVM"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVM</span></code></a> or <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.PyTorch" title="psyneulink.core.llvm.__init__.ExecutionMode.PyTorch"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.PyTorch</span></code></a> in the learn() method of a standard
---
> <li><p>Specifying <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVMRun" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVMRun"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVMRun</span></code></a> or <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.PyTorch" title="psyneulink.core.llvm.__init__.ExecutionMode.PyTorch"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.PyTorch</span></code></a> in the learn() method of a standard
380c380
< <p>Specifying <code class="xref any docutils literal notranslate"><span class="pre">ExecutionMode.LLVMRUn</span></code> in either the <a class="reference internal" href="Composition.html#psyneulink.core.compositions.composition.Composition.learn" title="psyneulink.core.compositions.composition.Composition.learn"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">learn</span></code></a> and <a class="reference internal" href="Composition.html#psyneulink.core.compositions.composition.Composition.run" title="psyneulink.core.compositions.composition.Composition.run"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">run</span></code></a>
---
> <p>Specifying <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVMRun" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVMRun"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVMRun</span></code></a> in either the <a class="reference internal" href="Composition.html#psyneulink.core.compositions.composition.Composition.learn" title="psyneulink.core.compositions.composition.Composition.learn"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">learn</span></code></a> and <a class="reference internal" href="Composition.html#psyneulink.core.compositions.composition.Composition.run" title="psyneulink.core.compositions.composition.Composition.run"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">run</span></code></a>
diff -r docs-base/Compilation.html docs-head/Compilation.html
237,238c237,238
< <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVM" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVM"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVM</span></code></a>: Compile and execute individual nodes. The scheduling loop still runs in Python. If any of the nodes fails to compile, an error is raised. <em>NOTE:</em> Schedules that require access to node data will not work correctly.</p></li>
< <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVMExec" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVMExec"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVMExec</span></code></a>: Execution of <code class="xref any docutils literal notranslate"><span class="pre">Composition.exec</span></code> is replaced by a compiled equivalent. If the <a class="reference internal" href="Composition.html"><span class="doc">Composition</span></a> fails to compile, an error is raised.</p></li>
---
> <li><p><code class="xref any docutils literal notranslate"><span class="pre">ExecutionMode._LLVMPerNode</span></code>: Compile and execute individual nodes. The scheduling loop still runs in Python. If any of the nodes fails to compile, an error is raised. <em>NOTE:</em> Schedules that require access to node data will not work correctly.</p></li>
> <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode._LLVMExec" title="psyneulink.core.llvm.__init__.ExecutionMode._LLVMExec"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode._LLVMExec</span></code></a>: Execution of <code class="xref any docutils literal notranslate"><span class="pre">Composition.exec</span></code> is replaced by a compiled equivalent. If the <a class="reference internal" href="Composition.html"><span class="doc">Composition</span></a> fails to compile, an error is raised.</p></li>
diff -r docs-base/Composition.html docs-head/Composition.html
1243c1243
< <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVM" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVM"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVM</span></code></a> and <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.PyTorch" title="psyneulink.core.llvm.__init__.ExecutionMode.PyTorch"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.PyTorch</span></code></a> can only be used in the <a class="reference internal" href="AutodiffComposition.html#psyneulink.library.compositions.autodiffcomposition.AutodiffComposition.learn" title="psyneulink.library.compositions.autodiffcomposition.AutodiffComposition.learn"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">learn</span></code></a>
---
> <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVMRun" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVMRun"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVMRun</span></code></a> and <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.PyTorch" title="psyneulink.core.llvm.__init__.ExecutionMode.PyTorch"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.PyTorch</span></code></a> can only be used in the <a class="reference internal" href="AutodiffComposition.html#psyneulink.library.compositions.autodiffcomposition.AutodiffComposition.learn" title="psyneulink.library.compositions.autodiffcomposition.AutodiffComposition.learn"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">learn</span></code></a>
1964,1965c1964,1965
< <li><p><em>True</em> – try to use the one that yields the greatesst improvement, progressively reverting to less powerful
< but more forgiving modes, in the order listed below, for each that fails;</p></li>
---
> <li><p><em>True</em> – try to use the one that yields the greatest improvement, progressively reverting to less powerful
> but more forgiving modes, trying LLVMRun, _LLVMExec, and Python.</p></li>
1969c1969
< <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVMExec" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVMExec"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVMExec</span></code></a> – compile and run each <a class="reference internal" href="Time.html#psyneulink.core.scheduling.time.TimeScale.TRIAL" title="psyneulink.core.scheduling.time.TimeScale.TRIAL"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">TRIAL</span></code></a>, using the Python interpreter
---
> <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode._LLVMExec" title="psyneulink.core.llvm.__init__.ExecutionMode._LLVMExec"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode._LLVMExec</span></code></a> – compile and run each <a class="reference internal" href="Time.html#psyneulink.core.scheduling.time.TimeScale.TRIAL" title="psyneulink.core.scheduling.time.TimeScale.TRIAL"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">TRIAL</span></code></a>, using the Python interpreter
1971,1972c1971,1973
< equivalent the execution of the <a class="reference internal" href="#psyneulink.core.compositions.composition.Composition.execute" title="psyneulink.core.compositions.composition.Composition.execute"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">execute</span></code></a> method using the Python interpreter;</p></li>
< <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVM" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVM"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVM</span></code></a> – compile and run <a class="reference internal" href="#composition-nodes"><span class="std std-ref">Node</span></a> of the <a class="reference internal" href="#"><span class="doc">Composition</span></a> and their <a class="reference internal" href="Projection.html"><span class="doc">Projections</span></a>, using the Python interpreter to call the Composition’s <a class="reference internal" href="#psyneulink.core.compositions.composition.Composition.scheduler" title="psyneulink.core.compositions.composition.Composition.scheduler"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">scheduler</span></code></a>,
---
> equivalent the execution of the <a class="reference internal" href="#psyneulink.core.compositions.composition.Composition.execute" title="psyneulink.core.compositions.composition.Composition.execute"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">execute</span></code></a> method using the Python interpreter;
> This mode does not support Trial scope scheduling rules and should not be used outside of development or testing.</p></li>
> <li><p><code class="xref any docutils literal notranslate"><span class="pre">ExecutionMode._LLVMPerNode</span></code> – compile and run <a class="reference internal" href="#composition-nodes"><span class="std std-ref">Node</span></a> of the <a class="reference internal" href="#"><span class="doc">Composition</span></a> and their <a class="reference internal" href="Projection.html"><span class="doc">Projections</span></a>, using the Python interpreter to call the Composition’s <a class="reference internal" href="#psyneulink.core.compositions.composition.Composition.scheduler" title="psyneulink.core.compositions.composition.Composition.scheduler"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">scheduler</span></code></a>,
1974c1975
< <a class="reference internal" href="Condition.html"><span class="doc">Conditions</span></a> that rely on Node <a class="reference internal" href="Parameters.html"><span class="doc">Parameters</span></a> is not supported;</p></li>
---
> <a class="reference internal" href="Condition.html"><span class="doc">Conditions</span></a> that rely on Node <a class="reference internal" href="Parameters.html"><span class="doc">Parameters</span></a> are not supported;</p></li>
1987c1988
< <li><p><code class="xref any docutils literal notranslate"><span class="pre">ExecutionMode.PTXrun</span></code> – compile multiple <a class="reference internal" href="Time.html#psyneulink.core.scheduling.time.TimeScale.TRIAL" title="psyneulink.core.scheduling.time.TimeScale.TRIAL"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">TRIAL</span></code></a>s  for execution on GPU
---
> <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.PTXRun" title="psyneulink.core.llvm.__init__.ExecutionMode.PTXRun"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.PTXRun</span></code></a> – compile multiple <a class="reference internal" href="Time.html#psyneulink.core.scheduling.time.TimeScale.TRIAL" title="psyneulink.core.scheduling.time.TimeScale.TRIAL"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">TRIAL</span></code></a>s  for execution on GPU
diff -r docs-base/Function.html docs-head/Function.html
304c304
< <em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">psyneulink.core.components.functions.function.</span></span><span class="sig-name descname"><span class="pre">ArgumentTherapy</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">default_variable</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">propensity</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">10.0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pertincacity</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">Manner.CONTRARIAN</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">params</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">owner</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">prefs</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#psyneulink.core.components.functions.function.ArgumentTherapy" title="Permalink to this definition">¶</a></dt>
---
> <em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">psyneulink.core.components.functions.function.</span></span><span class="sig-name descname"><span class="pre">ArgumentTherapy</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">default_variable</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">propensity</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">Manner.CONTRARIAN</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pertinacity</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">10.0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">params</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">owner</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">prefs</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#psyneulink.core.components.functions.function.ArgumentTherapy" title="Permalink to this definition">¶</a></dt>
457a458,462
> <dl class="py attribute">
> <dt class="sig sig-object py" id="psyneulink.core.components.functions.function.ArgumentTherapy.parameters">
> <span class="sig-name descname"><span class="pre">parameters</span></span><em class="property"> <span class="pre">=</span> <span class="pre">&lt;psyneulink.core.
...

See CI logs for the full diff.

@coveralls
Copy link

coveralls commented Feb 22, 2025

Coverage Status

coverage: 84.027% (-0.01%) from 84.037%
when pulling beebd2a on devel
into 5c8168f on master.

* Changes to allow passing BatchedImpl tensors

When pytorch vmap is used on a function, the function
is called to trace it with tenors passed as inputs
which are not normal pytorch tensors. They are in fact
BatchedImpl tensors that have no underlying storage.
These cannot be converted to double() or numpy arrays
so I needed to remove calls to convert these tensors
in this special case.

* Fix bug in _batch_inputs

_batch_inputs was not actually returning batches of
size batch_size.

* Testing bactch support.

* Fix batch_size=1 case.

* WIP merge for pytorch batching in autodiff

* Fix for when minibatch_size is ndarray

* Cleanup

* Remove handling of batched_results.

* Handle dtype-object in _get_variable_from_input

Not sure this works in general to be honest.

* Fixes from merging in devel.

* Fixes for ragged things.

* More fixes for ragged things.

* Fix bad torch.stack call in execute_input_ports

* Add a real pytorch training test with batching

I made a test that implements an equivalent network
in PyTorch and PNL, initializes them with the same
weights, trains them both and then compares the losses. I think this is similar to some other
tests in the file but this one tests batch size > 1
and it actually trains the pytorch network as well.

* More fixes

* Disable update_autodiff_all_output_values

Now that all_output_values contains the
batch dimension in the first dimension it
is causing and error when passed to
output_CIM.execute because it has the incorrect
number of input ports (unless batch size happens
to match number of input ports). Not sure what
the best fix to this is but disabling this line
seems to work and pass all tests. Need to ask Jon.

* Handle 3D structure better in autodiff update_results.

* Fix formatting

* Fix ragged processing.

A bunch of fixes for things wrong with ragged processing.

* Fix logging test.

We need to add batch dimension to the logging checks.

I also made the test check multiple batch sizes.

* Move variable list initialization outside look

I am pretty sure this was a bug.

* Fix ugly formatting

* Default variables need to be forced to atleast_2d

Since we have a batch dimension now, all the default
variable need to be forced to 2D.

* Fix store_memory to support batches.

Not sure this is the correct fix, I am getting errors
in results, but I don't know how else to implement
this.

* More fixes for defaults with batch size.

* More fixes for defaults with batch size.

* Fix store_memory

* Fix store_memory

* Uncomment some tests in test_emcomposition.py

* Revert change to _get_variable_from_input

I think I made this change in error, it was before
I fixed issues with handling ragged structures. Lets
see if tests pass.

* Execute the output_CIM on the last element of the batch to update the output ports

* Move check for torch to learn method.

Since we need torch now to setup inputs (before execute), I moved the check for it to learn.

* Add np.VisibleDeprecationWarning to catch.

Looks like old versions of numpy didn't throw ValueError

* Add pytorch mark to test

* Override new weights_only=True default in PyTorch 2.6

* Move the pytorch lower pin up to 1.13

Looks like weights_only argument wasn't
supported till then. That is a pretty ancient version of pytorch anyway.

Also pushed the upper pin up.

* Documentation cleanup

* Add a check for batch_size > 1 in EMSStorage

* CodeQL cleanup

* Better testing of batched_results argument.

* Style fixes.

---------

Co-authored-by: David Turner <dmturmer@princeton.edu>
Co-authored-by: jdcpni <jdc@princeton.edu>
Copy link

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

diff -r docs-base/AutodiffComposition.html docs-head/AutodiffComposition.html
364c364
< <li><p>Specifying <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVM" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVM"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVM</span></code></a> or <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.PyTorch" title="psyneulink.core.llvm.__init__.ExecutionMode.PyTorch"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.PyTorch</span></code></a> in the learn() method of a standard
---
> <li><p>Specifying <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVMRun" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVMRun"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVMRun</span></code></a> or <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.PyTorch" title="psyneulink.core.llvm.__init__.ExecutionMode.PyTorch"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.PyTorch</span></code></a> in the learn() method of a standard
380c380
< <p>Specifying <code class="xref any docutils literal notranslate"><span class="pre">ExecutionMode.LLVMRUn</span></code> in either the <a class="reference internal" href="Composition.html#psyneulink.core.compositions.composition.Composition.learn" title="psyneulink.core.compositions.composition.Composition.learn"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">learn</span></code></a> and <a class="reference internal" href="Composition.html#psyneulink.core.compositions.composition.Composition.run" title="psyneulink.core.compositions.composition.Composition.run"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">run</span></code></a>
---
> <p>Specifying <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVMRun" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVMRun"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVMRun</span></code></a> in either the <a class="reference internal" href="Composition.html#psyneulink.core.compositions.composition.Composition.learn" title="psyneulink.core.compositions.composition.Composition.learn"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">learn</span></code></a> and <a class="reference internal" href="Composition.html#psyneulink.core.compositions.composition.Composition.run" title="psyneulink.core.compositions.composition.Composition.run"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">run</span></code></a>
1163,1164c1163,1164
< <dd><p>Perform forward pass of model and compute loss for a single trial (i.e., a single input) in Pytorch mode.
< Losses are accumulated in pytorch_rep.track_losses, over calls to this method within a minibatch;</p>
---
> <dd><p>Perform forward pass of model and compute loss for a batch of trials in Pytorch mode.
> Losses are then accumulated, error is backpropagated by compositionrunner.run_learning()</p>
1166,1167c1166
< <div><p>at the end of a minibatch, they are averaged and backpropagated by compositionrunner.run_learning()
< before the next time it calls run(), in a call to backward() by do_gradient_optimization()
---
> <div><p>before the next time it calls run(), in a call to backward() by do_gradient_optimization()
1277c1276
< <span class="sig-name descname"><span class="pre">run</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">synch_projection_matrices_with_torch</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">NotImplemented</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">synch_node_variables_with_torch</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">NotImplemented</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">synch_node_values_with_torch</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">NotImplemented</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">synch_results_with_torch</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">NotImplemented</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">retain_torch_trained_outputs</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">NotImplemented</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">retain_torch_targets</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">NotImplemented</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">retain_torch_losses</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">NotImplemented</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#psyneulink.library.compositions.autodiffcomposition.AutodiffComposition.run" title="Permalink to this definition">¶</a></dt>
---
> <span class="sig-name descname"><span class="pre">run</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">synch_projection_matrices_with_torch</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">NotImplemented</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">synch_node_variables_with_torch</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">NotImplemented</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">synch_node_values_with_torch</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">NotImplemented</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">synch_results_with_torch</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">NotImplemented</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">retain_torch_trained_outputs</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">NotImplemented</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">retain_torch_targets</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">NotImplemented</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">retain_torch_losses</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">NotImplemented</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">batched_results</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#psyneulink.library.compositions.autodiffcomposition.AutodiffComposition.run" title="Permalink to this definition">¶</a></dt>
1322c1321
< <span class="sig-name descname"><span class="pre">load</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">directory</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">filename</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">context</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#psyneulink.library.compositions.autodiffcomposition.AutodiffComposition.load" title="Permalink to this definition">¶</a></dt>
---
> <span class="sig-name descname"><span class="pre">load</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">directory</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">filename</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">context</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">weights_only</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#psyneulink.library.compositions.autodiffcomposition.AutodiffComposition.load" title="Permalink to this definition">¶</a></dt>
diff -r docs-base/Compilation.html docs-head/Compilation.html
237,238c237,238
< <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVM" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVM"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVM</span></code></a>: Compile and execute individual nodes. The scheduling loop still runs in Python. If any of the nodes fails to compile, an error is raised. <em>NOTE:</em> Schedules that require access to node data will not work correctly.</p></li>
< <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVMExec" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVMExec"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVMExec</span></code></a>: Execution of <code class="xref any docutils literal notranslate"><span class="pre">Composition.exec</span></code> is replaced by a compiled equivalent. If the <a class="reference internal" href="Composition.html"><span class="doc">Composition</span></a> fails to compile, an error is raised.</p></li>
---
> <li><p><code class="xref any docutils literal notranslate"><span class="pre">ExecutionMode._LLVMPerNode</span></code>: Compile and execute individual nodes. The scheduling loop still runs in Python. If any of the nodes fails to compile, an error is raised. <em>NOTE:</em> Schedules that require access to node data will not work correctly.</p></li>
> <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode._LLVMExec" title="psyneulink.core.llvm.__init__.ExecutionMode._LLVMExec"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode._LLVMExec</span></code></a>: Execution of <code class="xref any docutils literal notranslate"><span class="pre">Composition.exec</span></code> is replaced by a compiled equivalent. If the <a class="reference internal" href="Composition.html"><span class="doc">Composition</span></a> fails to compile, an error is raised.</p></li>
diff -r docs-base/Composition.html docs-head/Composition.html
1243c1243
< <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVM" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVM"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVM</span></code></a> and <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.PyTorch" title="psyneulink.core.llvm.__init__.ExecutionMode.PyTorch"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.PyTorch</span></code></a> can only be used in the <a class="reference internal" href="AutodiffComposition.html#psyneulink.library.compositions.autodiffcomposition.AutodiffComposition.learn" title="psyneulink.library.compositions.autodiffcomposition.AutodiffComposition.learn"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">learn</span></code></a>
---
> <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVMRun" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVMRun"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVMRun</span></code></a> and <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.PyTorch" title="psyneulink.core.llvm.__init__.ExecutionMode.PyTorch"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.PyTorch</span></code></a> can only be used in the <a class="reference internal" href="AutodiffComposition.html#psyneulink.library.compositions.autodiffcomposition.AutodiffComposition.learn" title="psyneulink.library.compositions.autodiffcomposition.AutodiffComposition.learn"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">learn</span></code></a>
1964,1965c1964,1965
< <li><p><em>True</em> – try to use the one that yields the greatesst improvement, progressively reverting to less powerful
< but more forgiving modes, in the order listed below, for each that fails;</p></li>
---
> <li><p><em>True</em> – try to use the one that yields the greatest improvement, progressively reverting to less powerful
> but more forgiving modes, trying LLVMRun, _LLVMExec, and Python.</p></li>
1969c1969
< <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVMExec" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVMExec"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVMExec</span></code></a> – compile and run each <a class="reference internal" href="Time.html#psyneulink.core.scheduling.time.TimeScale.TRIAL" title="psyneulink.core.scheduling.time.TimeScale.TRIAL"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">TRIAL</span></code></a>, using the Python interpreter
---
> <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode._LLVMExec" title="psyneulink.core.llvm.__init__.ExecutionMode._LLVMExec"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode._LLVMExec</span></code></a> – compile and run each <a class="reference internal" href="Time.html#psyneulink.core.scheduling.time.TimeScale.TRIAL" title="psyneulink.core.scheduling.time.TimeScale.TRIAL"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">TRIAL</span></code></a>, using the Python interpreter
1971,1972c1971,1973
< equivalent the execution of the <a class="reference internal" href="#psyneulink.core.compositions.composition.Composi
...

See CI logs for the full diff.

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.

6 participants