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

Splitter refactoring #202

Merged
merged 13 commits into from
Apr 26, 2019
Merged

Splitter refactoring #202

merged 13 commits into from
Apr 26, 2019

Conversation

arvoelke
Copy link
Contributor

@arvoelke arvoelke commented Mar 26, 2019

Closes #80. Refactors the splitter logic for adding / removing connections to occur within the builder. This consolidates the connection logic into one place (builder/connection.py) so that backend-relevant logic and objects are manipulated at the same level of abstraction.

Overarching ideas:

  • The splitter returns "directives" (i.e., sets of instructions) to guide the builder.
  • The builder fills in all three "sub-models" (self, host, and host_pre) in parallel, by delegating the objects to the appropriate builder methods.

Solves the following bugs:

Random improvements:

  • split_pre_from_host is no longer O(n^2) (This was a misunderstanding on my part, fueled by the fact the variable named "queue" was actually a stack -- it is now actually a queue)
  • __contains__ is no longer O(n)

Bugs that have been identified that are outside the scope of this PR:

Existing issues that should now be more readily achievable:

Other future work:

@arvoelke arvoelke requested a review from hunse April 1, 2019 20:20
@hunse hunse force-pushed the splitter-refactoring branch 2 times, most recently from df54ce5 to de2b772 Compare April 3, 2019 18:08
nengo_loihi/builder/node.py Outdated Show resolved Hide resolved
nengo_loihi/builder/tests/test_connection.py Show resolved Hide resolved
nengo_loihi/splitter.py Outdated Show resolved Hide resolved
nengo_loihi/splitter.py Outdated Show resolved Hide resolved
nengo_loihi/splitter.py Outdated Show resolved Hide resolved
@arvoelke
Copy link
Contributor Author

arvoelke commented Apr 4, 2019

I ran @tcstewar's benchmark notebook with:

conditions = [
    'nengo',                                         # the normal nengo backend
    'nengo_loihi(precompute=False, target="loihi")', # using Loihi itself
    'nengo_loihi(precompute=True, target="loihi")',  # using Loihi itself with precompute
]

on both master and this branch.

On this branch, precompute=False and precompute=True gave identical accuracy (but with different speeds) across all benchmarks and so I modified a simple unit test (45eced7) to verify this. The learning benchmarks aren't supposed to work with precompute=True (#214) and so I added a commit (433b489) to check this and improve the error message.

On master, precompute=False and precompute=True gave different results for ['CircularConvolution', 'MatrixMultiply', 'SPASequence'], which I presume has something to do with some interaction between remove_passthroughs=True and precompute with the seeding of the network in the old splitter code (also see issue #210).

@arvoelke
Copy link
Contributor Author

arvoelke commented Apr 4, 2019

Pushed two more commits (1711044, 0ca11d8) to move LoihiInput and SpikeInput from builder/inputs.py back into inputs.py and move build_conv2d_connection from conv.py to builder/connections.py. This should now address all your comments @hunse.

@arvoelke
Copy link
Contributor Author

arvoelke commented Apr 4, 2019

Added a commit (6c201e0) that increases test coverage since I touched the lines of some un-tested convolution code.

@hunse
Copy link
Collaborator

hunse commented Apr 8, 2019

Just a few minor comments. Otherwise everything LGTM. Thanks for doing all those tests against the benchmarks.

@tbekolay tbekolay force-pushed the splitter-refactoring branch 4 times, most recently from 328f0b9 to 820bc77 Compare April 15, 2019 18:31
@tbekolay tbekolay force-pushed the splitter-refactoring branch 2 times, most recently from b415361 to f9bff69 Compare April 23, 2019 15:27
Copy link
Member

@tbekolay tbekolay left a comment

Choose a reason for hiding this comment

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

This is a big improvement, will make future development much easier. I made some changes within the history here, so best to see the commits one-by-one for my suggested changes. There are definitely some discussions points here, so it would be great to get @arvoelke and @hunse's thoughts and a signoff.

  1. 5694c27 Is Split a good name? Or should we stick with Splitter, SplitterDirective, or some other option?
  2. 15890be Similarly, is PassthroughSplit a good name?
  3. ea6d52e Should this be a separate PR or is it OK to include here?
  4. 16e322a Is get_seed something we want built into Model? And if so, do we do it now or make a separate issue for it?
  5. f64b102 Are BuildErrors sufficient here or do we need to make a new NengoException subclass?

From nengo_loihi.inputs. These classes are only used as part of
the build process and should not be made alongside Block and
LoihiInput instances.
@arvoelke
Copy link
Contributor Author

I added a couple very minor commits for coverage / sanity. I also rebased onto master again to pick up the testing fixes from the current/rates sync-up.

5694c27 Is Split a good name? Or should we stick with Splitter, SplitterDirective, or some other option?
15890be Similarly, is PassthroughSplit a good name?
ea6d52e Should this be a separate PR or is it OK to include here?

LGTM!

16e322a Is get_seed something we want built into Model? And if so, do we do it now or make a separate issue for it?

I think it's fine as is. A bunch of the weirdness with seeding can be resolved when we eventually drop support for nengo<3. This could end up simplifying a bunch of this code.

f64b102 Are BuildErrors sufficient here or do we need to make a new NengoException subclass?

This LGTM, but we should make a card to go through the rest of the code base? e..g, There are a bunch of ValueError exceptions in hardware/builder.py.

@tbekolay tbekolay force-pushed the splitter-refactoring branch 3 times, most recently from e30f32c to 76b8645 Compare April 24, 2019 16:52
@arvoelke
Copy link
Contributor Author

arvoelke commented Apr 24, 2019

I just noticed that the simulator docstring says the default for precompute=True. We should fix that here IMO.

@tbekolay
Copy link
Member

We should fix that here IMO.

OK, will do. Running into some issues getting the hardware build to pass so I'll be doing at least one more push anyhow.

arvoelke and others added 11 commits April 24, 2019 13:55
Also corrects an incorrect default in the simulator docstring.
The test was fragile with the old tolerances, failing for many seeds.
Most of the work done by the splitter is now done in the builder.
This should give more clarity and control over the mapping between
pre-build and post-build objects. The `Split` class takes on the
organizational tasks of the old `Splitter`, giving directives to
the builder about what should be on- or off-chip.

Several tests were added or modified to ensure that these changes
did not affect built models in adverse ways. Some tests were added
to ensure that the refactoring made improvements; for example, the
refactored splitter no longer mutates networks, which closes #211.
Simulations should now be identical whether precompute is True
or False, so the tolerance in test_precompute is now set to zero.

The passthrough removal process was also modified to act in the
same way as `Split`, and is now named `PassthroughSplit` accordingly.

Co-authored-by: Trevor Bekolay <tbekolay@gmail.com>
Also fix an issue caught by flake8
The decoder cache does not work for host models due to having
no context manager, which is normally constructed by the
top-level network builder.

This commit fixes #207 as it does not globally disable the
decoder cache. We also add some asserts to existing tests
for ensure that #207 is fixed.
Covers some previously uncovered lines in `conv.py`.
There were a few places where we were raising errors that were
not subclasses of NengoException. They are now appropriate
NengoExceptions.
A keyword argument changed in a recent abr_control commit.
@tbekolay tbekolay force-pushed the splitter-refactoring branch 2 times, most recently from 3053887 to 2808ea5 Compare April 26, 2019 02:17
@arvoelke arvoelke force-pushed the splitter-refactoring branch 3 times, most recently from 683384e to b315cf3 Compare April 26, 2019 16:39
This partially reverts commit
70ecb8a.

The patch to graph.Graph seems to be incomplete, as one process
could be writing to the file to be copied while another process
is attempting to read it. The includes are also not copied, so
likely we need a more robust solution for writing snip files to
temporary directories.

The command was only changed to request one worker instead of two.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Refactor builder logic
3 participants