Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Testing] Add tvm.testing.local_run #15268

Merged

Conversation

junrushao
Copy link
Member

This PR introduces tvm.testing.local_run, which serves as a convenient numpy-in numpy-out interface to quickly run a runtime.Module in TVM and obtain its running time and outputs.

Example:

@I.ir_module
class Module:
  ...

n = 128
np_a = np.random.uniform(-1, 1, [1, 32, 1, 128]).astype(np.float16)
np_b = np.random.uniform(-1, 1, [1, 32, n, 128]).astype(np.float16)
np_c = np.random.uniform(-1, 1, [1, 1, 1, n]).astype(np.float16)
np_d = np.random.uniform(-1, 1, [1, 32, 1, n]).astype(np.float32)

_, _, _, np_d = local_run(
    tvm.build(Module, target="llvm"),
    device_type="cpu",
    args=[np_a, np_b, np_c, np_d],
)

This PR introduces `tvm.testing.local_run`, which serves as a convenient
numpy-in numpy-out interface to quickly run a `runtime.Module` in TVM
and obtain its running time and outputs.

Example:

```python

@I.ir_module
class Module:
  ...

n = 128
np_a = np.random.uniform(-1, 1, [1, 32, 1, 128]).astype(np.float16)
np_b = np.random.uniform(-1, 1, [1, 32, n, 128]).astype(np.float16)
np_c = np.random.uniform(-1, 1, [1, 1, 1, n]).astype(np.float16)
np_d = np.random.uniform(-1, 1, [1, 32, 1, n]).astype(np.float32)

_, _, _, np_d = local_run(
    tvm.build(Module, target="llvm"),
    device_type="cpu",
    args=[np_a, np_b, np_c, np_d],
)
```
@tvm-bot
Copy link
Collaborator

tvm-bot commented Jul 8, 2023

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

  • No users to tag found in teams: testing See #10317 for details

Generated by tvm-bot

@junrushao junrushao marked this pull request as ready for review July 8, 2023 20:39
@junrushao junrushao merged commit 0c1aad7 into apache:main Jul 9, 2023
6 of 7 checks passed
junrushao added a commit to junrushao/tvm that referenced this pull request Jul 15, 2023
This PR introduces `tvm.testing.local_run`, which serves as a convenient
numpy-in numpy-out interface to quickly run a `runtime.Module` in TVM
and obtain its running time and outputs.

Example:

```python

@I.ir_module
class Module:
  ...

n = 128
np_a = np.random.uniform(-1, 1, [1, 32, 1, 128]).astype(np.float16)
np_b = np.random.uniform(-1, 1, [1, 32, n, 128]).astype(np.float16)
np_c = np.random.uniform(-1, 1, [1, 1, 1, n]).astype(np.float16)
np_d = np.random.uniform(-1, 1, [1, 32, 1, n]).astype(np.float32)

_, _, _, np_d = local_run(
    tvm.build(Module, target="llvm"),
    device_type="cpu",
    args=[np_a, np_b, np_c, np_d],
)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants