Skip to content

Fix some tests (especially compile with fullgraph=True on Python<3.11) - #38319

Merged
Cyrilvallez merged 4 commits into
mainfrom
fix-tests
May 23, 2025
Merged

Cyrilvallez merged 4 commits into
mainfrom
fix-tests

Conversation

@Cyrilvallez

Copy link
Copy Markdown
Member

What does this PR do?

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,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? 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, and
    here are tips on formatting docstrings.
  • 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.


logits = output.logits
torch.testing.assert_close(EXPECTED_LOGITS, logits[:, :3, :3], rtol=1e-3, atol=1e-3)
torch.testing.assert_close(EXPECTED_LOGITS, logits[:, -3:, :3], rtol=1e-3, atol=1e-3)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test was looking at the first 3 tokens in the seq_len dimension, but as we have padding tokens it does not really make sense... And as we don't use the mask workaround (unmask the fully unattended rows) on newer torch versions because the fix got upstreamed, we get different results here with the mask refactor. On the last 3 tokens though, there are no changes, as it should

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but could you very concisely explain why it works before the mask refactor PR? Just to get a bit of context

@Cyrilvallez Cyrilvallez May 23, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's simply that we used to change these positions of the mask, attending to them instead of skipping them - so we used to get numerical values for them, now we just have 0s instead as we don't attend to them at all

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Comment on lines -405 to -416
EXPECTED_LOGITS_LEFT = {
7: torch.Tensor(
[[0.1904, 0.0500, 0.7187], [0.1933, 0.0515, 0.7187], [0.2001, 0.0559, 0.7148]],
).to(torch_device),
8: torch.Tensor([[0.1914, 0.0508, 0.7188], [0.1953, 0.0510, 0.7227], [0.1973, 0.0562, 0.7148]]).to(
torch_device
),
9: torch.Tensor([[0.1904, 0.0513, 0.7227], [0.1943, 0.0518, 0.7227], [0.1982, 0.0557, 0.7148]]).to(
torch_device
),
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for cohere - does not make sense to check logits for padded positions, and behavior has changed

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you think better to remove this check instead of changing to -3:, :3 (like what you did for cohere), ok for me

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this one was specifically looking at the padded positions, we would only get 0s now so no need to test

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean attention output would be 0, then logits will get constant value based on later ops on the 0s value at those positions

Comment on lines -421 to +410
8: torch.Tensor([[0.2217, 0.5195, -0.3828], [0.8203, -0.2295, 0.6055], [0.2676, -0.7109, 0.2461]]).to(
torch_device
8: torch.Tensor([[ 0.2207, 0.5234, -0.3828], [ 0.8203, -0.2285, 0.6055], [ 0.2656, -0.7109, 0.2451]]).to(
torch_device,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I adjusted values for A100 only, as they were not correct - for T4 they are still the same, as once again there is no regresion on this test except for fully padded positions (but we never care about them) 🤗

def _prefetch_layer_in_context(self, layer_idx: int) -> None:
"""Performs the actual copy of the layer to device cache."""
if len(self.key_cache) >= layer_idx:
if len(self.key_cache) > layer_idx:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to ping gante here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can but it's a simple fix (if ==, then will be out of positions as Python is 0-indexed) on the Cache I added myself before 🤗 We did not have the issue before on the tests because this scenario would not happen as we are supposed to have interleaved layers in the HybridCache, but in the mask refactor I made it similar to StaticCache if no interleaved pattern in the config, so the issue came up!
cc @gante though, for reference!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gooddddddddd (I am asking as I don't know much about the history of this )

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea about how this should be, but it seems this just revert your changes in the mask refactor PR. So ok for me

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

@ydshieh ydshieh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. The change in cache_utils.py I don't have the expertise, others changes works for me 🙏 Thank you a lot 🫡

@Cyrilvallez

Copy link
Copy Markdown
Member Author

Alright, merging as I'm certain on the cache change!

@Cyrilvallez
Cyrilvallez merged commit 896833c into main May 23, 2025
@Cyrilvallez
Cyrilvallez deleted the fix-tests branch May 23, 2025 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants