Skip to content

Commit

Permalink
Make GPTQ test less flaky (#1295)
Browse files Browse the repository at this point in the history
# What does this PR do?

<!--
Congratulations! You've made it this far! You're not quite done yet
though.

Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.

Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.

Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Fixes # (issue)


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.

<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @


@OlivierDehaene OR @Narsil

 -->
  • Loading branch information
Narsil authored Nov 28, 2023
1 parent ba552e1 commit 624800c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
13 changes: 11 additions & 2 deletions integration-tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@


class ResponseComparator(JSONSnapshotExtension):
rtol = 0.2
def serialize(
self,
data,
Expand Down Expand Up @@ -58,7 +59,7 @@ def eq_token(token: Token, other: Token) -> bool:
return (
token.id == other.id
and token.text == other.text
and math.isclose(token.logprob, other.logprob, rel_tol=0.2)
and math.isclose(token.logprob, other.logprob, rel_tol=self.rtol)
and token.special == other.special
)

Expand All @@ -68,7 +69,7 @@ def eq_prefill_token(prefill_token: InputToken, other: InputToken) -> bool:
prefill_token.id == other.id
and prefill_token.text == other.text
and (
math.isclose(prefill_token.logprob, other.logprob, rel_tol=0.2)
math.isclose(prefill_token.logprob, other.logprob, rel_tol=self.rtol)
if prefill_token.logprob is not None
else prefill_token.logprob == other.logprob
)
Expand Down Expand Up @@ -148,6 +149,10 @@ def eq_response(response: Response, other: Response) -> bool:
)


class GenerousResponseComparator(ResponseComparator):
# Needed for GPTQ with exllama which has serious numerical fluctuations.
rtol = 0.75

class LauncherHandle:
def __init__(self, port: int):
self.client = AsyncClient(f"http://localhost:{port}")
Expand Down Expand Up @@ -193,6 +198,10 @@ def _inner_health(self) -> bool:
def response_snapshot(snapshot):
return snapshot.use_extension(ResponseComparator)

@pytest.fixture
def generous_response_snapshot(snapshot):
return snapshot.use_extension(GenerousResponseComparator)


@pytest.fixture(scope="module")
def event_loop():
Expand Down
12 changes: 6 additions & 6 deletions integration-tests/models/test_flash_starcoder_gptq.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ async def flash_starcoder_gptq(flash_starcoder_gptq_handle):

@pytest.mark.asyncio
@pytest.mark.private
async def test_flash_starcoder_gptq(flash_starcoder_gptq, response_snapshot):
async def test_flash_starcoder_gptq(flash_starcoder_gptq, generous_response_snapshot):
response = await flash_starcoder_gptq.generate(
"def geometric_mean(L: List[float]):",
max_new_tokens=20,
decoder_input_details=True,
)
assert response.details.generated_tokens == 20
assert response == response_snapshot
assert response == generous_response_snapshot


@pytest.mark.asyncio
@pytest.mark.private
async def test_flash_starcoder_gptq_default_params(
flash_starcoder_gptq, response_snapshot
flash_starcoder_gptq, generous_response_snapshot
):
response = await flash_starcoder_gptq.generate(
"def geometric_mean(L: List[float]):",
Expand All @@ -39,13 +39,13 @@ async def test_flash_starcoder_gptq_default_params(
seed=0,
)
assert response.details.generated_tokens == 20
assert response == response_snapshot
assert response == generous_response_snapshot


@pytest.mark.asyncio
@pytest.mark.private
async def test_flash_starcoder_gptq_load(
flash_starcoder_gptq, generate_load, response_snapshot
flash_starcoder_gptq, generate_load, generous_response_snapshot
):
responses = await generate_load(
flash_starcoder_gptq,
Expand All @@ -57,4 +57,4 @@ async def test_flash_starcoder_gptq_load(
assert len(responses) == 4
assert all([r.generated_text == responses[0].generated_text for r in responses])

assert responses == response_snapshot
assert responses == generous_response_snapshot

0 comments on commit 624800c

Please sign in to comment.