This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch refactor-s3
in repository https://gitbox.apache.org/repos/asf/tvm.git

commit 1f556e03a909e95911cd3be087831a03033b9f88
Author: tqchen <[email protected]>
AuthorDate: Sun May 4 11:53:51 2025 -0400

    Phase out asnumpy() in favor of numpy()
---
 python/tvm/contrib/msc/core/frontend/translate.py              |  4 ++--
 python/tvm/contrib/msc/core/tools/prune/pruner.py              |  2 +-
 python/tvm/contrib/msc/core/utils/info.py                      |  2 +-
 .../contrib/msc/framework/tensorrt/tools/quantize/quantizer.py |  2 +-
 .../tvm/contrib/msc/framework/tensorrt/tools/track/tracker.py  |  4 ++--
 python/tvm/contrib/msc/framework/torch/codegen/codegen.py      |  2 +-
 python/tvm/runtime/ndarray.py                                  | 10 ----------
 tests/python/contrib/test_hexagon/infrastructure.py            |  2 +-
 tests/python/contrib/test_hexagon/test_async_dma_pipeline.py   |  2 +-
 tests/python/contrib/test_hexagon/test_parallel_hvx.py         |  2 +-
 .../python/contrib/test_hexagon/test_parallel_hvx_load_vtcm.py |  4 ++--
 tests/python/contrib/test_hexagon/test_parallel_scalar.py      |  2 +-
 tests/python/contrib/test_hexagon/test_vtcm_bandwidth.py       |  2 +-
 tests/python/contrib/test_msc/test_plugin.py                   |  2 +-
 tests/python/contrib/test_msc/test_translate_tensorrt.py       |  4 ++--
 tests/python/meta_schedule/test_meta_schedule_runner.py        |  4 ++--
 tests/python/relax/test_op_misc.py                             |  2 +-
 tests/python/relax/test_runtime_sampling_flashinfer.py         |  2 +-
 tests/python/relax/test_vm_cuda_graph.py                       |  2 +-
 19 files changed, 23 insertions(+), 33 deletions(-)

diff --git a/python/tvm/contrib/msc/core/frontend/translate.py 
b/python/tvm/contrib/msc/core/frontend/translate.py
index 00621adfdc..687d770c93 100644
--- a/python/tvm/contrib/msc/core/frontend/translate.py
+++ b/python/tvm/contrib/msc/core/frontend/translate.py
@@ -88,7 +88,7 @@ def normalize_weights(
         weight_t = graph.find_tensor(ref_t.name)
         if weight_t.ndim == 1:
             if ref_t.ndim != weight_t.ndim:
-                return 
tvm.nd.array(data.asnumpy().reshape(weight_t.get_shape()))
+                return tvm.nd.array(data.numpy().reshape(weight_t.get_shape()))
             return data
         if ref_t.layout and weight_t.layout:
             ref_layout, weight_layout = ref_t.layout.name, weight_t.layout.name
@@ -97,7 +97,7 @@ def normalize_weights(
                     l in ref_layout for l in weight_layout
                 ), "layout mismatch {} compare to {}".format(ref_t, weight_t)
                 permute = [ref_layout.index(l) for l in weight_layout]
-                return tvm.nd.array(data.asnumpy().transpose(*permute))
+                return tvm.nd.array(data.numpy().transpose(*permute))
         return data
 
     weights = {t.name: _to_data(t, d) for t, d in t_weights.items() if 
graph.has_tensor(t.name)}
diff --git a/python/tvm/contrib/msc/core/tools/prune/pruner.py 
b/python/tvm/contrib/msc/core/tools/prune/pruner.py
index a008100be2..38f855d0eb 100644
--- a/python/tvm/contrib/msc/core/tools/prune/pruner.py
+++ b/python/tvm/contrib/msc/core/tools/prune/pruner.py
@@ -440,7 +440,7 @@ class BasePruner(WeightTool):
                 pruned_graphs.append(graph)
 
         def _flatten_size(weights):
-            weight_size = sum([w.asnumpy().size for w in weights.values()])
+            weight_size = sum([w.numpy().size for w in weights.values()])
             return weight_size / 2**20
 
         raw_size = _flatten_size(weights)
diff --git a/python/tvm/contrib/msc/core/utils/info.py 
b/python/tvm/contrib/msc/core/utils/info.py
index 2f927153c9..189dd3ebbb 100644
--- a/python/tvm/contrib/msc/core/utils/info.py
+++ b/python/tvm/contrib/msc/core/utils/info.py
@@ -96,7 +96,7 @@ class MSCArray(object):
             if self._type == "var":
                 shape = [int(s) for s in self._meta_data.struct_info.shape]
                 return np.zeros(shape, dtype=self._meta_data.struct_info.dtype)
-            return self._meta_data.asnumpy()
+            return self._meta_data.numpy()
         if self._framework == MSCFramework.TORCH:
             return self._meta_data.detach().cpu().numpy()
         return self._meta_data
diff --git 
a/python/tvm/contrib/msc/framework/tensorrt/tools/quantize/quantizer.py 
b/python/tvm/contrib/msc/framework/tensorrt/tools/quantize/quantizer.py
index ca2d78c427..88cc55a65e 100644
--- a/python/tvm/contrib/msc/framework/tensorrt/tools/quantize/quantizer.py
+++ b/python/tvm/contrib/msc/framework/tensorrt/tools/quantize/quantizer.py
@@ -186,7 +186,7 @@ class TensorRTQuantizerFactory(object):
                 if self._stage == QuantizeStage.GATHER:
                     saver = self._calibrate_savers[self._graph_id]
                     saver.save_batch(
-                        {name: data.asnumpy() for name, data in 
step_context["datas"].items()}
+                        {name: data.numpy() for name, data in 
step_context["datas"].items()}
                     )
                     for name, data in step_context["datas"].items():
                         self.debug_tensors(name, "any", "ctx_gather", 
{"gather": data})
diff --git a/python/tvm/contrib/msc/framework/tensorrt/tools/track/tracker.py 
b/python/tvm/contrib/msc/framework/tensorrt/tools/track/tracker.py
index fa59131ff4..7d4b686ce8 100644
--- a/python/tvm/contrib/msc/framework/tensorrt/tools/track/tracker.py
+++ b/python/tvm/contrib/msc/framework/tensorrt/tools/track/tracker.py
@@ -82,7 +82,7 @@ class TensorRTTrackerFactory(object):
                         continue
                     consumer = self._track_tensors[name]["consumer"]
                     strategys = self._get_tensor_strategys(name, consumer)
-                    self._track_tensor(data.asnumpy(), name, consumer, 
strategys)
+                    self._track_tensor(data.numpy(), name, consumer, strategys)
                 return super()._execute_before_forward(step_context)
 
             def _execute_after_forward(self, step_context: dict) -> dict:
@@ -104,7 +104,7 @@ class TensorRTTrackerFactory(object):
                         continue
                     consumer = self._track_tensors[name]["consumer"]
                     strategys = self._get_tensor_strategys(name, consumer)
-                    self._track_tensor(data.asnumpy(), name, consumer, 
strategys)
+                    self._track_tensor(data.numpy(), name, consumer, strategys)
                 return super()._execute_after_forward(step_context)
 
             def _process_tensor(
diff --git a/python/tvm/contrib/msc/framework/torch/codegen/codegen.py 
b/python/tvm/contrib/msc/framework/torch/codegen/codegen.py
index bb3082e5d8..5ca5de4006 100644
--- a/python/tvm/contrib/msc/framework/torch/codegen/codegen.py
+++ b/python/tvm/contrib/msc/framework/torch/codegen/codegen.py
@@ -66,7 +66,7 @@ def to_torch(
                     continue
                 w_tensor = graph.find_tensor(name)
                 w_name = w_tensor.alias or name
-                state_dict[w_name] = torch.from_numpy(data.asnumpy())
+                state_dict[w_name] = torch.from_numpy(data.numpy())
             torch.save(state_dict, folder.relpath(graph.name + ".pth"))
 
     def _bind_weights(model: torch.nn.Module, folder: msc_utils.MSCDirectory) 
-> torch.nn.Module:
diff --git a/python/tvm/runtime/ndarray.py b/python/tvm/runtime/ndarray.py
index 0db6d9f875..a939c0a875 100644
--- a/python/tvm/runtime/ndarray.py
+++ b/python/tvm/runtime/ndarray.py
@@ -151,16 +151,6 @@ class NDArray(tvm.ffi.core.NDArray):
     def __str__(self):
         return str(self.numpy())
 
-    def asnumpy(self):
-        """Convert this array to numpy array. This API will be deprecated in 
TVM v0.8 release.
-        Please use `numpy` instead."""
-        warnings.warn(
-            "NDArray.asnumpy() will be deprecated in TVM v0.8 release. "
-            "Please use NDArray.numpy() instead.",
-            DeprecationWarning,
-        )
-        return self.numpy()
-
     def numpy(self):
         """Convert this array to numpy array
 
diff --git a/tests/python/contrib/test_hexagon/infrastructure.py 
b/tests/python/contrib/test_hexagon/infrastructure.py
index 8d3ed034b5..376cc8c7da 100644
--- a/tests/python/contrib/test_hexagon/infrastructure.py
+++ b/tests/python/contrib/test_hexagon/infrastructure.py
@@ -109,7 +109,7 @@ def build_and_run(inputs, func, target: str, target_host: 
str, *args, **kwargs):
     )
     func(*tensors)
 
-    return tensors[-1].asnumpy()
+    return tensors[-1].numpy()
 
 
 def run_module(mod, inputs):
diff --git a/tests/python/contrib/test_hexagon/test_async_dma_pipeline.py 
b/tests/python/contrib/test_hexagon/test_async_dma_pipeline.py
index 6b5c44d56a..fe7a615531 100644
--- a/tests/python/contrib/test_hexagon/test_async_dma_pipeline.py
+++ b/tests/python/contrib/test_hexagon/test_async_dma_pipeline.py
@@ -295,7 +295,7 @@ def evaluate(
 
     time = timer(a_hexagon, b_hexagon, c_hexagon)
     if expected_output is not None:
-        tvm.testing.assert_allclose(c_hexagon.asnumpy(), expected_output)
+        tvm.testing.assert_allclose(c_hexagon.numpy(), expected_output)
     return round(time.mean * 1000, 4)
 
 
diff --git a/tests/python/contrib/test_hexagon/test_parallel_hvx.py 
b/tests/python/contrib/test_hexagon/test_parallel_hvx.py
index 679321aba7..8f77fa1c40 100644
--- a/tests/python/contrib/test_hexagon/test_parallel_hvx.py
+++ b/tests/python/contrib/test_hexagon/test_parallel_hvx.py
@@ -163,7 +163,7 @@ def evaluate(hexagon_session, shape_dtypes, 
expected_output_producer, sch):
         "__tvm_main__", hexagon_session.device, number=number, repeat=repeat
     )
     runtime = timer(a_hexagon, b_hexagon, c_hexagon)
-    tvm.testing.assert_allclose(c_hexagon.asnumpy(), 
expected_output_producer(c_shape, a, b))
+    tvm.testing.assert_allclose(c_hexagon.numpy(), 
expected_output_producer(c_shape, a, b))
 
     return round(runtime.mean * 1000, 6)
 
diff --git a/tests/python/contrib/test_hexagon/test_parallel_hvx_load_vtcm.py 
b/tests/python/contrib/test_hexagon/test_parallel_hvx_load_vtcm.py
index 3c21e8a9f6..a584997dd5 100644
--- a/tests/python/contrib/test_hexagon/test_parallel_hvx_load_vtcm.py
+++ b/tests/python/contrib/test_hexagon/test_parallel_hvx_load_vtcm.py
@@ -335,7 +335,7 @@ def setup_and_run(hexagon_session, sch, a, b, c, 
operations, mem_scope="global")
     )
     time = timer(a_hexagon, b_hexagon, c_hexagon)
     gops = round(operations * 128 * 3 / time.mean / 1e9, 4)
-    return gops, c_hexagon.asnumpy()
+    return gops, c_hexagon.numpy()
 
 
 def setup_and_run_preallocated(hexagon_session, sch, a, b, c, operations):
@@ -369,7 +369,7 @@ def setup_and_run_preallocated(hexagon_session, sch, a, b, 
c, operations):
     )
     time = timer(a_hexagon, b_hexagon, c_hexagon, a_vtcm_hexagon, 
b_vtcm_hexagon, c_vtcm_hexagon)
     gops = round(operations * 128 * 3 / time.mean / 1e9, 4)
-    return gops, c_hexagon.asnumpy()
+    return gops, c_hexagon.numpy()
 
 
 class TestMatMulVec:
diff --git a/tests/python/contrib/test_hexagon/test_parallel_scalar.py 
b/tests/python/contrib/test_hexagon/test_parallel_scalar.py
index d76f2b53a1..bd9c78d5da 100644
--- a/tests/python/contrib/test_hexagon/test_parallel_scalar.py
+++ b/tests/python/contrib/test_hexagon/test_parallel_scalar.py
@@ -109,7 +109,7 @@ def evaluate(hexagon_session, operations, expected, sch):
     )
     runtime = timer(a_hexagon, b_hexagon, c_hexagon)
 
-    tvm.testing.assert_allclose(c_hexagon.asnumpy(), expected(a, b))
+    tvm.testing.assert_allclose(c_hexagon.numpy(), expected(a, b))
 
     return round(runtime.mean * 1000, 6)
 
diff --git a/tests/python/contrib/test_hexagon/test_vtcm_bandwidth.py 
b/tests/python/contrib/test_hexagon/test_vtcm_bandwidth.py
index 9e0b7920b4..931f99b2ec 100644
--- a/tests/python/contrib/test_hexagon/test_vtcm_bandwidth.py
+++ b/tests/python/contrib/test_hexagon/test_vtcm_bandwidth.py
@@ -115,7 +115,7 @@ def evaluate(hexagon_session, sch, size):
     runtime = timer(a_hexagon, a_vtcm_hexagon)
 
     gbps = round((size / 2**30) / runtime.mean, 4)
-    tvm.testing.assert_allclose(a_vtcm_hexagon.asnumpy(), a)
+    tvm.testing.assert_allclose(a_vtcm_hexagon.numpy(), a)
 
     return gbps
 
diff --git a/tests/python/contrib/test_msc/test_plugin.py 
b/tests/python/contrib/test_msc/test_plugin.py
index 30eb6dd067..3cacb8a646 100644
--- a/tests/python/contrib/test_msc/test_plugin.py
+++ b/tests/python/contrib/test_msc/test_plugin.py
@@ -265,7 +265,7 @@ def _run_relax(relax_mod, target_name, data):
         relax_exec = tvm.compile(relax_mod, target)
         runnable = tvm.relax.VirtualMachine(relax_exec, device)
     data = tvm.nd.array(data, device)
-    return runnable["main"](data).asnumpy()
+    return runnable["main"](data).numpy()
 
 
 def _test_tvm_plugin(manager, target):
diff --git a/tests/python/contrib/test_msc/test_translate_tensorrt.py 
b/tests/python/contrib/test_msc/test_translate_tensorrt.py
index ab0f8be148..a3eaae09af 100644
--- a/tests/python/contrib/test_msc/test_translate_tensorrt.py
+++ b/tests/python/contrib/test_msc/test_translate_tensorrt.py
@@ -48,8 +48,8 @@ def build_and_run(mod, inputs):
         runnable = tvm.relax.VirtualMachine(rt_mod, tvm.cuda())
     res = runnable["main"](*inputs)
     if isinstance(res, tvm.runtime.NDArray):
-        return [res.asnumpy()]
-    return [e.asnumpy() for e in res]
+        return [res.numpy()]
+    return [e.numpy() for e in res]
 
 
 def check_names(mod):
diff --git a/tests/python/meta_schedule/test_meta_schedule_runner.py 
b/tests/python/meta_schedule/test_meta_schedule_runner.py
index 1b47abfa09..03ab8c58b4 100644
--- a/tests/python/meta_schedule/test_meta_schedule_runner.py
+++ b/tests/python/meta_schedule/test_meta_schedule_runner.py
@@ -830,7 +830,7 @@ def test_meta_schedule_local_runner_add_test():
         repeated_args_before = []
         repeated_args = local_default_alloc_argument(device, args_info, 
alloc_repeat)
         for args in repeated_args:
-            repeated_args_before.append([arg.asnumpy() for arg in args])
+            repeated_args_before.append([arg.numpy() for arg in args])
         return repeated_args
 
     def test_run_evaluator(
@@ -856,7 +856,7 @@ def test_meta_schedule_local_runner_add_test():
             device.sync()
             profile_result = evaluator(*args)
             repeated_costs.append(profile_result.results)
-            repeated_args_after.append([arg.asnumpy() for arg in args])
+            repeated_args_after.append([arg.numpy() for arg in args])
         costs = [float(cost) for cost in 
itertools.chain.from_iterable(repeated_costs)]
         for args_before, args_after in zip(repeated_args_before, 
repeated_args_after):
             _check_correct_add(args_before, args_after)
diff --git a/tests/python/relax/test_op_misc.py 
b/tests/python/relax/test_op_misc.py
index f786b89043..b53c10b369 100644
--- a/tests/python/relax/test_op_misc.py
+++ b/tests/python/relax/test_op_misc.py
@@ -23,7 +23,7 @@ from tvm.script import tir as T
 
 @tvm.register_func("test.op.identity", override=True)
 def identity_packed(a):
-    return tvm.nd.array(a.asnumpy())
+    return tvm.nd.array(a.numpy())
 
 
 @T.prim_func
diff --git a/tests/python/relax/test_runtime_sampling_flashinfer.py 
b/tests/python/relax/test_runtime_sampling_flashinfer.py
index 7b6deb6f02..dc3a3c86e6 100644
--- a/tests/python/relax/test_runtime_sampling_flashinfer.py
+++ b/tests/python/relax/test_runtime_sampling_flashinfer.py
@@ -75,7 +75,7 @@ def test_sampling():
         # the kernel expects (probs, output, maybe_indices, deterministic, 
philox_seed, philox_offset, cuda_stream)
         sampling_func(prob_tvm, output_tvm, None, deterministic, philox_seed, 
philox_offset, 0)
 
-        out = output_tvm.asnumpy()
+        out = output_tvm.numpy()
         for i in range(batch_size):
             sampled_token = out[i]
             counts[i, sampled_token] += 1
diff --git a/tests/python/relax/test_vm_cuda_graph.py 
b/tests/python/relax/test_vm_cuda_graph.py
index 69c04eeca4..1026864e4f 100644
--- a/tests/python/relax/test_vm_cuda_graph.py
+++ b/tests/python/relax/test_vm_cuda_graph.py
@@ -104,7 +104,7 @@ def test_vm_run():
     x = tvm.nd.array(x_np, dev)
     y = vm["main"](x)
     y_np = x_np + 1.0 + 1.0 + 1.0 + 1.0
-    tvm.testing.assert_allclose(y.asnumpy(), y_np, rtol=1e-5, atol=1e-5)
+    tvm.testing.assert_allclose(y.numpy(), y_np, rtol=1e-5, atol=1e-5)
 
 
 @tvm.testing.requires_cudagraph

Reply via email to