Fix resize_with_pad_torch dropping the batch dimension for a single-image batch - #1016
Open
ousamabenyounes wants to merge 1 commit into
Open
Fix resize_with_pad_torch dropping the batch dimension for a single-image batch#1016ousamabenyounes wants to merge 1 commit into
ousamabenyounes wants to merge 1 commit into
Conversation
…mage batch resize_with_pad_torch squeezed dim 0 whenever the batch size was 1, so a channels-last [1, H, W, C] input was returned as a 3D [H, W, C] tensor. This diverged from the JAX resize_with_pad, which preserves the input rank. Track whether a batch dimension was added internally and drop only that one, keeping a genuine size-1 batch intact for both channel orders. Fix Physical-Intelligence#805
ousamabenyounes
requested review from
Michael-Equi,
jimmyt857 and
kvablack
as code owners
August 15, 2026 01:51
jimmyt857
removed their request for review
August 15, 2026 01:56
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
Fix #805.
resize_with_pad_torchdropped the batch dimension for a single-image batch,diverging from the JAX
resize_with_pad, which preserves the input rank.For a channels-last 4D input of shape
[1, H, W, C]the function returned a 3D[H', W', C]tensor, because the final block squeezed dim 0 wheneverbatch_size == 1— regardless of whether the batch dimension was genuinelypresent in the input or had been added internally for a 3D image:
This breaks callers that feed batched observations (e.g.
Observation.from_dictwith an image of shape
(1, 3, 480, 640)) into the PyTorch path, and isinconsistent with the JAX reference which keeps
[1, H, W, C]as[1, H', W', C].Fix
Track whether a batch dimension was added internally (mirroring the JAX
has_batch_dim) and squeeze it back only in that case, for both channels-lastand channels-first inputs. A genuine size-1 batch is now preserved.
Test verification (RED → GREEN)
New regression test
test_resize_with_pad_torch_preserves_batch_diminsrc/openpi/shared/image_tools_test.py.RED — new test on
mainwith the fix reverted (prod code only):GREEN — with the fix:
ruff check .andruff format --checkare clean on the changed files.Files changed
src/openpi/shared/image_tools.pysrc/openpi/shared/image_tools_test.pyFull local suite
Local CI mirrors
.github/workflows/{test,pre-commit}.yml(
ruff check .,ruff format --check,uv run pytest --strict-markers -m "not manual"):ruff check .— all checks passed.ruff format --check— clean on the changed files (2 pre-existing, unrelateddrifted files in
examples/are unchanged here).new regression test. Two GPU-scale model-build tests
(
src/openpi/models/model_test.py,scripts/train_test.py::test_train[debug])are OOM-killed on the local 15 GiB host — identically on the unmodified
mainbaseline — so this is a pre-existing environment limit, not a regression from
this change. This diff only touches
image_tools, which those tests do notexercise; GitHub CI runs the full matrix.