From a1f727e9f8439e2c51f3469cc9dfd612a1fb815d Mon Sep 17 00:00:00 2001 From: algorithm1832 <737634857@qq.com> Date: Tue, 31 Mar 2026 17:32:40 +0000 Subject: [PATCH 1/2] add alias for once_differentiable --- python/paddle/autograd/function.py | 5 +++- test/autograd/test_once_differentiable.py | 28 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/autograd/test_once_differentiable.py diff --git a/python/paddle/autograd/function.py b/python/paddle/autograd/function.py index c796969be8a9ba..7787bbe9bf260c 100644 --- a/python/paddle/autograd/function.py +++ b/python/paddle/autograd/function.py @@ -12,4 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .py_layer import PyLayerContext as FunctionCtx # noqa: F401 +from .py_layer import ( + PyLayerContext as FunctionCtx, # noqa: F401 + once_differentiable as once_differentiable, +) diff --git a/test/autograd/test_once_differentiable.py b/test/autograd/test_once_differentiable.py new file mode 100644 index 00000000000000..53f64a7b046050 --- /dev/null +++ b/test/autograd/test_once_differentiable.py @@ -0,0 +1,28 @@ +# Copyright (c) 2026 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. + +import unittest + +import paddle + + +class TestOnceDifferentiable(unittest.TestCase): + def test_once_differentiable_compatibility(self): + pyLayerObj = paddle.autograd.py_layer.once_differentiable + functionObj = paddle.autograd.function.once_differentiable + self.assertEqual(pyLayerObj, functionObj) + + +if __name__ == '__main__': + unittest.main() From 0252b730142f6520d22376a153fa0c721e488f6c Mon Sep 17 00:00:00 2001 From: algorithm1832 <737634857@qq.com> Date: Thu, 2 Apr 2026 06:59:41 +0000 Subject: [PATCH 2/2] move test --- python/paddle/autograd/function.py | 2 +- test/autograd/test_once_differentiable.py | 28 ---------------------- test/legacy_test/test_autograd_function.py | 5 ++++ 3 files changed, 6 insertions(+), 29 deletions(-) delete mode 100644 test/autograd/test_once_differentiable.py diff --git a/python/paddle/autograd/function.py b/python/paddle/autograd/function.py index 7787bbe9bf260c..a8f1890a8637b4 100644 --- a/python/paddle/autograd/function.py +++ b/python/paddle/autograd/function.py @@ -14,5 +14,5 @@ from .py_layer import ( PyLayerContext as FunctionCtx, # noqa: F401 - once_differentiable as once_differentiable, + once_differentiable, # noqa: F401 ) diff --git a/test/autograd/test_once_differentiable.py b/test/autograd/test_once_differentiable.py deleted file mode 100644 index 53f64a7b046050..00000000000000 --- a/test/autograd/test_once_differentiable.py +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright (c) 2026 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. - -import unittest - -import paddle - - -class TestOnceDifferentiable(unittest.TestCase): - def test_once_differentiable_compatibility(self): - pyLayerObj = paddle.autograd.py_layer.once_differentiable - functionObj = paddle.autograd.function.once_differentiable - self.assertEqual(pyLayerObj, functionObj) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/legacy_test/test_autograd_function.py b/test/legacy_test/test_autograd_function.py index 4b1312ff9d61ed..5a3578daca8d12 100644 --- a/test/legacy_test/test_autograd_function.py +++ b/test/legacy_test/test_autograd_function.py @@ -674,6 +674,11 @@ def backward(ctx, grad_a, grad_b): b.sum().backward() self.assertEqual(x.grad, paddle.ones([1], dtype="float64")) + def test_once_differentiable_compatibility(self): + pyLayerObj = paddle.autograd.py_layer.once_differentiable + functionObj = paddle.autograd.function.once_differentiable + self.assertEqual(pyLayerObj, functionObj) + if __name__ == '__main__': unittest.main()