-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[torch.compile] Fine-grained CustomOp enabling mechanism #9300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tlrmchlsmth
merged 11 commits into
vllm-project:main
from
neuralmagic:luka/custom_ops_env
Oct 17, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
94118ed
add custom op enabling mechanism (with test)
ProExpertProg 88eef3f
Add a comment
ProExpertProg 14a3105
revert comment
ProExpertProg 69e5444
PR comments:
ProExpertProg 329f4af
Reformat test
ProExpertProg e78e4de
Add custom op registry
ProExpertProg 8f1fc44
PR comments:
ProExpertProg fae9e27
Fix comment in envs
ProExpertProg 5201dc6
Improve custom_op comment
ProExpertProg 0d42d55
Merge branch 'refs/heads/main' into luka/custom_ops_env
ProExpertProg 408d576
Lazy init for activations
ProExpertProg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import os | ||
from typing import List | ||
|
||
import pytest | ||
|
||
from vllm.model_executor.custom_op import CustomOp | ||
from vllm.model_executor.layers.activation import (GeluAndMul, | ||
ReLUSquaredActivation, | ||
SiluAndMul) | ||
from vllm.model_executor.layers.layernorm import RMSNorm | ||
|
||
|
||
# Registered subclass for test | ||
@CustomOp.register("relu3") | ||
class Relu3(ReLUSquaredActivation): | ||
pass | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"env, torch_level, ops_enabled, default_on", | ||
[ | ||
# Default values based on compile level | ||
("", 0, [True] * 4, True), | ||
("", 1, [True] * 4, True), | ||
("", 2, [True] * 4, True), # All by default | ||
("", 3, [False] * 4, False), | ||
("", 4, [False] * 4, False), # None by default | ||
# Explicitly enabling/disabling | ||
# | ||
# Default: all | ||
# | ||
# All but SiluAndMul | ||
("+rms_norm,-silu_and_mul", 0, [1, 0, 1, 1], True), | ||
# Only ReLU3 | ||
("none,-rms_norm,+relu3", 0, [0, 0, 0, 1], False), | ||
# All but SiluAndMul | ||
("all,-silu_and_mul", 1, [1, 0, 1, 1], True), | ||
# All but ReLU3 (even if ReLU2 is on) | ||
("-relu3,relu2", 1, [1, 1, 1, 0], True), | ||
# GeluAndMul and SiluAndMul | ||
("none,-relu3,+gelu_and_mul,+silu_and_mul", 2, [0, 1, 1, 0], False), | ||
# All but RMSNorm | ||
("-rms_norm", 2, [0, 1, 1, 1], True), | ||
# | ||
# Default: none | ||
# | ||
# Only ReLU3 | ||
("-silu_and_mul,+relu3", 3, [0, 0, 0, 1], False), | ||
# All but RMSNorm | ||
("all,-rms_norm", 4, [0, 1, 1, 1], True), | ||
]) | ||
def test_enabled_ops(env: str, torch_level: int, ops_enabled: List[int], | ||
default_on: bool): | ||
os.environ["VLLM_CUSTOM_OPS"] = env | ||
os.environ["VLLM_TORCH_COMPILE_LEVEL"] = str(torch_level) | ||
|
||
# Reset default_on (computed once): | ||
CustomOp.default_on.cache_clear() | ||
|
||
assert CustomOp.default_on() == default_on | ||
|
||
ops_enabled = [bool(x) for x in ops_enabled] | ||
|
||
assert RMSNorm(1024).enabled() == ops_enabled[0] | ||
assert CustomOp.op_registry["rms_norm"].enabled() == ops_enabled[0] | ||
|
||
assert SiluAndMul().enabled() == ops_enabled[1] | ||
assert CustomOp.op_registry["silu_and_mul"].enabled() == ops_enabled[1] | ||
|
||
assert GeluAndMul().enabled() == ops_enabled[2] | ||
assert CustomOp.op_registry["gelu_and_mul"].enabled() == ops_enabled[2] | ||
|
||
# If registered, subclasses should follow their own name | ||
assert Relu3().enabled() == ops_enabled[3] | ||
assert CustomOp.op_registry["relu3"].enabled() == ops_enabled[3] | ||
|
||
# Unregistered subclass | ||
class SiluAndMul2(SiluAndMul): | ||
pass | ||
|
||
# Subclasses should not require registration | ||
assert SiluAndMul2().enabled() == SiluAndMul().enabled() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"env", ["all,none", "all,+rms_norm,all", "+rms_norm,-rms_norm"]) | ||
def test_enabled_ops_invalid(env: str): | ||
os.environ["VLLM_CUSTOM_OPS"] = env | ||
CustomOp.default_on.cache_clear() | ||
|
||
with pytest.raises(AssertionError): | ||
RMSNorm(1024).enabled() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.