psdb.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from __future__ import annotations
  15. import builtins
  16. import types
  17. from typing import Callable, TypeVar
  18. from typing_extensions import ParamSpec
  19. T = TypeVar("T")
  20. P = ParamSpec("P")
  21. NO_BREAKGRAPH_CODES: set[types.CodeType] = set()
  22. NO_FALLBACK_CODES: set[types.CodeType] = set()
  23. def assert_true(input: bool):
  24. assert input
  25. def print(*args, **kwargs):
  26. builtins.print("[Dygraph]", *args, **kwargs)
  27. def breakpoint():
  28. import paddle
  29. old = paddle.framework.core.set_eval_frame(None)
  30. builtins.breakpoint() # noqa: T100
  31. paddle.framework.core.set_eval_frame(old)
  32. def check_no_breakgraph(fn: Callable[P, T]) -> Callable[P, T]:
  33. NO_BREAKGRAPH_CODES.add(fn.__code__)
  34. return fn
  35. def breakgraph():
  36. pass
  37. def check_no_fallback(fn: Callable[P, T]) -> Callable[P, T]:
  38. NO_FALLBACK_CODES.add(fn.__code__)
  39. return fn
  40. def fallback():
  41. pass
  42. def in_sot():
  43. return False