8000 [BUG] tvm.contrib.sparse.placeholder cannot be used as argument for tvm.build() · Issue #8413 · apache/tvm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
[BUG] tvm.contrib.sparse.placeholder cannot be used as argument for tvm.build() #8413
Closed
@learning-chip

Description

@learning-chip

Problem description

tvm.contrib.sparse.placeholder is intended to be an input type for topi.sparse.csrmv (#1289, #1291 by @liangfu). However, passing sparse.placeholder to tvm.build leads to ValueError: don't know how to convert type <class 'tvm.contrib.sparse.CSRPlaceholderOp'> to object.

This is because tvm.contrib.sparse.CSRPlaceholderOp cannot pass the check inside tvm.runtime.object_generic.convert_to_object:

if isinstance(value, ObjectTypes):

where ObjectTypes is defined as :

ObjectTypes = (ObjectBase, NDArrayBase, Module, ObjectRValueRef, PyNativeObject)

Steps to reproduce

Build TVM 0.8.dev from the latest master branch, and then run:

# Adapted from https://github.com/apache/tvm/blob/main/tests/python/topi/python/test_topi_sparse.py
import tvm
from tvm import te
from tvm import topi
import tvm.contrib.sparse as tvmsp


def build_csrmv(use_sparse=False, dtype='float32', target='llvm'):
    nr, nc, nnz = te.var("nr"), te.var("nc"), te.var("nnz")
    
    A = tvmsp.placeholder(shape=(nr, nc), nonzeros=nnz, dtype=dtype, name="A")
    B = te.placeholder((nc, 1), dtype=dtype, name="B")
    OUT = topi.sparse.csrmv(A, B)
    s = te.create_schedule(OUT.op)
    
    if use_sparse:
        f = tvm.build(
            s, [nr, A, B, OUT], 
            target=target, name="csrmv"
        )
    else:
        f = tvm.build(
            s, [nr, A.data, A.indices, A.indptr, B, OUT], 
            target=target, name="csrmv"
        )
    
    return f

csrmv = build_csrmv()  # works, when passing separate components inside CSR matrix
csrmv_sp = build_csrmv(use_sparse=True)  # fails, when passing the CSR matrix as a whole

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0