-
Notifications
You must be signed in to change notification settings - Fork 31
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
llvm: _comp_cached: handle weakref proxy/ref caching #2674
Open
kmantel
wants to merge
1
commit into
PrincetonUniversity:devel
Choose a base branch
from
kmantel:llvm-comp_cached
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit confusing. What is the proxy object observed here? and how is it related to autodiff composition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The autodiff relation is incidental - it's only how I happened to notice what seemed like unintentional cache misses.
The wrapper in
_comp_cached
stores a value for anobj
, and later is calledweakref.proxy
objects that referenceobj
. This does not locateobj
in the cache due toTypeError("cannot create weak reference to 'weakcallableproxy' object")
which is caughtPsyNeuLink/psyneulink/core/llvm/builder_context.py
Lines 77 to 81 in 0f3ab10
and bypasses caching.
The example I found creating these proxies is
PsyNeuLink/psyneulink/core/llvm/builder_context.py
Lines 64 to 66 in 0f3ab10
which was added after
_comp_cached
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. the change to use
weakref.proxy
(c65e0bd) introduced the bug in pr #2613. I should have checked the total number of generated structures.I'm still unsure about supporting proxy object caching vs. just reverting c65e0bd.
Does this change fix the high number of generated structures in
test_training_then_processing
? I'd expect that test (and all autodiff compositions) to run into the 'super()' issue instead.EDIT: To elaborate. It's interesting that the
unproxy_weakproxy
function works on super objects as well [0].We could use it to address the
super()
codepath as well as the issue introduced in c65e0bd. This would also allow us to remove the entire exception block incomp_cached
.The fewer
isinstance
checks and exception blocks on fast paths, the better.Otherwise, I think it'd be better to just revert c65e0bd.
[0] https://docs.python.org/3/library/functions.html#super
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you let me know how to check this?
I'm only aware of repeated calls to
PsyNeuLink/psyneulink/library/compositions/autodiffcomposition.py
Lines 858 to 865 in 06f3006
I missed at first that
bctx._cache
is a WeakKeyDictionary - in that case, it doesn't seem like a problem to just callunproxy_weakproxy
each time to let the super objects be stored as well, but I'm not too sure about the intent or benefits of this cache so I'll defer to you.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a good question. the comment above mentioned "AutodiffComposition._get_state_struct_type gets called many times" so I thought you had some monitoring set up.
Either way, it prodded me to fix the stats collection for code generation which has been fixed/extended in #2687.
you should be able to get some numbers by enabling printouts via
PNL_LLVM_DEBUG=stat
. running tests might need-n0
or pytest might hide the output.the
_comp_cached
wrapper is a generalized caching decorator for binary structure types used by compiled functions. any time there's a call toget_*_struct_type
it can be cached. There are many repeated calls to get the same structure because the structure construction is often recursive.specifically "node wrapper" is a pseudo object that represents node and all afferent projections. it gets compiled into a single function and reuses the same data types as composition execute and run. Thus generating node wrapper IR code call composition
get_*_struct_type
.There are a few places that call
get_.*_struct_type(super())
, so I'm not sure what caching will do with those. It can "just work", but it might need a closer look