Store _prev as a tuple in sum() and mean() - #18
Merged
Conversation
Every op builds its _prev through _create_child, which normalises it with
tuple(prev). sum() and mean() instead set out._prev = {self} directly, so
those two nodes carried a set.
_eval_forward reads node._prev[0] to pull an operand, and indexing a set
raises "TypeError: 'set' object is not subscriptable". So evaluating any graph
that reduces with sum or mean, which is almost every loss, crashed.
Store (self,) in both methods so _prev is a tuple everywhere. Added a test
that evaluates a sum and a mean graph through _eval_forward.
Owner
|
Hi! Welcome to Leanpass, @eeshsaxena; this is a genuinely huge milestone for me. You are leanpass's FIRST contributor!! |
Owner
|
Good catch about |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #7.
The bug
Every op builds its
_prevthrough_create_child, which normalises the argument withtuple(prev).sum()andmean()skip that helper and assign the set directly:so those two nodes carry a
setwhile every other node carries a tuple._eval_forwardpulls operands by index:Indexing a set raises
TypeError: 'set' object is not subscriptable, so evaluating any graph that reduces withsumormean(which is almost every loss) crashes.The fix
Store
(self,)in both methods so_previs a tuple everywhere:Test
Added
test_eval_forward_handles_reductions, which runs asumgraph and ameangraph through_eval_forwardand checks the values (30.0 and 14/3). It raisesTypeErroronmainand passes with this change. The fulltests/test_gradcheck.pysuite passes locally.One heads-up while I was in there:
grad_checkhas a separate, unrelated problem where it perturbs the reduced output node (node.data[idx] = ...) whose data is a scalar, which raises'numpy.float64' object does not support item assignment. That is outside the scope of this fix, so I left it alone, but happy to open a follow-up if useful.