fix: bare tf.squeeze() breaks graph-mode shape inference in neglogliks - #25
Merged
Merged
Conversation
…s (v0.1.5) Squeeze-with-no-axis can't statically prove a None-shaped dim isn't 1 when train_step retraces for a differently-shaped batch (e.g. a partial final batch), degrading output shape to unknown rank and crashing posterior_from_negloglik_per_state with TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'. Delete the now-redundant squeezes (values are already rank-1 from column slicing) and pin shape explicitly via tf.ensure_shape. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
tf.squeeze()with noaxisdecides at trace time which size-1 dims to drop; whentrain_stepretraces for a differently-shaped batch (e.g. a partial/remainder final batch), it can't statically prove aNonedim isn't 1, so it degrades the whole output shape to unknown rank. That flows intoposterior_from_negloglik_per_stateand crashesmodel.fit()in graph mode withTypeError: unsupported operand type(s) for -: 'NoneType' and 'int'.NegloglikLoss,_negloglik_normal,NegloglikNormal,NegloglikExponential,NegloglikExponentialScale, andNegloglikWeibull(values are already rank-1 from column slicing) and pinned the output shape explicitly viatf.ensure_shape(losses, [None]).v0.1.5and updatedCHANGELOG.md.Test plan
n=200, batch_size=32) and asserts a finite loss — fails pre-fix, passes post-fix.pytest pypsps/, 93 passed).🤖 Generated with Claude Code