mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2026-04-23 00:17:25 +08:00
[BugFix][Optimization] Replace silent failures with catchable exceptions and informative error messages (#6533)
* init * init * fix format * add * add files * add ut * fix some * add ut * add more * add * fix pre-commit * fix pre-commit * fix cover * skip long seq * add * add * fix * remove not need * fix set attr * fix comments * fix comments * fix failed tests --------- Co-authored-by: gongweibao <gognweibao@baidu.com>
This commit is contained in:
@@ -14,6 +14,9 @@
|
||||
# limitations under the License.
|
||||
"""
|
||||
|
||||
# NOTE: Coverage supplement test — uses mock to reach compilation pipeline
|
||||
# branches that require Triton/CUDA toolchain not available in unit tests.
|
||||
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
@@ -179,5 +182,41 @@ class TestPaddleUseTritonV2(unittest.TestCase):
|
||||
self.assertEqual(my_kernel.key_args, ["N", "K"])
|
||||
|
||||
|
||||
class TestKernelInterfaceUnsupportedTypes(unittest.TestCase):
|
||||
"""Test assert False paths for unsupported types in KernelInterface decorator (L192, L200)."""
|
||||
|
||||
def test_unsupported_constexpr_type_raises_assertion(self):
|
||||
"""Passing unsupported constexpr type triggers assert with message (L192)."""
|
||||
|
||||
def kernel(a, N: tl.constexpr, K: tl.constexpr):
|
||||
return
|
||||
|
||||
ki = tu2.KernelInterface(kernel, other_config={})
|
||||
ki.grid = [1, 1, 1]
|
||||
|
||||
# Pass a string (unsupported type) as constexpr arg 'N'
|
||||
a = paddle.to_tensor([1], dtype="float32")
|
||||
with self.assertRaises(AssertionError) as ctx:
|
||||
ki.decorator(a, N="bad_string", K=8)
|
||||
self.assertIn("Unsupported constexpr type", str(ctx.exception))
|
||||
self.assertIn("N", str(ctx.exception))
|
||||
|
||||
def test_unsupported_non_constexpr_arg_type_raises_assertion(self):
|
||||
"""Passing unsupported non-constexpr arg type triggers assert with message (L200)."""
|
||||
|
||||
def kernel(a, b, N: tl.constexpr, K: tl.constexpr):
|
||||
return
|
||||
|
||||
ki = tu2.KernelInterface(kernel, other_config={})
|
||||
ki.grid = [1, 1, 1]
|
||||
|
||||
# 'a' is a Tensor, 'b' is a non-constexpr non-Tensor — pass a string
|
||||
a = paddle.to_tensor([1], dtype="float32")
|
||||
with self.assertRaises(AssertionError) as ctx:
|
||||
ki.decorator(a, "bad_string", N=8, K=16)
|
||||
self.assertIn("Unsupported arg type", str(ctx.exception))
|
||||
self.assertIn("b", str(ctx.exception))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user