-
Notifications
You must be signed in to change notification settings - Fork 6k
[LoRA] use removeprefix
to preserve sanity.
#11493
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
Conversation
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. |
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.
LGTM, thanks.
Just for other reviewers: The change is not equivalent, as this will strictly check for prefixes, i.e. the new code corresponds to k[len(f"{prefix}.") :] if k.startswith(prefix) else k
. Also, removeprefix
was introduced in Python 3.9, but 3.8 is EOL so this should be fine.
@BenjaminBossan also to be clear that in our codebase |
No, I agree, I just wanted to highlight the difference in case there is an example where the "prefix" is actually allowed to be in the middle of the string. |
For the purposes of this PR and for the use of |
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.
Just some nits. Personal preference is to use f-strings but either is okay
Fix for the failing tests #11504. |
What does this PR do?
We have multiple recurrences of using the following patterns in our LoRA codebase:
k.replace(f"{prefix}.", "")
k[len(f"{prefix}.") :]
It's just mind-twisting sometimes and I think
removeprefix()
just makes it easier.I have run the integration tests and ensured they are passing.