From ff45ac078eb41316353fc9a21acfff27826352f4 Mon Sep 17 00:00:00 2001 From: Jundong Liu <61149469+littledgg@users.noreply.github.com> Date: Tue, 16 Dec 2025 11:05:30 +0800 Subject: [PATCH] [Feature] Use `paddle.compat.enable_torch_proxy` in `fastdeploy/__init__.py` (#5211) * test feature * fix xgrammar * fix paddleformer * try whitelist * manual patch PaddlePaddle/Paddle#76706 for test * remove triton version * add comment * Update scripts/run_ci_xpu.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * remove use-triton-in-paddle in requirement.txt --------- Co-authored-by: Nyakku Shigure Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- fastdeploy/__init__.py | 14 ++++++++++++++ requirements.txt | 1 - 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/fastdeploy/__init__.py b/fastdeploy/__init__.py index 2e9b49d00..4e6343f8c 100644 --- a/fastdeploy/__init__.py +++ b/fastdeploy/__init__.py @@ -31,6 +31,8 @@ if os.getenv("PROMETHEUS_MULTIPROC_DIR", "") == "": import typing +import paddle + # first import prometheus setup to set PROMETHEUS_MULTIPROC_DIR # otherwise, the Prometheus package will be imported first, # which will prevent correct multi-process setup @@ -40,12 +42,24 @@ from fastdeploy.metrics.prometheus_multiprocess_setup import ( setup_multiprocess_prometheus() + from paddleformers.utils.log import logger as pf_logger from fastdeploy.engine.sampling_params import SamplingParams from fastdeploy.entrypoints.llm import LLM from fastdeploy.utils import current_package_version, envs +paddle.compat.enable_torch_proxy(scope={"triton"}) +# paddle.compat.enable_torch_proxy(scope={"triton"}) enables the torch proxy +# specifically for the 'triton' module. This means `import torch` inside 'triton' +# will actually import paddle's compatibility layer (acting as torch). +# +# 'scope' acts as an allowlist. To add other modules, you can do: +# paddle.compat.enable_torch_proxy(scope={"triton", "new_module"}) +# +# Note: Ensure that any torch APIs used in 'new_module' are already implemented in Paddle. + + if envs.FD_DEBUG != 1: import logging diff --git a/requirements.txt b/requirements.txt index 50f95e00a..4cac619c4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,7 +26,6 @@ prometheus-client decord moviepy triton -use-triton-in-paddle crcmod msgpack gunicorn