Skip to content

Add repetition penalty warper #85

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

Merged
merged 2 commits into from
Apr 26, 2024

Conversation

shavit
Copy link
Contributor

@shavit shavit commented Mar 29, 2024

Closes #84

shavit added 2 commits March 29, 2024 14:29
  * Add penalty to logits warpers
  * Test repetition penalty
@shavit shavit marked this pull request as ready for review March 29, 2024 20:10
Copy link
Member

@pcuenca pcuenca left a comment

Choose a reason for hiding this comment

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

Thanks a lot! This is a very nice addition to the library 🔥 I'd just like to confirm whether results are the same as in transformers, will run some tests later.


public func warp(indices: [Int], logits: [Float]) -> (indices: [Int], logits: [Float]) {
var logits = logits
for index in indices {
Copy link
Member

Choose a reason for hiding this comment

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

Did you try to find an accelerated version of this? (not critical right now, but good to keep in mind for the future)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to use gather scatter, but didn't find scatter method in vDSP.

@@ -87,6 +87,36 @@ final class LogitsWarperTests: XCTestCase {
XCTAssertEqual(result5.logits, [2, 1, 0], accuracy: accuracy)
}

func testRepetitionPenaltyWarper() {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding tests! Did you verify results against the reference transformers implementation?

public struct RepetitionPenaltyWarper: LogitsWarper {
public var penalty: Float

public init(penalty: Double) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe let's throw here if penalty <= 0 (it must be strictly positive)

@pcuenca
Copy link
Member

pcuenca commented Apr 26, 2024

Test runners are not working for some reason. I verified locally that the tests pass, so merging now. Thanks @shavit!

@pcuenca pcuenca merged commit 5e02089 into huggingface:main Apr 26, 2024
1 check failed
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.

Is GenerationConfig.repetitionPenalty used during generation?
2 participants