disable_compat

paddle. disable_compat ( ) None [source]

Disable the PyTorch proxy by removing the TorchProxyMetaFinder from sys.meta_path. This prevents ‘torch’ imports from being proxied to PaddlePaddle.

Example

>>> import paddle
>>> paddle.enable_compat()  # Enable torch compat globally
>>> import torch  # type: ignore[import-not-found] # This will import paddle as torch
>>> assert torch.sin is paddle.sin
>>> paddle.disable_compat()  # Disable torch compat
>>> try:
...     import torch  # This will raise ModuleNotFoundError
... except ModuleNotFoundError:
...     print("PyTorch compat is disabled.")