Fix extra EOS tokens (#91)

* Fix extra EOS tokens

* Fix pre-commit error
This commit is contained in:
Anthony DePasquale
2024-07-04 01:22:29 +02:00
committed by GitHub
parent 0c08f3a7e4
commit 2a2931ba8d
2 changed files with 3 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/slessans/pre-commit-swift-format
rev: ""
rev: "fd627de92bdf84a75c924ed95691336d14e94cf1"
hooks:
- id: swift-format
args: ["--configuration", ".swift-format"]

View File

@@ -183,19 +183,10 @@ public func generate(
var start = Date.timeIntervalSinceReferenceDate
var promptTime: TimeInterval = 0
// build a set of additional stop tokens
let additionalEOSTokenIds = Set(
(extraEOSTokens ?? [])
.map {
tokenizer.encode(text: $0)
}
.filter {
// discard anything that is not a single token. sometimes
// the tokenizer will insert a <s> token, so accept that too
$0.count == 1 || ($0.count == 2 && $0[0] == 1)
}
.map {
$0.last!
.compactMap {
tokenizer.convertTokenToId($0)
})
var tokens = [Int]()