Skip to content

[Bug] Unexpected Segmentation Fault with Relax R.astype When Tensor Shape is Miswritten #17370

@Thrsu

Description

@Thrsu

There seems to be an issue when using R.astype in TVM's Relax script with a tensor shape that does not include a comma in the shape definition. Specifically, when a tensor is defined with the shape (1) instead of (1,), a segmentation fault occurs. The script runs without issue when the shape is correctly specified as (1,).

Expected behavior

A segmentation fault should not occur in this scenario.

Actual behavior

error: object of type 'int' has no len()
 --> seg_bug.py:14:17
    |  
 14 |              gv: R.Tensor((1), dtype="float32") = R.astype(lv, dtype="float32")  # segfault
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                            
Segmentation fault (core dumped)

Steps to reproduce

import tvm
from tvm.script import ir as I
from tvm.script import relax as R

@I.ir_module
class Module:
    @R.function
    def main(z: R.Tensor((1, 4, 64, 64), dtype="float32")) -> R.Tensor((1, 512, 64, 64), dtype="float32"):
        with R.dataflow():
            lv: R.Tensor((1, 4, 64, 64), dtype="float16") = R.astype(z, dtype="float16")
            # gv: R.Tensor((1,), dtype="float32") = R.astype(lv, dtype="float32")  # This works fine
            gv: R.Tensor((1), dtype="float32") = R.astype(lv, dtype="float32")  # Segfault here
            R.output(gv)
        return gv

mod = Module
mod.show()
mod = tvm.relax.transform.LegalizeOps()(mod)
mod.show()

cc @Lunderberg @tqchen @junrushao

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triagePRs or issues that need to be investigated by maintainers to find the right assignees to address ittype: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions