未验证 提交 4a8aa6d8 编写于 作者: F feifei-111 提交者: GitHub

fix conflict (#46388)

上级 6990edfe
...@@ -131,22 +131,34 @@ def monkey_patch_variable(): ...@@ -131,22 +131,34 @@ def monkey_patch_variable():
@static_only @static_only
def cpu(self): def cpu(self):
""" """
Variable should not have cpu() and cuda() interface. Variable should not have cpu() and cuda() interface.
But this interface can greatly facilitate dy2static. But this interface can greatly facilitate dy2static.
We do nothing here. We do nothing here.
""" """
return self return self
@static_only @static_only
def cuda(self): def cuda(self):
""" """
Variable should not have cpu() and cuda() interface. Variable should not have cpu() and cuda() interface.
But this interface can greatly facilitate dy2static. But this interface can greatly facilitate dy2static.
We do nothing here. We do nothing here.
""" """
return self return self
@static_only
def place(self):
"""
Variable don't have 'place' interface in static mode
But this interface can greatly facilitate dy2static.
So we give a warnning here and return None.
"""
warnings.warn(
"Variable do not have 'place' interface for static mode, try not to use it. None will be returned."
)
return None
def astype(self, dtype): def astype(self, dtype):
""" """
**Notes**: **Notes**:
...@@ -427,6 +439,7 @@ def monkey_patch_variable(): ...@@ -427,6 +439,7 @@ def monkey_patch_variable():
('astype', astype), ('astype', astype),
('cpu', cpu), ('cpu', cpu),
('cuda', cuda), ('cuda', cuda),
('place', place),
('append', append), ('append', append),
('item', _item), ('item', _item),
('pop', pop), ('pop', pop),
......
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import numpy as np
import paddle
import unittest
class TestPlace(unittest.TestCase):
def test_place(self):
paddle.enable_static()
x = paddle.to_tensor([1, 2, 3, 4])
self.assertTrue(x.place() == None)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册