Skip to content

Model tf.squeeze output shape by dropping singleton axes#379

Open
khatchad wants to merge 3 commits into
slice-shape-from-begin-sizefrom
squeeze-shape
Open

Model tf.squeeze output shape by dropping singleton axes#379
khatchad wants to merge 3 commits into
slice-shape-from-begin-sizefrom
squeeze-shape

Conversation

@khatchad

Copy link
Copy Markdown
Member

Models tf.squeeze's output shape, the tf.squeeze row of the pass_through audit wala#513 (Bucket 2a) — and the last corpus shape residual for the input-signature evaluation. Stacked on #375 (base branch slice-shape-from-begin-size): crf_forward's state only reaches (2, 4) once #375's tf.slice shape gives (2, 1, 4) to squeeze. Review/merge #375 first; this diff is squeeze-only.

Change

tf.squeeze was a pass_through alias, leaking the input shape unchanged. Replace it with a <new>+<return> summary paired with a dedicated Squeeze generator:

  • dtype inherits from input (via PassThroughUnaryTensorGenerator).
  • shape drops the singleton axes named by axis (negative axes count from the end), or every statically size-1 axis when axis is absent. Dynamic/symbolic dimensions are never dropped under the axis-absent form (not statically known to be 1); a named non-singleton axis falls back to ⊤ rather than producing a wrong shape.

Tests

  • testCrfForward's state (from tf.squeeze(tf.slice(...), [1])) tightens from the pre-squeeze (2, 1, 4) to (2, 4) — the corpus crf_* family is now fully shape-precise.
  • New tf2_test_squeeze.py + testSqueezeAxis (tf.squeeze(x, [1]) over (2, 1, 3, 1)(2, 3, 1)) and testSqueezeAll (tf.squeeze(x)(2, 3)).
  • Full suite green (excluding the unrelated com.ibm.wala.cast.python.jython.test resource bug, fixed in Scope com.ibm.wala.cast.python.jython.test's resource directory #377).

Progresses wala#513.

🤖 Generated with Claude Code

`tf.squeeze` was a `pass_through` alias, leaking the input shape
unchanged. Replace it with a `<new>+<return>` summary paired with a
dedicated `Squeeze` generator (the Bucket 2a pattern from wala#513):
dtype inherits from `input`; the output shape drops the singleton axes
named by `axis`, or every statically size-1 axis when `axis` is absent.
Dynamic/symbolic dimensions are never dropped under the axis-absent form
(not statically known to be 1), and a named non-singleton axis falls back
to ⊤ rather than producing a wrong shape.

Closes the last corpus shape residual on the dtype-already-concrete
`crf_forward`: `state` (from `tf.squeeze(tf.slice(...), [1])`) now infers
as `(2, 4)` instead of the pre-squeeze `(2, 1, 4)`. Adds
`tf2_test_squeeze.py` with `testSqueezeAxis` (named axis) and
`testSqueezeAll` (all size-1 axes). Full suite green.

Progresses wala#513 (the `tf.squeeze` row of the `pass_through` audit).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 11, 2026 13:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the TensorFlow modeling in WALA’s Python ML analysis by making tf.squeeze shape-aware instead of treating it as a shape pass-through, enabling tighter inferred tensor shapes in the corpus and in dedicated squeeze tests.

Changes:

  • Model tf.squeeze as a dedicated TensorFlow function (<new> + <return>) and route it to a new Squeeze tensor generator.
  • Implement shape derivation for tf.squeeze by removing singleton axes (either specified by axis or all statically-known 1 dims when axis is absent), while preserving dtype via PassThroughUnaryTensorGenerator.
  • Add/extend tests to pin inferred shapes for both tf.squeeze(x, [axis]) and tf.squeeze(x) and tighten the crf_forward expectation.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
com.ibm.wala.cast.python.test/data/tf2_test_squeeze.py New TF2 test program exercising tf.squeeze with and without an axis argument.
com.ibm.wala.cast.python.ml/source/com/ibm/wala/cast/python/ml/types/TensorFlowTypes.java Adds a MethodReference and signature entry for tf.squeeze.
com.ibm.wala.cast.python.ml/source/com/ibm/wala/cast/python/ml/client/TensorGeneratorFactory.java Routes tf.squeeze calls to the new Squeeze generator.
com.ibm.wala.cast.python.ml/source/com/ibm/wala/cast/python/ml/client/Squeeze.java New generator implementing squeeze axis resolution and output-shape derivation.
com.ibm.wala.cast.python.ml/data/tensorflow.xml Replaces squeeze’s prior pass_through alias with a modeled function class and do() method returning a tensor.
com.ibm.wala.cast.python.ml.test/source/com/ibm/wala/cast/python/ml/test/TestTensorflow2Model.java Updates testCrfForward expected shape and adds testSqueezeAxis/testSqueezeAll.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.28916% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.68%. Comparing base (56ccf7b) to head (85d312e).

Files with missing lines Patch % Lines
...ce/com/ibm/wala/cast/python/ml/client/Squeeze.java 65.15% 9 Missing and 14 partials ⚠️
Additional details and impacted files
@@                      Coverage Diff                       @@
##             slice-shape-from-begin-size     #379   +/-   ##
==============================================================
  Coverage                          71.68%   71.68%           
- Complexity                          2744     2767   +23     
==============================================================
  Files                                272      273    +1     
  Lines                              20393    20475   +82     
  Branches                            3298     3322   +24     
==============================================================
+ Hits                               14618    14677   +59     
- Misses                              4475     4484    +9     
- Partials                            1300     1314   +14     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

khatchad and others added 2 commits June 11, 2026 09:54
Address review: a named axis out of `[-rank, rank)` now falls back to ⊤
(was silently ignored, leaving the shape unsqueezed), and a named axis
is dropped only when it is statically size-1 (a dynamic/symbolic
dimension now falls back to ⊤ instead of being assumed squeezable). The
corpus and standalone cases are unaffected — their named axes are
constant 1.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Adds `testSqueezeSingleAxis` (`tf.squeeze(x, 1)`, exercising the
constant-integer axis branch of `resolveAxisInts`) and
`testSqueezeMultiAxis` (`tf.squeeze(x, [1, 3])`, exercising multi-element
axis normalization), closing the patch-coverage gap on the new generator.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

2 participants