Skip to content

Commit

Permalink
[torch.compile] add a flag to disable custom op (vllm-project#8488)
Browse files Browse the repository at this point in the history
  • Loading branch information
youkaichao authored and Jeffwan committed Sep 19, 2024
1 parent 789eeb1 commit 77eac8d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/compile/test_full_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
@pytest.mark.parametrize("model", ["meta-llama/Meta-Llama-3-8B"])
def test_full_graph(model):
# make sure these models can be captured in full graph mode
os.environ["VLLM_TEST_DYNAMO_GRAPH_CAPTURE"] = "1"
if "VLLM_TEST_DYNAMO_GRAPH_CAPTURE" not in os.environ:
os.environ["VLLM_TEST_DYNAMO_GRAPH_CAPTURE"] = "1"

from vllm import LLM, SamplingParams
prompts = [
Expand Down
5 changes: 5 additions & 0 deletions vllm/envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ def get_default_config_root():
(os.environ.get("VLLM_DYNAMO_USE_CUSTOM_DISPATCHER", "True").lower() in
("true", "1")),

# Internal flag to control whether we use custom op,
# or use the native pytorch implementation
"VLLM_TEST_COMPILE_NO_CUSTOM_OPS":
lambda: int(os.environ.get("VLLM_TEST_COMPILE_NO_CUSTOM_OPS", "0")),

# Internal flag to enable Dynamo fullgraph capture
"VLLM_TEST_DYNAMO_FULLGRAPH_CAPTURE":
lambda: bool(
Expand Down
5 changes: 5 additions & 0 deletions vllm/model_executor/custom_op.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import torch.nn as nn

import vllm.envs as envs
from vllm.platforms import current_platform
from vllm.utils import is_cpu, is_hip, is_xpu

Expand Down Expand Up @@ -53,6 +54,10 @@ def forward_gaudi(self, *args, **kwargs):
def dispatch_forward(self):
# NOTE(woosuk): Here we assume that vLLM was built for only one
# specific backend. Currently, we do not support dynamic dispatching.

if envs.VLLM_TEST_COMPILE_NO_CUSTOM_OPS:
return self.forward_native

if is_hip():
return self.forward_hip
elif is_cpu():
Expand Down

0 comments on commit 77eac8d

Please sign in to comment.