Files
FastDeploy/tests/operators/test_gelu_tanh.py
ming1753 cba185f1fe [Feature] Optim PaddleOCR-VL (#4873)
* [Feature] Optim PaddleOCR-VL

* fix bug
2025-11-07 14:56:44 +08:00

43 lines
1.2 KiB
Python

# Copyright (c) 2025 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 numpy as np
import paddle
from paddleformers.transformers.activations import ACT2FN
from fastdeploy.model_executor.ops.gpu import gelu_tanh
class TestGeluTanh(unittest.TestCase):
def setUp(self):
paddle.set_device("gpu")
np.random.seed(42)
def test_gelu_tanh(self):
x = paddle.randn(2048, 4096)
y0 = ACT2FN["gelu_new"](x)
y1 = gelu_tanh(x)
np.testing.assert_allclose(
y0.cast("float32").numpy(),
y1.cast("float32").numpy(),
rtol=1e-04,
atol=1e-04,
)
if __name__ == "__main__":
unittest.main()