Skip to content

Fix sliding_window hasattr in Mistral#27041

Merged
ArthurZucker merged 2 commits intohuggingface:mainfrom
IlyaGusev:patch-1
Nov 26, 2023
Merged

Fix sliding_window hasattr in Mistral#27041
ArthurZucker merged 2 commits intohuggingface:mainfrom
IlyaGusev:patch-1

Conversation

@IlyaGusev
Copy link
Contributor

@IlyaGusev IlyaGusev commented Oct 24, 2023

What does this PR do?

It fixes a bug with checking hasattr result with is not None. hasattr returns True of False, so the condition is always True without this fix.

Before submitting

Who can review?

@ArthurZucker @younesbelkada or anyone else.

@IlyaGusev
Copy link
Contributor Author

One more possible way to fix it is to use getattr(self.config, "sliding_window", None) instead.

Copy link
Contributor

@younesbelkada younesbelkada left a comment

Choose a reason for hiding this comment

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

thanks!

@patrickvonplaten
Copy link
Contributor

Just to better understand, how can sliding_window be set to None? It always defaults to a "non-None" value here:

@younesbelkada
Copy link
Contributor

younesbelkada commented Oct 24, 2023

@patrickvonplaten correct, it should never be None indeed - in any case the condition hasattr(config, "sliding_window") can be removed I think

Copy link
Contributor

@younesbelkada younesbelkada Oct 24, 2023

Choose a reason for hiding this comment

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

Suggested change
and hasattr(self.config, "sliding_window")

as per @patrickvonplaten 's explanation above

Copy link
Contributor Author

@IlyaGusev IlyaGusev Oct 24, 2023

Choose a reason for hiding this comment

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

What is the purpose of use_sliding_windows then? My understanding is that one can disable sliding windows by deleting this attribute completely.

So there are two possible cases:

  1. No "sliding_window" in the config -> use_sliding_windows is False -> no additional code is used
  2. "sliding_window" is in the config and it is not None -> use_sliding_windows is True when kv_cache is large enough -> additional code about sliding windows is used.

And there is the third case that is not possible:
3) "sliding_window" is in the config and it is None

The problem is that to reach case 1, one has to manually delattr this field.
So my suggestion is to replace hasattr(self.config, "sliding_window") with getattr(self.config, "sliding_window", None) is not None or even self.config.sliding_window is not None.
And by setting it to None, users can disable sliding windows.

@IlyaGusev
Copy link
Contributor Author

So this way if someone wants to disable sliding windows, they should either delete the attribute or set it to None.

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@IlyaGusev
Copy link
Contributor Author

I think it is still relevant and should be merged.

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Actually setting it to None should de-activate the sliding of the cache so yes.
Can you make sure to rebase on main?

@IlyaGusev
Copy link
Contributor Author

Done, I've rebased.

@ArthurZucker
Copy link
Collaborator

Thanks for the fix!

@ArthurZucker ArthurZucker merged commit f70db28 into huggingface:main Nov 26, 2023
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