Support `math.floor` on symbolic scalars (`executorch_prim::floor.Scalar`)

未关闭
#25,772 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@abaybektursun 已经在做这个了。

开始于 2026年11月27日。

  • #25773 来自 @abaybektursun —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python, pytorch

调研方向

Start with exir/passes/executorch_prim_ops_registry.py and the existing ceil, round, and trunc mappings, then inspect their implementations in kernels/prim_ops/register_prim_ops.cpp. Add matching math.floor support for symbolic scalars and verify the reproduction through to_edge(ep).to_executorch(); done means lowering succeeds for the provided dynamically shaped example. An open linked pull request already tracks this issue.

由索引模型根据 Issue 内容生成。

描述

🐛 Describe the bug

Lowering a dynamically-shaped exported program that calls math.floor on a symbolic expression fails in to_executorch() with AttributeError: 'builtin_function_or_method' object has no attribute '_schema'.

ceil, round, and trunc are mapped in exir/passes/executorch_prim_ops_registry.py and implemented in kernels/prim_ops/register_prim_ops.cpp, but floor is not. EdgeToBackendOpsPass therefore leaves math.floor as a Python builtin, which fails in ToOutVarPass.

Hit while exporting Hugging Face Transformers vision models (Swin, FocalNet, Depth Pro); tracked in https://github.com/huggingface/transformers/issues/51303 (item 10).

import math

import torch
from executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner
from executorch.exir import to_edge_transform_and_lower


class M(torch.nn.Module):
    def forward(self, x):
        return x[: math.floor(x.shape[0] / 3)]


ep = torch.export.export(
    M(), (torch.randn(8, 4),), dynamic_shapes=({0: torch.export.Dim.AUTO},)
)

to_edge_transform_and_lower(ep, partitioner=[XnnpackPartitioner()]).to_executorch()
Traceback (most recent call last):
  File "repro.py", line 17, in <module>
    to_edge_transform_and_lower(ep, partitioner=[XnnpackPartitioner()]).to_executorch()
  File ".../executorch/exir/program/_program.py", line 118, in wrapper
    return func(*args, **kwargs)
  File ".../executorch/exir/program/_program.py", line 1823, in to_executorch
    new_gm_res = p(new_gm)
  File ".../torch/fx/passes/infra/pass_base.py", line 46, in __call__
    res = self.call(graph_module)
  File ".../executorch/exir/passes/__init__.py", line 378, in call
    elif _get_overload_schema(target).kind() == SchemaKind.inplace:
  File ".../executorch/exir/operator/convert.py", line 88, in _get_overload_schema
    native_schema = _pybind_schema_to_native_schema(op_overload._schema)
AttributeError: 'builtin_function_or_method' object has no attribute '_schema'

The same error happens without XnnpackPartitioner (to_edge(ep).to_executorch()).

Versions
ExecuTorch: 1.6.0 (main @ ddb19caa)
PyTorch version: 2.15.0
Is debug build: False
CUDA used to build PyTorch: None
ROCm SDK used to build PyTorch: N/A
HIP used to build PyTorch: N/A

OS: macOS 27.2.1 (arm64)
Clang version: 21.0.0 (clang-2100.4.1.1)
CMake version: version 4.3.1

Python version: 3.11.14 (64-bit runtime)
Python platform: macOS-27.2.1-arm64-arm-64bit
Is CUDA available: False
CPU: Apple M4 Pro
主要语言
Python
星标
5.2k
派生
1.3k
平均合并
1 天 7 小时
30 天内合并 PR
644

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

pytorch/executorch 的其他 Issue

查看 pytorch/executorch 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。