-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
[Kernel][Model] logits_soft_cap for Gemma2 with flashinfer #6051
Merged
LiuXiaoxuanPKU
merged 15 commits into
vllm-project:main
from
LiuXiaoxuanPKU:flashinfer-logit-soft-cap
Jul 4, 2024
Merged
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c7ddd18
logits_soft_cap for gemma2 in flashinfer
LiuXiaoxuanPKU ceb7a16
separate tests
LiuXiaoxuanPKU afa1ef3
minor
LiuXiaoxuanPKU 6426e9b
format
LiuXiaoxuanPKU 8423d03
format
LiuXiaoxuanPKU 54f8548
add flashinfer unit test, update error message
LiuXiaoxuanPKU c0f298b
format
LiuXiaoxuanPKU d248cef
Update .buildkite/test-pipeline.yaml
LiuXiaoxuanPKU 0947961
fix
LiuXiaoxuanPKU 0cc481c
remove warning
LiuXiaoxuanPKU 06b1a4f
Merge branch 'main' of github.com:LiuXiaoxuanPKU/vllm
LiuXiaoxuanPKU 1f266c6
Merge branch 'main' into flashinfer-logit-soft-cap
LiuXiaoxuanPKU cf02682
fix merge bug
LiuXiaoxuanPKU 8e4d1d3
format
LiuXiaoxuanPKU 5257015
remove model test since unit tests already convered and unblock release
LiuXiaoxuanPKU 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 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,41 @@ | ||
"""Compare the outputs of HF and vLLM for Gemma2 models using greedy sampling. | ||
|
||
Run `pytest tests/models/test_gemma2.py`. | ||
""" | ||
import os | ||
|
||
import pytest | ||
|
||
from .utils import check_logprobs_close | ||
|
||
MODELS = ["google/gemma-2-9b"] | ||
|
||
|
||
@pytest.mark.parametrize("model", MODELS) | ||
@pytest.mark.parametrize("dtype", ["bfloat16"]) | ||
@pytest.mark.parametrize("max_tokens", [64]) | ||
@pytest.mark.parametrize("num_logprobs", [5]) | ||
def test_models( | ||
hf_runner, | ||
vllm_runner, | ||
example_prompts, | ||
model: str, | ||
dtype: str, | ||
max_tokens: int, | ||
num_logprobs: int, | ||
) -> None: | ||
os.environ['VLLM_ATTENTION_BACKEND'] = "FLASHINFER" | ||
# TODO(sang): Sliding window should be tested separately. | ||
with hf_runner(model, dtype=dtype) as hf_model: | ||
hf_outputs = hf_model.generate_greedy_logprobs_limit( | ||
example_prompts, max_tokens, num_logprobs) | ||
|
||
with vllm_runner(model, dtype=dtype) as vllm_model: | ||
vllm_outputs = vllm_model.generate_greedy_logprobs( | ||
example_prompts, max_tokens, num_logprobs) | ||
check_logprobs_close( | ||
outputs_0_lst=hf_outputs, | ||
outputs_1_lst=vllm_outputs, | ||
name_0="hf", | ||
name_1="vllm", | ||
) |
This file contains 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 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 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 |
---|---|---|
|
@@ -659,6 +659,16 @@ def _prepare_model_input_tensors( | |
dtype=torch.long, | ||
device=self.device) | ||
|
||
logits_soft_cap = getattr(self.model_config.hf_config, | ||
'final_logit_softcapping', None) | ||
if logits_soft_cap is not None and self.attn_backend.get_name( | ||
) != "flashinfer": | ||
logger.warning("Please use Flashinfer backend for models with" | ||
"logits_soft_cap (i.e., Gemma-2)." | ||
" Otherwise, the output might be wrong." | ||
" Set Flashinfer backend by " | ||
"export VLLM_ATTENTION_BACKEND=FLASHINFER.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should just raise an exception IMO. |
||
|
||
if self.attn_backend.get_name() == "flashinfer": | ||
if len(paged_kv_indptr) > 0: | ||
paged_kv_indices_tensor = torch.tensor(paged_kv_indices, | ||
|
@@ -676,7 +686,6 @@ def _prepare_model_input_tensors( | |
|
||
kv_cache_dtype = get_kv_cache_torch_dtype(self.kv_cache_dtype, | ||
self.model_config.dtype) | ||
|
||
attn_metadata = self.attn_backend.make_metadata( | ||
num_prefills=num_prefills, | ||
slot_mapping=slot_mapping_tensor, | ||
|
@@ -697,7 +706,8 @@ def _prepare_model_input_tensors( | |
query_start_loc=query_start_loc, | ||
device=self.device, | ||
data_type=kv_cache_dtype, | ||
use_cuda_graph=use_captured_graph) | ||
use_cuda_graph=use_captured_graph, | ||
logits_soft_cap=logits_soft_cap) | ||
|
||
else: | ||
attn_metadata = self.attn_backend.make_metadata( | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could I check if
logits_soft_cap
is supposed to be theattn_logit_softcapping
value instead? The two values are different in the Gemma2 config.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yongxb Nice catch!
final_logit_softcapping
is used to cap the final logits before sampling. @LiuXiaoxuanPKU Could you please fix this?