Skip to content

fix: bare tf.squeeze() breaks graph-mode shape inference in neglogliks - #25

Merged
gmgeorg merged 1 commit into
mainfrom
fix/squeeze-shape-inference
Aug 23, 2026
Merged

gmgeorg merged 1 commit into
mainfrom
fix/squeeze-shape-inference

Conversation

@gmgeorg

@gmgeorg gmgeorg commented Aug 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • tf.squeeze() with no axis decides at trace time which size-1 dims to drop; when train_step retraces for a differently-shaped batch (e.g. a partial/remainder final batch), it can't statically prove a None dim isn't 1, so it degrades the whole output shape to unknown rank. That flows into posterior_from_negloglik_per_state and crashes model.fit() in graph mode with TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'.
  • Removed the bare squeezes in NegloglikLoss, _negloglik_normal, NegloglikNormal, NegloglikExponential, NegloglikExponentialScale, and NegloglikWeibull (values are already rank-1 from column slicing) and pinned the output shape explicitly via tf.ensure_shape(losses, [None]).
  • Bumped version to v0.1.5 and updated CHANGELOG.md.

Test plan

  • Added a regression test parametrized over all four losses (exponential, exponential_scale, weibull, normal) that fits a model with a partial final batch (n=200, batch_size=32) and asserts a finite loss — fails pre-fix, passes post-fix.
  • Full test suite passes (pytest pypsps/, 93 passed).

🤖 Generated with Claude Code

…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>
@gmgeorg
gmgeorg merged commit 3e4c9b9 into main Aug 23, 2026
1 check passed
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.

1 participant