From ef5175344fa58d7387ccb8bf80dee6f44b833813 Mon Sep 17 00:00:00 2001 From: JiangDongHua <759421566@qq.com> Date: Wed, 21 Aug 2024 22:18:42 +0800 Subject: [PATCH 1/2] add Tensor method: new and new_ones --- python/oneflow/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/python/oneflow/__init__.py b/python/oneflow/__init__.py index 8706117f6a8..c51c1dc3444 100644 --- a/python/oneflow/__init__.py +++ b/python/oneflow/__init__.py @@ -508,3 +508,13 @@ def atexit_hook(hook): if oneflow._oneflow_internal.flags.with_mlir(): oneflow_internal_path = oneflow._oneflow_internal.__file__ oneflow._oneflow_internal.ir.load_jit_shared_lib(oneflow_internal_path) + +def flow_ones(self, *args, **kwargs): + return ones(*args, **kwargs, device=self.device, dtype=self.dtype) + +Tensor.new_ones = flow_ones + +def flow_zeros(self, *args, **kwargs): + return zeros(*args, **kwargs, device=self.device, dtype=self.dtype) + +Tensor.new = flow_zeros From ec74377ca9b9094fb655ab47566e0509d6cfc63c Mon Sep 17 00:00:00 2001 From: oneflow-ci-bot Date: Wed, 21 Aug 2024 14:22:43 +0000 Subject: [PATCH 2/2] auto format by CI --- python/oneflow/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/oneflow/__init__.py b/python/oneflow/__init__.py index c51c1dc3444..6cb20d920c4 100644 --- a/python/oneflow/__init__.py +++ b/python/oneflow/__init__.py @@ -509,12 +509,16 @@ def atexit_hook(hook): oneflow_internal_path = oneflow._oneflow_internal.__file__ oneflow._oneflow_internal.ir.load_jit_shared_lib(oneflow_internal_path) + def flow_ones(self, *args, **kwargs): return ones(*args, **kwargs, device=self.device, dtype=self.dtype) + Tensor.new_ones = flow_ones + def flow_zeros(self, *args, **kwargs): return zeros(*args, **kwargs, device=self.device, dtype=self.dtype) + Tensor.new = flow_zeros