pytorch / pytorch/executorch

[LLM runner] Align make_image_input HWC contract with runtime behavior

Open
#22,685 3 comments 0 reactions 3 assignees View on GitHub

@fatih-uzlmz is already working on this.

Since Sep 16, 2026.

bug module: llm
Dominant language
Python
Stars
5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
581

Description

Problem

The Python type stub and pybind docstring advertise HWC, 1xHWC, CHW, and 1xCHW image tensors. Runtime checks accept contiguous CHW and 1xCHW, but reject ordinary contiguous HWC and 1xHWC.

The implementation squeezes rank-4 input before checking ChannelsLast; PyTorch reports that memory format as false for the resulting rank-3 tensor, so the HWC branch is effectively unreachable. Direct tests with the built binding confirmed both CHW forms pass and both HWC forms fail.

The examples in #22620 document only the verified CHW behavior. Runtime and type-stub changes are intentionally excluded from that documentation-only PR.

Proposed resolution

Choose and enforce one contract:

  1. Implement real HWC and 1xHWC support with shape-aware conversion, or
  2. Remove the unreachable HWC path and narrow the pybind docstring and _llm_runner.pyi contract to contiguous CHW and 1xCHW.
Test plan

Add positive and negative coverage for all four layouts, both supported dtypes, invalid batch size, and noncontiguous tensors.

cc @larryliu0820 @cccclai @helunwencser @jackzhxng @digantdesai

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.