pytorch / pytorch/executorch

Vulkan model with (adaptive) avgpool1d (or maxpool1d) fail to load

Open
#12,224 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

🐛 Describe the bug

Some models containing avgpool1d ops delegated to Vulkan fail to load with following error: IndexError: vector::_M_range_check: __n (which is 18446744073709551614) >= this->size() (which is 4). Maxpool1d fails in the same way, as do the adaptive versions of both avgpool and maxpool.

import torch
from executorch.backends.vulkan.partitioner.vulkan_partitioner import VulkanPartitioner
from executorch.exir import to_edge_transform_and_lower, EdgeCompileConfig, to_edge
from executorch.extension.pybindings.portable_lib import _load_for_executorch_from_buffer

class Model(torch.nn.Module):
    def __init__(
        self,
        kernel_size=3,
        stride=None,
        padding=0,
        ceil_mode=False,
        count_include_pad=True,
    ):
        super().__init__()
        self.avgpool = torch.nn.AvgPool1d(
            kernel_size=kernel_size,
            stride=stride,
            padding=padding,
            ceil_mode=ceil_mode,
            count_include_pad=count_include_pad,
        )
        
    def forward(self, x):
        return self.avgpool(x)
        
model = Model()
inputs = (
    torch.randn(1, 3, 10),
)
eager_outputs = model(*inputs)

ep = torch.export.export(model.eval(), inputs)
print(ep)
lowered = to_edge_transform_and_lower(
    ep,
    partitioner=[VulkanPartitioner()],
    compile_config=EdgeCompileConfig(_check_ir_validity=False)
).to_executorch()
print(lowered.exported_program())

et_model = _load_for_executorch_from_buffer(lowered.buffer)
et_outputs = et_model([*inputs])[0]

print(f"Inputs: {inputs}")
print(f"Eager: {eager_outputs}")
print(f"ET:    {et_outputs}")

Outputs:

IndexError: vector::_M_range_check: __n (which is 18446744073709551614) >= this->size() (which is 4)
Traceback
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[13], line 42
     35 lowered = to_edge_transform_and_lower(
     36     ep,
     37     partitioner=[VulkanPartitioner()],
     38     compile_config=EdgeCompileConfig(_check_ir_validity=False)
     39 ).to_executorch()
     40 print(lowered.exported_program())
---> 42 et_model = _load_for_executorch_from_buffer(lowered.buffer)
     43 et_outputs = et_model([*inputs])[0]
     45 print(f"Inputs: {inputs}")
IndexError: vector::_M_range_check: __n (which is 18446744073709551614) >= this->size() (which is 4)
Versions

Run on Meta internal master, Jul 3, fbcode/SwiftShader

cc @SS-JIA @manuelcandales @cbilgin

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.

Research direction

Start with the provided Python reproduction and the VulkanPartitioner entry point, then trace how AvgPool1d, MaxPool1d, and their adaptive variants are lowered and loaded. Done means the listed pooling models load from the lowered buffer without the vector range-check IndexError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.